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
,
80 InterfaceProxy
* CreateVideoDecoderPPPProxy(Dispatcher
* dispatcher
) {
81 return new PPP_VideoDecoder_Proxy(dispatcher
);
86 PPP_VideoDecoder_Proxy::PPP_VideoDecoder_Proxy(Dispatcher
* dispatcher
)
87 : InterfaceProxy(dispatcher
),
88 ppp_video_decoder_impl_(NULL
) {
89 if (dispatcher
->IsPlugin()) {
90 ppp_video_decoder_impl_
= static_cast<const PPP_VideoDecoder_Dev
*>(
91 dispatcher
->local_get_interface()(PPP_VIDEODECODER_DEV_INTERFACE
));
95 PPP_VideoDecoder_Proxy::~PPP_VideoDecoder_Proxy() {
99 const InterfaceProxy::Info
* PPP_VideoDecoder_Proxy::GetInfo() {
100 static const Info info
= {
101 &video_decoder_interface
,
102 PPP_VIDEODECODER_DEV_INTERFACE
,
103 API_ID_PPP_VIDEO_DECODER_DEV
,
105 &CreateVideoDecoderPPPProxy
,
110 bool PPP_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message
& msg
) {
111 if (!dispatcher()->IsPlugin())
115 IPC_BEGIN_MESSAGE_MAP(PPP_VideoDecoder_Proxy
, msg
)
116 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_ProvidePictureBuffers
,
117 OnMsgProvidePictureBuffers
)
118 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_DismissPictureBuffer
,
119 OnMsgDismissPictureBuffer
)
120 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_PictureReady
,
122 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_NotifyError
,
124 IPC_MESSAGE_UNHANDLED(handled
= false)
125 IPC_END_MESSAGE_MAP()
130 void PPP_VideoDecoder_Proxy::OnMsgProvidePictureBuffers(
131 const HostResource
& decoder
,
132 uint32_t req_num_of_bufs
,
133 const PP_Size
& dimensions
,
134 uint32_t texture_target
) {
135 PP_Resource plugin_decoder
= PluginGlobals::Get()->plugin_resource_tracker()->
136 PluginResourceForHostResource(decoder
);
139 CallWhileUnlocked(ppp_video_decoder_impl_
->ProvidePictureBuffers
,
147 void PPP_VideoDecoder_Proxy::OnMsgDismissPictureBuffer(
148 const HostResource
& decoder
, int32_t picture_id
) {
149 PP_Resource plugin_decoder
= PluginGlobals::Get()->plugin_resource_tracker()->
150 PluginResourceForHostResource(decoder
);
153 CallWhileUnlocked(ppp_video_decoder_impl_
->DismissPictureBuffer
,
159 void PPP_VideoDecoder_Proxy::OnMsgPictureReady(
160 const HostResource
& decoder
, const PP_Picture_Dev
& picture
) {
161 PP_Resource plugin_decoder
= PluginGlobals::Get()->plugin_resource_tracker()->
162 PluginResourceForHostResource(decoder
);
165 CallWhileUnlocked(ppp_video_decoder_impl_
->PictureReady
,
171 void PPP_VideoDecoder_Proxy::OnMsgNotifyError(
172 const HostResource
& decoder
, PP_VideoDecodeError_Dev error
) {
173 PP_Resource plugin_decoder
= PluginGlobals::Get()->plugin_resource_tracker()->
174 PluginResourceForHostResource(decoder
);
177 CallWhileUnlocked(ppp_video_decoder_impl_
->NotifyError
,