Index: remoting/host/video_scheduler.cc |
diff --git a/remoting/host/video_scheduler.cc b/remoting/host/video_scheduler.cc |
index e6cead840b6641272b2e6d9a932c53d3df1cb476..66cc67dd4db88a2d8866b73e7195a64919ffb038 100644 |
--- a/remoting/host/video_scheduler.cc |
+++ b/remoting/host/video_scheduler.cc |
@@ -15,7 +15,6 @@ |
#include "base/sys_info.h" |
#include "base/time.h" |
#include "media/video/capture/screen/mouse_cursor_shape.h" |
-#include "media/video/capture/screen/screen_capture_data.h" |
#include "media/video/capture/screen/screen_capturer.h" |
#include "remoting/proto/control.pb.h" |
#include "remoting/proto/internal.pb.h" |
@@ -24,6 +23,7 @@ |
#include "remoting/protocol/message_decoder.h" |
#include "remoting/protocol/video_stub.h" |
#include "remoting/protocol/util.h" |
+#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
namespace remoting { |
@@ -57,28 +57,23 @@ scoped_refptr<VideoScheduler> VideoScheduler::Create( |
// Public methods -------------------------------------------------------------- |
-void VideoScheduler::OnCaptureCompleted( |
- scoped_refptr<media::ScreenCaptureData> capture_data) { |
+webrtc::SharedMemory* VideoScheduler::CreateSharedMemory(size_t size) { |
+ return NULL; |
+} |
+ |
+void VideoScheduler::OnCaptureCompleted(webrtc::DesktopFrame* frame) { |
DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
- // Do nothing if the scheduler is being stopped. |
- if (!capturer_) |
- return; |
+ scoped_ptr<webrtc::DesktopFrame> owned_frame(frame); |
- if (capture_data) { |
+ if (frame) { |
scheduler_.RecordCaptureTime( |
- base::TimeDelta::FromMilliseconds(capture_data->capture_time_ms())); |
- |
- // The best way to get this value is by binding the sequence number to |
- // the callback when calling CaptureInvalidRects(). However the callback |
- // system doesn't allow this. Reading from the member variable is |
- // accurate as long as capture is synchronous as the following statement |
- // will obtain the most recent sequence number received. |
- capture_data->set_client_sequence_number(sequence_number_); |
+ base::TimeDelta::FromMilliseconds(frame->capture_time_ms())); |
} |
encode_task_runner_->PostTask( |
- FROM_HERE, base::Bind(&VideoScheduler::EncodeFrame, this, capture_data)); |
+ FROM_HERE, base::Bind(&VideoScheduler::EncodeFrame, this, |
+ base::Passed(&owned_frame), sequence_number_)); |
} |
void VideoScheduler::OnCursorShapeChanged( |
@@ -174,6 +169,7 @@ void VideoScheduler::StartOnCaptureThread() { |
DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
// Start the capturer and let it notify us if cursor shape changes. |
+ capturer_->SetMouseShapeObserver(this); |
capturer_->Start(this); |
capture_timer_.reset(new base::OneShotTimer<VideoScheduler>()); |
@@ -185,17 +181,10 @@ void VideoScheduler::StartOnCaptureThread() { |
void VideoScheduler::StopOnCaptureThread() { |
DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
+ capturer_.reset(); |
alexeypa (please no reviews)
2013/04/26 21:33:58
nit: Add a comment saying that the frames currentl
Sergey Ulanov
2013/05/07 22:25:50
Done.
|
+ |
// |capture_timer_| must be destroyed on the thread on which it is used. |
capture_timer_.reset(); |
- |
- // Schedule deletion of |capturer_| once the encode thread is no longer |
- // processing capture data. See http://crbug.com/163641. This also clears |
- // |capturer_| pointer to prevent pending tasks from using it. |
- // TODO(wez): Make it safe to tear down capturer while buffers remain, and |
- // remove this work-around. |
- encode_task_runner_->PostTask( |
- FROM_HERE, base::Bind(&VideoScheduler::StopOnEncodeThread, this, |
- base::Passed(&capturer_))); |
} |
void VideoScheduler::ScheduleNextCapture() { |
@@ -232,7 +221,7 @@ void VideoScheduler::CaptureNextFrame() { |
ScheduleNextCapture(); |
// And finally perform one capture. |
- capturer_->CaptureFrame(); |
+ capturer_->Capture(webrtc::DesktopRegion()); |
} |
void VideoScheduler::FrameCaptureCompleted() { |
@@ -286,28 +275,35 @@ void VideoScheduler::SendCursorShape( |
// Encoder thread -------------------------------------------------------------- |
void VideoScheduler::EncodeFrame( |
- scoped_refptr<media::ScreenCaptureData> capture_data) { |
+ scoped_ptr<webrtc::DesktopFrame> frame, |
+ int sequence_number) { |
DCHECK(encode_task_runner_->BelongsToCurrentThread()); |
// If there is nothing to encode then send an empty keep-alive packet. |
- if (!capture_data || capture_data->dirty_region().isEmpty()) { |
+ if (!frame || frame->updated_region().is_empty()) { |
scoped_ptr<VideoPacket> packet(new VideoPacket()); |
packet->set_flags(VideoPacket::LAST_PARTITION); |
+ packet->set_sequence_number(sequence_number); |
network_task_runner_->PostTask( |
FROM_HERE, base::Bind(&VideoScheduler::SendVideoPacket, this, |
base::Passed(&packet))); |
+ capture_task_runner_->DeleteSoon(FROM_HERE, frame.release()); |
return; |
} |
encoder_->Encode( |
- capture_data, false, |
- base::Bind(&VideoScheduler::EncodedDataAvailableCallback, this)); |
+ frame.get(), base::Bind(&VideoScheduler::EncodedDataAvailableCallback, |
+ this, sequence_number)); |
+ capture_task_runner_->DeleteSoon(FROM_HERE, frame.release()); |
} |
void VideoScheduler::EncodedDataAvailableCallback( |
+ int sequence_number, |
scoped_ptr<VideoPacket> packet) { |
DCHECK(encode_task_runner_->BelongsToCurrentThread()); |
+ packet->set_sequence_number(sequence_number); |
+ |
bool last = (packet->flags() & VideoPacket::LAST_PACKET) != 0; |
if (last) { |
scheduler_.RecordEncodeTime( |
@@ -319,14 +315,4 @@ void VideoScheduler::EncodedDataAvailableCallback( |
base::Passed(&packet))); |
} |
-void VideoScheduler::StopOnEncodeThread( |
- scoped_ptr<media::ScreenCapturer> capturer) { |
- DCHECK(encode_task_runner_->BelongsToCurrentThread()); |
- |
- // This is posted by StopOnCaptureThread, so we know that by the time we |
- // process it there are no more encode tasks queued. Pass |capturer| for |
- // deletion on the capture thread. |
- capture_task_runner_->DeleteSoon(FROM_HERE, capturer.release()); |
-} |
- |
} // namespace remoting |