summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-16 02:14:11 +0000
committerraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-16 02:14:11 +0000
commitd29171a549b5c20980b9930c07e34da97bcbd13c (patch)
tree0acbe45178f5313cdd704652fc6f866c4255833b /ppapi
parentc0131a39a53f46594e6af35127f8c1b4e3bebd28 (diff)
downloadchromium_src-d29171a549b5c20980b9930c07e34da97bcbd13c.zip
chromium_src-d29171a549b5c20980b9930c07e34da97bcbd13c.tar.gz
chromium_src-d29171a549b5c20980b9930c07e34da97bcbd13c.tar.bz2
Implement host side of sync EnumerateVideoCaptureDevices
This implements the host side of the sync ppapi function EnumerateVideoCaptureDevices. BUG=none TEST=Wrote a sample that runs the sync and non-sync versions. Ran it and compared the outputs. Review URL: https://chromiumcodereview.appspot.com/11016007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162048 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/cpp/private/flash.cc30
-rw-r--r--ppapi/cpp/private/flash.h6
-rw-r--r--ppapi/examples/enumerate_devices/enumerate_devices.cc127
-rw-r--r--ppapi/examples/enumerate_devices/enumerate_devices.html87
-rw-r--r--ppapi/ppapi_tests.gypi10
5 files changed, 258 insertions, 2 deletions
diff --git a/ppapi/cpp/private/flash.cc b/ppapi/cpp/private/flash.cc
index 3a3da4e..5707b70 100644
--- a/ppapi/cpp/private/flash.cc
+++ b/ppapi/cpp/private/flash.cc
@@ -8,7 +8,9 @@
#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_errors.h"
+#include "ppapi/cpp/dev/device_ref_dev.h"
#include "ppapi/cpp/dev/font_dev.h"
+#include "ppapi/cpp/dev/video_capture_dev.h"
#include "ppapi/cpp/image_data.h"
#include "ppapi/cpp/instance_handle.h"
#include "ppapi/cpp/module.h"
@@ -24,6 +26,10 @@ namespace pp {
namespace {
+template <> const char* interface_name<PPB_Flash_12_6>() {
+ return PPB_FLASH_INTERFACE_12_6;
+}
+
template <> const char* interface_name<PPB_Flash_12_5>() {
return PPB_FLASH_INTERFACE_12_5;
}
@@ -53,7 +59,10 @@ PPB_Flash flash_12_combined_interface;
void InitializeCombinedInterface() {
if (initialized_combined_interface)
return;
- if (has_interface<PPB_Flash_12_5>()) {
+ if (has_interface<PPB_Flash_12_6>()) {
+ memcpy(&flash_12_combined_interface, get_interface<PPB_Flash_12_6>(),
+ sizeof(PPB_Flash_12_6));
+ } else if (has_interface<PPB_Flash_12_5>()) {
memcpy(&flash_12_combined_interface, get_interface<PPB_Flash_12_5>(),
sizeof(PPB_Flash_12_5));
} else if (has_interface<PPB_Flash_12_4>()) {
@@ -72,7 +81,8 @@ namespace flash {
// static
bool Flash::IsAvailable() {
- return has_interface<PPB_Flash_12_5>() ||
+ return has_interface<PPB_Flash_12_6>() ||
+ has_interface<PPB_Flash_12_5>() ||
has_interface<PPB_Flash_12_4>() ||
has_interface<PPB_Flash_12_3>();
}
@@ -246,6 +256,22 @@ bool Flash::SetCrashData(const InstanceHandle& instance,
}
// static
+int32_t Flash::EnumerateVideoCaptureDevices(
+ const InstanceHandle& instance,
+ const VideoCapture_Dev& video_capture,
+ std::vector<DeviceRef_Dev>* devices_out) {
+ InitializeCombinedInterface();
+ if (flash_12_combined_interface.EnumerateVideoCaptureDevices) {
+ ResourceArrayOutputAdapter<DeviceRef_Dev> adapter(devices_out);
+ return flash_12_combined_interface.EnumerateVideoCaptureDevices(
+ instance.pp_instance(),
+ video_capture.pp_resource(),
+ adapter.pp_array_output());
+ }
+ return PP_ERROR_FAILED;
+}
+
+// static
bool Flash::InvokePrinting(const InstanceHandle& instance) {
if (has_interface<PPB_Flash_Print_1_0>()) {
get_interface<PPB_Flash_Print_1_0>()->InvokePrinting(
diff --git a/ppapi/cpp/private/flash.h b/ppapi/cpp/private/flash.h
index dc5f929..857c689 100644
--- a/ppapi/cpp/private/flash.h
+++ b/ppapi/cpp/private/flash.h
@@ -6,6 +6,7 @@
#define PPAPI_CPP_PRIVATE_FLASH_H_
#include <string>
+#include <vector>
#include "ppapi/c/private/ppb_flash.h"
#include "ppapi/c/pp_stdint.h"
@@ -15,6 +16,7 @@ struct PP_Point;
namespace pp {
+class DeviceRef_Dev;
class FontDescription_Dev;
class ImageData;
class InstanceHandle;
@@ -23,6 +25,7 @@ class Point;
class Rect;
class URLRequestInfo;
class Var;
+class VideoCapture_Dev;
namespace flash {
@@ -63,6 +66,9 @@ class Flash {
static bool SetCrashData(const InstanceHandle& instance,
PP_FlashCrashKey key,
const pp::Var& value);
+ static int32_t EnumerateVideoCaptureDevices(const InstanceHandle& instance,
+ const VideoCapture_Dev& video_capture,
+ std::vector<DeviceRef_Dev>* devices_out);
// PPB_Flash_Print.
static bool InvokePrinting(const InstanceHandle& instance);
diff --git a/ppapi/examples/enumerate_devices/enumerate_devices.cc b/ppapi/examples/enumerate_devices/enumerate_devices.cc
new file mode 100644
index 0000000..383a0e5
--- /dev/null
+++ b/ppapi/examples/enumerate_devices/enumerate_devices.cc
@@ -0,0 +1,127 @@
+// 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 <assert.h>
+#include <string.h>
+
+#include <vector>
+
+#include "ppapi/c/dev/ppb_video_capture_dev.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/cpp/dev/device_ref_dev.h"
+#include "ppapi/cpp/dev/video_capture_dev.h"
+#include "ppapi/cpp/dev/video_capture_client_dev.h"
+#include "ppapi/cpp/completion_callback.h"
+#include "ppapi/cpp/instance.h"
+#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/private/flash.h"
+#include "ppapi/cpp/var.h"
+#include "ppapi/utility/completion_callback_factory.h"
+
+// When compiling natively on Windows, PostMessage can be #define-d to
+// something else.
+#ifdef PostMessage
+#undef PostMessage
+#endif
+
+namespace {
+
+// This object is the global object representing this plugin library as long
+// as it is loaded.
+class EnumerateDevicesDemoModule : public pp::Module {
+ public:
+ EnumerateDevicesDemoModule() : pp::Module() {}
+ virtual ~EnumerateDevicesDemoModule() {}
+ virtual pp::Instance* CreateInstance(PP_Instance instance);
+};
+
+class EnumerateDevicesDemoInstance : public pp::Instance,
+ public pp::VideoCaptureClient_Dev {
+ public:
+ EnumerateDevicesDemoInstance(PP_Instance instance, pp::Module* module);
+ virtual ~EnumerateDevicesDemoInstance();
+
+ // pp::Instance implementation (see PPP_Instance).
+ virtual void HandleMessage(const pp::Var& message_data);
+
+ // pp::VideoCaptureClient_Dev implementation.
+ virtual void OnDeviceInfo(PP_Resource resource,
+ const PP_VideoCaptureDeviceInfo_Dev& info,
+ const std::vector<pp::Buffer_Dev>& buffers) {}
+ virtual void OnStatus(PP_Resource resource, uint32_t status) {}
+ virtual void OnError(PP_Resource resource, uint32_t error) {}
+ virtual void OnBufferReady(PP_Resource resource, uint32_t buffer) {}
+
+ private:
+ void EnumerateDevicesFinished(int32_t result,
+ std::vector<pp::DeviceRef_Dev>& devices);
+
+ pp::VideoCapture_Dev video_capture_;
+ pp::CompletionCallbackFactory<EnumerateDevicesDemoInstance> callback_factory_;
+
+ std::vector<pp::DeviceRef_Dev> devices_;
+};
+
+EnumerateDevicesDemoInstance::EnumerateDevicesDemoInstance(PP_Instance instance,
+ pp::Module* module)
+ : pp::Instance(instance),
+ pp::VideoCaptureClient_Dev(this),
+ video_capture_(this),
+ callback_factory_(this) {
+}
+
+EnumerateDevicesDemoInstance::~EnumerateDevicesDemoInstance() {
+}
+
+void EnumerateDevicesDemoInstance::HandleMessage(const pp::Var& message_data) {
+ if (message_data.is_string()) {
+ std::string event = message_data.AsString();
+ if (event == "EnumerateDevicesAsync") {
+ pp::CompletionCallbackWithOutput<std::vector<pp::DeviceRef_Dev> >
+ callback = callback_factory_.NewCallbackWithOutput(
+ &EnumerateDevicesDemoInstance::EnumerateDevicesFinished);
+ video_capture_.EnumerateDevices(callback);
+ } else if (event == "EnumerateDevicesSync") {
+ std::vector<pp::DeviceRef_Dev> devices;
+ int32_t result = pp::flash::Flash::EnumerateVideoCaptureDevices(
+ this, video_capture_, &devices);
+ EnumerateDevicesFinished(result, devices);
+ }
+ }
+}
+
+void EnumerateDevicesDemoInstance::EnumerateDevicesFinished(
+ int32_t result,
+ std::vector<pp::DeviceRef_Dev>& devices) {
+ static const char* const kDelimiter = "#__#";
+
+ if (result == PP_OK) {
+ devices_.swap(devices);
+ std::string device_names;
+ for (size_t index = 0; index < devices_.size(); ++index) {
+ pp::Var name = devices_[index].GetName();
+ assert(name.is_string());
+
+ if (index != 0)
+ device_names += kDelimiter;
+ device_names += name.AsString();
+ }
+ PostMessage(pp::Var("EnumerationSuccess" + device_names));
+ } else {
+ PostMessage(pp::Var("EnumerationFailed"));
+ }
+}
+
+pp::Instance* EnumerateDevicesDemoModule::CreateInstance(PP_Instance instance) {
+ return new EnumerateDevicesDemoInstance(instance, this);
+}
+
+} // anonymous namespace
+
+namespace pp {
+// Factory function for your specialization of the Module object.
+Module* CreateModule() {
+ return new EnumerateDevicesDemoModule();
+}
+} // namespace pp
diff --git a/ppapi/examples/enumerate_devices/enumerate_devices.html b/ppapi/examples/enumerate_devices/enumerate_devices.html
new file mode 100644
index 0000000..d77cadb
--- /dev/null
+++ b/ppapi/examples/enumerate_devices/enumerate_devices.html
@@ -0,0 +1,87 @@
+<!DOCTYPE html>
+<html>
+ <!--
+ 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.
+ -->
+<head>
+ <title>Enumerate Devices Example</title>
+ <script type="text/javascript">
+ var device_array = [];
+ var enumerating = false;
+
+ function HandleMessage(message_event) {
+ if (message_event.data) {
+ var status = document.getElementById('status');
+ if (message_event.data == 'EnumerationFailed') {
+ status.innerText = 'Device enumeration failed!';
+ } else {
+ devices_data =
+ message_event.data.substring('EnumerationSuccess'.length);
+ if (devices_data.length > 0)
+ device_array = devices_data.split('#__#');
+ else
+ devices_array = [];
+
+ var list = document.getElementById('device_list');
+ if (devices_array.length == 0)
+ list.innerHTML = 'No devices.';
+ for (var i = 0; i < device_array.length; ++i) {
+ var list_item = document.createElement('li');
+ var span = document.createElement('span');
+ span.innerText = device_array[i];
+ list_item.appendChild(span);
+ list.appendChild(list_item);
+ }
+ status.innerText = 'Device enumeration success!';
+ }
+ enumerating = false;
+ }
+ }
+
+ function EnumerateDevices(sync) {
+ if (enumerating)
+ return;
+ enumerating = true;
+ var status = document.getElementById('status');
+ var plugin = document.getElementById('plugin');
+ if (sync) {
+ status.innerText = 'Enumerating devices sync...'
+ plugin.postMessage('EnumerateDevicesSync');
+ } else {
+ status.innerText = 'Enumerating devices async...'
+ plugin.postMessage('EnumerateDevicesAsync');
+ }
+ }
+
+ function Initialize() {
+ var plugin = document.getElementById('plugin');
+ plugin.addEventListener('message', HandleMessage, false);
+ EnumerateDevices(true);
+ }
+
+ document.addEventListener('DOMContentLoaded', Initialize, false);
+ </script>
+</head>
+
+<body>
+ <embed id="plugin" type="application/x-ppapi-example-enumerate-devices"
+ width=0 height=0 />
+ <div>
+ Press a link to enumerate video devices:
+ <ul>
+ <li><a href="javascript:EnumerateDevices(true)">Enumerate devices sync</a>
+ (only implemented for out-of-process)</li>
+ <li><a href="javascript:EnumerateDevices(false)">Enumerate devices async</a></li>
+ </ul>
+ </div>
+ <div id="available_devices">
+ Available device(s):
+ <ul id="device_list">No devices.</ul>
+ </div>
+ <div>
+ Status: <span id="status"></span>
+ </div>
+</body>
+</html>
diff --git a/ppapi/ppapi_tests.gypi b/ppapi/ppapi_tests.gypi
index 6aa5499..48ae15e 100644
--- a/ppapi/ppapi_tests.gypi
+++ b/ppapi/ppapi_tests.gypi
@@ -412,6 +412,16 @@
],
},
{
+ 'target_name': 'ppapi_example_enumerate_devices',
+ 'dependencies': [
+ 'ppapi_example_skeleton',
+ 'ppapi.gyp:ppapi_cpp',
+ ],
+ 'sources': [
+ 'examples/enumerate_devices/enumerate_devices.cc',
+ ],
+ },
+ {
'target_name': 'ppapi_example_flash_topmost',
'dependencies': [
'ppapi_example_skeleton',