diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-22 21:27:52 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-22 21:27:52 +0000 |
commit | 55424ebf0473d77fd3acdfd3d4d1fab52e5ecdf3 (patch) | |
tree | cc33197cf9a838dde3d9efbd62229c74e8f67320 /media/base/callback.h | |
parent | 6307cdcd4c47a404c48415b5ac2303f2590d00c3 (diff) | |
download | chromium_src-55424ebf0473d77fd3acdfd3d4d1fab52e5ecdf3.zip chromium_src-55424ebf0473d77fd3acdfd3d4d1fab52e5ecdf3.tar.gz chromium_src-55424ebf0473d77fd3acdfd3d4d1fab52e5ecdf3.tar.bz2 |
Implementation of OmxVideoDecodeEngine.
Also moves FFmpegVideoDecodeEngine FFmpegVideoDecoder, OmxVideoDecoder, and VideoDecoderImpl into their own files.
Refactors FFmpegDemuxerTest to be less of a characterization test, and to hopefully be less fragile.
Creates a set of utilities for handling Callbacks versus Tasks, and resource management related to Callbacks.
Re-enables the annexb filters for the chrome build of FFmpeg.
Added a BitstreamConverter class that abstracts the bitstream filter code.
Cleans up a few gyp mistakes with flag exporting.
Review URL: http://codereview.chromium.org/492023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35171 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/callback.h')
-rw-r--r-- | media/base/callback.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/media/base/callback.h b/media/base/callback.h index 553c842..d4b56fc5 100644 --- a/media/base/callback.h +++ b/media/base/callback.h @@ -3,13 +3,24 @@ // LICENSE file. // Some basic utilities for aiding in the management of Tasks and Callbacks. +// // AutoTaskRunner, and its brother AutoCallbackRunner are the scoped_ptr // equivalents for callbacks. They are useful for ensuring a callback is // executed and delete in the face of multiple return points in a function. +// +// TaskToCallbackAdapter converts a Task to a Callback0::Type since the two type +// heirarchies are strangely separate. +// +// CleanupCallback wraps another Callback and provides the ability to register +// objects for deletion as well as cleanup tasks that will be run on the +// callback's destruction. The deletion and cleanup tasks will be run on +// whatever thread the CleanupCallback is destroyed in. #ifndef MEDIA_BASE_CALLBACK_ #define MEDIA_BASE_CALLBACK_ +#include <vector> + #include "base/scoped_ptr.h" #include "base/task.h" @@ -57,6 +68,68 @@ class AutoCallbackRunner { DISALLOW_COPY_AND_ASSIGN(AutoCallbackRunner); }; +class TaskToCallbackAdapter : public Callback0::Type { + public: + static Callback0::Type* NewCallback(Task* task) { + return new TaskToCallbackAdapter(task); + } + + virtual ~TaskToCallbackAdapter() {} + + virtual void RunWithParams(const Tuple0& params) { task_->Run(); } + + private: + TaskToCallbackAdapter(Task* task) : task_(task) {} + + scoped_ptr<Task> task_; + + DISALLOW_COPY_AND_ASSIGN(TaskToCallbackAdapter); +}; + +template <typename CallbackType> +class CleanupCallback : public CallbackType { + public: + explicit CleanupCallback(CallbackType* callback) : callback_(callback) {} + + virtual ~CleanupCallback() { + for (size_t i = 0; i < run_when_done_.size(); i++) { + run_when_done_[i]->Run(); + delete run_when_done_[i]; + } + } + + virtual void RunWithParams(const typename CallbackType::TupleType& params) { + callback_->RunWithParams(params); + } + + template <typename T> + void DeleteWhenDone(T* ptr) { + class Deleter : public Task { + public: + Deleter(T* p) : ptr_(p) {} + + virtual void Run() { + delete ptr_; + } + + private: + T* ptr_; + }; + + RunWhenDone(new Deleter(ptr)); + } + + void RunWhenDone(Task* ptr) { + run_when_done_.push_back(ptr); + } + + private: + scoped_ptr<CallbackType> callback_; + std::vector<Task*> run_when_done_; + + DISALLOW_COPY_AND_ASSIGN(CleanupCallback); +}; + } // namespace media #endif // MEDIA_BASE_CALLBACK_ |