Bug 1097449 - Add locking around libav open/close; r=jya
authorAnthony Jones <ajones@mozilla.com>
Thu, 13 Nov 2014 17:50:26 +1300
changeset 215451 903fd76cc1185849953f6cccaedc7731b3722c15
parent 215450 153148514f228a9e7b89e83aae22095ca0ca5cd3
child 215452 fbb9dc943109b80ee22079de49b0d00df9dd22fe
push id27817
push usercbook@mozilla.com
push dateThu, 13 Nov 2014 15:21:11 +0000
treeherdermozilla-central@ae27ae77e32f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1097449
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1097449 - Add locking around libav open/close; r=jya
dom/media/fmp4/ffmpeg/FFmpegDataDecoder.cpp
dom/media/fmp4/ffmpeg/FFmpegDataDecoder.h
--- a/dom/media/fmp4/ffmpeg/FFmpegDataDecoder.cpp
+++ b/dom/media/fmp4/ffmpeg/FFmpegDataDecoder.cpp
@@ -13,16 +13,17 @@
 #include "FFmpegLog.h"
 #include "FFmpegDataDecoder.h"
 #include "prsystem.h"
 
 namespace mozilla
 {
 
 bool FFmpegDataDecoder<LIBAV_VER>::sFFmpegInitDone = false;
+StaticMutex FFmpegDataDecoder<LIBAV_VER>::sMonitor;
 
 FFmpegDataDecoder<LIBAV_VER>::FFmpegDataDecoder(MediaTaskQueue* aTaskQueue,
                                                 AVCodecID aCodecID)
   : mTaskQueue(aTaskQueue)
   , mCodecContext(nullptr)
   , mFrame(NULL)
   , mCodecID(aCodecID)
 {
@@ -53,16 +54,18 @@ ChoosePixelFormat(AVCodecContext* aCodec
 
   NS_WARNING("FFmpeg does not share any supported pixel formats.");
   return PIX_FMT_NONE;
 }
 
 nsresult
 FFmpegDataDecoder<LIBAV_VER>::Init()
 {
+  StaticMutexAutoLock mon(sMonitor);
+
   FFMPEG_LOG("Initialising FFmpeg decoder.");
 
   if (!sFFmpegInitDone) {
     av_register_all();
 #ifdef DEBUG
     av_log_set_level(AV_LOG_DEBUG);
 #endif
     sFFmpegInitDone = true;
@@ -125,16 +128,18 @@ FFmpegDataDecoder<LIBAV_VER>::Flush()
   mTaskQueue->Flush();
   avcodec_flush_buffers(mCodecContext);
   return NS_OK;
 }
 
 nsresult
 FFmpegDataDecoder<LIBAV_VER>::Shutdown()
 {
+  StaticMutexAutoLock mon(sMonitor);
+
   if (sFFmpegInitDone) {
     avcodec_close(mCodecContext);
     av_freep(&mCodecContext);
 #if LIBAVCODEC_VERSION_MAJOR >= 55
     av_frame_free(&mFrame);
 #elif LIBAVCODEC_VERSION_MAJOR == 54
     avcodec_free_frame(&mFrame);
 #else
--- a/dom/media/fmp4/ffmpeg/FFmpegDataDecoder.h
+++ b/dom/media/fmp4/ffmpeg/FFmpegDataDecoder.h
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef __FFmpegDataDecoder_h__
 #define __FFmpegDataDecoder_h__
 
 #include "PlatformDecoderModule.h"
 #include "FFmpegLibs.h"
 #include "mozilla/Vector.h"
+#include "mozilla/StaticMutex.h"
 
 namespace mozilla
 {
 
 template <int V>
 class FFmpegDataDecoder : public MediaDataDecoder
 {
 };
@@ -39,15 +40,16 @@ protected:
 
   MediaTaskQueue* mTaskQueue;
   AVCodecContext* mCodecContext;
   AVFrame*        mFrame;
   Vector<uint8_t> mExtraData;
 
 private:
   static bool sFFmpegInitDone;
+  static StaticMutex sMonitor;
 
   AVCodecID mCodecID;
 };
 
 } // namespace mozilla
 
 #endif // __FFmpegDataDecoder_h__