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

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::EnterResourceNoLock;
19 using ppapi::thunk::PPB_Buffer_API;
20 using ppapi::thunk::PPB_Context3D_API;
21 using ppapi::thunk::PPB_VideoDecoder_API;
22
23 namespace pp {
24 namespace proxy {
25
26 class VideoDecoder : public PluginResource,
27 public ::ppapi::VideoDecoderImpl {
28 public:
29 virtual ~VideoDecoder();
30
31 static VideoDecoder* Create(const HostResource& resource,
32 PP_Resource context3d_id,
33 const PP_VideoConfigElement* config);
34
35 // ResourceObjectBase overrides.
36 virtual PPB_VideoDecoder_API* AsPPB_VideoDecoder_API() OVERRIDE;
37
38 // PPB_VideoDecoder_API implementation.
39 virtual int32_t Decode(const PP_VideoBitstreamBuffer_Dev* bitstream_buffer,
40 PP_CompletionCallback callback) OVERRIDE;
41 virtual void AssignPictureBuffers(
42 uint32_t no_of_buffers, const PP_PictureBuffer_Dev* buffers) OVERRIDE;
43 virtual void ReusePictureBuffer(int32_t picture_buffer_id) OVERRIDE;
44 virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE;
45 virtual int32_t Reset(PP_CompletionCallback callback) OVERRIDE;
46 virtual void Destroy() OVERRIDE;
47
48 private:
49 friend class PPB_VideoDecoder_Proxy;
50 explicit VideoDecoder(const HostResource& resource);
51
52 // Run the callbacks that were passed into the plugin interface.
53 void FlushACK(int32_t result);
54 void ResetACK(int32_t result);
55 void EndOfBitstreamACK(int32_t buffer_id, int32_t result);
56
57 DISALLOW_COPY_AND_ASSIGN(VideoDecoder);
58 };
59
60 VideoDecoder::VideoDecoder(const HostResource& decoder)
61 : PluginResource(decoder),
62 VideoDecoderImpl(false) {
63 }
64
65 VideoDecoder* VideoDecoder::Create(const HostResource& resource,
66 PP_Resource context3d_id,
67 const PP_VideoConfigElement* config) {
68 if (!context3d_id)
69 return NULL;
70
71 EnterResourceNoLock<PPB_Context3D_API> enter_context(context3d_id, true);
72 if (enter_context.failed())
73 return NULL;
74
75 scoped_ptr<VideoDecoder> decoder(new VideoDecoder(resource));
76 if (decoder->Init(context3d_id, enter_context.object(), config))
77 return decoder.release();
78 return NULL;
79 }
80
81 VideoDecoder::~VideoDecoder() {
82 }
83
84 ::ppapi::thunk::PPB_VideoDecoder_API* VideoDecoder::AsPPB_VideoDecoder_API() {
85 return this;
86 }
87
88 int32_t VideoDecoder::Decode(
89 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer,
90 PP_CompletionCallback callback) {
91 ppapi::thunk::EnterResourceNoLock<PPB_Buffer_API>
92 enter_buffer(bitstream_buffer->data, true);
93 if (enter_buffer.failed())
94 return PP_ERROR_BADRESOURCE;
95
96 SetBitstreamBufferCallback(bitstream_buffer->id, callback);
97
98 Buffer* ppb_buffer =
99 static_cast<Buffer*>(enter_buffer.object());
100 HostResource host_buffer = ppb_buffer->host_resource();
101
102 FlushCommandBuffer();
103 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Decode(
104 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource(),
105 host_buffer, bitstream_buffer->id,
106 bitstream_buffer->size));
107 return PP_OK_COMPLETIONPENDING;
108 }
109
110 void VideoDecoder::AssignPictureBuffers(uint32_t no_of_buffers,
111 const PP_PictureBuffer_Dev* buffers) {
112 std::vector<PP_PictureBuffer_Dev> buffer_list(
113 buffers, buffers + no_of_buffers);
114 FlushCommandBuffer();
115 GetDispatcher()->Send(
116 new PpapiHostMsg_PPBVideoDecoder_AssignPictureBuffers(
117 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource(), buffer_list));
118 }
119
120 void VideoDecoder::ReusePictureBuffer(int32_t picture_buffer_id) {
121 FlushCommandBuffer();
122 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_ReusePictureBuffer(
123 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource(), picture_buffer_id));
124 }
125
126 int32_t VideoDecoder::Flush(PP_CompletionCallback callback) {
127 SetFlushCallback(callback);
128
129 FlushCommandBuffer();
130 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Flush(
131 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource()));
132 return PP_OK_COMPLETIONPENDING;
133 }
134
135 int32_t VideoDecoder::Reset(PP_CompletionCallback callback) {
136 SetResetCallback(callback);
137
138 FlushCommandBuffer();
139 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Reset(
140 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource()));
141 return PP_OK_COMPLETIONPENDING;
142 }
143
144 void VideoDecoder::Destroy() {
145 FlushCommandBuffer();
146 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Destroy(
147 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource()));
148 ::ppapi::VideoDecoderImpl::Destroy();
149 }
150
151 void VideoDecoder::ResetACK(int32_t result) {
152 RunResetCallback(result);
153 }
154
155 void VideoDecoder::FlushACK(int32_t result) {
156 RunFlushCallback(result);
157 }
158
159 void VideoDecoder::EndOfBitstreamACK(
160 int32_t bitstream_buffer_id, int32_t result) {
161 RunBitstreamBufferCallback(bitstream_buffer_id, result);
162 }
163
164 namespace {
165
166 InterfaceProxy* CreateVideoDecoderProxy(Dispatcher* dispatcher,
167 const void* target_interface) {
168 return new PPB_VideoDecoder_Proxy(dispatcher, target_interface);
169 }
170
171 } // namespace
172
173 PPB_VideoDecoder_Proxy::PPB_VideoDecoder_Proxy(Dispatcher* dispatcher,
174 const void* target_interface)
175 : InterfaceProxy(dispatcher, target_interface),
176 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
177 }
178
179 PPB_VideoDecoder_Proxy::~PPB_VideoDecoder_Proxy() {
180 }
181
182 // static
183 const InterfaceProxy::Info* PPB_VideoDecoder_Proxy::GetInfo() {
184 static const Info info = {
185 ::ppapi::thunk::GetPPB_VideoDecoder_Thunk(),
186 PPB_VIDEODECODER_DEV_INTERFACE,
187 INTERFACE_ID_PPB_VIDEO_DECODER_DEV,
188 false,
189 &CreateVideoDecoderProxy,
190 };
191 return &info;
192 }
193
194 bool PPB_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) {
195 bool handled = true;
196 IPC_BEGIN_MESSAGE_MAP(PPB_VideoDecoder_Proxy, msg)
197 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Create,
198 OnMsgCreate)
199 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Decode, OnMsgDecode)
200 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_AssignPictureBuffers,
201 OnMsgAssignPictureBuffers)
202 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_ReusePictureBuffer,
203 OnMsgReusePictureBuffer)
204 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Flush, OnMsgFlush)
205 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Reset, OnMsgReset)
206 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoDecoder_Destroy, OnMsgDestroy)
207 IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_ResetACK, OnMsgResetACK)
208 IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_EndOfBitstreamACK,
209 OnMsgEndOfBitstreamACK)
210 IPC_MESSAGE_HANDLER(PpapiMsg_PPBVideoDecoder_FlushACK, OnMsgFlushACK)
211 IPC_MESSAGE_UNHANDLED(handled = false)
212 IPC_END_MESSAGE_MAP()
213 DCHECK(handled);
214 return handled;
215 }
216
217 PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource(
218 PP_Instance instance, PP_Resource context3d_id,
219 const PP_VideoConfigElement* config) {
220 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
221 if (!dispatcher)
222 return 0;
223
224 std::vector<PP_VideoConfigElement> copied;
225 if (!ppapi::VideoDecoderImpl::CopyConfigsToVector(config, &copied))
226 return 0;
227
228 ppapi::thunk::EnterResourceNoLock<PPB_Context3D_API>
229 enter_context(context3d_id, true);
230 if (enter_context.failed())
231 return 0;
232 Context3D* ppb_context =
233 static_cast<Context3D*>(enter_context.object());
234 HostResource host_context = ppb_context->host_resource();
235
236 HostResource result;
237 dispatcher->Send(new PpapiHostMsg_PPBVideoDecoder_Create(
238 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, instance,
239 host_context, copied, &result));
240 if (result.is_null())
241 return 0;
242
243 linked_ptr<VideoDecoder> video_decoder(
244 VideoDecoder::Create(result, context3d_id, config));
245
246 return PluginResourceTracker::GetInstance()->AddResource(video_decoder);
247 }
248
249 void PPB_VideoDecoder_Proxy::OnMsgCreate(
250 PP_Instance instance, const HostResource& context3d_id,
251 const std::vector<PP_VideoConfigElement>& config,
252 HostResource* result) {
253 ::ppapi::thunk::EnterFunction< ::ppapi::thunk::ResourceCreationAPI>
254 resource_creation(instance, true);
255 if (resource_creation.failed())
256 return;
257
258 std::vector<PP_VideoConfigElement> copied = config;
259 copied.push_back(PP_VIDEOATTR_DICTIONARY_TERMINATOR);
260
261 // Make the resource and get the API pointer to its interface.
262 result->SetHostResource(
263 instance, resource_creation.functions()->CreateVideoDecoder(
264 instance, context3d_id.host_resource(), &copied.front()));
265 }
266
267 void PPB_VideoDecoder_Proxy::OnMsgDecode(
268 const HostResource& decoder,
269 const HostResource& buffer, int32 id, int32 size) {
270 if (!ppb_video_decoder_target())
271 return;
272
273 CompletionCallback callback = callback_factory_.NewRequiredCallback(
274 &PPB_VideoDecoder_Proxy::SendMsgEndOfBitstreamACKToPlugin, decoder, id);
275
276 PP_VideoBitstreamBuffer_Dev bitstream = { id, buffer.host_resource(), size };
277 ppb_video_decoder_target()->Decode(
278 decoder.host_resource(), &bitstream, callback.pp_completion_callback());
279 }
280
281 void PPB_VideoDecoder_Proxy::OnMsgAssignPictureBuffers(
282 const HostResource& decoder,
283 const std::vector<PP_PictureBuffer_Dev>& buffers) {
284 if (!ppb_video_decoder_target())
285 return;
286
287 DCHECK(!buffers.empty());
288 const PP_PictureBuffer_Dev* buffer_array = &buffers.front();
289
290 ppb_video_decoder_target()->AssignPictureBuffers(
291 decoder.host_resource(), buffers.size(), buffer_array);
292 }
293
294 void PPB_VideoDecoder_Proxy::OnMsgReusePictureBuffer(
295 const HostResource& decoder,
296 int32 picture_buffer_id) {
297 if (!ppb_video_decoder_target())
298 return;
299
300 ppb_video_decoder_target()->ReusePictureBuffer(
301 decoder.host_resource(), picture_buffer_id);
302 }
303
304 void PPB_VideoDecoder_Proxy::OnMsgFlush(const HostResource& decoder) {
305 if (!ppb_video_decoder_target())
306 return;
307
308 CompletionCallback callback = callback_factory_.NewRequiredCallback(
309 &PPB_VideoDecoder_Proxy::SendMsgFlushACKToPlugin, decoder);
310 ppb_video_decoder_target()->Flush(
311 decoder.host_resource(), callback.pp_completion_callback());
312 }
313
314 void PPB_VideoDecoder_Proxy::OnMsgReset(const HostResource& decoder) {
315 if (!ppb_video_decoder_target())
316 return;
317
318 CompletionCallback callback = callback_factory_.NewRequiredCallback(
319 &PPB_VideoDecoder_Proxy::SendMsgResetACKToPlugin, decoder);
320 ppb_video_decoder_target()->Reset(
321 decoder.host_resource(), callback.pp_completion_callback());
322 }
323
324 void PPB_VideoDecoder_Proxy::OnMsgDestroy(const HostResource& decoder) {
325 if (!ppb_video_decoder_target())
326 return;
327
328 ppb_video_decoder_target()->Destroy(decoder.host_resource());
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, result));
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, int32_t pp_error) {
351 EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder);
352 if (enter.succeeded())
353 static_cast<VideoDecoder*>(enter.object())->EndOfBitstreamACK(id, pp_error);
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(pp_error);
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(pp_error);
368 }
369
370 } // namespace proxy
371 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698