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
--- 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();
}
}