summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvictorhsieh@chromium.org <victorhsieh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-16 07:53:08 +0000
committervictorhsieh@chromium.org <victorhsieh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-16 07:53:08 +0000
commitcc12387e17998f7d1dc467f06f60fa1b0be88d73 (patch)
tree31d1548f140a56eee2879e5c7c51a688fdc1a4ff
parent0fa16e26f25c6680499146492003a374174023fe (diff)
downloadchromium_src-cc12387e17998f7d1dc467f06f60fa1b0be88d73.zip
chromium_src-cc12387e17998f7d1dc467f06f60fa1b0be88d73.tar.gz
chromium_src-cc12387e17998f7d1dc467f06f60fa1b0be88d73.tar.bz2
Refactor video capture to new design, as part of the whole Pepper resource redesign.
New design provides higher performance and involves writing much less code. See the pepper implementation doc for detail. http://www.chromium.org/developers/design-documents/pepper-plugin-implementation BUG= Review URL: https://chromiumcodereview.appspot.com/11274036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168163 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/content_renderer.gypi2
-rw-r--r--content/renderer/pepper/content_renderer_pepper_host_factory.cc10
-rw-r--r--content/renderer/pepper/pepper_flash_host.cc57
-rw-r--r--content/renderer/pepper/pepper_flash_host.h13
-rw-r--r--content/renderer/pepper/pepper_video_capture_host.cc460
-rw-r--r--content/renderer/pepper/pepper_video_capture_host.h116
-rw-r--r--ppapi/api/dev/ppb_video_capture_dev.idl24
-rw-r--r--ppapi/c/dev/ppb_video_capture_dev.h14
-rw-r--r--ppapi/cpp/dev/video_capture_dev.cc42
-rw-r--r--ppapi/cpp/dev/video_capture_dev.h5
-rw-r--r--ppapi/examples/enumerate_devices/enumerate_devices.html4
-rw-r--r--ppapi/examples/video_capture/video_capture.cc7
-rw-r--r--ppapi/examples/video_capture/video_capture.html10
-rw-r--r--ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c12
-rw-r--r--ppapi/ppapi_proxy.gypi6
-rw-r--r--ppapi/ppapi_shared.gypi2
-rw-r--r--ppapi/proxy/flash_resource.cc42
-rw-r--r--ppapi/proxy/flash_resource.h8
-rw-r--r--ppapi/proxy/flash_resource_unittest.cc40
-rw-r--r--ppapi/proxy/interface_list.cc2
-rw-r--r--ppapi/proxy/ppapi_messages.h89
-rw-r--r--ppapi/proxy/ppb_video_capture_proxy.cc546
-rw-r--r--ppapi/proxy/ppb_video_capture_proxy.h107
-rw-r--r--ppapi/proxy/resource_creation_proxy.cc8
-rw-r--r--ppapi/proxy/resource_message_params.cc9
-rw-r--r--ppapi/proxy/resource_message_params.h2
-rw-r--r--ppapi/proxy/serialized_structs.h8
-rw-r--r--ppapi/proxy/video_capture_resource.cc277
-rw-r--r--ppapi/proxy/video_capture_resource.h93
-rw-r--r--ppapi/shared_impl/ppb_video_capture_shared.cc187
-rw-r--r--ppapi/shared_impl/ppb_video_capture_shared.h100
-rw-r--r--ppapi/thunk/interfaces_ppb_public_dev.h5
-rw-r--r--ppapi/thunk/ppb_buffer_api.h3
-rw-r--r--ppapi/thunk/ppb_buffer_trusted_api.h3
-rw-r--r--ppapi/thunk/ppb_flash_functions_api.h6
-rw-r--r--ppapi/thunk/ppb_flash_thunk.cc17
-rw-r--r--ppapi/thunk/ppb_video_capture_api.h13
-rw-r--r--ppapi/thunk/ppb_video_capture_thunk.cc22
-rw-r--r--webkit/glue/webkit_glue.gypi2
-rw-r--r--webkit/plugins/ppapi/plugin_module.cc1
-rw-r--r--webkit/plugins/ppapi/ppb_buffer_impl.h8
-rw-r--r--webkit/plugins/ppapi/ppb_video_capture_impl.cc332
-rw-r--r--webkit/plugins/ppapi/ppb_video_capture_impl.h109
-rw-r--r--webkit/plugins/ppapi/resource_creation_impl.cc7
44 files changed, 1043 insertions, 1787 deletions
diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi
index 8b6e559..7d3bb02 100644
--- a/content/content_renderer.gypi
+++ b/content/content_renderer.gypi
@@ -199,6 +199,8 @@
'renderer/pepper/pepper_plugin_delegate_impl.h',
'renderer/pepper/pepper_proxy_channel_delegate_impl.cc',
'renderer/pepper/pepper_proxy_channel_delegate_impl.h',
+ 'renderer/pepper/pepper_video_capture_host.cc',
+ 'renderer/pepper/pepper_video_capture_host.h',
'renderer/pepper/pepper_websocket_host.cc',
'renderer/pepper/pepper_websocket_host.h',
'renderer/pepper/renderer_ppapi_host_impl.cc',
diff --git a/content/renderer/pepper/content_renderer_pepper_host_factory.cc b/content/renderer/pepper/content_renderer_pepper_host_factory.cc
index 7752263..65edc2c 100644
--- a/content/renderer/pepper/content_renderer_pepper_host_factory.cc
+++ b/content/renderer/pepper/content_renderer_pepper_host_factory.cc
@@ -9,6 +9,7 @@
#include "content/renderer/pepper/pepper_file_chooser_host.h"
#include "content/renderer/pepper/pepper_flash_clipboard_host.h"
#include "content/renderer/pepper/pepper_flash_host.h"
+#include "content/renderer/pepper/pepper_video_capture_host.h"
#include "content/renderer/pepper/pepper_websocket_host.h"
#include "content/renderer/pepper/renderer_ppapi_host_impl.h"
#include "ppapi/host/resource_host.h"
@@ -59,6 +60,15 @@ scoped_ptr<ResourceHost> ContentRendererPepperHostFactory::CreateResourceHost(
case PpapiHostMsg_FileChooser_Create::ID:
return scoped_ptr<ResourceHost>(new PepperFileChooserHost(
host_, instance, params.pp_resource()));
+ case PpapiHostMsg_VideoCapture_Create::ID: {
+ PepperVideoCaptureHost* host = new PepperVideoCaptureHost(
+ host_, instance, params.pp_resource());
+ if (!host->Init()) {
+ delete host;
+ return scoped_ptr<ResourceHost>();
+ }
+ return scoped_ptr<ResourceHost>(host);
+ }
}
}
diff --git a/content/renderer/pepper/pepper_flash_host.cc b/content/renderer/pepper/pepper_flash_host.cc
index d2e9f6f..c4468b6 100644
--- a/content/renderer/pepper/pepper_flash_host.cc
+++ b/content/renderer/pepper/pepper_flash_host.cc
@@ -4,21 +4,8 @@
#include "content/renderer/pepper/pepper_flash_host.h"
-#include <vector>
-
#include "content/public/renderer/renderer_ppapi_host.h"
-#include "ipc/ipc_message_macros.h"
#include "ppapi/c/pp_errors.h"
-#include "ppapi/host/dispatch_host_message.h"
-#include "ppapi/host/ppapi_host.h"
-#include "ppapi/proxy/enter_proxy.h"
-#include "ppapi/proxy/ppapi_messages.h"
-#include "ppapi/proxy/resource_message_params.h"
-#include "ppapi/thunk/ppb_video_capture_api.h"
-
-using ppapi::proxy::EnterHostFromHostResource;
-using ppapi::proxy::EnterHostFromHostResourceForceCallback;
-using ppapi::thunk::PPB_VideoCapture_API;
namespace content {
@@ -26,8 +13,7 @@ PepperFlashHost::PepperFlashHost(
RendererPpapiHost* host,
PP_Instance instance,
PP_Resource resource)
- : ResourceHost(host->GetPpapiHost(), instance, resource),
- callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ : ResourceHost(host->GetPpapiHost(), instance, resource) {
}
PepperFlashHost::~PepperFlashHost() {
@@ -36,47 +22,6 @@ PepperFlashHost::~PepperFlashHost() {
int32_t PepperFlashHost::OnResourceMessageReceived(
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) {
- IPC_BEGIN_MESSAGE_MAP(PepperFlashHost, msg)
- PPAPI_DISPATCH_HOST_RESOURCE_CALL(
- PpapiHostMsg_Flash_EnumerateVideoCaptureDevices,
- OnMsgEnumerateVideoCaptureDevices)
- IPC_END_MESSAGE_MAP()
return PP_ERROR_FAILED;
}
-
-int32_t PepperFlashHost::OnMsgEnumerateVideoCaptureDevices(
- ppapi::host::HostMessageContext* host_context,
- const ppapi::HostResource& host_resource) {
- EnterHostFromHostResourceForceCallback<PPB_VideoCapture_API> enter(
- host_resource, callback_factory_,
- &PepperFlashHost::OnEnumerateVideoCaptureDevicesComplete,
- host_context->MakeReplyMessageContext(),
- host_resource);
- if (enter.succeeded()) {
- // We don't want the output to go into a PP_ResourceArray (which is
- // deprecated), so just pass in NULL. We'll grab the DeviceRefData vector
- // in the callback and convert it to a PP_ArrayOutput in the plugin.
- enter.SetResult(enter.object()->EnumerateDevices(NULL, enter.callback()));
- }
- return PP_OK_COMPLETIONPENDING;
-}
-
-void PepperFlashHost::OnEnumerateVideoCaptureDevicesComplete(
- int32_t result,
- ppapi::host::ReplyMessageContext reply_message_context,
- const ppapi::HostResource& host_resource) {
- std::vector<ppapi::DeviceRefData> devices;
- if (result == PP_OK) {
- EnterHostFromHostResource<PPB_VideoCapture_API> enter(host_resource);
- if (enter.succeeded())
- devices = enter.object()->GetDeviceRefData();
- else
- result = PP_ERROR_FAILED;
- }
- reply_message_context.params.set_result(result);
- host()->SendReply(reply_message_context,
- PpapiPluginMsg_Flash_EnumerateVideoCaptureDevicesReply(devices));
-}
-
} // namespace content
-
diff --git a/content/renderer/pepper/pepper_flash_host.h b/content/renderer/pepper/pepper_flash_host.h
index 5073bc8..48a7af9 100644
--- a/content/renderer/pepper/pepper_flash_host.h
+++ b/content/renderer/pepper/pepper_flash_host.h
@@ -6,10 +6,8 @@
#define CONTENT_RENDERER_PEPPER_PEPPER_FLASH_HOST_H_
#include "base/basictypes.h"
-#include "ipc/ipc_message.h"
#include "ppapi/host/host_message_context.h"
#include "ppapi/host/resource_host.h"
-#include "ppapi/proxy/proxy_completion_callback_factory.h"
namespace content {
@@ -27,18 +25,7 @@ class PepperFlashHost
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) OVERRIDE;
- int32_t OnMsgEnumerateVideoCaptureDevices(
- ppapi::host::HostMessageContext* host_context,
- const ppapi::HostResource& host_resource);
private:
- void OnEnumerateVideoCaptureDevicesComplete(
- int32_t result,
- ppapi::host::ReplyMessageContext reply_message_context,
- const ppapi::HostResource& host_resource);
-
- ppapi::proxy::ProxyCompletionCallbackFactory<PepperFlashHost>
- callback_factory_;
-
DISALLOW_COPY_AND_ASSIGN(PepperFlashHost);
};
diff --git a/content/renderer/pepper/pepper_video_capture_host.cc b/content/renderer/pepper/pepper_video_capture_host.cc
new file mode 100644
index 0000000..19866d6
--- /dev/null
+++ b/content/renderer/pepper/pepper_video_capture_host.cc
@@ -0,0 +1,460 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// 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_video_capture_host.h"
+
+#include "ppapi/host/dispatch_host_message.h"
+#include "ppapi/host/ppapi_host.h"
+#include "ppapi/proxy/host_dispatcher.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/shared_impl/host_resource.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_buffer_api.h"
+#include "webkit/plugins/ppapi/host_globals.h"
+#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
+#include "webkit/plugins/ppapi/resource_helper.h"
+
+using ppapi::DeviceRefData;
+using ppapi::HostResource;
+using ppapi::TrackedCallback;
+using ppapi::thunk::EnterResourceNoLock;
+using ppapi::thunk::PPB_Buffer_API;
+using ppapi::thunk::PPB_BufferTrusted_API;
+using webkit::ppapi::HostGlobals;
+using webkit::ppapi::ResourceHelper;
+using webkit::ppapi::PPB_Buffer_Impl;
+using webkit::ppapi::PluginInstance;
+
+namespace {
+
+// Maximum number of buffers to actually allocate.
+const uint32_t kMaxBuffers = 20;
+
+} // namespace
+
+namespace content {
+
+PepperVideoCaptureHost::PepperVideoCaptureHost(RendererPpapiHost* host,
+ PP_Instance instance,
+ PP_Resource resource)
+ : ResourceHost(host->GetPpapiHost(), instance, resource),
+ renderer_ppapi_host_(host),
+ buffer_count_hint_(0),
+ status_(PP_VIDEO_CAPTURE_STATUS_STOPPED) {
+}
+
+PepperVideoCaptureHost::~PepperVideoCaptureHost() {
+ Close();
+}
+
+bool PepperVideoCaptureHost::Init() {
+ PluginInstance* instance = GetPluginInstance();
+ return !!instance;
+}
+
+int32_t PepperVideoCaptureHost::OnResourceMessageReceived(
+ const IPC::Message& msg,
+ ppapi::host::HostMessageContext* context) {
+ IPC_BEGIN_MESSAGE_MAP(PepperVideoCaptureHost, msg)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
+ PpapiHostMsg_VideoCapture_EnumerateDevices,
+ OnEnumerateDevices)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL(
+ PpapiHostMsg_VideoCapture_Open,
+ OnOpen)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
+ PpapiHostMsg_VideoCapture_StartCapture,
+ OnStartCapture)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL(
+ PpapiHostMsg_VideoCapture_ReuseBuffer,
+ OnReuseBuffer)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
+ PpapiHostMsg_VideoCapture_StopCapture,
+ OnStopCapture)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
+ PpapiHostMsg_VideoCapture_Close,
+ OnClose)
+ IPC_END_MESSAGE_MAP()
+ return PP_ERROR_FAILED;
+}
+
+void PepperVideoCaptureHost::OnInitialized(media::VideoCapture* capture,
+ bool succeeded) {
+ DCHECK(capture == platform_video_capture_.get());
+
+ if (succeeded) {
+ open_reply_context_.params.set_result(PP_OK);
+ } else {
+ DetachPlatformVideoCapture();
+ open_reply_context_.params.set_result(PP_ERROR_FAILED);
+ }
+
+ host()->SendReply(open_reply_context_,
+ PpapiPluginMsg_VideoCapture_OpenReply());
+}
+
+void PepperVideoCaptureHost::OnStarted(media::VideoCapture* capture) {
+ if (SetStatus(PP_VIDEO_CAPTURE_STATUS_STARTED, false))
+ SendStatus();
+}
+
+void PepperVideoCaptureHost::OnStopped(media::VideoCapture* capture) {
+ if (SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPED, false))
+ SendStatus();
+}
+
+void PepperVideoCaptureHost::OnPaused(media::VideoCapture* capture) {
+ if (SetStatus(PP_VIDEO_CAPTURE_STATUS_PAUSED, false))
+ SendStatus();
+}
+
+void PepperVideoCaptureHost::OnError(media::VideoCapture* capture,
+ int error_code) {
+ // Today, the media layer only sends "1" as an error.
+ DCHECK(error_code == 1);
+ // It either comes because some error was detected while starting (e.g. 2
+ // conflicting "master" resolution), or because the browser failed to start
+ // the capture.
+ SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPED, true);
+ host()->SendUnsolicitedReply(pp_resource(),
+ PpapiPluginMsg_VideoCapture_OnError(PP_ERROR_FAILED));
+}
+
+void PepperVideoCaptureHost::OnRemoved(media::VideoCapture* capture) {
+}
+
+void PepperVideoCaptureHost::OnBufferReady(
+ media::VideoCapture* capture,
+ scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) {
+ DCHECK(buffer.get());
+ for (uint32_t i = 0; i < buffers_.size(); ++i) {
+ if (!buffers_[i].in_use) {
+ // TODO(ihf): Switch to a size calculation based on stride.
+ // Stride is filled out now but not more meaningful than size
+ // until wjia unifies VideoFrameBuffer and media::VideoFrame.
+ size_t size = std::min(static_cast<size_t>(buffers_[i].buffer->size()),
+ buffer->buffer_size);
+ memcpy(buffers_[i].data, buffer->memory_pointer, size);
+ buffers_[i].in_use = true;
+ platform_video_capture_->FeedBuffer(buffer);
+ host()->SendUnsolicitedReply(pp_resource(),
+ PpapiPluginMsg_VideoCapture_OnBufferReady(i));
+ return;
+ }
+ }
+
+ // No free slot, just discard the frame and tell the media layer it can
+ // re-use the buffer.
+ platform_video_capture_->FeedBuffer(buffer);
+}
+
+void PepperVideoCaptureHost::OnDeviceInfoReceived(
+ media::VideoCapture* capture,
+ const media::VideoCaptureParams& device_info) {
+ PP_VideoCaptureDeviceInfo_Dev info = {
+ static_cast<uint32_t>(device_info.width),
+ static_cast<uint32_t>(device_info.height),
+ static_cast<uint32_t>(device_info.frame_per_second)
+ };
+ ReleaseBuffers();
+
+ // YUV 4:2:0
+ int uv_width = info.width / 2;
+ int uv_height = info.height / 2;
+ size_t size = info.width * info.height + 2 * uv_width * uv_height;
+
+ ppapi::proxy::ResourceMessageReplyParams params(pp_resource(), 0);
+
+ // Allocate buffers. We keep a reference to them, that is released in
+ // ReleaseBuffers. In the mean time, we prepare the resource and handle here
+ // for sending below.
+ std::vector<HostResource> buffer_host_resources;
+ buffers_.reserve(buffer_count_hint_);
+ ::ppapi::ResourceTracker* tracker =
+ HostGlobals::Get()->GetResourceTracker();
+ ppapi::proxy::HostDispatcher* dispatcher =
+ ppapi::proxy::HostDispatcher::GetForInstance(pp_instance());
+ for (size_t i = 0; i < buffer_count_hint_; ++i) {
+ PP_Resource res = PPB_Buffer_Impl::Create(pp_instance(), size);
+ if (!res)
+ break;
+
+ EnterResourceNoLock<PPB_Buffer_API> enter(res, true);
+ DCHECK(enter.succeeded());
+
+ BufferInfo buf;
+ buf.buffer = static_cast<PPB_Buffer_Impl*>(enter.object());
+ buf.data = buf.buffer->Map();
+ if (!buf.data) {
+ tracker->ReleaseResource(res);
+ break;
+ }
+ buffers_.push_back(buf);
+
+ // Add to HostResource array to be sent.
+ {
+ HostResource host_resource;
+ host_resource.SetHostResource(pp_instance(), res);
+ buffer_host_resources.push_back(host_resource);
+
+ // Add a reference for the plugin, which is resposible for releasing it.
+ tracker->AddRefResource(res);
+ }
+
+ // Add the serialized shared memory handle to params. FileDescriptor is
+ // treated in special case.
+ {
+ EnterResourceNoLock<PPB_BufferTrusted_API> enter(res, true);
+ DCHECK(enter.succeeded());
+ int handle;
+ int32_t result = enter.object()->GetSharedMemory(&handle);
+ DCHECK(result == PP_OK);
+ // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle,
+ // those casts are ugly.
+ base::PlatformFile platform_file =
+#if defined(OS_WIN)
+ reinterpret_cast<HANDLE>(static_cast<intptr_t>(handle));
+#elif defined(OS_POSIX)
+ handle;
+#else
+#error Not implemented.
+#endif
+ params.AppendHandle(
+ ppapi::proxy::SerializedHandle(
+ dispatcher->ShareHandleWithRemote(platform_file, false),
+ size));
+ }
+ }
+
+ if (buffers_.empty()) {
+ // We couldn't allocate/map buffers at all. Send an error and stop the
+ // capture.
+ SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPING, true);
+ platform_video_capture_->StopCapture(this);
+ OnError(capture, PP_ERROR_NOMEMORY);
+ return;
+ }
+
+ host()->Send(new PpapiPluginMsg_ResourceReply(
+ params, PpapiPluginMsg_VideoCapture_OnDeviceInfo(
+ info, buffer_host_resources, size)));
+}
+
+PluginInstance* PepperVideoCaptureHost::GetPluginInstance() const {
+ return renderer_ppapi_host_->GetPluginInstance(pp_instance());
+}
+
+int32_t PepperVideoCaptureHost::OnEnumerateDevices(
+ ppapi::host::HostMessageContext* context) {
+ PluginInstance* instance = GetPluginInstance();
+ if (!instance)
+ return PP_ERROR_FAILED;
+
+ enum_reply_context_ = context->MakeReplyMessageContext();
+ instance->delegate()->EnumerateDevices(
+ PP_DEVICETYPE_DEV_VIDEOCAPTURE,
+ base::Bind(&PepperVideoCaptureHost::EnumerateDevicesCallbackFunc,
+ AsWeakPtr()));
+ return PP_OK_COMPLETIONPENDING;
+}
+
+int32_t PepperVideoCaptureHost::OnOpen(
+ ppapi::host::HostMessageContext* context,
+ const std::string& device_id,
+ const PP_VideoCaptureDeviceInfo_Dev& requested_info,
+ uint32_t buffer_count) {
+ if (platform_video_capture_.get())
+ return PP_ERROR_FAILED;
+
+ PluginInstance* instance = GetPluginInstance();
+ if (!instance)
+ return PP_ERROR_FAILED;
+
+ SetRequestedInfo(requested_info, buffer_count);
+
+ platform_video_capture_ =
+ instance->delegate()->CreateVideoCapture(device_id, this);
+
+ open_reply_context_ = context->MakeReplyMessageContext();
+
+ // It is able to complete synchronously if the default device is used.
+ bool sync_completion = device_id.empty();
+ if (sync_completion) {
+ // Send OpenACK directly, but still need to return PP_OK_COMPLETIONPENDING
+ // to make PluginResource happy.
+ OnInitialized(platform_video_capture_.get(), true);
+ }
+
+ return PP_OK_COMPLETIONPENDING;
+}
+
+int32_t PepperVideoCaptureHost::OnStartCapture(
+ ppapi::host::HostMessageContext* context) {
+ if (!SetStatus(PP_VIDEO_CAPTURE_STATUS_STARTING, false) ||
+ !platform_video_capture_.get())
+ return PP_ERROR_FAILED;
+
+ DCHECK(buffers_.empty());
+
+ // It's safe to call this regardless it's capturing or not, because
+ // PepperPlatformVideoCaptureImpl maintains the state.
+ platform_video_capture_->StartCapture(this, capability_);
+ return PP_OK;
+}
+
+int32_t PepperVideoCaptureHost::OnReuseBuffer(
+ ppapi::host::HostMessageContext* context,
+ uint32_t buffer) {
+ if (buffer >= buffers_.size() || !buffers_[buffer].in_use)
+ return PP_ERROR_BADARGUMENT;
+ buffers_[buffer].in_use = false;
+ return PP_OK;
+}
+
+int32_t PepperVideoCaptureHost::OnStopCapture(
+ ppapi::host::HostMessageContext* context) {
+ return StopCapture();
+}
+
+int32_t PepperVideoCaptureHost::OnClose(
+ ppapi::host::HostMessageContext* context) {
+ return Close();
+}
+
+int32_t PepperVideoCaptureHost::StopCapture() {
+ if (!SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPING, false))
+ return PP_ERROR_FAILED;
+
+ DCHECK(platform_video_capture_.get());
+
+ ReleaseBuffers();
+ // It's safe to call this regardless it's capturing or not, because
+ // PepperPlatformVideoCaptureImpl maintains the state.
+ platform_video_capture_->StopCapture(this);
+ return PP_OK;
+}
+
+int32_t PepperVideoCaptureHost::Close() {
+ if (!platform_video_capture_.get())
+ return PP_OK;
+
+ StopCapture();
+ DCHECK(buffers_.empty());
+ DetachPlatformVideoCapture();
+ return PP_OK;
+}
+
+void PepperVideoCaptureHost::ReleaseBuffers() {
+ ::ppapi::ResourceTracker* tracker = HostGlobals::Get()->GetResourceTracker();
+ for (size_t i = 0; i < buffers_.size(); ++i) {
+ buffers_[i].buffer->Unmap();
+ tracker->ReleaseResource(buffers_[i].buffer->pp_resource());
+ }
+ buffers_.clear();
+}
+
+void PepperVideoCaptureHost::SendStatus() {
+ host()->SendUnsolicitedReply(pp_resource(),
+ PpapiPluginMsg_VideoCapture_OnStatus(status_));
+}
+
+void PepperVideoCaptureHost::SetRequestedInfo(
+ const PP_VideoCaptureDeviceInfo_Dev& device_info,
+ uint32_t buffer_count) {
+ // Clamp the buffer count to between 1 and |kMaxBuffers|.
+ buffer_count_hint_ = std::min(std::max(buffer_count, 1U), kMaxBuffers);
+
+ capability_.width = device_info.width;
+ capability_.height = device_info.height;
+ capability_.frame_rate = device_info.frames_per_second;
+ capability_.expected_capture_delay = 0; // Ignored.
+ capability_.color = media::VideoCaptureCapability::kI420;
+ capability_.interlaced = false; // Ignored.
+}
+
+void PepperVideoCaptureHost::DetachPlatformVideoCapture() {
+ if (platform_video_capture_.get()) {
+ platform_video_capture_->DetachEventHandler();
+ platform_video_capture_ = NULL;
+ }
+}
+
+void PepperVideoCaptureHost::EnumerateDevicesCallbackFunc(
+ int request_id,
+ bool succeeded,
+ const std::vector<ppapi::DeviceRefData>& devices) {
+ PluginInstance* instance = GetPluginInstance();
+ if (instance)
+ instance->delegate()->StopEnumerateDevices(request_id);
+
+ if (succeeded) {
+ enum_reply_context_.params.set_result(PP_OK);
+ host()->SendReply(enum_reply_context_,
+ PpapiPluginMsg_VideoCapture_EnumerateDevicesReply(
+ devices));
+ } else {
+ enum_reply_context_.params.set_result(PP_ERROR_FAILED);
+ host()->SendReply(enum_reply_context_,
+ PpapiPluginMsg_VideoCapture_EnumerateDevicesReply(
+ std::vector<DeviceRefData>()));
+ }
+}
+
+bool PepperVideoCaptureHost::SetStatus(PP_VideoCaptureStatus_Dev status,
+ bool forced) {
+ if (!forced) {
+ switch (status) {
+ case PP_VIDEO_CAPTURE_STATUS_STOPPED:
+ if (status_ != PP_VIDEO_CAPTURE_STATUS_STOPPING)
+ return false;
+ break;
+ case PP_VIDEO_CAPTURE_STATUS_STARTING:
+ if (status_ != PP_VIDEO_CAPTURE_STATUS_STOPPED)
+ return false;
+ break;
+ case PP_VIDEO_CAPTURE_STATUS_STARTED:
+ switch (status_) {
+ case PP_VIDEO_CAPTURE_STATUS_STARTING:
+ case PP_VIDEO_CAPTURE_STATUS_PAUSED:
+ break;
+ default:
+ return false;
+ }
+ break;
+ case PP_VIDEO_CAPTURE_STATUS_PAUSED:
+ switch (status_) {
+ case PP_VIDEO_CAPTURE_STATUS_STARTING:
+ case PP_VIDEO_CAPTURE_STATUS_STARTED:
+ break;
+ default:
+ return false;
+ }
+ break;
+ case PP_VIDEO_CAPTURE_STATUS_STOPPING:
+ switch (status_) {
+ case PP_VIDEO_CAPTURE_STATUS_STARTING:
+ case PP_VIDEO_CAPTURE_STATUS_STARTED:
+ case PP_VIDEO_CAPTURE_STATUS_PAUSED:
+ break;
+ default:
+ return false;
+ }
+ break;
+ }
+ }
+
+ status_ = status;
+ return true;
+}
+
+PepperVideoCaptureHost::BufferInfo::BufferInfo()
+ : in_use(false),
+ data(NULL),
+ buffer() {
+}
+
+PepperVideoCaptureHost::BufferInfo::~BufferInfo() {
+}
+
+} // namespace content
diff --git a/content/renderer/pepper/pepper_video_capture_host.h b/content/renderer/pepper/pepper_video_capture_host.h
new file mode 100644
index 0000000..90c7813
--- /dev/null
+++ b/content/renderer/pepper/pepper_video_capture_host.h
@@ -0,0 +1,116 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// 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_VIDEO_CAPTURE_HOST_H_
+#define CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_CAPTURE_HOST_H_
+
+#include "base/compiler_specific.h"
+#include "base/memory/ref_counted.h"
+#include "content/public/renderer/renderer_ppapi_host.h"
+#include "media/video/capture/video_capture.h"
+#include "media/video/capture/video_capture_types.h"
+#include "ppapi/c/dev/ppp_video_capture_dev.h"
+#include "ppapi/host/host_message_context.h"
+#include "ppapi/host/resource_host.h"
+#include "ppapi/shared_impl/ppb_device_ref_shared.h"
+#include "webkit/plugins/ppapi/plugin_delegate.h"
+#include "webkit/plugins/ppapi/ppb_buffer_impl.h"
+
+namespace content {
+
+class PepperVideoCaptureHost
+ : public ppapi::host::ResourceHost,
+ public webkit::ppapi::PluginDelegate::PlatformVideoCaptureEventHandler,
+ public base::SupportsWeakPtr<PepperVideoCaptureHost> {
+ public:
+ PepperVideoCaptureHost(RendererPpapiHost* host,
+ PP_Instance instance,
+ PP_Resource resource);
+
+ virtual ~PepperVideoCaptureHost();
+
+ bool Init();
+
+ virtual int32_t OnResourceMessageReceived(
+ const IPC::Message& msg,
+ ppapi::host::HostMessageContext* context) OVERRIDE;
+
+ // PluginDelegate::PlatformVideoCaptureEventHandler
+ virtual void OnInitialized(media::VideoCapture* capture,
+ bool succeeded) OVERRIDE;
+ virtual void OnStarted(media::VideoCapture* capture) OVERRIDE;
+ virtual void OnStopped(media::VideoCapture* capture) OVERRIDE;
+ virtual void OnPaused(media::VideoCapture* capture) OVERRIDE;
+ virtual void OnError(media::VideoCapture* capture, int error_code) OVERRIDE;
+ virtual void OnRemoved(media::VideoCapture* capture) OVERRIDE;
+ virtual void OnBufferReady(
+ media::VideoCapture* capture,
+ scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) OVERRIDE;
+ virtual void OnDeviceInfoReceived(
+ media::VideoCapture* capture,
+ const media::VideoCaptureParams& device_info) OVERRIDE;
+
+ private:
+ webkit::ppapi::PluginInstance* GetPluginInstance() const;
+
+ int32_t OnEnumerateDevices(
+ ppapi::host::HostMessageContext* context);
+ int32_t OnOpen(ppapi::host::HostMessageContext* context,
+ const std::string& device_id,
+ const PP_VideoCaptureDeviceInfo_Dev& requested_info,
+ uint32_t buffer_count);
+ int32_t OnStartCapture(ppapi::host::HostMessageContext* context);
+ int32_t OnReuseBuffer(ppapi::host::HostMessageContext* context,
+ uint32_t buffer);
+ int32_t OnStopCapture(ppapi::host::HostMessageContext* context);
+ int32_t OnClose(ppapi::host::HostMessageContext* context);
+
+ int32_t StopCapture();
+ int32_t Close();
+ void ReleaseBuffers();
+ void SendStatus();
+
+ void SetRequestedInfo(const PP_VideoCaptureDeviceInfo_Dev& device_info,
+ uint32_t buffer_count);
+
+ void DetachPlatformVideoCapture();
+
+ void EnumerateDevicesCallbackFunc(
+ int request_id,
+ bool succeeded,
+ const std::vector<ppapi::DeviceRefData>& devices);
+
+ bool SetStatus(PP_VideoCaptureStatus_Dev status, bool forced);
+
+ scoped_refptr<webkit::ppapi::PluginDelegate::PlatformVideoCapture>
+ platform_video_capture_;
+
+ // Buffers of video frame.
+ struct BufferInfo {
+ BufferInfo();
+ ~BufferInfo();
+
+ bool in_use;
+ void* data;
+ scoped_refptr<webkit::ppapi::PPB_Buffer_Impl> buffer;
+ };
+
+ RendererPpapiHost* renderer_ppapi_host_;
+
+ std::vector<BufferInfo> buffers_;
+ size_t buffer_count_hint_;
+
+ media::VideoCaptureCapability capability_;
+
+ PP_VideoCaptureStatus_Dev status_;
+
+ ppapi::host::ReplyMessageContext open_reply_context_;
+ ppapi::host::ReplyMessageContext enum_reply_context_;
+
+ DISALLOW_COPY_AND_ASSIGN(PepperVideoCaptureHost);
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_CAPTURE_HOST_H_
diff --git a/ppapi/api/dev/ppb_video_capture_dev.idl b/ppapi/api/dev/ppb_video_capture_dev.idl
index 10da4a8..179f353 100644
--- a/ppapi/api/dev/ppb_video_capture_dev.idl
+++ b/ppapi/api/dev/ppb_video_capture_dev.idl
@@ -7,7 +7,6 @@
* This file defines the <code>PPB_VideoCapture_Dev</code> interface.
*/
label Chrome {
- M14 = 0.1,
M19 = 0.2
};
@@ -54,25 +53,6 @@ interface PPB_VideoCapture_Dev {
[in] PP_Resource video_capture);
/**
- * Starts the capture. |requested_info| is a pointer to a structure containing
- * the requested resolution and frame rate. |buffer_count| is the number of
- * buffers requested by the plugin. Note: it is only used as advisory, the
- * browser may allocate more or fewer based on available resources.
- * How many buffers depends on usage. At least 2 to make sure latency doesn't
- * cause lost frames. If the plugin expects to hold on to more than one buffer
- * at a time (e.g. to do multi-frame processing, like video encoding), it
- * should request that many more.
- *
- * Returns PP_ERROR_FAILED if called when the capture was already started, or
- * PP_OK on success.
- */
- [version=0.1]
- int32_t StartCapture(
- [in] PP_Resource video_capture,
- [in] PP_VideoCaptureDeviceInfo_Dev requested_info,
- [in] uint32_t buffer_count);
-
- /**
* Enumerates video capture devices. Once the operation is completed
* successfully, |devices| will be set to a PPB_ResourceArray_Dev resource,
* which holds a list of PPB_DeviceRef_Dev resources.
@@ -85,7 +65,6 @@ interface PPB_VideoCapture_Dev {
* - the ref count of the returned |devices| has already been increased by 1
* for the caller.
*/
- [version=0.2]
int32_t EnumerateDevices(
[in] PP_Resource video_capture,
[out] PP_Resource devices,
@@ -104,7 +83,6 @@ interface PPB_VideoCapture_Dev {
* (e.g. to do multi-frame processing, like video encoding), it should request
* that many more.
*/
- [version=0.2]
int32_t Open(
[in] PP_Resource video_capture,
[in] PP_Resource device_ref,
@@ -118,7 +96,6 @@ interface PPB_VideoCapture_Dev {
* Returns PP_ERROR_FAILED if called when the capture was already started, or
* PP_OK on success.
*/
- [version=0.2]
int32_t StartCapture(
[in] PP_Resource video_capture);
@@ -150,7 +127,6 @@ interface PPB_VideoCapture_Dev {
* If a video capture resource is destroyed while a device is still open, then
* it will be implicitly closed, so you are not required to call this method.
*/
- [version=0.2]
void Close(
[in] PP_Resource video_capture);
};
diff --git a/ppapi/c/dev/ppb_video_capture_dev.h b/ppapi/c/dev/ppb_video_capture_dev.h
index 5a48725..baec914 100644
--- a/ppapi/c/dev/ppb_video_capture_dev.h
+++ b/ppapi/c/dev/ppb_video_capture_dev.h
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-/* From dev/ppb_video_capture_dev.idl modified Wed Feb 15 12:15:46 2012. */
+/* From dev/ppb_video_capture_dev.idl modified Tue Oct 30 17:39:32 2012. */
#ifndef PPAPI_C_DEV_PPB_VIDEO_CAPTURE_DEV_H_
#define PPAPI_C_DEV_PPB_VIDEO_CAPTURE_DEV_H_
@@ -16,7 +16,6 @@
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_stdint.h"
-#define PPB_VIDEOCAPTURE_DEV_INTERFACE_0_1 "PPB_VideoCapture(Dev);0.1"
#define PPB_VIDEOCAPTURE_DEV_INTERFACE_0_2 "PPB_VideoCapture(Dev);0.2"
#define PPB_VIDEOCAPTURE_DEV_INTERFACE PPB_VIDEOCAPTURE_DEV_INTERFACE_0_2
@@ -136,17 +135,6 @@ struct PPB_VideoCapture_Dev_0_2 {
};
typedef struct PPB_VideoCapture_Dev_0_2 PPB_VideoCapture_Dev;
-
-struct PPB_VideoCapture_Dev_0_1 {
- PP_Resource (*Create)(PP_Instance instance);
- PP_Bool (*IsVideoCapture)(PP_Resource video_capture);
- int32_t (*StartCapture)(
- PP_Resource video_capture,
- const struct PP_VideoCaptureDeviceInfo_Dev* requested_info,
- uint32_t buffer_count);
- int32_t (*ReuseBuffer)(PP_Resource video_capture, uint32_t buffer);
- int32_t (*StopCapture)(PP_Resource video_capture);
-};
/**
* @}
*/
diff --git a/ppapi/cpp/dev/video_capture_dev.cc b/ppapi/cpp/dev/video_capture_dev.cc
index 4fc11d5..3aa234f 100644
--- a/ppapi/cpp/dev/video_capture_dev.cc
+++ b/ppapi/cpp/dev/video_capture_dev.cc
@@ -18,28 +18,17 @@ template <> const char* interface_name<PPB_VideoCapture_Dev_0_2>() {
return PPB_VIDEOCAPTURE_DEV_INTERFACE_0_2;
}
-template <> const char* interface_name<PPB_VideoCapture_Dev_0_1>() {
- return PPB_VIDEOCAPTURE_DEV_INTERFACE_0_1;
-}
-
} // namespace
-VideoCapture_Dev::VideoCapture_Dev(const InstanceHandle& instance)
- : requested_info_(),
- buffer_count_(0) {
+VideoCapture_Dev::VideoCapture_Dev(const InstanceHandle& instance) {
if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev_0_2>()->Create(
instance.pp_instance()));
- } else if (has_interface<PPB_VideoCapture_Dev_0_1>()) {
- PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev_0_1>()->Create(
- instance.pp_instance()));
}
}
VideoCapture_Dev::VideoCapture_Dev(PP_Resource resource)
- : Resource(resource),
- requested_info_(),
- buffer_count_(0) {
+ : Resource(resource) {
}
VideoCapture_Dev::~VideoCapture_Dev() {
@@ -47,8 +36,7 @@ VideoCapture_Dev::~VideoCapture_Dev() {
// static
bool VideoCapture_Dev::IsAvailable() {
- return has_interface<PPB_VideoCapture_Dev_0_2>() ||
- has_interface<PPB_VideoCapture_Dev_0_1>();
+ return has_interface<PPB_VideoCapture_Dev_0_2>();
}
int32_t VideoCapture_Dev::EnumerateDevices(
@@ -79,15 +67,6 @@ int32_t VideoCapture_Dev::Open(
callback.pp_completion_callback());
}
- if (has_interface<PPB_VideoCapture_Dev_0_1>()) {
- if (device_ref.is_null()) {
- requested_info_ = requested_info;
- buffer_count_ = buffer_count;
- return callback.MayForce(PP_OK);
- }
- return callback.MayForce(PP_ERROR_NOTSUPPORTED);
- }
-
return callback.MayForce(PP_ERROR_NOINTERFACE);
}
@@ -97,11 +76,6 @@ int32_t VideoCapture_Dev::StartCapture() {
pp_resource());
}
- if (has_interface<PPB_VideoCapture_Dev_0_1>()) {
- return get_interface<PPB_VideoCapture_Dev_0_1>()->StartCapture(
- pp_resource(), &requested_info_, buffer_count_);
- }
-
return PP_ERROR_NOINTERFACE;
}
@@ -111,11 +85,6 @@ int32_t VideoCapture_Dev::ReuseBuffer(uint32_t buffer) {
buffer);
}
- if (has_interface<PPB_VideoCapture_Dev_0_1>()) {
- return get_interface<PPB_VideoCapture_Dev_0_1>()->ReuseBuffer(pp_resource(),
- buffer);
- }
-
return PP_ERROR_NOINTERFACE;
}
@@ -125,11 +94,6 @@ int32_t VideoCapture_Dev::StopCapture() {
pp_resource());
}
- if (has_interface<PPB_VideoCapture_Dev_0_1>()) {
- return get_interface<PPB_VideoCapture_Dev_0_1>()->StopCapture(
- pp_resource());
- }
-
return PP_ERROR_NOINTERFACE;
}
diff --git a/ppapi/cpp/dev/video_capture_dev.h b/ppapi/cpp/dev/video_capture_dev.h
index 87ce50d..45d68c62f6 100644
--- a/ppapi/cpp/dev/video_capture_dev.h
+++ b/ppapi/cpp/dev/video_capture_dev.h
@@ -37,11 +37,6 @@ class VideoCapture_Dev : public Resource {
int32_t ReuseBuffer(uint32_t buffer);
int32_t StopCapture();
void Close();
-
- private:
- // Used to store the arguments of Open() when using the v0.1 interface.
- PP_VideoCaptureDeviceInfo_Dev requested_info_;
- uint32_t buffer_count_;
};
} // namespace pp
diff --git a/ppapi/examples/enumerate_devices/enumerate_devices.html b/ppapi/examples/enumerate_devices/enumerate_devices.html
index d77cadb..6afd94d 100644
--- a/ppapi/examples/enumerate_devices/enumerate_devices.html
+++ b/ppapi/examples/enumerate_devices/enumerate_devices.html
@@ -22,10 +22,10 @@
if (devices_data.length > 0)
device_array = devices_data.split('#__#');
else
- devices_array = [];
+ device_array = [];
var list = document.getElementById('device_list');
- if (devices_array.length == 0)
+ if (device_array.length == 0)
list.innerHTML = 'No devices.';
for (var i = 0; i < device_array.length; ++i) {
var list_item = document.createElement('li');
diff --git a/ppapi/examples/video_capture/video_capture.cc b/ppapi/examples/video_capture/video_capture.cc
index 25d2ef0..8e080e1 100644
--- a/ppapi/examples/video_capture/video_capture.cc
+++ b/ppapi/examples/video_capture/video_capture.cc
@@ -198,13 +198,6 @@ void VCDemoInstance::HandleMessage(const pp::Var& message_data) {
video_capture_.EnumerateDevices(callback);
} else if (event == "UseDefault") {
Open(pp::DeviceRef_Dev());
- } else if (event == "UseDefault(v0.1)") {
- const PPB_VideoCapture_Dev_0_1* video_capture_0_1 =
- static_cast<const PPB_VideoCapture_Dev_0_1*>(
- pp::Module::Get()->GetBrowserInterface(
- PPB_VIDEOCAPTURE_DEV_INTERFACE_0_1));
- video_capture_0_1->StartCapture(video_capture_.pp_resource(),
- &capture_info_, 4);
} else if (event == "Stop") {
video_capture_.StopCapture();
}
diff --git a/ppapi/examples/video_capture/video_capture.html b/ppapi/examples/video_capture/video_capture.html
index 4aa888e..5b62c76 100644
--- a/ppapi/examples/video_capture/video_capture.html
+++ b/ppapi/examples/video_capture/video_capture.html
@@ -38,10 +38,8 @@
UseDevice(device_array[index], index);
}
- function UseDefaultDevice(use_0_1_interface) {
- var display_text = use_0_1_interface ? 'Default(v0.1)' : 'Default';
- var command = use_0_1_interface ? 'UseDefault(v0.1)' : 'UseDefault';
- UseDevice(display_text, command);
+ function UseDefaultDevice() {
+ UseDevice('Default', 'UseDefault');
}
function UseDevice(display_text, command) {
@@ -84,9 +82,7 @@
<div id="available_devices">
Available device(s), choose one to open:
<ul id="device_list">
- <li><a href="javascript:UseDefaultDevice(true);">
- Default - use interface version 0.1</a></li>
- <li><a href="javascript:UseDefaultDevice(false);">Default</a></li>
+ <li><a href="javascript:UseDefaultDevice();">Default</a></li>
</ul>
</div>
<div id="control_panel"></div>
diff --git a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c
index 1231f031..ba2c33c 100644
--- a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c
+++ b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c
@@ -189,7 +189,6 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Testing_Dev_0_91;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_TextInput_Dev_0_1;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_TextInput_Dev_0_2;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_URLUtil_Dev_0_6;
-static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_VideoCapture_Dev_0_1;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_VideoCapture_Dev_0_2;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_VideoDecoder_Dev_0_16;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_View_Dev_0_1;
@@ -1869,8 +1868,6 @@ struct PP_Var Pnacl_M17_PPB_URLUtil_Dev_GetPluginInstanceURL(PP_Instance instanc
/* End wrapper methods for PPB_URLUtil_Dev_0_6 */
-/* Not generating wrapper methods for PPB_VideoCapture_Dev_0_1 */
-
/* Begin wrapper methods for PPB_VideoCapture_Dev_0_2 */
static __attribute__((pnaclcall))
@@ -3933,8 +3930,6 @@ struct PPB_URLUtil_Dev_0_6 Pnacl_Wrappers_PPB_URLUtil_Dev_0_6 = {
.GetPluginInstanceURL = (struct PP_Var (*)(PP_Instance instance, struct PP_URLComponents_Dev* components))&Pnacl_M17_PPB_URLUtil_Dev_GetPluginInstanceURL
};
-/* Not generating wrapper interface for PPB_VideoCapture_Dev_0_1 */
-
struct PPB_VideoCapture_Dev_0_2 Pnacl_Wrappers_PPB_VideoCapture_Dev_0_2 = {
.Create = (PP_Resource (*)(PP_Instance instance))&Pnacl_M19_PPB_VideoCapture_Dev_Create,
.IsVideoCapture = (PP_Bool (*)(PP_Resource video_capture))&Pnacl_M19_PPB_VideoCapture_Dev_IsVideoCapture,
@@ -4771,12 +4766,6 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_URLUtil_Dev_0_6 = {
.real_iface = NULL
};
-static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_VideoCapture_Dev_0_1 = {
- .iface_macro = PPB_VIDEOCAPTURE_DEV_INTERFACE_0_1,
- .wrapped_iface = NULL /* Still need slot for real_iface */,
- .real_iface = NULL
-};
-
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_VideoCapture_Dev_0_2 = {
.iface_macro = PPB_VIDEOCAPTURE_DEV_INTERFACE_0_2,
.wrapped_iface = (void *) &Pnacl_Wrappers_PPB_VideoCapture_Dev_0_2,
@@ -5177,7 +5166,6 @@ static struct __PnaclWrapperInfo *s_ppb_wrappers[] = {
&Pnacl_WrapperInfo_PPB_TextInput_Dev_0_1,
&Pnacl_WrapperInfo_PPB_TextInput_Dev_0_2,
&Pnacl_WrapperInfo_PPB_URLUtil_Dev_0_6,
- &Pnacl_WrapperInfo_PPB_VideoCapture_Dev_0_1,
&Pnacl_WrapperInfo_PPB_VideoCapture_Dev_0_2,
&Pnacl_WrapperInfo_PPB_VideoDecoder_Dev_0_16,
&Pnacl_WrapperInfo_PPB_View_Dev_0_1,
diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi
index 4b6fad7..47769bd 100644
--- a/ppapi/ppapi_proxy.gypi
+++ b/ppapi/ppapi_proxy.gypi
@@ -119,8 +119,6 @@
'proxy/ppb_url_response_info_proxy.h',
'proxy/ppb_var_deprecated_proxy.cc',
'proxy/ppb_var_deprecated_proxy.h',
- 'proxy/ppb_video_capture_proxy.cc',
- 'proxy/ppb_video_capture_proxy.h',
'proxy/ppb_video_decoder_proxy.cc',
'proxy/ppb_video_decoder_proxy.h',
'proxy/ppb_x509_certificate_private_proxy.cc',
@@ -163,6 +161,8 @@
'proxy/url_request_info_resource.cc',
'proxy/url_request_info_resource.h',
'proxy/var_serialization_rules.h',
+ 'proxy/video_capture_resource.cc',
+ 'proxy/video_capture_resource.h',
'proxy/websocket_resource.cc',
'proxy/websocket_resource.h',
],
@@ -188,12 +188,12 @@
'proxy/ppb_flash_proxy.cc',
'proxy/ppb_pdf_proxy.cc',
'proxy/ppb_talk_private_proxy.cc',
- 'proxy/ppb_video_capture_proxy.cc',
'proxy/ppb_video_decoder_proxy.cc',
'proxy/ppp_content_decryptor_private_proxy.cc',
'proxy/ppp_instance_private_proxy.cc',
'proxy/ppp_video_decoder_proxy.cc',
'proxy/serialized_flash_menu.cc',
+ 'proxy/video_capture_resource.cc',
],
}],
],
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi
index 73c73f9..f2f4f85 100644
--- a/ppapi/ppapi_shared.gypi
+++ b/ppapi/ppapi_shared.gypi
@@ -82,8 +82,6 @@
'shared_impl/ppb_var_shared.h',
'shared_impl/ppb_video_decoder_shared.cc',
'shared_impl/ppb_video_decoder_shared.h',
- 'shared_impl/ppb_video_capture_shared.cc',
- 'shared_impl/ppb_video_capture_shared.h',
'shared_impl/ppb_view_shared.cc',
'shared_impl/ppb_view_shared.h',
'shared_impl/ppp_flash_browser_operations_shared.h',
diff --git a/ppapi/proxy/flash_resource.cc b/ppapi/proxy/flash_resource.cc
index b8dd5c8..afbe624 100644
--- a/ppapi/proxy/flash_resource.cc
+++ b/ppapi/proxy/flash_resource.cc
@@ -4,12 +4,7 @@
#include "ppapi/proxy/flash_resource.h"
-#include "ipc/ipc_message.h"
-#include "ppapi/c/pp_errors.h"
-#include "ppapi/proxy/dispatch_reply_message.h"
#include "ppapi/proxy/ppapi_messages.h"
-#include "ppapi/shared_impl/array_writer.h"
-#include "ppapi/thunk/enter.h"
namespace ppapi {
namespace proxy {
@@ -26,42 +21,5 @@ thunk::PPB_Flash_Functions_API* FlashResource::AsPPB_Flash_Functions_API() {
return this;
}
-int32_t FlashResource::EnumerateVideoCaptureDevices(
- PP_Instance instance,
- PP_Resource video_capture,
- const PP_ArrayOutput& devices) {
- ArrayWriter output;
- output.set_pp_array_output(devices);
- if (!output.is_valid())
- return PP_ERROR_BADARGUMENT;
-
- thunk::EnterResourceNoLock<thunk::PPB_VideoCapture_API> enter(video_capture,
- true);
- if (enter.failed())
- return PP_ERROR_NOINTERFACE;
-
- std::vector<ppapi::DeviceRefData> device_ref_data;
- int32_t result =
- SyncCall<PpapiPluginMsg_Flash_EnumerateVideoCaptureDevicesReply>(
- RENDERER,
- PpapiHostMsg_Flash_EnumerateVideoCaptureDevices(
- enter.resource()->host_resource()),
- &device_ref_data);
- if (result != PP_OK)
- return result;
-
- std::vector<scoped_refptr<Resource> > device_resources;
- for (size_t i = 0; i < device_ref_data.size(); ++i) {
- scoped_refptr<Resource> resource(new PPB_DeviceRef_Shared(
- OBJECT_IS_PROXY, instance, device_ref_data[i]));
- device_resources.push_back(resource);
- }
-
- if (!output.StoreResourceVector(device_resources))
- return PP_ERROR_FAILED;
-
- return PP_OK;
-}
-
} // namespace proxy
} // namespace ppapi
diff --git a/ppapi/proxy/flash_resource.h b/ppapi/proxy/flash_resource.h
index b5a4428..a0fe0e7 100644
--- a/ppapi/proxy/flash_resource.h
+++ b/ppapi/proxy/flash_resource.h
@@ -10,8 +10,6 @@
#include "ppapi/proxy/ppapi_proxy_export.h"
#include "ppapi/thunk/ppb_flash_functions_api.h"
-struct PP_ArrayOutput;
-
namespace ppapi {
namespace proxy {
@@ -25,12 +23,6 @@ class PPAPI_PROXY_EXPORT FlashResource
// Resource overrides.
virtual thunk::PPB_Flash_Functions_API* AsPPB_Flash_Functions_API() OVERRIDE;
- // PPB_Flash_Functions_API.
- virtual int32_t EnumerateVideoCaptureDevices(
- PP_Instance instance,
- PP_Resource video_capture,
- const PP_ArrayOutput& devices) OVERRIDE;
-
private:
DISALLOW_COPY_AND_ASSIGN(FlashResource);
};
diff --git a/ppapi/proxy/flash_resource_unittest.cc b/ppapi/proxy/flash_resource_unittest.cc
index 901e855..be083ed 100644
--- a/ppapi/proxy/flash_resource_unittest.cc
+++ b/ppapi/proxy/flash_resource_unittest.cc
@@ -17,33 +17,6 @@ namespace {
typedef PluginProxyTest FlashResourceTest;
-// This simulates the creation reply message of a VideoCapture resource. This
-// won't be necessary once VideoCapture is converted to the new-style proxy.
-class VideoCaptureCreationHandler : public IPC::Listener {
- public:
- VideoCaptureCreationHandler(ResourceMessageTestSink* test_sink,
- PP_Instance instance)
- : test_sink_(test_sink),
- instance_(instance) {
- }
- virtual ~VideoCaptureCreationHandler() {}
-
- virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE {
- if (msg.type() != ::PpapiHostMsg_PPBVideoCapture_Create::ID)
- return false;
-
- IPC::Message* reply_msg = IPC::SyncMessage::GenerateReply(&msg);
- HostResource resource;
- resource.SetHostResource(instance_, 12345);
- PpapiHostMsg_PPBVideoCapture_Create::WriteReplyParams(reply_msg, resource);
- test_sink_->SetSyncReplyMessage(reply_msg);
- return true;
- }
- private:
- ResourceMessageTestSink* test_sink_;
- PP_Instance instance_;
-};
-
void* Unused(void* user_data, uint32_t element_count, uint32_t element_size) {
return NULL;
}
@@ -60,19 +33,15 @@ TEST_F(FlashResourceTest, EnumerateVideoCaptureDevices) {
// Set up a sync call handler that should return this message.
std::vector<ppapi::DeviceRefData> reply_device_ref_data;
int32_t expected_result = PP_OK;
- PpapiPluginMsg_Flash_EnumerateVideoCaptureDevicesReply reply_msg(
+ PpapiPluginMsg_VideoCapture_EnumerateDevicesReply reply_msg(
reply_device_ref_data);
ResourceSyncCallHandler enumerate_video_devices_handler(
&sink(),
- PpapiHostMsg_Flash_EnumerateVideoCaptureDevices::ID,
+ PpapiHostMsg_VideoCapture_EnumerateDevices::ID,
expected_result,
reply_msg);
sink().AddFilter(&enumerate_video_devices_handler);
- // Setup the handler to simulate creation of the video resource.
- VideoCaptureCreationHandler video_creation_handler(&sink(), pp_instance());
- sink().AddFilter(&video_creation_handler);
-
// Set up the arguments to the call.
ScopedPPResource video_capture(ScopedPPResource::PassRef(),
::ppapi::thunk::GetPPB_VideoCapture_Dev_0_2_Thunk()->Create(
@@ -90,13 +59,12 @@ TEST_F(FlashResourceTest, EnumerateVideoCaptureDevices) {
// Check the result is as expected.
EXPECT_EQ(expected_result, actual_result);
- // Should have sent an "EnumerateVideoCaptureDevices" message.
+ // Should have sent an "VideoCapture_EnumerateDevices" message.
ASSERT_TRUE(enumerate_video_devices_handler.last_handled_msg().type() ==
- PpapiHostMsg_Flash_EnumerateVideoCaptureDevices::ID);
+ PpapiHostMsg_VideoCapture_EnumerateDevices::ID);
// Remove the filter or it will be destroyed before the sink() is destroyed.
sink().RemoveFilter(&enumerate_video_devices_handler);
- sink().RemoveFilter(&video_creation_handler);
}
} // namespace proxy
diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc
index 60ab4f2..d0efc1f 100644
--- a/ppapi/proxy/interface_list.cc
+++ b/ppapi/proxy/interface_list.cc
@@ -102,7 +102,6 @@
#include "ppapi/proxy/ppb_url_loader_proxy.h"
#include "ppapi/proxy/ppb_url_response_info_proxy.h"
#include "ppapi/proxy/ppb_var_deprecated_proxy.h"
-#include "ppapi/proxy/ppb_video_capture_proxy.h"
#include "ppapi/proxy/ppb_video_decoder_proxy.h"
#include "ppapi/proxy/ppb_x509_certificate_private_proxy.h"
#include "ppapi/proxy/ppp_class_proxy.h"
@@ -283,7 +282,6 @@ InterfaceList::InterfaceList() {
AddPPP(PPP_Graphics3D_Proxy::GetInfo());
#if !defined(OS_NACL)
AddPPP(PPP_Instance_Private_Proxy::GetInfo());
- AddPPP(PPP_VideoCapture_Proxy::GetInfo());
AddPPP(PPP_VideoDecoder_Proxy::GetInfo());
#endif
}
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index f2e7187..95384e2e 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -265,14 +265,7 @@ IPC_STRUCT_TRAITS_BEGIN(ppapi::NetworkInfo)
IPC_STRUCT_TRAITS_END()
#if !defined(OS_NACL) && !defined(NACL_WIN64)
-IPC_STRUCT_TRAITS_BEGIN(ppapi::proxy::PPPVideoCapture_Buffer)
- IPC_STRUCT_TRAITS_MEMBER(resource)
- IPC_STRUCT_TRAITS_MEMBER(handle)
- IPC_STRUCT_TRAITS_MEMBER(size)
-IPC_STRUCT_TRAITS_END()
-// TODO(tomfinegan): This is identical to PPPVideoCapture_Buffer, maybe replace
-// both with a single type?
IPC_STRUCT_TRAITS_BEGIN(ppapi::proxy::PPPDecryptor_Buffer)
IPC_STRUCT_TRAITS_MEMBER(resource)
IPC_STRUCT_TRAITS_MEMBER(handle)
@@ -752,31 +745,6 @@ IPC_SYNC_MESSAGE_ROUTED1_1(PpapiMsg_PPPInstancePrivate_GetInstanceObject,
PP_Instance /* instance */,
ppapi::proxy::SerializedVar /* result */)
-// PPB_VideoCapture_Dev
-IPC_MESSAGE_ROUTED3(PpapiMsg_PPBVideoCapture_EnumerateDevicesACK,
- ppapi::HostResource /* video_capture */,
- int32_t /* result */,
- std::vector<ppapi::DeviceRefData> /* devices */)
-IPC_MESSAGE_ROUTED2(PpapiMsg_PPBVideoCapture_OpenACK,
- ppapi::HostResource /* video_capture */,
- int32_t /* result */)
-
-// PPP_VideoCapture_Dev
-IPC_MESSAGE_ROUTED3(
- PpapiMsg_PPPVideoCapture_OnDeviceInfo,
- ppapi::HostResource /* video_capture */,
- PP_VideoCaptureDeviceInfo_Dev /* info */,
- std::vector<ppapi::proxy::PPPVideoCapture_Buffer> /* buffers */)
-IPC_MESSAGE_ROUTED2(PpapiMsg_PPPVideoCapture_OnStatus,
- ppapi::HostResource /* video_capture */,
- uint32_t /* status */)
-IPC_MESSAGE_ROUTED2(PpapiMsg_PPPVideoCapture_OnError,
- ppapi::HostResource /* video_capture */,
- uint32_t /* error_code */)
-IPC_MESSAGE_ROUTED2(PpapiMsg_PPPVideoCapture_OnBufferReady,
- ppapi::HostResource /* video_capture */,
- uint32_t /* buffer */)
-
// PPB_VideoDecoder_Dev.
// (Messages from renderer to plugin to notify it to run callbacks.)
IPC_MESSAGE_ROUTED3(PpapiMsg_PPBVideoDecoder_EndOfBitstreamACK,
@@ -1300,30 +1268,6 @@ IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBTesting_SimulateInputEvent,
ppapi::InputEventData /* input_event */)
#if !defined(OS_NACL) && !defined(NACL_WIN64)
-// PPB_VideoCapture_Dev.
-IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBVideoCapture_Create,
- PP_Instance /* instance */,
- ppapi::HostResource /* result */)
-IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBVideoCapture_EnumerateDevices,
- ppapi::HostResource /* video_capture */)
-IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBVideoCapture_Open,
- ppapi::HostResource /* video_capture */,
- std::string /* device_id */,
- PP_VideoCaptureDeviceInfo_Dev /* requested_info */,
- uint32_t /* buffer_count */)
-IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBVideoCapture_StartCapture,
- ppapi::HostResource /* video_capture */)
-IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBVideoCapture_ReuseBuffer,
- ppapi::HostResource /* video_capture */,
- uint32_t /* buffer */)
-IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBVideoCapture_StopCapture,
- ppapi::HostResource /* video_capture */)
-IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBVideoCapture_Close,
- ppapi::HostResource /* video_capture */)
-IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBVideoCapture_StartCapture0_1,
- ppapi::HostResource /* video_capture */,
- PP_VideoCaptureDeviceInfo_Dev /* requested_info */,
- uint32_t /* buffer_count */)
// PPB_VideoDecoder.
IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBVideoDecoder_Create,
@@ -1727,8 +1671,35 @@ IPC_MESSAGE_CONTROL1(PpapiPluginMsg_FlashMenu_ShowReply,
// Flash functions.
IPC_MESSAGE_CONTROL0(PpapiHostMsg_Flash_Create)
-IPC_MESSAGE_CONTROL1(PpapiHostMsg_Flash_EnumerateVideoCaptureDevices,
- ppapi::HostResource /* video_capture */)
-IPC_MESSAGE_CONTROL1(PpapiPluginMsg_Flash_EnumerateVideoCaptureDevicesReply,
+
+// VideoCapture_Dev, plugin -> host
+IPC_MESSAGE_CONTROL0(PpapiHostMsg_VideoCapture_Create)
+IPC_MESSAGE_CONTROL0(PpapiHostMsg_VideoCapture_StartCapture)
+IPC_MESSAGE_CONTROL1(PpapiHostMsg_VideoCapture_ReuseBuffer,
+ uint32_t /* buffer */)
+IPC_MESSAGE_CONTROL0(PpapiHostMsg_VideoCapture_StopCapture)
+IPC_MESSAGE_CONTROL0(PpapiHostMsg_VideoCapture_Close)
+
+// VideoCapture_Dev, plugin -> host -> plugin
+IPC_MESSAGE_CONTROL0(PpapiHostMsg_VideoCapture_EnumerateDevices)
+IPC_MESSAGE_CONTROL1(PpapiPluginMsg_VideoCapture_EnumerateDevicesReply,
std::vector<ppapi::DeviceRefData> /* devices */)
+IPC_MESSAGE_CONTROL3(PpapiHostMsg_VideoCapture_Open,
+ std::string /* device_id */,
+ PP_VideoCaptureDeviceInfo_Dev /* requested_info */,
+ uint32_t /* buffer_count */)
+IPC_MESSAGE_CONTROL0(PpapiPluginMsg_VideoCapture_OpenReply)
+
+// VideoCapture_Dev, host -> plugin
+IPC_MESSAGE_CONTROL3(PpapiPluginMsg_VideoCapture_OnDeviceInfo,
+ PP_VideoCaptureDeviceInfo_Dev /* info */,
+ std::vector<ppapi::HostResource> /* buffers */,
+ uint32_t /* buffer_size */)
+IPC_MESSAGE_CONTROL1(PpapiPluginMsg_VideoCapture_OnStatus,
+ uint32_t /* status */)
+IPC_MESSAGE_CONTROL1(PpapiPluginMsg_VideoCapture_OnError,
+ uint32_t /* error */)
+IPC_MESSAGE_CONTROL1(PpapiPluginMsg_VideoCapture_OnBufferReady,
+ uint32_t /* buffer */)
+
#endif // !defined(OS_NACL) && !defined(NACL_WIN64)
diff --git a/ppapi/proxy/ppb_video_capture_proxy.cc b/ppapi/proxy/ppb_video_capture_proxy.cc
deleted file mode 100644
index 2c65dc4..0000000
--- a/ppapi/proxy/ppb_video_capture_proxy.cc
+++ /dev/null
@@ -1,546 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ppapi/proxy/ppb_video_capture_proxy.h"
-
-#include "base/compiler_specific.h"
-#include "base/logging.h"
-#include "build/build_config.h"
-#include "ppapi/c/pp_errors.h"
-#include "ppapi/c/pp_resource.h"
-#include "ppapi/c/ppb_core.h"
-#include "ppapi/c/dev/ppb_video_capture_dev.h"
-#include "ppapi/proxy/enter_proxy.h"
-#include "ppapi/proxy/host_dispatcher.h"
-#include "ppapi/proxy/plugin_dispatcher.h"
-#include "ppapi/proxy/ppapi_messages.h"
-#include "ppapi/proxy/ppb_buffer_proxy.h"
-#include "ppapi/shared_impl/ppapi_globals.h"
-#include "ppapi/shared_impl/ppb_video_capture_shared.h"
-#include "ppapi/shared_impl/proxy_lock.h"
-#include "ppapi/shared_impl/resource_tracker.h"
-#include "ppapi/shared_impl/tracked_callback.h"
-#include "ppapi/thunk/ppb_buffer_api.h"
-#include "ppapi/thunk/ppb_buffer_trusted_api.h"
-#include "ppapi/thunk/ppb_video_capture_api.h"
-#include "ppapi/thunk/resource_creation_api.h"
-#include "ppapi/thunk/thunk.h"
-
-using ppapi::thunk::EnterResourceNoLock;
-using ppapi::thunk::PPB_Buffer_API;
-using ppapi::thunk::PPB_BufferTrusted_API;
-using ppapi::thunk::PPB_VideoCapture_API;
-
-namespace ppapi {
-namespace proxy {
-
-namespace {
-
-InterfaceProxy* CreatePPPVideoCaptureProxy(Dispatcher* dispatcher) {
- return new PPP_VideoCapture_Proxy(dispatcher);
-}
-
-void OnDeviceInfo(PP_Instance instance,
- PP_Resource resource,
- const PP_VideoCaptureDeviceInfo_Dev* info,
- uint32_t buffer_count,
- const PP_Resource resources[]) {
- HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
- if (!dispatcher) {
- NOTREACHED();
- return;
- }
- HostResource host_resource;
- host_resource.SetHostResource(instance, resource);
- std::vector<PPPVideoCapture_Buffer> buffers(buffer_count);
- const PPB_Core* core = static_cast<const PPB_Core*>(
- dispatcher->local_get_interface()(PPB_CORE_INTERFACE));
- DCHECK(core);
- for (uint32_t i = 0; i < buffer_count; ++i) {
- // We need to take a ref on the resource now. The browser may drop
- // references once we return from here, but we're sending an asynchronous
- // message. The plugin side takes ownership of that reference.
- core->AddRefResource(resources[i]);
- buffers[i].resource.SetHostResource(instance, resources[i]);
- {
- EnterResourceNoLock<PPB_Buffer_API> enter(resources[i], true);
- DCHECK(enter.succeeded());
- PP_Bool result = enter.object()->Describe(&buffers[i].size);
- DCHECK(result);
- }
- {
- EnterResourceNoLock<PPB_BufferTrusted_API> enter(resources[i], true);
- DCHECK(enter.succeeded());
- int handle;
- int32_t result = enter.object()->GetSharedMemory(&handle);
- DCHECK(result == PP_OK);
- // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle,
- // those casts are ugly.
- base::PlatformFile platform_file =
-#if defined(OS_WIN)
- reinterpret_cast<HANDLE>(static_cast<intptr_t>(handle));
-#elif defined(OS_POSIX)
- handle;
-#else
-#error Not implemented.
-#endif
- buffers[i].handle =
- dispatcher->ShareHandleWithRemote(platform_file, false);
- }
- }
- dispatcher->Send(new PpapiMsg_PPPVideoCapture_OnDeviceInfo(
- API_ID_PPP_VIDEO_CAPTURE_DEV, host_resource, *info, buffers));
-}
-
-void OnStatus(PP_Instance instance, PP_Resource resource, uint32_t status) {
- HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
- if (!dispatcher) {
- NOTREACHED();
- return;
- }
- HostResource host_resource;
- host_resource.SetHostResource(instance, resource);
- dispatcher->Send(new PpapiMsg_PPPVideoCapture_OnStatus(
- API_ID_PPP_VIDEO_CAPTURE_DEV, host_resource, status));
-}
-
-void OnError(PP_Instance instance, PP_Resource resource, uint32_t error_code) {
- HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
- if (!dispatcher) {
- NOTREACHED();
- return;
- }
- HostResource host_resource;
- host_resource.SetHostResource(instance, resource);
- dispatcher->Send(new PpapiMsg_PPPVideoCapture_OnError(
- API_ID_PPP_VIDEO_CAPTURE_DEV, host_resource, error_code));
-}
-
-void OnBufferReady(PP_Instance instance,
- PP_Resource resource,
- uint32_t buffer) {
- HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
- if (!dispatcher) {
- NOTREACHED();
- return;
- }
- HostResource host_resource;
- host_resource.SetHostResource(instance, resource);
- dispatcher->Send(new PpapiMsg_PPPVideoCapture_OnBufferReady(
- API_ID_PPP_VIDEO_CAPTURE_DEV, host_resource, buffer));
-}
-
-PPP_VideoCapture_Dev ppp_video_capture = {
- OnDeviceInfo,
- OnStatus,
- OnError,
- OnBufferReady
-};
-
-} // namespace
-
-class VideoCapture : public PPB_VideoCapture_Shared {
- public:
- explicit VideoCapture(const HostResource& resource);
- virtual ~VideoCapture();
-
- bool OnStatus(PP_VideoCaptureStatus_Dev status);
-
- void set_status(PP_VideoCaptureStatus_Dev status) {
- SetStatus(status, true);
- }
-
- void SetBufferCount(size_t count) {
- buffer_in_use_ = std::vector<bool>(count);
- }
-
- void SetBufferInUse(uint32_t buffer) {
- DCHECK(buffer < buffer_in_use_.size());
- buffer_in_use_[buffer] = true;
- }
-
- private:
- // PPB_VideoCapture_Shared implementation.
- virtual int32_t InternalEnumerateDevices(
- PP_Resource* devices,
- scoped_refptr<TrackedCallback> callback) OVERRIDE;
- virtual int32_t InternalOpen(
- const std::string& device_id,
- const PP_VideoCaptureDeviceInfo_Dev& requested_info,
- uint32_t buffer_count,
- scoped_refptr<TrackedCallback> callback) OVERRIDE;
- virtual int32_t InternalStartCapture() OVERRIDE;
- virtual int32_t InternalReuseBuffer(uint32_t buffer) OVERRIDE;
- virtual int32_t InternalStopCapture() OVERRIDE;
- virtual void InternalClose() OVERRIDE;
- virtual int32_t InternalStartCapture0_1(
- const PP_VideoCaptureDeviceInfo_Dev& requested_info,
- uint32_t buffer_count) OVERRIDE;
- virtual const std::vector<DeviceRefData>&
- InternalGetDeviceRefData() const OVERRIDE;
-
- PluginDispatcher* GetDispatcher() const {
- return PluginDispatcher::GetForResource(this);
- }
-
- std::vector<bool> buffer_in_use_;
-
- DISALLOW_COPY_AND_ASSIGN(VideoCapture);
-};
-
-VideoCapture::VideoCapture(const HostResource& resource)
- : PPB_VideoCapture_Shared(resource) {
-}
-
-VideoCapture::~VideoCapture() {
- Close();
-}
-
-bool VideoCapture::OnStatus(PP_VideoCaptureStatus_Dev status) {
- switch (status) {
- case PP_VIDEO_CAPTURE_STATUS_STARTED:
- case PP_VIDEO_CAPTURE_STATUS_PAUSED:
- case PP_VIDEO_CAPTURE_STATUS_STOPPED:
- return SetStatus(status, false);
- case PP_VIDEO_CAPTURE_STATUS_STARTING:
- case PP_VIDEO_CAPTURE_STATUS_STOPPING:
- // Those states are not sent by the browser.
- break;
- }
-
- NOTREACHED();
- return false;
-}
-
-int32_t VideoCapture::InternalEnumerateDevices(
- PP_Resource* devices,
- scoped_refptr<TrackedCallback> callback) {
- devices_ = devices;
- enumerate_devices_callback_ = callback;
- GetDispatcher()->Send(new PpapiHostMsg_PPBVideoCapture_EnumerateDevices(
- API_ID_PPB_VIDEO_CAPTURE_DEV, host_resource()));
- return PP_OK_COMPLETIONPENDING;
-}
-
-int32_t VideoCapture::InternalOpen(
- const std::string& device_id,
- const PP_VideoCaptureDeviceInfo_Dev& requested_info,
- uint32_t buffer_count,
- scoped_refptr<TrackedCallback> callback) {
- open_callback_ = callback;
- GetDispatcher()->Send(new PpapiHostMsg_PPBVideoCapture_Open(
- API_ID_PPB_VIDEO_CAPTURE_DEV, host_resource(), device_id, requested_info,
- buffer_count));
- return PP_OK_COMPLETIONPENDING;
-}
-
-int32_t VideoCapture::InternalStartCapture() {
- buffer_in_use_.clear();
- GetDispatcher()->Send(new PpapiHostMsg_PPBVideoCapture_StartCapture(
- API_ID_PPB_VIDEO_CAPTURE_DEV, host_resource()));
- return PP_OK;
-}
-
-int32_t VideoCapture::InternalReuseBuffer(uint32_t buffer) {
- if (buffer >= buffer_in_use_.size() || !buffer_in_use_[buffer])
- return PP_ERROR_BADARGUMENT;
- GetDispatcher()->Send(new PpapiHostMsg_PPBVideoCapture_ReuseBuffer(
- API_ID_PPB_VIDEO_CAPTURE_DEV, host_resource(), buffer));
- return PP_OK;
-}
-
-int32_t VideoCapture::InternalStopCapture() {
- GetDispatcher()->Send(new PpapiHostMsg_PPBVideoCapture_StopCapture(
- API_ID_PPB_VIDEO_CAPTURE_DEV, host_resource()));
- return PP_OK;
-}
-
-void VideoCapture::InternalClose() {
- GetDispatcher()->Send(new PpapiHostMsg_PPBVideoCapture_Close(
- API_ID_PPB_VIDEO_CAPTURE_DEV, host_resource()));
-}
-
-int32_t VideoCapture::InternalStartCapture0_1(
- const PP_VideoCaptureDeviceInfo_Dev& requested_info,
- uint32_t buffer_count) {
- buffer_in_use_.clear();
- GetDispatcher()->Send(new PpapiHostMsg_PPBVideoCapture_StartCapture0_1(
- API_ID_PPB_VIDEO_CAPTURE_DEV, host_resource(), requested_info,
- buffer_count));
- return PP_OK;
-}
-
-const std::vector<DeviceRefData>&
- VideoCapture::InternalGetDeviceRefData() const {
- // This should never be called at the plugin side.
- NOTREACHED();
- static std::vector<DeviceRefData> result;
- return result;
-}
-
-PPB_VideoCapture_Proxy::PPB_VideoCapture_Proxy(Dispatcher* dispatcher)
- : InterfaceProxy(dispatcher),
- ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {
-}
-
-PPB_VideoCapture_Proxy::~PPB_VideoCapture_Proxy() {
-}
-
-// static
-PP_Resource PPB_VideoCapture_Proxy::CreateProxyResource(PP_Instance instance) {
- PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
- if (!dispatcher)
- return 0;
-
- HostResource result;
- dispatcher->Send(new PpapiHostMsg_PPBVideoCapture_Create(
- API_ID_PPB_VIDEO_CAPTURE_DEV, instance, &result));
- if (result.is_null())
- return 0;
- return (new VideoCapture(result))->GetReference();
-}
-
-bool PPB_VideoCapture_Proxy::OnMessageReceived(const IPC::Message& msg) {
- if (!dispatcher()->permissions().HasPermission(PERMISSION_DEV))
- return false;
-
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(PPB_VideoCapture_Proxy, msg)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_Create, OnMsgCreate)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_EnumerateDevices,
- OnMsgEnumerateDevices)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_Open, OnMsgOpen)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_StartCapture,
- OnMsgStartCapture)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_ReuseBuffer,
- OnMsgReuseBuffer)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_StopCapture,
- OnMsgStopCapture)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_Close, OnMsgClose)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_StartCapture0_1,
- OnMsgStartCapture0_1)
-
- IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoCapture_EnumerateDevicesACK,
- OnMsgEnumerateDevicesACK)
- IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoCapture_OpenACK,
- OnMsgOpenACK)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- // TODO(brettw) handle bad messages!
- return handled;
-}
-
-void PPB_VideoCapture_Proxy::OnMsgCreate(PP_Instance instance,
- HostResource* result_resource) {
- thunk::EnterResourceCreation enter(instance);
- if (enter.succeeded()) {
- result_resource->SetHostResource(
- instance,
- enter.functions()->CreateVideoCapture(instance));
- }
-}
-
-void PPB_VideoCapture_Proxy::OnMsgEnumerateDevices(
- const HostResource& resource) {
- EnterHostFromHostResourceForceCallback<PPB_VideoCapture_API> enter(
- resource, callback_factory_,
- &PPB_VideoCapture_Proxy::EnumerateDevicesACKInHost, resource);
-
- if (enter.succeeded())
- enter.SetResult(enter.object()->EnumerateDevices(NULL, enter.callback()));
-}
-
-void PPB_VideoCapture_Proxy::OnMsgOpen(
- const ppapi::HostResource& resource,
- const std::string& device_id,
- const PP_VideoCaptureDeviceInfo_Dev& info,
- uint32_t buffers) {
- EnterHostFromHostResourceForceCallback<PPB_VideoCapture_API> enter(
- resource, callback_factory_, &PPB_VideoCapture_Proxy::OpenACKInHost,
- resource);
-
- if (enter.succeeded()) {
- enter.SetResult(enter.object()->Open(device_id, info, buffers,
- enter.callback()));
- }
-}
-
-void PPB_VideoCapture_Proxy::OnMsgStartCapture(const HostResource& resource) {
- EnterHostFromHostResource<PPB_VideoCapture_API> enter(resource);
- if (enter.succeeded())
- enter.object()->StartCapture();
-}
-
-void PPB_VideoCapture_Proxy::OnMsgReuseBuffer(const HostResource& resource,
- uint32_t buffer) {
- EnterHostFromHostResource<PPB_VideoCapture_API> enter(resource);
- if (enter.succeeded())
- enter.object()->ReuseBuffer(buffer);
-}
-
-void PPB_VideoCapture_Proxy::OnMsgStopCapture(const HostResource& resource) {
- EnterHostFromHostResource<PPB_VideoCapture_API> enter(resource);
- if (enter.succeeded())
- enter.object()->StopCapture();
-}
-
-void PPB_VideoCapture_Proxy::OnMsgClose(const HostResource& resource) {
- EnterHostFromHostResource<PPB_VideoCapture_API> enter(resource);
- if (enter.succeeded())
- enter.object()->Close();
-}
-
-void PPB_VideoCapture_Proxy::OnMsgStartCapture0_1(
- const HostResource& resource,
- const PP_VideoCaptureDeviceInfo_Dev& info,
- uint32_t buffers) {
- EnterHostFromHostResource<PPB_VideoCapture_API> enter(resource);
- if (enter.succeeded())
- enter.object()->StartCapture0_1(info, buffers);
-}
-
-void PPB_VideoCapture_Proxy::OnMsgEnumerateDevicesACK(
- const HostResource& resource,
- int32_t result,
- const std::vector<ppapi::DeviceRefData>& devices) {
- EnterPluginFromHostResource<PPB_VideoCapture_API> enter(resource);
- if (enter.succeeded()) {
- static_cast<VideoCapture*>(enter.object())->OnEnumerateDevicesComplete(
- result, devices);
- }
-}
-
-void PPB_VideoCapture_Proxy::OnMsgOpenACK(
- const HostResource& resource,
- int32_t result) {
- EnterPluginFromHostResource<PPB_VideoCapture_API> enter(resource);
- if (enter.succeeded())
- static_cast<VideoCapture*>(enter.object())->OnOpenComplete(result);
-}
-
-void PPB_VideoCapture_Proxy::EnumerateDevicesACKInHost(
- int32_t result,
- const HostResource& resource) {
- EnterHostFromHostResource<PPB_VideoCapture_API> enter(resource);
- dispatcher()->Send(new PpapiMsg_PPBVideoCapture_EnumerateDevicesACK(
- API_ID_PPB_VIDEO_CAPTURE_DEV, resource, result,
- enter.succeeded() && result == PP_OK ?
- enter.object()->GetDeviceRefData() : std::vector<DeviceRefData>()));
-}
-
-void PPB_VideoCapture_Proxy::OpenACKInHost(int32_t result,
- const HostResource& resource) {
- dispatcher()->Send(new PpapiMsg_PPBVideoCapture_OpenACK(
- API_ID_PPB_VIDEO_CAPTURE_DEV, resource, result));
-}
-
-PPP_VideoCapture_Proxy::PPP_VideoCapture_Proxy(Dispatcher* dispatcher)
- : InterfaceProxy(dispatcher),
- ppp_video_capture_impl_(NULL) {
- if (dispatcher->IsPlugin()) {
- ppp_video_capture_impl_ = static_cast<const PPP_VideoCapture_Dev*>(
- dispatcher->local_get_interface()(PPP_VIDEO_CAPTURE_DEV_INTERFACE));
- }
-}
-
-PPP_VideoCapture_Proxy::~PPP_VideoCapture_Proxy() {
-}
-
-// static
-const InterfaceProxy::Info* PPP_VideoCapture_Proxy::GetInfo() {
- static const Info info = {
- &ppp_video_capture,
- PPP_VIDEO_CAPTURE_DEV_INTERFACE,
- API_ID_PPP_VIDEO_CAPTURE_DEV,
- false,
- &CreatePPPVideoCaptureProxy,
- };
- return &info;
-}
-
-bool PPP_VideoCapture_Proxy::OnMessageReceived(const IPC::Message& msg) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(PPP_VideoCapture_Proxy, msg)
- IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoCapture_OnDeviceInfo,
- OnMsgOnDeviceInfo)
- IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoCapture_OnStatus, OnMsgOnStatus)
- IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoCapture_OnError, OnMsgOnError)
- IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoCapture_OnBufferReady,
- OnMsgOnBufferReady)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- // TODO(brettw) handle bad messages!
- return handled;
-}
-
-void PPP_VideoCapture_Proxy::OnMsgOnDeviceInfo(
- const HostResource& host_resource,
- const PP_VideoCaptureDeviceInfo_Dev& info,
- const std::vector<PPPVideoCapture_Buffer>& buffers) {
- EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource);
- if (enter.failed() || !ppp_video_capture_impl_)
- return;
-
- PluginResourceTracker* tracker =
- PluginGlobals::Get()->plugin_resource_tracker();
- scoped_array<PP_Resource> resources(new PP_Resource[buffers.size()]);
- for (size_t i = 0; i < buffers.size(); ++i) {
- // We assume that the browser created a new set of resources.
- DCHECK(!tracker->PluginResourceForHostResource(buffers[i].resource));
- resources[i] = PPB_Buffer_Proxy::AddProxyResource(buffers[i].resource,
- buffers[i].handle,
- buffers[i].size);
- }
-
- VideoCapture* capture = static_cast<VideoCapture*>(enter.object());
- capture->SetBufferCount(buffers.size());
- CallWhileUnlocked(ppp_video_capture_impl_->OnDeviceInfo,
- host_resource.instance(),
- capture->pp_resource(),
- &info,
- static_cast<uint32_t>(buffers.size()),
- const_cast<const PP_Resource*>(resources.get()));
- for (size_t i = 0; i < buffers.size(); ++i)
- tracker->ReleaseResource(resources[i]);
-}
-
-void PPP_VideoCapture_Proxy::OnMsgOnStatus(const HostResource& host_resource,
- uint32_t status) {
- EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource);
- if (enter.failed() || !ppp_video_capture_impl_)
- return;
-
- VideoCapture* capture = static_cast<VideoCapture*>(enter.object());
- if (!capture->OnStatus(static_cast<PP_VideoCaptureStatus_Dev>(status)))
- return;
- CallWhileUnlocked(ppp_video_capture_impl_->OnStatus,
- host_resource.instance(), capture->pp_resource(), status);
-}
-
-void PPP_VideoCapture_Proxy::OnMsgOnError(const HostResource& host_resource,
- uint32_t error_code) {
- EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource);
- if (enter.failed() || !ppp_video_capture_impl_)
- return;
-
- VideoCapture* capture = static_cast<VideoCapture*>(enter.object());
- capture->set_status(PP_VIDEO_CAPTURE_STATUS_STOPPED);
- CallWhileUnlocked(ppp_video_capture_impl_->OnError,
- host_resource.instance(), capture->pp_resource(), error_code);
-}
-
-void PPP_VideoCapture_Proxy::OnMsgOnBufferReady(
- const HostResource& host_resource, uint32_t buffer) {
- EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource);
- if (enter.failed() || !ppp_video_capture_impl_)
- return;
-
- VideoCapture* capture = static_cast<VideoCapture*>(enter.object());
- capture->SetBufferInUse(buffer);
- CallWhileUnlocked(ppp_video_capture_impl_->OnBufferReady,
- host_resource.instance(), capture->pp_resource(), buffer);
-}
-
-} // namespace proxy
-} // namespace ppapi
diff --git a/ppapi/proxy/ppb_video_capture_proxy.h b/ppapi/proxy/ppb_video_capture_proxy.h
deleted file mode 100644
index aeefa33..0000000
--- a/ppapi/proxy/ppb_video_capture_proxy.h
+++ /dev/null
@@ -1,107 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef PPAPI_PROXY_PPB_VIDEO_CAPTURE_PROXY_H_
-#define PPAPI_PROXY_PPB_VIDEO_CAPTURE_PROXY_H_
-
-#include <string>
-#include <vector>
-
-#include "ppapi/c/dev/ppp_video_capture_dev.h"
-#include "ppapi/c/pp_instance.h"
-#include "ppapi/proxy/interface_proxy.h"
-#include "ppapi/proxy/proxy_completion_callback_factory.h"
-#include "ppapi/proxy/serialized_structs.h"
-#include "ppapi/shared_impl/ppb_device_ref_shared.h"
-#include "ppapi/utility/completion_callback_factory.h"
-
-struct PP_VideoCaptureDeviceInfo_Dev;
-
-namespace ppapi {
-
-class HostResource;
-
-namespace proxy {
-
-class PPB_VideoCapture_Proxy : public InterfaceProxy {
- public:
- explicit PPB_VideoCapture_Proxy(Dispatcher* dispatcher);
- virtual ~PPB_VideoCapture_Proxy();
-
- static PP_Resource CreateProxyResource(PP_Instance instance);
-
- // InterfaceProxy implementation.
- virtual bool OnMessageReceived(const IPC::Message& msg);
-
- static const ApiID kApiID = API_ID_PPB_VIDEO_CAPTURE_DEV;
-
- private:
- // Message handlers in the renderer process.
- void OnMsgCreate(PP_Instance instance, ppapi::HostResource* result_resource);
- void OnMsgEnumerateDevices(const ppapi::HostResource& resource);
- void OnMsgOpen(const ppapi::HostResource& resource,
- const std::string& device_id,
- const PP_VideoCaptureDeviceInfo_Dev& info,
- uint32_t buffers);
- void OnMsgStartCapture(const ppapi::HostResource& resource);
- void OnMsgReuseBuffer(const ppapi::HostResource& resource,
- uint32_t buffer);
- void OnMsgStopCapture(const ppapi::HostResource& resource);
- void OnMsgClose(const ppapi::HostResource& resource);
- void OnMsgStartCapture0_1(const ppapi::HostResource& resource,
- const PP_VideoCaptureDeviceInfo_Dev& info,
- uint32_t buffers);
-
- // Message handlers in the plugin process.
- void OnMsgEnumerateDevicesACK(
- const ppapi::HostResource& resource,
- int32_t result,
- const std::vector<ppapi::DeviceRefData>& devices);
- void OnMsgOpenACK(const ppapi::HostResource& resource, int32_t result);
-
- void EnumerateDevicesACKInHost(int32_t result,
- const ppapi::HostResource& resource);
- void OpenACKInHost(int32_t result, const ppapi::HostResource& resource);
-
- ProxyCompletionCallbackFactory<PPB_VideoCapture_Proxy> callback_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(PPB_VideoCapture_Proxy);
-};
-
-class PPP_VideoCapture_Proxy : public InterfaceProxy {
- public:
- explicit PPP_VideoCapture_Proxy(Dispatcher* dispatcher);
- virtual ~PPP_VideoCapture_Proxy();
-
- static const Info* GetInfo();
-
- // InterfaceProxy implementation.
- virtual bool OnMessageReceived(const IPC::Message& msg);
-
- static const ApiID kApiID = API_ID_PPP_VIDEO_CAPTURE_DEV;
-
- private:
- // Message handlers.
- void OnMsgOnDeviceInfo(const ppapi::HostResource& video_capture,
- const PP_VideoCaptureDeviceInfo_Dev& info,
- const std::vector<PPPVideoCapture_Buffer>& buffers);
- void OnMsgOnStatus(const ppapi::HostResource& video_capture,
- uint32_t status);
- void OnMsgOnError(const ppapi::HostResource& video_capture,
- uint32_t error_code);
- void OnMsgOnBufferReady(const ppapi::HostResource& video_capture,
- uint32_t buffer);
-
- // When this proxy is in the plugin side, this value caches the interface
- // pointer so we don't have to retrieve it from the dispatcher each time.
- // In the host, this value is always NULL.
- const PPP_VideoCapture_Dev* ppp_video_capture_impl_;
-
- DISALLOW_COPY_AND_ASSIGN(PPP_VideoCapture_Proxy);
-};
-
-} // namespace proxy
-} // namespace ppapi
-
-#endif // PPAPI_PROXY_PPB_VIDEO_CAPTURE_PROXY_H_
diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc
index e76b567..2b8836a 100644
--- a/ppapi/proxy/resource_creation_proxy.cc
+++ b/ppapi/proxy/resource_creation_proxy.cc
@@ -35,11 +35,11 @@
#include "ppapi/proxy/ppb_tcp_socket_private_proxy.h"
#include "ppapi/proxy/ppb_udp_socket_private_proxy.h"
#include "ppapi/proxy/ppb_url_loader_proxy.h"
-#include "ppapi/proxy/ppb_video_capture_proxy.h"
#include "ppapi/proxy/ppb_video_decoder_proxy.h"
#include "ppapi/proxy/ppb_x509_certificate_private_proxy.h"
#include "ppapi/proxy/printing_resource.h"
#include "ppapi/proxy/url_request_info_resource.h"
+#include "ppapi/proxy/video_capture_resource.h"
#include "ppapi/proxy/websocket_resource.h"
#include "ppapi/shared_impl/api_id.h"
#include "ppapi/shared_impl/host_resource.h"
@@ -348,7 +348,11 @@ PP_Resource ResourceCreationProxy::CreateTalk(PP_Instance instance) {
}
PP_Resource ResourceCreationProxy::CreateVideoCapture(PP_Instance instance) {
- return PPB_VideoCapture_Proxy::CreateProxyResource(instance);
+ PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
+ if (!dispatcher)
+ return 0;
+ return (new VideoCaptureResource(GetConnection(), instance, dispatcher))
+ ->GetReference();
}
PP_Resource ResourceCreationProxy::CreateVideoDecoder(
diff --git a/ppapi/proxy/resource_message_params.cc b/ppapi/proxy/resource_message_params.cc
index 9228d7e..aaca8c9 100644
--- a/ppapi/proxy/resource_message_params.cc
+++ b/ppapi/proxy/resource_message_params.cc
@@ -91,6 +91,15 @@ bool ResourceMessageParams::TakeSocketHandleAtIndex(
return true;
}
+void ResourceMessageParams::TakeAllSharedMemoryHandles(
+ std::vector<base::SharedMemoryHandle>* handles) const {
+ for (size_t i = 0; i < handles_->data().size(); ++i) {
+ base::SharedMemoryHandle handle;
+ if (TakeSharedMemoryHandleAtIndex(i, &handle))
+ handles->push_back(handle);
+ }
+}
+
void ResourceMessageParams::AppendHandle(const SerializedHandle& handle) const {
handles_->data().push_back(handle);
}
diff --git a/ppapi/proxy/resource_message_params.h b/ppapi/proxy/resource_message_params.h
index 780adb0..d8e4e9d 100644
--- a/ppapi/proxy/resource_message_params.h
+++ b/ppapi/proxy/resource_message_params.h
@@ -54,6 +54,8 @@ class PPAPI_PROXY_EXPORT ResourceMessageParams {
base::SharedMemoryHandle* handle) const;
bool TakeSocketHandleAtIndex(size_t index,
IPC::PlatformFileForTransit* handle) const;
+ void TakeAllSharedMemoryHandles(
+ std::vector<base::SharedMemoryHandle>* handles) const;
// Appends the given handle to the list of handles sent with the call or
// reply.
diff --git a/ppapi/proxy/serialized_structs.h b/ppapi/proxy/serialized_structs.h
index e577a8f..d27b52c 100644
--- a/ppapi/proxy/serialized_structs.h
+++ b/ppapi/proxy/serialized_structs.h
@@ -81,12 +81,6 @@ struct PPBURLLoader_UpdateProgress_Params {
int64_t total_bytes_to_be_received;
};
-struct PPPVideoCapture_Buffer {
- ppapi::HostResource resource;
- uint32_t size;
- base::SharedMemoryHandle handle;
-};
-
// We put all our handles in a unified structure to make it easy to translate
// them in NaClIPCAdapter for use in NaCl.
class PPAPI_PROXY_EXPORT SerializedHandle {
@@ -189,8 +183,6 @@ class PPAPI_PROXY_EXPORT SerializedHandle {
IPC::PlatformFileForTransit descriptor_;
};
-// TODO(tomfinegan): This is identical to PPPVideoCapture_Buffer, maybe replace
-// both with a single type?
struct PPPDecryptor_Buffer {
ppapi::HostResource resource;
uint32_t size;
diff --git a/ppapi/proxy/video_capture_resource.cc b/ppapi/proxy/video_capture_resource.cc
new file mode 100644
index 0000000..7264b85
--- /dev/null
+++ b/ppapi/proxy/video_capture_resource.cc
@@ -0,0 +1,277 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/proxy/video_capture_resource.h"
+
+#include "ppapi/c/dev/ppp_video_capture_dev.h"
+#include "ppapi/proxy/dispatch_reply_message.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/plugin_globals.h"
+#include "ppapi/proxy/plugin_resource_tracker.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/ppb_buffer_proxy.h"
+#include "ppapi/proxy/resource_message_params.h"
+#include "ppapi/shared_impl/array_writer.h"
+#include "ppapi/shared_impl/proxy_lock.h"
+#include "ppapi/shared_impl/tracked_callback.h"
+
+namespace ppapi {
+namespace proxy {
+
+VideoCaptureResource::VideoCaptureResource(
+ Connection connection,
+ PP_Instance instance,
+ PluginDispatcher* dispatcher)
+ : PluginResource(connection, instance),
+ open_state_(BEFORE_OPEN),
+ has_pending_enum_devices_callback_(false) {
+ SendCreate(RENDERER, PpapiHostMsg_VideoCapture_Create());
+
+ ppp_video_capture_impl_ = static_cast<const PPP_VideoCapture_Dev*>(
+ dispatcher->local_get_interface()(PPP_VIDEO_CAPTURE_DEV_INTERFACE));
+}
+
+VideoCaptureResource::~VideoCaptureResource() {
+}
+
+void VideoCaptureResource::OnReplyReceived(
+ const ResourceMessageReplyParams& params,
+ const IPC::Message& msg) {
+ if (params.sequence()) {
+ PluginResource::OnReplyReceived(params, msg);
+ return;
+ }
+
+ IPC_BEGIN_MESSAGE_MAP(VideoCaptureResource, msg)
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
+ PpapiPluginMsg_VideoCapture_OnDeviceInfo,
+ OnPluginMsgOnDeviceInfo)
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
+ PpapiPluginMsg_VideoCapture_OnStatus,
+ OnPluginMsgOnStatus)
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
+ PpapiPluginMsg_VideoCapture_OnError,
+ OnPluginMsgOnError)
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
+ PpapiPluginMsg_VideoCapture_OnBufferReady,
+ OnPluginMsgOnBufferReady)
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(NOTREACHED())
+ IPC_END_MESSAGE_MAP()
+}
+
+int32_t VideoCaptureResource::EnumerateDevices(
+ PP_Resource* devices,
+ scoped_refptr<TrackedCallback> callback) {
+ if (has_pending_enum_devices_callback_)
+ return PP_ERROR_INPROGRESS;
+
+ has_pending_enum_devices_callback_ = true;
+
+ Call<PpapiPluginMsg_VideoCapture_EnumerateDevicesReply>(
+ RENDERER,
+ PpapiHostMsg_VideoCapture_EnumerateDevices(),
+ base::Bind(&VideoCaptureResource::OnPluginMsgEnumerateDevicesReply,
+ this,
+ devices,
+ callback));
+ return PP_OK_COMPLETIONPENDING;
+}
+
+int32_t VideoCaptureResource::Open(
+ const std::string& device_id,
+ const PP_VideoCaptureDeviceInfo_Dev& requested_info,
+ uint32_t buffer_count,
+ scoped_refptr<TrackedCallback> callback) {
+ if (open_state_ != BEFORE_OPEN)
+ return PP_ERROR_FAILED;
+
+ if (TrackedCallback::IsPending(open_callback_))
+ return PP_ERROR_INPROGRESS;
+
+ open_callback_ = callback;
+
+ Call<PpapiPluginMsg_VideoCapture_OpenReply>(
+ RENDERER,
+ PpapiHostMsg_VideoCapture_Open(device_id, requested_info, buffer_count),
+ base::Bind(&VideoCaptureResource::OnPluginMsgOpenReply, this));
+ return PP_OK_COMPLETIONPENDING;
+}
+
+int32_t VideoCaptureResource::StartCapture() {
+ if (open_state_ != OPENED)
+ return PP_ERROR_FAILED;
+
+ buffer_in_use_.clear();
+ Post(RENDERER, PpapiHostMsg_VideoCapture_StartCapture());
+ return PP_OK;
+}
+
+int32_t VideoCaptureResource::ReuseBuffer(uint32_t buffer) {
+ if (buffer >= buffer_in_use_.size() || !buffer_in_use_[buffer])
+ return PP_ERROR_BADARGUMENT;
+ Post(RENDERER, PpapiHostMsg_VideoCapture_ReuseBuffer(buffer));
+ return PP_OK;
+}
+
+int32_t VideoCaptureResource::StopCapture() {
+ if (open_state_ != OPENED)
+ return PP_ERROR_FAILED;
+
+ Post(RENDERER, PpapiHostMsg_VideoCapture_StopCapture());
+ return PP_OK;
+}
+
+void VideoCaptureResource::Close() {
+ if (open_state_ == CLOSED)
+ return;
+
+ Post(RENDERER, PpapiHostMsg_VideoCapture_Close());
+
+ open_state_ = CLOSED;
+
+ if (TrackedCallback::IsPending(open_callback_))
+ open_callback_->PostAbort();
+}
+
+int32_t VideoCaptureResource::EnumerateDevicesSync(
+ const PP_ArrayOutput& devices) {
+ ArrayWriter output;
+ output.set_pp_array_output(devices);
+ if (!output.is_valid())
+ return PP_ERROR_BADARGUMENT;
+
+ std::vector<ppapi::DeviceRefData> device_ref_data;
+ int32_t result = SyncCall<PpapiPluginMsg_VideoCapture_EnumerateDevicesReply>(
+ RENDERER,
+ PpapiHostMsg_VideoCapture_EnumerateDevices(),
+ &device_ref_data);
+
+ std::vector<scoped_refptr<Resource> > device_resources;
+ for (size_t i = 0; i < device_ref_data.size(); ++i) {
+ scoped_refptr<Resource> resource(new PPB_DeviceRef_Shared(
+ OBJECT_IS_PROXY, pp_instance(), device_ref_data[i]));
+ device_resources.push_back(resource);
+ }
+
+ if (!output.StoreResourceVector(device_resources))
+ return PP_ERROR_FAILED;
+
+ return result;
+}
+
+void VideoCaptureResource::OnPluginMsgOnDeviceInfo(
+ const ResourceMessageReplyParams& params,
+ const struct PP_VideoCaptureDeviceInfo_Dev& info,
+ const std::vector<HostResource>& buffers,
+ uint32_t buffer_size) {
+ if (!ppp_video_capture_impl_)
+ return;
+
+ std::vector<base::SharedMemoryHandle> handles;
+ params.TakeAllSharedMemoryHandles(&handles);
+ CHECK(handles.size() == buffers.size());
+
+ PluginResourceTracker* tracker =
+ PluginGlobals::Get()->plugin_resource_tracker();
+ scoped_array<PP_Resource> resources(new PP_Resource[buffers.size()]);
+ for (size_t i = 0; i < buffers.size(); ++i) {
+ // We assume that the browser created a new set of resources.
+ DCHECK(!tracker->PluginResourceForHostResource(buffers[i]));
+ resources[i] = ppapi::proxy::PPB_Buffer_Proxy::AddProxyResource(
+ buffers[i], handles[i], buffer_size);
+ }
+
+ buffer_in_use_ = std::vector<bool>(buffers.size());
+
+ CallWhileUnlocked(ppp_video_capture_impl_->OnDeviceInfo,
+ pp_instance(),
+ pp_resource(),
+ &info,
+ static_cast<uint32_t>(buffers.size()),
+ const_cast<const PP_Resource*>(resources.get()));
+
+ for (size_t i = 0; i < buffers.size(); ++i)
+ tracker->ReleaseResource(resources[i]);
+}
+
+void VideoCaptureResource::OnPluginMsgOnStatus(
+ const ResourceMessageReplyParams& params,
+ uint32_t status) {
+ switch (status) {
+ case PP_VIDEO_CAPTURE_STATUS_STARTING:
+ case PP_VIDEO_CAPTURE_STATUS_STOPPING:
+ // Those states are not sent by the browser.
+ NOTREACHED();
+ break;
+ }
+ if (ppp_video_capture_impl_) {
+ CallWhileUnlocked(ppp_video_capture_impl_->OnStatus,
+ pp_instance(),
+ pp_resource(),
+ status);
+ }
+}
+
+void VideoCaptureResource::OnPluginMsgOnError(
+ const ResourceMessageReplyParams& params,
+ uint32_t error_code) {
+ open_state_ = CLOSED;
+ if (ppp_video_capture_impl_) {
+ CallWhileUnlocked(ppp_video_capture_impl_->OnError,
+ pp_instance(),
+ pp_resource(),
+ error_code);
+ }
+}
+
+void VideoCaptureResource::OnPluginMsgOnBufferReady(
+ const ResourceMessageReplyParams& params,
+ uint32_t buffer) {
+ SetBufferInUse(buffer);
+ if (ppp_video_capture_impl_) {
+ CallWhileUnlocked(ppp_video_capture_impl_->OnBufferReady,
+ pp_instance(),
+ pp_resource(),
+ buffer);
+ }
+}
+
+void VideoCaptureResource::OnPluginMsgOpenReply(
+ const ResourceMessageReplyParams& params) {
+ if (open_state_ == BEFORE_OPEN && params.result() == PP_OK)
+ open_state_ = OPENED;
+
+ // The callback may have been aborted by Close().
+ if (TrackedCallback::IsPending(open_callback_))
+ open_callback_->Run(params.result());
+}
+
+void VideoCaptureResource::OnPluginMsgEnumerateDevicesReply(
+ PP_Resource* devices_output,
+ scoped_refptr<TrackedCallback> callback,
+ const ResourceMessageReplyParams& params,
+ const std::vector<DeviceRefData>& devices) {
+ if (!TrackedCallback::IsPending(callback))
+ return;
+
+ DCHECK(has_pending_enum_devices_callback_);
+ has_pending_enum_devices_callback_ = false;
+
+ if (params.result() == PP_OK && devices_output) {
+ // devices_output points to the resource array of PP_ArrayOutput. In C++,
+ // it's typically allocated in VideoCapture_Dev.
+ *devices_output = PPB_DeviceRef_Shared::CreateResourceArray(
+ OBJECT_IS_PROXY, pp_instance(), devices);
+ }
+
+ callback->Run(params.result());
+}
+
+void VideoCaptureResource::SetBufferInUse(uint32_t buffer_index) {
+ DCHECK(buffer_index < buffer_in_use_.size());
+ buffer_in_use_[buffer_index] = true;
+}
+
+} // namespace proxy
+} // namespace ppapi
diff --git a/ppapi/proxy/video_capture_resource.h b/ppapi/proxy/video_capture_resource.h
new file mode 100644
index 0000000..7e7eedb
--- /dev/null
+++ b/ppapi/proxy/video_capture_resource.h
@@ -0,0 +1,93 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_PROXY_VIDEO_CAPTURE_RESOURCE_H_
+#define PPAPI_PROXY_VIDEO_CAPTURE_RESOURCE_H_
+
+#include "base/compiler_specific.h"
+#include "ppapi/c/dev/ppp_video_capture_dev.h"
+#include "ppapi/proxy/plugin_resource.h"
+#include "ppapi/thunk/ppb_video_capture_api.h"
+
+namespace ppapi {
+namespace proxy {
+
+class VideoCaptureResource
+ : public PluginResource,
+ public ::ppapi::thunk::PPB_VideoCapture_API {
+ public:
+ VideoCaptureResource(Connection connection,
+ PP_Instance instance,
+ PluginDispatcher* dispatcher);
+ virtual ~VideoCaptureResource();
+
+ // PluginResource override.
+ virtual thunk::PPB_VideoCapture_API* AsPPB_VideoCapture_API() OVERRIDE {
+ return this;
+ }
+
+ // PPB_VideoCapture_API implementation.
+ virtual int32_t EnumerateDevices(
+ PP_Resource* devices,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t Open(const std::string& device_id,
+ const PP_VideoCaptureDeviceInfo_Dev& requested_info,
+ uint32_t buffer_count,
+ scoped_refptr<TrackedCallback> callback) OVERRIDE;
+ virtual int32_t StartCapture() OVERRIDE;
+ virtual int32_t ReuseBuffer(uint32_t buffer) OVERRIDE;
+ virtual int32_t StopCapture() OVERRIDE;
+ virtual void Close() OVERRIDE;
+ virtual int32_t EnumerateDevicesSync(const PP_ArrayOutput& devices) OVERRIDE;
+
+ private:
+ enum OpenState {
+ BEFORE_OPEN,
+ OPENED,
+ CLOSED
+ };
+
+ // PluginResource overrides.
+ virtual void OnReplyReceived(const ResourceMessageReplyParams& params,
+ const IPC::Message& msg) OVERRIDE;
+
+ void OnPluginMsgOnDeviceInfo(const ResourceMessageReplyParams& params,
+ const struct PP_VideoCaptureDeviceInfo_Dev& info,
+ const std::vector<HostResource>& buffers,
+ uint32_t buffer_size);
+ void OnPluginMsgOnStatus(const ResourceMessageReplyParams& params,
+ uint32_t status);
+ void OnPluginMsgOnError(const ResourceMessageReplyParams& params,
+ uint32_t error);
+ void OnPluginMsgOnBufferReady(const ResourceMessageReplyParams& params,
+ uint32_t buffer);
+
+ void OnPluginMsgOpenReply(const ResourceMessageReplyParams& params);
+ void OnPluginMsgEnumerateDevicesReply(
+ PP_Resource* devices_output,
+ scoped_refptr<TrackedCallback> callback,
+ const ResourceMessageReplyParams& params,
+ const std::vector<DeviceRefData>& devices);
+
+ void SetBufferInUse(uint32_t buffer_index);
+
+ // Points to the C interface of client implementation.
+ const PPP_VideoCapture_Dev* ppp_video_capture_impl_;
+
+ // Indicates that the i-th buffer is currently in use.
+ std::vector<bool> buffer_in_use_;
+
+ // Holds a reference of the callback so that Close() can cancel it.
+ scoped_refptr<TrackedCallback> open_callback_;
+ OpenState open_state_;
+
+ bool has_pending_enum_devices_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(VideoCaptureResource);
+};
+
+} // namespace proxy
+} // namespace ppapi
+
+#endif // PPAPI_PROXY_VIDEO_CAPTURE_RESOURCE_H_
diff --git a/ppapi/shared_impl/ppb_video_capture_shared.cc b/ppapi/shared_impl/ppb_video_capture_shared.cc
deleted file mode 100644
index 2a51b95..0000000
--- a/ppapi/shared_impl/ppb_video_capture_shared.cc
+++ /dev/null
@@ -1,187 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ppapi/shared_impl/ppb_video_capture_shared.h"
-
-#include "base/logging.h"
-#include "ppapi/c/pp_errors.h"
-#include "ppapi/shared_impl/ppb_device_ref_shared.h"
-#include "ppapi/shared_impl/ppb_resource_array_shared.h"
-
-namespace ppapi {
-
-PPB_VideoCapture_Shared::PPB_VideoCapture_Shared(PP_Instance instance)
- : Resource(OBJECT_IS_IMPL, instance),
- open_state_(BEFORE_OPEN),
- status_(PP_VIDEO_CAPTURE_STATUS_STOPPED),
- devices_(NULL),
- resource_object_type_(OBJECT_IS_IMPL) {
-}
-
-PPB_VideoCapture_Shared::PPB_VideoCapture_Shared(
- const HostResource& host_resource)
- : Resource(OBJECT_IS_PROXY, host_resource),
- open_state_(BEFORE_OPEN),
- status_(PP_VIDEO_CAPTURE_STATUS_STOPPED),
- devices_(NULL),
- resource_object_type_(OBJECT_IS_PROXY) {
-}
-
-PPB_VideoCapture_Shared::~PPB_VideoCapture_Shared() {
-}
-
-thunk::PPB_VideoCapture_API* PPB_VideoCapture_Shared::AsPPB_VideoCapture_API() {
- return this;
-}
-
-int32_t PPB_VideoCapture_Shared::EnumerateDevices(
- PP_Resource* devices,
- scoped_refptr<TrackedCallback> callback) {
- if (TrackedCallback::IsPending(enumerate_devices_callback_))
- return PP_ERROR_INPROGRESS;
-
- return InternalEnumerateDevices(devices, callback);
-}
-
-int32_t PPB_VideoCapture_Shared::Open(
- const std::string& device_id,
- const PP_VideoCaptureDeviceInfo_Dev& requested_info,
- uint32_t buffer_count,
- scoped_refptr<TrackedCallback> callback) {
- if (open_state_ != BEFORE_OPEN)
- return PP_ERROR_FAILED;
-
- if (TrackedCallback::IsPending(open_callback_))
- return PP_ERROR_INPROGRESS;
-
- return InternalOpen(device_id, requested_info, buffer_count, callback);
-}
-
-int32_t PPB_VideoCapture_Shared::StartCapture() {
- if (open_state_ != OPENED ||
- !SetStatus(PP_VIDEO_CAPTURE_STATUS_STARTING, false)) {
- return PP_ERROR_FAILED;
- }
-
- return InternalStartCapture();
-}
-
-int32_t PPB_VideoCapture_Shared::ReuseBuffer(uint32_t buffer) {
- return InternalReuseBuffer(buffer);
-}
-
-int32_t PPB_VideoCapture_Shared::StopCapture() {
- if (open_state_ != OPENED ||
- !SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPING, false)) {
- return PP_ERROR_FAILED;
- }
-
- return InternalStopCapture();
-}
-
-void PPB_VideoCapture_Shared::Close() {
- if (open_state_ == CLOSED)
- return;
-
- InternalClose();
- open_state_ = CLOSED;
-
- if (TrackedCallback::IsPending(open_callback_))
- open_callback_->PostAbort();
-}
-
-int32_t PPB_VideoCapture_Shared::StartCapture0_1(
- const PP_VideoCaptureDeviceInfo_Dev& requested_info,
- uint32_t buffer_count) {
- if (open_state_ == BEFORE_OPEN) {
- if (TrackedCallback::IsPending(open_callback_))
- return PP_ERROR_FAILED;
- open_state_ = OPENED;
- } else if (open_state_ == CLOSED) {
- return PP_ERROR_FAILED;
- }
-
- if (!SetStatus(PP_VIDEO_CAPTURE_STATUS_STARTING, false))
- return PP_ERROR_FAILED;
-
- return InternalStartCapture0_1(requested_info, buffer_count);
-}
-
-const std::vector<DeviceRefData>& PPB_VideoCapture_Shared::GetDeviceRefData(
- ) const {
- return InternalGetDeviceRefData();
-}
-
-void PPB_VideoCapture_Shared::OnEnumerateDevicesComplete(
- int32_t result,
- const std::vector<DeviceRefData>& devices) {
- DCHECK(TrackedCallback::IsPending(enumerate_devices_callback_));
-
- if (result == PP_OK && devices_) {
- *devices_ = PPB_DeviceRef_Shared::CreateResourceArray(
- resource_object_type_, pp_instance(), devices);
- }
- devices_ = NULL;
-
- enumerate_devices_callback_->Run(result);
-}
-
-void PPB_VideoCapture_Shared::OnOpenComplete(int32_t result) {
- if (open_state_ == BEFORE_OPEN && result == PP_OK)
- open_state_ = OPENED;
-
- // The callback may have been aborted by Close(), or the open operation is
- // completed synchronously.
- if (TrackedCallback::IsPending(open_callback_))
- open_callback_->Run(result);
-}
-
-bool PPB_VideoCapture_Shared::SetStatus(PP_VideoCaptureStatus_Dev status,
- bool forced) {
- if (!forced) {
- switch (status) {
- case PP_VIDEO_CAPTURE_STATUS_STOPPED:
- if (status_ != PP_VIDEO_CAPTURE_STATUS_STOPPING)
- return false;
- break;
- case PP_VIDEO_CAPTURE_STATUS_STARTING:
- if (status_ != PP_VIDEO_CAPTURE_STATUS_STOPPED)
- return false;
- break;
- case PP_VIDEO_CAPTURE_STATUS_STARTED:
- switch (status_) {
- case PP_VIDEO_CAPTURE_STATUS_STARTING:
- case PP_VIDEO_CAPTURE_STATUS_PAUSED:
- break;
- default:
- return false;
- }
- break;
- case PP_VIDEO_CAPTURE_STATUS_PAUSED:
- switch (status_) {
- case PP_VIDEO_CAPTURE_STATUS_STARTING:
- case PP_VIDEO_CAPTURE_STATUS_STARTED:
- break;
- default:
- return false;
- }
- break;
- case PP_VIDEO_CAPTURE_STATUS_STOPPING:
- switch (status_) {
- case PP_VIDEO_CAPTURE_STATUS_STARTING:
- case PP_VIDEO_CAPTURE_STATUS_STARTED:
- case PP_VIDEO_CAPTURE_STATUS_PAUSED:
- break;
- default:
- return false;
- }
- break;
- }
- }
-
- status_ = status;
- return true;
-}
-
-} // namespace ppapi
diff --git a/ppapi/shared_impl/ppb_video_capture_shared.h b/ppapi/shared_impl/ppb_video_capture_shared.h
deleted file mode 100644
index 80b29fe..0000000
--- a/ppapi/shared_impl/ppb_video_capture_shared.h
+++ /dev/null
@@ -1,100 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef PPAPI_SHARED_IMPL_PPB_VIDEO_CAPTURE_SHARED_H_
-#define PPAPI_SHARED_IMPL_PPB_VIDEO_CAPTURE_SHARED_H_
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "base/memory/ref_counted.h"
-#include "ppapi/shared_impl/ppapi_shared_export.h"
-#include "ppapi/shared_impl/resource.h"
-#include "ppapi/shared_impl/tracked_callback.h"
-#include "ppapi/thunk/ppb_video_capture_api.h"
-
-namespace ppapi {
-
-class PPAPI_SHARED_EXPORT PPB_VideoCapture_Shared
- : public Resource,
- NON_EXPORTED_BASE(public thunk::PPB_VideoCapture_API) {
- public:
- explicit PPB_VideoCapture_Shared(PP_Instance instance);
- explicit PPB_VideoCapture_Shared(const HostResource& host_resource);
- virtual ~PPB_VideoCapture_Shared();
-
- // Resource implementation.
- virtual thunk::PPB_VideoCapture_API* AsPPB_VideoCapture_API() OVERRIDE;
-
- // PPB_VideoCapture_API implementation.
- virtual int32_t EnumerateDevices(
- PP_Resource* devices,
- scoped_refptr<TrackedCallback> callback) OVERRIDE;
- virtual int32_t Open(const std::string& device_id,
- const PP_VideoCaptureDeviceInfo_Dev& requested_info,
- uint32_t buffer_count,
- scoped_refptr<TrackedCallback> callback) OVERRIDE;
- virtual int32_t StartCapture() OVERRIDE;
- virtual int32_t ReuseBuffer(uint32_t buffer) OVERRIDE;
- virtual int32_t StopCapture() OVERRIDE;
- virtual void Close() OVERRIDE;
- virtual int32_t StartCapture0_1(
- const PP_VideoCaptureDeviceInfo_Dev& requested_info,
- uint32_t buffer_count) OVERRIDE;
- virtual const std::vector<DeviceRefData>& GetDeviceRefData() const OVERRIDE;
-
- void OnEnumerateDevicesComplete(int32_t result,
- const std::vector<DeviceRefData>& devices);
- void OnOpenComplete(int32_t result);
-
- protected:
- enum OpenState {
- BEFORE_OPEN,
- OPENED,
- CLOSED
- };
-
- // Subclasses should implement these methods to do impl- and proxy-specific
- // work.
- virtual int32_t InternalEnumerateDevices(
- PP_Resource* devices,
- scoped_refptr<TrackedCallback> callback) = 0;
- virtual int32_t InternalOpen(
- const std::string& device_id,
- const PP_VideoCaptureDeviceInfo_Dev& requested_info,
- uint32_t buffer_count,
- scoped_refptr<TrackedCallback> callback) = 0;
- virtual int32_t InternalStartCapture() = 0;
- virtual int32_t InternalReuseBuffer(uint32_t buffer) = 0;
- virtual int32_t InternalStopCapture() = 0;
- virtual void InternalClose() = 0;
- virtual int32_t InternalStartCapture0_1(
- const PP_VideoCaptureDeviceInfo_Dev& requested_info,
- uint32_t buffer_count) = 0;
- virtual const std::vector<DeviceRefData>& InternalGetDeviceRefData(
- ) const = 0;
-
- // Checks whether |status| is expected and sets |status_| if yes. If |forced|
- // is set to true, this method will bypass sanity check and always set
- // |status_|.
- bool SetStatus(PP_VideoCaptureStatus_Dev status, bool forced);
-
- OpenState open_state_;
- PP_VideoCaptureStatus_Dev status_;
-
- scoped_refptr<TrackedCallback> enumerate_devices_callback_;
- scoped_refptr<TrackedCallback> open_callback_;
-
- // Output parameter of EnumerateDevices(). It should not be accessed after
- // |enumerate_devices_callback_| is run.
- PP_Resource* devices_;
-
- ResourceObjectType resource_object_type_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(PPB_VideoCapture_Shared);
-};
-
-} // namespace ppapi
-
-#endif // PPAPI_SHARED_IMPL_PPB_VIDEO_CAPTURE_SHARED_H_
diff --git a/ppapi/thunk/interfaces_ppb_public_dev.h b/ppapi/thunk/interfaces_ppb_public_dev.h
index 90007e26..6fb578e 100644
--- a/ppapi/thunk/interfaces_ppb_public_dev.h
+++ b/ppapi/thunk/interfaces_ppb_public_dev.h
@@ -15,7 +15,6 @@ PROXIED_IFACE(NoAPIName, PPB_MEMORY_DEV_INTERFACE_0_1, PPB_Memory_Dev_0_1)
PROXIED_API(PPB_Buffer)
UNPROXIED_API(PPB_DirectoryReader)
UNPROXIED_API(PPB_Scrollbar)
-PROXIED_API(PPB_VideoCapture)
PROXIED_API(PPB_VideoDecoder)
UNPROXIED_API(PPB_Widget)
@@ -58,9 +57,7 @@ PROXIED_IFACE(PPB_Instance, PPB_TEXTINPUT_DEV_INTERFACE_0_1,
PPB_TextInput_Dev_0_1)
PROXIED_IFACE(PPB_Instance, PPB_TEXTINPUT_DEV_INTERFACE_0_2,
PPB_TextInput_Dev_0_2)
-PROXIED_IFACE(PPB_VideoCapture, PPB_VIDEOCAPTURE_DEV_INTERFACE_0_1,
- PPB_VideoCapture_Dev_0_1)
-PROXIED_IFACE(PPB_VideoCapture, PPB_VIDEOCAPTURE_DEV_INTERFACE_0_2,
+PROXIED_IFACE(NoAPIName, PPB_VIDEOCAPTURE_DEV_INTERFACE_0_2,
PPB_VideoCapture_Dev_0_2)
PROXIED_IFACE(PPB_VideoDecoder, PPB_VIDEODECODER_DEV_INTERFACE_0_16,
PPB_VideoDecoder_Dev_0_16)
diff --git a/ppapi/thunk/ppb_buffer_api.h b/ppapi/thunk/ppb_buffer_api.h
index f11bbd0..e82f2c4 100644
--- a/ppapi/thunk/ppb_buffer_api.h
+++ b/ppapi/thunk/ppb_buffer_api.h
@@ -7,11 +7,12 @@
#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_stdint.h"
+#include "ppapi/thunk/ppapi_thunk_export.h"
namespace ppapi {
namespace thunk {
-class PPB_Buffer_API {
+class PPAPI_THUNK_EXPORT PPB_Buffer_API {
public:
virtual ~PPB_Buffer_API() {}
diff --git a/ppapi/thunk/ppb_buffer_trusted_api.h b/ppapi/thunk/ppb_buffer_trusted_api.h
index 5301e6e..41ebbba 100644
--- a/ppapi/thunk/ppb_buffer_trusted_api.h
+++ b/ppapi/thunk/ppb_buffer_trusted_api.h
@@ -7,11 +7,12 @@
#include "ppapi/c/dev/ppb_buffer_dev.h"
#include "ppapi/c/trusted/ppb_buffer_trusted.h"
+#include "ppapi/thunk/ppapi_thunk_export.h"
namespace ppapi {
namespace thunk {
-class PPB_BufferTrusted_API {
+class PPAPI_THUNK_EXPORT PPB_BufferTrusted_API {
public:
virtual ~PPB_BufferTrusted_API() {}
diff --git a/ppapi/thunk/ppb_flash_functions_api.h b/ppapi/thunk/ppb_flash_functions_api.h
index 2a4a24e..73fa118 100644
--- a/ppapi/thunk/ppb_flash_functions_api.h
+++ b/ppapi/thunk/ppb_flash_functions_api.h
@@ -18,12 +18,6 @@ namespace thunk {
class PPAPI_THUNK_EXPORT PPB_Flash_Functions_API {
public:
virtual ~PPB_Flash_Functions_API() {}
-
- // PPB_Flash.
- virtual int32_t EnumerateVideoCaptureDevices(
- PP_Instance instance,
- PP_Resource video_capture,
- const PP_ArrayOutput& devices) = 0;
};
} // namespace thunk
diff --git a/ppapi/thunk/ppb_flash_thunk.cc b/ppapi/thunk/ppb_flash_thunk.cc
index b95a724..ec8e17e 100644
--- a/ppapi/thunk/ppb_flash_thunk.cc
+++ b/ppapi/thunk/ppb_flash_thunk.cc
@@ -12,6 +12,7 @@
#include "ppapi/thunk/ppb_flash_api.h"
#include "ppapi/thunk/ppb_flash_functions_api.h"
#include "ppapi/thunk/ppb_instance_api.h"
+#include "ppapi/thunk/ppb_video_capture_api.h"
#include "ppapi/thunk/thunk.h"
namespace ppapi {
@@ -158,18 +159,10 @@ PP_Bool SetCrashData(PP_Instance instance,
int32_t EnumerateVideoCaptureDevices(PP_Instance instance,
PP_Resource video_capture,
PP_ArrayOutput devices) {
- EnterInstance enter(instance);
- if (enter.succeeded()) {
- PPB_Flash_Functions_API* api =
- enter.functions()->GetFlashFunctionsAPI(instance);
- if (api) {
- return api->EnumerateVideoCaptureDevices(instance, video_capture,
- devices);
- } else {
- return PP_ERROR_NOINTERFACE;
- }
- }
- return PP_ERROR_BADRESOURCE;
+ thunk::EnterResource<thunk::PPB_VideoCapture_API> enter(video_capture, true);
+ if (enter.failed())
+ return enter.retval();
+ return enter.object()->EnumerateDevicesSync(devices);
}
const PPB_Flash_12_0 g_ppb_flash_12_0_thunk = {
diff --git a/ppapi/thunk/ppb_video_capture_api.h b/ppapi/thunk/ppb_video_capture_api.h
index 117b495..a12e201 100644
--- a/ppapi/thunk/ppb_video_capture_api.h
+++ b/ppapi/thunk/ppb_video_capture_api.h
@@ -10,6 +10,8 @@
#include "base/memory/ref_counted.h"
#include "ppapi/c/dev/ppb_video_capture_dev.h"
+#include "ppapi/c/pp_array_output.h"
+#include "ppapi/c/pp_resource.h"
namespace ppapi {
@@ -33,14 +35,9 @@ class PPB_VideoCapture_API {
virtual int32_t StopCapture() = 0;
virtual void Close() = 0;
- // For backward compatibility.
- virtual int32_t StartCapture0_1(
- const PP_VideoCaptureDeviceInfo_Dev& requested_info,
- uint32_t buffer_count) = 0;
-
- // This function is not exposed through the C API, but returns the internal
- // data for easy proxying.
- virtual const std::vector<DeviceRefData>& GetDeviceRefData() const = 0;
+ // This function is not exposed through the C API. It is only used by flash
+ // to make synchronous device enumeration.
+ virtual int32_t EnumerateDevicesSync(const PP_ArrayOutput& devices) = 0;
};
} // namespace thunk
diff --git a/ppapi/thunk/ppb_video_capture_thunk.cc b/ppapi/thunk/ppb_video_capture_thunk.cc
index 54cb68c..1ab038f 100644
--- a/ppapi/thunk/ppb_video_capture_thunk.cc
+++ b/ppapi/thunk/ppb_video_capture_thunk.cc
@@ -92,24 +92,6 @@ void Close(PP_Resource video_capture) {
enter.object()->Close();
}
-int32_t StartCapture0_1(PP_Resource video_capture,
- const PP_VideoCaptureDeviceInfo_Dev* requested_info,
- uint32_t buffer_count) {
- EnterVideoCapture enter(video_capture, true);
- if (enter.failed())
- return enter.retval();
-
- return enter.object()->StartCapture0_1(*requested_info, buffer_count);
-}
-
-const PPB_VideoCapture_Dev_0_1 g_ppb_video_capture_0_1_thunk = {
- &Create,
- &IsVideoCapture,
- &StartCapture0_1,
- &ReuseBuffer,
- &StopCapture
-};
-
const PPB_VideoCapture_Dev_0_2 g_ppb_video_capture_0_2_thunk = {
&Create,
&IsVideoCapture,
@@ -123,10 +105,6 @@ const PPB_VideoCapture_Dev_0_2 g_ppb_video_capture_0_2_thunk = {
} // namespace
-const PPB_VideoCapture_Dev_0_1* GetPPB_VideoCapture_Dev_0_1_Thunk() {
- return &g_ppb_video_capture_0_1_thunk;
-}
-
const PPB_VideoCapture_Dev_0_2* GetPPB_VideoCapture_Dev_0_2_Thunk() {
return &g_ppb_video_capture_0_2_thunk;
}
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index 215fe40..7a17b05 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -243,8 +243,6 @@
'../plugins/ppapi/ppb_url_response_info_impl.h',
'../plugins/ppapi/ppb_var_deprecated_impl.cc',
'../plugins/ppapi/ppb_var_deprecated_impl.h',
- '../plugins/ppapi/ppb_video_capture_impl.cc',
- '../plugins/ppapi/ppb_video_capture_impl.h',
'../plugins/ppapi/ppb_video_decoder_impl.cc',
'../plugins/ppapi/ppb_video_decoder_impl.h',
'../plugins/ppapi/ppb_widget_impl.cc',
diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc
index 41248c8..dd230ec 100644
--- a/webkit/plugins/ppapi/plugin_module.cc
+++ b/webkit/plugins/ppapi/plugin_module.cc
@@ -117,7 +117,6 @@
#include "webkit/plugins/ppapi/ppb_scrollbar_impl.h"
#include "webkit/plugins/ppapi/ppb_uma_private_impl.h"
#include "webkit/plugins/ppapi/ppb_var_deprecated_impl.h"
-#include "webkit/plugins/ppapi/ppb_video_capture_impl.h"
#include "webkit/plugins/ppapi/ppb_video_decoder_impl.h"
using ppapi::InputEventData;
diff --git a/webkit/plugins/ppapi/ppb_buffer_impl.h b/webkit/plugins/ppapi/ppb_buffer_impl.h
index 595e90b..8c55ead 100644
--- a/webkit/plugins/ppapi/ppb_buffer_impl.h
+++ b/webkit/plugins/ppapi/ppb_buffer_impl.h
@@ -11,13 +11,15 @@
#include "ppapi/thunk/ppb_buffer_api.h"
#include "ppapi/thunk/ppb_buffer_trusted_api.h"
#include "ppapi/shared_impl/resource.h"
+#include "webkit/plugins/webkit_plugins_export.h"
namespace webkit {
namespace ppapi {
-class PPB_Buffer_Impl : public ::ppapi::Resource,
- public ::ppapi::thunk::PPB_Buffer_API,
- public ::ppapi::thunk::PPB_BufferTrusted_API {
+class WEBKIT_PLUGINS_EXPORT PPB_Buffer_Impl :
+ public ::ppapi::Resource,
+ public ::ppapi::thunk::PPB_Buffer_API,
+ public ::ppapi::thunk::PPB_BufferTrusted_API {
public:
virtual ~PPB_Buffer_Impl();
diff --git a/webkit/plugins/ppapi/ppb_video_capture_impl.cc b/webkit/plugins/ppapi/ppb_video_capture_impl.cc
deleted file mode 100644
index caf9027..0000000
--- a/webkit/plugins/ppapi/ppb_video_capture_impl.cc
+++ /dev/null
@@ -1,332 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "webkit/plugins/ppapi/ppb_video_capture_impl.h"
-
-#include <algorithm>
-#include <string>
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "ppapi/c/dev/pp_video_capture_dev.h"
-#include "ppapi/c/dev/ppb_video_capture_dev.h"
-#include "ppapi/c/pp_completion_callback.h"
-#include "ppapi/c/pp_errors.h"
-#include "ppapi/shared_impl/ppapi_globals.h"
-#include "ppapi/shared_impl/ppb_device_ref_shared.h"
-#include "ppapi/shared_impl/resource_tracker.h"
-#include "ppapi/shared_impl/tracked_callback.h"
-#include "ppapi/thunk/enter.h"
-#include "webkit/plugins/ppapi/common.h"
-#include "webkit/plugins/ppapi/plugin_module.h"
-#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
-#include "webkit/plugins/ppapi/ppb_buffer_impl.h"
-#include "webkit/plugins/ppapi/resource_helper.h"
-
-using ppapi::DeviceRefData;
-using ppapi::PpapiGlobals;
-using ppapi::thunk::EnterResourceNoLock;
-using ppapi::thunk::PPB_Buffer_API;
-using ppapi::thunk::PPB_VideoCapture_API;
-using ppapi::TrackedCallback;
-
-namespace {
-
-// Maximum number of buffers to actually allocate.
-const uint32_t kMaxBuffers = 20;
-
-} // namespace
-
-namespace webkit {
-namespace ppapi {
-
-PPB_VideoCapture_Impl::PPB_VideoCapture_Impl(PP_Instance instance)
- : PPB_VideoCapture_Shared(instance),
- buffer_count_hint_(0),
- ppp_videocapture_(NULL),
- capability_() {
-}
-
-PPB_VideoCapture_Impl::~PPB_VideoCapture_Impl() {
- Close();
-}
-
-bool PPB_VideoCapture_Impl::Init() {
- PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
- if (!instance)
- return false;
- ppp_videocapture_ = static_cast<const PPP_VideoCapture_Dev*>(
- instance->module()->GetPluginInterface(PPP_VIDEO_CAPTURE_DEV_INTERFACE));
- if (!ppp_videocapture_)
- return false;
-
- return true;
-}
-
-void PPB_VideoCapture_Impl::OnStarted(media::VideoCapture* capture) {
- if (SetStatus(PP_VIDEO_CAPTURE_STATUS_STARTED, false))
- SendStatus();
-}
-
-void PPB_VideoCapture_Impl::OnStopped(media::VideoCapture* capture) {
- if (SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPED, false))
- SendStatus();
-}
-
-void PPB_VideoCapture_Impl::OnPaused(media::VideoCapture* capture) {
- if (SetStatus(PP_VIDEO_CAPTURE_STATUS_PAUSED, false))
- SendStatus();
-}
-
-void PPB_VideoCapture_Impl::OnError(media::VideoCapture* capture,
- int error_code) {
- // Today, the media layer only sends "1" as an error.
- DCHECK(error_code == 1);
- // It either comes because some error was detected while starting (e.g. 2
- // conflicting "master" resolution), or because the browser failed to start
- // the capture.
- SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPED, true);
- ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_FAILED);
-}
-
-void PPB_VideoCapture_Impl::OnRemoved(media::VideoCapture* capture) {
-}
-
-void PPB_VideoCapture_Impl::OnBufferReady(
- media::VideoCapture* capture,
- scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) {
- DCHECK(buffer.get());
- for (uint32_t i = 0; i < buffers_.size(); ++i) {
- if (!buffers_[i].in_use) {
- // TODO(ihf): Switch to a size calculation based on stride.
- // Stride is filled out now but not more meaningful than size
- // until wjia unifies VideoFrameBuffer and media::VideoFrame.
- size_t size = std::min(static_cast<size_t>(buffers_[i].buffer->size()),
- buffer->buffer_size);
- memcpy(buffers_[i].data, buffer->memory_pointer, size);
- buffers_[i].in_use = true;
- platform_video_capture_->FeedBuffer(buffer);
- ppp_videocapture_->OnBufferReady(pp_instance(), pp_resource(), i);
- return;
- }
- }
-
- // No free slot, just discard the frame and tell the media layer it can
- // re-use the buffer.
- platform_video_capture_->FeedBuffer(buffer);
-}
-
-void PPB_VideoCapture_Impl::OnDeviceInfoReceived(
- media::VideoCapture* capture,
- const media::VideoCaptureParams& device_info) {
- PP_VideoCaptureDeviceInfo_Dev info = {
- static_cast<uint32_t>(device_info.width),
- static_cast<uint32_t>(device_info.height),
- static_cast<uint32_t>(device_info.frame_per_second)
- };
- ReleaseBuffers();
-
- // Allocate buffers. We keep a reference to them, that is released in
- // ReleaseBuffers.
- // YUV 4:2:0
- int uv_width = info.width / 2;
- int uv_height = info.height / 2;
- size_t size = info.width * info.height + 2 * uv_width * uv_height;
- scoped_array<PP_Resource> resources(new PP_Resource[buffer_count_hint_]);
-
- buffers_.reserve(buffer_count_hint_);
- for (size_t i = 0; i < buffer_count_hint_; ++i) {
- resources[i] = PPB_Buffer_Impl::Create(pp_instance(), size);
- if (!resources[i])
- break;
-
- EnterResourceNoLock<PPB_Buffer_API> enter(resources[i], true);
- DCHECK(enter.succeeded());
-
- BufferInfo info;
- info.buffer = static_cast<PPB_Buffer_Impl*>(enter.object());
- info.data = info.buffer->Map();
- if (!info.data) {
- PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(resources[i]);
- break;
- }
- buffers_.push_back(info);
- }
-
- if (buffers_.empty()) {
- // We couldn't allocate/map buffers at all. Send an error and stop the
- // capture.
- ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_NOMEMORY);
- SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPING, true);
- platform_video_capture_->StopCapture(this);
- return;
- }
-
- ppp_videocapture_->OnDeviceInfo(pp_instance(), pp_resource(), &info,
- buffers_.size(), resources.get());
-}
-
-void PPB_VideoCapture_Impl::OnInitialized(media::VideoCapture* capture,
- bool succeeded) {
- DCHECK(capture == platform_video_capture_.get());
-
- OnOpenComplete(succeeded ? PP_OK : PP_ERROR_FAILED);
-}
-
-int32_t PPB_VideoCapture_Impl::InternalEnumerateDevices(
- PP_Resource* devices,
- scoped_refptr<TrackedCallback> callback) {
- PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
- if (!instance)
- return PP_ERROR_FAILED;
-
- devices_ = devices;
- enumerate_devices_callback_ = callback;
- instance->delegate()->EnumerateDevices(
- PP_DEVICETYPE_DEV_VIDEOCAPTURE,
- base::Bind(&PPB_VideoCapture_Impl::EnumerateDevicesCallbackFunc,
- AsWeakPtr()));
- return PP_OK_COMPLETIONPENDING;
-}
-
-int32_t PPB_VideoCapture_Impl::InternalOpen(
- const std::string& device_id,
- const PP_VideoCaptureDeviceInfo_Dev& requested_info,
- uint32_t buffer_count,
- scoped_refptr<TrackedCallback> callback) {
- // It is able to complete synchronously if the default device is used.
- bool sync_completion = device_id.empty();
-
- PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
- if (!instance)
- return PP_ERROR_FAILED;
-
- SetRequestedInfo(requested_info, buffer_count);
-
- DCHECK(!platform_video_capture_.get());
- platform_video_capture_ =
- instance->delegate()->CreateVideoCapture(device_id, this);
-
- if (sync_completion) {
- OnInitialized(platform_video_capture_.get(), true);
- return PP_OK;
- } else {
- open_callback_ = callback;
- return PP_OK_COMPLETIONPENDING;
- }
-}
-
-int32_t PPB_VideoCapture_Impl::InternalStartCapture() {
- DCHECK(buffers_.empty());
- platform_video_capture_->StartCapture(this, capability_);
- return PP_OK;
-}
-
-int32_t PPB_VideoCapture_Impl::InternalReuseBuffer(uint32_t buffer) {
- if (buffer >= buffers_.size() || !buffers_[buffer].in_use)
- return PP_ERROR_BADARGUMENT;
- buffers_[buffer].in_use = false;
- return PP_OK;
-}
-
-int32_t PPB_VideoCapture_Impl::InternalStopCapture() {
- ReleaseBuffers();
- platform_video_capture_->StopCapture(this);
- return PP_OK;
-}
-
-void PPB_VideoCapture_Impl::InternalClose() {
- StopCapture();
- DCHECK(buffers_.empty());
-
- DetachPlatformVideoCapture();
-}
-
-int32_t PPB_VideoCapture_Impl::InternalStartCapture0_1(
- const PP_VideoCaptureDeviceInfo_Dev& requested_info,
- uint32_t buffer_count) {
- PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
- if (!instance) {
- SetStatus(PP_VIDEO_CAPTURE_STATUS_STOPPED, true);
- return PP_ERROR_FAILED;
- }
-
- DCHECK(buffers_.empty());
-
- SetRequestedInfo(requested_info, buffer_count);
-
- DetachPlatformVideoCapture();
- platform_video_capture_ =
- instance->delegate()->CreateVideoCapture("", this);
- platform_video_capture_->StartCapture(this, capability_);
-
- return PP_OK;
-}
-
-const PPB_VideoCapture_Impl::DeviceRefDataVector&
- PPB_VideoCapture_Impl::InternalGetDeviceRefData() const {
- return devices_data_;
-}
-
-void PPB_VideoCapture_Impl::ReleaseBuffers() {
- ::ppapi::ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
- for (size_t i = 0; i < buffers_.size(); ++i) {
- buffers_[i].buffer->Unmap();
- tracker->ReleaseResource(buffers_[i].buffer->pp_resource());
- }
- buffers_.clear();
-}
-
-void PPB_VideoCapture_Impl::SendStatus() {
- ppp_videocapture_->OnStatus(pp_instance(), pp_resource(), status_);
-}
-
-void PPB_VideoCapture_Impl::SetRequestedInfo(
- const PP_VideoCaptureDeviceInfo_Dev& device_info,
- uint32_t buffer_count) {
- // Clamp the buffer count to between 1 and |kMaxBuffers|.
- buffer_count_hint_ = std::min(std::max(buffer_count, 1U), kMaxBuffers);
-
- capability_.width = device_info.width;
- capability_.height = device_info.height;
- capability_.frame_rate = device_info.frames_per_second;
- capability_.expected_capture_delay = 0; // Ignored.
- capability_.color = media::VideoCaptureCapability::kI420;
- capability_.interlaced = false; // Ignored.
-}
-
-void PPB_VideoCapture_Impl::DetachPlatformVideoCapture() {
- if (platform_video_capture_.get()) {
- platform_video_capture_->DetachEventHandler();
- platform_video_capture_ = NULL;
- }
-}
-
-void PPB_VideoCapture_Impl::EnumerateDevicesCallbackFunc(
- int request_id,
- bool succeeded,
- const DeviceRefDataVector& devices) {
- devices_data_.clear();
- if (succeeded)
- devices_data_ = devices;
-
- PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
- if (instance)
- instance->delegate()->StopEnumerateDevices(request_id);
-
- OnEnumerateDevicesComplete(succeeded ? PP_OK : PP_ERROR_FAILED, devices);
-}
-
-PPB_VideoCapture_Impl::BufferInfo::BufferInfo()
- : in_use(false),
- data(NULL),
- buffer() {
-}
-
-PPB_VideoCapture_Impl::BufferInfo::~BufferInfo() {
-}
-
-} // namespace ppapi
-} // namespace webkit
diff --git a/webkit/plugins/ppapi/ppb_video_capture_impl.h b/webkit/plugins/ppapi/ppb_video_capture_impl.h
deleted file mode 100644
index 06e63aa..0000000
--- a/webkit/plugins/ppapi/ppb_video_capture_impl.h
+++ /dev/null
@@ -1,109 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef WEBKIT_PLUGINS_PPAPI_PPB_VIDEO_CAPTURE_IMPL_H_
-#define WEBKIT_PLUGINS_PPAPI_PPB_VIDEO_CAPTURE_IMPL_H_
-
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "base/memory/ref_counted.h"
-#include "media/video/capture/video_capture.h"
-#include "media/video/capture/video_capture_types.h"
-#include "ppapi/c/dev/ppp_video_capture_dev.h"
-#include "ppapi/shared_impl/ppb_video_capture_shared.h"
-#include "ppapi/shared_impl/resource.h"
-#include "webkit/plugins/ppapi/plugin_delegate.h"
-#include "webkit/plugins/ppapi/ppb_buffer_impl.h"
-
-struct PP_VideoCaptureDeviceInfo_Dev;
-
-namespace webkit {
-namespace ppapi {
-
-class PPB_VideoCapture_Impl
- : public ::ppapi::PPB_VideoCapture_Shared,
- public PluginDelegate::PlatformVideoCaptureEventHandler,
- public base::SupportsWeakPtr<PPB_VideoCapture_Impl> {
- public:
- explicit PPB_VideoCapture_Impl(PP_Instance instance);
- virtual ~PPB_VideoCapture_Impl();
-
- bool Init();
-
- // PluginDelegate::PlatformVideoCaptureEventHandler implementation.
- virtual void OnStarted(media::VideoCapture* capture) OVERRIDE;
- virtual void OnStopped(media::VideoCapture* capture) OVERRIDE;
- virtual void OnPaused(media::VideoCapture* capture) OVERRIDE;
- virtual void OnError(media::VideoCapture* capture, int error_code) OVERRIDE;
- virtual void OnRemoved(media::VideoCapture* capture) OVERRIDE;
- virtual void OnBufferReady(
- media::VideoCapture* capture,
- scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) OVERRIDE;
- virtual void OnDeviceInfoReceived(
- media::VideoCapture* capture,
- const media::VideoCaptureParams& device_info) OVERRIDE;
- virtual void OnInitialized(media::VideoCapture* capture,
- bool succeeded) OVERRIDE;
-
- private:
- typedef std::vector< ::ppapi::DeviceRefData> DeviceRefDataVector;
-
- // PPB_VideoCapture_Shared implementation.
- virtual int32_t InternalEnumerateDevices(
- PP_Resource* devices,
- scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
- virtual int32_t InternalOpen(
- const std::string& device_id,
- const PP_VideoCaptureDeviceInfo_Dev& requested_info,
- uint32_t buffer_count,
- scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
- virtual int32_t InternalStartCapture() OVERRIDE;
- virtual int32_t InternalReuseBuffer(uint32_t buffer) OVERRIDE;
- virtual int32_t InternalStopCapture() OVERRIDE;
- virtual void InternalClose() OVERRIDE;
- virtual int32_t InternalStartCapture0_1(
- const PP_VideoCaptureDeviceInfo_Dev& requested_info,
- uint32_t buffer_count) OVERRIDE;
- virtual const DeviceRefDataVector& InternalGetDeviceRefData() const OVERRIDE;
-
- void ReleaseBuffers();
- void SendStatus();
-
- void SetRequestedInfo(const PP_VideoCaptureDeviceInfo_Dev& device_info,
- uint32_t buffer_count);
-
- void DetachPlatformVideoCapture();
-
- void EnumerateDevicesCallbackFunc(int request_id,
- bool succeeded,
- const DeviceRefDataVector& devices);
-
- scoped_refptr<PluginDelegate::PlatformVideoCapture> platform_video_capture_;
-
- size_t buffer_count_hint_;
- struct BufferInfo {
- BufferInfo();
- ~BufferInfo();
-
- bool in_use;
- void* data;
- scoped_refptr<PPB_Buffer_Impl> buffer;
- };
- std::vector<BufferInfo> buffers_;
-
- const PPP_VideoCapture_Dev* ppp_videocapture_;
-
- DeviceRefDataVector devices_data_;
-
- media::VideoCaptureCapability capability_;
-
- DISALLOW_COPY_AND_ASSIGN(PPB_VideoCapture_Impl);
-};
-
-} // namespace ppapi
-} // namespace webkit
-
-#endif // WEBKIT_PLUGINS_PPAPI_PPB_VIDEO_CAPTURE_IMPL_H_
diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc
index 0a85d9f..1f6d904 100644
--- a/webkit/plugins/ppapi/resource_creation_impl.cc
+++ b/webkit/plugins/ppapi/resource_creation_impl.cc
@@ -29,7 +29,6 @@
#include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h"
#include "webkit/plugins/ppapi/ppb_udp_socket_private_impl.h"
#include "webkit/plugins/ppapi/ppb_url_loader_impl.h"
-#include "webkit/plugins/ppapi/ppb_video_capture_impl.h"
#include "webkit/plugins/ppapi/ppb_video_decoder_impl.h"
#include "webkit/plugins/ppapi/ppb_x509_certificate_private_impl.h"
#include "webkit/plugins/ppapi/resource_helper.h"
@@ -272,11 +271,7 @@ PP_Resource ResourceCreationImpl::CreateURLLoader(PP_Instance instance) {
}
PP_Resource ResourceCreationImpl::CreateVideoCapture(PP_Instance instance) {
- scoped_refptr<PPB_VideoCapture_Impl> video_capture =
- new PPB_VideoCapture_Impl(instance);
- if (!video_capture->Init())
- return 0;
- return video_capture->GetReference();
+ return 0; // VideoCapture is not supported in process now.
}
PP_Resource ResourceCreationImpl::CreateVideoDecoder(