| 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/libyuv/include/libyuv/convert.h" | 9 #include "third_party/libyuv/include/libyuv/convert.h" |
| 10 #include "third_party/webrtc/media/engine/webrtcvideoframe.h" | 10 #include "third_party/webrtc/media/engine/webrtcvideoframe.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 desktop_capturer_->Start(this); | 64 desktop_capturer_->Start(this); |
| 65 | 65 |
| 66 capture_timer_.reset(new base::RepeatingTimer()); | 66 capture_timer_.reset(new base::RepeatingTimer()); |
| 67 capture_timer_->Start(FROM_HERE, | 67 capture_timer_->Start(FROM_HERE, |
| 68 base::TimeDelta::FromSeconds(1) / kFramesPerSec, this, | 68 base::TimeDelta::FromSeconds(1) / kFramesPerSec, this, |
| 69 &WebrtcVideoCapturerAdapter::CaptureNextFrame); | 69 &WebrtcVideoCapturerAdapter::CaptureNextFrame); |
| 70 | 70 |
| 71 return cricket::CS_RUNNING; | 71 return cricket::CS_RUNNING; |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Similar to the base class implementation with some important differences: | 74 bool WebrtcVideoCapturerAdapter::PauseCapturer(bool pause) { |
| 75 // 1. Does not call either Stop() or Start(), as those would affect the state of | |
| 76 // |desktop_capturer_|. | |
| 77 // 2. Does not support unpausing after stopping the capturer. It is unclear | |
| 78 // if that flow needs to be supported. | |
| 79 bool WebrtcVideoCapturerAdapter::Pause(bool pause) { | |
| 80 DCHECK(thread_checker_.CalledOnValidThread()); | 75 DCHECK(thread_checker_.CalledOnValidThread()); |
| 81 | 76 |
| 82 if (pause) { | 77 if (pause) { |
| 83 if (capture_state() == cricket::CS_PAUSED) | 78 if (paused_) |
| 84 return true; | 79 return true; |
| 85 | 80 |
| 86 bool running = capture_state() == cricket::CS_STARTING || | 81 bool running = capture_state() == cricket::CS_STARTING || |
| 87 capture_state() == cricket::CS_RUNNING; | 82 capture_state() == cricket::CS_RUNNING; |
| 88 | 83 |
| 89 DCHECK_EQ(running, IsRunning()); | 84 DCHECK_EQ(running, IsRunning()); |
| 90 | 85 |
| 91 if (!running) { | 86 if (!running) { |
| 92 LOG(ERROR) | 87 LOG(ERROR) |
| 93 << "Cannot pause WebrtcVideoCapturerAdapter."; | 88 << "Cannot pause WebrtcVideoCapturerAdapter."; |
| 94 return false; | 89 return false; |
| 95 } | 90 } |
| 96 | 91 |
| 97 // Stop |capture_timer_| and set capture state to cricket::CS_PAUSED. | |
| 98 capture_timer_->Stop(); | 92 capture_timer_->Stop(); |
| 99 SetCaptureState(cricket::CS_PAUSED); | 93 paused_ = true; |
| 100 | 94 |
| 101 VLOG(1) << "WebrtcVideoCapturerAdapter paused."; | 95 VLOG(1) << "WebrtcVideoCapturerAdapter paused."; |
| 102 | 96 |
| 103 return true; | 97 return true; |
| 104 } else { // Unpausing. | 98 } else { // Unpausing. |
| 105 if (capture_state() != cricket::CS_PAUSED || !GetCaptureFormat() || | 99 if (!paused_ || !GetCaptureFormat() || !capture_timer_) { |
| 106 !capture_timer_) { | |
| 107 LOG(ERROR) << "Cannot unpause WebrtcVideoCapturerAdapter."; | 100 LOG(ERROR) << "Cannot unpause WebrtcVideoCapturerAdapter."; |
| 108 return false; | 101 return false; |
| 109 } | 102 } |
| 110 | 103 |
| 111 // Restart |capture_timer_| and set capture state to cricket::CS_RUNNING; | |
| 112 capture_timer_->Start(FROM_HERE, | 104 capture_timer_->Start(FROM_HERE, |
| 113 base::TimeDelta::FromMicroseconds( | 105 base::TimeDelta::FromMicroseconds( |
| 114 GetCaptureFormat()->interval / | 106 GetCaptureFormat()->interval / |
| 115 (base::Time::kNanosecondsPerMicrosecond)), | 107 (base::Time::kNanosecondsPerMicrosecond)), |
| 116 this, | 108 this, |
| 117 &WebrtcVideoCapturerAdapter::CaptureNextFrame); | 109 &WebrtcVideoCapturerAdapter::CaptureNextFrame); |
| 118 SetCaptureState(cricket::CS_RUNNING); | 110 paused_ = false; |
| 119 | 111 |
| 120 VLOG(1) << "WebrtcVideoCapturerAdapter unpaused."; | 112 VLOG(1) << "WebrtcVideoCapturerAdapter unpaused."; |
| 121 } | 113 } |
| 122 return true; | 114 return true; |
| 123 } | 115 } |
| 124 | 116 |
| 125 void WebrtcVideoCapturerAdapter::Stop() { | 117 void WebrtcVideoCapturerAdapter::Stop() { |
| 126 DCHECK(thread_checker_.CalledOnValidThread()); | 118 DCHECK(thread_checker_.CalledOnValidThread()); |
| 127 DCHECK_NE(capture_state(), cricket::CS_STOPPED); | 119 DCHECK_NE(capture_state(), cricket::CS_STOPPED); |
| 128 | 120 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 left * webrtc::DesktopFrame::kBytesPerPixel, | 208 left * webrtc::DesktopFrame::kBytesPerPixel, |
| 217 frame->stride(), | 209 frame->stride(), |
| 218 yuv_frame_->GetYPlane() + yuv_frame_->GetYPitch() * top + left, | 210 yuv_frame_->GetYPlane() + yuv_frame_->GetYPitch() * top + left, |
| 219 yuv_frame_->GetYPitch(), | 211 yuv_frame_->GetYPitch(), |
| 220 yuv_frame_->GetUPlane() + yuv_frame_->GetUPitch() * top / 2 + left / 2, | 212 yuv_frame_->GetUPlane() + yuv_frame_->GetUPitch() * top / 2 + left / 2, |
| 221 yuv_frame_->GetUPitch(), | 213 yuv_frame_->GetUPitch(), |
| 222 yuv_frame_->GetVPlane() + yuv_frame_->GetVPitch() * top / 2 + left / 2, | 214 yuv_frame_->GetVPlane() + yuv_frame_->GetVPitch() * top / 2 + left / 2, |
| 223 yuv_frame_->GetVPitch(), width, height); | 215 yuv_frame_->GetVPitch(), width, height); |
| 224 } | 216 } |
| 225 | 217 |
| 226 SignalVideoFrame(this, yuv_frame_.get()); | 218 OnFrame(this, yuv_frame_.get()); |
| 227 } | 219 } |
| 228 | 220 |
| 229 void WebrtcVideoCapturerAdapter::CaptureNextFrame() { | 221 void WebrtcVideoCapturerAdapter::CaptureNextFrame() { |
| 230 DCHECK(thread_checker_.CalledOnValidThread()); | 222 DCHECK(thread_checker_.CalledOnValidThread()); |
| 231 | 223 |
| 232 if (capture_pending_) | 224 if (capture_pending_) |
| 233 return; | 225 return; |
| 234 capture_pending_ = true; | 226 capture_pending_ = true; |
| 235 desktop_capturer_->Capture(webrtc::DesktopRegion()); | 227 desktop_capturer_->Capture(webrtc::DesktopRegion()); |
| 236 } | 228 } |
| 237 | 229 |
| 238 } // namespace protocol | 230 } // namespace protocol |
| 239 } // namespace remoting | 231 } // namespace remoting |
| OLD | NEW |