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

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

Issue 12047101: Move screen capturers from remoting/capturer to media/video/capturer/screen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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/video_scheduler.h ('k') | remoting/host/video_scheduler_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) 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop_proxy.h" 13 #include "base/message_loop_proxy.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/sys_info.h" 15 #include "base/sys_info.h"
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "remoting/capturer/capture_data.h" 17 #include "media/video/capture/screen/mouse_cursor_shape.h"
18 #include "remoting/capturer/mouse_cursor_shape.h" 18 #include "media/video/capture/screen/screen_capture_data.h"
19 #include "remoting/capturer/video_frame_capturer.h" 19 #include "media/video/capture/screen/screen_capturer.h"
20 #include "remoting/proto/control.pb.h" 20 #include "remoting/proto/control.pb.h"
21 #include "remoting/proto/internal.pb.h" 21 #include "remoting/proto/internal.pb.h"
22 #include "remoting/proto/video.pb.h" 22 #include "remoting/proto/video.pb.h"
23 #include "remoting/protocol/cursor_shape_stub.h" 23 #include "remoting/protocol/cursor_shape_stub.h"
24 #include "remoting/protocol/message_decoder.h" 24 #include "remoting/protocol/message_decoder.h"
25 #include "remoting/protocol/video_stub.h" 25 #include "remoting/protocol/video_stub.h"
26 #include "remoting/protocol/util.h" 26 #include "remoting/protocol/util.h"
27 27
28 namespace remoting { 28 namespace remoting {
29 29
30 // Maximum number of frames that can be processed simultaneously. 30 // Maximum number of frames that can be processed simultaneously.
31 // TODO(hclam): Move this value to CaptureScheduler. 31 // TODO(hclam): Move this value to CaptureScheduler.
32 static const int kMaxPendingCaptures = 2; 32 static const int kMaxPendingCaptures = 2;
33 33
34 // static 34 // static
35 scoped_refptr<VideoScheduler> VideoScheduler::Create( 35 scoped_refptr<VideoScheduler> VideoScheduler::Create(
36 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, 36 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
37 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, 37 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner,
38 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, 38 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
39 scoped_ptr<VideoFrameCapturer> capturer, 39 scoped_ptr<media::ScreenCapturer> capturer,
40 scoped_ptr<VideoEncoder> encoder, 40 scoped_ptr<VideoEncoder> encoder,
41 protocol::CursorShapeStub* cursor_stub, 41 protocol::CursorShapeStub* cursor_stub,
42 protocol::VideoStub* video_stub) { 42 protocol::VideoStub* video_stub) {
43 DCHECK(network_task_runner->BelongsToCurrentThread()); 43 DCHECK(network_task_runner->BelongsToCurrentThread());
44 DCHECK(capturer); 44 DCHECK(capturer);
45 DCHECK(encoder); 45 DCHECK(encoder);
46 DCHECK(cursor_stub); 46 DCHECK(cursor_stub);
47 DCHECK(video_stub); 47 DCHECK(video_stub);
48 48
49 scoped_refptr<VideoScheduler> scheduler = new VideoScheduler( 49 scoped_refptr<VideoScheduler> scheduler = new VideoScheduler(
50 capture_task_runner, encode_task_runner, network_task_runner, 50 capture_task_runner, encode_task_runner, network_task_runner,
51 capturer.Pass(), encoder.Pass(), cursor_stub, video_stub); 51 capturer.Pass(), encoder.Pass(), cursor_stub, video_stub);
52 capture_task_runner->PostTask( 52 capture_task_runner->PostTask(
53 FROM_HERE, base::Bind(&VideoScheduler::StartOnCaptureThread, scheduler)); 53 FROM_HERE, base::Bind(&VideoScheduler::StartOnCaptureThread, scheduler));
54 54
55 return scheduler; 55 return scheduler;
56 } 56 }
57 57
58 // Public methods -------------------------------------------------------------- 58 // Public methods --------------------------------------------------------------
59 59
60 void VideoScheduler::OnCaptureCompleted( 60 void VideoScheduler::OnCaptureCompleted(
61 scoped_refptr<CaptureData> capture_data) { 61 scoped_refptr<media::ScreenCaptureData> capture_data) {
62 DCHECK(capture_task_runner_->BelongsToCurrentThread()); 62 DCHECK(capture_task_runner_->BelongsToCurrentThread());
63 63
64 if (capture_data) { 64 if (capture_data) {
65 scheduler_.RecordCaptureTime( 65 scheduler_.RecordCaptureTime(
66 base::TimeDelta::FromMilliseconds(capture_data->capture_time_ms())); 66 base::TimeDelta::FromMilliseconds(capture_data->capture_time_ms()));
67 67
68 // The best way to get this value is by binding the sequence number to 68 // The best way to get this value is by binding the sequence number to
69 // the callback when calling CaptureInvalidRects(). However the callback 69 // the callback when calling CaptureInvalidRects(). However the callback
70 // system doesn't allow this. Reading from the member variable is 70 // system doesn't allow this. Reading from the member variable is
71 // accurate as long as capture is synchronous as the following statement 71 // accurate as long as capture is synchronous as the following statement
72 // will obtain the most recent sequence number received. 72 // will obtain the most recent sequence number received.
73 capture_data->set_client_sequence_number(sequence_number_); 73 capture_data->set_client_sequence_number(sequence_number_);
74 } 74 }
75 75
76 encode_task_runner_->PostTask( 76 encode_task_runner_->PostTask(
77 FROM_HERE, base::Bind(&VideoScheduler::EncodeFrame, this, capture_data)); 77 FROM_HERE, base::Bind(&VideoScheduler::EncodeFrame, this, capture_data));
78 } 78 }
79 79
80 void VideoScheduler::OnCursorShapeChanged( 80 void VideoScheduler::OnCursorShapeChanged(
81 scoped_ptr<MouseCursorShape> cursor_shape) { 81 scoped_ptr<media::MouseCursorShape> cursor_shape) {
82 DCHECK(capture_task_runner_->BelongsToCurrentThread()); 82 DCHECK(capture_task_runner_->BelongsToCurrentThread());
83 83
84 scoped_ptr<protocol::CursorShapeInfo> cursor_proto( 84 scoped_ptr<protocol::CursorShapeInfo> cursor_proto(
85 new protocol::CursorShapeInfo()); 85 new protocol::CursorShapeInfo());
86 cursor_proto->set_width(cursor_shape->size.width()); 86 cursor_proto->set_width(cursor_shape->size.width());
87 cursor_proto->set_height(cursor_shape->size.height()); 87 cursor_proto->set_height(cursor_shape->size.height());
88 cursor_proto->set_hotspot_x(cursor_shape->hotspot.x()); 88 cursor_proto->set_hotspot_x(cursor_shape->hotspot.x());
89 cursor_proto->set_hotspot_y(cursor_shape->hotspot.y()); 89 cursor_proto->set_hotspot_y(cursor_shape->hotspot.y());
90 cursor_proto->set_data(cursor_shape->data); 90 cursor_proto->set_data(cursor_shape->data);
91 91
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 133
134 sequence_number_ = sequence_number; 134 sequence_number_ = sequence_number;
135 } 135 }
136 136
137 // Private methods ----------------------------------------------------------- 137 // Private methods -----------------------------------------------------------
138 138
139 VideoScheduler::VideoScheduler( 139 VideoScheduler::VideoScheduler(
140 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, 140 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner,
141 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, 141 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner,
142 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, 142 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
143 scoped_ptr<VideoFrameCapturer> capturer, 143 scoped_ptr<media::ScreenCapturer> capturer,
144 scoped_ptr<VideoEncoder> encoder, 144 scoped_ptr<VideoEncoder> encoder,
145 protocol::CursorShapeStub* cursor_stub, 145 protocol::CursorShapeStub* cursor_stub,
146 protocol::VideoStub* video_stub) 146 protocol::VideoStub* video_stub)
147 : capture_task_runner_(capture_task_runner), 147 : capture_task_runner_(capture_task_runner),
148 encode_task_runner_(encode_task_runner), 148 encode_task_runner_(encode_task_runner),
149 network_task_runner_(network_task_runner), 149 network_task_runner_(network_task_runner),
150 capturer_(capturer.Pass()), 150 capturer_(capturer.Pass()),
151 encoder_(encoder.Pass()), 151 encoder_(encoder.Pass()),
152 cursor_stub_(cursor_stub), 152 cursor_stub_(cursor_stub),
153 video_stub_(video_stub), 153 video_stub_(video_stub),
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 scoped_ptr<protocol::CursorShapeInfo> cursor_shape) { 272 scoped_ptr<protocol::CursorShapeInfo> cursor_shape) {
273 DCHECK(network_task_runner_->BelongsToCurrentThread()); 273 DCHECK(network_task_runner_->BelongsToCurrentThread());
274 274
275 if (!cursor_stub_) 275 if (!cursor_stub_)
276 return; 276 return;
277 277
278 cursor_stub_->SetCursorShape(*cursor_shape); 278 cursor_stub_->SetCursorShape(*cursor_shape);
279 } 279 }
280 280
281 void VideoScheduler::StopOnNetworkThread( 281 void VideoScheduler::StopOnNetworkThread(
282 scoped_ptr<VideoFrameCapturer> capturer) { 282 scoped_ptr<media::ScreenCapturer> capturer) {
283 DCHECK(network_task_runner_->BelongsToCurrentThread()); 283 DCHECK(network_task_runner_->BelongsToCurrentThread());
284 284
285 // This is posted by StopOnEncodeThread meaning that both capture and encode 285 // This is posted by StopOnEncodeThread meaning that both capture and encode
286 // threads are stopped now and it is safe to delete |capturer|. 286 // threads are stopped now and it is safe to delete |capturer|.
287 } 287 }
288 288
289 // Encoder thread -------------------------------------------------------------- 289 // Encoder thread --------------------------------------------------------------
290 290
291 void VideoScheduler::EncodeFrame( 291 void VideoScheduler::EncodeFrame(
292 scoped_refptr<CaptureData> capture_data) { 292 scoped_refptr<media::ScreenCaptureData> capture_data) {
293 DCHECK(encode_task_runner_->BelongsToCurrentThread()); 293 DCHECK(encode_task_runner_->BelongsToCurrentThread());
294 294
295 // If there is nothing to encode then send an empty keep-alive packet. 295 // If there is nothing to encode then send an empty keep-alive packet.
296 if (!capture_data || capture_data->dirty_region().isEmpty()) { 296 if (!capture_data || capture_data->dirty_region().isEmpty()) {
297 scoped_ptr<VideoPacket> packet(new VideoPacket()); 297 scoped_ptr<VideoPacket> packet(new VideoPacket());
298 packet->set_flags(VideoPacket::LAST_PARTITION); 298 packet->set_flags(VideoPacket::LAST_PARTITION);
299 network_task_runner_->PostTask( 299 network_task_runner_->PostTask(
300 FROM_HERE, base::Bind(&VideoScheduler::SendVideoPacket, this, 300 FROM_HERE, base::Bind(&VideoScheduler::SendVideoPacket, this,
301 base::Passed(&packet))); 301 base::Passed(&packet)));
302 return; 302 return;
(...skipping 13 matching lines...) Expand all
316 scheduler_.RecordEncodeTime( 316 scheduler_.RecordEncodeTime(
317 base::TimeDelta::FromMilliseconds(packet->encode_time_ms())); 317 base::TimeDelta::FromMilliseconds(packet->encode_time_ms()));
318 } 318 }
319 319
320 network_task_runner_->PostTask( 320 network_task_runner_->PostTask(
321 FROM_HERE, base::Bind(&VideoScheduler::SendVideoPacket, this, 321 FROM_HERE, base::Bind(&VideoScheduler::SendVideoPacket, this,
322 base::Passed(&packet))); 322 base::Passed(&packet)));
323 } 323 }
324 324
325 void VideoScheduler::StopOnEncodeThread( 325 void VideoScheduler::StopOnEncodeThread(
326 scoped_ptr<VideoFrameCapturer> capturer) { 326 scoped_ptr<media::ScreenCapturer> capturer) {
327 DCHECK(encode_task_runner_->BelongsToCurrentThread()); 327 DCHECK(encode_task_runner_->BelongsToCurrentThread());
328 328
329 // This is posted by StopOnCaptureThread, so we know that by the time we 329 // This is posted by StopOnCaptureThread, so we know that by the time we
330 // process it there are no more encode tasks queued. Pass |capturer_| for 330 // process it there are no more encode tasks queued. Pass |capturer_| for
331 // deletion on the thread that created it. 331 // deletion on the thread that created it.
332 network_task_runner_->PostTask( 332 network_task_runner_->PostTask(
333 FROM_HERE, base::Bind(&VideoScheduler::StopOnNetworkThread, this, 333 FROM_HERE, base::Bind(&VideoScheduler::StopOnNetworkThread, this,
334 base::Passed(&capturer))); 334 base::Passed(&capturer)));
335 } 335 }
336 336
337 } // namespace remoting 337 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/video_scheduler.h ('k') | remoting/host/video_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698