Bug 1361964 - WebMBufferedState::UpdateIndex() should read from cache. draft
authorJW Wang <jwwang@mozilla.com>
Thu, 04 May 2017 21:32:13 +0800
changeset 573014 4e7504273945ac1fb009445d81f461784fb571af
parent 572442 b9151926f9cf72eec5dc8da45ecbdbcbee271508
child 573029 931681d969e5266114bda146cbb94d61edda60c9
push id57272
push userjwwang@mozilla.com
push dateFri, 05 May 2017 06:46:49 +0000
bugs1361964
milestone55.0a1
Bug 1361964 - WebMBufferedState::UpdateIndex() should read from cache. We don't want to trigger download when calculating buffer ranges since download changes buffer ranges. MozReview-Commit-ID: Be8qFUQ5PpR
dom/media/MediaResource.h
dom/media/webm/WebMBufferedParser.cpp
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -237,16 +237,27 @@ public:
       aOffset += bytesRead;
       aCount -= bytesRead;
       curr += bytesRead;
     }
     bytes->SetLength(curr - start);
     return bytes.forget();
   }
 
+  already_AddRefed<MediaByteBuffer> CachedReadAt(int64_t aOffset, uint32_t aCount)
+  {
+    RefPtr<MediaByteBuffer> bytes = new MediaByteBuffer();
+    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();
+  }
+
   // 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.
--- a/dom/media/webm/WebMBufferedParser.cpp
+++ b/dom/media/webm/WebMBufferedParser.cpp
@@ -444,17 +444,17 @@ void WebMBufferedState::UpdateIndex(cons
         if (idx) {
           mRangeParsers[idx].SetTimecodeScale(mRangeParsers[0].GetTimecodeScale());
         }
       }
     }
     while (length > 0) {
       static const uint32_t BLOCK_SIZE = 1048576;
       uint32_t block = std::min(length, BLOCK_SIZE);
-      RefPtr<MediaByteBuffer> bytes = aResource->MediaReadAt(offset, block);
+      RefPtr<MediaByteBuffer> bytes = aResource->CachedReadAt(offset, block);
       if (!bytes) {
         break;
       }
       NotifyDataArrived(bytes->Elements(), bytes->Length(), offset);
       length -= bytes->Length();
       offset += bytes->Length();
     }
   }