Index: webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc |
diff --git a/webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc b/webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc |
index 75d2bfa73245a050aa9688e53b0f0fe1538884b0..54d84dc58b4a2479e2e937f33955ffb4e7a694c4 100644 |
--- a/webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc |
+++ b/webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc |
@@ -34,8 +34,9 @@ const size_t kYPlaneIndex = 0; |
const size_t kUPlaneIndex = 1; |
const size_t kVPlaneIndex = 2; |
-#if !defined(WEBRTC_CHROMIUM_BUILD) |
+#if defined(WEBRTC_INITIALIZE_FFMPEG) |
+rtc::CriticalSection ffmpeg_init_lock; |
hbos
2016/01/27 13:35:42
Is it OK to have a global variable that is a class
stefan-webrtc
2016/01/27 14:00:39
Hm, I'm not sure, but I think it should be OK. We
hbos
2016/01/28 10:31:09
If I expose it in the header then I have to make s
stefan-webrtc
2016/01/28 10:39:46
I just wanted to make sure we considered it. Agree
|
bool ffmpeg_initialized = false; |
stefan-webrtc
2016/01/27 14:00:38
I guess an option could be to use atomics for this
hbos
2016/01/28 10:31:09
Don't think it matters since I have to use the loc
stefan-webrtc
2016/01/28 10:39:46
Leave as is.
|
// Called by FFmpeg to do mutex operations if initialized using |
@@ -61,10 +62,8 @@ int LockManagerOperation(void** lock, AVLockOp op) |
return -1; |
} |
-// TODO(hbos): Assumed to be called on a single thread. Should DCHECK that |
-// InitializeFFmpeg is only called on one thread or make it thread safe. |
-// See https://bugs.chromium.org/p/webrtc/issues/detail?id=5427. |
void InitializeFFmpeg() { |
+ rtc::CritScope cs(&ffmpeg_init_lock); |
if (!ffmpeg_initialized) { |
if (av_lockmgr_register(LockManagerOperation) < 0) { |
RTC_NOTREACHED() << "av_lockmgr_register failed."; |
@@ -75,7 +74,7 @@ void InitializeFFmpeg() { |
} |
} |
-#endif // !defined(WEBRTC_CHROMIUM_BUILD) |
+#endif // defined(WEBRTC_INITIALIZE_FFMPEG) |
// Called by FFmpeg when it is done with a frame buffer, see AVGetBuffer2. |
void AVFreeBuffer2(void* opaque, uint8_t* data) { |
@@ -179,12 +178,13 @@ int32_t H264DecoderImpl::InitDecode(const VideoCodec* codec_settings, |
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
} |
- // In Chromium FFmpeg will be initialized outside of WebRTC and we should not |
- // attempt to do so ourselves or it will be initialized twice. |
- // TODO(hbos): Put behind a different flag in case non-chromium project wants |
- // to initialize externally. |
- // See https://bugs.chromium.org/p/webrtc/issues/detail?id=5427. |
-#if !defined(WEBRTC_CHROMIUM_BUILD) |
+ // FFmpeg must have been initialized (with |av_lockmgr_register| and |
+ // |av_register_all|) before we proceed. |InitializeFFmpeg| does this, which |
+ // makes sense for WebRTC standalone. In other cases, such as Chromium, FFmpeg |
+ // is initialized externally and calling |InitializeFFmpeg| would be |
+ // thread-unsafe and result in FFmpeg being initialized twice, which could |
+ // break other FFmpeg usage. See the |rtc_skip_ffmpeg_init| flag. |
stefan-webrtc
2016/01/27 14:00:39
How is it safe to do this in webrtc if Chrome can
hbos
2016/01/28 10:31:09
Calling InitializeFFmpeg multiple times won't init
|
+#if defined(WEBRTC_INITIALIZE_FFMPEG) |
// Make sure FFmpeg has been initialized. |
InitializeFFmpeg(); |
#endif |