Index: content/browser/media/capture/web_contents_video_capture_device.cc |
diff --git a/content/browser/media/capture/web_contents_video_capture_device.cc b/content/browser/media/capture/web_contents_video_capture_device.cc |
index dca65d372608f867c1c8feb45cec5a50f282b5a0..4d111732a784d690e04c5fb503a31555e6a5ffe9 100644 |
--- a/content/browser/media/capture/web_contents_video_capture_device.cc |
+++ b/content/browser/media/capture/web_contents_video_capture_device.cc |
@@ -63,8 +63,6 @@ |
#include "base/threading/thread.h" |
#include "base/threading/thread_checker.h" |
#include "base/time/time.h" |
-#include "content/browser/media/capture/content_video_capture_device_core.h" |
-#include "content/browser/media/capture/video_capture_oracle.h" |
#include "content/browser/media/capture/web_contents_capture_util.h" |
#include "content/browser/media/capture/web_contents_tracker.h" |
#include "content/browser/renderer_host/render_widget_host_impl.h" |
@@ -76,6 +74,9 @@ |
#include "content/public/browser/web_contents.h" |
#include "media/base/video_capture_types.h" |
#include "media/base/video_util.h" |
+#include "media/capture/screen_capture_device_core.h" |
+#include "media/capture/thread_safe_capture_oracle.h" |
+#include "media/capture/video_capture_oracle.h" |
#include "skia/ext/image_operations.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
#include "third_party/skia/include/core/SkColor.h" |
@@ -116,8 +117,8 @@ class VideoFrameDeliveryLog { |
// with RenderWidgetHostViewFrameSubscriber. We create one per event type. |
class FrameSubscriber : public RenderWidgetHostViewFrameSubscriber { |
public: |
- FrameSubscriber(VideoCaptureOracle::Event event_type, |
- const scoped_refptr<ThreadSafeCaptureOracle>& oracle, |
+ FrameSubscriber(media::VideoCaptureOracle::Event event_type, |
+ const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle, |
VideoFrameDeliveryLog* delivery_log) |
: event_type_(event_type), |
oracle_proxy_(oracle), |
@@ -131,8 +132,8 @@ class FrameSubscriber : public RenderWidgetHostViewFrameSubscriber { |
deliver_frame_cb) override; |
private: |
- const VideoCaptureOracle::Event event_type_; |
- scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_; |
+ const media::VideoCaptureOracle::Event event_type_; |
+ scoped_refptr<media::ThreadSafeCaptureOracle> oracle_proxy_; |
VideoFrameDeliveryLog* const delivery_log_; |
}; |
@@ -162,7 +163,7 @@ class ContentCaptureSubscription { |
// work. |
ContentCaptureSubscription( |
const RenderWidgetHost& source, |
- const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, |
+ const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, |
const CaptureCallback& capture_callback); |
~ContentCaptureSubscription(); |
@@ -198,14 +199,15 @@ void RenderVideoFrame(const SkBitmap& input, |
// Renews capture subscriptions based on feedback from WebContentsTracker, and |
// also executes copying of the backing store on the UI BrowserThread. |
-class WebContentsCaptureMachine : public VideoCaptureMachine { |
+class WebContentsCaptureMachine : public media::VideoCaptureMachine { |
public: |
WebContentsCaptureMachine(int render_process_id, int main_render_frame_id); |
~WebContentsCaptureMachine() override; |
// VideoCaptureMachine overrides. |
- bool Start(const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, |
- const media::VideoCaptureParams& params) override; |
+ void Start(const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, |
+ const media::VideoCaptureParams& params, |
+ const base::Callback<void(bool)> callback) override; |
void Stop(const base::Closure& callback) override; |
// Starts a copy from the backing store or the composited surface. Must be run |
@@ -219,6 +221,10 @@ class WebContentsCaptureMachine : public VideoCaptureMachine { |
deliver_frame_cb); |
private: |
+ bool InternalStart( |
+ const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, |
+ const media::VideoCaptureParams& params); |
+ void InternalStop(const base::Closure& callback); |
bool IsStarted() const; |
// Computes the preferred size of the target RenderWidget for optimal capture. |
@@ -260,7 +266,7 @@ class WebContentsCaptureMachine : public VideoCaptureMachine { |
scoped_ptr<base::Thread> render_thread_; |
// Makes all the decisions about which frames to copy, and how. |
- scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_; |
+ scoped_refptr<media::ThreadSafeCaptureOracle> oracle_proxy_; |
// Video capture parameters that this machine is started with. |
media::VideoCaptureParams capture_params_; |
@@ -287,7 +293,7 @@ bool FrameSubscriber::ShouldCaptureFrame( |
TRACE_EVENT1("gpu.capture", "FrameSubscriber::ShouldCaptureFrame", |
"instance", this); |
- ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; |
+ media::ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; |
bool oracle_decision = oracle_proxy_->ObserveEventAndDecideCapture( |
event_type_, damage_rect, present_time, storage, &capture_frame_cb); |
@@ -300,12 +306,12 @@ bool FrameSubscriber::ShouldCaptureFrame( |
ContentCaptureSubscription::ContentCaptureSubscription( |
const RenderWidgetHost& source, |
- const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, |
+ const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, |
const CaptureCallback& capture_callback) |
: render_process_id_(source.GetProcess()->GetID()), |
render_widget_id_(source.GetRoutingID()), |
delivery_log_(), |
- timer_subscriber_(VideoCaptureOracle::kTimerPoll, oracle_proxy, |
+ timer_subscriber_(media::VideoCaptureOracle::kTimerPoll, oracle_proxy, |
&delivery_log_), |
capture_callback_(capture_callback), |
timer_(true, true) { |
@@ -317,7 +323,7 @@ ContentCaptureSubscription::ContentCaptureSubscription( |
// oracle. |
if (view) { |
scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber( |
- new FrameSubscriber(VideoCaptureOracle::kCompositorUpdate, |
+ new FrameSubscriber(media::VideoCaptureOracle::kCompositorUpdate, |
oracle_proxy, &delivery_log_)); |
view->BeginFrameSubscription(subscriber.Pass()); |
} |
@@ -325,8 +331,8 @@ ContentCaptureSubscription::ContentCaptureSubscription( |
// Subscribe to timer events. This instance will service these as well. |
timer_.Start(FROM_HERE, |
std::max(oracle_proxy->min_capture_period(), |
- base::TimeDelta::FromMilliseconds( |
- VideoCaptureOracle::kMinTimerPollPeriodMillis)), |
+ base::TimeDelta::FromMilliseconds(media |
+ ::VideoCaptureOracle::kMinTimerPollPeriodMillis)), |
base::Bind(&ContentCaptureSubscription::OnTimer, |
base::Unretained(this))); |
} |
@@ -483,8 +489,23 @@ bool WebContentsCaptureMachine::IsStarted() const { |
return weak_ptr_factory_.HasWeakPtrs(); |
} |
-bool WebContentsCaptureMachine::Start( |
- const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, |
+void WebContentsCaptureMachine::Start( |
+ const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, |
+ const media::VideoCaptureParams& params, |
+ const base::Callback<void(bool)> callback) { |
+ // Starts the capture machine asynchronously. |
+ BrowserThread::PostTaskAndReplyWithResult( |
+ BrowserThread::UI, |
+ FROM_HERE, |
+ base::Bind(&WebContentsCaptureMachine::InternalStart, |
+ base::Unretained(this), |
+ oracle_proxy, |
+ params), |
+ callback); |
+} |
+ |
+bool WebContentsCaptureMachine::InternalStart( |
+ const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, |
const media::VideoCaptureParams& params) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
DCHECK(!IsStarted()); |
@@ -513,6 +534,15 @@ bool WebContentsCaptureMachine::Start( |
} |
void WebContentsCaptureMachine::Stop(const base::Closure& callback) { |
+ // Stops the capture machine asynchronously. |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, base::Bind( |
+ &WebContentsCaptureMachine::InternalStop, |
+ base::Unretained(this), |
+ callback)); |
+} |
+ |
+void WebContentsCaptureMachine::InternalStop(const base::Closure& callback) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
if (!IsStarted()) { |
@@ -711,9 +741,9 @@ void WebContentsCaptureMachine::UpdateCaptureSize() { |
WebContentsVideoCaptureDevice::WebContentsVideoCaptureDevice( |
int render_process_id, int main_render_frame_id) |
- : core_(new ContentVideoCaptureDeviceCore(scoped_ptr<VideoCaptureMachine>( |
- new WebContentsCaptureMachine( |
- render_process_id, main_render_frame_id)))) {} |
+ : core_(new media::ScreenCaptureDeviceCore( |
+ scoped_ptr<media::VideoCaptureMachine>(new WebContentsCaptureMachine( |
+ render_process_id, main_render_frame_id)))) {} |
WebContentsVideoCaptureDevice::~WebContentsVideoCaptureDevice() { |
DVLOG(2) << "WebContentsVideoCaptureDevice@" << this << " destroying."; |