Chromium Code Reviews| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 // Capturer thread ------------------------------------------------------------- | 135 // Capturer thread ------------------------------------------------------------- |
| 136 | 136 |
| 137 void ScreenRecorder::DoStart() { | 137 void ScreenRecorder::DoStart() { |
| 138 DCHECK_EQ(capture_loop_, MessageLoop::current()); | 138 DCHECK_EQ(capture_loop_, MessageLoop::current()); |
| 139 | 139 |
| 140 if (is_recording()) { | 140 if (is_recording()) { |
| 141 NOTREACHED() << "Record session already started."; | 141 NOTREACHED() << "Record session already started."; |
| 142 return; | 142 return; |
| 143 } | 143 } |
| 144 | 144 |
| 145 capturer()->SetCursorShapeChangedCallback( | |
| 146 base::Bind(&ScreenRecorder::CursorShapeChangedCallback, this)); | |
|
Wez
2012/05/16 00:20:04
nit: Could we do this in the ScreenRecorder's cons
garykac
2012/05/22 00:42:03
Wrong thread.
| |
| 147 | |
| 145 capturer()->Start(); | 148 capturer()->Start(); |
| 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 |
| (...skipping 52 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_refptr<CursorShapeData> cursor_data) { | |
| 222 DCHECK_EQ(capture_loop_, MessageLoop::current()); | |
| 223 | |
| 224 if (!is_recording()) | |
| 225 return; | |
| 226 | |
| 227 encode_loop_->PostTask( | |
| 228 FROM_HERE, base::Bind(&ScreenRecorder::DoEncodeCursor, | |
| 229 this, cursor_data)); | |
| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 this, base::Passed(packet.Pass()))); | 315 this, base::Passed(packet.Pass()))); |
| 301 return; | 316 return; |
| 302 } | 317 } |
| 303 | 318 |
| 304 encode_start_time_ = base::Time::Now(); | 319 encode_start_time_ = base::Time::Now(); |
| 305 encoder()->Encode( | 320 encoder()->Encode( |
| 306 capture_data, false, | 321 capture_data, false, |
| 307 base::Bind(&ScreenRecorder::EncodedDataAvailableCallback, this)); | 322 base::Bind(&ScreenRecorder::EncodedDataAvailableCallback, this)); |
| 308 } | 323 } |
| 309 | 324 |
| 325 void ScreenRecorder::DoEncodeCursor(scoped_refptr<CursorShapeData> cursor) { | |
| 326 DCHECK_EQ(encode_loop_, MessageLoop::current()); | |
| 327 | |
| 328 scoped_ptr<VideoPacket> packet(new VideoPacket()); | |
| 329 packet->set_flags(VideoPacket::CURSOR_SHAPE); | |
| 330 | |
| 331 CursorShapeInfo* info = packet->mutable_cursor_shape(); | |
| 332 info->set_width(16); | |
| 333 info->set_height(16); | |
| 334 info->set_hotspot_x(0); | |
| 335 info->set_hotspot_y(0); | |
| 336 | |
| 337 packet->mutable_data()->resize(16 * 16 * 4); | |
| 338 uint8* data = const_cast<uint8*>(reinterpret_cast<const uint8*>( | |
| 339 packet->mutable_data()->data())); | |
| 340 // TODO(garykac) Copy real cursor data into packet. | |
|
Wez
2012/05/16 00:20:04
Copying the data should be implemented in this CL,
garykac
2012/05/22 00:42:03
Done.
| |
| 341 for (int y = 0; y < 16; y++) { | |
| 342 for (int x = 0; x < 16; x++) { | |
| 343 *data++ = 0xff; | |
| 344 *data++ = 0xff; | |
| 345 *data++ = 0xff; | |
| 346 *data++ = 0xff; | |
| 347 } | |
| 348 } | |
| 349 | |
| 350 network_loop_->PostTask( | |
| 351 FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this, | |
| 352 base::Passed(packet.Pass()))); | |
| 353 } | |
| 354 | |
| 310 void ScreenRecorder::DoStopOnEncodeThread(const base::Closure& done_task) { | 355 void ScreenRecorder::DoStopOnEncodeThread(const base::Closure& done_task) { |
| 311 DCHECK_EQ(encode_loop_, MessageLoop::current()); | 356 DCHECK_EQ(encode_loop_, MessageLoop::current()); |
| 312 | 357 |
| 313 encoder_stopped_ = true; | 358 encoder_stopped_ = true; |
| 314 | 359 |
| 315 // When this method is being executed there are no more tasks on encode thread | 360 // When this method is being executed there are no more tasks on encode thread |
| 316 // for this object. We can then post a task to capture thread to finish the | 361 // for this object. We can then post a task to capture thread to finish the |
| 317 // stop sequence. | 362 // stop sequence. |
| 318 capture_loop_->PostTask(FROM_HERE, done_task); | 363 capture_loop_->PostTask(FROM_HERE, done_task); |
| 319 } | 364 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 333 packet->set_encode_time_ms(encode_time_ms); | 378 packet->set_encode_time_ms(encode_time_ms); |
| 334 scheduler_.RecordEncodeTime(encode_time); | 379 scheduler_.RecordEncodeTime(encode_time); |
| 335 } | 380 } |
| 336 | 381 |
| 337 network_loop_->PostTask( | 382 network_loop_->PostTask( |
| 338 FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this, | 383 FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this, |
| 339 base::Passed(packet.Pass()))); | 384 base::Passed(packet.Pass()))); |
| 340 } | 385 } |
| 341 | 386 |
| 342 } // namespace remoting | 387 } // namespace remoting |
| OLD | NEW |