OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 platform_video_decoder_->Initialize(copied); |
Ami GONE FROM CHROMIUM
2011/06/01 15:45:37
We shouldn't be ignoring the return value here. (
polina
2011/06/01 21:45:43
Done.
| |
231 | 237 |
232 initialization_callback_ = callback; | 238 initialization_callback_ = callback; |
233 | 239 |
234 return platform_video_decoder_.get()? true : false; | 240 return PP_OK_COMPLETIONPENDING; |
235 } | 241 } |
236 | 242 |
237 bool PPB_VideoDecoder_Impl::Decode( | 243 int32_t PPB_VideoDecoder_Impl::Decode( |
238 PP_VideoBitstreamBuffer_Dev* bitstream_buffer, | 244 PP_VideoBitstreamBuffer_Dev* bitstream_buffer, |
239 PP_CompletionCallback callback) { | 245 PP_CompletionCallback callback) { |
240 if (!platform_video_decoder_.get()) | 246 if (!platform_video_decoder_.get()) |
241 return false; | 247 return PP_ERROR_BADRESOURCE; |
242 | 248 |
243 ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_Buffer_API> | 249 ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_Buffer_API> |
244 enter(bitstream_buffer->data, true); | 250 enter(bitstream_buffer->data, true); |
245 if (enter.failed()) | 251 if (enter.failed()) |
246 return false; | 252 return PP_ERROR_FAILED; |
247 | 253 |
248 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); | 254 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); |
249 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, | 255 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, |
250 buffer->shared_memory()->handle(), | 256 buffer->shared_memory()->handle(), |
251 static_cast<size_t>(buffer->size())); | 257 static_cast<size_t>(buffer->size())); |
252 | 258 |
253 // Store the callback to inform when bitstream buffer has been processed. | 259 // Store the callback to inform when bitstream buffer has been processed. |
254 // TODO(vmr): handle simultaneous decodes + callbacks. | 260 // TODO(vmr): handle simultaneous decodes + callbacks. |
255 bitstream_buffer_callback_ = callback; | 261 bitstream_buffer_callback_ = callback; |
256 | 262 |
257 return platform_video_decoder_->Decode(decode_buffer); | 263 if (platform_video_decoder_->Decode(decode_buffer)) |
264 return PP_OK_COMPLETIONPENDING; | |
265 else | |
266 return PP_ERROR_FAILED; | |
258 } | 267 } |
259 | 268 |
260 void PPB_VideoDecoder_Impl::AssignGLESBuffers( | 269 void PPB_VideoDecoder_Impl::AssignGLESBuffers( |
261 uint32_t no_of_buffers, | 270 uint32_t no_of_buffers, |
262 PP_GLESBuffer_Dev* buffers) { | 271 PP_GLESBuffer_Dev* buffers) { |
263 if (!platform_video_decoder_.get()) | 272 if (!platform_video_decoder_.get()) |
264 return; | 273 return; |
265 | 274 |
266 std::vector<media::GLESBuffer> wrapped_buffers; | 275 std::vector<media::GLESBuffer> wrapped_buffers; |
267 for (uint32 i = 0; i < no_of_buffers; i++) { | 276 for (uint32 i = 0; i < no_of_buffers; i++) { |
(...skipping 18 matching lines...) Expand all Loading... | |
286 } | 295 } |
287 platform_video_decoder_->AssignSysmemBuffers(wrapped_buffers); | 296 platform_video_decoder_->AssignSysmemBuffers(wrapped_buffers); |
288 } | 297 } |
289 | 298 |
290 void PPB_VideoDecoder_Impl::ReusePictureBuffer(int32_t picture_buffer_id) { | 299 void PPB_VideoDecoder_Impl::ReusePictureBuffer(int32_t picture_buffer_id) { |
291 if (!platform_video_decoder_.get()) | 300 if (!platform_video_decoder_.get()) |
292 return; | 301 return; |
293 platform_video_decoder_->ReusePictureBuffer(picture_buffer_id); | 302 platform_video_decoder_->ReusePictureBuffer(picture_buffer_id); |
294 } | 303 } |
295 | 304 |
296 bool PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { | 305 int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { |
297 if (!platform_video_decoder_.get()) | 306 if (!platform_video_decoder_.get()) |
298 return false; | 307 return PP_ERROR_BADRESOURCE; |
299 | 308 |
300 // Store the callback to be called when Flush() is done. | 309 // Store the callback to be called when Flush() is done. |
301 // TODO(vmr): Check for current flush/abort operations. | 310 // TODO(vmr): Check for current flush/abort operations. |
302 flush_callback_ = callback; | 311 flush_callback_ = callback; |
303 | 312 |
304 return platform_video_decoder_->Flush(); | 313 if (platform_video_decoder_->Flush()) |
314 return PP_OK_COMPLETIONPENDING; | |
315 else | |
316 return PP_ERROR_FAILED; | |
305 } | 317 } |
306 | 318 |
307 bool PPB_VideoDecoder_Impl::Abort(PP_CompletionCallback callback) { | 319 int32_t PPB_VideoDecoder_Impl::Abort(PP_CompletionCallback callback) { |
308 if (!platform_video_decoder_.get()) | 320 if (!platform_video_decoder_.get()) |
309 return false; | 321 return PP_ERROR_BADRESOURCE; |
310 | 322 |
311 // Store the callback to be called when Abort() is done. | 323 // Store the callback to be called when Abort() is done. |
312 // TODO(vmr): Check for current flush/abort operations. | 324 // TODO(vmr): Check for current flush/abort operations. |
313 abort_callback_ = callback; | 325 abort_callback_ = callback; |
314 | 326 |
315 return platform_video_decoder_->Abort(); | 327 if (platform_video_decoder_->Abort()) |
328 return PP_OK_COMPLETIONPENDING; | |
329 else | |
330 return PP_ERROR_FAILED; | |
316 } | 331 } |
317 | 332 |
318 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( | 333 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( |
319 uint32 requested_num_of_buffers, | 334 uint32 requested_num_of_buffers, |
320 const gfx::Size& dimensions, | 335 const gfx::Size& dimensions, |
321 media::VideoDecodeAccelerator::MemoryType type) { | 336 media::VideoDecodeAccelerator::MemoryType type) { |
322 if (!ppp_videodecoder_) | 337 if (!ppp_videodecoder_) |
323 return; | 338 return; |
324 | 339 |
325 // TODO(vrk): Compiler assert or use switch statement instead of making | 340 // TODO(vrk): Compiler assert or use switch statement instead of making |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
434 } | 449 } |
435 | 450 |
436 Picture::Picture(const PP_Picture_Dev& picture) | 451 Picture::Picture(const PP_Picture_Dev& picture) |
437 : picture_buffer_id_(picture.picture_buffer_id), | 452 : picture_buffer_id_(picture.picture_buffer_id), |
438 bitstream_buffer_id_(picture.bitstream_buffer_id), | 453 bitstream_buffer_id_(picture.bitstream_buffer_id), |
439 visible_size_(picture.visible_size.width, picture.visible_size.height), | 454 visible_size_(picture.visible_size.width, picture.visible_size.height), |
440 decoded_size_(picture.decoded_size.width, picture.decoded_size.height) { | 455 decoded_size_(picture.decoded_size.width, picture.decoded_size.height) { |
441 } | 456 } |
442 | 457 |
443 } // namespace media | 458 } // namespace media |
OLD | NEW |