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
This commit is contained in:
@@ -168,6 +168,8 @@
|
||||
'renderer/pepper/pepper_device_enumeration_event_handler.h',
|
||||
'renderer/pepper/pepper_file_chooser_host.cc',
|
||||
'renderer/pepper/pepper_file_chooser_host.h',
|
||||
'renderer/pepper/pepper_flash_host.cc',
|
||||
'renderer/pepper/pepper_flash_host.h',
|
||||
'renderer/pepper/pepper_hung_plugin_filter.cc',
|
||||
'renderer/pepper/pepper_hung_plugin_filter.h',
|
||||
'renderer/pepper/pepper_in_process_resource_creation.cc',
|
||||
|
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "content/renderer/pepper/pepper_file_chooser_host.h"
|
||||
#include "content/renderer/pepper/pepper_flash_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"
|
||||
@@ -55,6 +56,16 @@ scoped_ptr<ResourceHost> ContentRendererPepperHostFactory::CreateResourceHost(
|
||||
host_, instance, params.pp_resource()));
|
||||
}
|
||||
}
|
||||
|
||||
// Resources for Flash interfaces.
|
||||
if (GetPermissions().HasPermission(ppapi::PERMISSION_FLASH)) {
|
||||
switch (message.type()) {
|
||||
case PpapiHostMsg_Flash_Create::ID:
|
||||
return scoped_ptr<ResourceHost>(new PepperFlashHost(
|
||||
host_, instance, params.pp_resource()));
|
||||
}
|
||||
}
|
||||
|
||||
return scoped_ptr<ResourceHost>();
|
||||
}
|
||||
|
||||
|
82
content/renderer/pepper/pepper_flash_host.cc
Normal file
82
content/renderer/pepper/pepper_flash_host.cc
Normal file
@@ -0,0 +1,82 @@
|
||||
// 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_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 {
|
||||
|
||||
PepperFlashHost::PepperFlashHost(
|
||||
RendererPpapiHost* host,
|
||||
PP_Instance instance,
|
||||
PP_Resource resource)
|
||||
: ResourceHost(host->GetPpapiHost(), instance, resource),
|
||||
callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
|
||||
}
|
||||
|
||||
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
|
||||
|
47
content/renderer/pepper/pepper_flash_host.h
Normal file
47
content/renderer/pepper/pepper_flash_host.h
Normal file
@@ -0,0 +1,47 @@
|
||||
// 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_FLASH_HOST_H_
|
||||
#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 {
|
||||
|
||||
class RendererPpapiHost;
|
||||
|
||||
class PepperFlashHost
|
||||
: public ppapi::host::ResourceHost {
|
||||
public:
|
||||
PepperFlashHost(RendererPpapiHost* host,
|
||||
PP_Instance instance,
|
||||
PP_Resource resource);
|
||||
virtual ~PepperFlashHost();
|
||||
|
||||
virtual int32_t OnResourceMessageReceived(
|
||||
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);
|
||||
};
|
||||
|
||||
} // namespace content
|
||||
|
||||
#endif // CONTENT_RENDERER_PEPPER_PEPPER_FLASH_HOST_H_
|
@@ -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>();
|
||||
}
|
||||
@@ -245,6 +255,22 @@ bool Flash::SetCrashData(const InstanceHandle& instance,
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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>()) {
|
||||
|
@@ -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);
|
||||
|
127
ppapi/examples/enumerate_devices/enumerate_devices.cc
Normal file
127
ppapi/examples/enumerate_devices/enumerate_devices.cc
Normal file
@@ -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
|
87
ppapi/examples/enumerate_devices/enumerate_devices.html
Normal file
87
ppapi/examples/enumerate_devices/enumerate_devices.html
Normal file
@@ -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>
|
@@ -411,6 +411,16 @@
|
||||
'examples/video_capture/video_capture.cc',
|
||||
],
|
||||
},
|
||||
{
|
||||
'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': [
|
||||
|
Reference in New Issue
Block a user