#599: get PR_Now() out of the frame path

This commit is contained in:
Cameron Kaiser 2020-04-15 21:07:43 -07:00
parent 6428efdd0e
commit cce50271ab
1 changed files with 18 additions and 10 deletions

View File

@ -35,6 +35,7 @@ FFmpegH264Decoder<LIBAV_VER>::PtsCorrectionContext::PtsCorrectionContext()
// PRIntervalTime is insufficient since the timeout length may be
// many seconds.
static PRTime sLockOutDueToOOM = 0L;
static bool sIsLockedOut = false;
int64_t
FFmpegH264Decoder<LIBAV_VER>::PtsCorrectionContext::GuessCorrectPts(int64_t aPts, int64_t aDts)
@ -99,11 +100,14 @@ FFmpegH264Decoder<LIBAV_VER>::DecodeResult
FFmpegH264Decoder<LIBAV_VER>::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<uint8_t*>(aSample->Data());
@ -152,11 +156,14 @@ FFmpegH264Decoder<LIBAV_VER>::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<LIBAV_VER>::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;