Bug 1374475 - Don't throttle download of media files under 8MB in size. r?jwwang draft
authorChris Pearce <cpearce@mozilla.com>
Tue, 20 Jun 2017 13:03:49 +1200
changeset 597032 cf97f3510fdb35c96881668e881841e5486dd070
parent 596660 72346a4d6afcc17504f911190dbf470100e879ec
child 597038 a7fe66c6164fb60b5bff4f19e66631dae3b969b3
push id64800
push userbmo:cpearce@mozilla.com
push dateTue, 20 Jun 2017 01:13:50 +0000
reviewersjwwang
bugs1374475, 1373618
milestone56.0a1
Bug 1374475 - Don't throttle download of media files under 8MB in size. r?jwwang The startup latency for an HTTP transaction can be high, this adds delay when we're seeking into an unbuffered range. So we should not throttle the download for small files, to speed up seeking. This also works around the problem in bug 1373618 in the case where the download is fast enough for the entire file to predownload before a seek. MozReview-Commit-ID: A8Hqi71IJ1H
dom/media/MediaDecoder.cpp
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -1025,16 +1025,25 @@ bool
 MediaDecoder::ShouldThrottleDownload()
 {
   // 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.
   MOZ_ASSERT(NS_IsMainThread());
   NS_ENSURE_TRUE(mDecoderStateMachine, false);
 
+  int64_t length = mResource->GetLength();
+  if (length > 0 &&
+      length <= int64_t(MediaPrefs::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)) {
     return true;
   }
 
   MediaStatistics stats = GetStatistics();
   if (!stats.mDownloadRateReliable || !stats.mPlaybackRateReliable) {
     return false;