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 const 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 Initialize(PP_Resource video_decoder, |
| 57 const 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->Initialize(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 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, | 72 const 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 const PP_GLESBuffer_Dev* buffers) { | 84 const 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 &Initialize, |
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(const PP_VideoConfigElement* decoder_config, | 222 int32_t PPB_VideoDecoder_Impl::Initialize( |
220 PP_CompletionCallback callback) { | 223 const PP_VideoConfigElement* decoder_config, |
| 224 PP_CompletionCallback callback) { |
| 225 if (!callback.func) |
| 226 return PP_ERROR_BADARGUMENT; |
221 if (!instance()) | 227 if (!instance()) |
222 return false; | 228 return PP_ERROR_FAILED; |
223 | 229 |
224 platform_video_decoder_.reset( | 230 platform_video_decoder_.reset( |
225 instance()->delegate()->CreateVideoDecoder(this)); | 231 instance()->delegate()->CreateVideoDecoder(this)); |
226 | 232 |
| 233 if (!platform_video_decoder_.get()) |
| 234 return PP_ERROR_FAILED; |
| 235 |
227 std::vector<uint32> copied; | 236 std::vector<uint32> copied; |
228 // TODO(vrk): Validate configs before copy. | 237 // TODO(vrk): Validate configs before copy. |
229 CopyToConfigList(decoder_config, &copied); | 238 CopyToConfigList(decoder_config, &copied); |
230 platform_video_decoder_->Initialize(copied); | 239 if (platform_video_decoder_->Initialize(copied)) { |
231 | 240 initialization_callback_ = callback; |
232 initialization_callback_ = callback; | 241 return PP_OK_COMPLETIONPENDING; |
233 | 242 } else { |
234 return platform_video_decoder_.get()? true : false; | 243 return PP_ERROR_FAILED; |
| 244 } |
235 } | 245 } |
236 | 246 |
237 bool PPB_VideoDecoder_Impl::Decode( | 247 int32_t PPB_VideoDecoder_Impl::Decode( |
238 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, | 248 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, |
239 PP_CompletionCallback callback) { | 249 PP_CompletionCallback callback) { |
240 if (!platform_video_decoder_.get()) | 250 if (!platform_video_decoder_.get()) |
241 return false; | 251 return PP_ERROR_BADRESOURCE; |
242 | 252 |
243 ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_Buffer_API> | 253 ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_Buffer_API> |
244 enter(bitstream_buffer->data, true); | 254 enter(bitstream_buffer->data, true); |
245 if (enter.failed()) | 255 if (enter.failed()) |
246 return false; | 256 return PP_ERROR_FAILED; |
247 | 257 |
248 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); | 258 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); |
249 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, | 259 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, |
250 buffer->shared_memory()->handle(), | 260 buffer->shared_memory()->handle(), |
251 static_cast<size_t>(buffer->size())); | 261 static_cast<size_t>(buffer->size())); |
252 | 262 |
253 // Store the callback to inform when bitstream buffer has been processed. | 263 // Store the callback to inform when bitstream buffer has been processed. |
254 // TODO(vmr): handle simultaneous decodes + callbacks. | 264 // TODO(vmr): handle simultaneous decodes + callbacks. |
255 bitstream_buffer_callback_ = callback; | 265 bitstream_buffer_callback_ = callback; |
256 | 266 |
257 return platform_video_decoder_->Decode(decode_buffer); | 267 if (platform_video_decoder_->Decode(decode_buffer)) |
| 268 return PP_OK_COMPLETIONPENDING; |
| 269 else |
| 270 return PP_ERROR_FAILED; |
258 } | 271 } |
259 | 272 |
260 void PPB_VideoDecoder_Impl::AssignGLESBuffers( | 273 void PPB_VideoDecoder_Impl::AssignGLESBuffers( |
261 uint32_t no_of_buffers, | 274 uint32_t no_of_buffers, |
262 const PP_GLESBuffer_Dev* buffers) { | 275 const PP_GLESBuffer_Dev* buffers) { |
263 if (!platform_video_decoder_.get()) | 276 if (!platform_video_decoder_.get()) |
264 return; | 277 return; |
265 | 278 |
266 std::vector<media::GLESBuffer> wrapped_buffers; | 279 std::vector<media::GLESBuffer> wrapped_buffers; |
267 for (uint32 i = 0; i < no_of_buffers; i++) { | 280 for (uint32 i = 0; i < no_of_buffers; i++) { |
(...skipping 18 matching lines...) Expand all Loading... |
286 } | 299 } |
287 platform_video_decoder_->AssignSysmemBuffers(wrapped_buffers); | 300 platform_video_decoder_->AssignSysmemBuffers(wrapped_buffers); |
288 } | 301 } |
289 | 302 |
290 void PPB_VideoDecoder_Impl::ReusePictureBuffer(int32_t picture_buffer_id) { | 303 void PPB_VideoDecoder_Impl::ReusePictureBuffer(int32_t picture_buffer_id) { |
291 if (!platform_video_decoder_.get()) | 304 if (!platform_video_decoder_.get()) |
292 return; | 305 return; |
293 platform_video_decoder_->ReusePictureBuffer(picture_buffer_id); | 306 platform_video_decoder_->ReusePictureBuffer(picture_buffer_id); |
294 } | 307 } |
295 | 308 |
296 bool PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { | 309 int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { |
297 if (!platform_video_decoder_.get()) | 310 if (!platform_video_decoder_.get()) |
298 return false; | 311 return PP_ERROR_BADRESOURCE; |
299 | 312 |
300 // Store the callback to be called when Flush() is done. | 313 // Store the callback to be called when Flush() is done. |
301 // TODO(vmr): Check for current flush/abort operations. | 314 // TODO(vmr): Check for current flush/abort operations. |
302 flush_callback_ = callback; | 315 flush_callback_ = callback; |
303 | 316 |
304 return platform_video_decoder_->Flush(); | 317 if (platform_video_decoder_->Flush()) |
| 318 return PP_OK_COMPLETIONPENDING; |
| 319 else |
| 320 return PP_ERROR_FAILED; |
305 } | 321 } |
306 | 322 |
307 bool PPB_VideoDecoder_Impl::Abort(PP_CompletionCallback callback) { | 323 int32_t PPB_VideoDecoder_Impl::Abort(PP_CompletionCallback callback) { |
308 if (!platform_video_decoder_.get()) | 324 if (!platform_video_decoder_.get()) |
309 return false; | 325 return PP_ERROR_BADRESOURCE; |
310 | 326 |
311 // Store the callback to be called when Abort() is done. | 327 // Store the callback to be called when Abort() is done. |
312 // TODO(vmr): Check for current flush/abort operations. | 328 // TODO(vmr): Check for current flush/abort operations. |
313 abort_callback_ = callback; | 329 abort_callback_ = callback; |
314 | 330 |
315 return platform_video_decoder_->Abort(); | 331 if (platform_video_decoder_->Abort()) |
| 332 return PP_OK_COMPLETIONPENDING; |
| 333 else |
| 334 return PP_ERROR_FAILED; |
316 } | 335 } |
317 | 336 |
318 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( | 337 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( |
319 uint32 requested_num_of_buffers, | 338 uint32 requested_num_of_buffers, |
320 const gfx::Size& dimensions, | 339 const gfx::Size& dimensions, |
321 media::VideoDecodeAccelerator::MemoryType type) { | 340 media::VideoDecodeAccelerator::MemoryType type) { |
322 if (!ppp_videodecoder_) | 341 if (!ppp_videodecoder_) |
323 return; | 342 return; |
324 | 343 |
325 // TODO(vrk): Compiler assert or use switch statement instead of making | 344 // 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 } | 453 } |
435 | 454 |
436 Picture::Picture(const PP_Picture_Dev& picture) | 455 Picture::Picture(const PP_Picture_Dev& picture) |
437 : picture_buffer_id_(picture.picture_buffer_id), | 456 : picture_buffer_id_(picture.picture_buffer_id), |
438 bitstream_buffer_id_(picture.bitstream_buffer_id), | 457 bitstream_buffer_id_(picture.bitstream_buffer_id), |
439 visible_size_(picture.visible_size.width, picture.visible_size.height), | 458 visible_size_(picture.visible_size.width, picture.visible_size.height), |
440 decoded_size_(picture.decoded_size.width, picture.decoded_size.height) { | 459 decoded_size_(picture.decoded_size.width, picture.decoded_size.height) { |
441 } | 460 } |
442 | 461 |
443 } // namespace media | 462 } // namespace media |
OLD | NEW |