| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/host/video_scheduler.h" | 5 #include "remoting/host/video_scheduler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 DCHECK(capturer_); | 69 DCHECK(capturer_); |
| 70 DCHECK(mouse_cursor_monitor_); | 70 DCHECK(mouse_cursor_monitor_); |
| 71 DCHECK(encoder_); | 71 DCHECK(encoder_); |
| 72 DCHECK(cursor_stub_); | 72 DCHECK(cursor_stub_); |
| 73 DCHECK(video_stub_); | 73 DCHECK(video_stub_); |
| 74 } | 74 } |
| 75 | 75 |
| 76 // Public methods -------------------------------------------------------------- | 76 // Public methods -------------------------------------------------------------- |
| 77 | 77 |
| 78 webrtc::SharedMemory* VideoScheduler::CreateSharedMemory(size_t size) { | 78 webrtc::SharedMemory* VideoScheduler::CreateSharedMemory(size_t size) { |
| 79 return NULL; | 79 return nullptr; |
| 80 } | 80 } |
| 81 | 81 |
| 82 void VideoScheduler::OnCaptureCompleted(webrtc::DesktopFrame* frame) { | 82 void VideoScheduler::OnCaptureCompleted(webrtc::DesktopFrame* frame) { |
| 83 DCHECK(capture_task_runner_->BelongsToCurrentThread()); | 83 DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
| 84 | 84 |
| 85 capture_pending_ = false; | 85 capture_pending_ = false; |
| 86 | 86 |
| 87 scoped_ptr<webrtc::DesktopFrame> owned_frame(frame); | 87 scoped_ptr<webrtc::DesktopFrame> owned_frame(frame); |
| 88 | 88 |
| 89 if (owned_frame) { | 89 if (owned_frame) { |
| 90 scheduler_.RecordCaptureTime( | 90 scheduler_.RecordCaptureTime( |
| 91 base::TimeDelta::FromMilliseconds(owned_frame->capture_time_ms())); | 91 base::TimeDelta::FromMilliseconds(owned_frame->capture_time_ms())); |
| 92 } | 92 } |
| 93 | 93 |
| 94 // Even when |frame| is NULL we still need to post it to the encode thread | 94 // Even when |frame| is nullptr we still need to post it to the encode thread |
| 95 // to make sure frames are freed in the same order they are received and | 95 // to make sure frames are freed in the same order they are received and |
| 96 // that we don't start capturing frame n+2 before frame n is freed. | 96 // that we don't start capturing frame n+2 before frame n is freed. |
| 97 encode_task_runner_->PostTask( | 97 encode_task_runner_->PostTask( |
| 98 FROM_HERE, base::Bind(&VideoScheduler::EncodeFrame, this, | 98 FROM_HERE, base::Bind(&VideoScheduler::EncodeFrame, this, |
| 99 base::Passed(&owned_frame), latest_event_timestamp_, | 99 base::Passed(&owned_frame), latest_event_timestamp_, |
| 100 base::TimeTicks::Now())); | 100 base::TimeTicks::Now())); |
| 101 | 101 |
| 102 // If a frame was skipped, try to capture it again. | 102 // If a frame was skipped, try to capture it again. |
| 103 if (did_skip_frame_) { | 103 if (did_skip_frame_) { |
| 104 capture_task_runner_->PostTask( | 104 capture_task_runner_->PostTask( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 148 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 149 | 149 |
| 150 capture_task_runner_->PostTask( | 150 capture_task_runner_->PostTask( |
| 151 FROM_HERE, base::Bind(&VideoScheduler::StartOnCaptureThread, this)); | 151 FROM_HERE, base::Bind(&VideoScheduler::StartOnCaptureThread, this)); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void VideoScheduler::Stop() { | 154 void VideoScheduler::Stop() { |
| 155 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 155 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 156 | 156 |
| 157 // Clear stubs to prevent further updates reaching the client. | 157 // Clear stubs to prevent further updates reaching the client. |
| 158 cursor_stub_ = NULL; | 158 cursor_stub_ = nullptr; |
| 159 video_stub_ = NULL; | 159 video_stub_ = nullptr; |
| 160 | 160 |
| 161 keep_alive_timer_.reset(); | 161 keep_alive_timer_.reset(); |
| 162 | 162 |
| 163 capture_task_runner_->PostTask( | 163 capture_task_runner_->PostTask( |
| 164 FROM_HERE, base::Bind(&VideoScheduler::StopOnCaptureThread, this)); | 164 FROM_HERE, base::Bind(&VideoScheduler::StopOnCaptureThread, this)); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void VideoScheduler::Pause(bool pause) { | 167 void VideoScheduler::Pause(bool pause) { |
| 168 if (!capture_task_runner_->BelongsToCurrentThread()) { | 168 if (!capture_task_runner_->BelongsToCurrentThread()) { |
| 169 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 169 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 263 |
| 264 capture_timer_->Start(FROM_HERE, | 264 capture_timer_->Start(FROM_HERE, |
| 265 scheduler_.NextCaptureDelay(), | 265 scheduler_.NextCaptureDelay(), |
| 266 this, | 266 this, |
| 267 &VideoScheduler::CaptureNextFrame); | 267 &VideoScheduler::CaptureNextFrame); |
| 268 } | 268 } |
| 269 | 269 |
| 270 void VideoScheduler::CaptureNextFrame() { | 270 void VideoScheduler::CaptureNextFrame() { |
| 271 DCHECK(capture_task_runner_->BelongsToCurrentThread()); | 271 DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
| 272 | 272 |
| 273 // If we are stopping (|capturer_| is NULL), or paused, then don't capture. | 273 // If we are stopping (|capturer_| is nullptr), or paused, then don't capture. |
| 274 if (!capturer_ || is_paused_) | 274 if (!capturer_ || is_paused_) |
| 275 return; | 275 return; |
| 276 | 276 |
| 277 // Make sure we have at most two outstanding recordings. We can simply return | 277 // Make sure we have at most two outstanding recordings. We can simply return |
| 278 // if we can't make a capture now, the next capture will be started by the | 278 // if we can't make a capture now, the next capture will be started by the |
| 279 // end of an encode operation. | 279 // end of an encode operation. |
| 280 if (pending_frames_ >= kMaxPendingFrames || capture_pending_) { | 280 if (pending_frames_ >= kMaxPendingFrames || capture_pending_) { |
| 281 did_skip_frame_ = true; | 281 did_skip_frame_ = true; |
| 282 return; | 282 return; |
| 283 } | 283 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 frame.reset(); | 398 frame.reset(); |
| 399 | 399 |
| 400 scheduler_.RecordEncodeTime( | 400 scheduler_.RecordEncodeTime( |
| 401 base::TimeDelta::FromMilliseconds(packet->encode_time_ms())); | 401 base::TimeDelta::FromMilliseconds(packet->encode_time_ms())); |
| 402 network_task_runner_->PostTask( | 402 network_task_runner_->PostTask( |
| 403 FROM_HERE, base::Bind(&VideoScheduler::SendVideoPacket, this, | 403 FROM_HERE, base::Bind(&VideoScheduler::SendVideoPacket, this, |
| 404 base::Passed(&packet))); | 404 base::Passed(&packet))); |
| 405 } | 405 } |
| 406 | 406 |
| 407 } // namespace remoting | 407 } // namespace remoting |
| OLD | NEW |