diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-31 18:32:13 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-31 18:32:13 +0000 |
commit | acda308500fea6641a79f7584516d7d153a4a241 (patch) | |
tree | 7ce924637edc497b81c96829f6c754c60f2575e6 /webkit/plugins | |
parent | 100421d5653b09d8b61f14bee5465dfe9d1b934c (diff) | |
download | chromium_src-acda308500fea6641a79f7584516d7d153a4a241.zip chromium_src-acda308500fea6641a79f7584516d7d153a4a241.tar.gz chromium_src-acda308500fea6641a79f7584516d7d153a4a241.tar.bz2 |
Checking in major revision of Pepper video decode APIs.
Part of a patch by vmr@chromium.org:
http://codereview.chromium.org/6541068/
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6776008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80028 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins')
-rw-r--r-- | webkit/plugins/ppapi/DEPS | 1 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.cc | 4 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.h | 4 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_delegate.h | 15 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_video_decoder_impl.cc | 263 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_video_decoder_impl.h | 50 |
6 files changed, 274 insertions, 63 deletions
diff --git a/webkit/plugins/ppapi/DEPS b/webkit/plugins/ppapi/DEPS index 5c56369..baf1b82 100644 --- a/webkit/plugins/ppapi/DEPS +++ b/webkit/plugins/ppapi/DEPS @@ -3,6 +3,7 @@ include_rules = [ "+ppapi/c", "+ppapi/shared_impl", "+printing", + "+media/video", "+skia", "+ui/base", ] diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index 77b66ac..10aee19 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -41,7 +41,7 @@ MockPluginDelegate::PlatformContext3D* MockPluginDelegate::CreateContext3D() { MockPluginDelegate::PlatformVideoDecoder* MockPluginDelegate::CreateVideoDecoder( - const PP_VideoDecoderConfig_Dev& decoder_config) { + PP_VideoDecoderConfig_Dev* decoder_config) { return NULL; } diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index 9a4113f..9e91160 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -22,7 +22,7 @@ class MockPluginDelegate : public PluginDelegate { virtual PlatformImage2D* CreateImage2D(int width, int height); virtual PlatformContext3D* CreateContext3D(); virtual PlatformVideoDecoder* CreateVideoDecoder( - const PP_VideoDecoderConfig_Dev& decoder_config); + PP_VideoDecoderConfig_Dev* decoder_config); virtual PlatformAudio* CreateAudio(uint32_t sample_rate, uint32_t sample_count, PlatformAudio::Client* client); diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index 5bf0d07..6112d53 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -13,6 +13,7 @@ #include "base/shared_memory.h" #include "base/sync_socket.h" #include "googleurl/src/gurl.h" +#include "media/video/video_decode_accelerator.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_instance.h" @@ -54,9 +55,7 @@ struct WebFileChooserParams; } struct PP_Flash_NetAddress; -struct PP_VideoCompressedDataBuffer_Dev; struct PP_VideoDecoderConfig_Dev; -struct PP_VideoUncompressedDataBuffer_Dev; class TransportDIB; @@ -198,15 +197,11 @@ class PluginDelegate { virtual ~PlatformAudio() {} }; - class PlatformVideoDecoder { + // Interface for PlatformVideoDecoder is directly inherited from general media + // VideoDecodeAccelerator interface. + class PlatformVideoDecoder : public media::VideoDecodeAccelerator { public: virtual ~PlatformVideoDecoder() {} - - // Returns false on failure. - virtual bool Decode(PP_VideoCompressedDataBuffer_Dev& input_buffer) = 0; - virtual int32_t Flush(PP_CompletionCallback& callback) = 0; - virtual bool ReturnUncompressedDataBuffer( - PP_VideoUncompressedDataBuffer_Dev& buffer) = 0; }; // Notification that the given plugin has crashed. When a plugin crashes, all @@ -234,7 +229,7 @@ class PluginDelegate { // The caller will own the pointer returned from this. virtual PlatformVideoDecoder* CreateVideoDecoder( - const PP_VideoDecoderConfig_Dev& decoder_config) = 0; + PP_VideoDecoderConfig_Dev* decoder_config) = 0; // The caller is responsible for calling Shutdown() on the returned pointer // to clean up the corresponding resources allocated during this call. diff --git a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc index 9d6add6..d6c1b62 100644 --- a/webkit/plugins/ppapi/ppb_video_decoder_impl.cc +++ b/webkit/plugins/ppapi/ppb_video_decoder_impl.cc @@ -1,15 +1,18 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "webkit/plugins/ppapi/ppb_video_decoder_impl.h" +#include <string> + #include "base/logging.h" #include "ppapi/c/dev/pp_video_dev.h" #include "ppapi/c/dev/ppb_video_decoder_dev.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" #include "webkit/plugins/ppapi/common.h" +#include "webkit/plugins/ppapi/var.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" #include "webkit/plugins/ppapi/resource_tracker.h" @@ -19,29 +22,26 @@ namespace ppapi { namespace { -PP_Bool GetConfig(PP_Instance instance_id, - PP_VideoCodecId_Dev codec, - PP_VideoConfig_Dev* configs, - int32_t config_size, - int32_t *num_config) { +PP_Bool GetConfigs(PP_Instance instance_id, + PP_VideoDecoderConfig_Dev* proto_config, + PP_VideoDecoderConfig_Dev* matching_configs, + int32_t matching_configs_size, + int32_t* num_of_matching_configs) { PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); - *num_config = 0; if (!instance) return PP_FALSE; - // Get configs based on codec. - - if (configs) { - // Fill in the array of configs. - } - - // Update *num_config. + scoped_refptr<PPB_VideoDecoder_Impl> decoder( + new PPB_VideoDecoder_Impl(instance)); - return PP_TRUE; + return BoolToPPBool(decoder->GetConfigs(proto_config, + matching_configs, + matching_configs_size, + num_of_matching_configs)); } PP_Resource Create(PP_Instance instance_id, - const PP_VideoDecoderConfig_Dev* decoder_config) { + PP_VideoDecoderConfig_Dev* decoder_config) { PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); if (!instance) return 0; @@ -49,55 +49,88 @@ PP_Resource Create(PP_Instance instance_id, scoped_refptr<PPB_VideoDecoder_Impl> decoder( new PPB_VideoDecoder_Impl(instance)); - if (!decoder->Init(*decoder_config)) + if (!decoder->Init(const_cast<PP_VideoDecoderConfig_Dev*>(decoder_config))) return 0; return decoder->GetReference(); } +PP_Bool IsVideoDecoder(PP_Resource resource) { + return BoolToPPBool(!!Resource::GetAs<PPB_VideoDecoder_Impl>(resource)); +} + PP_Bool Decode(PP_Resource decoder_id, - PP_VideoCompressedDataBuffer_Dev* input_buffer) { + PP_VideoBitstreamBuffer_Dev* bitstream_buffer, + PP_CompletionCallback callback) { scoped_refptr<PPB_VideoDecoder_Impl> decoder( Resource::GetAs<PPB_VideoDecoder_Impl>(decoder_id)); if (!decoder) return PP_FALSE; - decoder->Decode(*input_buffer); - return PP_TRUE; + return BoolToPPBool(decoder->Decode(bitstream_buffer, callback)); +} + +void AssignPictureBuffer(PP_Resource video_decoder, + uint32_t no_of_buffers, + union PP_PictureData_Dev* picture_buffer) { + scoped_refptr<PPB_VideoDecoder_Impl> decoder( + Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); + if (!decoder) + return; + + decoder->AssignPictureBuffer(no_of_buffers, picture_buffer); +} + +void ReusePictureBuffer(PP_Resource video_decoder, + union PP_PictureData_Dev* picture_buffer) { + scoped_refptr<PPB_VideoDecoder_Impl> decoder( + Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); + if (!decoder) + return; + + decoder->ReusePictureBuffer(picture_buffer); } -int32_t Flush(PP_Resource decoder_id, PP_CompletionCallback callback) { +PP_Bool Flush(PP_Resource decoder_id, + PP_CompletionCallback callback) { scoped_refptr<PPB_VideoDecoder_Impl> decoder( Resource::GetAs<PPB_VideoDecoder_Impl>(decoder_id)); if (!decoder) - return PP_ERROR_BADRESOURCE; + return PP_FALSE; - return decoder->Flush(callback); + return BoolToPPBool(decoder->Flush(callback)); } -PP_Bool ReturnUncompressedDataBuffer( - PP_Resource decoder_id, - PP_VideoUncompressedDataBuffer_Dev* buffer) { +PP_Bool Abort(PP_Resource decoder_id, + PP_CompletionCallback callback) { scoped_refptr<PPB_VideoDecoder_Impl> decoder( Resource::GetAs<PPB_VideoDecoder_Impl>(decoder_id)); if (!decoder) return PP_FALSE; - return BoolToPPBool(decoder->ReturnUncompressedDataBuffer(*buffer)); + return BoolToPPBool(decoder->Abort(callback)); } + const PPB_VideoDecoder_Dev ppb_videodecoder = { - &GetConfig, + &GetConfigs, &Create, + &IsVideoDecoder, &Decode, + &AssignPictureBuffer, + &ReusePictureBuffer, &Flush, - &ReturnUncompressedDataBuffer + &Abort, }; } // namespace PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PluginInstance* instance) - : Resource(instance) { + : Resource(instance), + callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), + abort_callback_(PP_BlockUntilComplete()), + flush_callback_(PP_BlockUntilComplete()), + bitstream_buffer_callback_(PP_BlockUntilComplete()) { } PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { @@ -112,8 +145,23 @@ PPB_VideoDecoder_Impl* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_Impl() { return this; } -bool PPB_VideoDecoder_Impl::Init( - const PP_VideoDecoderConfig_Dev& decoder_config) { +bool PPB_VideoDecoder_Impl::GetConfigs( + PP_VideoDecoderConfig_Dev* proto_config, + PP_VideoDecoderConfig_Dev* matching_configs, + int32_t matching_configs_size, + int32_t* num_of_matching_configs) { + if (!instance()) + return false; + if (!platform_video_decoder_.get()) + return false; + + // TODO(vmr): Implement. + NOTIMPLEMENTED(); + + return false; +} + +bool PPB_VideoDecoder_Impl::Init(PP_VideoDecoderConfig_Dev* decoder_config) { if (!instance()) return false; @@ -124,28 +172,161 @@ bool PPB_VideoDecoder_Impl::Init( } bool PPB_VideoDecoder_Impl::Decode( - PP_VideoCompressedDataBuffer_Dev& input_buffer) { + PP_VideoBitstreamBuffer_Dev* bitstream_buffer, + PP_CompletionCallback callback) { if (!platform_video_decoder_.get()) return false; - return platform_video_decoder_->Decode(input_buffer); + media::BitstreamBuffer* decode_buffer = NULL; + // TODO(vmr): Convert bitstream_buffer to BitstreamBuffer object. + NOTIMPLEMENTED(); + + // Store the callback to inform when bitstream buffer has been processed. + // TODO(vmr): handle simultaneous decodes + callbacks. + bitstream_buffer_callback_ = callback; + + return platform_video_decoder_->Decode( + decode_buffer, + callback_factory_.NewCallback( + &PPB_VideoDecoder_Impl::OnBitstreamBufferProcessed)); } -int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback& callback) { +void PPB_VideoDecoder_Impl::AssignPictureBuffer( + uint32_t no_of_picture_buffers, + PP_PictureData_Dev* picture_buffers) { if (!platform_video_decoder_.get()) - return PP_ERROR_FAILED; + return; - return platform_video_decoder_->Flush(callback); + // TODO(vmr): Map PP_PictureData_Dev into PictureBuffer object. + NOTIMPLEMENTED(); + + media::VideoDecodeAccelerator::PictureBuffer* buffer = NULL; + platform_video_decoder_->ReusePictureBuffer(buffer); } -bool PPB_VideoDecoder_Impl::ReturnUncompressedDataBuffer( - PP_VideoUncompressedDataBuffer_Dev& buffer) { +void PPB_VideoDecoder_Impl::ReusePictureBuffer( + PP_PictureData_Dev* picture_buffer) { + if (!platform_video_decoder_.get()) + return; + + // TODO(vmr): Map PP_PictureData_Dev into PictureBuffer object. + NOTIMPLEMENTED(); + + media::VideoDecodeAccelerator::PictureBuffer* buffer = NULL; + platform_video_decoder_->ReusePictureBuffer(buffer); +} + +bool PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { + if (!platform_video_decoder_.get()) + return false; + + // Store the callback to be called when Flush() is done. + // TODO(vmr): Check for current flush/abort operations. + flush_callback_ = callback; + + return platform_video_decoder_->Flush( + callback_factory_.NewCallback( + &PPB_VideoDecoder_Impl::OnFlushComplete)); +} + +bool PPB_VideoDecoder_Impl::Abort(PP_CompletionCallback callback) { if (!platform_video_decoder_.get()) return false; - return platform_video_decoder_->ReturnUncompressedDataBuffer(buffer); + // Store the callback to be called when Abort() is done. + // TODO(vmr): Check for current flush/abort operations. + abort_callback_ = callback; + + return platform_video_decoder_->Abort( + callback_factory_.NewCallback( + &PPB_VideoDecoder_Impl::OnAbortComplete)); +} + +void PPB_VideoDecoder_Impl::ProvidePictureBuffers( + uint32_t requested_num_of_buffers, + const std::vector<uint32_t>& buffer_properties) { + // TODO(vmr): Implement. + NOTIMPLEMENTED(); +} + +void PPB_VideoDecoder_Impl::PictureReady( + media::VideoDecodeAccelerator::Picture* picture) { + // TODO(vmr): Implement. + NOTIMPLEMENTED(); + + // Convert the picture. + // Get plugin's PPP interface function pointers. + // PPP_VideoDecoder* ppp_videodecoder; + // Call ProvidePictureBuffers function pointer and return. + // ppp_videodecoder->PictureReady(resource_decoder, picture, + // pic_buffer_used_again); +} + +void PPB_VideoDecoder_Impl::DismissPictureBuffer( + media::VideoDecodeAccelerator::PictureBuffer* picture_buffer) { + // TODO(vmr): Implement. + NOTIMPLEMENTED(); +} + +void PPB_VideoDecoder_Impl::NotifyPictureReady() { + // No need to react here as we are already reacting to PictureReady. +} + +void PPB_VideoDecoder_Impl::NotifyEndOfStream() { + // TODO(vmr): Implement. + NOTIMPLEMENTED(); + + // Get decoder's resource handle. + // PP_Resource resource_decoder; + // Get plugin's PPP interface function pointers. + // PPP_VideoDecoder* ppp_videodecoder; + // Call EndOfStream function pointer and return. + // ppp_videodecoder->EndOfStream(resource_decoder); +} + +void PPB_VideoDecoder_Impl::NotifyError( + media::VideoDecodeAccelerator::Error error) { + // TODO(vmr): Implement. + NOTIMPLEMENTED(); + + // Get decoder's resource handle. + // PP_Resource resource_decoder; + // Get plugin's PPP interface function pointers. + // PPP_VideoDecoder* ppp_videodecoder; + // Call NotifyError function pointer. + // ppp_videodecoder->NotifyError(error, error_data, data_size); +} + +void PPB_VideoDecoder_Impl::OnAbortComplete() { + if (abort_callback_.func == NULL) + return; + + // Call the callback that was stored to be called when Abort is done. + PP_CompletionCallback callback = PP_BlockUntilComplete(); + std::swap(callback, abort_callback_); + PP_RunCompletionCallback(&callback, PP_OK); +} + +void PPB_VideoDecoder_Impl::OnBitstreamBufferProcessed() { + if (bitstream_buffer_callback_.func == NULL) + return; + + // Call the callback that was stored to be called when bitstream was sent for + // decoding. + PP_CompletionCallback callback = PP_BlockUntilComplete(); + std::swap(callback, bitstream_buffer_callback_); + PP_RunCompletionCallback(&callback, PP_OK); +} + +void PPB_VideoDecoder_Impl::OnFlushComplete() { + if (flush_callback_.func == NULL) + return; + + // Call the callback that was stored to be called when Flush is done. + PP_CompletionCallback callback = PP_BlockUntilComplete(); + std::swap(callback, flush_callback_); + PP_RunCompletionCallback(&callback, PP_OK); } } // namespace ppapi } // namespace webkit - diff --git a/webkit/plugins/ppapi/ppb_video_decoder_impl.h b/webkit/plugins/ppapi/ppb_video_decoder_impl.h index 492cb33..cb9750d 100644 --- a/webkit/plugins/ppapi/ppb_video_decoder_impl.h +++ b/webkit/plugins/ppapi/ppb_video_decoder_impl.h @@ -5,14 +5,18 @@ #ifndef WEBKIT_PLUGINS_PPAPI_PPB_VIDEO_DECODER_IMPL_H_ #define WEBKIT_PLUGINS_PPAPI_PPB_VIDEO_DECODER_IMPL_H_ +#include <vector> + #include "base/basictypes.h" +#include "base/memory/scoped_callback_factory.h" #include "base/memory/scoped_ptr.h" +#include "ppapi/c/pp_var.h" #include "webkit/plugins/ppapi/plugin_delegate.h" #include "webkit/plugins/ppapi/resource.h" +union PP_PictureData_Dev; struct PP_VideoDecoderConfig_Dev; -struct PP_VideoCompressedDataBuffer_Dev; -struct PP_VideoUncompressedDataBuffer_Dev; +struct PP_VideoBitstreamBuffer_Dev; struct PPB_VideoDecoder_Dev; namespace webkit { @@ -20,9 +24,10 @@ namespace ppapi { class PluginInstance; -class PPB_VideoDecoder_Impl : public Resource { +class PPB_VideoDecoder_Impl : public Resource, + public media::VideoDecodeAccelerator::Client { public: - PPB_VideoDecoder_Impl(PluginInstance* instance); + explicit PPB_VideoDecoder_Impl(PluginInstance* instance); virtual ~PPB_VideoDecoder_Impl(); // Returns a pointer to the interface implementing PPB_VideoDecoder that is @@ -33,16 +38,45 @@ class PPB_VideoDecoder_Impl : public Resource { virtual PPB_VideoDecoder_Impl* AsPPB_VideoDecoder_Impl(); // PPB_VideoDecoder implementation. - bool Init(const PP_VideoDecoderConfig_Dev& decoder_config); - bool Decode(PP_VideoCompressedDataBuffer_Dev& input_buffer); - int32_t Flush(PP_CompletionCallback& callback); - bool ReturnUncompressedDataBuffer(PP_VideoUncompressedDataBuffer_Dev& buffer); + bool GetConfigs(PP_VideoDecoderConfig_Dev* proto_config, + PP_VideoDecoderConfig_Dev* matching_configs, + int32_t matching_configs_size, + int32_t* num_of_matching_configs); + bool Init(PP_VideoDecoderConfig_Dev* dec_config); + bool Decode(PP_VideoBitstreamBuffer_Dev* bitstream_buffer, + PP_CompletionCallback callback); + void AssignPictureBuffer(uint32_t no_of_picture_buffers, + PP_PictureData_Dev* picture_buffers); + void ReusePictureBuffer(PP_PictureData_Dev* picture_buffer); + bool Flush(PP_CompletionCallback callback); + bool Abort(PP_CompletionCallback callback); + + // media::VideoDecodeAccelerator::Client implementation. + void ProvidePictureBuffers(uint32_t requested_num_of_buffers, + const std::vector<uint32_t>& buffer_properties); + void DismissPictureBuffer( + media::VideoDecodeAccelerator::PictureBuffer* picture_buffer); + void PictureReady(media::VideoDecodeAccelerator::Picture* picture); + void NotifyPictureReady(); + void NotifyEndOfStream(); + void NotifyError(media::VideoDecodeAccelerator::Error error); private: + void OnAbortComplete(); + void OnBitstreamBufferProcessed(); + void OnFlushComplete(); + // This is NULL before initialization, and if this PPB_VideoDecoder_Impl is // swapped with another. scoped_ptr<PluginDelegate::PlatformVideoDecoder> platform_video_decoder_; + // Factory to produce our callbacks. + base::ScopedCallbackFactory<PPB_VideoDecoder_Impl> callback_factory_; + + PP_CompletionCallback abort_callback_; + PP_CompletionCallback flush_callback_; + PP_CompletionCallback bitstream_buffer_callback_; + DISALLOW_COPY_AND_ASSIGN(PPB_VideoDecoder_Impl); }; |