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_dev_api.h"
14 #include "ppapi/thunk/thunk.h"
21 void ProvidePictureBuffers(PP_Instance instance
, PP_Resource decoder
,
22 uint32_t req_num_of_bufs
,
23 const PP_Size
* dimensions
,
24 uint32_t texture_target
) {
25 HostResource decoder_resource
;
26 decoder_resource
.SetHostResource(instance
, decoder
);
28 HostDispatcher::GetForInstance(instance
)->Send(
29 new PpapiMsg_PPPVideoDecoder_ProvidePictureBuffers(
30 API_ID_PPP_VIDEO_DECODER_DEV
,
31 decoder_resource
, req_num_of_bufs
, *dimensions
, texture_target
));
34 void DismissPictureBuffer(PP_Instance instance
, PP_Resource decoder
,
35 int32_t picture_buffer_id
) {
36 HostResource decoder_resource
;
37 decoder_resource
.SetHostResource(instance
, decoder
);
39 HostDispatcher::GetForInstance(instance
)->Send(
40 new PpapiMsg_PPPVideoDecoder_DismissPictureBuffer(
41 API_ID_PPP_VIDEO_DECODER_DEV
,
42 decoder_resource
, picture_buffer_id
));
45 void PictureReady(PP_Instance instance
, PP_Resource decoder
,
46 const PP_Picture_Dev
* picture
) {
47 HostResource decoder_resource
;
48 decoder_resource
.SetHostResource(instance
, decoder
);
50 HostDispatcher::GetForInstance(instance
)->Send(
51 new PpapiMsg_PPPVideoDecoder_PictureReady(
52 API_ID_PPP_VIDEO_DECODER_DEV
, decoder_resource
, *picture
));
55 void NotifyError(PP_Instance instance
, PP_Resource decoder
,
56 PP_VideoDecodeError_Dev error
) {
57 HostResource decoder_resource
;
58 decoder_resource
.SetHostResource(instance
, decoder
);
60 // It's possible that the error we're being notified about is happening
61 // because the instance is shutting down. In this case, our instance may
62 // already have been removed from the HostDispatcher map.
63 HostDispatcher
* dispatcher
= HostDispatcher::GetForInstance(instance
);
66 new PpapiMsg_PPPVideoDecoder_NotifyError(
67 API_ID_PPP_VIDEO_DECODER_DEV
, decoder_resource
, error
));
71 static const PPP_VideoDecoder_Dev video_decoder_interface
= {
72 &ProvidePictureBuffers
,
73 &DismissPictureBuffer
,
80 PPP_VideoDecoder_Proxy::PPP_VideoDecoder_Proxy(Dispatcher
* dispatcher
)
81 : InterfaceProxy(dispatcher
),
82 ppp_video_decoder_impl_(NULL
) {
83 if (dispatcher
->IsPlugin()) {
84 ppp_video_decoder_impl_
= static_cast<const PPP_VideoDecoder_Dev
*>(
85 dispatcher
->local_get_interface()(PPP_VIDEODECODER_DEV_INTERFACE
));
89 PPP_VideoDecoder_Proxy::~PPP_VideoDecoder_Proxy() {
93 const PPP_VideoDecoder_Dev
* PPP_VideoDecoder_Proxy::GetProxyInterface() {
94 return &video_decoder_interface
;
97 bool PPP_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message
& msg
) {
98 if (!dispatcher()->IsPlugin())
102 IPC_BEGIN_MESSAGE_MAP(PPP_VideoDecoder_Proxy
, msg
)
103 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_ProvidePictureBuffers
,
104 OnMsgProvidePictureBuffers
)
105 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_DismissPictureBuffer
,
106 OnMsgDismissPictureBuffer
)
107 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_PictureReady
,
109 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_NotifyError
,
111 IPC_MESSAGE_UNHANDLED(handled
= false)
112 IPC_END_MESSAGE_MAP()
117 void PPP_VideoDecoder_Proxy::OnMsgProvidePictureBuffers(
118 const HostResource
& decoder
,
119 uint32_t req_num_of_bufs
,
120 const PP_Size
& dimensions
,
121 uint32_t texture_target
) {
122 PP_Resource plugin_decoder
= PluginGlobals::Get()->plugin_resource_tracker()->
123 PluginResourceForHostResource(decoder
);
126 CallWhileUnlocked(ppp_video_decoder_impl_
->ProvidePictureBuffers
,
134 void PPP_VideoDecoder_Proxy::OnMsgDismissPictureBuffer(
135 const HostResource
& decoder
, int32_t picture_id
) {
136 PP_Resource plugin_decoder
= PluginGlobals::Get()->plugin_resource_tracker()->
137 PluginResourceForHostResource(decoder
);
140 CallWhileUnlocked(ppp_video_decoder_impl_
->DismissPictureBuffer
,
146 void PPP_VideoDecoder_Proxy::OnMsgPictureReady(
147 const HostResource
& decoder
, const PP_Picture_Dev
& picture
) {
148 PP_Resource plugin_decoder
= PluginGlobals::Get()->plugin_resource_tracker()->
149 PluginResourceForHostResource(decoder
);
152 CallWhileUnlocked(ppp_video_decoder_impl_
->PictureReady
,
158 void PPP_VideoDecoder_Proxy::OnMsgNotifyError(
159 const HostResource
& decoder
, PP_VideoDecodeError_Dev error
) {
160 PP_Resource plugin_decoder
= PluginGlobals::Get()->plugin_resource_tracker()->
161 PluginResourceForHostResource(decoder
);
164 CallWhileUnlocked(ppp_video_decoder_impl_
->NotifyError
,