Bug 1097449 - Add locking around libav open/close; r=jya

This commit is contained in:
Anthony Jones 2014-11-13 17:50:26 +13:00
parent a7be610621
commit 0155ca113a
2 changed files with 7 additions and 0 deletions

View File

@ -18,6 +18,7 @@ namespace mozilla
{
bool FFmpegDataDecoder<LIBAV_VER>::sFFmpegInitDone = false;
StaticMutex FFmpegDataDecoder<LIBAV_VER>::sMonitor;
FFmpegDataDecoder<LIBAV_VER>::FFmpegDataDecoder(MediaTaskQueue* aTaskQueue,
AVCodecID aCodecID)
@ -58,6 +59,8 @@ ChoosePixelFormat(AVCodecContext* aCodecContext, const PixelFormat* aFormats)
nsresult
FFmpegDataDecoder<LIBAV_VER>::Init()
{
StaticMutexAutoLock mon(sMonitor);
FFMPEG_LOG("Initialising FFmpeg decoder.");
if (!sFFmpegInitDone) {
@ -130,6 +133,8 @@ FFmpegDataDecoder<LIBAV_VER>::Flush()
nsresult
FFmpegDataDecoder<LIBAV_VER>::Shutdown()
{
StaticMutexAutoLock mon(sMonitor);
if (sFFmpegInitDone) {
avcodec_close(mCodecContext);
av_freep(&mCodecContext);

View File

@ -10,6 +10,7 @@
#include "PlatformDecoderModule.h"
#include "FFmpegLibs.h"
#include "mozilla/Vector.h"
#include "mozilla/StaticMutex.h"
namespace mozilla
{
@ -44,6 +45,7 @@ protected:
private:
static bool sFFmpegInitDone;
static StaticMutex sMonitor;
AVCodecID mCodecID;
};