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" |
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 "remoting/capturer/capture_data.h" |
18 #include "remoting/capturer/mouse_cursor_shape.h" | 18 #include "remoting/capturer/mouse_cursor_shape.h" |
19 #include "remoting/capturer/video_frame_capturer.h" | 19 #include "remoting/capturer/video_frame_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/client_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 VideoFrameCapturer* capturer, | 39 VideoFrameCapturer* capturer, |
40 scoped_ptr<VideoEncoder> encoder, | 40 scoped_ptr<VideoEncoder> encoder, |
41 protocol::ClientStub* client_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(client_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, encoder.Pass(), client_stub, video_stub); | 51 capturer, 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<CaptureData> capture_data) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 | 137 |
138 // Private methods ----------------------------------------------------------- | 138 // Private methods ----------------------------------------------------------- |
139 | 139 |
140 VideoScheduler::VideoScheduler( | 140 VideoScheduler::VideoScheduler( |
141 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, | 141 scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, |
142 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, | 142 scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, |
143 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | 143 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
144 VideoFrameCapturer* capturer, | 144 VideoFrameCapturer* capturer, |
145 scoped_ptr<VideoEncoder> encoder, | 145 scoped_ptr<VideoEncoder> encoder, |
146 protocol::ClientStub* client_stub, | 146 protocol::CursorShapeStub* cursor_stub, |
147 protocol::VideoStub* video_stub) | 147 protocol::VideoStub* video_stub) |
148 : capture_task_runner_(capture_task_runner), | 148 : capture_task_runner_(capture_task_runner), |
149 encode_task_runner_(encode_task_runner), | 149 encode_task_runner_(encode_task_runner), |
150 network_task_runner_(network_task_runner), | 150 network_task_runner_(network_task_runner), |
151 capturer_(capturer), | 151 capturer_(capturer), |
152 encoder_(encoder.Pass()), | 152 encoder_(encoder.Pass()), |
153 cursor_stub_(client_stub), | 153 cursor_stub_(cursor_stub), |
154 video_stub_(video_stub), | 154 video_stub_(video_stub), |
155 pending_captures_(0), | 155 pending_captures_(0), |
156 did_skip_frame_(false), | 156 did_skip_frame_(false), |
157 is_paused_(false), | 157 is_paused_(false), |
158 sequence_number_(0) { | 158 sequence_number_(0) { |
159 } | 159 } |
160 | 160 |
161 VideoScheduler::~VideoScheduler() { | 161 VideoScheduler::~VideoScheduler() { |
162 } | 162 } |
163 | 163 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 | 316 |
317 void VideoScheduler::StopOnEncodeThread(const base::Closure& done_task) { | 317 void VideoScheduler::StopOnEncodeThread(const base::Closure& done_task) { |
318 DCHECK(encode_task_runner_->BelongsToCurrentThread()); | 318 DCHECK(encode_task_runner_->BelongsToCurrentThread()); |
319 | 319 |
320 // This is posted by StopOnCaptureThread, so we know that by the time we | 320 // This is posted by StopOnCaptureThread, so we know that by the time we |
321 // process it there are no more encode tasks queued. | 321 // process it there are no more encode tasks queued. |
322 network_task_runner_->PostTask(FROM_HERE, done_task); | 322 network_task_runner_->PostTask(FROM_HERE, done_task); |
323 } | 323 } |
324 | 324 |
325 } // namespace remoting | 325 } // namespace remoting |
OLD | NEW |