diff --git a/dom/media/platforms/ffmpeg/FFmpegH264Decoder.cpp b/dom/media/platforms/ffmpeg/FFmpegH264Decoder.cpp index 4b2df08ea..d84936a8e 100644 --- a/dom/media/platforms/ffmpeg/FFmpegH264Decoder.cpp +++ b/dom/media/platforms/ffmpeg/FFmpegH264Decoder.cpp @@ -35,6 +35,7 @@ FFmpegH264Decoder::PtsCorrectionContext::PtsCorrectionContext() // PRIntervalTime is insufficient since the timeout length may be // many seconds. static PRTime sLockOutDueToOOM = 0L; +static bool sIsLockedOut = false; int64_t FFmpegH264Decoder::PtsCorrectionContext::GuessCorrectPts(int64_t aPts, int64_t aDts) @@ -99,11 +100,14 @@ FFmpegH264Decoder::DecodeResult FFmpegH264Decoder::DoDecodeFrame(MediaRawData* aSample) { MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn()); - if (MOZ_UNLIKELY(PR_Now() < sLockOutDueToOOM)) { - // Halt further allocations. - NS_WARNING("** FFMPEG LOCKED OUT DUE TO OUT OF MEMORY **"); - mCallback->Error(); - return DecodeResult::DECODE_ERROR; + if (MOZ_UNLIKELY(sIsLockedOut)) { + if (PR_Now() < sLockOutDueToOOM) { + // Halt further allocations. + NS_WARNING("** FFMPEG LOCKED OUT DUE TO OUT OF MEMORY **"); + mCallback->Error(); + return DecodeResult::DECODE_ERROR; + } + sIsLockedOut = false; } uint8_t* inputData = const_cast(aSample->Data()); @@ -152,11 +156,14 @@ FFmpegH264Decoder::DoDecodeFrame(MediaRawData* aSample, uint8_t* aData, int aSize) { MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn()); - if (MOZ_UNLIKELY(PR_Now() < sLockOutDueToOOM)) { - // Halt further allocations. - NS_WARNING("** FFMPEG LOCKED OUT DUE TO OUT OF MEMORY **"); - mCallback->Error(); - return DecodeResult::DECODE_ERROR; + if (MOZ_UNLIKELY(sIsLockedOut)) { + if (PR_Now() < sLockOutDueToOOM) { + // Halt further allocations. + NS_WARNING("** FFMPEG LOCKED OUT DUE TO OUT OF MEMORY **"); + mCallback->Error(); + return DecodeResult::DECODE_ERROR; + } + sIsLockedOut = false; } AVPacket packet; @@ -254,6 +261,7 @@ FFmpegH264Decoder::DoDecodeFrame(MediaRawData* aSample, if (!v) { int32_t lockout = 3; /* XXX: make a pref */ fprintf(stderr, "Warning: TenFourFox ran out of memory trying to decode H.264 video.\nAny H.264 video on any page playing in the next %i seconds will be blocked.\n", lockout); + sIsLockedOut = true; sLockOutDueToOOM = PR_Now() + ( PR_USEC_PER_SEC * lockout ); mCallback->Error(); return DecodeResult::DECODE_ERROR;