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.
5 #include "ppapi/proxy/ppp_video_decoder_proxy.h"
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"
16 using ppapi::thunk::PPB_VideoDecoder_API
;
23 void 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
);
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
));
36 void DismissPictureBuffer(PP_Instance instance
, PP_Resource decoder
,
37 int32_t picture_buffer_id
) {
38 HostResource decoder_resource
;
39 decoder_resource
.SetHostResource(instance
, decoder
);
41 HostDispatcher::GetForInstance(instance
)->Send(
42 new PpapiMsg_PPPVideoDecoder_DismissPictureBuffer(
43 API_ID_PPP_VIDEO_DECODER_DEV
,
44 decoder_resource
, picture_buffer_id
));
47 void PictureReady(PP_Instance instance
, PP_Resource decoder
,
48 const PP_Picture_Dev
* picture
) {
49 HostResource decoder_resource
;
50 decoder_resource
.SetHostResource(instance
, decoder
);
52 HostDispatcher::GetForInstance(instance
)->Send(
53 new PpapiMsg_PPPVideoDecoder_PictureReady(
54 API_ID_PPP_VIDEO_DECODER_DEV
, decoder_resource
, *picture
));
57 void NotifyError(PP_Instance instance
, PP_Resource decoder
,
58 PP_VideoDecodeError_Dev error
) {
59 HostResource decoder_resource
;
60 decoder_resource
.SetHostResource(instance
, decoder
);
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
);
68 new PpapiMsg_PPPVideoDecoder_NotifyError(
69 API_ID_PPP_VIDEO_DECODER_DEV
, decoder_resource
, error
));
73 static const PPP_VideoDecoder_Dev video_decoder_interface
= {
74 &ProvidePictureBuffers
,
75 &DismissPictureBuffer
,
82 PPP_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
));
91 PPP_VideoDecoder_Proxy::~PPP_VideoDecoder_Proxy() {
95 const PPP_VideoDecoder_Dev
* PPP_VideoDecoder_Proxy::GetProxyInterface() {
96 return &video_decoder_interface
;
99 bool PPP_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message
& msg
) {
100 if (!dispatcher()->IsPlugin())
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
,
111 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_NotifyError
,
113 IPC_MESSAGE_UNHANDLED(handled
= false)
114 IPC_END_MESSAGE_MAP()
119 void 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
);
128 CallWhileUnlocked(ppp_video_decoder_impl_
->ProvidePictureBuffers
,
136 void 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
);
142 CallWhileUnlocked(ppp_video_decoder_impl_
->DismissPictureBuffer
,
148 void 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
);
154 CallWhileUnlocked(ppp_video_decoder_impl_
->PictureReady
,
160 void 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
);
166 CallWhileUnlocked(ppp_video_decoder_impl_
->NotifyError
,