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

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

Issue 10382184: [Chromoting] Initial plumbing for cursor shape. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Call SetCursor only for native format images Created 8 years, 7 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) 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"
22 #include "remoting/protocol/cursor_shape_stub.h"
21 #include "remoting/protocol/connection_to_client.h" 23 #include "remoting/protocol/connection_to_client.h"
22 #include "remoting/protocol/message_decoder.h" 24 #include "remoting/protocol/message_decoder.h"
23 #include "remoting/protocol/util.h" 25 #include "remoting/protocol/util.h"
24 26
25 using remoting::protocol::ConnectionToClient; 27 using remoting::protocol::ConnectionToClient;
26 28
27 namespace remoting { 29 namespace remoting {
28 30
29 // Maximum number of frames that can be processed similtaneously. 31 // Maximum number of frames that can be processed similtaneously.
30 // TODO(hclam): Move this value to CaptureScheduler. 32 // TODO(hclam): Move this value to CaptureScheduler.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // Capturer thread ------------------------------------------------------------- 137 // Capturer thread -------------------------------------------------------------
136 138
137 void ScreenRecorder::DoStart() { 139 void ScreenRecorder::DoStart() {
138 DCHECK_EQ(capture_loop_, MessageLoop::current()); 140 DCHECK_EQ(capture_loop_, MessageLoop::current());
139 141
140 if (is_recording()) { 142 if (is_recording()) {
141 NOTREACHED() << "Record session already started."; 143 NOTREACHED() << "Record session already started.";
142 return; 144 return;
143 } 145 }
144 146
145 capturer()->Start(); 147 capturer()->Start(
148 base::Bind(&ScreenRecorder::CursorShapeChangedCallback, this));
149
146 capture_timer_.reset(new base::OneShotTimer<ScreenRecorder>()); 150 capture_timer_.reset(new base::OneShotTimer<ScreenRecorder>());
147 151
148 // Capture first frame immedately. 152 // Capture first frame immedately.
149 DoCapture(); 153 DoCapture();
150 } 154 }
151 155
152 void ScreenRecorder::StartCaptureTimer() { 156 void ScreenRecorder::StartCaptureTimer() {
153 DCHECK_EQ(capture_loop_, MessageLoop::current()); 157 DCHECK_EQ(capture_loop_, MessageLoop::current());
154 158
155 capture_timer_->Start(FROM_HERE, 159 capture_timer_->Start(FROM_HERE,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // system doesn't allow this. Reading from the member variable is 211 // system doesn't allow this. Reading from the member variable is
208 // accurate as long as capture is synchronous as the following statement 212 // accurate as long as capture is synchronous as the following statement
209 // will obtain the most recent sequence number received. 213 // will obtain the most recent sequence number received.
210 capture_data->set_client_sequence_number(sequence_number_); 214 capture_data->set_client_sequence_number(sequence_number_);
211 } 215 }
212 216
213 encode_loop_->PostTask( 217 encode_loop_->PostTask(
214 FROM_HERE, base::Bind(&ScreenRecorder::DoEncode, this, capture_data)); 218 FROM_HERE, base::Bind(&ScreenRecorder::DoEncode, this, capture_data));
215 } 219 }
216 220
221 void ScreenRecorder::CursorShapeChangedCallback(
222 scoped_ptr<protocol::CursorShapeInfo> cursor_data) {
223 DCHECK_EQ(capture_loop_, MessageLoop::current());
224
225 if (!is_recording())
226 return;
227
228 encode_loop_->PostTask(
229 FROM_HERE, base::Bind(&ScreenRecorder::DoEncodeCursorShape,
Wez 2012/05/29 18:02:54 You can skip directly to DoSendCursorShape here ..
garykac 2012/05/30 23:22:45 Done.
230 this, base::Passed(cursor_data.Pass())));
231 }
232
217 void ScreenRecorder::DoFinishOneRecording() { 233 void ScreenRecorder::DoFinishOneRecording() {
218 DCHECK_EQ(capture_loop_, MessageLoop::current()); 234 DCHECK_EQ(capture_loop_, MessageLoop::current());
219 235
220 if (!is_recording()) 236 if (!is_recording())
221 return; 237 return;
222 238
223 // Decrement the number of recording in process since we have completed 239 // Decrement the number of recording in process since we have completed
224 // one cycle. 240 // one cycle.
225 --recordings_; 241 --recordings_;
226 DCHECK_GE(recordings_, 0); 242 DCHECK_GE(recordings_, 0);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 // 290 //
275 // After that a task is posted on encode thread to continue the stop 291 // After that a task is posted on encode thread to continue the stop
276 // sequence. 292 // sequence.
277 network_stopped_ = true; 293 network_stopped_ = true;
278 294
279 encode_loop_->PostTask( 295 encode_loop_->PostTask(
280 FROM_HERE, base::Bind(&ScreenRecorder::DoStopOnEncodeThread, 296 FROM_HERE, base::Bind(&ScreenRecorder::DoStopOnEncodeThread,
281 this, done_task)); 297 this, done_task));
282 } 298 }
283 299
300 void ScreenRecorder::DoSendCursorShape(
301 scoped_ptr<protocol::CursorShapeInfo> cursor_shape) {
302 DCHECK(network_loop_->BelongsToCurrentThread());
303
304 if (network_stopped_ || connections_.empty())
305 return;
306
307 // TODO(sergeyu): Currently we send the data only to the first
308 // connection. Send it to all connections if necessary.
309 connections_.front()->cursor_shape_stub()->SetCursorShape(*cursor_shape);
310 }
311
284 // Encoder thread -------------------------------------------------------------- 312 // Encoder thread --------------------------------------------------------------
285 313
286 void ScreenRecorder::DoEncode( 314 void ScreenRecorder::DoEncode(
287 scoped_refptr<CaptureData> capture_data) { 315 scoped_refptr<CaptureData> capture_data) {
288 DCHECK_EQ(encode_loop_, MessageLoop::current()); 316 DCHECK_EQ(encode_loop_, MessageLoop::current());
289 317
290 if (encoder_stopped_) 318 if (encoder_stopped_)
291 return; 319 return;
292 320
293 // Early out if there's nothing to encode. 321 // Early out if there's nothing to encode.
294 if (!capture_data || capture_data->dirty_region().isEmpty()) { 322 if (!capture_data || capture_data->dirty_region().isEmpty()) {
295 // Send an empty video packet to keep network active. 323 // Send an empty video packet to keep network active.
296 scoped_ptr<VideoPacket> packet(new VideoPacket()); 324 scoped_ptr<VideoPacket> packet(new VideoPacket());
297 packet->set_flags(VideoPacket::LAST_PARTITION); 325 packet->set_flags(VideoPacket::LAST_PARTITION);
298 network_loop_->PostTask( 326 network_loop_->PostTask(
299 FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, 327 FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket,
300 this, base::Passed(packet.Pass()))); 328 this, base::Passed(packet.Pass())));
301 return; 329 return;
302 } 330 }
303 331
304 encode_start_time_ = base::Time::Now(); 332 encode_start_time_ = base::Time::Now();
305 encoder()->Encode( 333 encoder()->Encode(
306 capture_data, false, 334 capture_data, false,
307 base::Bind(&ScreenRecorder::EncodedDataAvailableCallback, this)); 335 base::Bind(&ScreenRecorder::EncodedDataAvailableCallback, this));
308 } 336 }
309 337
338 void ScreenRecorder::DoEncodeCursorShape(
Wez 2012/05/29 18:02:54 ... and remove this method entirely. :)
garykac 2012/05/30 23:22:45 Done.
339 scoped_ptr<protocol::CursorShapeInfo> cursor) {
340 DCHECK_EQ(encode_loop_, MessageLoop::current());
341
342 network_loop_->PostTask(
343 FROM_HERE, base::Bind(&ScreenRecorder::DoSendCursorShape, this,
344 base::Passed(cursor.Pass())));
345 }
346
310 void ScreenRecorder::DoStopOnEncodeThread(const base::Closure& done_task) { 347 void ScreenRecorder::DoStopOnEncodeThread(const base::Closure& done_task) {
311 DCHECK_EQ(encode_loop_, MessageLoop::current()); 348 DCHECK_EQ(encode_loop_, MessageLoop::current());
312 349
313 encoder_stopped_ = true; 350 encoder_stopped_ = true;
314 351
315 // When this method is being executed there are no more tasks on encode thread 352 // 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 353 // for this object. We can then post a task to capture thread to finish the
317 // stop sequence. 354 // stop sequence.
318 capture_loop_->PostTask(FROM_HERE, done_task); 355 capture_loop_->PostTask(FROM_HERE, done_task);
319 } 356 }
(...skipping 13 matching lines...) Expand all
333 packet->set_encode_time_ms(encode_time_ms); 370 packet->set_encode_time_ms(encode_time_ms);
334 scheduler_.RecordEncodeTime(encode_time); 371 scheduler_.RecordEncodeTime(encode_time);
335 } 372 }
336 373
337 network_loop_->PostTask( 374 network_loop_->PostTask(
338 FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this, 375 FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this,
339 base::Passed(packet.Pass()))); 376 base::Passed(packet.Pass())));
340 } 377 }
341 378
342 } // namespace remoting 379 } // 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