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()); |
piman
2011/08/02 00:40:08
So, we do this enter of the context, which is a ma
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
OK, I changed the Init function to take a PPB_Cont
|
+ |
+ 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) { |
+ std::vector<PP_PictureBuffer_Dev> buffer_list; |
+ for (uint32 i = 0; i < no_of_buffers; ++i) |
+ buffer_list.push_back(buffers[i]); |
piman
2011/08/02 00:40:08
You can write all this as:
std::vector<PP_PictureB
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
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! |
+ 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 }; |
piman
2011/08/02 00:40:08
nit: Can't this fit on one line ? If yes, please r
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Done.
|
+ |
+ 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()) |
+ 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( |
piman
2011/08/02 00:40:08
Make this a NewRequiredCallback...
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Done.
|
+ &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()); |
piman
2011/08/02 00:40:08
... Call the host interface directly through targe
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Done.
|
+ if (result != PP_OK_COMPLETIONPENDING) |
piman
2011/08/02 00:40:08
... and you can skip this part !
This whole funct
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Neato! Done w/ all, thanks!
|
+ 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 |