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 def9f9a744781c5fb930faa65d089d3bc8030701..278119d48181403bca0fbb0dcb972ebf419adaad 100644 |
--- a/content/browser/media/capture/web_contents_video_capture_device.cc |
+++ b/content/browser/media/capture/web_contents_video_capture_device.cc |
@@ -62,8 +62,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" |
@@ -75,6 +73,8 @@ |
#include "content/public/browser/web_contents.h" |
#include "media/base/video_capture_types.h" |
#include "media/base/video_util.h" |
+#include "media/capture/media_video_capture_device_core.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" |
@@ -115,8 +115,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), |
@@ -130,8 +130,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_; |
}; |
@@ -161,7 +161,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(); |
@@ -197,14 +197,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 |
@@ -218,6 +219,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. |
@@ -259,7 +264,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_; |
@@ -286,7 +291,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); |
@@ -299,12 +304,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) { |
@@ -316,7 +321,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()); |
} |
@@ -324,8 +329,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))); |
} |
@@ -482,8 +487,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()); |
@@ -512,6 +532,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()) { |
@@ -710,9 +739,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::MediaVideoCaptureDeviceCore( |
+ scoped_ptr<media::VideoCaptureMachine>(new WebContentsCaptureMachine( |
+ render_process_id, main_render_frame_id)))) {} |
WebContentsVideoCaptureDevice::~WebContentsVideoCaptureDevice() { |
DVLOG(2) << "WebContentsVideoCaptureDevice@" << this << " destroying."; |