ppp_video_decoder_proxy.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "ppapi/proxy/ppp_video_decoder_proxy.h" 6 7#include "ppapi/proxy/host_dispatcher.h" 8#include "ppapi/proxy/plugin_globals.h" 9#include "ppapi/proxy/plugin_resource_tracker.h" 10#include "ppapi/proxy/ppapi_messages.h" 11#include "ppapi/proxy/ppb_video_decoder_proxy.h" 12#include "ppapi/thunk/enter.h" 13#include "ppapi/thunk/ppb_video_decoder_api.h" 14#include "ppapi/thunk/thunk.h" 15 16using ppapi::thunk::PPB_VideoDecoder_API; 17 18namespace ppapi { 19namespace proxy { 20 21namespace { 22 23void ProvidePictureBuffers(PP_Instance instance, PP_Resource decoder, 24 uint32_t req_num_of_bufs, 25 const PP_Size* dimensions, 26 uint32_t texture_target) { 27 HostResource decoder_resource; 28 decoder_resource.SetHostResource(instance, decoder); 29 30 HostDispatcher::GetForInstance(instance)->Send( 31 new PpapiMsg_PPPVideoDecoder_ProvidePictureBuffers( 32 API_ID_PPP_VIDEO_DECODER_DEV, 33 decoder_resource, req_num_of_bufs, *dimensions, texture_target)); 34} 35 36void DismissPictureBuffer(PP_Instance instance, PP_Resource decoder, 37 int32_t picture_buffer_id) { 38 HostResource decoder_resource; 39 decoder_resource.SetHostResource(instance, decoder); 40 41 HostDispatcher::GetForInstance(instance)->Send( 42 new PpapiMsg_PPPVideoDecoder_DismissPictureBuffer( 43 API_ID_PPP_VIDEO_DECODER_DEV, 44 decoder_resource, picture_buffer_id)); 45} 46 47void PictureReady(PP_Instance instance, PP_Resource decoder, 48 const PP_Picture_Dev* picture) { 49 HostResource decoder_resource; 50 decoder_resource.SetHostResource(instance, decoder); 51 52 HostDispatcher::GetForInstance(instance)->Send( 53 new PpapiMsg_PPPVideoDecoder_PictureReady( 54 API_ID_PPP_VIDEO_DECODER_DEV, decoder_resource, *picture)); 55} 56 57void NotifyError(PP_Instance instance, PP_Resource decoder, 58 PP_VideoDecodeError_Dev error) { 59 HostResource decoder_resource; 60 decoder_resource.SetHostResource(instance, decoder); 61 62 // It's possible that the error we're being notified about is happening 63 // because the instance is shutting down. In this case, our instance may 64 // already have been removed from the HostDispatcher map. 65 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); 66 if (dispatcher) { 67 dispatcher->Send( 68 new PpapiMsg_PPPVideoDecoder_NotifyError( 69 API_ID_PPP_VIDEO_DECODER_DEV, decoder_resource, error)); 70 } 71} 72 73static const PPP_VideoDecoder_Dev video_decoder_interface = { 74 &ProvidePictureBuffers, 75 &DismissPictureBuffer, 76 &PictureReady, 77 &NotifyError 78}; 79 80} // namespace 81 82PPP_VideoDecoder_Proxy::PPP_VideoDecoder_Proxy(Dispatcher* dispatcher) 83 : InterfaceProxy(dispatcher), 84 ppp_video_decoder_impl_(NULL) { 85 if (dispatcher->IsPlugin()) { 86 ppp_video_decoder_impl_ = static_cast<const PPP_VideoDecoder_Dev*>( 87 dispatcher->local_get_interface()(PPP_VIDEODECODER_DEV_INTERFACE)); 88 } 89} 90 91PPP_VideoDecoder_Proxy::~PPP_VideoDecoder_Proxy() { 92} 93 94// static 95const PPP_VideoDecoder_Dev* PPP_VideoDecoder_Proxy::GetProxyInterface() { 96 return &video_decoder_interface; 97} 98 99bool PPP_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) { 100 if (!dispatcher()->IsPlugin()) 101 return false; 102 103 bool handled = true; 104 IPC_BEGIN_MESSAGE_MAP(PPP_VideoDecoder_Proxy, msg) 105 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_ProvidePictureBuffers, 106 OnMsgProvidePictureBuffers) 107 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_DismissPictureBuffer, 108 OnMsgDismissPictureBuffer) 109 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_PictureReady, 110 OnMsgPictureReady) 111 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_NotifyError, 112 OnMsgNotifyError) 113 IPC_MESSAGE_UNHANDLED(handled = false) 114 IPC_END_MESSAGE_MAP() 115 DCHECK(handled); 116 return handled; 117} 118 119void PPP_VideoDecoder_Proxy::OnMsgProvidePictureBuffers( 120 const HostResource& decoder, 121 uint32_t req_num_of_bufs, 122 const PP_Size& dimensions, 123 uint32_t texture_target) { 124 PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> 125 PluginResourceForHostResource(decoder); 126 if (!plugin_decoder) 127 return; 128 CallWhileUnlocked(ppp_video_decoder_impl_->ProvidePictureBuffers, 129 decoder.instance(), 130 plugin_decoder, 131 req_num_of_bufs, 132 &dimensions, 133 texture_target); 134} 135 136void PPP_VideoDecoder_Proxy::OnMsgDismissPictureBuffer( 137 const HostResource& decoder, int32_t picture_id) { 138 PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> 139 PluginResourceForHostResource(decoder); 140 if (!plugin_decoder) 141 return; 142 CallWhileUnlocked(ppp_video_decoder_impl_->DismissPictureBuffer, 143 decoder.instance(), 144 plugin_decoder, 145 picture_id); 146} 147 148void PPP_VideoDecoder_Proxy::OnMsgPictureReady( 149 const HostResource& decoder, const PP_Picture_Dev& picture) { 150 PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> 151 PluginResourceForHostResource(decoder); 152 if (!plugin_decoder) 153 return; 154 CallWhileUnlocked(ppp_video_decoder_impl_->PictureReady, 155 decoder.instance(), 156 plugin_decoder, 157 &picture); 158} 159 160void PPP_VideoDecoder_Proxy::OnMsgNotifyError( 161 const HostResource& decoder, PP_VideoDecodeError_Dev error) { 162 PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> 163 PluginResourceForHostResource(decoder); 164 if (!plugin_decoder) 165 return; 166 CallWhileUnlocked(ppp_video_decoder_impl_->NotifyError, 167 decoder.instance(), 168 plugin_decoder, 169 error); 170} 171 172} // namespace proxy 173} // namespace ppapi 174