Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1105)

Unified Diff: ppapi/proxy/ppb_video_decoder_proxy.cc

Issue 7545014: Implement PPAPI VideoDecode out-of-process support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: responses to ddorwin and piman Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..197dc35054f36534b00b8a5937c4ad4bf6044d3d
--- /dev/null
+++ b/ppapi/proxy/ppb_video_decoder_proxy.cc
@@ -0,0 +1,358 @@
+// 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());
Ami GONE FROM CHROMIUM 2011/08/02 00:49:08 ditto to comment in ppb_impl
vrk (LEFT CHROMIUM) 2011/08/03 19:04:30 n/a method gone!
+
+ 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();
Ami GONE FROM CHROMIUM 2011/08/02 00:49:08 this doesn't seem to go anywhere... ;)
vrk (LEFT CHROMIUM) 2011/08/03 19:04:30 HAHA! Yeahhhhh whoops... there is no point in over
+
+ 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) {
+ std::vector<PP_PictureBuffer_Dev> buffer_list;
+ for (uint32 i = 0; i < no_of_buffers; ++i)
+ buffer_list.push_back(buffers[i]);
Ami GONE FROM CHROMIUM 2011/08/02 00:49:08 Can you not use the iterator-based vector ctor her
vrk (LEFT CHROMIUM) 2011/08/03 19:04:30 Ahh yes, that is superior. Done!
+ FlushCommandBuffer();
+ GetDispatcher()->Send(
+ new PpapiHostMsg_PPBVideoDecoder_AssignPictureBuffers(
+ INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource(), buffer_list));
+
+}
+
+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!
Ami GONE FROM CHROMIUM 2011/08/02 00:49:08 DCHECK instead of FIXME?
vrk (LEFT CHROMIUM) 2011/08/03 19:04:30 Done.
+ 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)
Ami GONE FROM CHROMIUM 2011/08/02 00:49:08 When can this fail?
vrk (LEFT CHROMIUM) 2011/08/03 22:05:22 brettw addressed; I added comment. Done.
+ 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<PP_PictureBuffer_Dev>& buffers) {
+ const PP_PictureBuffer_Dev* buffer_array;
+ if (!buffers.empty())
Ami GONE FROM CHROMIUM 2011/08/02 00:49:08 DCHECK instead?
vrk (LEFT CHROMIUM) 2011/08/03 19:04:30 Done.
+ buffer_array = &buffers.front();
+ else
+ buffer_array = NULL;
+
+ EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder);
+ if (enter.succeeded())
+ enter.object()->AssignPictureBuffers(buffers.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

Powered by Google App Engine
This is Rietveld 408576698