summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-06 03:15:48 +0000
committerpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-06 03:15:48 +0000
commit97dd433374f7a5e5195fb6c65bdab33740b98e86 (patch)
tree9d75e9732ff0a56929c24fd5ffd82d5865382e3e /ppapi
parenta82aa8513ec8f638ab2d68fca5e6a1a1d5fd1e67 (diff)
downloadchromium_src-97dd433374f7a5e5195fb6c65bdab33740b98e86.zip
chromium_src-97dd433374f7a5e5195fb6c65bdab33740b98e86.tar.gz
chromium_src-97dd433374f7a5e5195fb6c65bdab33740b98e86.tar.bz2
Video Capture Pepper API
The API is very simple at this point but works end-to-end. BUG=None TEST=VideoCapture sample (in a later CL) Review URL: http://codereview.chromium.org/7553003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95719 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/c/dev/pp_video_capture_dev.h49
-rw-r--r--ppapi/c/dev/ppb_video_capture_dev.h91
-rw-r--r--ppapi/c/dev/ppp_video_capture_dev.h69
-rw-r--r--ppapi/ppapi_shared.gypi2
-rw-r--r--ppapi/proxy/interface_id.h2
-rw-r--r--ppapi/proxy/resource_creation_proxy.cc5
-rw-r--r--ppapi/proxy/resource_creation_proxy.h1
-rw-r--r--ppapi/shared_impl/resource_object_base.h1
-rw-r--r--ppapi/thunk/ppb_video_capture_api.h27
-rw-r--r--ppapi/thunk/ppb_video_capture_thunk.cc73
-rw-r--r--ppapi/thunk/resource_creation_api.h2
-rw-r--r--ppapi/thunk/thunk.h2
12 files changed, 324 insertions, 0 deletions
diff --git a/ppapi/c/dev/pp_video_capture_dev.h b/ppapi/c/dev/pp_video_capture_dev.h
new file mode 100644
index 0000000..6f35313
--- /dev/null
+++ b/ppapi/c/dev/pp_video_capture_dev.h
@@ -0,0 +1,49 @@
+/* Copyright (c) 2011 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_C_DEV_PP_VIDEO_CAPTURE_DEV_H_
+#define PPAPI_C_DEV_PP_VIDEO_CAPTURE_DEV_H_
+
+#include "ppapi/c/pp_stdint.h"
+
+/**
+ * PP_VideoCaptureDeviceInfo_Dev is a structure that represent a video capture
+ * configuration, such as resolution and frame rate.
+ */
+struct PP_VideoCaptureDeviceInfo_Dev {
+ uint32_t width;
+ uint32_t height;
+ uint32_t frames_per_second;
+};
+PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_VideoCaptureDeviceInfo_Dev, 12);
+
+/**
+ * PP_VideoCaptureStatus_Dev is an enumeration that defines the various possible
+ * states of a VideoCapture.
+ */
+typedef enum {
+ /**
+ * Initial state, capture is stopped.
+ */
+ PP_VIDEO_CAPTURE_STATUS_STOPPED,
+ /**
+ * StartCapture has been called, but capture hasn't started yet.
+ */
+ PP_VIDEO_CAPTURE_STATUS_STARTING,
+ /**
+ * Capture is started.
+ */
+ PP_VIDEO_CAPTURE_STATUS_STARTED,
+ /**
+ * Capture has been started, but is paused because no buffer is available.
+ */
+ PP_VIDEO_CAPTURE_STATUS_PAUSED,
+ /**
+ * StopCapture has been called, but capture hasn't stopped yet.
+ */
+ PP_VIDEO_CAPTURE_STATUS_STOPPING
+} PP_VideoCaptureStatus_Dev;
+PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VideoCaptureStatus_Dev, 4);
+
+#endif /* PPAPI_C_DEV_PP_VIDEO_CAPTURE_DEV_H_ */
diff --git a/ppapi/c/dev/ppb_video_capture_dev.h b/ppapi/c/dev/ppb_video_capture_dev.h
new file mode 100644
index 0000000..21a18de
--- /dev/null
+++ b/ppapi/c/dev/ppb_video_capture_dev.h
@@ -0,0 +1,91 @@
+/* Copyright (c) 2011 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_C_DEV_PPB_VIDEO_CAPTURE_DEV_H_
+#define PPAPI_C_DEV_PPB_VIDEO_CAPTURE_DEV_H_
+
+#include "ppapi/c/dev/pp_video_capture_dev.h"
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/c/pp_stdint.h"
+
+#define PPB_VIDEO_CAPTURE_DEV_INTERFACE_0_1 "PPB_VideoCapture(Dev);0.1"
+#define PPB_VIDEO_CAPTURE_DEV_INTERFACE PPB_VIDEO_CAPTURE_DEV_INTERFACE_0_1
+
+/**
+ * Video capture interface. It goes hand-in-hand with PPP_VideoCapture_Dev.
+ *
+ * Theory of operation:
+ * 1- Create a VideoCapture resource using Create.
+ * 2- Start the capture using StartCapture. You pass in the requested info
+ * (resolution, frame rate), as well as suggest a number of buffers you will
+ * need.
+ * 3- Receive the OnDeviceInfo callback, in PPP_VideoCapture_Dev, which will
+ * give you the actual capture info (the requested one is not guaranteed), as
+ * well as an array of buffers allocated by the browser.
+ * 4- On every frame captured by the browser, OnBufferReady (in
+ * PPP_VideoCapture_Dev) is called with the index of the buffer from the array
+ * containing the new frame. The buffer is now "owned" by the plugin, and the
+ * browser won't reuse it until ReuseBuffer is called.
+ * 5- When the plugin is done with the buffer, call ReuseBuffer
+ * 6- Stop the capture using StopCapture.
+ *
+ * The browser may change the resolution based on the constraints of the system,
+ * in which case OnDeviceInfo will be called again, with new buffers.
+ *
+ * The buffers contain the pixel data for a frame. The format is planar YUV
+ * 4:2:0, one byte per pixel, tightly packed (width x height Y values, then
+ * width/2 x height/2 U values, then width/2 x height/2 V values).
+ */
+struct PPB_VideoCapture_Dev {
+ /**
+ * Creates a new VideoCapture.
+ */
+ PP_Resource (*Create)(PP_Instance instance);
+
+ /**
+ * Returns PP_TRUE if the given resource is a VideoCapture.
+ */
+ PP_Bool (*IsVideoCapture)(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 of 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.
+ */
+ int32_t (*StartCapture)(
+ PP_Resource video_capture,
+ const struct PP_VideoCaptureDeviceInfo_Dev* requested_info,
+ uint32_t buffer_count);
+
+ /**
+ * Allows the browser to reuse a buffer that was previously sent by
+ * PPP_VideoCapture_Dev.OnBufferReady. |buffer| is the index of the buffer in
+ * the array returned by PPP_VideoCapture_Dev.OnDeviceInfo.
+ *
+ * Returns PP_ERROR_BADARGUMENT if buffer is out of range (greater than the
+ * number of buffers returned by PPP_VideoCapture_Dev.OnDeviceInfo), or if it
+ * is not currently owned by the plugin. Returns PP_OK otherwise.
+ */
+ int32_t (*ReuseBuffer)(PP_Resource video_capture, uint32_t buffer);
+
+ /**
+ * Stops the capture.
+ *
+ * Returns PP_ERROR_FAILED if the capture wasn't already started, or PP_OK on
+ * success.
+ */
+ int32_t (*StopCapture)(PP_Resource video_capture);
+};
+
+#endif /* PPAPI_C_DEV_PPB_VIDEO_CAPTURE_DEV_H_ */
diff --git a/ppapi/c/dev/ppp_video_capture_dev.h b/ppapi/c/dev/ppp_video_capture_dev.h
new file mode 100644
index 0000000..390ea6f
--- /dev/null
+++ b/ppapi/c/dev/ppp_video_capture_dev.h
@@ -0,0 +1,69 @@
+/* Copyright (c) 2011 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_C_DEV_PPP_VIDEO_CAPTURE_DEV_H_
+#define PPAPI_C_DEV_PPP_VIDEO_CAPTURE_DEV_H_
+
+#include "ppapi/c/dev/pp_video_capture_dev.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/c/pp_stdint.h"
+
+#define PPP_VIDEO_CAPTURE_DEV_INTERFACE_0_1 "PPP_VideoCapture(Dev);0.1"
+#define PPP_VIDEO_CAPTURE_DEV_INTERFACE PPP_VIDEO_CAPTURE_DEV_INTERFACE_0_1
+
+/**
+ * Video Capture client interface. See |PPB_VideoCapture_Dev| for general theory
+ * of operation.
+ */
+struct PPP_VideoCapture_Dev {
+ /**
+ * Signals the capture device information, such as resolution and frame rate,
+ * and the array of buffers that the browser will use to send pixel data.
+ *
+ * |info| is a pointer to the PP_VideoCaptureDeviceInfo_Dev structure
+ * containing resolution and frame rate.
+ * |buffer_count| is the number of buffers, and |buffers| is the array of
+ * PPB_Buffer_Dev buffers.
+ *
+ * Note: the buffers are passed without an extra reference. The plugin is
+ * expected to add its own references to the buffers.
+ */
+ void (*OnDeviceInfo)(PP_Instance instance,
+ PP_Resource video_capture,
+ const struct PP_VideoCaptureDeviceInfo_Dev* info,
+ uint32_t buffer_count,
+ const PP_Resource* buffers);
+
+ /**
+ * Signals status changes on the VideoCapture. |status| is a
+ * one of the values from PP_VideoCaptureStatus_Dev;
+ */
+ void (*OnStatus)(PP_Instance instance,
+ PP_Resource video_capture,
+ uint32_t status);
+
+ /**
+ * Signals an error from the video capture system.
+ *
+ * Errors that can be generated:
+ * - PP_ERROR_NOMEMORY: not enough memory was available to allocate buffers.
+ * - PP_ERROR_FAILED: video capture could not start.
+ */
+ void (*OnError)(PP_Instance instance,
+ PP_Resource video_capture,
+ uint32_t error_code);
+
+ /**
+ * Signals that a buffer is available for consumption by the plugin.
+ *
+ * |buffer| is the index of the buffer, in the array returned by OnDeviceInfo.
+ */
+ void (*OnBufferReady)(PP_Instance,
+ PP_Resource video_capture,
+ uint32_t buffer);
+};
+
+#endif /* PPAPI_C_DEV_PPP_VIDEO_CAPTURE_DEV_H_ */
+
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi
index fea7e66..7a3b9e3 100644
--- a/ppapi/ppapi_shared.gypi
+++ b/ppapi/ppapi_shared.gypi
@@ -137,6 +137,8 @@
'thunk/ppb_url_request_info_thunk.cc',
'thunk/ppb_url_response_info_api.h',
'thunk/ppb_url_response_info_thunk.cc',
+ 'thunk/ppb_video_capture_api.h',
+ 'thunk/ppb_video_capture_thunk.cc',
'thunk/ppb_video_decoder_api.h',
'thunk/ppb_video_decoder_thunk.cc',
'thunk/ppb_video_layer_api.h',
diff --git a/ppapi/proxy/interface_id.h b/ppapi/proxy/interface_id.h
index 23fa86d..7cfe468 100644
--- a/ppapi/proxy/interface_id.h
+++ b/ppapi/proxy/interface_id.h
@@ -51,6 +51,7 @@ enum InterfaceID {
INTERFACE_ID_PPB_URL_UTIL,
INTERFACE_ID_PPB_VAR,
INTERFACE_ID_PPB_VAR_DEPRECATED,
+ INTERFACE_ID_PPB_VIDEO_CAPTURE_DEV,
INTERFACE_ID_PPB_VIDEO_DECODER_DEV,
INTERFACE_ID_PPP_CLASS,
@@ -59,6 +60,7 @@ enum InterfaceID {
INTERFACE_ID_PPP_INSTANCE,
INTERFACE_ID_PPP_INSTANCE_PRIVATE,
INTERFACE_ID_PPP_MESSAGING,
+ INTERFACE_ID_PPP_VIDEO_CAPTURE_DEV,
INTERFACE_ID_PPP_VIDEO_DECODER_DEV,
INTERFACE_ID_RESOURCE_CREATION,
diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc
index d517ea6..57da2e0 100644
--- a/ppapi/proxy/resource_creation_proxy.cc
+++ b/ppapi/proxy/resource_creation_proxy.cc
@@ -291,6 +291,11 @@ PP_Resource ResourceCreationProxy::CreateURLRequestInfo(PP_Instance instance) {
return PPB_URLRequestInfo_Proxy::CreateProxyResource(instance);
}
+PP_Resource ResourceCreationProxy::CreateVideoCapture(PP_Instance instance) {
+ NOTIMPLEMENTED();
+ return 0;
+}
+
PP_Resource ResourceCreationProxy::CreateVideoDecoder(
PP_Instance instance,
PP_Resource context3d_id,
diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h
index 2eefe62..7a91884 100644
--- a/ppapi/proxy/resource_creation_proxy.h
+++ b/ppapi/proxy/resource_creation_proxy.h
@@ -109,6 +109,7 @@ class ResourceCreationProxy : public ::ppapi::FunctionGroupBase,
const char* proto) OVERRIDE;
virtual PP_Resource CreateURLLoader(PP_Instance instance) OVERRIDE;
virtual PP_Resource CreateURLRequestInfo(PP_Instance instance) OVERRIDE;
+ virtual PP_Resource CreateVideoCapture(PP_Instance instance) OVERRIDE;
virtual PP_Resource CreateVideoDecoder(
PP_Instance instance,
PP_Resource context3d_id,
diff --git a/ppapi/shared_impl/resource_object_base.h b/ppapi/shared_impl/resource_object_base.h
index 1394718..847e382 100644
--- a/ppapi/shared_impl/resource_object_base.h
+++ b/ppapi/shared_impl/resource_object_base.h
@@ -37,6 +37,7 @@
F(PPB_URLLoader_API) \
F(PPB_URLRequestInfo_API) \
F(PPB_URLResponseInfo_API) \
+ F(PPB_VideoCapture_API) \
F(PPB_VideoDecoder_API) \
F(PPB_VideoLayer_API) \
F(PPB_Widget_API)
diff --git a/ppapi/thunk/ppb_video_capture_api.h b/ppapi/thunk/ppb_video_capture_api.h
new file mode 100644
index 0000000..33c4aa6
--- /dev/null
+++ b/ppapi/thunk/ppb_video_capture_api.h
@@ -0,0 +1,27 @@
+// Copyright (c) 2011 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_THUNK_VIDEO_CAPTURE_API_H_
+#define PPAPI_THUNK_VIDEO_CAPTURE_API_H_
+
+#include "ppapi/c/dev/ppb_video_capture_dev.h"
+
+namespace ppapi {
+namespace thunk {
+
+class PPB_VideoCapture_API {
+ public:
+ virtual ~PPB_VideoCapture_API() {}
+
+ virtual int32_t StartCapture(
+ const PP_VideoCaptureDeviceInfo_Dev& requested_info,
+ uint32_t buffer_count) = 0;
+ virtual int32_t ReuseBuffer(uint32_t buffer) = 0;
+ virtual int32_t StopCapture() = 0;
+};
+
+} // namespace thunk
+} // namespace ppapi
+
+#endif // PPAPI_THUNK_VIDEO_CAPTURE_API_H_
diff --git a/ppapi/thunk/ppb_video_capture_thunk.cc b/ppapi/thunk/ppb_video_capture_thunk.cc
new file mode 100644
index 0000000..c320cb5
--- /dev/null
+++ b/ppapi/thunk/ppb_video_capture_thunk.cc
@@ -0,0 +1,73 @@
+// Copyright (c) 2011 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/c/pp_errors.h"
+#include "ppapi/thunk/common.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/thunk.h"
+#include "ppapi/thunk/ppb_video_capture_api.h"
+#include "ppapi/thunk/resource_creation_api.h"
+
+namespace ppapi {
+namespace thunk {
+
+namespace {
+
+typedef EnterResource<PPB_VideoCapture_API> EnterVideoCapture;
+
+PP_Resource Create(PP_Instance instance) {
+ EnterFunction<ResourceCreationAPI> enter(instance, true);
+ if (enter.failed())
+ return 0;
+ return enter.functions()->CreateVideoCapture(instance);
+}
+
+PP_Bool IsVideoCapture(PP_Resource resource) {
+ EnterVideoCapture enter(resource, false);
+ return PP_FromBool(enter.succeeded());
+}
+
+int32_t StartCapture(PP_Resource video_capture,
+ const PP_VideoCaptureDeviceInfo_Dev* requested_info,
+ uint32_t buffer_count) {
+ EnterVideoCapture enter(video_capture, true);
+ if (enter.failed())
+ return PP_ERROR_BADRESOURCE;
+
+ return enter.object()->StartCapture(*requested_info, buffer_count);
+}
+
+int32_t ReuseBuffer(PP_Resource video_capture,
+ uint32_t buffer) {
+ EnterVideoCapture enter(video_capture, true);
+ if (enter.failed())
+ return PP_ERROR_BADRESOURCE;
+
+ return enter.object()->ReuseBuffer(buffer);
+}
+
+int32_t StopCapture(PP_Resource video_capture) {
+ EnterVideoCapture enter(video_capture, true);
+ if (enter.failed())
+ return PP_ERROR_BADRESOURCE;
+
+ return enter.object()->StopCapture();
+}
+
+const PPB_VideoCapture_Dev g_ppb_videocapture_thunk = {
+ &Create,
+ &IsVideoCapture,
+ &StartCapture,
+ &ReuseBuffer,
+ &StopCapture
+};
+
+} // namespace
+
+const PPB_VideoCapture_Dev* GetPPB_VideoCapture_Thunk() {
+ return &g_ppb_videocapture_thunk;
+}
+
+} // namespace thunk
+} // namespace ppapi
diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h
index 8d6c01b..6852ef6 100644
--- a/ppapi/thunk/resource_creation_api.h
+++ b/ppapi/thunk/resource_creation_api.h
@@ -20,6 +20,7 @@
struct PP_Flash_Menu;
struct PP_FontDescription_Dev;
+struct PP_VideoCaptureDeviceInfo_Dev;
struct PP_Size;
namespace ppapi {
@@ -109,6 +110,7 @@ class ResourceCreationAPI {
const char* proto) = 0;
virtual PP_Resource CreateURLLoader(PP_Instance instance) = 0;
virtual PP_Resource CreateURLRequestInfo(PP_Instance instance) = 0;
+ virtual PP_Resource CreateVideoCapture(PP_Instance instance) = 0;
virtual PP_Resource CreateVideoDecoder(
PP_Instance instance,
PP_Resource context3d_id,
diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h
index 46544cc..ac0008e 100644
--- a/ppapi/thunk/thunk.h
+++ b/ppapi/thunk/thunk.h
@@ -47,6 +47,7 @@ struct PPB_URLLoader;
struct PPB_URLLoaderTrusted;
struct PPB_URLRequestInfo;
struct PPB_URLResponseInfo;
+struct PPB_VideoCapture_Dev;
struct PPB_VideoDecoder_Dev;
struct PPB_VideoLayer_Dev;
struct PPB_WheelInputEvent;
@@ -101,6 +102,7 @@ const PPB_URLLoader* GetPPB_URLLoader_Thunk();
const PPB_URLLoaderTrusted* GetPPB_URLLoaderTrusted_Thunk();
const PPB_URLRequestInfo* GetPPB_URLRequestInfo_Thunk();
const PPB_URLResponseInfo* GetPPB_URLResponseInfo_Thunk();
+const PPB_VideoCapture_Dev* GetPPB_VideoCapture_Thunk();
const PPB_VideoDecoder_Dev* GetPPB_VideoDecoder_Thunk();
const PPB_VideoLayer_Dev* GetPPB_VideoLayer_Thunk();
const PPB_WheelInputEvent* GetPPB_WheelInputEvent_Thunk();