Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(810)

Side by Side Diff: remoting/host/screen_recorder.cc

Issue 7633009: Use MessageLoopProxy for network message loop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/screen_recorder.h ('k') | remoting/host/screen_recorder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop_proxy.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "base/task.h" 13 #include "base/task.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 #include "remoting/base/capture_data.h" 15 #include "remoting/base/capture_data.h"
15 #include "remoting/base/tracer.h" 16 #include "remoting/base/tracer.h"
16 #include "remoting/proto/control.pb.h" 17 #include "remoting/proto/control.pb.h"
17 #include "remoting/proto/video.pb.h" 18 #include "remoting/proto/video.pb.h"
18 #include "remoting/protocol/client_stub.h" 19 #include "remoting/protocol/client_stub.h"
19 #include "remoting/protocol/connection_to_client.h" 20 #include "remoting/protocol/connection_to_client.h"
20 #include "remoting/protocol/message_decoder.h" 21 #include "remoting/protocol/message_decoder.h"
21 #include "remoting/protocol/util.h" 22 #include "remoting/protocol/util.h"
22 23
23 using remoting::protocol::ConnectionToClient; 24 using remoting::protocol::ConnectionToClient;
24 25
25 namespace remoting { 26 namespace remoting {
26 27
27 // By default we capture 20 times a second. This number is obtained by 28 // By default we capture 20 times a second. This number is obtained by
28 // experiment to provide good latency. 29 // experiment to provide good latency.
29 static const double kDefaultCaptureRate = 20.0; 30 static const double kDefaultCaptureRate = 20.0;
30 31
31 // Maximum number of frames that can be processed similtaneously. 32 // Maximum number of frames that can be processed similtaneously.
32 // TODO(sergeyu): Should this be set to 1? Or should we change 33 // TODO(sergeyu): Should this be set to 1? Or should we change
33 // dynamically depending on how fast network and CPU are? Experement 34 // dynamically depending on how fast network and CPU are? Experement
34 // with it. 35 // with it.
35 static const int kMaxRecordings = 2; 36 static const int kMaxRecordings = 2;
36 37
37 ScreenRecorder::ScreenRecorder( 38 ScreenRecorder::ScreenRecorder(
38 MessageLoop* capture_loop, 39 MessageLoop* capture_loop,
39 MessageLoop* encode_loop, 40 MessageLoop* encode_loop,
40 MessageLoop* network_loop, 41 base::MessageLoopProxy* network_loop,
41 Capturer* capturer, 42 Capturer* capturer,
42 Encoder* encoder) 43 Encoder* encoder)
43 : capture_loop_(capture_loop), 44 : capture_loop_(capture_loop),
44 encode_loop_(encode_loop), 45 encode_loop_(encode_loop),
45 network_loop_(network_loop), 46 network_loop_(network_loop),
46 capturer_(capturer), 47 capturer_(capturer),
47 encoder_(encoder), 48 encoder_(encoder),
48 is_recording_(false), 49 is_recording_(false),
49 network_stopped_(false), 50 network_stopped_(false),
50 encoder_stopped_(false), 51 encoder_stopped_(false),
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 268
268 void ScreenRecorder::DoInvalidateFullScreen() { 269 void ScreenRecorder::DoInvalidateFullScreen() {
269 DCHECK_EQ(capture_loop_, MessageLoop::current()); 270 DCHECK_EQ(capture_loop_, MessageLoop::current());
270 271
271 capturer_->InvalidateFullScreen(); 272 capturer_->InvalidateFullScreen();
272 } 273 }
273 274
274 // Network thread -------------------------------------------------------------- 275 // Network thread --------------------------------------------------------------
275 276
276 void ScreenRecorder::DoSendVideoPacket(VideoPacket* packet) { 277 void ScreenRecorder::DoSendVideoPacket(VideoPacket* packet) {
277 DCHECK_EQ(network_loop_, MessageLoop::current()); 278 DCHECK(network_loop_->BelongsToCurrentThread());
278 279
279 TraceContext::tracer()->PrintString("DoSendVideoPacket"); 280 TraceContext::tracer()->PrintString("DoSendVideoPacket");
280 281
281 bool last = (packet->flags() & VideoPacket::LAST_PARTITION) != 0; 282 bool last = (packet->flags() & VideoPacket::LAST_PARTITION) != 0;
282 283
283 if (network_stopped_ || connections_.empty()) { 284 if (network_stopped_ || connections_.empty()) {
284 delete packet; 285 delete packet;
285 return; 286 return;
286 } 287 }
287 288
(...skipping 23 matching lines...) Expand all
311 312
312 if (network_stopped_) 313 if (network_stopped_)
313 return; 314 return;
314 315
315 capture_loop_->PostTask( 316 capture_loop_->PostTask(
316 FROM_HERE, NewTracedMethod(this, &ScreenRecorder::DoFinishOneRecording)); 317 FROM_HERE, NewTracedMethod(this, &ScreenRecorder::DoFinishOneRecording));
317 } 318 }
318 319
319 void ScreenRecorder::DoAddConnection( 320 void ScreenRecorder::DoAddConnection(
320 scoped_refptr<ConnectionToClient> connection) { 321 scoped_refptr<ConnectionToClient> connection) {
321 DCHECK_EQ(network_loop_, MessageLoop::current()); 322 DCHECK(network_loop_->BelongsToCurrentThread());
322 323
323 connections_.push_back(connection); 324 connections_.push_back(connection);
324 } 325 }
325 326
326 void ScreenRecorder::DoRemoveClient( 327 void ScreenRecorder::DoRemoveClient(
327 scoped_refptr<ConnectionToClient> connection) { 328 scoped_refptr<ConnectionToClient> connection) {
328 DCHECK_EQ(network_loop_, MessageLoop::current()); 329 DCHECK(network_loop_->BelongsToCurrentThread());
329 330
330 ConnectionToClientList::iterator it = 331 ConnectionToClientList::iterator it =
331 std::find(connections_.begin(), connections_.end(), connection); 332 std::find(connections_.begin(), connections_.end(), connection);
332 if (it != connections_.end()) { 333 if (it != connections_.end()) {
333 connections_.erase(it); 334 connections_.erase(it);
334 } 335 }
335 } 336 }
336 337
337 void ScreenRecorder::DoRemoveAllClients() { 338 void ScreenRecorder::DoRemoveAllClients() {
338 DCHECK_EQ(network_loop_, MessageLoop::current()); 339 DCHECK(network_loop_->BelongsToCurrentThread());
339 340
340 // Clear the list of connections. 341 // Clear the list of connections.
341 connections_.clear(); 342 connections_.clear();
342 } 343 }
343 344
344 void ScreenRecorder::DoStopOnNetworkThread(Task* done_task) { 345 void ScreenRecorder::DoStopOnNetworkThread(Task* done_task) {
345 DCHECK_EQ(network_loop_, MessageLoop::current()); 346 DCHECK(network_loop_->BelongsToCurrentThread());
346 347
347 // There could be tasks on the network thread when this method is being 348 // There could be tasks on the network thread when this method is being
348 // executed. By setting the flag we'll not post anymore tasks from network 349 // executed. By setting the flag we'll not post anymore tasks from network
349 // thread. 350 // thread.
350 // 351 //
351 // After that a task is posted on encode thread to continue the stop 352 // After that a task is posted on encode thread to continue the stop
352 // sequence. 353 // sequence.
353 network_stopped_ = true; 354 network_stopped_ = true;
354 355
355 encode_loop_->PostTask( 356 encode_loop_->PostTask(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 (base::Time::Now() - encode_start_time_).InMilliseconds()); 410 (base::Time::Now() - encode_start_time_).InMilliseconds());
410 packet->set_encode_time_ms(encode_time); 411 packet->set_encode_time_ms(encode_time);
411 } 412 }
412 413
413 network_loop_->PostTask( 414 network_loop_->PostTask(
414 FROM_HERE, 415 FROM_HERE,
415 NewTracedMethod(this, &ScreenRecorder::DoSendVideoPacket, packet)); 416 NewTracedMethod(this, &ScreenRecorder::DoSendVideoPacket, packet));
416 } 417 }
417 418
418 } // namespace remoting 419 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/screen_recorder.h ('k') | remoting/host/screen_recorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698