Bug 1399751. P3 - pass the offset of range request to ChannelMediaResource::OnStartRequest().
So we don't have to look at GetOffset(). We want to reduce the use of
MediaCacheStream::mChannelOffset so it is easier to fix data races about it.
MozReview-Commit-ID: 3GAbKYA9xi4
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -119,17 +119,17 @@ NS_IMPL_ISUPPORTS(ChannelMediaResource::
nsIThreadRetargetableStreamListener)
nsresult
ChannelMediaResource::Listener::OnStartRequest(nsIRequest* aRequest,
nsISupports* aContext)
{
if (!mResource)
return NS_OK;
- return mResource->OnStartRequest(aRequest);
+ return mResource->OnStartRequest(aRequest, mOffset);
}
nsresult
ChannelMediaResource::Listener::OnStopRequest(nsIRequest* aRequest,
nsISupports* aContext,
nsresult aStatus)
{
if (!mResource)
@@ -185,17 +185,18 @@ static bool
IsPayloadCompressed(nsIHttpChannel* aChannel)
{
nsAutoCString encoding;
Unused << aChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Encoding"), encoding);
return encoding.Length() > 0;
}
nsresult
-ChannelMediaResource::OnStartRequest(nsIRequest* aRequest)
+ChannelMediaResource::OnStartRequest(nsIRequest* aRequest,
+ int64_t aRequestOffset)
{
NS_ASSERTION(mChannel.get() == aRequest, "Wrong channel!");
MediaDecoderOwner* owner = mCallback->GetMediaOwner();
NS_ENSURE_TRUE(owner, NS_ERROR_FAILURE);
dom::HTMLMediaElement* element = owner->GetMediaElement();
NS_ENSURE_TRUE(element, NS_ERROR_FAILURE);
nsresult status;
@@ -283,26 +284,26 @@ ChannelMediaResource::OnStartRequest(nsI
// Note: If aRangeTotal == -1, then the total bytes is unknown at this stage.
// For now, tell the decoder that the stream is infinite.
if (rangeTotal != -1) {
contentLength = std::max(contentLength, rangeTotal);
}
mCacheStream.NotifyDataStarted(rangeStart);
}
acceptsRanges = gotRangeHeader;
- } else if (GetOffset() > 0 && responseStatus == HTTP_OK_CODE) {
+ } else if (aRequestOffset > 0 && responseStatus == HTTP_OK_CODE) {
// If we get an OK response but we were seeking, or requesting a byte
// range, then we have to assume that seeking doesn't work. We also need
// to tell the cache that it's getting data for the start of the stream.
mCacheStream.NotifyDataStarted(0);
// The server claimed it supported range requests. It lied.
acceptsRanges = false;
}
- if (GetOffset() == 0 && contentLength >= 0 &&
+ if (aRequestOffset == 0 && contentLength >= 0 &&
(responseStatus == HTTP_OK_CODE ||
responseStatus == HTTP_PARTIAL_RESPONSE_CODE)) {
mCacheStream.NotifyDataLength(contentLength);
}
// XXX we probably should examine the Content-Range header in case
// the server gave us a range which is not quite what we asked for
// If we get an HTTP_OK_CODE response to our byte range request,
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -528,17 +528,17 @@ public:
};
friend class Listener;
nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override;
protected:
bool IsSuspendedByCache();
// These are called on the main thread by Listener.
- nsresult OnStartRequest(nsIRequest* aRequest);
+ nsresult OnStartRequest(nsIRequest* aRequest, int64_t aRequestOffset);
nsresult OnStopRequest(nsIRequest* aRequest, nsresult aStatus);
nsresult OnDataAvailable(nsIRequest* aRequest,
nsIInputStream* aStream,
uint32_t aCount);
nsresult OnChannelRedirect(nsIChannel* aOld,
nsIChannel* aNew,
uint32_t aFlags,
int64_t aOffset);