Index: media/filters/ffmpeg_glue.cc |
diff --git a/media/filters/ffmpeg_glue.cc b/media/filters/ffmpeg_glue.cc |
index 71e92b43ef3392a7cf6d994a86c60f2b5f648dfb..127763990e943b5f4440654f7639adffdddd5655 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() { |
scherkus (not reviewing)
2012/11/02 23:39:28
I wonder if this ever gets called :)
DaleCurtis
2012/11/02 23:45:55
Yes, unless you declare it as:
static base::LazyI
scherkus (not reviewing)
2012/11/02 23:48:05
I'm ok w/ a leaky FFmpeg initializer. This is esse
DaleCurtis
2012/11/02 23:49:39
Done.
|
+ if (initialized_) |
+ av_lockmgr_register(NULL); |
+ } |
+ |
+ 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> li = LAZY_INSTANCE_INITIALIZER; |
+ CHECK(li.Get().initialized()); |
} |
FFmpegGlue::FFmpegGlue(FFmpegURLProtocol* protocol) |