| Index: ppapi/proxy/ppb_video_decoder_proxy.cc
|
| diff --git a/ppapi/proxy/ppb_video_decoder_proxy.cc b/ppapi/proxy/ppb_video_decoder_proxy.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ff509b93656c04cc37ded2d67f4bfacb90dadcc6
|
| --- /dev/null
|
| +++ b/ppapi/proxy/ppb_video_decoder_proxy.cc
|
| @@ -0,0 +1,371 @@
|
| +// 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/proxy/ppb_video_decoder_proxy.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "gpu/command_buffer/client/gles2_implementation.h"
|
| +#include "ppapi/proxy/enter_proxy.h"
|
| +#include "ppapi/proxy/plugin_dispatcher.h"
|
| +#include "ppapi/proxy/ppapi_messages.h"
|
| +#include "ppapi/proxy/ppb_buffer_proxy.h"
|
| +#include "ppapi/proxy/ppb_context_3d_proxy.h"
|
| +#include "ppapi/thunk/enter.h"
|
| +#include "ppapi/thunk/resource_creation_api.h"
|
| +#include "ppapi/thunk/thunk.h"
|
| +
|
| +using ::ppapi::thunk::PPB_Buffer_API;
|
| +using ::ppapi::thunk::PPB_Context3D_API;
|
| +using ::ppapi::thunk::PPB_VideoDecoder_API;
|
| +
|
| +namespace pp {
|
| +namespace proxy {
|
| +
|
| +VideoDecoder::VideoDecoder(const HostResource& decoder)
|
| + : PluginResource(decoder),
|
| + VideoDecoderImpl(false) {
|
| +}
|
| +
|
| +VideoDecoder* VideoDecoder::Create(const HostResource& resource,
|
| + PP_Resource context3d_id,
|
| + const PP_VideoConfigElement* config) {
|
| + scoped_ptr<VideoDecoder> decoder(new VideoDecoder(resource));
|
| + if (decoder->Init(context3d_id, config))
|
| + return decoder.release();
|
| + return NULL;
|
| +}
|
| +
|
| +VideoDecoder::~VideoDecoder() {
|
| +}
|
| +
|
| +::ppapi::thunk::PPB_VideoDecoder_API* VideoDecoder::AsPPB_VideoDecoder_API() {
|
| + return this;
|
| +}
|
| +
|
| +bool VideoDecoder::Init(PP_Resource context,
|
| + const PP_VideoConfigElement* decoder_config) {
|
| + if(!::ppapi::VideoDecoderImpl::Init(context, decoder_config))
|
| + return false;
|
| +
|
| + ppapi::thunk::EnterResourceNoLock<PPB_Context3D_API>
|
| + enter_context(context, true);
|
| + DCHECK(enter_context.succeeded());
|
| +
|
| + std::vector<int32> copied;
|
| + if (!CopyConfigsToVector(decoder_config, &copied))
|
| + return false;
|
| +
|
| + Context3D* ppb_context =
|
| + static_cast<Context3D*>(enter_context.object());
|
| + HostResource host_context = ppb_context->host_resource();
|
| +
|
| + return true;
|
| +}
|
| +
|
| +int32_t VideoDecoder::Decode(
|
| + const PP_VideoBitstreamBuffer_Dev* bitstream_buffer,
|
| + PP_CompletionCallback callback) {
|
| + ppapi::thunk::EnterResourceNoLock<PPB_Buffer_API>
|
| + enter_buffer(bitstream_buffer->data, true);
|
| + if (enter_buffer.failed())
|
| + return PP_ERROR_BADRESOURCE;
|
| +
|
| + AddBitstreamBufferCallback(bitstream_buffer->id, callback);
|
| +
|
| + Buffer* ppb_buffer =
|
| + static_cast<Buffer*>(enter_buffer.object());
|
| + HostResource host_buffer = ppb_buffer->host_resource();
|
| +
|
| + FlushCommandBuffer();
|
| + GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Decode(
|
| + INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource(),
|
| + host_buffer, bitstream_buffer->id,
|
| + bitstream_buffer->size));
|
| + return PP_OK_COMPLETIONPENDING;
|
| +}
|
| +
|
| +void VideoDecoder::AssignPictureBuffers(uint32_t no_of_buffers,
|
| + const PP_PictureBuffer_Dev* buffers) {
|
| + // Rearrange data for IPC command.
|
| + std::vector<int32> buffer_ids;
|
| + std::vector<uint32> texture_ids;
|
| + std::vector<PP_Size> sizes;
|
| + for (uint32 i = 0; i < no_of_buffers; i++) {
|
| + texture_ids.push_back(buffers[i].texture_id);
|
| + buffer_ids.push_back(buffers[i].id);
|
| + sizes.push_back(buffers[i].size);
|
| + }
|
| +
|
| + FlushCommandBuffer();
|
| + GetDispatcher()->Send(
|
| + new PpapiHostMsg_PPBVideoDecoder_AssignPictureBuffers(
|
| + INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource(),
|
| + buffer_ids, texture_ids, sizes));
|
| +}
|
| +
|
| +void VideoDecoder::ReusePictureBuffer(int32_t picture_buffer_id) {
|
| + FlushCommandBuffer();
|
| + GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_ReusePictureBuffer(
|
| + INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource(), picture_buffer_id));
|
| +}
|
| +
|
| +int32_t VideoDecoder::Flush(PP_CompletionCallback callback) {
|
| + SetFlushCallback(callback);
|
| +
|
| + FlushCommandBuffer();
|
| + GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Flush(
|
| + INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource()));
|
| + return PP_OK_COMPLETIONPENDING;
|
| +}
|
| +
|
| +int32_t VideoDecoder::Reset(PP_CompletionCallback callback) {
|
| + SetResetCallback(callback);
|
| +
|
| + FlushCommandBuffer();
|
| + GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Reset(
|
| + INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource()));
|
| + return PP_OK_COMPLETIONPENDING;
|
| +}
|
| +
|
| +void VideoDecoder::Destroy() {
|
| + FlushCommandBuffer();
|
| + GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Destroy(
|
| + INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource()));
|
| + ::ppapi::VideoDecoderImpl::Destroy();
|
| +}
|
| +
|
| +void VideoDecoder::ResetACK() {
|
| + RunResetCallback();
|
| +}
|
| +
|
| +void VideoDecoder::FlushACK() {
|
| + RunFlushCallback();
|
| +}
|
| +
|
| +void VideoDecoder::EndOfBitstreamACK(int32_t bitstream_buffer_id) {
|
| + RunBitstreamBufferCallback(bitstream_buffer_id);
|
| +}
|
| +
|
| +namespace {
|
| +
|
| +InterfaceProxy* CreateVideoDecoderProxy(Dispatcher* dispatcher,
|
| + const void* target_interface) {
|
| + return new PPB_VideoDecoder_Proxy(dispatcher, target_interface);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +PPB_VideoDecoder_Proxy::PPB_VideoDecoder_Proxy(Dispatcher* dispatcher,
|
| + const void* target_interface)
|
| + : InterfaceProxy(dispatcher, target_interface),
|
| + callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
|
| +}
|
| +
|
| +PPB_VideoDecoder_Proxy::~PPB_VideoDecoder_Proxy() {
|
| +}
|
| +
|
| +// static
|
| +const InterfaceProxy::Info* PPB_VideoDecoder_Proxy::GetInfo() {
|
| + static const Info info = {
|
| + ::ppapi::thunk::GetPPB_VideoDecoder_Thunk(),
|
| + PPB_VIDEODECODER_DEV_INTERFACE,
|
| + INTERFACE_ID_PPB_VIDEO_DECODER_DEV,
|
| + false,
|
| + &CreateVideoDecoderProxy,
|
| + };
|
| + return &info;
|
| +}
|
| +
|
| +bool PPB_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) {
|
| + bool handled = true;
|
| + IPC_BEGIN_MESSAGE_MAP(PPB_VideoDecoder_Proxy, msg)
|
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Create,
|
| + OnMsgCreate)
|
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Decode, OnMsgDecode)
|
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_AssignPictureBuffers,
|
| + OnMsgAssignPictureBuffers)
|
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_ReusePictureBuffer,
|
| + OnMsgReusePictureBuffer)
|
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Flush, OnMsgFlush)
|
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Reset, OnMsgReset)
|
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Destroy, OnMsgDestroy)
|
| + IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_ResetACK, OnMsgResetACK)
|
| + IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_EndOfBitstreamACK,
|
| + OnMsgEndOfBitstreamACK)
|
| + IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_FlushACK, OnMsgFlushACK)
|
| + IPC_MESSAGE_UNHANDLED(handled = false)
|
| + IPC_END_MESSAGE_MAP()
|
| + // FIXME(brettw) handle bad messages!
|
| + return handled;
|
| +}
|
| +
|
| +PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource(
|
| + PP_Instance instance, PP_Resource context3d_id,
|
| + const PP_VideoConfigElement* config) {
|
| + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
|
| + if (!dispatcher)
|
| + return 0;
|
| +
|
| + std::vector<int32_t> copied;
|
| + if (!ppapi::VideoDecoderImpl::CopyConfigsToVector(config, &copied))
|
| + return 0;
|
| +
|
| + ppapi::thunk::EnterResourceNoLock<PPB_Context3D_API>
|
| + enter_context(context3d_id, true);
|
| + if (enter_context.failed())
|
| + return 0;
|
| + Context3D* ppb_context =
|
| + static_cast<Context3D*>(enter_context.object());
|
| + HostResource host_context = ppb_context->host_resource();
|
| +
|
| + HostResource result;
|
| + dispatcher->Send(new PpapiHostMsg_PPBVideoDecoder_Create(
|
| + INTERFACE_ID_PPB_VIDEO_DECODER_DEV, instance,
|
| + host_context, copied, &result));
|
| + if (result.is_null())
|
| + return 0;
|
| +
|
| + linked_ptr<VideoDecoder> video_decoder(
|
| + VideoDecoder::Create(result, context3d_id, config));
|
| +
|
| + return PluginResourceTracker::GetInstance()->AddResource(video_decoder);
|
| +}
|
| +
|
| +void PPB_VideoDecoder_Proxy::OnMsgCreate(PP_Instance instance,
|
| + const HostResource& context3d_id,
|
| + const std::vector<int32_t>& config,
|
| + HostResource* result) {
|
| + ::ppapi::thunk::EnterFunction< ::ppapi::thunk::ResourceCreationAPI>
|
| + resource_creation(instance, true);
|
| + if (resource_creation.failed())
|
| + return;
|
| +
|
| + std::vector<int32_t> copied = config;
|
| + copied.push_back(PP_VIDEOATTR_DICTIONARY_TERMINATOR);
|
| +
|
| + // Make the resource and get the API pointer to its interface.
|
| + result->SetHostResource(
|
| + instance, resource_creation.functions()->CreateVideoDecoder(
|
| + instance, context3d_id.host_resource(), &copied.front()));
|
| +}
|
| +
|
| +void PPB_VideoDecoder_Proxy::OnMsgDecode(
|
| + const HostResource& decoder,
|
| + const HostResource& buffer, int32 id, int32 size) {
|
| + CompletionCallback callback = callback_factory_.NewOptionalCallback(
|
| + &PPB_VideoDecoder_Proxy::SendMsgEndOfBitstreamACKToPlugin, decoder, id);
|
| +
|
| + PP_VideoBitstreamBuffer_Dev bitstream =
|
| + { id, buffer.host_resource(), size };
|
| +
|
| + EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder);
|
| + int32_t result = PP_ERROR_BADRESOURCE;
|
| + if (enter.succeeded()) {
|
| + result = enter.object()->Decode(
|
| + &bitstream, callback.pp_completion_callback());
|
| + }
|
| +
|
| + if (result != PP_OK_COMPLETIONPENDING)
|
| + callback.Run(result);
|
| +}
|
| +
|
| +void PPB_VideoDecoder_Proxy::OnMsgAssignPictureBuffers(
|
| + const HostResource& decoder,
|
| + const std::vector<int32>& buffer_ids,
|
| + const std::vector<uint32>& texture_ids,
|
| + const std::vector<PP_Size>& sizes) {
|
| + std::vector<PP_PictureBuffer_Dev> buffers;
|
| + for (uint i = 0; i < buffer_ids.size(); ++i) {
|
| + PP_PictureBuffer_Dev buffer =
|
| + { buffer_ids[i], sizes[i], texture_ids[i] };
|
| + buffers.push_back(buffer);
|
| + }
|
| + PP_PictureBuffer_Dev* buffer_array = NULL;
|
| + if (!buffers.empty())
|
| + buffer_array = &buffers.front();
|
| +
|
| + EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder);
|
| + if (enter.succeeded())
|
| + enter.object()->AssignPictureBuffers(buffer_ids.size(), buffer_array);
|
| +}
|
| +
|
| +void PPB_VideoDecoder_Proxy::OnMsgReusePictureBuffer(
|
| + const HostResource& decoder,
|
| + int32 picture_buffer_id) {
|
| + EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder);
|
| + if (enter.succeeded())
|
| + enter.object()->ReusePictureBuffer(picture_buffer_id);
|
| +}
|
| +
|
| +void PPB_VideoDecoder_Proxy::OnMsgFlush(const HostResource& decoder) {
|
| + CompletionCallback callback = callback_factory_.NewOptionalCallback(
|
| + &PPB_VideoDecoder_Proxy::SendMsgFlushACKToPlugin, decoder);
|
| +
|
| + EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder);
|
| + int32_t result = PP_ERROR_BADRESOURCE;
|
| + if (enter.succeeded())
|
| + result = enter.object()->Flush(callback.pp_completion_callback());
|
| + if (result != PP_OK_COMPLETIONPENDING)
|
| + callback.Run(result);
|
| +}
|
| +
|
| +void PPB_VideoDecoder_Proxy::OnMsgReset(const HostResource& decoder) {
|
| + CompletionCallback callback = callback_factory_.NewOptionalCallback(
|
| + &PPB_VideoDecoder_Proxy::SendMsgResetACKToPlugin, decoder);
|
| +
|
| + EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder);
|
| + int32_t result = PP_ERROR_BADRESOURCE;
|
| + if (enter.succeeded())
|
| + result = enter.object()->Reset(callback.pp_completion_callback());
|
| + if (result != PP_OK_COMPLETIONPENDING)
|
| + callback.Run(result);
|
| +}
|
| +
|
| +void PPB_VideoDecoder_Proxy::OnMsgDestroy(const HostResource& decoder) {
|
| + EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder);
|
| + if (enter.succeeded())
|
| + enter.object()->Destroy();
|
| +}
|
| +
|
| +void PPB_VideoDecoder_Proxy::SendMsgEndOfBitstreamACKToPlugin(
|
| + int32_t result, const HostResource& decoder, int32 id) {
|
| + dispatcher()->Send(new PpapiMsg_PPBVideoDecoder_EndOfBitstreamACK(
|
| + INTERFACE_ID_PPB_VIDEO_DECODER_DEV, decoder, id));
|
| +}
|
| +
|
| +void PPB_VideoDecoder_Proxy::SendMsgFlushACKToPlugin(
|
| + int32_t result, const HostResource& decoder) {
|
| + dispatcher()->Send(new PpapiMsg_PPBVideoDecoder_FlushACK(
|
| + INTERFACE_ID_PPB_VIDEO_DECODER_DEV, decoder, result));
|
| +}
|
| +
|
| +void PPB_VideoDecoder_Proxy::SendMsgResetACKToPlugin(
|
| + int32_t result, const HostResource& decoder) {
|
| + dispatcher()->Send(new PpapiMsg_PPBVideoDecoder_ResetACK(
|
| + INTERFACE_ID_PPB_VIDEO_DECODER_DEV, decoder, result));
|
| +}
|
| +
|
| +void PPB_VideoDecoder_Proxy::OnMsgEndOfBitstreamACK(
|
| + const HostResource& decoder, int32_t id) {
|
| + EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder);
|
| + if (enter.succeeded())
|
| + static_cast<VideoDecoder*>(enter.object())->EndOfBitstreamACK(id);
|
| +}
|
| +
|
| +void PPB_VideoDecoder_Proxy::OnMsgFlushACK(
|
| + const HostResource& decoder, int32_t pp_error) {
|
| + EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder);
|
| + if (enter.succeeded())
|
| + static_cast<VideoDecoder*>(enter.object())->FlushACK();
|
| +}
|
| +
|
| +void PPB_VideoDecoder_Proxy::OnMsgResetACK(
|
| + const HostResource& decoder, int32_t pp_error) {
|
| + EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder);
|
| + if (enter.succeeded())
|
| + static_cast<VideoDecoder*>(enter.object())->ResetACK();
|
| +}
|
| +
|
| +} // namespace proxy
|
| +} // namespace pp
|
|
|