Bug 1224973 - Part 4: Pref media.suspend-bkgnd-video.enabled. r?cpearce, jwwang
Pref to control feature. Enabled at request of :cpearce.
MozReview-Commit-ID: 7Ci7mNqugOh
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -201,16 +201,31 @@ static void InitVideoQueuePrefs() {
"media.video-queue.default-size", MAX_VIDEO_QUEUE_SIZE);
sVideoQueueHWAccelSize = Preferences::GetUint(
"media.video-queue.hw-accel-size", HW_VIDEO_QUEUE_SIZE);
sVideoQueueSendToCompositorSize = Preferences::GetUint(
"media.video-queue.send-to-compositor-size", VIDEO_QUEUE_SEND_TO_COMPOSITOR_SIZE);
}
}
+static bool sSuspendBackgroundVideos = true;
+
+static void
+InitSuspendBackgroundPref()
+{
+ MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");
+
+ static bool sSetupPrefCache = false;
+ if (!sSetupPrefCache) {
+ sSetupPrefCache = true;
+ Preferences::AddBoolVarCache(&sSuspendBackgroundVideos,
+ "media.suspend-bkgnd-video.enabled", true);
+ }
+}
+
MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
MediaDecoderReader* aReader,
bool aRealTime) :
mDecoderID(aDecoder),
mFrameStats(&aDecoder->GetFrameStatistics()),
mVideoFrameContainer(aDecoder->GetVideoFrameContainer()),
mAudioChannel(aDecoder->GetAudioChannel()),
mTaskQueue(new TaskQueue(GetMediaThreadPool(MediaThreadType::PLAYBACK),
@@ -290,16 +305,17 @@ MediaDecoderStateMachine::MediaDecoderSt
"MediaDecoderStateMachine::mPlaybackOffset (Canonical)"),
mIsAudioDataAudible(mTaskQueue, false,
"MediaDecoderStateMachine::mIsAudioDataAudible (Canonical)")
{
MOZ_COUNT_CTOR(MediaDecoderStateMachine);
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
InitVideoQueuePrefs();
+ InitSuspendBackgroundPref();
mBufferingWait = IsRealTime() ? 0 : 15;
mLowDataThresholdUsecs = IsRealTime() ? 0 : detail::LOW_DATA_THRESHOLD_USECS;
#ifdef XP_WIN
// Ensure high precision timers are enabled on Windows, otherwise the state
// machine isn't woken up at reliable intervals to set the next frame,
// and we drop frames while painting. Note that multiple calls to this
@@ -1327,16 +1343,21 @@ void MediaDecoderStateMachine::PlayState
}
ScheduleStateMachine();
}
void MediaDecoderStateMachine::VisibilityChanged()
{
DECODER_LOG("VisibilityChanged: is visible = %c", mIsVisible ? 'T' : 'F');
+
+ if (!sSuspendBackgroundVideos) {
+ // Not suspending background videos so there's nothing to do.
+ return;
+ }
}
void MediaDecoderStateMachine::BufferedRangeUpdated()
{
MOZ_ASSERT(OnTaskQueue());
// While playing an unseekable stream of unknown duration, mObservedDuration
// is updated (in AdvanceFrame()) as we play. But if data is being downloaded