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