Bug 1415766. P2 - move Seek() to private and tighten up some assertions.
MozReview-Commit-ID: BBsXqKUrOi1
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -2410,28 +2410,28 @@ MediaCacheStream::SetPlaybackRate(uint32
return;
mPlaybackBytesPerSecond = aBytesPerSecond;
mMediaCache->QueueUpdate();
}
nsresult
MediaCacheStream::Seek(int64_t aOffset)
{
- NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
+ MOZ_ASSERT(!NS_IsMainThread());
+ mMediaCache->GetReentrantMonitor().AssertCurrentThreadIn();
- ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
- if (mClosed) {
- return NS_ERROR_FAILURE;
+ if (!IsOffsetAllowed(aOffset)) {
+ return NS_ERROR_ILLEGAL_VALUE;
}
+ if (mClosed) {
+ return NS_ERROR_ABORT;
+ }
+
int64_t oldOffset = mStreamOffset;
- int64_t newOffset = aOffset;
- if (!IsOffsetAllowed(newOffset)) {
- return NS_ERROR_FAILURE;
- }
- mStreamOffset = newOffset;
+ mStreamOffset = aOffset;
LOG("Stream %p Seek to %" PRId64, this, mStreamOffset);
mMediaCache->NoteSeek(this, oldOffset);
mMediaCache->QueueUpdate();
return NS_OK;
}
void
MediaCacheStream::ThrottleReadahead(bool bThrottle)
--- a/dom/media/MediaCache.h
+++ b/dom/media/MediaCache.h
@@ -334,17 +334,16 @@ public:
// Returns true when all streams for this resource are suspended or their
// channel has ended.
bool AreAllStreamsForResourceSuspended();
// These methods must be called on a different thread from the main
// thread. They should always be called on the same thread for a given
// stream.
- nsresult Seek(int64_t aOffset);
int64_t Tell();
// *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 Read(char* aBuffer, uint32_t aCount, uint32_t* aBytes);
// Seeks to aOffset in the stream then performs a Read operation. See
// 'Read' for argument and return details.
@@ -428,16 +427,19 @@ private:
// is nothing to read.
uint32_t ReadPartialBlock(int64_t aOffset, Span<char> aBuffer);
// Read data from the cache block specified by aOffset. Return the number of
// bytes read successfully or an error code if any failure.
Result<uint32_t, nsresult> ReadBlockFromCache(int64_t aOffset,
Span<char> aBuffer);
+ // Non-main thread only.
+ nsresult Seek(int64_t aOffset);
+
// Returns the end of the bytes starting at the given offset
// which are in cache.
// This method assumes that the cache monitor is held and can be called on
// any thread.
int64_t GetCachedDataEndInternal(int64_t aOffset);
// Returns the offset of the first byte of cached data at or after aOffset,
// or -1 if there is no such cached data.
// This method assumes that the cache monitor is held and can be called on