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

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

Issue 6975053: PPAPI: Fix interface functions that take PP_CompletionCallbacks, but don't (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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 "media/video/picture.h"
(...skipping 26 matching lines...) Expand all
37 37
38 scoped_refptr<PPB_VideoDecoder_Impl> decoder( 38 scoped_refptr<PPB_VideoDecoder_Impl> decoder(
39 new PPB_VideoDecoder_Impl(instance)); 39 new PPB_VideoDecoder_Impl(instance));
40 40
41 return BoolToPPBool(decoder->GetConfigs(proto_config, 41 return BoolToPPBool(decoder->GetConfigs(proto_config,
42 matching_configs, 42 matching_configs,
43 matching_configs_size, 43 matching_configs_size,
44 num_of_matching_configs)); 44 num_of_matching_configs));
45 } 45 }
46 46
47 PP_Resource Create(PP_Instance instance_id, 47 PP_Resource Create(PP_Instance instance_id) {
48 PP_VideoConfigElement* decoder_config,
49 PP_CompletionCallback callback) {
50 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); 48 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
51 if (!instance) 49 if (!instance)
52 return 0; 50 return 0;
53 51
52 PPB_VideoDecoder_Impl* decoder = new PPB_VideoDecoder_Impl(instance);
53 return decoder->GetReference();
54 }
55
56 int32_t Init(PP_Resource video_decoder,
57 PP_VideoConfigElement* decoder_config,
58 struct PP_CompletionCallback callback) {
54 scoped_refptr<PPB_VideoDecoder_Impl> decoder( 59 scoped_refptr<PPB_VideoDecoder_Impl> decoder(
55 new PPB_VideoDecoder_Impl(instance)); 60 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder));
61 if (!decoder)
62 return PP_ERROR_BADRESOURCE;
56 63
57 if (!decoder->Init( 64 return decoder->Init(decoder_config, callback);
58 const_cast<PP_VideoConfigElement*>(decoder_config), callback)) {
59 return 0;
60 }
61
62 return decoder->GetReference();
63 } 65 }
64 66
65 PP_Bool IsVideoDecoder(PP_Resource resource) { 67 PP_Bool IsVideoDecoder(PP_Resource resource) {
66 return BoolToPPBool(!!Resource::GetAs<PPB_VideoDecoder_Impl>(resource)); 68 return BoolToPPBool(!!Resource::GetAs<PPB_VideoDecoder_Impl>(resource));
67 } 69 }
68 70
69 PP_Bool Decode(PP_Resource decoder_id, 71 int32_t Decode(PP_Resource decoder_id,
70 PP_VideoBitstreamBuffer_Dev* bitstream_buffer, 72 PP_VideoBitstreamBuffer_Dev* bitstream_buffer,
71 PP_CompletionCallback callback) { 73 PP_CompletionCallback callback) {
72 scoped_refptr<PPB_VideoDecoder_Impl> decoder( 74 scoped_refptr<PPB_VideoDecoder_Impl> decoder(
73 Resource::GetAs<PPB_VideoDecoder_Impl>(decoder_id)); 75 Resource::GetAs<PPB_VideoDecoder_Impl>(decoder_id));
74 if (!decoder) 76 if (!decoder)
75 return PP_FALSE; 77 return PP_ERROR_BADRESOURCE;
76 78
77 return BoolToPPBool(decoder->Decode(bitstream_buffer, callback)); 79 return decoder->Decode(bitstream_buffer, callback);
78 } 80 }
79 81
80 void AssignGLESBuffers(PP_Resource video_decoder, 82 void AssignGLESBuffers(PP_Resource video_decoder,
81 uint32_t no_of_buffers, 83 uint32_t no_of_buffers,
82 PP_GLESBuffer_Dev* buffers) { 84 PP_GLESBuffer_Dev* buffers) {
83 scoped_refptr<PPB_VideoDecoder_Impl> decoder( 85 scoped_refptr<PPB_VideoDecoder_Impl> decoder(
84 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); 86 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder));
85 if (!decoder) 87 if (!decoder)
86 return; 88 return;
87 89
(...skipping 13 matching lines...) Expand all
101 103
102 void ReusePictureBuffer(PP_Resource video_decoder, int32_t picture_buffer_id) { 104 void ReusePictureBuffer(PP_Resource video_decoder, int32_t picture_buffer_id) {
103 scoped_refptr<PPB_VideoDecoder_Impl> decoder( 105 scoped_refptr<PPB_VideoDecoder_Impl> decoder(
104 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); 106 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder));
105 if (!decoder) 107 if (!decoder)
106 return; 108 return;
107 109
108 decoder->ReusePictureBuffer(picture_buffer_id); 110 decoder->ReusePictureBuffer(picture_buffer_id);
109 } 111 }
110 112
111 PP_Bool Flush(PP_Resource video_decoder, PP_CompletionCallback callback) { 113 int32_t Flush(PP_Resource video_decoder, PP_CompletionCallback callback) {
112 scoped_refptr<PPB_VideoDecoder_Impl> decoder( 114 scoped_refptr<PPB_VideoDecoder_Impl> decoder(
113 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); 115 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder));
114 if (!decoder) 116 if (!decoder)
115 return PP_FALSE; 117 return PP_ERROR_BADRESOURCE;
116 118
117 return BoolToPPBool(decoder->Flush(callback)); 119 return decoder->Flush(callback);
118 } 120 }
119 121
120 PP_Bool Abort(PP_Resource video_decoder, 122 int32_t Abort(PP_Resource video_decoder,
121 PP_CompletionCallback callback) { 123 PP_CompletionCallback callback) {
122 scoped_refptr<PPB_VideoDecoder_Impl> decoder( 124 scoped_refptr<PPB_VideoDecoder_Impl> decoder(
123 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); 125 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder));
124 if (!decoder) 126 if (!decoder)
125 return PP_FALSE; 127 return PP_ERROR_BADRESOURCE;
126 128
127 return BoolToPPBool(decoder->Abort(callback)); 129 return decoder->Abort(callback);
128 } 130 }
129 131
130 const PPB_VideoDecoder_Dev ppb_videodecoder = { 132 const PPB_VideoDecoder_Dev ppb_videodecoder = {
131 &GetConfigs, 133 &GetConfigs,
132 &Create, 134 &Create,
135 &Init,
133 &IsVideoDecoder, 136 &IsVideoDecoder,
134 &Decode, 137 &Decode,
135 &AssignGLESBuffers, 138 &AssignGLESBuffers,
136 &AssignSysmemBuffers, 139 &AssignSysmemBuffers,
137 &ReusePictureBuffer, 140 &ReusePictureBuffer,
138 &Flush, 141 &Flush,
139 &Abort, 142 &Abort,
140 }; 143 };
141 144
142 // Utility methods to convert data to and from the ppapi C-types and their 145 // Utility methods to convert data to and from the ppapi C-types and their
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 platform_video_decoder_->GetConfigs(requested, &matched); 212 platform_video_decoder_->GetConfigs(requested, &matched);
210 213
211 uint32 i; 214 uint32 i;
212 for (i = 0; i < matched.size() && i < matching_configs_size; i++) 215 for (i = 0; i < matched.size() && i < matching_configs_size; i++)
213 matching_configs[i] = matched[i]; 216 matching_configs[i] = matched[i];
214 *num_of_matching_configs = i; 217 *num_of_matching_configs = i;
215 218
216 return true; 219 return true;
217 } 220 }
218 221
219 bool PPB_VideoDecoder_Impl::Init(PP_VideoConfigElement* decoder_config, 222 int32_t PPB_VideoDecoder_Impl::Init(PP_VideoConfigElement* decoder_config,
220 PP_CompletionCallback callback) { 223 PP_CompletionCallback callback) {
221 if (!instance()) 224 if (!callback.func)
222 return false; 225 return PP_ERROR_BADARGUMENT;
223 226
224 platform_video_decoder_.reset( 227 platform_video_decoder_.reset(
225 instance()->delegate()->CreateVideoDecoder(this)); 228 instance()->delegate()->CreateVideoDecoder(this));
226 229
230 if (!platform_video_decoder_.get())
231 return PP_ERROR_FAILED;
232
227 std::vector<uint32> copied; 233 std::vector<uint32> copied;
228 // TODO(vrk): Validate configs before copy. 234 // TODO(vrk): Validate configs before copy.
229 CopyToConfigList(decoder_config, &copied); 235 CopyToConfigList(decoder_config, &copied);
230 platform_video_decoder_->Initialize(copied); 236 if (platform_video_decoder_->Initialize(copied)) {
231 237 initialization_callback_ = callback;
232 initialization_callback_ = callback; 238 return PP_OK_COMPLETIONPENDING;
233 239 } else {
234 return platform_video_decoder_.get()? true : false; 240 return PP_ERROR_FAILED;
241 }
235 } 242 }
236 243
237 bool PPB_VideoDecoder_Impl::Decode( 244 int32_t PPB_VideoDecoder_Impl::Decode(
238 PP_VideoBitstreamBuffer_Dev* bitstream_buffer, 245 PP_VideoBitstreamBuffer_Dev* bitstream_buffer,
239 PP_CompletionCallback callback) { 246 PP_CompletionCallback callback) {
240 if (!platform_video_decoder_.get()) 247 if (!platform_video_decoder_.get())
241 return false; 248 return PP_ERROR_BADRESOURCE;
242 249
243 ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_Buffer_API> 250 ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_Buffer_API>
244 enter(bitstream_buffer->data, true); 251 enter(bitstream_buffer->data, true);
245 if (enter.failed()) 252 if (enter.failed())
246 return false; 253 return PP_ERROR_FAILED;
247 254
248 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); 255 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object());
249 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, 256 media::BitstreamBuffer decode_buffer(bitstream_buffer->id,
250 buffer->shared_memory()->handle(), 257 buffer->shared_memory()->handle(),
251 static_cast<size_t>(buffer->size())); 258 static_cast<size_t>(buffer->size()));
252 259
253 // Store the callback to inform when bitstream buffer has been processed. 260 // Store the callback to inform when bitstream buffer has been processed.
254 // TODO(vmr): handle simultaneous decodes + callbacks. 261 // TODO(vmr): handle simultaneous decodes + callbacks.
255 bitstream_buffer_callback_ = callback; 262 bitstream_buffer_callback_ = callback;
256 263
257 return platform_video_decoder_->Decode(decode_buffer); 264 if (platform_video_decoder_->Decode(decode_buffer))
265 return PP_OK_COMPLETIONPENDING;
266 else
267 return PP_ERROR_FAILED;
258 } 268 }
259 269
260 void PPB_VideoDecoder_Impl::AssignGLESBuffers( 270 void PPB_VideoDecoder_Impl::AssignGLESBuffers(
261 uint32_t no_of_buffers, 271 uint32_t no_of_buffers,
262 PP_GLESBuffer_Dev* buffers) { 272 PP_GLESBuffer_Dev* buffers) {
263 if (!platform_video_decoder_.get()) 273 if (!platform_video_decoder_.get())
264 return; 274 return;
265 275
266 std::vector<media::GLESBuffer> wrapped_buffers; 276 std::vector<media::GLESBuffer> wrapped_buffers;
267 for (uint32 i = 0; i < no_of_buffers; i++) { 277 for (uint32 i = 0; i < no_of_buffers; i++) {
(...skipping 18 matching lines...) Expand all
286 } 296 }
287 platform_video_decoder_->AssignSysmemBuffers(wrapped_buffers); 297 platform_video_decoder_->AssignSysmemBuffers(wrapped_buffers);
288 } 298 }
289 299
290 void PPB_VideoDecoder_Impl::ReusePictureBuffer(int32_t picture_buffer_id) { 300 void PPB_VideoDecoder_Impl::ReusePictureBuffer(int32_t picture_buffer_id) {
291 if (!platform_video_decoder_.get()) 301 if (!platform_video_decoder_.get())
292 return; 302 return;
293 platform_video_decoder_->ReusePictureBuffer(picture_buffer_id); 303 platform_video_decoder_->ReusePictureBuffer(picture_buffer_id);
294 } 304 }
295 305
296 bool PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { 306 int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) {
297 if (!platform_video_decoder_.get()) 307 if (!platform_video_decoder_.get())
298 return false; 308 return PP_ERROR_BADRESOURCE;
299 309
300 // Store the callback to be called when Flush() is done. 310 // Store the callback to be called when Flush() is done.
301 // TODO(vmr): Check for current flush/abort operations. 311 // TODO(vmr): Check for current flush/abort operations.
302 flush_callback_ = callback; 312 flush_callback_ = callback;
303 313
304 return platform_video_decoder_->Flush(); 314 if (platform_video_decoder_->Flush())
315 return PP_OK_COMPLETIONPENDING;
316 else
317 return PP_ERROR_FAILED;
305 } 318 }
306 319
307 bool PPB_VideoDecoder_Impl::Abort(PP_CompletionCallback callback) { 320 int32_t PPB_VideoDecoder_Impl::Abort(PP_CompletionCallback callback) {
308 if (!platform_video_decoder_.get()) 321 if (!platform_video_decoder_.get())
309 return false; 322 return PP_ERROR_BADRESOURCE;
310 323
311 // Store the callback to be called when Abort() is done. 324 // Store the callback to be called when Abort() is done.
312 // TODO(vmr): Check for current flush/abort operations. 325 // TODO(vmr): Check for current flush/abort operations.
313 abort_callback_ = callback; 326 abort_callback_ = callback;
314 327
315 return platform_video_decoder_->Abort(); 328 if (platform_video_decoder_->Abort())
329 return PP_OK_COMPLETIONPENDING;
330 else
331 return PP_ERROR_FAILED;
316 } 332 }
317 333
318 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( 334 void PPB_VideoDecoder_Impl::ProvidePictureBuffers(
319 uint32 requested_num_of_buffers, 335 uint32 requested_num_of_buffers,
320 const gfx::Size& dimensions, 336 const gfx::Size& dimensions,
321 media::VideoDecodeAccelerator::MemoryType type) { 337 media::VideoDecodeAccelerator::MemoryType type) {
322 if (!ppp_videodecoder_) 338 if (!ppp_videodecoder_)
323 return; 339 return;
324 340
325 // TODO(vrk): Compiler assert or use switch statement instead of making 341 // TODO(vrk): Compiler assert or use switch statement instead of making
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } 450 }
435 451
436 Picture::Picture(const PP_Picture_Dev& picture) 452 Picture::Picture(const PP_Picture_Dev& picture)
437 : picture_buffer_id_(picture.picture_buffer_id), 453 : picture_buffer_id_(picture.picture_buffer_id),
438 bitstream_buffer_id_(picture.bitstream_buffer_id), 454 bitstream_buffer_id_(picture.bitstream_buffer_id),
439 visible_size_(picture.visible_size.width, picture.visible_size.height), 455 visible_size_(picture.visible_size.width, picture.visible_size.height),
440 decoded_size_(picture.decoded_size.width, picture.decoded_size.height) { 456 decoded_size_(picture.decoded_size.width, picture.decoded_size.height) {
441 } 457 }
442 458
443 } // namespace media 459 } // namespace media
OLDNEW
« ppapi/tests/test_video_decoder.cc ('K') | « webkit/plugins/ppapi/ppb_video_decoder_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698