Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Side by Side Diff: ppapi/proxy/ppb_video_decoder_proxy.cc

Issue 7545014: Implement PPAPI VideoDecode out-of-process support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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());
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 // Rearrange data for IPC command.
91 std::vector<int32> buffer_ids;
92 std::vector<uint32> texture_ids;
93 std::vector<PP_Size> sizes;
94 for (uint32 i = 0; i < no_of_buffers; i++) {
95 texture_ids.push_back(buffers[i].texture_id);
96 buffer_ids.push_back(buffers[i].id);
97 sizes.push_back(buffers[i].size);
98 }
99
100 FlushCommandBuffer();
101 GetDispatcher()->Send(
102 new PpapiHostMsg_PPBVideoDecoder_AssignPictureBuffers(
103 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource(),
104 buffer_ids, texture_ids, sizes));
105 }
106
107 void VideoDecoder::ReusePictureBuffer(int32_t picture_buffer_id) {
108 FlushCommandBuffer();
109 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_ReusePictureBuffer(
110 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource(), picture_buffer_id));
111 }
112
113 int32_t VideoDecoder::Flush(PP_CompletionCallback callback) {
114 SetFlushCallback(callback);
115
116 FlushCommandBuffer();
117 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Flush(
118 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource()));
119 return PP_OK_COMPLETIONPENDING;
120 }
121
122 int32_t VideoDecoder::Reset(PP_CompletionCallback callback) {
123 SetResetCallback(callback);
124
125 FlushCommandBuffer();
126 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Reset(
127 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource()));
128 return PP_OK_COMPLETIONPENDING;
129 }
130
131 void VideoDecoder::Destroy() {
132 FlushCommandBuffer();
133 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Destroy(
134 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource()));
135 ::ppapi::VideoDecoderImpl::Destroy();
136 }
137
138 void VideoDecoder::ResetACK() {
139 RunResetCallback();
140 }
141
142 void VideoDecoder::FlushACK() {
143 RunFlushCallback();
144 }
145
146 void VideoDecoder::EndOfBitstreamACK(int32_t bitstream_buffer_id) {
147 RunBitstreamBufferCallback(bitstream_buffer_id);
148 }
149
150 namespace {
151
152 InterfaceProxy* CreateVideoDecoderProxy(Dispatcher* dispatcher,
153 const void* target_interface) {
154 return new PPB_VideoDecoder_Proxy(dispatcher, target_interface);
155 }
156
157 } // namespace
158
159 PPB_VideoDecoder_Proxy::PPB_VideoDecoder_Proxy(Dispatcher* dispatcher,
160 const void* target_interface)
161 : InterfaceProxy(dispatcher, target_interface),
162 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
163 }
164
165 PPB_VideoDecoder_Proxy::~PPB_VideoDecoder_Proxy() {
166 }
167
168 // static
169 const InterfaceProxy::Info* PPB_VideoDecoder_Proxy::GetInfo() {
170 static const Info info = {
171 ::ppapi::thunk::GetPPB_VideoDecoder_Thunk(),
172 PPB_VIDEODECODER_DEV_INTERFACE,
173 INTERFACE_ID_PPB_VIDEO_DECODER_DEV,
174 false,
175 &CreateVideoDecoderProxy,
176 };
177 return &info;
178 }
179
180 bool PPB_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) {
181 bool handled = true;
182 IPC_BEGIN_MESSAGE_MAP(PPB_VideoDecoder_Proxy, msg)
183 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Create,
184 OnMsgCreate)
185 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Decode, OnMsgDecode)
186 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_AssignPictureBuffers,
187 OnMsgAssignPictureBuffers)
188 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_ReusePictureBuffer,
189 OnMsgReusePictureBuffer)
190 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Flush, OnMsgFlush)
191 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Reset, OnMsgReset)
192 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Destroy, OnMsgDestroy)
193 IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_ResetACK, OnMsgResetACK)
194 IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_EndOfBitstreamACK,
195 OnMsgEndOfBitstreamACK)
196 IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_FlushACK, OnMsgFlushACK)
197 IPC_MESSAGE_UNHANDLED(handled = false)
198 IPC_END_MESSAGE_MAP()
199 // FIXME(brettw) handle bad messages!
200 return handled;
201 }
202
203 PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource(
204 PP_Instance instance, PP_Resource context3d_id,
205 const PP_VideoConfigElement* config) {
206 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
207 if (!dispatcher)
208 return 0;
209
210 std::vector<int32_t> copied;
211 if (!ppapi::VideoDecoderImpl::CopyConfigsToVector(config, &copied))
212 return 0;
213
214 ppapi::thunk::EnterResourceNoLock<PPB_Context3D_API>
215 enter_context(context3d_id, true);
216 if (enter_context.failed())
217 return 0;
218 Context3D* ppb_context =
219 static_cast<Context3D*>(enter_context.object());
220 HostResource host_context = ppb_context->host_resource();
221
222 HostResource result;
223 dispatcher->Send(new PpapiHostMsg_PPBVideoDecoder_Create(
224 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, instance,
225 host_context, copied, &result));
226 if (result.is_null())
227 return 0;
228
229 linked_ptr<VideoDecoder> video_decoder(
230 VideoDecoder::Create(result, context3d_id, config));
231
232 return PluginResourceTracker::GetInstance()->AddResource(video_decoder);
233 }
234
235 void PPB_VideoDecoder_Proxy::OnMsgCreate(PP_Instance instance,
236 const HostResource& context3d_id,
237 const std::vector<int32_t>& config,
238 HostResource* result) {
239 ::ppapi::thunk::EnterFunction< ::ppapi::thunk::ResourceCreationAPI>
240 resource_creation(instance, true);
241 if (resource_creation.failed())
242 return;
243
244 std::vector<int32_t> copied = config;
245 copied.push_back(PP_VIDEOATTR_DICTIONARY_TERMINATOR);
246
247 // Make the resource and get the API pointer to its interface.
248 result->SetHostResource(
249 instance, resource_creation.functions()->CreateVideoDecoder(
250 instance, context3d_id.host_resource(), &copied.front()));
251 }
252
253 void PPB_VideoDecoder_Proxy::OnMsgDecode(
254 const HostResource& decoder,
255 const HostResource& buffer, int32 id, int32 size) {
256 CompletionCallback callback = callback_factory_.NewOptionalCallback(
257 &PPB_VideoDecoder_Proxy::SendMsgEndOfBitstreamACKToPlugin, decoder, id);
258
259 PP_VideoBitstreamBuffer_Dev bitstream =
260 { id, buffer.host_resource(), size };
261
262 EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder);
263 int32_t result = PP_ERROR_BADRESOURCE;
264 if (enter.succeeded()) {
265 result = enter.object()->Decode(
266 &bitstream, callback.pp_completion_callback());
267 }
268
269 if (result != PP_OK_COMPLETIONPENDING)
270 callback.Run(result);
271 }
272
273 void PPB_VideoDecoder_Proxy::OnMsgAssignPictureBuffers(
274 const HostResource& decoder,
275 const std::vector<int32>& buffer_ids,
276 const std::vector<uint32>& texture_ids,
277 const std::vector<PP_Size>& sizes) {
278 std::vector<PP_PictureBuffer_Dev> buffers;
279 for (uint i = 0; i < buffer_ids.size(); ++i) {
280 PP_PictureBuffer_Dev buffer =
281 { buffer_ids[i], sizes[i], texture_ids[i] };
282 buffers.push_back(buffer);
283 }
284 PP_PictureBuffer_Dev* buffer_array = NULL;
285 if (!buffers.empty())
286 buffer_array = &buffers.front();
287
288 EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder);
289 if (enter.succeeded())
290 enter.object()->AssignPictureBuffers(buffer_ids.size(), buffer_array);
291 }
292
293 void PPB_VideoDecoder_Proxy::OnMsgReusePictureBuffer(
294 const HostResource& decoder,
295 int32 picture_buffer_id) {
296 EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder);
297 if (enter.succeeded())
298 enter.object()->ReusePictureBuffer(picture_buffer_id);
299 }
300
301 void PPB_VideoDecoder_Proxy::OnMsgFlush(const HostResource& decoder) {
302 CompletionCallback callback = callback_factory_.NewOptionalCallback(
303 &PPB_VideoDecoder_Proxy::SendMsgFlushACKToPlugin, decoder);
304
305 EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder);
306 int32_t result = PP_ERROR_BADRESOURCE;
307 if (enter.succeeded())
308 result = enter.object()->Flush(callback.pp_completion_callback());
309 if (result != PP_OK_COMPLETIONPENDING)
310 callback.Run(result);
311 }
312
313 void PPB_VideoDecoder_Proxy::OnMsgReset(const HostResource& decoder) {
314 CompletionCallback callback = callback_factory_.NewOptionalCallback(
315 &PPB_VideoDecoder_Proxy::SendMsgResetACKToPlugin, decoder);
316
317 EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder);
318 int32_t result = PP_ERROR_BADRESOURCE;
319 if (enter.succeeded())
320 result = enter.object()->Reset(callback.pp_completion_callback());
321 if (result != PP_OK_COMPLETIONPENDING)
322 callback.Run(result);
323 }
324
325 void PPB_VideoDecoder_Proxy::OnMsgDestroy(const HostResource& decoder) {
326 EnterHostFromHostResource<PPB_VideoDecoder_API> enter(decoder);
327 if (enter.succeeded())
328 enter.object()->Destroy();
329 }
330
331 void PPB_VideoDecoder_Proxy::SendMsgEndOfBitstreamACKToPlugin(
332 int32_t result, const HostResource& decoder, int32 id) {
333 dispatcher()->Send(new PpapiMsg_PPBVideoDecoder_EndOfBitstreamACK(
334 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, decoder, id));
335 }
336
337 void PPB_VideoDecoder_Proxy::SendMsgFlushACKToPlugin(
338 int32_t result, const HostResource& decoder) {
339 dispatcher()->Send(new PpapiMsg_PPBVideoDecoder_FlushACK(
340 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, decoder, result));
341 }
342
343 void PPB_VideoDecoder_Proxy::SendMsgResetACKToPlugin(
344 int32_t result, const HostResource& decoder) {
345 dispatcher()->Send(new PpapiMsg_PPBVideoDecoder_ResetACK(
346 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, decoder, result));
347 }
348
349 void PPB_VideoDecoder_Proxy::OnMsgEndOfBitstreamACK(
350 const HostResource& decoder, int32_t id) {
351 EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder);
352 if (enter.succeeded())
353 static_cast<VideoDecoder*>(enter.object())->EndOfBitstreamACK(id);
354 }
355
356 void PPB_VideoDecoder_Proxy::OnMsgFlushACK(
357 const HostResource& decoder, int32_t pp_error) {
358 EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder);
359 if (enter.succeeded())
360 static_cast<VideoDecoder*>(enter.object())->FlushACK();
361 }
362
363 void PPB_VideoDecoder_Proxy::OnMsgResetACK(
364 const HostResource& decoder, int32_t pp_error) {
365 EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder);
366 if (enter.succeeded())
367 static_cast<VideoDecoder*>(enter.object())->ResetACK();
368 }
369
370 } // namespace proxy
371 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698