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

Side by Side Diff: webkit/plugins/ppapi/ppb_video_decoder_impl.cc

Issue 6901036: Update VideoDecode PPAPI structs to be consistent with media structures, part 1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/plugins/ppapi/ppb_video_decoder_impl.h" 5 #include "webkit/plugins/ppapi/ppb_video_decoder_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "media/video/picture.h"
10 #include "ppapi/c/dev/pp_video_dev.h" 11 #include "ppapi/c/dev/pp_video_dev.h"
11 #include "ppapi/c/dev/ppb_video_decoder_dev.h" 12 #include "ppapi/c/dev/ppb_video_decoder_dev.h"
13 #include "ppapi/c/dev/ppp_video_decoder_dev.h"
12 #include "ppapi/c/pp_completion_callback.h" 14 #include "ppapi/c/pp_completion_callback.h"
13 #include "ppapi/c/pp_errors.h" 15 #include "ppapi/c/pp_errors.h"
14 #include "webkit/plugins/ppapi/common.h" 16 #include "webkit/plugins/ppapi/common.h"
17 #include "webkit/plugins/ppapi/plugin_module.h"
15 #include "webkit/plugins/ppapi/var.h" 18 #include "webkit/plugins/ppapi/var.h"
scherkus (not reviewing) 2011/04/26 22:36:34 nit: include order
vrk (LEFT CHROMIUM) 2011/04/27 00:40:33 Done.
16 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
20 #include "webkit/plugins/ppapi/ppb_buffer_impl.h"
17 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" 21 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
18 #include "webkit/plugins/ppapi/resource_tracker.h" 22 #include "webkit/plugins/ppapi/resource_tracker.h"
19 23
20 namespace webkit { 24 namespace webkit {
21 namespace ppapi { 25 namespace ppapi {
22 26
23 namespace { 27 namespace {
24 28
25 PP_Bool GetConfigs(PP_Instance instance_id, 29 PP_Bool GetConfigs(PP_Instance instance_id,
26 PP_VideoDecoderConfig_Dev* proto_config, 30 PP_VideoDecoderConfig_Dev* proto_config,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 scoped_refptr<PPB_VideoDecoder_Impl> decoder( 69 scoped_refptr<PPB_VideoDecoder_Impl> decoder(
66 Resource::GetAs<PPB_VideoDecoder_Impl>(decoder_id)); 70 Resource::GetAs<PPB_VideoDecoder_Impl>(decoder_id));
67 if (!decoder) 71 if (!decoder)
68 return PP_FALSE; 72 return PP_FALSE;
69 73
70 return BoolToPPBool(decoder->Decode(bitstream_buffer, callback)); 74 return BoolToPPBool(decoder->Decode(bitstream_buffer, callback));
71 } 75 }
72 76
73 void AssignPictureBuffer(PP_Resource video_decoder, 77 void AssignPictureBuffer(PP_Resource video_decoder,
74 uint32_t no_of_buffers, 78 uint32_t no_of_buffers,
75 union PP_PictureData_Dev* picture_buffer) { 79 struct PP_PictureBuffer_Dev* picture_buffer) {
76 scoped_refptr<PPB_VideoDecoder_Impl> decoder( 80 scoped_refptr<PPB_VideoDecoder_Impl> decoder(
77 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); 81 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder));
78 if (!decoder) 82 if (!decoder)
79 return; 83 return;
80 84
81 decoder->AssignPictureBuffer(no_of_buffers, picture_buffer); 85 decoder->AssignPictureBuffer(no_of_buffers, picture_buffer);
82 } 86 }
83 87
84 void ReusePictureBuffer(PP_Resource video_decoder, 88 void ReusePictureBuffer(PP_Resource video_decoder,
85 union PP_PictureData_Dev* picture_buffer) { 89 int32_t picture_buffer_id) {
86 scoped_refptr<PPB_VideoDecoder_Impl> decoder( 90 scoped_refptr<PPB_VideoDecoder_Impl> decoder(
87 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); 91 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder));
88 if (!decoder) 92 if (!decoder)
89 return; 93 return;
90 94
91 decoder->ReusePictureBuffer(picture_buffer); 95 decoder->ReusePictureBuffer(picture_buffer_id);
92 } 96 }
93 97
94 PP_Bool Flush(PP_Resource video_decoder, 98 PP_Bool Flush(PP_Resource video_decoder,
95 PP_CompletionCallback callback) { 99 PP_CompletionCallback callback) {
96 scoped_refptr<PPB_VideoDecoder_Impl> decoder( 100 scoped_refptr<PPB_VideoDecoder_Impl> decoder(
97 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); 101 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder));
98 if (!decoder) 102 if (!decoder)
99 return PP_FALSE; 103 return PP_FALSE;
100 104
101 return BoolToPPBool(decoder->Flush(callback)); 105 return BoolToPPBool(decoder->Flush(callback));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 NOTIMPLEMENTED(); 163 NOTIMPLEMENTED();
160 164
161 return false; 165 return false;
162 } 166 }
163 167
164 bool PPB_VideoDecoder_Impl::Init(PP_VideoDecoderConfig_Dev* decoder_config) { 168 bool PPB_VideoDecoder_Impl::Init(PP_VideoDecoderConfig_Dev* decoder_config) {
165 if (!instance()) 169 if (!instance())
166 return false; 170 return false;
167 171
168 platform_video_decoder_.reset( 172 platform_video_decoder_.reset(
169 instance()->delegate()->CreateVideoDecoder(decoder_config)); 173 instance()->delegate()->CreateVideoDecoder(decoder_config, this));
170 174
171 return platform_video_decoder_.get()? true : false; 175 return platform_video_decoder_.get()? true : false;
172 } 176 }
173 177
174 bool PPB_VideoDecoder_Impl::Decode( 178 bool PPB_VideoDecoder_Impl::Decode(
175 PP_VideoBitstreamBuffer_Dev* bitstream_buffer, 179 PP_VideoBitstreamBuffer_Dev* bitstream_buffer,
176 PP_CompletionCallback callback) { 180 PP_CompletionCallback callback) {
177 if (!platform_video_decoder_.get()) 181 if (!platform_video_decoder_.get())
178 return false; 182 return false;
179 183
180 media::BitstreamBuffer* decode_buffer = NULL; 184 scoped_refptr<PPB_Buffer_Impl> pepper_buffer =
181 // TODO(vmr): Convert bitstream_buffer to BitstreamBuffer object. 185 Resource::GetAs<PPB_Buffer_Impl>(bitstream_buffer->bitstream);
182 NOTIMPLEMENTED(); 186
187 media::BitstreamBuffer* decode_buffer =
188 new media::BitstreamBuffer(pepper_buffer->mapped_buffer(),
189 bitstream_buffer->bitstream_size,
190 bitstream_buffer->user_handle);
183 191
184 // Store the callback to inform when bitstream buffer has been processed. 192 // Store the callback to inform when bitstream buffer has been processed.
185 // TODO(vmr): handle simultaneous decodes + callbacks. 193 // TODO(vmr): handle simultaneous decodes + callbacks.
186 bitstream_buffer_callback_ = callback; 194 bitstream_buffer_callback_ = callback;
187 195
188 return platform_video_decoder_->Decode( 196 return platform_video_decoder_->Decode(
189 decode_buffer, 197 decode_buffer,
190 callback_factory_.NewCallback( 198 callback_factory_.NewCallback(
191 &PPB_VideoDecoder_Impl::OnBitstreamBufferProcessed)); 199 &PPB_VideoDecoder_Impl::OnBitstreamBufferProcessed));
192 } 200 }
193 201
194 void PPB_VideoDecoder_Impl::AssignPictureBuffer( 202 void PPB_VideoDecoder_Impl::AssignPictureBuffer(
195 uint32_t no_of_picture_buffers, 203 uint32_t no_of_picture_buffers,
196 PP_PictureData_Dev* picture_buffers) { 204 PP_PictureBuffer_Dev* picture_buffers) {
197 if (!platform_video_decoder_.get()) 205 if (!platform_video_decoder_.get())
198 return; 206 return;
199 207
200 // TODO(vmr): Map PP_PictureData_Dev into PictureBuffer object. 208 std::vector<media::VideoDecodeAccelerator::PictureBuffer*> wrapped_buffers;
201 NOTIMPLEMENTED(); 209 for (uint i = 0; i < no_of_picture_buffers; i++) {
202 210 struct PP_PictureBuffer_Dev in_buf = picture_buffers[i];
203 media::VideoDecodeAccelerator::PictureBuffer* buffer = NULL; 211 media::VideoDecodeAccelerator::PictureBuffer* buffer =
204 platform_video_decoder_->ReusePictureBuffer(buffer); 212 CreateMediaPictureBuffer(in_buf);
213 wrapped_buffers.push_back(buffer);
214 platform_video_decoder_->AssignPictureBuffer(wrapped_buffers);
215 }
205 } 216 }
206 217
207 void PPB_VideoDecoder_Impl::ReusePictureBuffer( 218 void PPB_VideoDecoder_Impl::ReusePictureBuffer(int32_t picture_buffer_id) {
208 PP_PictureData_Dev* picture_buffer) {
209 if (!platform_video_decoder_.get()) 219 if (!platform_video_decoder_.get())
210 return; 220 return;
211 221 platform_video_decoder_->ReusePictureBuffer(picture_buffer_id);
212 // TODO(vmr): Map PP_PictureData_Dev into PictureBuffer object.
213 NOTIMPLEMENTED();
214
215 media::VideoDecodeAccelerator::PictureBuffer* buffer = NULL;
216 platform_video_decoder_->ReusePictureBuffer(buffer);
217 } 222 }
218 223
219 bool PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { 224 bool PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) {
220 if (!platform_video_decoder_.get()) 225 if (!platform_video_decoder_.get())
221 return false; 226 return false;
222 227
223 // Store the callback to be called when Flush() is done. 228 // Store the callback to be called when Flush() is done.
224 // TODO(vmr): Check for current flush/abort operations. 229 // TODO(vmr): Check for current flush/abort operations.
225 flush_callback_ = callback; 230 flush_callback_ = callback;
226 231
(...skipping 11 matching lines...) Expand all
238 abort_callback_ = callback; 243 abort_callback_ = callback;
239 244
240 return platform_video_decoder_->Abort( 245 return platform_video_decoder_->Abort(
241 callback_factory_.NewCallback( 246 callback_factory_.NewCallback(
242 &PPB_VideoDecoder_Impl::OnAbortComplete)); 247 &PPB_VideoDecoder_Impl::OnAbortComplete));
243 } 248 }
244 249
245 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( 250 void PPB_VideoDecoder_Impl::ProvidePictureBuffers(
246 uint32_t requested_num_of_buffers, 251 uint32_t requested_num_of_buffers,
247 const std::vector<uint32_t>& buffer_properties) { 252 const std::vector<uint32_t>& buffer_properties) {
248 // TODO(vmr): Implement. 253 // TODO(vrk): The structures to represent buffer properties in media::
254 // versus ppapi:: do not match. These need to be consistent before
255 // this can be implemented.
249 NOTIMPLEMENTED(); 256 NOTIMPLEMENTED();
250 } 257 }
251 258
252 void PPB_VideoDecoder_Impl::PictureReady( 259 void PPB_VideoDecoder_Impl::PictureReady(
253 media::VideoDecodeAccelerator::Picture* picture) { 260 media::VideoDecodeAccelerator::Picture& picture) {
254 // TODO(vmr): Implement. 261 const PPP_VideoDecoder_Dev* ppp_videodecoder =
Ami GONE FROM CHROMIUM 2011/04/26 23:01:57 worth doing this once in the ctor to avoid this 3-
vrk (LEFT CHROMIUM) 2011/04/27 00:40:33 Done.
255 NOTIMPLEMENTED(); 262 static_cast<const PPP_VideoDecoder_Dev*>(instance()->module()->
256 263 GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE));
257 // Convert the picture. 264 ScopedResourceId resource(this);
258 // Get plugin's PPP interface function pointers. 265 struct PP_Picture_Dev* out_pic = CreatePictureDev(picture);
Ami GONE FROM CHROMIUM 2011/04/26 23:01:57 I think this leaks all out_pics? To make the curre
vrk (LEFT CHROMIUM) 2011/04/27 00:40:33 Yeah, that sounds right. Hmm... not quite sure how
259 // PPP_VideoDecoder* ppp_videodecoder; 266 ppp_videodecoder->PictureReady(resource.id, out_pic);
260 // Call ProvidePictureBuffers function pointer and return.
261 // ppp_videodecoder->PictureReady(resource_decoder, picture,
262 // pic_buffer_used_again);
263 } 267 }
264 268
265 void PPB_VideoDecoder_Impl::DismissPictureBuffer( 269 void PPB_VideoDecoder_Impl::DismissPictureBuffer(int32 picture_buffer_id) {
266 media::VideoDecodeAccelerator::PictureBuffer* picture_buffer) { 270 const PPP_VideoDecoder_Dev* ppp_videodecoder =
267 // TODO(vmr): Implement. 271 static_cast<const PPP_VideoDecoder_Dev*>(instance()->module()->
268 NOTIMPLEMENTED(); 272 GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE));
273 ScopedResourceId resource(this);
274 ppp_videodecoder->DismissPictureBuffer(resource.id, picture_buffer_id);
269 } 275 }
270 276
271 void PPB_VideoDecoder_Impl::NotifyEndOfStream() { 277 void PPB_VideoDecoder_Impl::NotifyEndOfStream() {
272 // TODO(vmr): Implement. 278 const PPP_VideoDecoder_Dev* ppp_videodecoder =
273 NOTIMPLEMENTED(); 279 static_cast<const PPP_VideoDecoder_Dev*>(instance()->module()->
274 280 GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE));
275 // Get decoder's resource handle. 281 ScopedResourceId resource(this);
276 // PP_Resource resource_decoder; 282 ppp_videodecoder->EndOfStream(resource.id);
277 // Get plugin's PPP interface function pointers.
278 // PPP_VideoDecoder* ppp_videodecoder;
279 // Call EndOfStream function pointer and return.
280 // ppp_videodecoder->EndOfStream(resource_decoder);
281 } 283 }
282 284
283 void PPB_VideoDecoder_Impl::NotifyError( 285 void PPB_VideoDecoder_Impl::NotifyError(
284 media::VideoDecodeAccelerator::Error error) { 286 media::VideoDecodeAccelerator::Error error) {
285 // TODO(vmr): Implement. 287 // TODO(vmr): Implement.
286 NOTIMPLEMENTED(); 288 NOTIMPLEMENTED();
287 289
288 // Get decoder's resource handle. 290 // Get decoder's resource handle.
289 // PP_Resource resource_decoder; 291 // PP_Resource resource_decoder;
290 // Get plugin's PPP interface function pointers. 292 // Get plugin's PPP interface function pointers.
291 // PPP_VideoDecoder* ppp_videodecoder; 293 // PPP_VideoDecoder* ppp_videodecoder;
292 // Call NotifyError function pointer. 294 // Call NotifyError function pointer.
293 // ppp_videodecoder->NotifyError(error, error_data, data_size); 295 // ppp_videodecoder->NotifyError(error, error_data, data_size);
294 } 296 }
295 297
298 media::VideoDecodeAccelerator::PictureBuffer*
299 PPB_VideoDecoder_Impl::CreateMediaPictureBuffer(
300 struct PP_PictureBuffer_Dev& input) {
301
302 gfx::Size size(input.width, input.height);
303
304 std::vector<media::PictureBuffer::DataPlaneHandle> data_plane_handles;
305 media::PictureBuffer::DataPlaneHandle data_plane;
306 media::PictureBuffer::MemoryType memory_type;
307
308 if (input.storage_type == PP_PICTUREBUFFERTYPE_SYSTEM) {
scherkus (not reviewing) 2011/04/26 22:36:34 nit: two spaces should be one
Ami GONE FROM CHROMIUM 2011/04/26 23:01:57 extra space in there, but maybe use a switch inste
vrk (LEFT CHROMIUM) 2011/04/27 00:40:33 Done.
309 memory_type = media::PictureBuffer::PICTUREBUFFER_MEMORYTYPE_SYSTEM;
310 scoped_refptr<PPB_Buffer_Impl> pepper_buffer =
311 Resource::GetAs<PPB_Buffer_Impl>(input.storage.sysmem);
312 assert(pepper_buffer->is_mapped());
313 data_plane.sysmem = static_cast<void*>(pepper_buffer->mapped_buffer());
314 } else if (input.storage_type == PP_PICTUREBUFFERTYPE_SYSTEM) {
315 memory_type = media::PictureBuffer::PICTUREBUFFER_MEMORYTYPE_GL_TEXTURE;
316 data_plane.gles2_texture.texture_id =
317 input.storage.gles2_texture.texture_id;
318 data_plane.gles2_texture.context_id = input.storage.gles2_texture.context;
319 } else {
320 // Storage type unrecognized.
321 NOTREACHED();
scherkus (not reviewing) 2011/04/26 22:36:34 warning: on release builds this will be optimized
vrk (LEFT CHROMIUM) 2011/04/27 00:40:33 For now, returning NULL and not adding it to the p
322 }
323 data_plane_handles.push_back(data_plane);
324
325 media::PictureBuffer* buffer =
326 new media::PictureBuffer(input.id, size, memory_type, data_plane_handles);
327
328 return buffer;
329 }
330
331 media::VideoDecodeAccelerator::Picture*
332 PPB_VideoDecoder_Impl::CreateMediaPicture(struct PP_Picture_Dev& input) {
333 gfx::Size visible_size(input.visible_width, input.visible_height);
334 gfx::Size decoded_size(input.decoded_width, input.decoded_height);
335 media::Picture* picture =
336 new media::Picture(input.picture_buffer_id, decoded_size,
337 visible_size, input.bitstream_user_handle);
338 return picture;
339 }
340
341 struct PP_Picture_Dev* PPB_VideoDecoder_Impl::CreatePictureDev(
342 media::VideoDecodeAccelerator::Picture& input) {
343 struct PP_Picture_Dev* picture = (struct PP_Picture_Dev*)
344 malloc(sizeof(struct PP_Picture_Dev));
scherkus (not reviewing) 2011/04/26 22:36:34 not a pepper master but I'm not seeing any other p
vrk (LEFT CHROMIUM) 2011/04/27 00:40:33 Yeah I wasn't sure on this case. Again, since I'm
345 picture->picture_buffer_id = input.GetId();
346 picture->bitstream_user_handle = input.GetUserHandle();
347 picture->visible_width = input.GetVisibleSize().width();
348 picture->visible_height = input.GetVisibleSize().height();
349 picture->decoded_width = input.GetDecodedSize().width();
350 picture->decoded_height = input.GetDecodedSize().height();
351 return picture;
352 }
353
296 void PPB_VideoDecoder_Impl::OnAbortComplete() { 354 void PPB_VideoDecoder_Impl::OnAbortComplete() {
297 if (abort_callback_.func == NULL) 355 if (abort_callback_.func == NULL)
298 return; 356 return;
299 357
300 // Call the callback that was stored to be called when Abort is done. 358 // Call the callback that was stored to be called when Abort is done.
301 PP_CompletionCallback callback = PP_BlockUntilComplete(); 359 PP_CompletionCallback callback = PP_BlockUntilComplete();
302 std::swap(callback, abort_callback_); 360 std::swap(callback, abort_callback_);
303 PP_RunCompletionCallback(&callback, PP_OK); 361 PP_RunCompletionCallback(&callback, PP_OK);
304 } 362 }
305 363
306 void PPB_VideoDecoder_Impl::OnBitstreamBufferProcessed() { 364 void PPB_VideoDecoder_Impl::OnBitstreamBufferProcessed() {
307 if (bitstream_buffer_callback_.func == NULL) 365 if (bitstream_buffer_callback_.func == NULL)
308 return; 366 return;
309 367
368 const PPP_VideoDecoder_Dev* ppp_videodecoder =
369 static_cast<const PPP_VideoDecoder_Dev*>(instance()->module()->
370 GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE));
371
372 ScopedResourceId resource(this);
373 // TODO: Does this really need to be a ptr?
scherkus (not reviewing) 2011/04/26 22:36:34 todo for who?
vrk (LEFT CHROMIUM) 2011/04/27 00:40:33 Whoops, this whole block of added code doesn't mak
374 PP_Picture_Dev decoded_picture;
375 ppp_videodecoder->PictureReady(resource.id, &decoded_picture);
376
310 // Call the callback that was stored to be called when bitstream was sent for 377 // Call the callback that was stored to be called when bitstream was sent for
311 // decoding. 378 // decoding.
312 PP_CompletionCallback callback = PP_BlockUntilComplete(); 379 PP_CompletionCallback callback = PP_BlockUntilComplete();
313 std::swap(callback, bitstream_buffer_callback_); 380 std::swap(callback, bitstream_buffer_callback_);
314 PP_RunCompletionCallback(&callback, PP_OK); 381 PP_RunCompletionCallback(&callback, PP_OK);
315 } 382 }
316 383
317 void PPB_VideoDecoder_Impl::OnFlushComplete() { 384 void PPB_VideoDecoder_Impl::OnFlushComplete() {
318 if (flush_callback_.func == NULL) 385 if (flush_callback_.func == NULL)
319 return; 386 return;
320 387
321 // Call the callback that was stored to be called when Flush is done. 388 // Call the callback that was stored to be called when Flush is done.
322 PP_CompletionCallback callback = PP_BlockUntilComplete(); 389 PP_CompletionCallback callback = PP_BlockUntilComplete();
323 std::swap(callback, flush_callback_); 390 std::swap(callback, flush_callback_);
324 PP_RunCompletionCallback(&callback, PP_OK); 391 PP_RunCompletionCallback(&callback, PP_OK);
325 } 392 }
326 393
327 } // namespace ppapi 394 } // namespace ppapi
328 } // namespace webkit 395 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698