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" |
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/base/capture_data.h" | 17 #include "remoting/base/capture_data.h" |
18 #include "remoting/proto/control.pb.h" | 18 #include "remoting/proto/control.pb.h" |
| 19 #include "remoting/proto/internal.pb.h" |
19 #include "remoting/proto/video.pb.h" | 20 #include "remoting/proto/video.pb.h" |
20 #include "remoting/protocol/client_stub.h" | 21 #include "remoting/protocol/client_stub.h" |
21 #include "remoting/protocol/connection_to_client.h" | 22 #include "remoting/protocol/connection_to_client.h" |
22 #include "remoting/protocol/message_decoder.h" | 23 #include "remoting/protocol/message_decoder.h" |
23 #include "remoting/protocol/util.h" | 24 #include "remoting/protocol/util.h" |
24 | 25 |
25 using remoting::protocol::ConnectionToClient; | 26 using remoting::protocol::ConnectionToClient; |
26 | 27 |
27 namespace remoting { | 28 namespace remoting { |
28 | 29 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // Capturer thread ------------------------------------------------------------- | 136 // Capturer thread ------------------------------------------------------------- |
136 | 137 |
137 void ScreenRecorder::DoStart() { | 138 void ScreenRecorder::DoStart() { |
138 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 139 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
139 | 140 |
140 if (is_recording()) { | 141 if (is_recording()) { |
141 NOTREACHED() << "Record session already started."; | 142 NOTREACHED() << "Record session already started."; |
142 return; | 143 return; |
143 } | 144 } |
144 | 145 |
145 capturer()->Start(); | 146 capturer()->Start( |
| 147 base::Bind(&ScreenRecorder::CursorShapeChangedCallback, this)); |
| 148 |
146 capture_timer_.reset(new base::OneShotTimer<ScreenRecorder>()); | 149 capture_timer_.reset(new base::OneShotTimer<ScreenRecorder>()); |
147 | 150 |
148 // Capture first frame immedately. | 151 // Capture first frame immedately. |
149 DoCapture(); | 152 DoCapture(); |
150 } | 153 } |
151 | 154 |
152 void ScreenRecorder::StartCaptureTimer() { | 155 void ScreenRecorder::StartCaptureTimer() { |
153 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 156 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
154 | 157 |
155 capture_timer_->Start(FROM_HERE, | 158 capture_timer_->Start(FROM_HERE, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // system doesn't allow this. Reading from the member variable is | 210 // system doesn't allow this. Reading from the member variable is |
208 // accurate as long as capture is synchronous as the following statement | 211 // accurate as long as capture is synchronous as the following statement |
209 // will obtain the most recent sequence number received. | 212 // will obtain the most recent sequence number received. |
210 capture_data->set_client_sequence_number(sequence_number_); | 213 capture_data->set_client_sequence_number(sequence_number_); |
211 } | 214 } |
212 | 215 |
213 encode_loop_->PostTask( | 216 encode_loop_->PostTask( |
214 FROM_HERE, base::Bind(&ScreenRecorder::DoEncode, this, capture_data)); | 217 FROM_HERE, base::Bind(&ScreenRecorder::DoEncode, this, capture_data)); |
215 } | 218 } |
216 | 219 |
| 220 void ScreenRecorder::CursorShapeChangedCallback( |
| 221 scoped_ptr<protocol::CursorShapeInfo> cursor_shape) { |
| 222 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
| 223 |
| 224 if (!is_recording()) |
| 225 return; |
| 226 |
| 227 network_loop_->PostTask( |
| 228 FROM_HERE, base::Bind(&ScreenRecorder::DoSendCursorShape, this, |
| 229 base::Passed(cursor_shape.Pass()))); |
| 230 } |
| 231 |
217 void ScreenRecorder::DoFinishOneRecording() { | 232 void ScreenRecorder::DoFinishOneRecording() { |
218 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 233 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
219 | 234 |
220 if (!is_recording()) | 235 if (!is_recording()) |
221 return; | 236 return; |
222 | 237 |
223 // Decrement the number of recording in process since we have completed | 238 // Decrement the number of recording in process since we have completed |
224 // one cycle. | 239 // one cycle. |
225 --recordings_; | 240 --recordings_; |
226 DCHECK_GE(recordings_, 0); | 241 DCHECK_GE(recordings_, 0); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 // | 289 // |
275 // After that a task is posted on encode thread to continue the stop | 290 // After that a task is posted on encode thread to continue the stop |
276 // sequence. | 291 // sequence. |
277 network_stopped_ = true; | 292 network_stopped_ = true; |
278 | 293 |
279 encode_loop_->PostTask( | 294 encode_loop_->PostTask( |
280 FROM_HERE, base::Bind(&ScreenRecorder::DoStopOnEncodeThread, | 295 FROM_HERE, base::Bind(&ScreenRecorder::DoStopOnEncodeThread, |
281 this, done_task)); | 296 this, done_task)); |
282 } | 297 } |
283 | 298 |
| 299 void ScreenRecorder::DoSendCursorShape( |
| 300 scoped_ptr<protocol::CursorShapeInfo> cursor_shape) { |
| 301 DCHECK(network_loop_->BelongsToCurrentThread()); |
| 302 |
| 303 if (network_stopped_ || connections_.empty()) |
| 304 return; |
| 305 |
| 306 // TODO(sergeyu): Currently we send the data only to the first |
| 307 // connection. Send it to all connections if necessary. |
| 308 connections_.front()->client_stub()->SetCursorShape(*cursor_shape); |
| 309 } |
| 310 |
284 // Encoder thread -------------------------------------------------------------- | 311 // Encoder thread -------------------------------------------------------------- |
285 | 312 |
286 void ScreenRecorder::DoEncode( | 313 void ScreenRecorder::DoEncode( |
287 scoped_refptr<CaptureData> capture_data) { | 314 scoped_refptr<CaptureData> capture_data) { |
288 DCHECK_EQ(encode_loop_, MessageLoop::current()); | 315 DCHECK_EQ(encode_loop_, MessageLoop::current()); |
289 | 316 |
290 if (encoder_stopped_) | 317 if (encoder_stopped_) |
291 return; | 318 return; |
292 | 319 |
293 // Early out if there's nothing to encode. | 320 // Early out if there's nothing to encode. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 packet->set_encode_time_ms(encode_time_ms); | 360 packet->set_encode_time_ms(encode_time_ms); |
334 scheduler_.RecordEncodeTime(encode_time); | 361 scheduler_.RecordEncodeTime(encode_time); |
335 } | 362 } |
336 | 363 |
337 network_loop_->PostTask( | 364 network_loop_->PostTask( |
338 FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this, | 365 FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this, |
339 base::Passed(packet.Pass()))); | 366 base::Passed(packet.Pass()))); |
340 } | 367 } |
341 | 368 |
342 } // namespace remoting | 369 } // namespace remoting |
OLD | NEW |