From 97dd433374f7a5e5195fb6c65bdab33740b98e86 Mon Sep 17 00:00:00 2001 From: "piman@chromium.org" Date: Sat, 6 Aug 2011 03:15:48 +0000 Subject: Video Capture Pepper API The API is very simple at this point but works end-to-end. BUG=None TEST=VideoCapture sample (in a later CL) Review URL: http://codereview.chromium.org/7553003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95719 0039d316-1c4b-4281-b951-d872f2087c98 --- content/renderer/pepper_plugin_delegate_impl.cc | 68 ++++++++++++++++++++++++- content/renderer/pepper_plugin_delegate_impl.h | 2 + 2 files changed, 68 insertions(+), 2 deletions(-) (limited to 'content') diff --git a/content/renderer/pepper_plugin_delegate_impl.cc b/content/renderer/pepper_plugin_delegate_impl.cc index 2ce1076..c061b80 100644 --- a/content/renderer/pepper_plugin_delegate_impl.cc +++ b/content/renderer/pepper_plugin_delegate_impl.cc @@ -36,6 +36,7 @@ #include "content/renderer/gpu/renderer_gl_context.h" #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" #include "content/renderer/media/audio_message_filter.h" +#include "content/renderer/media/video_capture_impl_manager.h" #include "content/renderer/p2p/p2p_transport_impl.h" #include "content/renderer/pepper_platform_context_3d_impl.h" #include "content/renderer/pepper_platform_video_decoder_impl.h" @@ -44,6 +45,7 @@ #include "content/renderer/render_widget_fullscreen_pepper.h" #include "content/renderer/webplugin_delegate_proxy.h" #include "ipc/ipc_channel_handle.h" +#include "media/video/capture/video_capture_proxy.h" #include "ppapi/c/dev/pp_video_dev.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/private/ppb_flash.h" @@ -73,8 +75,6 @@ using WebKit::WebView; namespace { -const int32 kDefaultCommandBufferSize = 1024 * 1024; - int32_t PlatformFileToInt(base::PlatformFile handle) { #if defined(OS_WIN) return static_cast(reinterpret_cast(handle)); @@ -376,6 +376,64 @@ class QuotaCallbackTranslator : public QuotaDispatcher::Callback { scoped_ptr callback_; }; +class PlatformVideoCaptureImpl + : public webkit::ppapi::PluginDelegate::PlatformVideoCapture { + public: + PlatformVideoCaptureImpl(media::VideoCapture::EventHandler* handler) + : handler_proxy_(new media::VideoCaptureHandlerProxy( + handler, base::MessageLoopProxy::CreateForCurrentThread())) { + VideoCaptureImplManager* manager = + RenderThread::current()->video_capture_impl_manager(); + // 1 means the "default" video capture device. + // TODO(piman): Add a way to enumerate devices and pass them through the + // API. + video_capture_ = manager->AddDevice(1, handler_proxy_.get()); + } + + // Overrides from media::VideoCapture::EventHandler + virtual ~PlatformVideoCaptureImpl() { + VideoCaptureImplManager* manager = + RenderThread::current()->video_capture_impl_manager(); + manager->RemoveDevice(1, handler_proxy_.get()); + } + + virtual void StartCapture( + EventHandler* handler, + const VideoCaptureCapability& capability) OVERRIDE { + DCHECK(handler == handler_proxy_->proxied()); + video_capture_->StartCapture(handler_proxy_.get(), capability); + } + + virtual void StopCapture(EventHandler* handler) OVERRIDE { + DCHECK(handler == handler_proxy_->proxied()); + video_capture_->StopCapture(handler_proxy_.get()); + } + + virtual void FeedBuffer(scoped_refptr buffer) OVERRIDE { + video_capture_->FeedBuffer(buffer); + } + + virtual bool CaptureStarted() OVERRIDE { + return handler_proxy_->state().started; + } + + virtual int CaptureWidth() OVERRIDE { + return handler_proxy_->state().width; + } + + virtual int CaptureHeight() OVERRIDE { + return handler_proxy_->state().height; + } + + virtual int CaptureFrameRate() OVERRIDE { + return handler_proxy_->state().frame_rate; + } + + private: + scoped_ptr handler_proxy_; + media::VideoCapture* video_capture_; +}; + } // namespace bool DispatcherWrapper::Init( @@ -854,6 +912,12 @@ webkit::ppapi::PluginDelegate::PlatformContext3D* #endif } +webkit::ppapi::PluginDelegate::PlatformVideoCapture* +PepperPluginDelegateImpl::CreateVideoCapture( + media::VideoCapture::EventHandler* handler) { + return new PlatformVideoCaptureImpl(handler); +} + webkit::ppapi::PluginDelegate::PlatformVideoDecoder* PepperPluginDelegateImpl::CreateVideoDecoder( media::VideoDecodeAccelerator::Client* client, diff --git a/content/renderer/pepper_plugin_delegate_impl.h b/content/renderer/pepper_plugin_delegate_impl.h index e465dfe..c7f9886 100644 --- a/content/renderer/pepper_plugin_delegate_impl.h +++ b/content/renderer/pepper_plugin_delegate_impl.h @@ -178,6 +178,8 @@ class PepperPluginDelegateImpl PlatformAudio::Client* client); virtual PlatformImage2D* CreateImage2D(int width, int height); virtual PlatformContext3D* CreateContext3D(); + virtual PlatformVideoCapture* CreateVideoCapture( + media::VideoCapture::EventHandler* handler) OVERRIDE; virtual PlatformVideoDecoder* CreateVideoDecoder( media::VideoDecodeAccelerator::Client* client, int32 command_buffer_route_id); -- cgit v1.1