| 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/video_frame_pump.h" | 5 #include "remoting/protocol/video_frame_pump.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 namespace remoting { | 24 namespace remoting { |
| 25 namespace protocol { | 25 namespace protocol { |
| 26 | 26 |
| 27 // Interval between empty keep-alive frames. These frames are sent only when the | 27 // Interval between empty keep-alive frames. These frames are sent only when the |
| 28 // stream is paused or inactive for some other reason (e.g. when blocked on | 28 // stream is paused or inactive for some other reason (e.g. when blocked on |
| 29 // capturer). To prevent PseudoTCP from resetting congestion window this value | 29 // capturer). To prevent PseudoTCP from resetting congestion window this value |
| 30 // must be smaller than the minimum RTO used in PseudoTCP, which is 250ms. | 30 // must be smaller than the minimum RTO used in PseudoTCP, which is 250ms. |
| 31 static const int kKeepAlivePacketIntervalMs = 200; | 31 static const int kKeepAlivePacketIntervalMs = 200; |
| 32 | 32 |
| 33 static bool g_enable_timestamps = false; | |
| 34 | |
| 35 VideoFramePump::FrameTimestamps::FrameTimestamps() {} | 33 VideoFramePump::FrameTimestamps::FrameTimestamps() {} |
| 36 VideoFramePump::FrameTimestamps::~FrameTimestamps() {} | 34 VideoFramePump::FrameTimestamps::~FrameTimestamps() {} |
| 37 | 35 |
| 38 VideoFramePump::PacketWithTimestamps::PacketWithTimestamps( | 36 VideoFramePump::PacketWithTimestamps::PacketWithTimestamps( |
| 39 std::unique_ptr<VideoPacket> packet, | 37 std::unique_ptr<VideoPacket> packet, |
| 40 std::unique_ptr<FrameTimestamps> timestamps) | 38 std::unique_ptr<FrameTimestamps> timestamps) |
| 41 : packet(std::move(packet)), timestamps(std::move(timestamps)) {} | 39 : packet(std::move(packet)), timestamps(std::move(timestamps)) {} |
| 42 | 40 |
| 43 VideoFramePump::PacketWithTimestamps::~PacketWithTimestamps() {} | 41 VideoFramePump::PacketWithTimestamps::~PacketWithTimestamps() {} |
| 44 | 42 |
| 45 // static | |
| 46 void VideoFramePump::EnableTimestampsForTests() { | |
| 47 g_enable_timestamps = true; | |
| 48 } | |
| 49 | |
| 50 VideoFramePump::VideoFramePump( | 43 VideoFramePump::VideoFramePump( |
| 51 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, | 44 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, |
| 52 std::unique_ptr<webrtc::DesktopCapturer> capturer, | 45 std::unique_ptr<webrtc::DesktopCapturer> capturer, |
| 53 std::unique_ptr<VideoEncoder> encoder, | 46 std::unique_ptr<VideoEncoder> encoder, |
| 54 protocol::VideoStub* video_stub) | 47 protocol::VideoStub* video_stub) |
| 55 : encode_task_runner_(encode_task_runner), | 48 : encode_task_runner_(encode_task_runner), |
| 56 capturer_(std::move(capturer)), | 49 capturer_(std::move(capturer)), |
| 57 encoder_(std::move(encoder)), | 50 encoder_(std::move(encoder)), |
| 58 video_stub_(video_stub), | 51 video_stub_(video_stub), |
| 59 keep_alive_timer_( | 52 keep_alive_timer_( |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 208 } |
| 216 | 209 |
| 217 send_pending_ = true; | 210 send_pending_ = true; |
| 218 video_stub_->ProcessVideoPacket(std::move(packet->packet), | 211 video_stub_->ProcessVideoPacket(std::move(packet->packet), |
| 219 base::Bind(&VideoFramePump::OnVideoPacketSent, | 212 base::Bind(&VideoFramePump::OnVideoPacketSent, |
| 220 weak_factory_.GetWeakPtr())); | 213 weak_factory_.GetWeakPtr())); |
| 221 } | 214 } |
| 222 | 215 |
| 223 void VideoFramePump::UpdateFrameTimers(VideoPacket* packet, | 216 void VideoFramePump::UpdateFrameTimers(VideoPacket* packet, |
| 224 FrameTimestamps* timestamps) { | 217 FrameTimestamps* timestamps) { |
| 225 if (g_enable_timestamps) | |
| 226 packet->set_timestamp(timestamps->capture_ended_time.ToInternalValue()); | |
| 227 | |
| 228 | |
| 229 if (!timestamps->input_event_received_time.is_null()) { | 218 if (!timestamps->input_event_received_time.is_null()) { |
| 230 packet->set_capture_pending_time_ms((timestamps->capture_started_time - | 219 packet->set_capture_pending_time_ms((timestamps->capture_started_time - |
| 231 timestamps->input_event_received_time) | 220 timestamps->input_event_received_time) |
| 232 .InMilliseconds()); | 221 .InMilliseconds()); |
| 233 packet->set_latest_event_timestamp( | 222 packet->set_latest_event_timestamp( |
| 234 timestamps->input_event_client_timestamp); | 223 timestamps->input_event_client_timestamp); |
| 235 } | 224 } |
| 236 | 225 |
| 237 packet->set_capture_overhead_time_ms( | 226 packet->set_capture_overhead_time_ms( |
| 238 (timestamps->capture_ended_time - timestamps->capture_started_time) | 227 (timestamps->capture_ended_time - timestamps->capture_started_time) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 } | 262 } |
| 274 | 263 |
| 275 void VideoFramePump::OnKeepAlivePacketSent() { | 264 void VideoFramePump::OnKeepAlivePacketSent() { |
| 276 DCHECK(thread_checker_.CalledOnValidThread()); | 265 DCHECK(thread_checker_.CalledOnValidThread()); |
| 277 | 266 |
| 278 keep_alive_timer_.Reset(); | 267 keep_alive_timer_.Reset(); |
| 279 } | 268 } |
| 280 | 269 |
| 281 } // namespace protocol | 270 } // namespace protocol |
| 282 } // namespace remoting | 271 } // namespace remoting |
| OLD | NEW |