| Index: content/renderer/pepper/pepper_platform_video_capture.cc
|
| diff --git a/content/renderer/pepper/pepper_platform_video_capture.cc b/content/renderer/pepper/pepper_platform_video_capture.cc
|
| index 81e175cb24a985fb721a649ab14ca8dd87b3d09d..60fc32e000968990a4d53a258020144bd970453b 100644
|
| --- a/content/renderer/pepper/pepper_platform_video_capture.cc
|
| +++ b/content/renderer/pepper/pepper_platform_video_capture.cc
|
| @@ -12,7 +12,7 @@
|
| #include "content/renderer/pepper/pepper_video_capture_host.h"
|
| #include "content/renderer/render_thread_impl.h"
|
| #include "content/renderer/render_view_impl.h"
|
| -#include "media/base/bind_to_current_loop.h"
|
| +#include "media/video/capture/video_capture_proxy.h"
|
| #include "url/gurl.h"
|
|
|
| namespace content {
|
| @@ -25,10 +25,13 @@
|
| : render_view_(render_view),
|
| device_id_(device_id),
|
| session_id_(0),
|
| + handler_proxy_(new media::VideoCaptureHandlerProxy(
|
| + this,
|
| + base::MessageLoopProxy::current())),
|
| handler_(handler),
|
| + unbalanced_start_(false),
|
| pending_open_device_(false),
|
| - pending_open_device_id_(-1),
|
| - weak_factory_(this) {
|
| + pending_open_device_id_(-1) {
|
| // We need to open the device and obtain the label and session ID before
|
| // initializing.
|
| if (render_view_.get()) {
|
| @@ -36,45 +39,62 @@
|
| PP_DEVICETYPE_DEV_VIDEOCAPTURE,
|
| device_id,
|
| document_url,
|
| - base::Bind(&PepperPlatformVideoCapture::OnDeviceOpened,
|
| - weak_factory_.GetWeakPtr()));
|
| + base::Bind(&PepperPlatformVideoCapture::OnDeviceOpened, this));
|
| pending_open_device_ = true;
|
| }
|
| }
|
|
|
| void PepperPlatformVideoCapture::StartCapture(
|
| + media::VideoCapture::EventHandler* handler,
|
| const media::VideoCaptureParams& params) {
|
| - DCHECK(thread_checker_.CalledOnValidThread());
|
| - if (!stop_capture_cb_.is_null())
|
| + DCHECK(handler == handler_);
|
| +
|
| + if (unbalanced_start_)
|
| return;
|
| - VideoCaptureImplManager* manager =
|
| - RenderThreadImpl::current()->video_capture_impl_manager();
|
| - stop_capture_cb_ =
|
| - manager->StartCapture(session_id_,
|
| - params,
|
| - media::BindToCurrentLoop(base::Bind(
|
| - &PepperPlatformVideoCapture::OnStateUpdate,
|
| - weak_factory_.GetWeakPtr())),
|
| - media::BindToCurrentLoop(base::Bind(
|
| - &PepperPlatformVideoCapture::OnFrameReady,
|
| - weak_factory_.GetWeakPtr())));
|
| +
|
| + if (video_capture_) {
|
| + unbalanced_start_ = true;
|
| + AddRef(); // Will be balanced in OnRemoved().
|
| + video_capture_->StartCapture(handler_proxy_.get(), params);
|
| + }
|
| }
|
|
|
| -void PepperPlatformVideoCapture::StopCapture() {
|
| - DCHECK(thread_checker_.CalledOnValidThread());
|
| - if (stop_capture_cb_.is_null())
|
| +void PepperPlatformVideoCapture::StopCapture(
|
| + media::VideoCapture::EventHandler* handler) {
|
| + DCHECK(handler == handler_);
|
| + if (!unbalanced_start_)
|
| return;
|
| - stop_capture_cb_.Run();
|
| - stop_capture_cb_.Reset();
|
| +
|
| + if (video_capture_) {
|
| + unbalanced_start_ = false;
|
| + video_capture_->StopCapture(handler_proxy_.get());
|
| + }
|
| +}
|
| +
|
| +bool PepperPlatformVideoCapture::CaptureStarted() {
|
| + return handler_proxy_->state().started;
|
| +}
|
| +
|
| +int PepperPlatformVideoCapture::CaptureFrameRate() {
|
| + return handler_proxy_->state().frame_rate;
|
| +}
|
| +
|
| +void PepperPlatformVideoCapture::GetDeviceSupportedFormats(
|
| + const DeviceFormatsCallback& callback) {
|
| + NOTREACHED();
|
| +}
|
| +
|
| +void PepperPlatformVideoCapture::GetDeviceFormatsInUse(
|
| + const DeviceFormatsInUseCallback& callback) {
|
| + NOTREACHED();
|
| }
|
|
|
| void PepperPlatformVideoCapture::DetachEventHandler() {
|
| handler_ = NULL;
|
| - StopCapture();
|
| - if (!release_device_cb_.is_null()) {
|
| - release_device_cb_.Run();
|
| - release_device_cb_.Reset();
|
| - }
|
| + StopCapture(NULL);
|
| +
|
| + video_capture_.reset();
|
| +
|
| if (render_view_.get()) {
|
| if (!label_.empty()) {
|
| GetMediaDeviceManager()->CloseDevice(label_);
|
| @@ -88,11 +108,51 @@
|
| }
|
| }
|
|
|
| +void PepperPlatformVideoCapture::OnStarted(VideoCapture* capture) {
|
| + if (handler_)
|
| + handler_->OnStarted(capture);
|
| +}
|
| +
|
| +void PepperPlatformVideoCapture::OnStopped(VideoCapture* capture) {
|
| + if (handler_)
|
| + handler_->OnStopped(capture);
|
| +}
|
| +
|
| +void PepperPlatformVideoCapture::OnPaused(VideoCapture* capture) {
|
| + if (handler_)
|
| + handler_->OnPaused(capture);
|
| +}
|
| +
|
| +void PepperPlatformVideoCapture::OnError(VideoCapture* capture,
|
| + int error_code) {
|
| + if (handler_)
|
| + handler_->OnError(capture, error_code);
|
| +}
|
| +
|
| +void PepperPlatformVideoCapture::OnRemoved(VideoCapture* capture) {
|
| + if (handler_)
|
| + handler_->OnRemoved(capture);
|
| +
|
| + Release(); // Balance the AddRef() in StartCapture().
|
| +}
|
| +
|
| +void PepperPlatformVideoCapture::OnFrameReady(
|
| + VideoCapture* capture,
|
| + const scoped_refptr<media::VideoFrame>& frame) {
|
| + if (handler_)
|
| + handler_->OnFrameReady(capture, frame);
|
| +}
|
| +
|
| PepperPlatformVideoCapture::~PepperPlatformVideoCapture() {
|
| - DCHECK(stop_capture_cb_.is_null());
|
| - DCHECK(release_device_cb_.is_null());
|
| + DCHECK(!video_capture_);
|
| DCHECK(label_.empty());
|
| DCHECK(!pending_open_device_);
|
| +}
|
| +
|
| +void PepperPlatformVideoCapture::Initialize() {
|
| + VideoCaptureImplManager* manager =
|
| + RenderThreadImpl::current()->video_capture_impl_manager();
|
| + video_capture_ = manager->UseDevice(session_id_);
|
| }
|
|
|
| void PepperPlatformVideoCapture::OnDeviceOpened(int request_id,
|
| @@ -106,41 +166,11 @@
|
| label_ = label;
|
| session_id_ = GetMediaDeviceManager()->GetSessionID(
|
| PP_DEVICETYPE_DEV_VIDEOCAPTURE, label);
|
| - VideoCaptureImplManager* manager =
|
| - RenderThreadImpl::current()->video_capture_impl_manager();
|
| - release_device_cb_ = manager->UseDevice(session_id_);
|
| + Initialize();
|
| }
|
|
|
| if (handler_)
|
| - handler_->OnInitialized(succeeded);
|
| -}
|
| -
|
| -void PepperPlatformVideoCapture::OnStateUpdate(VideoCaptureState state) {
|
| - if (!handler_)
|
| - return;
|
| - switch (state) {
|
| - case VIDEO_CAPTURE_STATE_STARTED:
|
| - handler_->OnStarted();
|
| - break;
|
| - case VIDEO_CAPTURE_STATE_STOPPED:
|
| - handler_->OnStopped();
|
| - break;
|
| - case VIDEO_CAPTURE_STATE_PAUSED:
|
| - handler_->OnPaused();
|
| - break;
|
| - case VIDEO_CAPTURE_STATE_ERROR:
|
| - handler_->OnError();
|
| - break;
|
| - default:
|
| - NOTREACHED() << "Unexpected state: " << state << ".";
|
| - }
|
| -}
|
| -
|
| -void PepperPlatformVideoCapture::OnFrameReady(
|
| - const scoped_refptr<media::VideoFrame>& frame,
|
| - const media::VideoCaptureFormat& format) {
|
| - if (handler_ && !stop_capture_cb_.is_null())
|
| - handler_->OnFrameReady(frame, format);
|
| + handler_->OnInitialized(this, succeeded);
|
| }
|
|
|
| PepperMediaDeviceManager* PepperPlatformVideoCapture::GetMediaDeviceManager() {
|
|
|