diff --git a/dom/media/MediaResource.h b/dom/media/MediaResource.h index f01da1707547..2601eb62f20f 100644 --- a/dom/media/MediaResource.h +++ b/dom/media/MediaResource.h @@ -175,17 +175,6 @@ public: // each read. virtual bool ShouldCacheReads() = 0; - already_AddRefed CachedReadAt(int64_t aOffset, uint32_t aCount) - { - RefPtr bytes = new MediaByteBuffer(); - bool ok = bytes->SetLength(aCount, fallible); - NS_ENSURE_TRUE(ok, nullptr); - char* curr = reinterpret_cast(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. @@ -777,6 +766,19 @@ public: bytes->SetLength(curr - start); return bytes.forget(); } + + already_AddRefed CachedMediaReadAt(int64_t aOffset, + uint32_t aCount) const + { + RefPtr bytes = new MediaByteBuffer(); + bool ok = bytes->SetLength(aCount, fallible); + NS_ENSURE_TRUE(ok, nullptr); + char* curr = reinterpret_cast(bytes->Elements()); + nsresult rv = mResource->ReadFromCache(curr, aOffset, aCount); + NS_ENSURE_SUCCESS(rv, nullptr); + return bytes.forget(); + } + // Get the length of the stream in bytes. Returns -1 if not known. // This can change over time; after a seek operation, a misbehaving // server may give us a resource of a different length to what it had diff --git a/dom/media/webm/WebMBufferedParser.cpp b/dom/media/webm/WebMBufferedParser.cpp index 0f7bc61cdb48..f6cea14cd6df 100644 --- a/dom/media/webm/WebMBufferedParser.cpp +++ b/dom/media/webm/WebMBufferedParser.cpp @@ -446,10 +446,12 @@ void WebMBufferedState::UpdateIndex(const MediaByteRangeSet& aRanges, MediaResou } } } + + MediaResourceIndex res(aResource); while (length > 0) { static const uint32_t BLOCK_SIZE = 1048576; uint32_t block = std::min(length, BLOCK_SIZE); - RefPtr bytes = aResource->CachedReadAt(offset, block); + RefPtr bytes = res.CachedMediaReadAt(offset, block); if (!bytes) { break; }