Bug 1413483 - add mPendingSeekOffset to store the seek offset initiated by the cache.
Seek() can't create a new channel if the resource is still suspended. we need
to store the seek offset specified by the cache so we know where to seek when
the resource is resumed.
Otherwise the new channel will download data at the wrong position and the
cache will need to run Update() and call CacheClientSeek() again which is
a waste.
MozReview-Commit-ID: 9OJ3FRnKitT
--- a/dom/media/ChannelMediaResource.cpp
+++ b/dom/media/ChannelMediaResource.cpp
@@ -737,19 +737,21 @@ ChannelMediaResource::Resume()
} else {
int64_t totalLength = GetLength();
// If mOffset is at the end of the stream, then we shouldn't try to
// seek to it. The seek will fail and be wasted anyway. We can leave
// the channel dead; if the media cache wants to read some other data
// in the future, it will call CacheClientSeek itself which will reopen the
// channel.
if (totalLength < 0 || GetOffset() < totalLength) {
- // There is (or may be) data to read at mOffset, so start reading it.
+ // There is (or may be) data to read, so start reading it.
// Need to recreate the channel.
- Seek(GetOffset(), false);
+ Seek(mPendingSeekOffset != -1 ? mPendingSeekOffset : GetOffset(),
+ false);
+ mPendingSeekOffset = -1;
element->DownloadResumed();
} else {
// The channel remains dead. Do not notify DownloadResumed() which
// will leave the media element in NETWORK_LOADING state.
}
}
}
}
@@ -894,19 +896,22 @@ ChannelMediaResource::Seek(int64_t aOffs
if (aResume) {
mSuspendAgent.Resume();
}
// Don't create a new channel if we are still suspended. The channel will
// be recreated when we are resumed.
if (mSuspendAgent.IsSuspended()) {
+ // Store the offset so we know where to seek when resumed.
+ mPendingSeekOffset = aOffset;
return NS_OK;
}
+ MOZ_DIAGNOSTIC_ASSERT(mPendingSeekOffset == -1);
nsresult rv = RecreateChannel();
NS_ENSURE_SUCCESS(rv, rv);
return OpenChannel(aOffset);
}
void
ChannelMediaResource::CacheClientSeek(int64_t aOffset, bool aResume)
--- a/dom/media/ChannelMediaResource.h
+++ b/dom/media/ChannelMediaResource.h
@@ -244,16 +244,19 @@ protected:
uint32_t* aWriteCount);
// Main thread access only
// True if Close() has been called.
bool mClosed = false;
RefPtr<Listener> mListener;
// A mono-increasing integer to uniquely identify the channel we are loading.
uint32_t mLoadID = 0;
+ // Used by the cache to store the offset to seek to when we are resumed.
+ // -1 means no seek initiated by the cache is waiting.
+ int64_t mPendingSeekOffset = -1;
// When this flag is set, if we get a network error we should silently
// reopen the stream.
bool mReopenOnError;
// Any thread access
MediaCacheStream mCacheStream;
MediaChannelStatistics mChannelStatistics;