Android WebView: build debug/release based on variant.
[chromium-blink-merge.git] / ppapi / proxy / ppp_video_decoder_proxy.cc
blobf1a672127911ec4177fbcd39320ac4390dc8a013
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;
18 namespace ppapi {
19 namespace proxy {
21 namespace {
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);
66 if (dispatcher) {
67 dispatcher->Send(
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,
76 &PictureReady,
77 &NotifyError
80 InterfaceProxy* CreateVideoDecoderPPPProxy(Dispatcher* dispatcher) {
81 return new PPP_VideoDecoder_Proxy(dispatcher);
84 } // namespace
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() {
98 // static
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,
104 false,
105 &CreateVideoDecoderPPPProxy,
107 return &info;
110 bool PPP_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) {
111 if (!dispatcher()->IsPlugin())
112 return false;
114 bool handled = true;
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,
121 OnMsgPictureReady)
122 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_NotifyError,
123 OnMsgNotifyError)
124 IPC_MESSAGE_UNHANDLED(handled = false)
125 IPC_END_MESSAGE_MAP()
126 DCHECK(handled);
127 return handled;
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);
137 if (!plugin_decoder)
138 return;
139 CallWhileUnlocked(ppp_video_decoder_impl_->ProvidePictureBuffers,
140 decoder.instance(),
141 plugin_decoder,
142 req_num_of_bufs,
143 &dimensions,
144 texture_target);
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);
151 if (!plugin_decoder)
152 return;
153 CallWhileUnlocked(ppp_video_decoder_impl_->DismissPictureBuffer,
154 decoder.instance(),
155 plugin_decoder,
156 picture_id);
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);
163 if (!plugin_decoder)
164 return;
165 CallWhileUnlocked(ppp_video_decoder_impl_->PictureReady,
166 decoder.instance(),
167 plugin_decoder,
168 &picture);
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);
175 if (!plugin_decoder)
176 return;
177 CallWhileUnlocked(ppp_video_decoder_impl_->NotifyError,
178 decoder.instance(),
179 plugin_decoder,
180 error);
183 } // namespace proxy
184 } // namespace ppapi