diff options
author | vrk@chromium.org <vrk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-06 03:23:58 +0000 |
---|---|---|
committer | vrk@chromium.org <vrk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-06 03:23:58 +0000 |
commit | 7ace8ad34d1f1d98b62da88ac6aaff1f33d8aaaa (patch) | |
tree | 4beeeef47d3ee8a731dcd56150c6938a99b9df78 /ppapi/shared_impl | |
parent | 10a57d167dd2836ddbd62e8786a12a344707ac73 (diff) | |
download | chromium_src-7ace8ad34d1f1d98b62da88ac6aaff1f33d8aaaa.zip chromium_src-7ace8ad34d1f1d98b62da88ac6aaff1f33d8aaaa.tar.gz chromium_src-7ace8ad34d1f1d98b62da88ac6aaff1f33d8aaaa.tar.bz2 |
Implement PPAPI VideoDecode out-of-process support
This CL implements the proxy necessary for out-of-process video decoding and
introduces a shared base class between the PPB_VideoDecoder_Impl and the proxy.
BUG=NONE
TEST=gles2 plugin runs with or without --ppapi-out-of-process flag, no crashes
Review URL: http://codereview.chromium.org/7545014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95724 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/shared_impl')
-rw-r--r-- | ppapi/shared_impl/tracker_base.h | 2 | ||||
-rw-r--r-- | ppapi/shared_impl/video_decoder_impl.cc | 109 | ||||
-rw-r--r-- | ppapi/shared_impl/video_decoder_impl.h | 97 |
3 files changed, 208 insertions, 0 deletions
diff --git a/ppapi/shared_impl/tracker_base.h b/ppapi/shared_impl/tracker_base.h index 7d4d9e8..7790ea3 100644 --- a/ppapi/shared_impl/tracker_base.h +++ b/ppapi/shared_impl/tracker_base.h @@ -23,6 +23,8 @@ class Var; // called "Tracker", and this would be used in both the plugin side of the // proxy as well as the implementation in the renderer. Currently, all this // does is forward to the process-type-specific tracker to get the information. +// TODO(fischman/vrk): When brettw fixes the TODO above, fix the ugliness in +// VideoDecoderImpl accordingly. class TrackerBase { public: // Must be called before any other function that uses the TrackerBase. diff --git a/ppapi/shared_impl/video_decoder_impl.cc b/ppapi/shared_impl/video_decoder_impl.cc new file mode 100644 index 0000000..ae185c1 --- /dev/null +++ b/ppapi/shared_impl/video_decoder_impl.cc @@ -0,0 +1,109 @@ +// 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 "ppapi/shared_impl/video_decoder_impl.h" + +#include "base/logging.h" +#include "gpu/command_buffer/client/gles2_implementation.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/proxy/plugin_resource_tracker.h" +#include "ppapi/thunk/ppb_context_3d_api.h" +#include "ppapi/thunk/enter.h" + +using ppapi::thunk::PPB_Context3D_API; + +namespace ppapi { + +VideoDecoderImpl::VideoDecoderImpl() + : flush_callback_(PP_MakeCompletionCallback(NULL, NULL)), + reset_callback_(PP_MakeCompletionCallback(NULL, NULL)), + context3d_id_(0), + gles2_impl_(NULL) { +} + +thunk::PPB_VideoDecoder_API* VideoDecoderImpl::AsPPB_VideoDecoder_API() { + return this; +} + +VideoDecoderImpl::~VideoDecoderImpl() { +} + +bool VideoDecoderImpl::Init(PP_Resource context3d_id, + PPB_Context3D_API* context3d, + const PP_VideoConfigElement* decoder_config) { + if (!context3d || !decoder_config || !context3d_id) + return false; + + DCHECK(!gles2_impl_ && !context3d_id_); + gles2_impl_ = context3d->GetGLES2Impl(); + AddRefResource(context3d_id); + context3d_id_ = context3d_id; + return true; +} + +void VideoDecoderImpl::Destroy() { + context3d_id_ = 0; + gles2_impl_ = NULL; + UnrefResource(context3d_id_); +} + +void VideoDecoderImpl::SetFlushCallback(PP_CompletionCallback callback) { + CHECK(callback.func); + DCHECK(!flush_callback_.func); + flush_callback_ = callback; +} + +void VideoDecoderImpl::SetResetCallback(PP_CompletionCallback callback) { + CHECK(callback.func); + DCHECK(!reset_callback_.func); + reset_callback_ = callback; +} + +void VideoDecoderImpl::SetBitstreamBufferCallback( + int32 bitstream_buffer_id, PP_CompletionCallback callback) { + CHECK(bitstream_buffer_callbacks_.insert( + std::make_pair(bitstream_buffer_id, callback)).second); +} + +void VideoDecoderImpl::RunFlushCallback(int32 result) { + DCHECK(flush_callback_.func); + PP_RunAndClearCompletionCallback(&flush_callback_, result); +} + +void VideoDecoderImpl::RunResetCallback(int32 result) { + DCHECK(reset_callback_.func); + PP_RunAndClearCompletionCallback(&reset_callback_, result); +} + +void VideoDecoderImpl::RunBitstreamBufferCallback( + int32 bitstream_buffer_id, int32 result) { + CallbackById::iterator it = + bitstream_buffer_callbacks_.find(bitstream_buffer_id); + DCHECK(it != bitstream_buffer_callbacks_.end()); + PP_CompletionCallback cc = it->second; + bitstream_buffer_callbacks_.erase(it); + PP_RunCompletionCallback(&cc, PP_OK); +} + +void VideoDecoderImpl::FlushCommandBuffer() { + if (gles2_impl_) + gles2_impl_->Flush(); +} + +bool VideoDecoderImpl::CopyConfigsToVector( + const PP_VideoConfigElement* configs_to_copy, + std::vector<PP_VideoConfigElement>* out_configs) { + // TODO(fischman/vrk): This is still broken. We need to get rid of the silly + // PP_VideoConfigElement vector in favor of a struct (see TODO in + // ppb_video_decoder_dev.h). + const PP_VideoConfigElement* current = configs_to_copy; + while (current && *current != PP_VIDEOATTR_DICTIONARY_TERMINATOR) { + out_configs->push_back(*current); + out_configs->push_back(*(current + 1)); + current += 2; + } + return true; +} + +} // namespace ppapi diff --git a/ppapi/shared_impl/video_decoder_impl.h b/ppapi/shared_impl/video_decoder_impl.h new file mode 100644 index 0000000..cc0da6d --- /dev/null +++ b/ppapi/shared_impl/video_decoder_impl.h @@ -0,0 +1,97 @@ +// 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. + +#ifndef PPAPI_SHARED_IMPL_VIDEO_DECODER_IMPL_H_ +#define PPAPI_SHARED_IMPL_VIDEO_DECODER_IMPL_H_ + +#include <map> +#include <vector> + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ppapi/c/dev/ppb_video_decoder_dev.h" +#include "ppapi/shared_impl/resource_object_base.h" +#include "ppapi/thunk/ppb_video_decoder_api.h" + +namespace gpu { +namespace gles2 { +class GLES2Implementation; +} // namespace gles2 +} // namespace gpu + +namespace ppapi { +namespace thunk { +class PPB_Context3D_API; +} // namespace thunk +} // namespace ppapi + +namespace ppapi { + +// Implements the logic to set and run callbacks for various video decoder +// events. Both the proxy and the renderer implementation share this code. +class VideoDecoderImpl : public ResourceObjectBase, + public thunk::PPB_VideoDecoder_API { + public: + VideoDecoderImpl(); + virtual ~VideoDecoderImpl(); + + // ResourceObjectBase implementation. + virtual PPB_VideoDecoder_API* AsPPB_VideoDecoder_API() OVERRIDE; + + // PPB_VideoDecoder_API implementation. + virtual void Destroy() OVERRIDE; + + // Copy C-style config list into |out_configs| vector. + static bool CopyConfigsToVector( + const PP_VideoConfigElement* configs_to_copy, + std::vector<PP_VideoConfigElement>* out_configs); + + protected: + void SetFlushCallback(PP_CompletionCallback callback); + void SetResetCallback(PP_CompletionCallback callback); + void SetBitstreamBufferCallback( + int32 bitstream_buffer_id, PP_CompletionCallback callback); + + void RunFlushCallback(int32 result); + void RunResetCallback(int32 result); + void RunBitstreamBufferCallback(int32 bitstream_buffer_id, int32 result); + + // Tell command buffer to process all commands it has received so far. + void FlushCommandBuffer(); + + // Initialize the underlying decoder and return success status. + virtual bool Init(PP_Resource context3d_id, + thunk::PPB_Context3D_API* context, + const PP_VideoConfigElement* dec_config); + + // TODO(fischman/vrk): Remove accordingly when brettw has merged resource + // trackers. + virtual void AddRefResource(PP_Resource resource) = 0; + virtual void UnrefResource(PP_Resource resource) = 0; + + private: + // Key: bitstream_buffer_id, value: callback to run when bitstream decode is + // done. + typedef std::map<int32, PP_CompletionCallback> CallbackById; + + PP_CompletionCallback flush_callback_; + PP_CompletionCallback reset_callback_; + CallbackById bitstream_buffer_callbacks_; + + // The resource ID of the underlying Context3d object being used. Used only + // for reference counting to keep it alive for the lifetime of |*this|. + PP_Resource context3d_id_; + + // Reference to the GLES2Implementation owned by |context3d_id_|. + // Context3D is guaranteed to be alive for the lifetime of this class. + // In the out-of-process case, Context3D's gles2_impl() exists in the plugin + // process only, so gles2_impl_ is NULL in that case. + gpu::gles2::GLES2Implementation* gles2_impl_; + + DISALLOW_COPY_AND_ASSIGN(VideoDecoderImpl); +}; + +} // namespace ppapi + +#endif // PPAPI_SHARED_IMPL_VIDEO_DECODER_IMPL_H_ |