Bug 1224973 - Part 4: Pref media.suspend-bkgnd-video.enabled. r?cpearce, jwwang draft
authorDan Glastonbury <dglastonbury@mozilla.com>
Mon, 18 Apr 2016 16:31:26 +1000
changeset 363159 63013b3800f4741682a7c836eecc8dc4ee42a32a
parent 363158 54ff8a1f81c1871a73826bfed6640f8cdb805e97
child 363160 143e4346c3ee4e101e37657cd66335e81a225c9c
push id17118
push userbmo:dglastonbury@mozilla.com
push dateWed, 04 May 2016 02:49:28 +0000
reviewerscpearce, jwwang
bugs1224973
milestone49.0a1
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
dom/media/MediaDecoderStateMachine.cpp
--- 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