From c957fbd2ef933be7ea446bd321ef70770aeeb2cc Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Fri, 3 May 2019 02:44:31 +0000 Subject: [PATCH] Bug 1540573 - P5. Only "always throttle" media download to the readahead on cellular connections. r=jya Normally when downloading media data we throttle the download only if we're ahead of the read cursor more than the "readahead limit", and if we estimate that the connection is fast enough that we'll be able to download at a rate fast enough to playback in real time if we resume it later. On mobile we additionally override this so that we always throttle the download once we're ahead of the read cursor by the readahead limit. This is to save data. I think we can relax this to only do this override if we're on a cellular connection; if we're on WiFi we can assume data is cheap. Differential Revision: https://phabricator.services.mozilla.com/D26234 --HG-- extra : moz-landing-system : lando --- dom/media/ChannelMediaDecoder.cpp | 11 +++++++---- mobile/android/app/mobile.js | 7 ++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dom/media/ChannelMediaDecoder.cpp b/dom/media/ChannelMediaDecoder.cpp index b732d1ae4626..6ed95cd449a5 100644 --- a/dom/media/ChannelMediaDecoder.cpp +++ b/dom/media/ChannelMediaDecoder.cpp @@ -11,6 +11,7 @@ #include "BaseMediaResource.h" #include "MediaShutdownManager.h" #include "mozilla/StaticPrefs.h" +#include "VideoUtils.h" namespace mozilla { @@ -458,8 +459,9 @@ MediaStatistics ChannelMediaDecoder::GetStatistics( bool ChannelMediaDecoder::ShouldThrottleDownload( const MediaStatistics& aStats) { // We throttle the download if either the throttle override pref is set - // (so that we can always throttle in Firefox on mobile) or if the download - // is fast enough that there's no concern about playback being interrupted. + // (so that we always throttle at the readahead limit on mobile if using + // a cellular network) or if the download is fast enough that there's no + // concern about playback being interrupted. MOZ_ASSERT(NS_IsMainThread()); NS_ENSURE_TRUE(GetStateMachine(), false); @@ -472,8 +474,9 @@ bool ChannelMediaDecoder::ShouldThrottleDownload( return false; } - if (Preferences::GetBool("media.throttle-regardless-of-download-rate", - false)) { + if (OnCellularConnection() && + Preferences::GetBool( + "media.throttle-cellular-regardless-of-download-rate", false)) { return true; } diff --git a/mobile/android/app/mobile.js b/mobile/android/app/mobile.js index 8d77f1243556..5a1d499134e8 100644 --- a/mobile/android/app/mobile.js +++ b/mobile/android/app/mobile.js @@ -553,9 +553,10 @@ pref("browser.meta_refresh_when_inactive.disabled", true); // prevent video elements from preloading too much data pref("media.preload.default", 1); // default to preload none pref("media.preload.auto", 2); // preload metadata if preload=auto -// On mobile we'll throttle the download once the readahead_limit is hit, -// even if the download is slow. This is to preserve battery and data. -pref("media.throttle-regardless-of-download-rate", true); +// On mobile we throttle the download once the readahead_limit is hit +// if we're using a cellular connection, even if the download is slow. +// This is to preserve battery and data. +pref("media.throttle-cellular-regardless-of-download-rate", true); // Number of video frames we buffer while decoding video. // On Android this is decided by a similar value which varies for