Bug 1097449 - Add locking around libav open/close; r=jya
☠☠ backed out by 9e77604d6a12 ☠ ☠
authorAnthony Jones <ajones@mozilla.com>
Thu, 13 Nov 2014 14:48:08 +1300
changeset 215444 f8ff4c7a978a1889e5372d9691c75d3f86f2eea7
parent 215443 92295f515d2de1f859a82c710155df30f74412c8
child 215445 b883bad7f4f628b25694daa9dbf9458d3981c935
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;
+Monitor FFmpegDataDecoder<LIBAV_VER>::sMonitor("FFmpegDataDecoder");
 
 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()
 {
+  MonitorAutoLock 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()
 {
+  MonitorAutoLock 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
@@ -39,15 +39,16 @@ protected:
 
   MediaTaskQueue* mTaskQueue;
   AVCodecContext* mCodecContext;
   AVFrame*        mFrame;
   Vector<uint8_t> mExtraData;
 
 private:
   static bool sFFmpegInitDone;
+  static Monitor sMonitor;
 
   AVCodecID mCodecID;
 };
 
 } // namespace mozilla
 
 #endif // __FFmpegDataDecoder_h__