diff options
author | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-13 18:17:30 +0000 |
---|---|---|
committer | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-13 18:17:30 +0000 |
commit | 436fd41df6378a81cbd8706eb9b1daed95cc7cab (patch) | |
tree | d40cbe4296f2b39dc9221e48a90ff7d53140003e /webkit/plugins | |
parent | 67351452e1e16cb9b01c609ce185a9e819cf2254 (diff) | |
download | chromium_src-436fd41df6378a81cbd8706eb9b1daed95cc7cab.zip chromium_src-436fd41df6378a81cbd8706eb9b1daed95cc7cab.tar.gz chromium_src-436fd41df6378a81cbd8706eb9b1daed95cc7cab.tar.bz2 |
Overhauled OmxVideoDecodeAccelerator's state machine implementation and related code.
This implementation makes explicit the transitions being effected and the states
expected to be involved in each transition, instead of the previous
implementation's use of implicit information (e.g. "we just went from Idle to
Loaded, therefore we must be Abort()'ing"). This is not only much more readable
but also enables implementation of Reset() (for Seek) and replaces Abort()
(which never had a well-defined purpose that was consistent in documentation and
implementation, nor a customer use-case).
DID some TODOs in OmxVideoDecodeAccelerator:
- Replaced error-code checking boilerplate w/ a failure-handling macro.
- Simplified the component-name-getting dance in CreateComponent().
Updated the PPAPI interface:
- Removed GetConfigs & AssignSysmemBuffers (neither of which ever came into its own)
- Replaced Abort with Reset, and added Destroy (which still nobody calls, but
that'll change shortly).
- Cleaned up the interface's documentation.
BUG=86122
TEST=OVDATest, gles2 sample plugin
Review URL: http://codereview.chromium.org/7338010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92383 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins')
-rw-r--r-- | webkit/plugins/ppapi/ppb_video_decoder_impl.cc | 152 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_video_decoder_impl.h | 16 |
2 files changed, 60 insertions, 108 deletions
diff --git a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc index f5f6126..234a906 100644 --- a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc +++ b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc @@ -32,43 +32,13 @@ using ppapi::thunk::PPB_VideoDecoder_API; namespace webkit { namespace ppapi { -namespace { - -// Utility methods to convert data to and from the ppapi C-types and their -// C++ media-namespace equivalents. -void CopyToPictureDev(const media::Picture& input, PP_Picture_Dev* output) { - DCHECK(output); - output->picture_buffer_id = input.picture_buffer_id(); - output->bitstream_buffer_id = input.bitstream_buffer_id(); - output->visible_size = - PP_MakeSize(input.visible_size().width(), input.visible_size().height()); - output->decoded_size = - PP_MakeSize(input.decoded_size().width(), input.decoded_size().height()); -} - -void CopyToConfigList( - const PP_VideoConfigElement* configs, std::vector<uint32>* output) { - DCHECK(configs); - DCHECK(output); - // TODO(vrk): This is assuming PP_VideoAttributeDictionary and - // VideoAttributeKey have identical enum values. There is no compiler - // assert to guarantee this. We either need to add such asserts or - // merge PP_VideoAttributeDictionary and VideoAttributeKey. - const PP_VideoConfigElement* current = configs; - while (*current != PP_VIDEOATTR_DICTIONARY_TERMINATOR) { - output->push_back(static_cast<uint32>(*configs)); - current++; - } -} - -} // namespace - PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PluginInstance* instance) : Resource(instance), callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), context3d_id_(0), - abort_callback_(PP_BlockUntilComplete()), - flush_callback_(PP_BlockUntilComplete()) { + destroy_callback_(PP_BlockUntilComplete()), + flush_callback_(PP_BlockUntilComplete()), + reset_callback_(PP_BlockUntilComplete()) { ppp_videodecoder_ = static_cast<const PPP_VideoDecoder_Dev*>(instance->module()-> GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); @@ -83,31 +53,6 @@ PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { return this; } -PP_Bool PPB_VideoDecoder_Impl::GetConfigs( - const PP_VideoConfigElement* requested_configs, - PP_VideoConfigElement* matching_configs, - uint32_t matching_configs_size, - uint32_t* num_of_matching_configs) { - if (!instance()) - return PP_FALSE; - if (!platform_video_decoder_.get()) - return PP_FALSE; - if (!matching_configs) - return PP_FALSE; - - std::vector<uint32> requested; - CopyToConfigList(requested_configs, &requested); - std::vector<uint32> matched; - platform_video_decoder_->GetConfigs(requested, &matched); - - uint32 i; - for (i = 0; i < matched.size() && i < matching_configs_size; i++) - matching_configs[i] = matched[i]; - *num_of_matching_configs = i; - - return PP_TRUE; -} - int32_t PPB_VideoDecoder_Impl::Initialize( PP_Resource context_id, const PP_VideoConfigElement* decoder_config, @@ -139,8 +84,19 @@ int32_t PPB_VideoDecoder_Impl::Initialize( return PP_ERROR_FAILED; std::vector<uint32> copied; - // TODO(vrk): Validate configs before copy. - CopyToConfigList(decoder_config, &copied); + // TODO(fischman,vrk): this is completely broken in that it fails to account + // for the semantic distinction between keys and values; it is certainly + // possible for a value to show up as 0, and that shouldn't terminate the + // config vector. Only a *key* of 0 should do so. + // TODO(vrk): This is assuming PP_VideoAttributeDictionary and + // VideoAttributeKey have identical enum values. There is no compiler + // assert to guarantee this. We either need to add such asserts or + // merge PP_VideoAttributeDictionary and VideoAttributeKey. + for (const PP_VideoConfigElement* current = decoder_config; + *current != PP_VIDEOATTR_DICTIONARY_TERMINATOR; ++current) { + copied.push_back(static_cast<uint32>(*current)); + } + if (platform_video_decoder_->Initialize(copied)) { initialization_callback_ = callback; return PP_OK_COMPLETIONPENDING; @@ -188,31 +144,6 @@ void PPB_VideoDecoder_Impl::AssignGLESBuffers( platform_video_decoder_->AssignGLESBuffers(wrapped_buffers); } -void PPB_VideoDecoder_Impl::AssignSysmemBuffers( - uint32_t no_of_buffers, - const PP_SysmemBuffer_Dev* buffers) { - if (!platform_video_decoder_.get()) - return; - - std::vector<media::SysmemBuffer> wrapped_buffers; - for (uint32 i = 0; i < no_of_buffers; i++) { - PP_SysmemBuffer_Dev in_buf = buffers[i]; - // TODO(brettw) we should properly handle the errors here if the buffer - // isn't a valid image rather than CHECKing. - EnterResourceNoLock<PPB_Buffer_API> enter(in_buf.data, true); - CHECK(enter.succeeded()); - webkit::ppapi::PPB_Buffer_Impl* pepper_buffer = - static_cast<webkit::ppapi::PPB_Buffer_Impl*>(enter.object()); - CHECK(pepper_buffer->IsMapped()); - media::SysmemBuffer buffer( - in_buf.info.id, - gfx::Size(in_buf.info.size.width, in_buf.info.size.height), - pepper_buffer->Map()); - wrapped_buffers.push_back(buffer); - } - platform_video_decoder_->AssignSysmemBuffers(wrapped_buffers); -} - void PPB_VideoDecoder_Impl::ReusePictureBuffer(int32_t picture_buffer_id) { if (!platform_video_decoder_.get()) return; @@ -224,22 +155,34 @@ int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { return PP_ERROR_BADRESOURCE; // Store the callback to be called when Flush() is done. - // TODO(vmr): Check for current flush/abort operations. + // TODO(fischman,vrk): consider implications of already-outstanding callback. flush_callback_ = callback; platform_video_decoder_->Flush(); return PP_OK_COMPLETIONPENDING; } -int32_t PPB_VideoDecoder_Impl::Abort(PP_CompletionCallback callback) { +int32_t PPB_VideoDecoder_Impl::Reset(PP_CompletionCallback callback) { if (!platform_video_decoder_.get()) return PP_ERROR_BADRESOURCE; - // Store the callback to be called when Abort() is done. - // TODO(vmr): Check for current flush/abort operations. - abort_callback_ = callback; + // Store the callback to be called when Reset() is done. + // TODO(fischman,vrk): consider implications of already-outstanding callback. + reset_callback_ = callback; - platform_video_decoder_->Abort(); + platform_video_decoder_->Reset(); + return PP_OK_COMPLETIONPENDING; +} + +int32_t PPB_VideoDecoder_Impl::Destroy(PP_CompletionCallback callback) { + if (!platform_video_decoder_.get()) + return PP_ERROR_BADRESOURCE; + + // Store the callback to be called when Destroy() is done. + // TODO(fischman,vrk): consider implications of already-outstanding callback. + destroy_callback_ = callback; + + platform_video_decoder_->Destroy(); return PP_OK_COMPLETIONPENDING; } @@ -266,10 +209,15 @@ void PPB_VideoDecoder_Impl::PictureReady(const media::Picture& picture) { return; ScopedResourceId resource(this); - PP_Picture_Dev out_pic; - CopyToPictureDev(picture, &out_pic); + PP_Picture_Dev output; + output.picture_buffer_id = picture.picture_buffer_id(); + output.bitstream_buffer_id = picture.bitstream_buffer_id(); + output.visible_size = PP_MakeSize(picture.visible_size().width(), + picture.visible_size().height()); + output.decoded_size = PP_MakeSize(picture.decoded_size().width(), + picture.decoded_size().height()); ppp_videodecoder_->PictureReady( - instance()->pp_instance(), resource.id, out_pic); + instance()->pp_instance(), resource.id, output); } void PPB_VideoDecoder_Impl::DismissPictureBuffer(int32 picture_buffer_id) { @@ -303,12 +251,20 @@ void PPB_VideoDecoder_Impl::NotifyError( static_cast<PP_VideoDecodeError_Dev>(error)); } -void PPB_VideoDecoder_Impl::NotifyAbortDone() { - if (abort_callback_.func == NULL) +void PPB_VideoDecoder_Impl::NotifyResetDone() { + if (reset_callback_.func == NULL) + return; + + // Call the callback that was stored to be called when Reset is done. + PP_RunAndClearCompletionCallback(&reset_callback_, PP_OK); +} + +void PPB_VideoDecoder_Impl::NotifyDestroyDone() { + if (destroy_callback_.func == NULL) return; - // Call the callback that was stored to be called when Abort is done. - PP_RunAndClearCompletionCallback(&abort_callback_, PP_OK); + // Call the callback that was stored to be called when Destroy is done. + PP_RunAndClearCompletionCallback(&destroy_callback_, PP_OK); } void PPB_VideoDecoder_Impl::NotifyEndOfBitstreamBuffer( diff --git a/webkit/plugins/ppapi/ppb_video_decoder_impl.h b/webkit/plugins/ppapi/ppb_video_decoder_impl.h index 75db896..76c5b6e 100644 --- a/webkit/plugins/ppapi/ppb_video_decoder_impl.h +++ b/webkit/plugins/ppapi/ppb_video_decoder_impl.h @@ -18,7 +18,6 @@ #include "webkit/plugins/ppapi/resource.h" struct PP_GLESBuffer_Dev; -struct PP_SysmemBuffer_Dev; struct PP_VideoDecoderConfig_Dev; struct PP_VideoBitstreamBuffer_Dev; struct PPB_VideoDecoder_Dev; @@ -40,10 +39,6 @@ class PPB_VideoDecoder_Impl : public Resource, virtual PPB_VideoDecoder_API* AsPPB_VideoDecoder_API() OVERRIDE; // PPB_VideoDecoder implementation. - virtual PP_Bool GetConfigs(const PP_VideoConfigElement* requested_configs, - PP_VideoConfigElement* matching_configs, - uint32_t matching_configs_size, - uint32_t* num_of_matching_configs) OVERRIDE; virtual int32_t Initialize(PP_Resource context_id, const PP_VideoConfigElement* dec_config, PP_CompletionCallback callback) OVERRIDE; @@ -51,11 +46,10 @@ class PPB_VideoDecoder_Impl : public Resource, PP_CompletionCallback callback) OVERRIDE; virtual void AssignGLESBuffers(uint32_t no_of_buffers, const PP_GLESBuffer_Dev* buffers) OVERRIDE; - virtual void AssignSysmemBuffers(uint32_t no_of_buffers, - const PP_SysmemBuffer_Dev* buffers) OVERRIDE; virtual void ReusePictureBuffer(int32_t picture_buffer_id) OVERRIDE; virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE; - virtual int32_t Abort(PP_CompletionCallback callback) OVERRIDE; + virtual int32_t Reset(PP_CompletionCallback callback) OVERRIDE; + virtual int32_t Destroy(PP_CompletionCallback callback) OVERRIDE; // media::VideoDecodeAccelerator::Client implementation. virtual void ProvidePictureBuffers( @@ -70,7 +64,8 @@ class PPB_VideoDecoder_Impl : public Resource, media::VideoDecodeAccelerator::Error error) OVERRIDE; virtual void NotifyFlushDone() OVERRIDE; virtual void NotifyEndOfBitstreamBuffer(int32 buffer_id) OVERRIDE; - virtual void NotifyAbortDone() OVERRIDE; + virtual void NotifyResetDone() OVERRIDE; + virtual void NotifyDestroyDone() OVERRIDE; private: // Key: bitstream_buffer_id, value: callback to run when bitstream decode is @@ -89,8 +84,9 @@ class PPB_VideoDecoder_Impl : public Resource, PP_Resource context3d_id_; PP_CompletionCallback initialization_callback_; - PP_CompletionCallback abort_callback_; + PP_CompletionCallback destroy_callback_; PP_CompletionCallback flush_callback_; + PP_CompletionCallback reset_callback_; CallbackById bitstream_buffer_callbacks_; // Reference to the plugin requesting this interface. |