| 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 13 matching lines...) Expand all Loading... |
| 24 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 24 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 25 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor.h" | 25 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor.h" |
| 26 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor_shape.h" | 26 #include "third_party/webrtc/modules/desktop_capture/mouse_cursor_shape.h" |
| 27 | 27 |
| 28 namespace remoting { | 28 namespace remoting { |
| 29 | 29 |
| 30 // Maximum number of frames that can be processed simultaneously. | 30 // Maximum number of frames that can be processed simultaneously. |
| 31 // TODO(hclam): Move this value to CaptureScheduler. | 31 // TODO(hclam): Move this value to CaptureScheduler. |
| 32 static const int kMaxPendingFrames = 2; | 32 static const int kMaxPendingFrames = 2; |
| 33 | 33 |
| 34 // Interval between empty keep-alive frames. These frames are sent only | 34 // Interval between empty keep-alive frames. These frames are sent only when the |
| 35 // when there are no real video frames being sent. To prevent PseudoTCP from | 35 // stream is paused or inactive for some other reason (e.g. when blocked on |
| 36 // resetting congestion window this value must be smaller than the minimum | 36 // capturer). To prevent PseudoTCP from resetting congestion window this value |
| 37 // RTO used in PseudoTCP, which is 250ms. | 37 // must be smaller than the minimum RTO used in PseudoTCP, which is 250ms. |
| 38 static const int kKeepAlivePacketIntervalMs = 200; | 38 static const int kKeepAlivePacketIntervalMs = 200; |
| 39 | 39 |
| 40 static bool g_enable_timestamps = false; | 40 static bool g_enable_timestamps = false; |
| 41 | 41 |
| 42 // static | 42 // static |
| 43 void VideoScheduler::EnableTimestampsForTests() { | 43 void VideoScheduler::EnableTimestampsForTests() { |
| 44 g_enable_timestamps = true; | 44 g_enable_timestamps = true; |
| 45 } | 45 } |
| 46 | 46 |
| 47 VideoScheduler::VideoScheduler( | 47 VideoScheduler::VideoScheduler( |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } | 367 } |
| 368 | 368 |
| 369 // Encoder thread -------------------------------------------------------------- | 369 // Encoder thread -------------------------------------------------------------- |
| 370 | 370 |
| 371 void VideoScheduler::EncodeFrame( | 371 void VideoScheduler::EncodeFrame( |
| 372 scoped_ptr<webrtc::DesktopFrame> frame, | 372 scoped_ptr<webrtc::DesktopFrame> frame, |
| 373 int64 sequence_number, | 373 int64 sequence_number, |
| 374 base::TimeTicks timestamp) { | 374 base::TimeTicks timestamp) { |
| 375 DCHECK(encode_task_runner_->BelongsToCurrentThread()); | 375 DCHECK(encode_task_runner_->BelongsToCurrentThread()); |
| 376 | 376 |
| 377 // Drop the frame if there were no changes. | 377 // If there is nothing to encode then send an empty packet. |
| 378 if (!frame || frame->updated_region().is_empty()) { | 378 if (!frame || frame->updated_region().is_empty()) { |
| 379 capture_task_runner_->DeleteSoon(FROM_HERE, frame.release()); | 379 capture_task_runner_->DeleteSoon(FROM_HERE, frame.release()); |
| 380 capture_task_runner_->PostTask( | 380 scoped_ptr<VideoPacket> packet(new VideoPacket()); |
| 381 FROM_HERE, base::Bind(&VideoScheduler::FrameCaptureCompleted, this)); | 381 packet->set_client_sequence_number(sequence_number); |
| 382 network_task_runner_->PostTask( |
| 383 FROM_HERE, |
| 384 base::Bind( |
| 385 &VideoScheduler::SendVideoPacket, this, base::Passed(&packet))); |
| 382 return; | 386 return; |
| 383 } | 387 } |
| 384 | 388 |
| 385 scoped_ptr<VideoPacket> packet = encoder_->Encode(*frame); | 389 scoped_ptr<VideoPacket> packet = encoder_->Encode(*frame); |
| 386 packet->set_client_sequence_number(sequence_number); | 390 packet->set_client_sequence_number(sequence_number); |
| 387 | 391 |
| 388 if (g_enable_timestamps) { | 392 if (g_enable_timestamps) { |
| 389 packet->set_timestamp(timestamp.ToInternalValue()); | 393 packet->set_timestamp(timestamp.ToInternalValue()); |
| 390 } | 394 } |
| 391 | 395 |
| 392 // Destroy the frame before sending |packet| because SendVideoPacket() may | 396 // Destroy the frame before sending |packet| because SendVideoPacket() may |
| 393 // trigger another frame to be captured, and the screen capturer expects the | 397 // trigger another frame to be captured, and the screen capturer expects the |
| 394 // old frame to be freed by then. | 398 // old frame to be freed by then. |
| 395 frame.reset(); | 399 frame.reset(); |
| 396 | 400 |
| 397 scheduler_.RecordEncodeTime( | 401 scheduler_.RecordEncodeTime( |
| 398 base::TimeDelta::FromMilliseconds(packet->encode_time_ms())); | 402 base::TimeDelta::FromMilliseconds(packet->encode_time_ms())); |
| 399 network_task_runner_->PostTask( | 403 network_task_runner_->PostTask( |
| 400 FROM_HERE, base::Bind(&VideoScheduler::SendVideoPacket, this, | 404 FROM_HERE, base::Bind(&VideoScheduler::SendVideoPacket, this, |
| 401 base::Passed(&packet))); | 405 base::Passed(&packet))); |
| 402 } | 406 } |
| 403 | 407 |
| 404 } // namespace remoting | 408 } // namespace remoting |
| OLD | NEW |