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 VideoPacket* packet_ptr = packet.get(); | 243 base::Closure callback; |
| 244 if ((packet->flags() & VideoPacket::LAST_PARTITION) != 0) |
| 245 callback = base::Bind(&ScreenRecorder::VideoFrameSentCallback, this); |
244 | 246 |
245 // TODO(sergeyu): Currently we send the data only to the first | 247 // TODO(sergeyu): Currently we send the data only to the first |
246 // connection. Send it to all connections if necessary. | 248 // connection. Send it to all connections if necessary. |
247 connections_.front()->video_stub()->ProcessVideoPacket( | 249 connections_.front()->video_stub()->ProcessVideoPacket( |
248 packet_ptr, base::Bind( | 250 packet.Pass(), callback); |
249 &ScreenRecorder::VideoPacketSentCallback, this, | |
250 base::Passed(packet.Pass()))); | |
251 } | 251 } |
252 | 252 |
253 void ScreenRecorder::VideoPacketSentCallback(scoped_ptr<VideoPacket> packet) { | 253 void ScreenRecorder::VideoFrameSentCallback() { |
| 254 DCHECK(network_loop_->BelongsToCurrentThread()); |
| 255 |
254 if (network_stopped_) | 256 if (network_stopped_) |
255 return; | 257 return; |
256 | 258 |
257 if ((packet->flags() & VideoPacket::LAST_PARTITION) != 0) { | 259 capture_loop_->PostTask( |
258 // Post DoFinishOneRecording() if that was the last packet for the | 260 FROM_HERE, base::Bind(&ScreenRecorder::DoFinishOneRecording, this)); |
259 // frame. | |
260 capture_loop_->PostTask( | |
261 FROM_HERE, base::Bind(&ScreenRecorder::DoFinishOneRecording, this)); | |
262 } | |
263 } | 261 } |
264 | 262 |
265 void ScreenRecorder::DoStopOnNetworkThread(const base::Closure& done_task) { | 263 void ScreenRecorder::DoStopOnNetworkThread(const base::Closure& done_task) { |
266 DCHECK(network_loop_->BelongsToCurrentThread()); | 264 DCHECK(network_loop_->BelongsToCurrentThread()); |
267 | 265 |
268 // 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 |
269 // 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 |
270 // thread. | 268 // thread. |
271 // | 269 // |
272 // 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... |
327 packet->set_encode_time_ms(encode_time_ms); | 325 packet->set_encode_time_ms(encode_time_ms); |
328 scheduler_.RecordEncodeTime(encode_time); | 326 scheduler_.RecordEncodeTime(encode_time); |
329 } | 327 } |
330 | 328 |
331 network_loop_->PostTask( | 329 network_loop_->PostTask( |
332 FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this, | 330 FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this, |
333 base::Passed(packet.Pass()))); | 331 base::Passed(packet.Pass()))); |
334 } | 332 } |
335 | 333 |
336 } // namespace remoting | 334 } // namespace remoting |
OLD | NEW |