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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 73 } |
74 | 74 |
75 void VideoScheduler::Start() { | 75 void VideoScheduler::Start() { |
76 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 76 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
77 | 77 |
78 keep_alive_timer_.reset(new base::DelayTimer<VideoScheduler>( | 78 keep_alive_timer_.reset(new base::DelayTimer<VideoScheduler>( |
79 FROM_HERE, base::TimeDelta::FromMilliseconds(kKeepAlivePacketIntervalMs), | 79 FROM_HERE, base::TimeDelta::FromMilliseconds(kKeepAlivePacketIntervalMs), |
80 this, &VideoScheduler::SendKeepAlivePacket)); | 80 this, &VideoScheduler::SendKeepAlivePacket)); |
81 | 81 |
82 capture_task_runner_->PostTask( | 82 capture_task_runner_->PostTask( |
83 FROM_HERE, base::Bind(&VideoScheduler::StartOnCaptureThread, this)); | 83 FROM_HERE, base::Bind(&VideoScheduler::StartOnCaptureThread, this, |
| 84 video_stub_->SupportsAcks())); |
84 } | 85 } |
85 | 86 |
86 void VideoScheduler::Stop() { | 87 void VideoScheduler::Stop() { |
87 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 88 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
88 | 89 |
89 // Clear stubs to prevent further updates reaching the client. | 90 // Clear stubs to prevent further updates reaching the client. |
90 cursor_stub_ = nullptr; | 91 cursor_stub_ = nullptr; |
91 video_stub_ = nullptr; | 92 video_stub_ = nullptr; |
92 | 93 |
93 keep_alive_timer_.reset(); | 94 keep_alive_timer_.reset(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 base::Passed(&cursor_proto))); | 197 base::Passed(&cursor_proto))); |
197 } | 198 } |
198 | 199 |
199 void VideoScheduler::OnMouseCursorPosition( | 200 void VideoScheduler::OnMouseCursorPosition( |
200 webrtc::MouseCursorMonitor::CursorState state, | 201 webrtc::MouseCursorMonitor::CursorState state, |
201 const webrtc::DesktopVector& position) { | 202 const webrtc::DesktopVector& position) { |
202 // We're not subscribing to mouse position changes. | 203 // We're not subscribing to mouse position changes. |
203 NOTREACHED(); | 204 NOTREACHED(); |
204 } | 205 } |
205 | 206 |
206 void VideoScheduler::StartOnCaptureThread() { | 207 void VideoScheduler::StartOnCaptureThread(bool acks_supported) { |
207 DCHECK(capture_task_runner_->BelongsToCurrentThread()); | 208 DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
208 DCHECK(!capture_scheduler_); | 209 DCHECK(!capture_scheduler_); |
209 | 210 |
210 mouse_cursor_monitor_->Init(this, webrtc::MouseCursorMonitor::SHAPE_ONLY); | 211 mouse_cursor_monitor_->Init(this, webrtc::MouseCursorMonitor::SHAPE_ONLY); |
211 capturer_->Start(this); | 212 capturer_->Start(this); |
212 | 213 |
213 capture_scheduler_.reset(new CaptureScheduler( | 214 capture_scheduler_.reset(new CaptureScheduler( |
214 base::Bind(&VideoScheduler::CaptureNextFrame, this))); | 215 base::Bind(&VideoScheduler::CaptureNextFrame, this), acks_supported)); |
215 capture_scheduler_->Start(); | 216 capture_scheduler_->Start(); |
216 } | 217 } |
217 | 218 |
218 void VideoScheduler::StopOnCaptureThread() { | 219 void VideoScheduler::StopOnCaptureThread() { |
219 DCHECK(capture_task_runner_->BelongsToCurrentThread()); | 220 DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
220 | 221 |
221 // This doesn't deleted already captured frames, so encoder can keep using the | 222 // This doesn't deleted already captured frames, so encoder can keep using the |
222 // frames that were captured previously. | 223 // frames that were captured previously. |
223 capturer_.reset(); | 224 capturer_.reset(); |
224 | 225 |
(...skipping 17 matching lines...) Expand all Loading... |
242 capture_scheduler_->OnFrameEncoded(encode_time); | 243 capture_scheduler_->OnFrameEncoded(encode_time); |
243 } | 244 } |
244 | 245 |
245 void VideoScheduler::ProcessFrameSentOnCaptureThread() { | 246 void VideoScheduler::ProcessFrameSentOnCaptureThread() { |
246 DCHECK(capture_task_runner_->BelongsToCurrentThread()); | 247 DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
247 | 248 |
248 if (capture_scheduler_) | 249 if (capture_scheduler_) |
249 capture_scheduler_->OnFrameSent(); | 250 capture_scheduler_->OnFrameSent(); |
250 } | 251 } |
251 | 252 |
| 253 void VideoScheduler::ProcessFrameAckOnCaptureThread() { |
| 254 DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
| 255 |
| 256 if (capture_scheduler_) |
| 257 capture_scheduler_->OnFrameAck(); |
| 258 } |
| 259 |
252 // Network thread -------------------------------------------------------------- | 260 // Network thread -------------------------------------------------------------- |
253 | 261 |
254 void VideoScheduler::SendVideoPacket(scoped_ptr<VideoPacket> packet) { | 262 void VideoScheduler::SendVideoPacket(scoped_ptr<VideoPacket> packet) { |
255 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 263 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
256 | 264 |
257 if (!video_stub_) | 265 if (!video_stub_) |
258 return; | 266 return; |
259 | 267 |
260 video_stub_->ProcessVideoPacket( | 268 video_stub_->ProcessVideoPacket( |
261 packet.Pass(), base::Bind(&VideoScheduler::OnVideoPacketSent, this)); | 269 packet.Pass(), base::Bind(&VideoScheduler::OnVideoPacketProgress, this)); |
262 } | 270 } |
263 | 271 |
264 void VideoScheduler::OnVideoPacketSent() { | 272 void VideoScheduler::OnVideoPacketProgress( |
| 273 protocol::VideoStub::PacketProgress progress) { |
265 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 274 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
266 | 275 |
267 if (!video_stub_) | 276 if (!video_stub_) |
268 return; | 277 return; |
269 | 278 |
270 keep_alive_timer_->Reset(); | 279 switch (progress) { |
| 280 case protocol::VideoStub::PacketProgress::SENT: |
| 281 keep_alive_timer_->Reset(); |
| 282 capture_task_runner_->PostTask( |
| 283 FROM_HERE, |
| 284 base::Bind(&VideoScheduler::ProcessFrameSentOnCaptureThread, this)); |
| 285 break; |
271 | 286 |
272 capture_task_runner_->PostTask( | 287 case protocol::VideoStub::PacketProgress::DONE: |
273 FROM_HERE, | 288 if (video_stub_->SupportsAcks()) { |
274 base::Bind(&VideoScheduler::ProcessFrameSentOnCaptureThread, this)); | 289 capture_task_runner_->PostTask( |
| 290 FROM_HERE, |
| 291 base::Bind(&VideoScheduler::ProcessFrameAckOnCaptureThread, this)); |
| 292 } |
| 293 break; |
| 294 } |
275 } | 295 } |
276 | 296 |
277 void VideoScheduler::SendKeepAlivePacket() { | 297 void VideoScheduler::SendKeepAlivePacket() { |
278 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 298 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
279 | 299 |
280 if (!video_stub_) | 300 if (!video_stub_) |
281 return; | 301 return; |
282 | 302 |
283 video_stub_->ProcessVideoPacket( | 303 video_stub_->ProcessVideoPacket( |
284 make_scoped_ptr(new VideoPacket()), | 304 make_scoped_ptr(new VideoPacket()), |
285 base::Bind(&VideoScheduler::OnKeepAlivePacketSent, this)); | 305 base::Bind(&VideoScheduler::OnKeepAlivePacketProgress, this)); |
286 } | 306 } |
287 | 307 |
288 void VideoScheduler::OnKeepAlivePacketSent() { | 308 void VideoScheduler::OnKeepAlivePacketProgress( |
| 309 protocol::VideoStub::PacketProgress progress) { |
289 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 310 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
290 | 311 |
291 if (keep_alive_timer_) | 312 if (progress == protocol::VideoStub::PacketProgress::SENT && |
| 313 keep_alive_timer_) { |
292 keep_alive_timer_->Reset(); | 314 keep_alive_timer_->Reset(); |
| 315 } |
293 } | 316 } |
294 | 317 |
295 void VideoScheduler::SendCursorShape( | 318 void VideoScheduler::SendCursorShape( |
296 scoped_ptr<protocol::CursorShapeInfo> cursor_shape) { | 319 scoped_ptr<protocol::CursorShapeInfo> cursor_shape) { |
297 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 320 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
298 | 321 |
299 if (!cursor_stub_) | 322 if (!cursor_stub_) |
300 return; | 323 return; |
301 | 324 |
302 cursor_stub_->SetCursorShape(*cursor_shape); | 325 cursor_stub_->SetCursorShape(*cursor_shape); |
(...skipping 30 matching lines...) Expand all Loading... |
333 capture_task_runner_->PostTask( | 356 capture_task_runner_->PostTask( |
334 FROM_HERE, | 357 FROM_HERE, |
335 base::Bind(&VideoScheduler::ProcessFrameEncodedOnCaptureThread, this, | 358 base::Bind(&VideoScheduler::ProcessFrameEncodedOnCaptureThread, this, |
336 base::TimeDelta::FromMilliseconds(packet->encode_time_ms()))); | 359 base::TimeDelta::FromMilliseconds(packet->encode_time_ms()))); |
337 network_task_runner_->PostTask( | 360 network_task_runner_->PostTask( |
338 FROM_HERE, base::Bind(&VideoScheduler::SendVideoPacket, this, | 361 FROM_HERE, base::Bind(&VideoScheduler::SendVideoPacket, this, |
339 base::Passed(&packet))); | 362 base::Passed(&packet))); |
340 } | 363 } |
341 | 364 |
342 } // namespace remoting | 365 } // namespace remoting |
OLD | NEW |