Skip to content

Commit

Permalink
#550: OOM lockout kludge, alter paths + #334: remove tele from MSE
Browse files Browse the repository at this point in the history
  • Loading branch information
classilla committed Mar 19, 2019
1 parent 4922145 commit 9279f48
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
4 changes: 4 additions & 0 deletions dom/html/HTMLMediaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2648,6 +2648,7 @@ HTMLMediaElement::ReportEMETelemetry()
void
HTMLMediaElement::ReportMSETelemetry()
{
#if(0)
// Report telemetry for videos when a page is unloaded. We
// want to know data on what state the video is at when
// the user has exited.
Expand Down Expand Up @@ -2700,6 +2701,7 @@ HTMLMediaElement::ReportMSETelemetry()
Telemetry::Accumulate(Telemetry::VIDEO_MSE_JOIN_LATENCY_MS, SECONDS_TO_MS(latency));
LOG(LogLevel::Debug, ("%p VIDEO_MSE_JOIN_LATENCY = %f (%d ms) count=%d\n",
this, latency, SECONDS_TO_MS(latency), mJoinLatency.Count()));
#endif
}

void HTMLMediaElement::UnbindFromTree(bool aDeep,
Expand Down Expand Up @@ -4236,12 +4238,14 @@ void HTMLMediaElement::SuspendOrResumeElement(bool aPauseElement, bool aSuspendE
UpdateSrcMediaStreamPlaying();
UpdateAudioChannelPlayingState();
if (aPauseElement) {
#if(0)
if (mMediaSource) {
ReportMSETelemetry();
#ifdef MOZ_EME
ReportEMETelemetry();
#endif
}
#endif

#ifdef MOZ_EME
// For EME content, force destruction of the CDM client (and CDM
Expand Down
6 changes: 3 additions & 3 deletions dom/media/platforms/ffmpeg/FFmpegDataDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "FFmpegLog.h"
#include "FFmpegDataDecoder.h"
#include "prsystem.h"
#include "prenv.h"
#include "FFmpegRuntimeLinker.h"

#include "libavutil/pixfmt.h"
Expand Down Expand Up @@ -248,9 +249,8 @@ FFmpegDataDecoder<LIBAV_VER>::FindAVCodec(AVCodecID aCodec)
StaticMutexAutoLock mon(sMonitor);
if (!sFFmpegInitDone) {
avcodec_register_all();
#ifdef DEBUG
av_log_set_level(AV_LOG_DEBUG);
#endif
if (PR_GetEnv("AV_LOG_DEBUG"))
av_log_set_level(AV_LOG_DEBUG);
sFFmpegInitDone = true;
}
return avcodec_find_decoder(aCodec);
Expand Down
22 changes: 21 additions & 1 deletion dom/media/platforms/ffmpeg/FFmpegH264Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "FFmpegLog.h"
#include "mozilla/PodOperations.h"

#include "prtime.h"

typedef mozilla::layers::Image Image;
typedef mozilla::layers::PlanarYCbCrImage PlanarYCbCrImage;

Expand All @@ -30,6 +32,10 @@ FFmpegH264Decoder<LIBAV_VER>::PtsCorrectionContext::PtsCorrectionContext()
{
}

// PRIntervalTime is insufficient since the timeout length may be
// many seconds.
static PRTime sLockOutDueToOOM = 0L;

int64_t
FFmpegH264Decoder<LIBAV_VER>::PtsCorrectionContext::GuessCorrectPts(int64_t aPts, int64_t aDts)
{
Expand Down Expand Up @@ -93,6 +99,12 @@ FFmpegH264Decoder<LIBAV_VER>::DecodeResult
FFmpegH264Decoder<LIBAV_VER>::DoDecodeFrame(MediaRawData* aSample)
{
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
if (PR_Now() < sLockOutDueToOOM) {
// Halt further allocations.
NS_WARNING("** FFMPEG LOCKED OUT DUE TO OUT OF MEMORY **");
mCallback->Error();
return DecodeResult::DECODE_ERROR;
}

uint8_t* inputData = const_cast<uint8_t*>(aSample->Data());
size_t inputSize = aSample->Size();
Expand Down Expand Up @@ -140,6 +152,12 @@ FFmpegH264Decoder<LIBAV_VER>::DoDecodeFrame(MediaRawData* aSample,
uint8_t* aData, int aSize)
{
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
if (PR_Now() < sLockOutDueToOOM) {
// Halt further allocations.
NS_WARNING("** FFMPEG LOCKED OUT DUE TO OUT OF MEMORY **");
mCallback->Error();
return DecodeResult::DECODE_ERROR;
}

AVPacket packet;
av_init_packet(&packet);
Expand Down Expand Up @@ -234,7 +252,9 @@ FFmpegH264Decoder<LIBAV_VER>::DoDecodeFrame(MediaRawData* aSample,
-1,
mImage);
if (!v) {
NS_WARNING("image allocation error.");
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);
sLockOutDueToOOM = PR_Now() + ( PR_USEC_PER_SEC * lockout );
mCallback->Error();
return DecodeResult::DECODE_ERROR;
}
Expand Down
8 changes: 3 additions & 5 deletions dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ FFmpegRuntimeLinker::Link()
#endif
free(libFullPath);
}
// Try also finding the library in ~/Library/ffmpeg.
if (!sLinkedLib &&
PR_GetEnv("HOME") &&
asprintf(&libFullPath, "%s/Library/ffmpeg/%s", PR_GetEnv("HOME"), lib)
> 0 && libFullPath) {
// Try also finding the library in ~/Library/TenFourFox-FFmpeg.
if (!sLinkedLib && PR_GetEnv("HOME") &&
asprintf(&libFullPath, "%s/Library/TenFourFox-FFmpeg/%s", PR_GetEnv("HOME"), lib) > 0 && libFullPath) {
#if DEBUG
fprintf(stderr, "TenFourFox looking for FFmpeg: %s\n", libFullPath);
#endif
Expand Down

0 comments on commit 9279f48

Please sign in to comment.