summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-26 19:09:27 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-26 19:09:27 +0000
commit3f90dbc4e700692dbb1b03103f4e4b93c002e56b (patch)
tree28834098f57c558433c32ae59e322ed4f253de66
parent3a3128e1a77365346e62ce5e977216119f129e34 (diff)
downloadchromium_src-3f90dbc4e700692dbb1b03103f4e4b93c002e56b.zip
chromium_src-3f90dbc4e700692dbb1b03103f4e4b93c002e56b.tar.gz
chromium_src-3f90dbc4e700692dbb1b03103f4e4b93c002e56b.tar.bz2
Remove unittest usage of PluginDelegate by PepperDeviceEnumerationHostHelperTest as part of the work on removing PluginDelegate completely.
This required removing a bunch of interfaces. Since all the code is in content now, I removed these intermediate interfaces and just passed the concrete types directly. The removed interfaces were: PluginDelegate::PlatformAudioInput PluginDelegate::PlatformAudioInputClient PluginDelegate::PlatformVideoCapture PluginDelegate::PlatformVideoCaptureEventHandler BUG=263054 R=yzshen@chromium.org Review URL: https://codereview.chromium.org/20635004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213963 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/content_renderer.gypi8
-rw-r--r--content/renderer/pepper/mock_plugin_delegate.cc26
-rw-r--r--content/renderer/pepper/mock_plugin_delegate.h14
-rw-r--r--content/renderer/pepper/pepper_audio_input_host.cc32
-rw-r--r--content/renderer/pepper/pepper_audio_input_host.h25
-rw-r--r--content/renderer/pepper/pepper_device_enumeration_event_handler.cc127
-rw-r--r--content/renderer/pepper/pepper_device_enumeration_event_handler.h55
-rw-r--r--content/renderer/pepper/pepper_device_enumeration_host_helper.cc24
-rw-r--r--content/renderer/pepper/pepper_device_enumeration_host_helper.h18
-rw-r--r--content/renderer/pepper/pepper_device_enumeration_host_helper_unittest.cc40
-rw-r--r--content/renderer/pepper/pepper_platform_audio_input.cc (renamed from content/renderer/pepper/pepper_platform_audio_input_impl.cc)101
-rw-r--r--content/renderer/pepper/pepper_platform_audio_input.h (renamed from content/renderer/pepper/pepper_platform_audio_input_impl.h)66
-rw-r--r--content/renderer/pepper/pepper_platform_video_capture.cc (renamed from content/renderer/pepper/pepper_platform_video_capture_impl.cc)81
-rw-r--r--content/renderer/pepper/pepper_platform_video_capture.h (renamed from content/renderer/pepper/pepper_platform_video_capture_impl.h)39
-rw-r--r--content/renderer/pepper/pepper_plugin_delegate_impl.cc126
-rw-r--r--content/renderer/pepper/pepper_plugin_delegate_impl.h39
-rw-r--r--content/renderer/pepper/pepper_video_capture_host.cc36
-rw-r--r--content/renderer/pepper/pepper_video_capture_host.h16
-rw-r--r--content/renderer/pepper/plugin_delegate.h93
19 files changed, 400 insertions, 566 deletions
diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi
index 4f4ddf5..d94a6f4 100644
--- a/content/content_renderer.gypi
+++ b/content/content_renderer.gypi
@@ -309,16 +309,16 @@
'renderer/pepper/pepper_in_process_resource_creation.h',
'renderer/pepper/pepper_in_process_router.cc',
'renderer/pepper/pepper_in_process_router.h',
- 'renderer/pepper/pepper_platform_audio_input_impl.cc',
- 'renderer/pepper/pepper_platform_audio_input_impl.h',
+ 'renderer/pepper/pepper_platform_audio_input.cc',
+ 'renderer/pepper/pepper_platform_audio_input.h',
'renderer/pepper/pepper_platform_audio_output_impl.cc',
'renderer/pepper/pepper_platform_audio_output_impl.h',
'renderer/pepper/pepper_platform_context_3d_impl.cc',
'renderer/pepper/pepper_platform_context_3d_impl.h',
'renderer/pepper/pepper_platform_image_2d_impl.cc',
'renderer/pepper/pepper_platform_image_2d_impl.h',
- 'renderer/pepper/pepper_platform_video_capture_impl.cc',
- 'renderer/pepper/pepper_platform_video_capture_impl.h',
+ 'renderer/pepper/pepper_platform_video_capture.cc',
+ 'renderer/pepper/pepper_platform_video_capture.h',
'renderer/pepper/pepper_plugin_delegate_impl.cc',
'renderer/pepper/pepper_plugin_delegate_impl.h',
'renderer/pepper/pepper_plugin_instance_impl.cc',
diff --git a/content/renderer/pepper/mock_plugin_delegate.cc b/content/renderer/pepper/mock_plugin_delegate.cc
index 69bb2d5..8b6660a 100644
--- a/content/renderer/pepper/mock_plugin_delegate.cc
+++ b/content/renderer/pepper/mock_plugin_delegate.cc
@@ -101,14 +101,6 @@ MockPluginDelegate::CreateVideoDecoder(
return NULL;
}
-MockPluginDelegate::PlatformVideoCapture*
-MockPluginDelegate::CreateVideoCapture(
- const std::string& device_id,
- const GURL& document_url,
- PlatformVideoCaptureEventHandler* handler){
- return NULL;
-}
-
uint32_t MockPluginDelegate::GetAudioHardwareOutputSampleRate() {
return 0;
}
@@ -124,15 +116,6 @@ MockPluginDelegate::PlatformAudioOutput* MockPluginDelegate::CreateAudioOutput(
return NULL;
}
-MockPluginDelegate::PlatformAudioInput* MockPluginDelegate::CreateAudioInput(
- const std::string& device_id,
- const GURL& document_url,
- uint32_t sample_rate,
- uint32_t sample_count,
- PlatformAudioInputClient* client) {
- return NULL;
-}
-
MockPluginDelegate::Broker* MockPluginDelegate::ConnectToBroker(
PPB_Broker_Impl* client) {
return NULL;
@@ -367,15 +350,6 @@ bool MockPluginDelegate::IsPageVisible() const {
return true;
}
-int MockPluginDelegate::EnumerateDevices(
- PP_DeviceType_Dev type,
- const EnumerateDevicesCallback& callback) {
- return -1;
-}
-
-void MockPluginDelegate::StopEnumerateDevices(int request_id) {
-}
-
IPC::PlatformFileForTransit MockPluginDelegate::ShareHandleWithRemote(
base::PlatformFile handle,
base::ProcessId target_process_id,
diff --git a/content/renderer/pepper/mock_plugin_delegate.h b/content/renderer/pepper/mock_plugin_delegate.h
index 248572a..f6384f3 100644
--- a/content/renderer/pepper/mock_plugin_delegate.h
+++ b/content/renderer/pepper/mock_plugin_delegate.h
@@ -49,22 +49,12 @@ class MockPluginDelegate : public PluginDelegate {
virtual PlatformVideoDecoder* CreateVideoDecoder(
media::VideoDecodeAccelerator::Client* client,
int32 command_buffer_route_id) OVERRIDE;
- virtual PlatformVideoCapture* CreateVideoCapture(
- const std::string& device_id,
- const GURL& document_url,
- PlatformVideoCaptureEventHandler* handler) OVERRIDE;
virtual uint32_t GetAudioHardwareOutputSampleRate() OVERRIDE;
virtual uint32_t GetAudioHardwareOutputBufferSize() OVERRIDE;
virtual PlatformAudioOutput* CreateAudioOutput(
uint32_t sample_rate,
uint32_t sample_count,
PlatformAudioOutputClient* client) OVERRIDE;
- virtual PlatformAudioInput* CreateAudioInput(
- const std::string& device_id,
- const GURL& document_url,
- uint32_t sample_rate,
- uint32_t sample_count,
- PlatformAudioInputClient* client) OVERRIDE;
virtual Broker* ConnectToBroker(PPB_Broker_Impl* client) OVERRIDE;
virtual void NumberOfFindResultsChanged(int identifier,
int total,
@@ -173,10 +163,6 @@ class MockPluginDelegate : public PluginDelegate {
virtual void SampleGamepads(WebKit::WebGamepads* data) OVERRIDE;
virtual bool IsInFullscreenMode() OVERRIDE;
virtual bool IsPageVisible() const OVERRIDE;
- virtual int EnumerateDevices(
- PP_DeviceType_Dev type,
- const EnumerateDevicesCallback& callback) OVERRIDE;
- virtual void StopEnumerateDevices(int request_id) OVERRIDE;
virtual IPC::PlatformFileForTransit ShareHandleWithRemote(
base::PlatformFile handle,
base::ProcessId target_process_id,
diff --git a/content/renderer/pepper/pepper_audio_input_host.cc b/content/renderer/pepper/pepper_audio_input_host.cc
index a4056d2..5b48f3e 100644
--- a/content/renderer/pepper/pepper_audio_input_host.cc
+++ b/content/renderer/pepper/pepper_audio_input_host.cc
@@ -6,8 +6,11 @@
#include "base/logging.h"
#include "build/build_config.h"
+#include "content/renderer/pepper/pepper_device_enumeration_event_handler.h"
+#include "content/renderer/pepper/pepper_platform_audio_input.h"
#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
#include "content/renderer/pepper/renderer_ppapi_host_impl.h"
+#include "content/renderer/render_view_impl.h"
#include "ipc/ipc_message.h"
#include "media/audio/shared_memory_util.h"
#include "ppapi/c/pp_errors.h"
@@ -47,7 +50,11 @@ PepperAudioInputHost::PepperAudioInputHost(
: ResourceHost(host->GetPpapiHost(), instance, resource),
renderer_ppapi_host_(host),
audio_input_(NULL),
- enumeration_helper_(this, this, PP_DEVICETYPE_DEV_AUDIOCAPTURE) {
+ enumeration_helper_(
+ this,
+ PepperDeviceEnumerationEventHandler::GetForRenderView(
+ host->GetRenderViewForInstance(pp_instance())),
+ PP_DEVICETYPE_DEV_AUDIOCAPTURE) {
}
PepperAudioInputHost::~PepperAudioInputHost() {
@@ -83,14 +90,6 @@ void PepperAudioInputHost::StreamCreationFailed() {
base::SyncSocket::kInvalidHandle);
}
-PluginDelegate* PepperAudioInputHost::GetPluginDelegate() {
- PepperPluginInstanceImpl* instance =
- renderer_ppapi_host_->GetPluginInstanceImpl(pp_instance());
- if (instance)
- return instance->delegate();
- return NULL;
-}
-
int32_t PepperAudioInputHost::OnOpen(
ppapi::host::HostMessageContext* context,
const std::string& device_id,
@@ -101,10 +100,6 @@ int32_t PepperAudioInputHost::OnOpen(
if (audio_input_)
return PP_ERROR_FAILED;
- PluginDelegate* plugin_delegate = GetPluginDelegate();
- if (!plugin_delegate)
- return PP_ERROR_FAILED;
-
PepperPluginInstanceImpl* instance =
renderer_ppapi_host_->GetPluginInstanceImpl(pp_instance());
if (!instance)
@@ -112,9 +107,14 @@ int32_t PepperAudioInputHost::OnOpen(
// When it is done, we'll get called back on StreamCreated() or
// StreamCreationFailed().
- audio_input_ = plugin_delegate->CreateAudioInput(
- device_id, instance->container()->element().document().url(),
- sample_rate, sample_frame_count, this);
+ RenderViewImpl* render_view = static_cast<RenderViewImpl*>(
+ renderer_ppapi_host_->GetRenderViewForInstance(pp_instance()));
+
+ audio_input_ = PepperPlatformAudioInput::Create(
+ render_view->AsWeakPtr(), device_id,
+ instance->container()->element().document().url(),
+ static_cast<int>(sample_rate),
+ static_cast<int>(sample_frame_count), this);
if (audio_input_) {
open_context_.reset(new ppapi::host::ReplyMessageContext(
context->MakeReplyMessageContext()));
diff --git a/content/renderer/pepper/pepper_audio_input_host.h b/content/renderer/pepper/pepper_audio_input_host.h
index f142197..70c4303 100644
--- a/content/renderer/pepper/pepper_audio_input_host.h
+++ b/content/renderer/pepper/pepper_audio_input_host.h
@@ -13,20 +13,16 @@
#include "base/memory/shared_memory.h"
#include "base/sync_socket.h"
#include "content/renderer/pepper/pepper_device_enumeration_host_helper.h"
-#include "content/renderer/pepper/plugin_delegate.h"
#include "ipc/ipc_platform_file.h"
#include "ppapi/c/ppb_audio_config.h"
#include "ppapi/host/host_message_context.h"
#include "ppapi/host/resource_host.h"
namespace content {
-
+class PepperPlatformAudioInput;
class RendererPpapiHostImpl;
-class PepperAudioInputHost
- : public ppapi::host::ResourceHost,
- public PluginDelegate::PlatformAudioInputClient,
- public PepperDeviceEnumerationHostHelper::Delegate {
+class PepperAudioInputHost : public ppapi::host::ResourceHost {
public:
PepperAudioInputHost(RendererPpapiHostImpl* host,
PP_Instance instance,
@@ -37,14 +33,11 @@ class PepperAudioInputHost
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) OVERRIDE;
- // PluginDelegate::PlatformAudioInputClient implementation.
- virtual void StreamCreated(base::SharedMemoryHandle shared_memory_handle,
- size_t shared_memory_size,
- base::SyncSocket::Handle socket) OVERRIDE;
- virtual void StreamCreationFailed() OVERRIDE;
-
- // PepperDeviceEnumerationHostHelper::Delegate implementation.
- virtual PluginDelegate* GetPluginDelegate() OVERRIDE;
+ // Called when the stream is created.
+ void StreamCreated(base::SharedMemoryHandle shared_memory_handle,
+ size_t shared_memory_size,
+ base::SyncSocket::Handle socket);
+ void StreamCreationFailed();
private:
int32_t OnOpen(ppapi::host::HostMessageContext* context,
@@ -73,9 +66,9 @@ class PepperAudioInputHost
scoped_ptr<ppapi::host::ReplyMessageContext> open_context_;
- // PluginDelegate audio input object that we delegate audio IPC through.
+ // Audio input object that we delegate audio IPC through.
// We don't own this pointer but are responsible for calling Shutdown on it.
- PluginDelegate::PlatformAudioInput* audio_input_;
+ PepperPlatformAudioInput* audio_input_;
PepperDeviceEnumerationHostHelper enumeration_helper_;
diff --git a/content/renderer/pepper/pepper_device_enumeration_event_handler.cc b/content/renderer/pepper/pepper_device_enumeration_event_handler.cc
index 8828fee..c8234d1 100644
--- a/content/renderer/pepper/pepper_device_enumeration_event_handler.cc
+++ b/content/renderer/pepper/pepper_device_enumeration_event_handler.cc
@@ -5,6 +5,8 @@
#include "content/renderer/pepper/pepper_device_enumeration_event_handler.h"
#include "base/logging.h"
+#include "content/renderer/media/media_stream_dispatcher.h"
+#include "content/renderer/render_view_impl.h"
#include "ppapi/shared_impl/ppb_device_ref_shared.h"
namespace content {
@@ -22,8 +24,22 @@ ppapi::DeviceRefData FromStreamDeviceInfo(const StreamDeviceInfo& info) {
} // namespace
-PepperDeviceEnumerationEventHandler::PepperDeviceEnumerationEventHandler()
- : next_id_(1) {
+PepperDeviceEnumerationEventHandler*
+ PepperDeviceEnumerationEventHandler::GetForRenderView(
+ RenderView* render_view) {
+ PepperDeviceEnumerationEventHandler* handler =
+ PepperDeviceEnumerationEventHandler::Get(render_view);
+ if (!handler)
+ handler = new PepperDeviceEnumerationEventHandler(render_view);
+ return handler;
+}
+
+PepperDeviceEnumerationEventHandler::PepperDeviceEnumerationEventHandler(
+ RenderView* render_view)
+ : RenderViewObserver(render_view),
+ RenderViewObserverTracker<PepperDeviceEnumerationEventHandler>(
+ render_view),
+ next_id_(1) {
}
PepperDeviceEnumerationEventHandler::~PepperDeviceEnumerationEventHandler() {
@@ -31,26 +47,105 @@ PepperDeviceEnumerationEventHandler::~PepperDeviceEnumerationEventHandler() {
DCHECK(open_callbacks_.empty());
}
-int PepperDeviceEnumerationEventHandler::RegisterEnumerateDevicesCallback(
- const PluginDelegate::EnumerateDevicesCallback& callback) {
+int PepperDeviceEnumerationEventHandler::EnumerateDevices(
+ PP_DeviceType_Dev type,
+ const EnumerateDevicesCallback& callback) {
enumerate_callbacks_[next_id_] = callback;
- return next_id_++;
+ int request_id = next_id_++;
+
+#if defined(ENABLE_WEBRTC)
+ GetRenderViewImpl()->media_stream_dispatcher()->EnumerateDevices(
+ request_id, AsWeakPtr(),
+ PepperDeviceEnumerationEventHandler::FromPepperDeviceType(type),
+ GURL());
+#else
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &PepperDeviceEnumerationEventHandler::OnDevicesEnumerationFailed,
+ AsWeakPtr(),
+ request_id));
+#endif
+
+ return request_id;
}
-void PepperDeviceEnumerationEventHandler::UnregisterEnumerateDevicesCallback(
- int request_id) {
+void PepperDeviceEnumerationEventHandler::StopEnumerateDevices(int request_id) {
enumerate_callbacks_.erase(request_id);
+
+#if defined(ENABLE_WEBRTC)
+ // Need to post task since this function might be called inside the callback
+ // of EnumerateDevices.
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&MediaStreamDispatcher::StopEnumerateDevices,
+ GetRenderViewImpl()->media_stream_dispatcher()->AsWeakPtr(),
+ request_id,
+ AsWeakPtr()));
+#endif
}
-int PepperDeviceEnumerationEventHandler::RegisterOpenDeviceCallback(
- const PepperPluginDelegateImpl::OpenDeviceCallback& callback) {
+int PepperDeviceEnumerationEventHandler::OpenDevice(
+ PP_DeviceType_Dev type,
+ const std::string& device_id,
+ const GURL& document_url,
+ const OpenDeviceCallback& callback) {
open_callbacks_[next_id_] = callback;
- return next_id_++;
+ int request_id = next_id_++;
+
+#if defined(ENABLE_WEBRTC)
+ GetRenderViewImpl()->media_stream_dispatcher()->
+ OpenDevice(
+ request_id,
+ AsWeakPtr(),
+ device_id,
+ PepperDeviceEnumerationEventHandler::FromPepperDeviceType(type),
+ document_url.GetOrigin());
+#else
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(&PepperDeviceEnumerationEventHandler::OnDeviceOpenFailed,
+ AsWeakPtr(),
+ request_id));
+#endif
+
+ return request_id;
}
-void PepperDeviceEnumerationEventHandler::UnregisterOpenDeviceCallback(
- int request_id) {
+void PepperDeviceEnumerationEventHandler::CancelOpenDevice(int request_id) {
open_callbacks_.erase(request_id);
+
+#if defined(ENABLE_WEBRTC)
+ GetRenderViewImpl()->media_stream_dispatcher()->CancelOpenDevice(
+ request_id, AsWeakPtr());
+#endif
+}
+
+void PepperDeviceEnumerationEventHandler::CloseDevice(
+ const std::string& label) {
+#if defined(ENABLE_WEBRTC)
+ GetRenderViewImpl()->media_stream_dispatcher()->CloseDevice(label);
+#endif
+}
+
+int PepperDeviceEnumerationEventHandler::GetSessionID(
+ PP_DeviceType_Dev type,
+ const std::string& label) {
+#if defined(ENABLE_WEBRTC)
+ switch (type) {
+ case PP_DEVICETYPE_DEV_AUDIOCAPTURE:
+ return GetRenderViewImpl()->media_stream_dispatcher()->audio_session_id(
+ label, 0);
+ case PP_DEVICETYPE_DEV_VIDEOCAPTURE:
+ return GetRenderViewImpl()->media_stream_dispatcher()->video_session_id(
+ label, 0);
+ default:
+ NOTREACHED();
+ return 0;
+ }
+#else
+ return 0;
+#endif
}
void PepperDeviceEnumerationEventHandler::OnStreamGenerated(
@@ -129,7 +224,7 @@ void PepperDeviceEnumerationEventHandler::NotifyDevicesEnumerated(
return;
}
- PluginDelegate::EnumerateDevicesCallback callback = iter->second;
+ EnumerateDevicesCallback callback = iter->second;
std::vector<ppapi::DeviceRefData> devices;
if (succeeded) {
@@ -152,10 +247,14 @@ void PepperDeviceEnumerationEventHandler::NotifyDeviceOpened(
return;
}
- PepperPluginDelegateImpl::OpenDeviceCallback callback = iter->second;
+ OpenDeviceCallback callback = iter->second;
open_callbacks_.erase(iter);
callback.Run(request_id, succeeded, label);
}
+RenderViewImpl* PepperDeviceEnumerationEventHandler::GetRenderViewImpl() {
+ return static_cast<RenderViewImpl*>(render_view());
+}
+
} // namespace content
diff --git a/content/renderer/pepper/pepper_device_enumeration_event_handler.h b/content/renderer/pepper/pepper_device_enumeration_event_handler.h
index 05835ed..02b44a3 100644
--- a/content/renderer/pepper/pepper_device_enumeration_event_handler.h
+++ b/content/renderer/pepper/pepper_device_enumeration_event_handler.h
@@ -9,25 +9,50 @@
#include "base/memory/weak_ptr.h"
#include "content/renderer/media/media_stream_dispatcher_eventhandler.h"
-#include "content/renderer/pepper/pepper_plugin_delegate_impl.h"
-#include "content/renderer/pepper/plugin_delegate.h"
+#include "content/renderer/pepper/pepper_device_enumeration_host_helper.h"
+#include "content/public/renderer/render_view_observer_tracker.h"
+#include "content/public/renderer/render_view_observer.h"
namespace content {
+class RenderViewImpl;
class PepperDeviceEnumerationEventHandler
: public MediaStreamDispatcherEventHandler,
+ public PepperDeviceEnumerationHostHelper::Delegate,
+ public RenderViewObserver,
+ public RenderViewObserverTracker<PepperDeviceEnumerationEventHandler>,
public base::SupportsWeakPtr<PepperDeviceEnumerationEventHandler> {
public:
- PepperDeviceEnumerationEventHandler();
+ static PepperDeviceEnumerationEventHandler* GetForRenderView(
+ RenderView* render_view);
virtual ~PepperDeviceEnumerationEventHandler();
- int RegisterEnumerateDevicesCallback(
- const PluginDelegate::EnumerateDevicesCallback& callback);
- void UnregisterEnumerateDevicesCallback(int request_id);
-
- int RegisterOpenDeviceCallback(
- const PepperPluginDelegateImpl::OpenDeviceCallback& callback);
- void UnregisterOpenDeviceCallback(int request_id);
+ // PepperDeviceEnumerationHostHelper::Delegate implementation:
+ virtual int EnumerateDevices(
+ PP_DeviceType_Dev type,
+ const EnumerateDevicesCallback& callback) OVERRIDE;
+ virtual void StopEnumerateDevices(int request_id) OVERRIDE;
+
+ typedef base::Callback<void (int /* request_id */,
+ bool /* succeeded */,
+ const std::string& /* label */)>
+ OpenDeviceCallback;
+
+ // Opens the specified device. The request ID passed into the callback will be
+ // the same as the return value. If successful, the label passed into the
+ // callback identifies a audio/video steam, which can be used to call
+ // CloseDevice() and GetSesssionID().
+ int OpenDevice(PP_DeviceType_Dev type,
+ const std::string& device_id,
+ const GURL& document_url,
+ const OpenDeviceCallback& callback);
+ // Cancels an request to open device, using the request ID returned by
+ // OpenDevice(). It is guaranteed that the callback passed into OpenDevice()
+ // won't be called afterwards.
+ void CancelOpenDevice(int request_id);
+ void CloseDevice(const std::string& label);
+ // Gets audio/video session ID given a label.
+ int GetSessionID(PP_DeviceType_Dev type, const std::string& label);
// MediaStreamDispatcherEventHandler implementation.
virtual void OnStreamGenerated(
@@ -51,6 +76,8 @@ class PepperDeviceEnumerationEventHandler
static PP_DeviceType_Dev FromMediaStreamType(MediaStreamType type);
private:
+ PepperDeviceEnumerationEventHandler(RenderView* render_view);
+
void NotifyDevicesEnumerated(
int request_id,
bool succeeded,
@@ -60,14 +87,14 @@ class PepperDeviceEnumerationEventHandler
bool succeeded,
const std::string& label);
+ RenderViewImpl* GetRenderViewImpl();
+
int next_id_;
- typedef std::map<int, PluginDelegate::EnumerateDevicesCallback>
- EnumerateCallbackMap;
+ typedef std::map<int, EnumerateDevicesCallback> EnumerateCallbackMap;
EnumerateCallbackMap enumerate_callbacks_;
- typedef std::map<int, PepperPluginDelegateImpl::OpenDeviceCallback>
- OpenCallbackMap;
+ typedef std::map<int, OpenDeviceCallback> OpenCallbackMap;
OpenCallbackMap open_callbacks_;
DISALLOW_COPY_AND_ASSIGN(PepperDeviceEnumerationEventHandler);
diff --git a/content/renderer/pepper/pepper_device_enumeration_host_helper.cc b/content/renderer/pepper/pepper_device_enumeration_host_helper.cc
index ba281ea..9ec6373 100644
--- a/content/renderer/pepper/pepper_device_enumeration_host_helper.cc
+++ b/content/renderer/pepper/pepper_device_enumeration_host_helper.cc
@@ -8,7 +8,6 @@
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
-#include "content/renderer/pepper/plugin_delegate.h"
#include "ipc/ipc_message.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/host/dispatch_host_message.h"
@@ -27,27 +26,25 @@ class PepperDeviceEnumerationHostHelper::ScopedRequest
: public base::SupportsWeakPtr<ScopedRequest> {
public:
// |owner| must outlive this object.
- ScopedRequest(PepperDeviceEnumerationHostHelper* owner,
- const PluginDelegate::EnumerateDevicesCallback& callback)
+ ScopedRequest(
+ PepperDeviceEnumerationHostHelper* owner,
+ const Delegate::EnumerateDevicesCallback& callback)
: owner_(owner),
callback_(callback),
requested_(false),
request_id_(0),
sync_call_(false) {
- PluginDelegate* plugin_delegate = owner_->delegate_->GetPluginDelegate();
- if (!plugin_delegate)
- return;
-
requested_ = true;
- // Note that the callback passed into PluginDelegate::EnumerateDevices() may
- // be called synchronously. In that case, |request_id_| hasn't been updated
+ // Note that the callback passed into
+ // PepperDeviceEnumerationHostHelper::Delegate::EnumerateDevices() may be
+ // called synchronously. In that case, |request_id_| hasn't been updated
// when the callback is called. Moreover, |callback| may destroy this
// object. So we don't pass in |callback| directly. Instead, we use
// EnumerateDevicesCallbackBody() to ensure that we always call |callback|
// asynchronously.
sync_call_ = true;
- request_id_ = plugin_delegate->EnumerateDevices(
+ request_id_ = owner_->delegate_->EnumerateDevices(
owner_->device_type_,
base::Bind(&ScopedRequest::EnumerateDevicesCallbackBody, AsWeakPtr()));
sync_call_ = false;
@@ -55,9 +52,7 @@ class PepperDeviceEnumerationHostHelper::ScopedRequest
~ScopedRequest() {
if (requested_) {
- PluginDelegate* plugin_delegate = owner_->delegate_->GetPluginDelegate();
- if (plugin_delegate)
- plugin_delegate->StopEnumerateDevices(request_id_);
+ owner_->delegate_->StopEnumerateDevices(request_id_);
}
}
@@ -84,7 +79,8 @@ class PepperDeviceEnumerationHostHelper::ScopedRequest
}
PepperDeviceEnumerationHostHelper* owner_;
- PluginDelegate::EnumerateDevicesCallback callback_;
+ PepperDeviceEnumerationHostHelper::Delegate::EnumerateDevicesCallback
+ callback_;
bool requested_;
int request_id_;
bool sync_call_;
diff --git a/content/renderer/pepper/pepper_device_enumeration_host_helper.h b/content/renderer/pepper/pepper_device_enumeration_host_helper.h
index d7e92c7..424475b 100644
--- a/content/renderer/pepper/pepper_device_enumeration_host_helper.h
+++ b/content/renderer/pepper/pepper_device_enumeration_host_helper.h
@@ -8,6 +8,7 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/callback_forward.h"
#include "base/memory/scoped_ptr.h"
#include "content/common/content_export.h"
#include "ppapi/c/dev/ppb_device_ref_dev.h"
@@ -27,7 +28,6 @@ class Message;
}
namespace content {
-class PluginDelegate;
// Resource hosts that support device enumeration can use this class to filter
// and process PpapiHostMsg_DeviceEnumeration_* messages.
@@ -40,9 +40,19 @@ class CONTENT_EXPORT PepperDeviceEnumerationHostHelper {
public:
virtual ~Delegate() {}
- // TODO(yzshen): Move the relevant functionality out of PluginDelegate and
- // get rid of this method.
- virtual PluginDelegate* GetPluginDelegate() = 0;
+ typedef base::Callback<
+ void (int /* request_id */,
+ bool /* succeeded */,
+ const std::vector< ::ppapi::DeviceRefData>& /* devices */)>
+ EnumerateDevicesCallback;
+
+ // Enumerates devices of the specified type. The request ID passed into the
+ // callback will be the same as the return value.
+ virtual int EnumerateDevices(PP_DeviceType_Dev type,
+ const EnumerateDevicesCallback& callback) = 0;
+ // Stop enumerating devices of the specified |request_id|. The |request_id|
+ // is the return value of EnumerateDevicesCallback.
+ virtual void StopEnumerateDevices(int request_id) = 0;
};
// |resource_host| and |delegate| must outlive this object.
diff --git a/content/renderer/pepper/pepper_device_enumeration_host_helper_unittest.cc b/content/renderer/pepper/pepper_device_enumeration_host_helper_unittest.cc
index a6ff34b..895bdd8 100644
--- a/content/renderer/pepper/pepper_device_enumeration_host_helper_unittest.cc
+++ b/content/renderer/pepper/pepper_device_enumeration_host_helper_unittest.cc
@@ -7,7 +7,6 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
-#include "content/renderer/pepper/mock_plugin_delegate.h"
#include "content/renderer/pepper/pepper_device_enumeration_host_helper.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/host/host_message_context.h"
@@ -24,12 +23,12 @@ namespace content {
namespace {
-class TestPluginDelegate : public MockPluginDelegate {
+class TestDelegate : public PepperDeviceEnumerationHostHelper::Delegate {
public:
- TestPluginDelegate() : last_used_id_(0) {
+ TestDelegate() : last_used_id_(0) {
}
- virtual ~TestPluginDelegate() {
+ virtual ~TestDelegate() {
CHECK(callbacks_.empty());
}
@@ -70,38 +69,15 @@ class TestPluginDelegate : public MockPluginDelegate {
std::map<int, EnumerateDevicesCallback> callbacks_;
int last_used_id_;
- DISALLOW_COPY_AND_ASSIGN(TestPluginDelegate);
-};
-
-class TestResourceHost : public ppapi::host::ResourceHost,
- public PepperDeviceEnumerationHostHelper::Delegate {
- public:
- TestResourceHost(ppapi::host::PpapiHost* host,
- PP_Instance instance,
- PP_Resource resource,
- PluginDelegate* delegate)
- : ResourceHost(host, instance, resource),
- delegate_(delegate) {
- }
-
- virtual ~TestResourceHost() {}
-
- virtual PluginDelegate* GetPluginDelegate() OVERRIDE {
- return delegate_;
- }
-
- private:
- PluginDelegate* delegate_;
-
- DISALLOW_COPY_AND_ASSIGN(TestResourceHost);
+ DISALLOW_COPY_AND_ASSIGN(TestDelegate);
};
class PepperDeviceEnumerationHostHelperTest : public testing::Test {
protected:
PepperDeviceEnumerationHostHelperTest()
: ppapi_host_(&sink_, ppapi::PpapiPermissions()),
- resource_host_(&ppapi_host_, 12345, 67890, &delegate_),
- device_enumeration_(&resource_host_, &resource_host_,
+ resource_host_(&ppapi_host_, 12345, 67890),
+ device_enumeration_(&resource_host_, &delegate_,
PP_DEVICETYPE_DEV_AUDIOCAPTURE) {
}
@@ -139,10 +115,10 @@ class PepperDeviceEnumerationHostHelperTest : public testing::Test {
EXPECT_EQ(expected, reply_data);
}
- TestPluginDelegate delegate_;
+ TestDelegate delegate_;
ppapi::proxy::ResourceMessageTestSink sink_;
ppapi::host::PpapiHost ppapi_host_;
- TestResourceHost resource_host_;
+ ppapi::host::ResourceHost resource_host_;
PepperDeviceEnumerationHostHelper device_enumeration_;
private:
diff --git a/content/renderer/pepper/pepper_platform_audio_input_impl.cc b/content/renderer/pepper/pepper_platform_audio_input.cc
index 68ce940..aa5c1c6 100644
--- a/content/renderer/pepper/pepper_platform_audio_input_impl.cc
+++ b/content/renderer/pepper/pepper_platform_audio_input.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/renderer/pepper/pepper_platform_audio_input_impl.h"
+#include "content/renderer/pepper/pepper_platform_audio_input.h"
#include "base/bind.h"
#include "base/logging.h"
@@ -10,8 +10,10 @@
#include "build/build_config.h"
#include "content/child/child_process.h"
#include "content/renderer/media/audio_input_message_filter.h"
-#include "content/renderer/pepper/pepper_plugin_delegate_impl.h"
+#include "content/renderer/pepper/pepper_audio_input_host.h"
+#include "content/renderer/pepper/pepper_device_enumeration_event_handler.h"
#include "content/renderer/render_thread_impl.h"
+#include "content/renderer/render_view_impl.h"
#include "media/audio/audio_manager_base.h"
#include "ppapi/shared_impl/ppb_audio_config_shared.h"
#include "url/gurl.h"
@@ -19,42 +21,42 @@
namespace content {
// static
-PepperPlatformAudioInputImpl* PepperPlatformAudioInputImpl::Create(
- const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate,
+PepperPlatformAudioInput* PepperPlatformAudioInput::Create(
+ const base::WeakPtr<RenderViewImpl>& render_view,
const std::string& device_id,
const GURL& document_url,
int sample_rate,
int frames_per_buffer,
- PluginDelegate::PlatformAudioInputClient* client) {
- scoped_refptr<PepperPlatformAudioInputImpl> audio_input(
- new PepperPlatformAudioInputImpl());
- if (audio_input->Initialize(plugin_delegate, device_id, document_url,
+ PepperAudioInputHost* client) {
+ scoped_refptr<PepperPlatformAudioInput> audio_input(
+ new PepperPlatformAudioInput());
+ if (audio_input->Initialize(render_view, device_id, document_url,
sample_rate, frames_per_buffer, client)) {
// Balanced by Release invoked in
- // PepperPlatformAudioInputImpl::ShutDownOnIOThread().
+ // PepperPlatformAudioInput::ShutDownOnIOThread().
audio_input->AddRef();
return audio_input.get();
}
return NULL;
}
-void PepperPlatformAudioInputImpl::StartCapture() {
+void PepperPlatformAudioInput::StartCapture() {
DCHECK(main_message_loop_proxy_->BelongsToCurrentThread());
io_message_loop_proxy_->PostTask(
FROM_HERE,
- base::Bind(&PepperPlatformAudioInputImpl::StartCaptureOnIOThread, this));
+ base::Bind(&PepperPlatformAudioInput::StartCaptureOnIOThread, this));
}
-void PepperPlatformAudioInputImpl::StopCapture() {
+void PepperPlatformAudioInput::StopCapture() {
DCHECK(main_message_loop_proxy_->BelongsToCurrentThread());
io_message_loop_proxy_->PostTask(
FROM_HERE,
- base::Bind(&PepperPlatformAudioInputImpl::StopCaptureOnIOThread, this));
+ base::Bind(&PepperPlatformAudioInput::StopCaptureOnIOThread, this));
}
-void PepperPlatformAudioInputImpl::ShutDown() {
+void PepperPlatformAudioInput::ShutDown() {
DCHECK(main_message_loop_proxy_->BelongsToCurrentThread());
// Make sure we don't call shutdown more than once.
@@ -66,10 +68,10 @@ void PepperPlatformAudioInputImpl::ShutDown() {
client_ = NULL;
io_message_loop_proxy_->PostTask(
FROM_HERE,
- base::Bind(&PepperPlatformAudioInputImpl::ShutDownOnIOThread, this));
+ base::Bind(&PepperPlatformAudioInput::ShutDownOnIOThread, this));
}
-void PepperPlatformAudioInputImpl::OnStreamCreated(
+void PepperPlatformAudioInput::OnStreamCreated(
base::SharedMemoryHandle handle,
base::SyncSocket::Handle socket_handle,
int length,
@@ -91,7 +93,7 @@ void PepperPlatformAudioInputImpl::OnStreamCreated(
// cleaned up on the main thread.
main_message_loop_proxy_->PostTask(
FROM_HERE,
- base::Bind(&PepperPlatformAudioInputImpl::OnStreamCreated, this,
+ base::Bind(&PepperPlatformAudioInput::OnStreamCreated, this,
handle, socket_handle, length, total_segments));
} else {
// Must dereference the client only on the main thread. Shutdown may have
@@ -106,17 +108,17 @@ void PepperPlatformAudioInputImpl::OnStreamCreated(
}
}
-void PepperPlatformAudioInputImpl::OnVolume(double volume) {}
+void PepperPlatformAudioInput::OnVolume(double volume) {}
-void PepperPlatformAudioInputImpl::OnStateChanged(
+void PepperPlatformAudioInput::OnStateChanged(
media::AudioInputIPCDelegate::State state) {
}
-void PepperPlatformAudioInputImpl::OnIPCClosed() {
+void PepperPlatformAudioInput::OnIPCClosed() {
ipc_.reset();
}
-PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() {
+PepperPlatformAudioInput::~PepperPlatformAudioInput() {
// Make sure we have been shut down. Warning: this may happen on the I/O
// thread!
// Although these members should be accessed on a specific thread (either the
@@ -128,7 +130,7 @@ PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() {
DCHECK(!pending_open_device_);
}
-PepperPlatformAudioInputImpl::PepperPlatformAudioInputImpl()
+PepperPlatformAudioInput::PepperPlatformAudioInput()
: client_(NULL),
main_message_loop_proxy_(base::MessageLoopProxy::current()),
io_message_loop_proxy_(ChildProcess::current()->io_message_loop_proxy()),
@@ -137,22 +139,22 @@ PepperPlatformAudioInputImpl::PepperPlatformAudioInputImpl()
pending_open_device_id_(-1) {
}
-bool PepperPlatformAudioInputImpl::Initialize(
- const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate,
+bool PepperPlatformAudioInput::Initialize(
+ const base::WeakPtr<RenderViewImpl>& render_view,
const std::string& device_id,
const GURL& document_url,
int sample_rate,
int frames_per_buffer,
- PluginDelegate::PlatformAudioInputClient* client) {
+ PepperAudioInputHost* client) {
DCHECK(main_message_loop_proxy_->BelongsToCurrentThread());
- if (!plugin_delegate.get() || !client)
+ if (!render_view.get() || !client)
return false;
ipc_ = RenderThreadImpl::current()->audio_input_message_filter()->
- CreateAudioInputIPC(plugin_delegate->GetRoutingID());
+ CreateAudioInputIPC(render_view->GetRoutingID());
- plugin_delegate_ = plugin_delegate;
+ render_view_ = render_view;
client_ = client;
params_.Reset(media::AudioParameters::AUDIO_PCM_LINEAR,
@@ -162,17 +164,17 @@ bool PepperPlatformAudioInputImpl::Initialize(
// We need to open the device and obtain the label and session ID before
// initializing.
- pending_open_device_id_ = plugin_delegate_->OpenDevice(
+ pending_open_device_id_ = GetHandler()->OpenDevice(
PP_DEVICETYPE_DEV_AUDIOCAPTURE,
device_id.empty() ? media::AudioManagerBase::kDefaultDeviceId : device_id,
document_url,
- base::Bind(&PepperPlatformAudioInputImpl::OnDeviceOpened, this));
+ base::Bind(&PepperPlatformAudioInput::OnDeviceOpened, this));
pending_open_device_ = true;
return true;
}
-void PepperPlatformAudioInputImpl::InitializeOnIOThread(int session_id) {
+void PepperPlatformAudioInput::InitializeOnIOThread(int session_id) {
DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
if (!ipc_)
@@ -183,14 +185,14 @@ void PepperPlatformAudioInputImpl::InitializeOnIOThread(int session_id) {
ipc_->CreateStream(this, session_id, params_, false, 1);
}
-void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() {
+void PepperPlatformAudioInput::StartCaptureOnIOThread() {
DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
if (ipc_)
ipc_->RecordStream();
}
-void PepperPlatformAudioInputImpl::StopCaptureOnIOThread() {
+void PepperPlatformAudioInput::StopCaptureOnIOThread() {
DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
// TODO(yzshen): We cannot re-start capturing if the stream is closed.
@@ -200,37 +202,37 @@ void PepperPlatformAudioInputImpl::StopCaptureOnIOThread() {
ipc_.reset();
}
-void PepperPlatformAudioInputImpl::ShutDownOnIOThread() {
+void PepperPlatformAudioInput::ShutDownOnIOThread() {
DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
StopCaptureOnIOThread();
main_message_loop_proxy_->PostTask(
FROM_HERE,
- base::Bind(&PepperPlatformAudioInputImpl::CloseDevice, this));
+ base::Bind(&PepperPlatformAudioInput::CloseDevice, this));
Release(); // Release for the delegate, balances out the reference taken in
- // PepperPluginDelegateImpl::CreateAudioInput.
+ // PepperPlatformAudioInput::Create.
}
-void PepperPlatformAudioInputImpl::OnDeviceOpened(int request_id,
- bool succeeded,
- const std::string& label) {
+void PepperPlatformAudioInput::OnDeviceOpened(int request_id,
+ bool succeeded,
+ const std::string& label) {
DCHECK(main_message_loop_proxy_->BelongsToCurrentThread());
pending_open_device_ = false;
pending_open_device_id_ = -1;
- if (succeeded && plugin_delegate_.get()) {
+ if (succeeded && render_view_.get()) {
DCHECK(!label.empty());
label_ = label;
if (client_) {
- int session_id = plugin_delegate_->GetSessionID(
+ int session_id = GetHandler()->GetSessionID(
PP_DEVICETYPE_DEV_AUDIOCAPTURE, label);
io_message_loop_proxy_->PostTask(
FROM_HERE,
- base::Bind(&PepperPlatformAudioInputImpl::InitializeOnIOThread,
+ base::Bind(&PepperPlatformAudioInput::InitializeOnIOThread,
this, session_id));
} else {
// Shutdown has occurred.
@@ -241,27 +243,32 @@ void PepperPlatformAudioInputImpl::OnDeviceOpened(int request_id,
}
}
-void PepperPlatformAudioInputImpl::CloseDevice() {
+void PepperPlatformAudioInput::CloseDevice() {
DCHECK(main_message_loop_proxy_->BelongsToCurrentThread());
- if (plugin_delegate_.get()) {
+ if (render_view_.get()) {
if (!label_.empty()) {
- plugin_delegate_->CloseDevice(label_);
+ GetHandler()->CloseDevice(label_);
label_.clear();
}
if (pending_open_device_) {
- plugin_delegate_->CancelOpenDevice(pending_open_device_id_);
+ GetHandler()->CancelOpenDevice(pending_open_device_id_);
pending_open_device_ = false;
pending_open_device_id_ = -1;
}
}
}
-void PepperPlatformAudioInputImpl::NotifyStreamCreationFailed() {
+void PepperPlatformAudioInput::NotifyStreamCreationFailed() {
DCHECK(main_message_loop_proxy_->BelongsToCurrentThread());
if (client_)
client_->StreamCreationFailed();
}
+PepperDeviceEnumerationEventHandler* PepperPlatformAudioInput::GetHandler() {
+ return PepperDeviceEnumerationEventHandler::GetForRenderView(
+ render_view_.get());
+}
+
} // namespace content
diff --git a/content/renderer/pepper/pepper_platform_audio_input_impl.h b/content/renderer/pepper/pepper_platform_audio_input.h
index 3c18e7c..5b96eb0 100644
--- a/content/renderer/pepper/pepper_platform_audio_input_impl.h
+++ b/content/renderer/pepper/pepper_platform_audio_input.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_IMPL_H_
-#define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_IMPL_H_
+#ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_H_
+#define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_H_
#include <string>
@@ -12,47 +12,51 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "content/renderer/pepper/plugin_delegate.h"
#include "media/audio/audio_input_ipc.h"
#include "media/audio/audio_parameters.h"
class GURL;
+namespace base {
+class MessageLoopProxy;
+}
+
namespace media {
class AudioParameters;
}
namespace content {
-class PepperPluginDelegateImpl;
+class PepperAudioInputHost;
+class PepperDeviceEnumerationEventHandler;
+class RenderViewImpl;
-// PepperPlatformAudioInputImpl is operated on two threads: the main thread (the
+// PepperPlatformAudioInput is operated on two threads: the main thread (the
// thread on which objects are created) and the I/O thread. All public methods,
// except the destructor, must be called on the main thread. The notifications
-// to the users of this class (via the PlatformAudioInputClient interface) are
-// also sent on the main thread. Internally, this class sends audio input IPC
-// messages and receives media::AudioInputIPCDelegate notifications on the
-// I/O thread.
-
-class PepperPlatformAudioInputImpl
- : public PluginDelegate::PlatformAudioInput,
- public media::AudioInputIPCDelegate,
- public base::RefCountedThreadSafe<PepperPlatformAudioInputImpl> {
+// to the users of this class (i.e. PepperAudioInputHost) are also sent on the
+// main thread. Internally, this class sends audio input IPC messages and
+// receives media::AudioInputIPCDelegate notifications on the I/O thread.
+
+class PepperPlatformAudioInput
+ : public media::AudioInputIPCDelegate,
+ public base::RefCountedThreadSafe<PepperPlatformAudioInput> {
public:
// Factory function, returns NULL on failure. StreamCreated() will be called
// when the stream is created.
- static PepperPlatformAudioInputImpl* Create(
- const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate,
+ static PepperPlatformAudioInput* Create(
+ const base::WeakPtr<RenderViewImpl>& render_view,
const std::string& device_id,
const GURL& document_url,
int sample_rate,
int frames_per_buffer,
- PluginDelegate::PlatformAudioInputClient* client);
+ PepperAudioInputHost* client);
- // PlatformAudioInput implementation (called on main thread).
- virtual void StartCapture() OVERRIDE;
- virtual void StopCapture() OVERRIDE;
- virtual void ShutDown() OVERRIDE;
+ // Called on main thread.
+ void StartCapture();
+ void StopCapture();
+ // Closes the stream. Make sure to call this before the object is destructed.
+ void ShutDown();
// media::AudioInputIPCDelegate.
virtual void OnStreamCreated(base::SharedMemoryHandle handle,
@@ -65,20 +69,20 @@ class PepperPlatformAudioInputImpl
virtual void OnIPCClosed() OVERRIDE;
protected:
- virtual ~PepperPlatformAudioInputImpl();
+ virtual ~PepperPlatformAudioInput();
private:
- friend class base::RefCountedThreadSafe<PepperPlatformAudioInputImpl>;
+ friend class base::RefCountedThreadSafe<PepperPlatformAudioInput>;
- PepperPlatformAudioInputImpl();
+ PepperPlatformAudioInput();
bool Initialize(
- const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate,
+ const base::WeakPtr<RenderViewImpl>& render_view,
const std::string& device_id,
const GURL& document_url,
int sample_rate,
int frames_per_buffer,
- PluginDelegate::PlatformAudioInputClient* client);
+ PepperAudioInputHost* client);
// I/O thread backends to above functions.
void InitializeOnIOThread(int session_id);
@@ -92,9 +96,11 @@ class PepperPlatformAudioInputImpl
void CloseDevice();
void NotifyStreamCreationFailed();
+ PepperDeviceEnumerationEventHandler* GetHandler();
+
// The client to notify when the stream is created. THIS MUST ONLY BE
// ACCESSED ON THE MAIN THREAD.
- PluginDelegate::PlatformAudioInputClient* client_;
+ PepperAudioInputHost* client_;
// Used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE
// I/O THREAD.
@@ -104,7 +110,7 @@ class PepperPlatformAudioInputImpl
scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
// THIS MUST ONLY BE ACCESSED ON THE MAIN THREAD.
- base::WeakPtr<PepperPluginDelegateImpl> plugin_delegate_;
+ base::WeakPtr<RenderViewImpl> render_view_;
// The unique ID to identify the opened device. THIS MUST ONLY BE ACCESSED ON
// THE MAIN THREAD.
@@ -124,9 +130,9 @@ class PepperPlatformAudioInputImpl
// THIS MUST ONLY BE ACCESSED ON THE MAIN THREAD.
int pending_open_device_id_;
- DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioInputImpl);
+ DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioInput);
};
} // namespace content
-#endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_IMPL_H_
+#endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_H_
diff --git a/content/renderer/pepper/pepper_platform_video_capture_impl.cc b/content/renderer/pepper/pepper_platform_video_capture.cc
index fd121a6..4dc7d6d 100644
--- a/content/renderer/pepper/pepper_platform_video_capture_impl.cc
+++ b/content/renderer/pepper/pepper_platform_video_capture.cc
@@ -2,25 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/renderer/pepper/pepper_platform_video_capture_impl.h"
+#include "content/renderer/pepper/pepper_platform_video_capture.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_loop_proxy.h"
#include "content/renderer/media/video_capture_impl_manager.h"
+#include "content/renderer/pepper/pepper_device_enumeration_event_handler.h"
#include "content/renderer/pepper/pepper_plugin_delegate_impl.h"
+#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/video/capture/video_capture_proxy.h"
#include "url/gurl.h"
namespace content {
-PepperPlatformVideoCaptureImpl::PepperPlatformVideoCaptureImpl(
- const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate,
+PepperPlatformVideoCapture::PepperPlatformVideoCapture(
+ const base::WeakPtr<RenderViewImpl>& render_view,
const std::string& device_id,
const GURL& document_url,
- PluginDelegate::PlatformVideoCaptureEventHandler* handler)
- : plugin_delegate_(plugin_delegate),
+ PepperVideoCaptureHost* handler)
+ : render_view_(render_view),
device_id_(device_id),
session_id_(0),
handler_proxy_(new media::VideoCaptureHandlerProxy(
@@ -32,17 +35,17 @@ PepperPlatformVideoCaptureImpl::PepperPlatformVideoCaptureImpl(
pending_open_device_id_(-1) {
// We need to open the device and obtain the label and session ID before
// initializing.
- if (plugin_delegate_.get()) {
- pending_open_device_id_ = plugin_delegate_->OpenDevice(
+ if (render_view_.get()) {
+ pending_open_device_id_ = GetDeviceEnumerationEventHandler()->OpenDevice(
PP_DEVICETYPE_DEV_VIDEOCAPTURE,
device_id,
document_url,
- base::Bind(&PepperPlatformVideoCaptureImpl::OnDeviceOpened, this));
+ base::Bind(&PepperPlatformVideoCapture::OnDeviceOpened, this));
pending_open_device_ = true;
}
}
-void PepperPlatformVideoCaptureImpl::StartCapture(
+void PepperPlatformVideoCapture::StartCapture(
media::VideoCapture::EventHandler* handler,
const media::VideoCaptureCapability& capability) {
DCHECK(handler == handler_);
@@ -57,7 +60,7 @@ void PepperPlatformVideoCaptureImpl::StartCapture(
}
}
-void PepperPlatformVideoCaptureImpl::StopCapture(
+void PepperPlatformVideoCapture::StopCapture(
media::VideoCapture::EventHandler* handler) {
DCHECK(handler == handler_);
if (!unbalanced_start_)
@@ -69,29 +72,29 @@ void PepperPlatformVideoCaptureImpl::StopCapture(
}
}
-void PepperPlatformVideoCaptureImpl::FeedBuffer(
+void PepperPlatformVideoCapture::FeedBuffer(
scoped_refptr<VideoFrameBuffer> buffer) {
if (video_capture_)
video_capture_->FeedBuffer(buffer);
}
-bool PepperPlatformVideoCaptureImpl::CaptureStarted() {
+bool PepperPlatformVideoCapture::CaptureStarted() {
return handler_proxy_->state().started;
}
-int PepperPlatformVideoCaptureImpl::CaptureWidth() {
+int PepperPlatformVideoCapture::CaptureWidth() {
return handler_proxy_->state().width;
}
-int PepperPlatformVideoCaptureImpl::CaptureHeight() {
+int PepperPlatformVideoCapture::CaptureHeight() {
return handler_proxy_->state().height;
}
-int PepperPlatformVideoCaptureImpl::CaptureFrameRate() {
+int PepperPlatformVideoCapture::CaptureFrameRate() {
return handler_proxy_->state().frame_rate;
}
-void PepperPlatformVideoCaptureImpl::DetachEventHandler() {
+void PepperPlatformVideoCapture::DetachEventHandler() {
handler_ = NULL;
StopCapture(NULL);
@@ -102,49 +105,49 @@ void PepperPlatformVideoCaptureImpl::DetachEventHandler() {
video_capture_ = NULL;
}
- if (plugin_delegate_.get()) {
+ if (render_view_.get()) {
if (!label_.empty()) {
- plugin_delegate_->CloseDevice(label_);
+ GetDeviceEnumerationEventHandler()->CloseDevice(label_);
label_.clear();
}
if (pending_open_device_) {
- plugin_delegate_->CancelOpenDevice(pending_open_device_id_);
+ GetDeviceEnumerationEventHandler()->CancelOpenDevice(
+ pending_open_device_id_);
pending_open_device_ = false;
pending_open_device_id_ = -1;
}
}
}
-void PepperPlatformVideoCaptureImpl::OnStarted(VideoCapture* capture) {
+void PepperPlatformVideoCapture::OnStarted(VideoCapture* capture) {
if (handler_)
handler_->OnStarted(capture);
}
-void PepperPlatformVideoCaptureImpl::OnStopped(VideoCapture* capture) {
+void PepperPlatformVideoCapture::OnStopped(VideoCapture* capture) {
if (handler_)
handler_->OnStopped(capture);
}
-void PepperPlatformVideoCaptureImpl::OnPaused(VideoCapture* capture) {
+void PepperPlatformVideoCapture::OnPaused(VideoCapture* capture) {
if (handler_)
handler_->OnPaused(capture);
}
-void PepperPlatformVideoCaptureImpl::OnError(
- VideoCapture* capture,
- int error_code) {
+void PepperPlatformVideoCapture::OnError(VideoCapture* capture,
+ int error_code) {
if (handler_)
handler_->OnError(capture, error_code);
}
-void PepperPlatformVideoCaptureImpl::OnRemoved(VideoCapture* capture) {
+void PepperPlatformVideoCapture::OnRemoved(VideoCapture* capture) {
if (handler_)
handler_->OnRemoved(capture);
Release(); // Balance the AddRef() in StartCapture().
}
-void PepperPlatformVideoCaptureImpl::OnBufferReady(
+void PepperPlatformVideoCapture::OnBufferReady(
VideoCapture* capture,
scoped_refptr<VideoFrameBuffer> buffer) {
if (handler_) {
@@ -156,36 +159,36 @@ void PepperPlatformVideoCaptureImpl::OnBufferReady(
}
}
-void PepperPlatformVideoCaptureImpl::OnDeviceInfoReceived(
+void PepperPlatformVideoCapture::OnDeviceInfoReceived(
VideoCapture* capture,
const media::VideoCaptureParams& device_info) {
if (handler_)
handler_->OnDeviceInfoReceived(capture, device_info);
}
-PepperPlatformVideoCaptureImpl::~PepperPlatformVideoCaptureImpl() {
+PepperPlatformVideoCapture::~PepperPlatformVideoCapture() {
DCHECK(!video_capture_);
DCHECK(label_.empty());
DCHECK(!pending_open_device_);
}
-void PepperPlatformVideoCaptureImpl::Initialize() {
+void PepperPlatformVideoCapture::Initialize() {
VideoCaptureImplManager* manager =
RenderThreadImpl::current()->video_capture_impl_manager();
video_capture_ = manager->AddDevice(session_id_, handler_proxy_.get());
}
-void PepperPlatformVideoCaptureImpl::OnDeviceOpened(int request_id,
- bool succeeded,
- const std::string& label) {
+void PepperPlatformVideoCapture::OnDeviceOpened(int request_id,
+ bool succeeded,
+ const std::string& label) {
pending_open_device_ = false;
pending_open_device_id_ = -1;
- succeeded = succeeded && plugin_delegate_.get();
+ succeeded = succeeded && render_view_.get();
if (succeeded) {
label_ = label;
- session_id_ = plugin_delegate_->GetSessionID(PP_DEVICETYPE_DEV_VIDEOCAPTURE,
- label);
+ session_id_ = GetDeviceEnumerationEventHandler()->GetSessionID(
+ PP_DEVICETYPE_DEV_VIDEOCAPTURE, label);
Initialize();
}
@@ -193,4 +196,10 @@ void PepperPlatformVideoCaptureImpl::OnDeviceOpened(int request_id,
handler_->OnInitialized(this, succeeded);
}
+PepperDeviceEnumerationEventHandler*
+ PepperPlatformVideoCapture::GetDeviceEnumerationEventHandler() {
+ return PepperDeviceEnumerationEventHandler::GetForRenderView(
+ render_view_.get());
+}
+
} // namespace content
diff --git a/content/renderer/pepper/pepper_platform_video_capture_impl.h b/content/renderer/pepper/pepper_platform_video_capture.h
index 40dc8e0..fefcc13 100644
--- a/content/renderer/pepper/pepper_platform_video_capture_impl.h
+++ b/content/renderer/pepper/pepper_platform_video_capture.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_IMPL_H_
-#define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_IMPL_H_
+#ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_H_
+#define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_H_
#include <string>
@@ -11,7 +11,6 @@
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "content/renderer/pepper/plugin_delegate.h"
#include "media/video/capture/video_capture.h"
#include "media/video/capture/video_capture_types.h"
@@ -22,20 +21,26 @@ class VideoCaptureHandlerProxy;
}
namespace content {
-
+class PepperDeviceEnumerationEventHandler;
class PepperPluginDelegateImpl;
+class PepperVideoCaptureHost;
+class RenderViewImpl;
-class PepperPlatformVideoCaptureImpl
- : public PluginDelegate::PlatformVideoCapture,
+class PepperPlatformVideoCapture
+ : public media::VideoCapture,
+ public base::RefCounted<PepperPlatformVideoCapture>,
public media::VideoCapture::EventHandler {
public:
- PepperPlatformVideoCaptureImpl(
- const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate,
+ PepperPlatformVideoCapture(
+ const base::WeakPtr<RenderViewImpl>& render_view,
const std::string& device_id,
const GURL& document_url,
- PluginDelegate::PlatformVideoCaptureEventHandler* handler);
+ PepperVideoCaptureHost* handler);
+
+ // Detaches the event handler and stops sending notifications to it.
+ void DetachEventHandler();
- // PluginDelegate::PlatformVideoCapture implementation.
+ // media::VideoCapture implementation.
virtual void StartCapture(
media::VideoCapture::EventHandler* handler,
const media::VideoCaptureCapability& capability) OVERRIDE;
@@ -45,7 +50,6 @@ class PepperPlatformVideoCaptureImpl
virtual int CaptureWidth() OVERRIDE;
virtual int CaptureHeight() OVERRIDE;
virtual int CaptureFrameRate() OVERRIDE;
- virtual void DetachEventHandler() OVERRIDE;
// media::VideoCapture::EventHandler implementation
virtual void OnStarted(VideoCapture* capture) OVERRIDE;
@@ -60,7 +64,8 @@ class PepperPlatformVideoCaptureImpl
const media::VideoCaptureParams& device_info) OVERRIDE;
protected:
- virtual ~PepperPlatformVideoCaptureImpl();
+ friend class base::RefCounted<PepperPlatformVideoCapture>;
+ virtual ~PepperPlatformVideoCapture();
private:
void Initialize();
@@ -69,7 +74,9 @@ class PepperPlatformVideoCaptureImpl
bool succeeded,
const std::string& label);
- base::WeakPtr<PepperPluginDelegateImpl> plugin_delegate_;
+ PepperDeviceEnumerationEventHandler* GetDeviceEnumerationEventHandler();
+
+ base::WeakPtr<RenderViewImpl> render_view_;
std::string device_id_;
std::string label_;
@@ -77,7 +84,7 @@ class PepperPlatformVideoCaptureImpl
scoped_ptr<media::VideoCaptureHandlerProxy> handler_proxy_;
- PluginDelegate::PlatformVideoCaptureEventHandler* handler_;
+ PepperVideoCaptureHost* handler_;
media::VideoCapture* video_capture_;
@@ -90,9 +97,9 @@ class PepperPlatformVideoCaptureImpl
bool pending_open_device_;
int pending_open_device_id_;
- DISALLOW_COPY_AND_ASSIGN(PepperPlatformVideoCaptureImpl);
+ DISALLOW_COPY_AND_ASSIGN(PepperPlatformVideoCapture);
};
} // namespace content
-#endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_IMPL_H_
+#endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_VIDEO_CAPTURE_H_
diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.cc b/content/renderer/pepper/pepper_plugin_delegate_impl.cc
index 55c3e12..24d23ae 100644
--- a/content/renderer/pepper/pepper_plugin_delegate_impl.cc
+++ b/content/renderer/pepper/pepper_plugin_delegate_impl.cc
@@ -43,17 +43,14 @@
#include "content/renderer/pepper/content_renderer_pepper_host_factory.h"
#include "content/renderer/pepper/pepper_broker_impl.h"
#include "content/renderer/pepper/pepper_browser_connection.h"
-#include "content/renderer/pepper/pepper_device_enumeration_event_handler.h"
#include "content/renderer/pepper/pepper_file_system_host.h"
#include "content/renderer/pepper/pepper_graphics_2d_host.h"
#include "content/renderer/pepper/pepper_hung_plugin_filter.h"
#include "content/renderer/pepper/pepper_in_process_resource_creation.h"
#include "content/renderer/pepper/pepper_in_process_router.h"
-#include "content/renderer/pepper/pepper_platform_audio_input_impl.h"
#include "content/renderer/pepper/pepper_platform_audio_output_impl.h"
#include "content/renderer/pepper/pepper_platform_context_3d_impl.h"
#include "content/renderer/pepper/pepper_platform_image_2d_impl.h"
-#include "content/renderer/pepper/pepper_platform_video_capture_impl.h"
#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
#include "content/renderer/pepper/pepper_plugin_registry.h"
#include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h"
@@ -314,9 +311,7 @@ PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderViewImpl* render_view)
render_view_(render_view),
pepper_browser_connection_(this),
focused_plugin_(NULL),
- last_mouse_event_target_(NULL),
- device_enumeration_event_handler_(
- new PepperDeviceEnumerationEventHandler()) {
+ last_mouse_event_target_(NULL) {
}
PepperPluginDelegateImpl::~PepperPluginDelegateImpl() {
@@ -785,15 +780,6 @@ PluginDelegate::PlatformContext3D*
return new PlatformContext3DImpl;
}
-PluginDelegate::PlatformVideoCapture*
- PepperPluginDelegateImpl::CreateVideoCapture(
- const std::string& device_id,
- const GURL& document_url,
- PlatformVideoCaptureEventHandler* handler) {
- return new PepperPlatformVideoCaptureImpl(AsWeakPtr(), device_id,
- document_url, handler);
-}
-
PluginDelegate::PlatformVideoDecoder*
PepperPluginDelegateImpl::CreateVideoDecoder(
media::VideoDecodeAccelerator::Client* client,
@@ -833,17 +819,6 @@ PluginDelegate::PlatformAudioOutput*
GetRoutingID(), client);
}
-PluginDelegate::PlatformAudioInput* PepperPluginDelegateImpl::CreateAudioInput(
- const std::string& device_id,
- const GURL& document_url,
- uint32_t sample_rate,
- uint32_t sample_count,
- PluginDelegate::PlatformAudioInputClient* client) {
- return PepperPlatformAudioInputImpl::Create(
- AsWeakPtr(), device_id, document_url, static_cast<int>(sample_rate),
- static_cast<int>(sample_count), client);
-}
-
// If a broker has not already been created for this plugin, creates one.
PluginDelegate::Broker* PepperPluginDelegateImpl::ConnectToBroker(
PPB_Broker_Impl* client) {
@@ -1372,46 +1347,6 @@ bool PepperPluginDelegateImpl::IsPageVisible() const {
return !render_view_->is_hidden();
}
-int PepperPluginDelegateImpl::EnumerateDevices(
- PP_DeviceType_Dev type,
- const EnumerateDevicesCallback& callback) {
- int request_id =
- device_enumeration_event_handler_->RegisterEnumerateDevicesCallback(
- callback);
-
-#if defined(ENABLE_WEBRTC)
- render_view_->media_stream_dispatcher()->EnumerateDevices(
- request_id, device_enumeration_event_handler_->AsWeakPtr(),
- PepperDeviceEnumerationEventHandler::FromPepperDeviceType(type),
- GURL());
-#else
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(
- &PepperDeviceEnumerationEventHandler::OnDevicesEnumerationFailed,
- device_enumeration_event_handler_->AsWeakPtr(),
- request_id));
-#endif
-
- return request_id;
-}
-
-void PepperPluginDelegateImpl::StopEnumerateDevices(int request_id) {
- device_enumeration_event_handler_->UnregisterEnumerateDevicesCallback(
- request_id);
-
-#if defined(ENABLE_WEBRTC)
- // Need to post task since this function might be called inside the callback
- // of EnumerateDevices.
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(&MediaStreamDispatcher::StopEnumerateDevices,
- render_view_->media_stream_dispatcher()->AsWeakPtr(),
- request_id,
- device_enumeration_event_handler_->AsWeakPtr()));
-#endif
-}
-
bool PepperPluginDelegateImpl::OnMessageReceived(const IPC::Message& message) {
if (pepper_browser_connection_.OnMessageReceived(message))
return true;
@@ -1534,65 +1469,6 @@ int PepperPluginDelegateImpl::GetRoutingID() const {
return render_view_->routing_id();
}
-int PepperPluginDelegateImpl::OpenDevice(PP_DeviceType_Dev type,
- const std::string& device_id,
- const GURL& document_url,
- const OpenDeviceCallback& callback) {
- int request_id =
- device_enumeration_event_handler_->RegisterOpenDeviceCallback(callback);
-
-#if defined(ENABLE_WEBRTC)
- render_view_->media_stream_dispatcher()->OpenDevice(
- request_id,
- device_enumeration_event_handler_->AsWeakPtr(),
- device_id,
- PepperDeviceEnumerationEventHandler::FromPepperDeviceType(type),
- document_url.GetOrigin());
-#else
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(&PepperDeviceEnumerationEventHandler::OnDeviceOpenFailed,
- device_enumeration_event_handler_->AsWeakPtr(),
- request_id));
-#endif
-
- return request_id;
-}
-
-void PepperPluginDelegateImpl::CancelOpenDevice(int request_id) {
- device_enumeration_event_handler_->UnregisterOpenDeviceCallback(request_id);
-
-#if defined(ENABLE_WEBRTC)
- render_view_->media_stream_dispatcher()->CancelOpenDevice(
- request_id, device_enumeration_event_handler_->AsWeakPtr());
-#endif
-}
-
-void PepperPluginDelegateImpl::CloseDevice(const std::string& label) {
-#if defined(ENABLE_WEBRTC)
- render_view_->media_stream_dispatcher()->CloseDevice(label);
-#endif
-}
-
-int PepperPluginDelegateImpl::GetSessionID(PP_DeviceType_Dev type,
- const std::string& label) {
-#if defined(ENABLE_WEBRTC)
- switch (type) {
- case PP_DEVICETYPE_DEV_AUDIOCAPTURE:
- return render_view_->media_stream_dispatcher()->audio_session_id(label,
- 0);
- case PP_DEVICETYPE_DEV_VIDEOCAPTURE:
- return render_view_->media_stream_dispatcher()->video_session_id(label,
- 0);
- default:
- NOTREACHED();
- return 0;
- }
-#else
- return 0;
-#endif
-}
-
MouseLockDispatcher::LockTarget*
PepperPluginDelegateImpl::GetOrCreateLockTargetAdapter(
PepperPluginInstanceImpl* instance) {
diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.h b/content/renderer/pepper/pepper_plugin_delegate_impl.h
index cb5ab8b..286ca0c 100644
--- a/content/renderer/pepper/pepper_plugin_delegate_impl.h
+++ b/content/renderer/pepper/pepper_plugin_delegate_impl.h
@@ -44,7 +44,6 @@ namespace content {
class ContextProviderCommandBuffer;
class GamepadSharedMemoryReader;
class PepperBrokerImpl;
-class PepperDeviceEnumerationEventHandler;
class PluginModule;
class RenderViewImpl;
struct WebPluginInfo;
@@ -69,27 +68,6 @@ class PepperPluginDelegateImpl
CONTENT_EXPORT int GetRoutingID() const;
- typedef base::Callback<void (int /* request_id */,
- bool /* succeeded */,
- const std::string& /* label */)>
- OpenDeviceCallback;
-
- // Opens the specified device. The request ID passed into the callback will be
- // the same as the return value. If successful, the label passed into the
- // callback identifies a audio/video steam, which can be used to call
- // CloseDevice() and GetSesssionID().
- int OpenDevice(PP_DeviceType_Dev type,
- const std::string& device_id,
- const GURL& document_url,
- const OpenDeviceCallback& callback);
- // Cancels an request to open device, using the request ID returned by
- // OpenDevice(). It is guaranteed that the callback passed into OpenDevice()
- // won't be called afterwards.
- void CancelOpenDevice(int request_id);
- void CloseDevice(const std::string& label);
- // Gets audio/video session ID given a label.
- int GetSessionID(PP_DeviceType_Dev type, const std::string& label);
-
private:
// RenderViewPepperHelper implementation.
virtual WebKit::WebPlugin* CreatePepperWebPlugin(
@@ -161,21 +139,11 @@ class PepperPluginDelegateImpl
uint32_t sample_rate,
uint32_t sample_count,
PlatformAudioOutputClient* client) OVERRIDE;
- virtual PlatformAudioInput* CreateAudioInput(
- const std::string& device_id,
- const GURL& document_url,
- uint32_t sample_rate,
- uint32_t sample_count,
- PlatformAudioInputClient* client) OVERRIDE;
virtual PlatformImage2D* CreateImage2D(int width, int height) OVERRIDE;
virtual PlatformGraphics2D* GetGraphics2D(
PepperPluginInstanceImpl* instance,
PP_Resource resource) OVERRIDE;
virtual PlatformContext3D* CreateContext3D() OVERRIDE;
- virtual PlatformVideoCapture* CreateVideoCapture(
- const std::string& device_id,
- const GURL& document_url,
- PlatformVideoCaptureEventHandler* handler) OVERRIDE;
virtual PlatformVideoDecoder* CreateVideoDecoder(
media::VideoDecodeAccelerator::Client* client,
int32 command_buffer_route_id) OVERRIDE;
@@ -294,10 +262,6 @@ class PepperPluginDelegateImpl
virtual bool IsInFullscreenMode() OVERRIDE;
virtual void SampleGamepads(WebKit::WebGamepads* data) OVERRIDE;
virtual bool IsPageVisible() const OVERRIDE;
- virtual int EnumerateDevices(
- PP_DeviceType_Dev type,
- const EnumerateDevicesCallback& callback) OVERRIDE;
- virtual void StopEnumerateDevices(int request_id) OVERRIDE;
virtual void HandleDocumentLoad(
PepperPluginInstanceImpl* instance,
const WebKit::WebURLResponse& response) OVERRIDE;
@@ -425,9 +389,6 @@ class PepperPluginDelegateImpl
scoped_ptr<GamepadSharedMemoryReader> gamepad_shared_memory_reader_;
- scoped_ptr<PepperDeviceEnumerationEventHandler>
- device_enumeration_event_handler_;
-
scoped_refptr<ContextProviderCommandBuffer> offscreen_context3d_;
DISALLOW_COPY_AND_ASSIGN(PepperPluginDelegateImpl);
diff --git a/content/renderer/pepper/pepper_video_capture_host.cc b/content/renderer/pepper/pepper_video_capture_host.cc
index b1aa2e8..1c791e6 100644
--- a/content/renderer/pepper/pepper_video_capture_host.cc
+++ b/content/renderer/pepper/pepper_video_capture_host.cc
@@ -5,8 +5,11 @@
#include "content/renderer/pepper/pepper_video_capture_host.h"
#include "content/renderer/pepper/host_globals.h"
+#include "content/renderer/pepper/pepper_device_enumeration_event_handler.h"
+#include "content/renderer/pepper/pepper_platform_video_capture.h"
#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
#include "content/renderer/pepper/renderer_ppapi_host_impl.h"
+#include "content/renderer/render_view_impl.h"
#include "ppapi/host/dispatch_host_message.h"
#include "ppapi/host/ppapi_host.h"
#include "ppapi/proxy/host_dispatcher.h"
@@ -39,7 +42,11 @@ PepperVideoCaptureHost::PepperVideoCaptureHost(RendererPpapiHostImpl* host,
renderer_ppapi_host_(host),
buffer_count_hint_(0),
status_(PP_VIDEO_CAPTURE_STATUS_STOPPED),
- enumeration_helper_(this, this, PP_DEVICETYPE_DEV_VIDEOCAPTURE) {
+ enumeration_helper_(
+ this,
+ PepperDeviceEnumerationEventHandler::GetForRenderView(
+ host->GetRenderViewForInstance(pp_instance())),
+ PP_DEVICETYPE_DEV_VIDEOCAPTURE) {
}
PepperVideoCaptureHost::~PepperVideoCaptureHost() {
@@ -47,7 +54,7 @@ PepperVideoCaptureHost::~PepperVideoCaptureHost() {
}
bool PepperVideoCaptureHost::Init() {
- return !!GetPluginDelegate();
+ return !!renderer_ppapi_host_->GetPluginInstance(pp_instance());
}
int32_t PepperVideoCaptureHost::OnResourceMessageReceived(
@@ -239,14 +246,6 @@ void PepperVideoCaptureHost::OnDeviceInfoReceived(
info, buffer_host_resources, size)));
}
-PluginDelegate* PepperVideoCaptureHost::GetPluginDelegate() {
- PepperPluginInstanceImpl* instance =
- renderer_ppapi_host_->GetPluginInstanceImpl(pp_instance());
- if (instance)
- return instance->delegate();
- return NULL;
-}
-
int32_t PepperVideoCaptureHost::OnOpen(
ppapi::host::HostMessageContext* context,
const std::string& device_id,
@@ -255,10 +254,6 @@ int32_t PepperVideoCaptureHost::OnOpen(
if (platform_video_capture_.get())
return PP_ERROR_FAILED;
- PluginDelegate* plugin_delegate = GetPluginDelegate();
- if (!plugin_delegate)
- return PP_ERROR_FAILED;
-
SetRequestedInfo(requested_info, buffer_count);
PepperPluginInstance* instance =
@@ -266,9 +261,12 @@ int32_t PepperVideoCaptureHost::OnOpen(
if (!instance)
return PP_ERROR_FAILED;
- platform_video_capture_ =
- plugin_delegate->CreateVideoCapture(device_id,
- instance->GetContainer()->element().document().url(), this);
+ RenderViewImpl* render_view = static_cast<RenderViewImpl*>(
+ renderer_ppapi_host_->GetRenderViewForInstance(pp_instance()));
+
+ platform_video_capture_ = new PepperPlatformVideoCapture(
+ render_view->AsWeakPtr(), device_id,
+ instance->GetContainer()->element().document().url(), this);
open_reply_context_ = context->MakeReplyMessageContext();
@@ -284,7 +282,7 @@ int32_t PepperVideoCaptureHost::OnStartCapture(
DCHECK(buffers_.empty());
// It's safe to call this regardless it's capturing or not, because
- // PepperPlatformVideoCaptureImpl maintains the state.
+ // PepperPlatformVideoCapture maintains the state.
platform_video_capture_->StartCapture(this, capability_);
return PP_OK;
}
@@ -316,7 +314,7 @@ int32_t PepperVideoCaptureHost::StopCapture() {
ReleaseBuffers();
// It's safe to call this regardless it's capturing or not, because
- // PepperPlatformVideoCaptureImpl maintains the state.
+ // PepperPlatformVideoCapture maintains the state.
platform_video_capture_->StopCapture(this);
return PP_OK;
}
diff --git a/content/renderer/pepper/pepper_video_capture_host.h b/content/renderer/pepper/pepper_video_capture_host.h
index e01c1b1..55d304d 100644
--- a/content/renderer/pepper/pepper_video_capture_host.h
+++ b/content/renderer/pepper/pepper_video_capture_host.h
@@ -9,7 +9,6 @@
#include "base/memory/ref_counted.h"
#include "content/public/renderer/renderer_ppapi_host.h"
#include "content/renderer/pepper/pepper_device_enumeration_host_helper.h"
-#include "content/renderer/pepper/plugin_delegate.h"
#include "content/renderer/pepper/ppb_buffer_impl.h"
#include "media/video/capture/video_capture.h"
#include "media/video/capture/video_capture_types.h"
@@ -18,12 +17,12 @@
#include "ppapi/host/resource_host.h"
namespace content {
+class PepperPlatformVideoCapture;
class RendererPpapiHostImpl;
class PepperVideoCaptureHost
: public ppapi::host::ResourceHost,
- public PluginDelegate::PlatformVideoCaptureEventHandler,
- public PepperDeviceEnumerationHostHelper::Delegate {
+ public media::VideoCapture::EventHandler {
public:
PepperVideoCaptureHost(RendererPpapiHostImpl* host,
PP_Instance instance,
@@ -37,9 +36,9 @@ class PepperVideoCaptureHost
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) OVERRIDE;
- // PluginDelegate::PlatformVideoCaptureEventHandler
- virtual void OnInitialized(media::VideoCapture* capture,
- bool succeeded) OVERRIDE;
+ void OnInitialized(media::VideoCapture* capture, bool succeeded);
+
+ // media::VideoCapture::EventHandler
virtual void OnStarted(media::VideoCapture* capture) OVERRIDE;
virtual void OnStopped(media::VideoCapture* capture) OVERRIDE;
virtual void OnPaused(media::VideoCapture* capture) OVERRIDE;
@@ -52,9 +51,6 @@ class PepperVideoCaptureHost
media::VideoCapture* capture,
const media::VideoCaptureParams& device_info) OVERRIDE;
- // PepperDeviceEnumerationHostHelper::Delegate implementation.
- virtual PluginDelegate* GetPluginDelegate() OVERRIDE;
-
private:
int32_t OnOpen(ppapi::host::HostMessageContext* context,
const std::string& device_id,
@@ -78,7 +74,7 @@ class PepperVideoCaptureHost
bool SetStatus(PP_VideoCaptureStatus_Dev status, bool forced);
- scoped_refptr<PluginDelegate::PlatformVideoCapture> platform_video_capture_;
+ scoped_refptr<PepperPlatformVideoCapture> platform_video_capture_;
// Buffers of video frame.
struct BufferInfo {
diff --git a/content/renderer/pepper/plugin_delegate.h b/content/renderer/pepper/plugin_delegate.h
index deb5d04..f7b6f92 100644
--- a/content/renderer/pepper/plugin_delegate.h
+++ b/content/renderer/pepper/plugin_delegate.h
@@ -18,10 +18,8 @@
#include "base/time/time.h"
#include "content/common/content_export.h"
#include "ipc/ipc_platform_file.h"
-#include "media/video/capture/video_capture.h"
#include "media/video/video_decode_accelerator.h"
#include "ppapi/c/dev/pp_video_dev.h"
-#include "ppapi/c/dev/ppb_device_ref_dev.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_file_info.h"
@@ -239,24 +237,16 @@ class PluginDelegate {
virtual bool Echo(const base::Callback<void()>& callback) = 0;
};
- // The base class of clients used by |PlatformAudioOutput| and
- // |PlatformAudioInput|.
- class PlatformAudioClientBase {
- protected:
- virtual ~PlatformAudioClientBase() {}
-
+ class PlatformAudioOutputClient {
public:
+ virtual ~PlatformAudioOutputClient() {}
+
// Called when the stream is created.
virtual void StreamCreated(base::SharedMemoryHandle shared_memory_handle,
size_t shared_memory_size,
base::SyncSocket::Handle socket) = 0;
};
- class PlatformAudioOutputClient : public PlatformAudioClientBase {
- protected:
- virtual ~PlatformAudioOutputClient() {}
- };
-
class PlatformAudioOutput {
public:
// Starts the playback. Returns false on error or if called before the
@@ -275,27 +265,6 @@ class PluginDelegate {
virtual ~PlatformAudioOutput() {}
};
- class PlatformAudioInputClient : public PlatformAudioClientBase {
- public:
- virtual void StreamCreationFailed() = 0;
-
- protected:
- virtual ~PlatformAudioInputClient() {}
- };
-
- class PlatformAudioInput {
- public:
- virtual void StartCapture() = 0;
- virtual void StopCapture() = 0;
-
- // Closes the stream. Make sure to call this before the object is
- // destructed.
- virtual void ShutDown() = 0;
-
- protected:
- virtual ~PlatformAudioInput() {}
- };
-
// Interface for PlatformVideoDecoder is directly inherited from general media
// VideoDecodeAccelerator interface.
class PlatformVideoDecoder : public media::VideoDecodeAccelerator {
@@ -303,28 +272,6 @@ class PluginDelegate {
virtual ~PlatformVideoDecoder() {}
};
- class PlatformVideoCaptureEventHandler
- : public media::VideoCapture::EventHandler {
- public:
- virtual ~PlatformVideoCaptureEventHandler() {}
-
- virtual void OnInitialized(media::VideoCapture* capture,
- bool succeeded) = 0;
- };
-
- class PlatformVideoCapture : public media::VideoCapture,
- public base::RefCounted<PlatformVideoCapture> {
- public:
- // Detaches the event handler and stops sending notifications to it.
- virtual void DetachEventHandler() = 0;
-
- protected:
- virtual ~PlatformVideoCapture() {}
-
- private:
- friend class base::RefCounted<PlatformVideoCapture>;
- };
-
// Provides access to the ppapi broker.
class Broker {
public:
@@ -396,16 +343,6 @@ class PluginDelegate {
// The caller will own the pointer returned from this.
virtual PlatformContext3D* CreateContext3D() = 0;
- // If |device_id| is empty, the default video capture device will be used. The
- // user can start using the returned object to capture video right away.
- // Otherwise, the specified device will be used. The user needs to wait till
- // |handler| gets an OnInitialized() notification to start using the returned
- // object.
- virtual PlatformVideoCapture* CreateVideoCapture(
- const std::string& device_id,
- const GURL& document_url,
- PlatformVideoCaptureEventHandler* handler) = 0;
-
// The caller will own the pointer returned from this.
virtual PlatformVideoDecoder* CreateVideoDecoder(
media::VideoDecodeAccelerator::Client* client,
@@ -424,16 +361,6 @@ class PluginDelegate {
uint32_t sample_count,
PlatformAudioOutputClient* client) = 0;
- // If |device_id| is empty, the default audio input device will be used.
- // The caller is responsible for calling Shutdown() on the returned pointer
- // to clean up the corresponding resources allocated during this call.
- virtual PlatformAudioInput* CreateAudioInput(
- const std::string& device_id,
- const GURL& document_url,
- uint32_t sample_rate,
- uint32_t sample_count,
- PlatformAudioInputClient* client) = 0;
-
// A pointer is returned immediately, but it is not ready to be used until
// BrokerConnected has been called.
// The caller is responsible for calling Disconnect() on the returned pointer
@@ -633,20 +560,6 @@ class PluginDelegate {
// Returns true if the containing page is visible.
virtual bool IsPageVisible() const = 0;
- typedef base::Callback<
- void (int /* request_id */,
- bool /* succeeded */,
- const std::vector< ::ppapi::DeviceRefData>& /* devices */)>
- EnumerateDevicesCallback;
-
- // Enumerates devices of the specified type. The request ID passed into the
- // callback will be the same as the return value.
- virtual int EnumerateDevices(PP_DeviceType_Dev type,
- const EnumerateDevicesCallback& callback) = 0;
- // Stop enumerating devices of the specified |request_id|. The |request_id|
- // is the return value of EnumerateDevicesCallback.
- virtual void StopEnumerateDevices(int request_id) = 0;
-
// Share a given handle with the target process.
virtual IPC::PlatformFileForTransit ShareHandleWithRemote(
base::PlatformFile handle,