Bug 1375772. P2 - revert the changes in bug 1364001 and its followups. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 23 Jun 2017 14:43:54 +0800
changeset 599467 5728fe56473a9a7aa6252e3ac5d85c0451863fac
parent 599466 9b54ed88bb22a985f3f5fa48a9e19846ae7df5f7
child 600360 5521a642e180b80939ea115cd25fd482c2815168
push id65537
push userjwwang@mozilla.com
push dateFri, 23 Jun 2017 06:55:10 +0000
bugs1375772, 1364001
milestone56.0a1
Bug 1375772. P2 - revert the changes in bug 1364001 and its followups. MozReview-Commit-ID: 4c4urU5NNHp
dom/media/MediaCache.cpp
dom/media/MediaCache.h
dom/media/MediaDecoder.cpp
dom/media/MediaDecoder.h
dom/media/MediaResource.cpp
dom/media/MediaResource.h
mobile/android/app/mobile.js
modules/libpref/init/all.js
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -1288,24 +1288,22 @@ MediaCache::Update()
       } else if (mIndex.Length() > uint32_t(maxBlocks)) {
         // We're in the process of bringing the cache size back to the
         // desired limit, so don't bring in more data yet
         LOG("Stream %p throttling to reduce cache size", stream);
         enableReading = false;
       } else {
         TimeDuration predictedNewDataUse = PredictNextUseForIncomingData(stream);
 
-        if (stream->mThrottleReadahead &&
-            stream->mCacheSuspended &&
+        if (stream->mCacheSuspended &&
             predictedNewDataUse.ToSeconds() > resumeThreshold) {
           // Don't need data for a while, so don't bother waking up the stream
           LOG("Stream %p avoiding wakeup since more data is not needed", stream);
           enableReading = false;
-        } else if (stream->mThrottleReadahead &&
-                   predictedNewDataUse.ToSeconds() > readaheadLimit) {
+        } else if (predictedNewDataUse.ToSeconds() > readaheadLimit) {
           // Don't read ahead more than this much
           LOG("Stream %p throttling to avoid reading ahead too far", stream);
           enableReading = false;
         } else if (freeBlockCount > 0) {
           // Free blocks in the cache, so keep reading
           LOG("Stream %p reading since there are free blocks", stream);
           enableReading = true;
         } else if (latestNextUse <= TimeDuration(0)) {
@@ -2257,28 +2255,16 @@ MediaCacheStream::SeekInternal(int64_t a
 
   LOG("Stream %p Seek to %" PRId64, this, mStreamOffset);
   mMediaCache->NoteSeek(this, oldOffset);
 
   mMediaCache->QueueUpdate();
   return NS_OK;
 }
 
-void
-MediaCacheStream::ThrottleReadahead(bool bThrottle)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  if (mThrottleReadahead != bThrottle) {
-    LOGI("Stream %p ThrottleReadahead %d", this, bThrottle);
-    mThrottleReadahead = bThrottle;
-    ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
-    mMediaCache->QueueUpdate();
-  }
-}
-
 int64_t
 MediaCacheStream::Tell()
 {
   ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
   return mStreamOffset;
 }
 
 nsresult
--- a/dom/media/MediaCache.h
+++ b/dom/media/MediaCache.h
@@ -339,18 +339,16 @@ public:
   // Seeks to aOffset in the stream then performs a Read operation.
   // *aBytes gets the number of bytes that were actually read. This can
   // be less than aCount. If the first byte of data is not in the cache,
   // this will block until the data is available or the stream is
   // closed, otherwise it won't block.
   nsresult ReadAt(int64_t aOffset, char* aBuffer,
                   uint32_t aCount, uint32_t* aBytes);
 
-  void ThrottleReadahead(bool bThrottle);
-
   size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const;
 
 private:
   friend class MediaCache;
 
   /**
    * A doubly-linked list of blocks. Add/Remove/Get methods are all
    * constant time. We declare this here so that a stream can contain a
@@ -515,15 +513,13 @@ private:
   // mChannelOffset%BLOCK_SIZE bytes have been filled in with good data,
   // the rest are garbage.
   // Heap allocate this buffer since the exact power-of-2 will cause allocation
   // slop when combined with the rest of the object members.
   UniquePtr<uint8_t[]> mPartialBlockBuffer = MakeUnique<uint8_t[]>(BLOCK_SIZE);
 
   // True if associated with a private browsing window.
   const bool mIsPrivateBrowsing;
-
-  bool mThrottleReadahead = false;
 };
 
 } // namespace mozilla
 
 #endif
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -876,56 +876,23 @@ MediaDecoder::NotifySuspendedStatusChang
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
   if (mResource) {
     bool suspended = mResource->IsSuspendedByCache();
     GetOwner()->NotifySuspendedByCache(suspended);
   }
 }
 
-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;
-  }
-  uint32_t factor =
-    std::max(2u, Preferences::GetUint("media.throttle-factor", 2));
-  return stats.mDownloadRate > factor * stats.mPlaybackRate;
-}
-
 void
 MediaDecoder::DownloadProgressed()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
   UpdatePlaybackRate();
   GetOwner()->DownloadProgressed();
-  mResource->ThrottleReadahead(ShouldThrottleDownload());
 }
 
 void
 MediaDecoder::NotifyDownloadEnded(nsresult aStatus)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
 
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -641,18 +641,16 @@ protected:
 
   // Ensures our media stream has been unpinned.
   void UnpinForSeek();
 
   const char* PlayStateStr();
 
   void OnMetadataUpdate(TimedMetadata&& aMetadata);
 
-  bool ShouldThrottleDownload();
-
   // This should only ever be accessed from the main thread.
   // It is set in the constructor and cleared in Shutdown when the element goes
   // away. The decoder does not add a reference the element.
   MediaDecoderOwner* mOwner;
 
   // The AbstractThread from mOwner.
   const RefPtr<AbstractThread> mAbstractMainThread;
 
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -718,22 +718,16 @@ nsresult ChannelMediaResource::ReadAt(in
 
   nsresult rv = mCacheStream.ReadAt(aOffset, aBuffer, aCount, aBytes);
   if (NS_SUCCEEDED(rv)) {
     DispatchBytesConsumed(*aBytes, aOffset);
   }
   return rv;
 }
 
-void
-ChannelMediaResource::ThrottleReadahead(bool bThrottle)
-{
-  mCacheStream.ThrottleReadahead(bThrottle);
-}
-
 int64_t ChannelMediaResource::Tell()
 {
   return mCacheStream.Tell();
 }
 
 nsresult ChannelMediaResource::GetCachedRanges(MediaByteRangeSet& aRanges)
 {
   return mCacheStream.GetCachedRanges(aRanges);
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -210,21 +210,16 @@ public:
     bool ok = bytes->SetLength(aCount, fallible);
     NS_ENSURE_TRUE(ok, nullptr);
     char* curr = reinterpret_cast<char*>(bytes->Elements());
     nsresult rv = ReadFromCache(curr, aOffset, aCount);
     NS_ENSURE_SUCCESS(rv, nullptr);
     return bytes.forget();
   }
 
-  // Pass true to limit the amount of readahead data (specified by
-  // "media.cache_readahead_limit") or false to read as much as the
-  // cache size allows.
-  virtual void ThrottleReadahead(bool bThrottle) { }
-
   // Report the current offset in bytes from the start of the stream.
   // This is used to approximate where we currently are in the playback of a
   // media.
   // A call to ReadAt will update this position.
   virtual int64_t Tell() = 0;
   // Moves any existing channel loads into or out of background. Background
   // loads don't block the load event. This also determines whether or not any
   // new loads initiated (for example to seek) will be in the background.
@@ -498,18 +493,16 @@ public:
   // MediaCacheStream::NotifyDataReceived/Ended.
   // This can fail.
   nsresult CacheClientSeek(int64_t aOffset, bool aResume);
   // Suspend the current load since data is currently not wanted
   nsresult CacheClientSuspend();
   // Resume the current load since data is wanted again
   nsresult CacheClientResume();
 
-  void ThrottleReadahead(bool bThrottle) override;
-
   // Main thread
   nsresult Open(nsIStreamListener** aStreamListener) override;
   nsresult Close() override;
   void     Suspend(bool aCloseImmediately) override;
   void     Resume() override;
   already_AddRefed<nsIPrincipal> GetCurrentPrincipal() override;
   // Return true if the stream has been closed.
   bool     IsClosed() const { return mCacheStream.IsClosed(); }
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -593,19 +593,16 @@ pref("browser.meta_refresh_when_inactive
 // 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
 pref("media.cache_size", 32768);    // 32MB media cache
 // Try to save battery by not resuming reading from a connection until we fall
 // below 10s of buffered data.
 pref("media.cache_resume_threshold", 10);
 pref("media.cache_readahead_limit", 30);
-// 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);
 
 // 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);
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -316,46 +316,34 @@ pref("mathml.disabled",    false);
 pref("mathml.scale_stretchy_operators.enabled", true);
 
 pref("media.dormant-on-pause-timeout-ms", 5000);
 
 // File-backed MediaCache size in kilobytes
 pref("media.cache_size", 512000);
 // When a network connection is suspended, don't resume it until the
 // amount of buffered data falls below this threshold (in seconds).
-pref("media.cache_resume_threshold", 30);
+pref("media.cache_resume_threshold", 999999);
 // Stop reading ahead when our buffered data is this many seconds ahead
 // of the current playback position. This limit can stop us from using arbitrary
 // amounts of network bandwidth prefetching huge videos.
-pref("media.cache_readahead_limit", 60);
+pref("media.cache_readahead_limit", 999999);
 // If a resource is known to be smaller than this size (in kilobytes), a
 // memory-backed MediaCache may be used; otherwise the (single shared
 // global) file-backed MediaCache is used.
 pref("media.memory_cache_max_size", 8192);
 // Don't create more memory-backed MediaCaches if their combined size would go
 // above the lowest limit (in kilobytes or in percent of physical memory size).
 pref("media.memory_caches_combined_limit_kb", 524288);
 pref("media.memory_caches_combined_limit_pc_sysmem", 5);
 
 // Cache size hint (in bytes) for each MediaResourceIndex.
 // 0 -> no cache. Will use next power of 2, clamped to 32B-128KB.
 pref("media.cache.resource-index", 8192);
 
-// We'll throttle the download if the download rate is throttle-factor times
-// the estimated playback rate, AND we satisfy the cache readahead_limit
-// above. The estimated playback rate is time_duration/length_in_bytes.
-// This means we'll only throttle the download if there's no concern that
-// throttling would cause us to stop and buffer.
-pref("media.throttle-factor", 2);
-// By default, we'll throttle media download once we've reached the the
-// readahead_limit if the download is fast. This pref toggles the "and the
-// download is fast" check off, so that we can always throttle the download
-// once the readaheadd limit is reached even on a slow network.
-pref("media.throttle-regardless-of-download-rate", false);
-
 // Master HTML5 media volume scale.
 pref("media.volume_scale", "1.0");
 
 // Timeout for wakelock release
 pref("media.wakelock_timeout", 2000);
 
 // Whether we should play videos opened in a "video document", i.e. videos
 // opened as top-level documents, as opposed to inside a media element.