| Index: ppapi/proxy/video_capture_resource.cc
|
| diff --git a/ppapi/proxy/video_capture_resource.cc b/ppapi/proxy/video_capture_resource.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..43cfefb3873234c08b0d74cfe2cee021c86fb3a2
|
| --- /dev/null
|
| +++ b/ppapi/proxy/video_capture_resource.cc
|
| @@ -0,0 +1,238 @@
|
| +// 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/ppapi_messages.h"
|
| +#include "ppapi/proxy/ppb_buffer_proxy.h"
|
| +#include "ppapi/proxy/resource_message_params.h"
|
| +#include "ppapi/shared_impl/ppb_video_capture_shared.h"
|
| +#include "ppapi/shared_impl/tracked_callback.h"
|
| +
|
| +namespace ppapi {
|
| +namespace proxy {
|
| +
|
| +VideoCaptureResource::VideoCaptureResource(
|
| + Connection connection,
|
| + PP_Instance instance,
|
| + PluginDispatcher* dispatcher)
|
| + : PluginResource(connection, instance),
|
| + PPB_VideoCapture_Shared(),
|
| + devices_(NULL) {
|
| + if (!sent_create_to_renderer())
|
| + 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,
|
| + OnDeviceInfo)
|
| + PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
|
| + PpapiPluginMsg_VideoCapture_OnStatus,
|
| + OnStatus)
|
| + PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
|
| + PpapiPluginMsg_VideoCapture_OnError,
|
| + OnError)
|
| + PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(
|
| + PpapiPluginMsg_VideoCapture_OnBufferReady,
|
| + OnBufferReady)
|
| + PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(NOTREACHED())
|
| + IPC_END_MESSAGE_MAP()
|
| +}
|
| +
|
| +int32_t VideoCaptureResource::EnumerateDevices(
|
| + PP_Resource* devices,
|
| + scoped_refptr<TrackedCallback> callback) {
|
| + if (TrackedCallback::IsPending(enumerate_devices_callback_))
|
| + return PP_ERROR_INPROGRESS;
|
| +
|
| + devices_ = devices;
|
| + enumerate_devices_callback_ = callback;
|
| +
|
| + Call<PpapiPluginMsg_VideoCapture_EnumerateDevicesResponse>(
|
| + RENDERER,
|
| + PpapiHostMsg_VideoCapture_EnumerateDevices(),
|
| + base::Bind(&VideoCaptureResource::OnEnumerateDevicesComplete, this));
|
| + 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_OpenACK>(
|
| + RENDERER,
|
| + PpapiHostMsg_VideoCapture_Open(device_id, requested_info, buffer_count),
|
| + base::Bind(&VideoCaptureResource::OnOpenComplete, this));
|
| + return PP_OK_COMPLETIONPENDING;
|
| +}
|
| +
|
| +int32_t VideoCaptureResource::StartCapture() {
|
| + return PPB_VideoCapture_Shared::StartCapture();
|
| +}
|
| +
|
| +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() {
|
| + return PPB_VideoCapture_Shared::StopCapture();
|
| +}
|
| +
|
| +void VideoCaptureResource::Close() {
|
| + Post(RENDERER, PpapiHostMsg_VideoCapture_Close());
|
| +
|
| + if (TrackedCallback::IsPending(open_callback_))
|
| + open_callback_->PostAbort();
|
| +}
|
| +
|
| +int32_t VideoCaptureResource::StartCapture0_1(
|
| + const PP_VideoCaptureDeviceInfo_Dev& requested_info,
|
| + uint32_t buffer_count) {
|
| + return PPB_VideoCapture_Shared::StartCapture0_1(requested_info,
|
| + buffer_count);
|
| +}
|
| +
|
| +void VideoCaptureResource::OnDeviceInfo(
|
| + 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.GetAllSharedMemoryHandles(&handles);
|
| + DCHECK(handles.size() == buffers.size());
|
| +
|
| + scoped_array<PP_Resource> resources(new PP_Resource[buffers.size()]);
|
| + for (size_t i = 0; i < buffers.size(); ++i) {
|
| + resources[i] = ppapi::proxy::PPB_Buffer_Proxy::AddProxyResource(
|
| + buffers[i], handles[i], buffer_size);
|
| + }
|
| +
|
| + buffer_in_use_ = std::vector<bool>(buffers.size());
|
| +
|
| + ppp_video_capture_impl_->OnDeviceInfo(
|
| + pp_instance(),
|
| + pp_resource(),
|
| + &info,
|
| + buffers.size(),
|
| + resources.get());
|
| +}
|
| +
|
| +void VideoCaptureResource::OnStatus(
|
| + const ResourceMessageReplyParams& params,
|
| + uint32_t status) {
|
| + if (ppp_video_capture_impl_)
|
| + ppp_video_capture_impl_->OnStatus(pp_instance(), pp_resource(), status);
|
| +}
|
| +
|
| +void VideoCaptureResource::OnError(
|
| + const ResourceMessageReplyParams& params,
|
| + uint32_t error_code) {
|
| + if (ppp_video_capture_impl_)
|
| + ppp_video_capture_impl_->OnError(pp_instance(), pp_resource(), error_code);
|
| +}
|
| +
|
| +void VideoCaptureResource::OnBufferReady(
|
| + const ResourceMessageReplyParams& params,
|
| + uint32_t buffer) {
|
| + SetBufferInUse(buffer);
|
| + if (ppp_video_capture_impl_) {
|
| + ppp_video_capture_impl_->OnBufferReady(pp_instance(), pp_resource(),
|
| + buffer);
|
| + }
|
| +}
|
| +
|
| +int32_t VideoCaptureResource::InternalStartCapture() {
|
| + buffer_in_use_.clear();
|
| + Post(RENDERER, PpapiHostMsg_VideoCapture_StartCapture());
|
| + return PP_OK;
|
| +}
|
| +
|
| +int32_t VideoCaptureResource::InternalStopCapture() {
|
| + Post(RENDERER, PpapiHostMsg_VideoCapture_StopCapture());
|
| + return PP_OK;
|
| +}
|
| +
|
| +int32_t VideoCaptureResource::InternalStartCapture0_1(
|
| + const PP_VideoCaptureDeviceInfo_Dev& requested_info,
|
| + uint32_t buffer_count) {
|
| + if (TrackedCallback::IsPending(open_callback_))
|
| + return PP_ERROR_FAILED;
|
| +
|
| + buffer_in_use_.clear();
|
| + Post(RENDERER, PpapiHostMsg_VideoCapture_StartCapture0_1(requested_info,
|
| + buffer_count));
|
| + return PP_OK;
|
| +}
|
| +
|
| +void VideoCaptureResource::OnOpenComplete(
|
| + const ResourceMessageReplyParams& params,
|
| + 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_))
|
| + TrackedCallback::ClearAndRun(&open_callback_, result);
|
| +}
|
| +
|
| +void VideoCaptureResource::OnEnumerateDevicesComplete(
|
| + const ResourceMessageReplyParams& params,
|
| + int32_t result,
|
| + const std::vector<DeviceRefData>& devices) {
|
| + DCHECK(TrackedCallback::IsPending(enumerate_devices_callback_));
|
| +
|
| + if (result == PP_OK && devices_) {
|
| + devices_data_ = devices;
|
| +
|
| + // devices_ points to the resource array of PP_ArrayOutput allocated in
|
| + // VideoCapture_Dev.
|
| + *devices_ = PPB_DeviceRef_Shared::CreateResourceArray(
|
| + OBJECT_IS_PROXY, pp_instance(), devices);
|
| + }
|
| + devices_ = NULL;
|
| +
|
| + TrackedCallback::ClearAndRun(&enumerate_devices_callback_, 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
|
|
|