Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Unified Diff: media/filters/ffmpeg_glue.cc

Issue 11368064: Handle FFmpeg initialization in a lazy instance. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Leaky! Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/ffmpeg_glue.cc
diff --git a/media/filters/ffmpeg_glue.cc b/media/filters/ffmpeg_glue.cc
index 71e92b43ef3392a7cf6d994a86c60f2b5f648dfb..e3b227b2ac5140f74f9057090d0bafdb26429961 100644
--- a/media/filters/ffmpeg_glue.cc
+++ b/media/filters/ffmpeg_glue.cc
@@ -4,6 +4,7 @@
#include "media/filters/ffmpeg_glue.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/synchronization/lock.h"
#include "media/ffmpeg/ffmpeg_common.h"
@@ -83,23 +84,42 @@ static int LockManagerOperation(void** lock, enum AVLockOp op) {
return 1;
}
-static bool InitializeFFmpegInternal() {
- // Before doing anything disable logging as it interferes with layout tests.
- av_log_set_level(AV_LOG_QUIET);
+// FFmpeg must only be initialized once, so use a LazyInstance to ensure this.
+class FFmpegInitializer {
+ public:
+ bool initialized() { return initialized_; }
- // Register our protocol glue code with FFmpeg.
- if (av_lockmgr_register(&LockManagerOperation) != 0)
- return false;
+ private:
+ friend struct base::DefaultLazyInstanceTraits<FFmpegInitializer>;
- // Now register the rest of FFmpeg.
- av_register_all();
- return true;
-}
+ FFmpegInitializer()
+ : initialized_(false) {
+ // Before doing anything disable logging as it interferes with layout tests.
+ av_log_set_level(AV_LOG_QUIET);
+
+ // Register our protocol glue code with FFmpeg.
+ if (av_lockmgr_register(&LockManagerOperation) != 0)
+ return;
+
+ // Now register the rest of FFmpeg.
+ av_register_all();
+
+ initialized_ = true;
+ }
+
+ ~FFmpegInitializer() {
+ NOTREACHED() << "FFmpegInitializer should be leaky!";
+ }
+
+ bool initialized_;
+
+ DISALLOW_COPY_AND_ASSIGN(FFmpegInitializer);
+};
void FFmpegGlue::InitializeFFmpeg() {
- // FFmpeg only needs to be initialized once.
- static const bool kStatus = InitializeFFmpegInternal();
- CHECK(kStatus);
+ static base::LazyInstance<FFmpegInitializer>::Leaky li =
+ LAZY_INSTANCE_INITIALIZER;
+ CHECK(li.Get().initialized());
}
FFmpegGlue::FFmpegGlue(FFmpegURLProtocol* protocol)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698