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/screen_recorder.h" | 5 #include "remoting/host/screen_recorder.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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 233 } |
234 | 234 |
235 // Network thread -------------------------------------------------------------- | 235 // Network thread -------------------------------------------------------------- |
236 | 236 |
237 void ScreenRecorder::DoSendVideoPacket(scoped_ptr<VideoPacket> packet) { | 237 void ScreenRecorder::DoSendVideoPacket(scoped_ptr<VideoPacket> packet) { |
238 DCHECK(network_loop_->BelongsToCurrentThread()); | 238 DCHECK(network_loop_->BelongsToCurrentThread()); |
239 | 239 |
240 if (network_stopped_ || connections_.empty()) | 240 if (network_stopped_ || connections_.empty()) |
241 return; | 241 return; |
242 | 242 |
| 243 base::Closure callback; |
| 244 if ((packet->flags() & VideoPacket::LAST_PARTITION) != 0) |
| 245 callback = base::Bind(&ScreenRecorder::VideoFrameSentCallback, this); |
| 246 |
243 // TODO(sergeyu): Currently we send the data only to the first | 247 // TODO(sergeyu): Currently we send the data only to the first |
244 // connection. Send it to all connections if necessary. | 248 // connection. Send it to all connections if necessary. |
245 connections_.front()->video_stub()->ProcessVideoPacket( | 249 connections_.front()->video_stub()->ProcessVideoPacket( |
246 packet.get(), base::Bind( | 250 packet.Pass(), callback); |
247 &ScreenRecorder::VideoPacketSentCallback, this, | |
248 base::Passed(packet.Pass()))); | |
249 } | 251 } |
250 | 252 |
251 void ScreenRecorder::VideoPacketSentCallback(scoped_ptr<VideoPacket> packet) { | 253 void ScreenRecorder::VideoFrameSentCallback() { |
| 254 DCHECK(network_loop_->BelongsToCurrentThread()); |
| 255 |
252 if (network_stopped_) | 256 if (network_stopped_) |
253 return; | 257 return; |
254 | 258 |
255 if ((packet->flags() & VideoPacket::LAST_PARTITION) != 0) { | 259 capture_loop_->PostTask( |
256 // Post DoFinishOneRecording() if that was the last packet for the | 260 FROM_HERE, base::Bind(&ScreenRecorder::DoFinishOneRecording, this)); |
257 // frame. | |
258 capture_loop_->PostTask( | |
259 FROM_HERE, base::Bind(&ScreenRecorder::DoFinishOneRecording, this)); | |
260 } | |
261 } | 261 } |
262 | 262 |
263 void ScreenRecorder::DoStopOnNetworkThread(const base::Closure& done_task) { | 263 void ScreenRecorder::DoStopOnNetworkThread(const base::Closure& done_task) { |
264 DCHECK(network_loop_->BelongsToCurrentThread()); | 264 DCHECK(network_loop_->BelongsToCurrentThread()); |
265 | 265 |
266 // There could be tasks on the network thread when this method is being | 266 // There could be tasks on the network thread when this method is being |
267 // executed. By setting the flag we'll not post anymore tasks from network | 267 // executed. By setting the flag we'll not post anymore tasks from network |
268 // thread. | 268 // thread. |
269 // | 269 // |
270 // After that a task is posted on encode thread to continue the stop | 270 // After that a task is posted on encode thread to continue the stop |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 packet->set_encode_time_ms(encode_time_ms); | 325 packet->set_encode_time_ms(encode_time_ms); |
326 scheduler_.RecordEncodeTime(encode_time); | 326 scheduler_.RecordEncodeTime(encode_time); |
327 } | 327 } |
328 | 328 |
329 network_loop_->PostTask( | 329 network_loop_->PostTask( |
330 FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this, | 330 FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this, |
331 base::Passed(packet.Pass()))); | 331 base::Passed(packet.Pass()))); |
332 } | 332 } |
333 | 333 |
334 } // namespace remoting | 334 } // namespace remoting |
OLD | NEW |