Bug 1424937 - read as many bytes as possible before giving up reading due to download ends abnormally. r=bechen,gerald
authorJW Wang <jwwang@mozilla.com>
Wed, 13 Dec 2017 18:28:16 +0800
changeset 396255 358f1c414f3ed3b6c7a08a131032155e4c467938
parent 396254 cc95b6d1680b26b327c7c430082eb6bc45982d18
child 396256 bb00bf981b4ec47476310050835501a84e93bbfb
push id56961
push userjwwang@mozilla.com
push dateWed, 13 Dec 2017 23:38:13 +0000
treeherderautoland@358f1c414f3e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbechen, gerald
bugs1424937
milestone59.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 1424937 - read as many bytes as possible before giving up reading due to download ends abnormally. r=bechen,gerald MozReview-Commit-ID: 39vdgyY5NCT
dom/media/MediaCache.cpp
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -2679,21 +2679,16 @@ MediaCacheStream::Read(char* aBuffer, ui
   auto buffer = MakeSpan<char>(aBuffer, aCount);
 
   // Read one block (or part of a block) at a time
   while (!buffer.IsEmpty()) {
     if (mClosed) {
       return NS_ERROR_ABORT;
     }
 
-    if (mDidNotifyDataEnded && NS_FAILED(mNotifyDataEndedStatus)) {
-      // Abort reading since download ends abnormally.
-      return NS_ERROR_FAILURE;
-    }
-
     if (!IsOffsetAllowed(streamOffset)) {
       LOGE("Stream %p invalid offset=%" PRId64, this, streamOffset);
       return NS_ERROR_ILLEGAL_VALUE;
     }
 
     if (mStreamLength >= 0 && streamOffset >= mStreamLength) {
       // Don't try to read beyond the end of the stream
       break;
@@ -2729,16 +2724,26 @@ MediaCacheStream::Read(char* aBuffer, ui
         break;
       }
     }
     if (foundDataInPartialBlock) {
       // Break for we've reached EOS.
       break;
     }
 
+    if (mDidNotifyDataEnded && NS_FAILED(mNotifyDataEndedStatus)) {
+      // Since download ends abnormally, there is no point in waiting for new
+      // data to come. We will check the partial block to read as many bytes as
+      // possible before exiting this function.
+      bytes = ReadPartialBlock(lock, streamOffset, buffer);
+      streamOffset += bytes;
+      buffer = buffer.From(bytes);
+      break;
+    }
+
     if (mStreamOffset != streamOffset) {
       // Update mStreamOffset before we drop the lock. We need to run
       // Update() again since stream reading strategy might have changed.
       mStreamOffset = streamOffset;
       mMediaCache->QueueUpdate(lock);
     }
 
     // No data to read, so block