| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/protocol/webrtc_video_capturer_adapter.h" | 5 #include "remoting/protocol/webrtc_video_capturer_adapter.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "third_party/libjingle/source/talk/media/webrtc/webrtcvideoframe.h" | 9 #include "third_party/libjingle/source/talk/media/webrtc/webrtcvideoframe.h" |
| 10 #include "third_party/libyuv/include/libyuv/convert.h" | 10 #include "third_party/libyuv/include/libyuv/convert.h" |
| 11 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 11 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 12 | 12 |
| 13 namespace remoting { | 13 namespace remoting { |
| 14 namespace protocol { | 14 namespace protocol { |
| 15 | 15 |
| 16 // Number of frames to be captured per second. | 16 // Number of frames to be captured per second. |
| 17 const int kFramesPerSec = 30; | 17 const int kFramesPerSec = 30; |
| 18 | 18 |
| 19 WebrtcVideoCapturerAdapter::WebrtcVideoCapturerAdapter( | 19 WebrtcVideoCapturerAdapter::WebrtcVideoCapturerAdapter( |
| 20 scoped_ptr<webrtc::DesktopCapturer> capturer) | 20 scoped_ptr<webrtc::DesktopCapturer> capturer) |
| 21 : desktop_capturer_(std::move(capturer)) { | 21 : desktop_capturer_(std::move(capturer)), weak_factory_(this) { |
| 22 DCHECK(desktop_capturer_); | 22 DCHECK(desktop_capturer_); |
| 23 | 23 |
| 24 // Disable video adaptation since we don't intend to use it. | 24 // Disable video adaptation since we don't intend to use it. |
| 25 set_enable_video_adapter(false); | 25 set_enable_video_adapter(false); |
| 26 } | 26 } |
| 27 | 27 |
| 28 WebrtcVideoCapturerAdapter::~WebrtcVideoCapturerAdapter() { | 28 WebrtcVideoCapturerAdapter::~WebrtcVideoCapturerAdapter() { |
| 29 DCHECK(!capture_timer_); | 29 DCHECK(!capture_timer_); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void WebrtcVideoCapturerAdapter::SetSizeCallback( |
| 33 const SizeCallback& size_callback) { |
| 34 DCHECK(thread_checker_.CalledOnValidThread()); |
| 35 size_callback_ = size_callback; |
| 36 } |
| 37 |
| 38 base::WeakPtr<WebrtcVideoCapturerAdapter> |
| 39 WebrtcVideoCapturerAdapter::GetWeakPtr() { |
| 40 return weak_factory_.GetWeakPtr(); |
| 41 } |
| 42 |
| 32 bool WebrtcVideoCapturerAdapter::GetBestCaptureFormat( | 43 bool WebrtcVideoCapturerAdapter::GetBestCaptureFormat( |
| 33 const cricket::VideoFormat& desired, | 44 const cricket::VideoFormat& desired, |
| 34 cricket::VideoFormat* best_format) { | 45 cricket::VideoFormat* best_format) { |
| 35 DCHECK(thread_checker_.CalledOnValidThread()); | 46 DCHECK(thread_checker_.CalledOnValidThread()); |
| 36 | 47 |
| 37 // The |capture_format| passed to Start() is always ignored, so copy | 48 // The |capture_format| passed to Start() is always ignored, so copy |
| 38 // |best_format| to |desired_format|. | 49 // |best_format| to |desired_format|. |
| 39 *best_format = desired; | 50 *best_format = desired; |
| 40 return true; | 51 return true; |
| 41 } | 52 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 scoped_ptr<webrtc::DesktopFrame> owned_frame(frame); | 164 scoped_ptr<webrtc::DesktopFrame> owned_frame(frame); |
| 154 | 165 |
| 155 // Drop the frame if there were no changes. | 166 // Drop the frame if there were no changes. |
| 156 if (!owned_frame || owned_frame->updated_region().is_empty()) | 167 if (!owned_frame || owned_frame->updated_region().is_empty()) |
| 157 return; | 168 return; |
| 158 | 169 |
| 159 size_t width = frame->size().width(); | 170 size_t width = frame->size().width(); |
| 160 size_t height = frame->size().height(); | 171 size_t height = frame->size().height(); |
| 161 if (!yuv_frame_ || yuv_frame_->GetWidth() != width || | 172 if (!yuv_frame_ || yuv_frame_->GetWidth() != width || |
| 162 yuv_frame_->GetHeight() != height) { | 173 yuv_frame_->GetHeight() != height) { |
| 174 if (!size_callback_.is_null()) |
| 175 size_callback_.Run(frame->size()); |
| 176 |
| 163 scoped_ptr<cricket::WebRtcVideoFrame> webrtc_frame( | 177 scoped_ptr<cricket::WebRtcVideoFrame> webrtc_frame( |
| 164 new cricket::WebRtcVideoFrame()); | 178 new cricket::WebRtcVideoFrame()); |
| 165 webrtc_frame->InitToEmptyBuffer(width, height, 1, 1, 0); | 179 webrtc_frame->InitToEmptyBuffer(width, height, 1, 1, 0); |
| 166 yuv_frame_ = std::move(webrtc_frame); | 180 yuv_frame_ = std::move(webrtc_frame); |
| 167 | 181 |
| 168 // Set updated_region so the whole frame is converted to YUV below. | 182 // Set updated_region so the whole frame is converted to YUV below. |
| 169 frame->mutable_updated_region()->SetRect( | 183 frame->mutable_updated_region()->SetRect( |
| 170 webrtc::DesktopRect::MakeWH(width, height)); | 184 webrtc::DesktopRect::MakeWH(width, height)); |
| 171 } | 185 } |
| 172 | 186 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 DCHECK(thread_checker_.CalledOnValidThread()); | 227 DCHECK(thread_checker_.CalledOnValidThread()); |
| 214 | 228 |
| 215 if (capture_pending_) | 229 if (capture_pending_) |
| 216 return; | 230 return; |
| 217 capture_pending_ = true; | 231 capture_pending_ = true; |
| 218 desktop_capturer_->Capture(webrtc::DesktopRegion()); | 232 desktop_capturer_->Capture(webrtc::DesktopRegion()); |
| 219 } | 233 } |
| 220 | 234 |
| 221 } // namespace protocol | 235 } // namespace protocol |
| 222 } // namespace remoting | 236 } // namespace remoting |
| OLD | NEW |