From b55038bbf2f7512cae0a5688a0eba561a33137e3 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Fri, 28 Sep 2012 13:34:03 -0400 Subject: [PATCH] Bug 794747 - add a pref for the default size of the VideoQueue. r=kinetik --- .../media/nsBuiltinDecoderStateMachine.cpp | 33 ++++++++++--------- content/media/nsBuiltinDecoderStateMachine.h | 4 +++ modules/libpref/src/init/all.js | 4 +++ 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/content/media/nsBuiltinDecoderStateMachine.cpp b/content/media/nsBuiltinDecoderStateMachine.cpp index 100423bf1c7..6cae9596032 100644 --- a/content/media/nsBuiltinDecoderStateMachine.cpp +++ b/content/media/nsBuiltinDecoderStateMachine.cpp @@ -60,19 +60,6 @@ const uint32_t SILENCE_BYTES_CHUNK = 32 * 1024; // which is at or after the current playback position. static const uint32_t LOW_VIDEO_FRAMES = 1; -// If we've got more than AMPLE_VIDEO_FRAMES decoded video frames waiting in -// the video queue, we will not decode any more video frames until some have -// been consumed by the play state machine thread. -#ifdef MOZ_WIDGET_GONK -// On B2G this is decided by a similar value which varies for each OMX decoder -// |OMX_PARAM_PORTDEFINITIONTYPE::nBufferCountMin|. This number must be less -// than the OMX equivalent or gecko will think it is chronically starved of -// video frames. All decoders seen so far have a value of at least 4. -static const uint32_t AMPLE_VIDEO_FRAMES = 3; -#else -static const uint32_t AMPLE_VIDEO_FRAMES = 10; -#endif - // Arbitrary "frame duration" when playing only audio. static const int AUDIO_DURATION_USECS = 40000; @@ -430,6 +417,22 @@ nsBuiltinDecoderStateMachine::nsBuiltinDecoderStateMachine(nsBuiltinDecoder* aDe mBufferingWait = mRealTime ? 0 : BUFFERING_WAIT_S; mLowDataThresholdUsecs = mRealTime ? 0 : LOW_DATA_THRESHOLD_USECS; + + // If we've got more than mAmpleVideoFrames decoded video frames waiting in + // the video queue, we will not decode any more video frames until some have + // been consumed by the play state machine thread. +#ifdef MOZ_WIDGET_GONK + // On B2G this is decided by a similar value which varies for each OMX decoder + // |OMX_PARAM_PORTDEFINITIONTYPE::nBufferCountMin|. This number must be less + // than the OMX equivalent or gecko will think it is chronically starved of + // video frames. All decoders seen so far have a value of at least 4. + mAmpleVideoFrames = Preferences::GetUint("media.video-queue.default-size", 3); +#else + mAmpleVideoFrames = Preferences::GetUint("media.video-queue.default-size", 10); +#endif + if (mAmpleVideoFrames < 2) { + mAmpleVideoFrames = 2; + } } nsBuiltinDecoderStateMachine::~nsBuiltinDecoderStateMachine() @@ -750,7 +753,7 @@ bool nsBuiltinDecoderStateMachine::HaveEnoughDecodedVideo() { mDecoder->GetReentrantMonitor().AssertCurrentThreadIn(); - if (static_cast(mReader->VideoQueue().GetSize()) < AMPLE_VIDEO_FRAMES) { + if (static_cast(mReader->VideoQueue().GetSize()) < mAmpleVideoFrames) { return false; } @@ -786,7 +789,7 @@ void nsBuiltinDecoderStateMachine::DecodeLoop() // Once we've decoded more than videoPumpThreshold video frames, we'll // no longer be considered to be "pumping video". - const unsigned videoPumpThreshold = mRealTime ? 0 : AMPLE_VIDEO_FRAMES / 2; + const unsigned videoPumpThreshold = mRealTime ? 0 : mAmpleVideoFrames / 2; // After the audio decode fills with more than audioPumpThreshold usecs // of decoded audio, we'll start to check whether the audio or video decode diff --git a/content/media/nsBuiltinDecoderStateMachine.h b/content/media/nsBuiltinDecoderStateMachine.h index 59007404f02..255b59b7a04 100644 --- a/content/media/nsBuiltinDecoderStateMachine.h +++ b/content/media/nsBuiltinDecoderStateMachine.h @@ -605,6 +605,10 @@ protected: uint32_t mBufferingWait; int64_t mLowDataThresholdUsecs; + // If we've got more than mAmpleVideoFrames decoded video frames waiting in + // the video queue, we will not decode any more video frames until some have + // been consumed by the play state machine thread. + uint32_t mAmpleVideoFrames; // True if we shouldn't play our audio (but still write it to any capturing // streams). bool mAudioCaptured; diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 112ba928b3a..7edf9180188 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -182,6 +182,10 @@ pref("media.webaudio.enabled", false); // Whether to autostart a media element with an |autoplay| attribute pref("media.autoplay.enabled", true); +// The default number of decoded video frames that are enqueued in +// nsBuiltinDecoderReader's mVideoQueue. +pref("media.video-queue.default-size", 10); + // 0 = Off, 1 = Full, 2 = Tagged Images Only. // See eCMSMode in gfx/thebes/gfxPlatform.h pref("gfx.color_management.mode", 2);