Bug 1540573 - P5. Only "always throttle" media download to the readahead on cellular connections. r=jya
authorChris Pearce <cpearce@mozilla.com>
Mon, 06 May 2019 22:43:09 +0000
changeset 531630 07c6d54744f70517f1d5d92789c44335631229da
parent 531629 bcbb8c779852193d99648b9a109daf5ffe17058a
child 531631 0d175912734db128b3f4fc4dab37a10997d17852
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1540573
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
dom/media/ChannelMediaDecoder.cpp
mobile/android/app/mobile.js
--- a/dom/media/ChannelMediaDecoder.cpp
+++ b/dom/media/ChannelMediaDecoder.cpp
@@ -7,16 +7,17 @@
 #include "ChannelMediaDecoder.h"
 #include "ChannelMediaResource.h"
 #include "DecoderTraits.h"
 #include "MediaDecoderStateMachine.h"
 #include "MediaFormatReader.h"
 #include "BaseMediaResource.h"
 #include "MediaShutdownManager.h"
 #include "mozilla/StaticPrefs.h"
+#include "VideoUtils.h"
 
 namespace mozilla {
 
 extern LazyLogModule gMediaDecoderLog;
 #define LOG(x, ...) \
   DDMOZ_LOG(gMediaDecoderLog, LogLevel::Debug, x, ##__VA_ARGS__)
 
 ChannelMediaDecoder::ResourceCallback::ResourceCallback(
@@ -454,32 +455,34 @@ MediaStatistics ChannelMediaDecoder::Get
   result.mPlaybackRateReliable = aInfo.mReliable;
   result.mPlaybackPosition = aPlaybackPosition;
   return result;
 }
 
 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);
 
   int64_t length = aStats.mTotalBytes;
   if (length > 0 &&
       length <= int64_t(StaticPrefs::MediaMemoryCacheMaxSize()) * 1024) {
     // Don't throttle the download of small resources. This is to speed
     // up seeking, as seeks into unbuffered ranges would require starting
     // up a new HTTP transaction, which adds latency.
     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;
   }
 
   if (!aStats.mDownloadRateReliable || !aStats.mPlaybackRateReliable) {
     return false;
   }
   uint32_t factor =
       std::max(2u, Preferences::GetUint("media.throttle-factor", 2));
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -548,19 +548,20 @@ pref("dom.webnotifications.enabled", tru
 pref("browser.chrome.toolbar_tips", false);
 
 // don't allow meta-refresh when backgrounded
 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
 // 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.
 pref("media.video-queue.default-size", 3);