OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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/ppb_video_decoder_proxy.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "gpu/command_buffer/client/gles2_implementation.h" | |
9 #include "ppapi/proxy/enter_proxy.h" | |
10 #include "ppapi/proxy/plugin_dispatcher.h" | |
11 #include "ppapi/proxy/ppapi_messages.h" | |
12 #include "ppapi/proxy/ppb_buffer_proxy.h" | |
13 #include "ppapi/proxy/ppb_context_3d_proxy.h" | |
14 #include "ppapi/thunk/enter.h" | |
15 #include "ppapi/thunk/resource_creation_api.h" | |
16 #include "ppapi/thunk/thunk.h" | |
17 | |
18 using ::ppapi::thunk::PPB_Buffer_API; | |
19 using ::ppapi::thunk::PPB_Context3D_API; | |
20 using ::ppapi::thunk::PPB_VideoDecoder_API; | |
21 | |
22 namespace pp { | |
23 namespace proxy { | |
24 | |
25 VideoDecoder::VideoDecoder(const HostResource& decoder) | |
26 : PluginResource(decoder), | |
27 VideoDecoderImpl(false) { | |
28 } | |
29 | |
30 VideoDecoder* VideoDecoder::Create(const HostResource& resource, | |
31 PP_Resource context3d_id, | |
32 const PP_VideoConfigElement* config) { | |
33 scoped_ptr<VideoDecoder> decoder(new VideoDecoder(resource)); | |
34 if (decoder->Init(context3d_id, config)) | |
35 return decoder.release(); | |
36 return NULL; | |
37 } | |
38 | |
39 VideoDecoder::~VideoDecoder() { | |
40 } | |
41 | |
42 ::ppapi::thunk::PPB_VideoDecoder_API* VideoDecoder::AsPPB_VideoDecoder_API() { | |
43 return this; | |
44 } | |
45 | |
46 bool VideoDecoder::Init(PP_Resource context, | |
47 const PP_VideoConfigElement* decoder_config) { | |
48 if(!::ppapi::VideoDecoderImpl::Init(context, decoder_config)) | |
49 return false; | |
50 | |
51 ppapi::thunk::EnterResourceNoLock<PPB_Context3D_API> | |
52 enter_context(context, true); | |
53 DCHECK(enter_context.succeeded()); | |
piman
2011/08/02 00:40:08
So, we do this enter of the context, which is a ma
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
OK, I changed the Init function to take a PPB_Cont
| |
54 | |
55 std::vector<int32> copied; | |
56 if (!CopyConfigsToVector(decoder_config, &copied)) | |
57 return false; | |
58 | |
59 Context3D* ppb_context = | |
60 static_cast<Context3D*>(enter_context.object()); | |
61 HostResource host_context = ppb_context->host_resource(); | |
62 | |
63 return true; | |
64 } | |
65 | |
66 int32_t VideoDecoder::Decode( | |
67 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, | |
68 PP_CompletionCallback callback) { | |
69 ppapi::thunk::EnterResourceNoLock<PPB_Buffer_API> | |
70 enter_buffer(bitstream_buffer->data, true); | |
71 if (enter_buffer.failed()) | |
72 return PP_ERROR_BADRESOURCE; | |
73 | |
74 AddBitstreamBufferCallback(bitstream_buffer->id, callback); | |
75 | |
76 Buffer* ppb_buffer = | |
77 static_cast<Buffer*>(enter_buffer.object()); | |
78 HostResource host_buffer = ppb_buffer->host_resource(); | |
79 | |
80 FlushCommandBuffer(); | |
81 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Decode( | |
82 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource(), | |
83 host_buffer, bitstream_buffer->id, | |
84 bitstream_buffer->size)); | |
85 return PP_OK_COMPLETIONPENDING; | |
86 } | |
87 | |
88 void VideoDecoder::AssignPictureBuffers(uint32_t no_of_buffers, | |
89 const PP_PictureBuffer_Dev* buffers) { | |
90 std::vector<PP_PictureBuffer_Dev> buffer_list; | |
91 for (uint32 i = 0; i < no_of_buffers; ++i) | |
92 buffer_list.push_back(buffers[i]); | |
piman
2011/08/02 00:40:08
You can write all this as:
std::vector<PP_PictureB
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Done.
| |
93 FlushCommandBuffer(); | |
94 GetDispatcher()->Send( | |
95 new PpapiHostMsg_PPBVideoDecoder_AssignPictureBuffers( | |
96 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource(), buffer_list)); | |
97 | |
98 } | |
99 | |
100 void VideoDecoder::ReusePictureBuffer(int32_t picture_buffer_id) { | |
101 FlushCommandBuffer(); | |
102 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_ReusePictureBuffer( | |
103 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource(), picture_buffer_id)); | |
104 } | |
105 | |
106 int32_t VideoDecoder::Flush(PP_CompletionCallback callback) { | |
107 SetFlushCallback(callback); | |
108 | |
109 FlushCommandBuffer(); | |
110 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Flush( | |
111 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource())); | |
112 return PP_OK_COMPLETIONPENDING; | |
113 } | |
114 | |
115 int32_t VideoDecoder::Reset(PP_CompletionCallback callback) { | |
116 SetResetCallback(callback); | |
117 | |
118 FlushCommandBuffer(); | |
119 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Reset( | |
120 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource())); | |
121 return PP_OK_COMPLETIONPENDING; | |
122 } | |
123 | |
124 void VideoDecoder::Destroy() { | |
125 FlushCommandBuffer(); | |
126 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Destroy( | |
127 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource())); | |
128 ::ppapi::VideoDecoderImpl::Destroy(); | |
129 } | |
130 | |
131 void VideoDecoder::ResetACK() { | |
132 RunResetCallback(); | |
133 } | |
134 | |
135 void VideoDecoder::FlushACK() { | |
136 RunFlushCallback(); | |
137 } | |
138 | |
139 void VideoDecoder::EndOfBitstreamACK(int32_t bitstream_buffer_id) { | |
140 RunBitstreamBufferCallback(bitstream_buffer_id); | |
141 } | |
142 | |
143 namespace { | |
144 | |
145 InterfaceProxy* CreateVideoDecoderProxy(Dispatcher* dispatcher, | |
146 const void* target_interface) { | |
147 return new PPB_VideoDecoder_Proxy(dispatcher, target_interface); | |
148 } | |
149 | |
150 } // namespace | |
151 | |
152 PPB_VideoDecoder_Proxy::PPB_VideoDecoder_Proxy(Dispatcher* dispatcher, | |
153 const void* target_interface) | |
154 : InterfaceProxy(dispatcher, target_interface), | |
155 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
156 } | |
157 | |
158 PPB_VideoDecoder_Proxy::~PPB_VideoDecoder_Proxy() { | |
159 } | |
160 | |
161 // static | |
162 const InterfaceProxy::Info* PPB_VideoDecoder_Proxy::GetInfo() { | |
163 static const Info info = { | |
164 ::ppapi::thunk::GetPPB_VideoDecoder_Thunk(), | |
165 PPB_VIDEODECODER_DEV_INTERFACE, | |
166 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, | |
167 false, | |
168 &CreateVideoDecoderProxy, | |
169 }; | |
170 return &info; | |
171 } | |
172 | |
173 bool PPB_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) { | |
174 bool handled = true; | |
175 IPC_BEGIN_MESSAGE_MAP(PPB_VideoDecoder_Proxy, msg) | |
176 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Create, | |
177 OnMsgCreate) | |
178 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Decode, OnMsgDecode) | |
179 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_AssignPictureBuffers, | |
180 OnMsgAssignPictureBuffers) | |
181 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_ReusePictureBuffer, | |
182 OnMsgReusePictureBuffer) | |
183 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Flush, OnMsgFlush) | |
184 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Reset, OnMsgReset) | |
185 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Destroy, OnMsgDestroy) | |
186 IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_ResetACK, OnMsgResetACK) | |
187 IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_EndOfBitstreamACK, | |
188 OnMsgEndOfBitstreamACK) | |
189 IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_FlushACK, OnMsgFlushACK) | |
190 IPC_MESSAGE_UNHANDLED(handled = false) | |
191 IPC_END_MESSAGE_MAP() | |
192 // FIXME(brettw) handle bad messages! | |
193 return handled; | |
194 } | |
195 | |
196 PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource( | |
197 PP_Instance instance, PP_Resource context3d_id, | |
198 const PP_VideoConfigElement* config) { | |
199 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | |
200 if (!dispatcher) | |
201 return 0; | |
202 | |
203 std::vector<int32_t> copied; | |
204 if (!ppapi::VideoDecoderImpl::CopyConfigsToVector(config, &copied)) | |
205 return 0; | |
206 | |
207 ppapi::thunk::EnterResourceNoLock<PPB_Context3D_API> | |
208 enter_context(context3d_id, true); | |
209 if (enter_context.failed()) | |
210 return 0; | |
211 Context3D* ppb_context = | |
212 static_cast<Context3D*>(enter_context.object()); | |
213 HostResource host_context = ppb_context->host_resource(); | |
214 | |
215 HostResource result; | |
216 dispatcher->Send(new PpapiHostMsg_PPBVideoDecoder_Create( | |
217 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, instance, | |
218 host_context, copied, &result)); | |
219 if (result.is_null()) | |
220 return 0; | |
221 | |
222 linked_ptr<VideoDecoder> video_decoder( | |
223 VideoDecoder::Create(result, context3d_id, config)); | |
224 | |
225 return PluginResourceTracker::GetInstance()->AddResource(video_decoder); | |
226 } | |
227 | |
228 void PPB_VideoDecoder_Proxy::OnMsgCreate(PP_Instance instance, | |
229 const HostResource& context3d_id, | |
230 const std::vector<int32_t>& config, | |
231 HostResource* result) { | |
232 ::ppapi::thunk::EnterFunction< ::ppapi::thunk::ResourceCreationAPI> | |
233 resource_creation(instance, true); | |
234 if (resource_creation.failed()) | |
235 return; | |
236 | |
237 std::vector<int32_t> copied = config; | |
238 copied.push_back(PP_VIDEOATTR_DICTIONARY_TERMINATOR); | |
239 | |
240 // Make the resource and get the API pointer to its interface. | |
241 result->SetHostResource( | |
242 instance, resource_creation.functions()->CreateVideoDecoder( | |
243 instance, context3d_id.host_resource(), &copied.front())); | |
244 } | |
245 | |
246 void PPB_VideoDecoder_Proxy::OnMsgDecode( | |
247 const HostResource& decoder, | |
248 const HostResource& buffer, int32 id, int32 size) { | |
249 CompletionCallback callback = callback_factory_.NewOptionalCallback( | |
250 &PPB_VideoDecoder_Proxy::SendMsgEndOfBitstreamACKToPlugin, decoder, id); | |
251 | |
252 PP_VideoBitstreamBuffer_Dev bitstream = | |
253 { id, buffer.host_resource(), size }; | |
piman
2011/08/02 00:40:08
nit: Can't this fit on one line ? If yes, please r
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Done.
| |
254 | |
255 EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder); | |
256 int32_t result = PP_ERROR_BADRESOURCE; | |
257 if (enter.succeeded()) { | |
258 result = enter.object()->Decode( | |
259 &bitstream, callback.pp_completion_callback()); | |
260 } | |
261 | |
262 if (result != PP_OK_COMPLETIONPENDING) | |
263 callback.Run(result); | |
264 } | |
265 | |
266 void PPB_VideoDecoder_Proxy::OnMsgAssignPictureBuffers( | |
267 const HostResource& decoder, | |
268 const std::vector<PP_PictureBuffer_Dev>& buffers) { | |
269 const PP_PictureBuffer_Dev* buffer_array; | |
270 if (!buffers.empty()) | |
271 buffer_array = &buffers.front(); | |
272 else | |
273 buffer_array = NULL; | |
274 | |
275 EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder); | |
276 if (enter.succeeded()) | |
277 enter.object()->AssignPictureBuffers(buffers.size(), buffer_array); | |
278 } | |
279 | |
280 void PPB_VideoDecoder_Proxy::OnMsgReusePictureBuffer( | |
281 const HostResource& decoder, | |
282 int32 picture_buffer_id) { | |
283 EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder); | |
284 if (enter.succeeded()) | |
285 enter.object()->ReusePictureBuffer(picture_buffer_id); | |
286 } | |
287 | |
288 void PPB_VideoDecoder_Proxy::OnMsgFlush(const HostResource& decoder) { | |
289 CompletionCallback callback = callback_factory_.NewOptionalCallback( | |
piman
2011/08/02 00:40:08
Make this a NewRequiredCallback...
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Done.
| |
290 &PPB_VideoDecoder_Proxy::SendMsgFlushACKToPlugin, decoder); | |
291 | |
292 EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder); | |
293 int32_t result = PP_ERROR_BADRESOURCE; | |
294 if (enter.succeeded()) | |
295 result = enter.object()->Flush(callback.pp_completion_callback()); | |
piman
2011/08/02 00:40:08
... Call the host interface directly through targe
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Done.
| |
296 if (result != PP_OK_COMPLETIONPENDING) | |
piman
2011/08/02 00:40:08
... and you can skip this part !
This whole funct
vrk (LEFT CHROMIUM)
2011/08/03 19:04:31
Neato! Done w/ all, thanks!
| |
297 callback.Run(result); | |
298 } | |
299 | |
300 void PPB_VideoDecoder_Proxy::OnMsgReset(const HostResource& decoder) { | |
301 CompletionCallback callback = callback_factory_.NewOptionalCallback( | |
302 &PPB_VideoDecoder_Proxy::SendMsgResetACKToPlugin, decoder); | |
303 | |
304 EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder); | |
305 int32_t result = PP_ERROR_BADRESOURCE; | |
306 if (enter.succeeded()) | |
307 result = enter.object()->Reset(callback.pp_completion_callback()); | |
308 if (result != PP_OK_COMPLETIONPENDING) | |
309 callback.Run(result); | |
310 } | |
311 | |
312 void PPB_VideoDecoder_Proxy::OnMsgDestroy(const HostResource& decoder) { | |
313 EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder); | |
314 if (enter.succeeded()) | |
315 enter.object()->Destroy(); | |
316 } | |
317 | |
318 void PPB_VideoDecoder_Proxy::SendMsgEndOfBitstreamACKToPlugin( | |
319 int32_t result, const HostResource& decoder, int32 id) { | |
320 dispatcher()->Send(new PpapiMsg_PPBVideoDecoder_EndOfBitstreamACK( | |
321 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, decoder, id)); | |
322 } | |
323 | |
324 void PPB_VideoDecoder_Proxy::SendMsgFlushACKToPlugin( | |
325 int32_t result, const HostResource& decoder) { | |
326 dispatcher()->Send(new PpapiMsg_PPBVideoDecoder_FlushACK( | |
327 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, decoder, result)); | |
328 } | |
329 | |
330 void PPB_VideoDecoder_Proxy::SendMsgResetACKToPlugin( | |
331 int32_t result, const HostResource& decoder) { | |
332 dispatcher()->Send(new PpapiMsg_PPBVideoDecoder_ResetACK( | |
333 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, decoder, result)); | |
334 } | |
335 | |
336 void PPB_VideoDecoder_Proxy::OnMsgEndOfBitstreamACK( | |
337 const HostResource& decoder, int32_t id) { | |
338 EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder); | |
339 if (enter.succeeded()) | |
340 static_cast<VideoDecoder*>(enter.object())->EndOfBitstreamACK(id); | |
341 } | |
342 | |
343 void PPB_VideoDecoder_Proxy::OnMsgFlushACK( | |
344 const HostResource& decoder, int32_t pp_error) { | |
345 EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder); | |
346 if (enter.succeeded()) | |
347 static_cast<VideoDecoder*>(enter.object())->FlushACK(); | |
348 } | |
349 | |
350 void PPB_VideoDecoder_Proxy::OnMsgResetACK( | |
351 const HostResource& decoder, int32_t pp_error) { | |
352 EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder); | |
353 if (enter.succeeded()) | |
354 static_cast<VideoDecoder*>(enter.object())->ResetACK(); | |
355 } | |
356 | |
357 } // namespace proxy | |
358 } // namespace pp | |
OLD | NEW |