Bug 1399751. P3 - pass the offset of range request to ChannelMediaResource::OnStartRequest(). draft
authorJW Wang <jwwang@mozilla.com>
Thu, 14 Sep 2017 14:33:15 +0800
changeset 665186 a702c9fc35dfef0389f9e1627d2739973d281633
parent 665185 49aab0220d67918fc7f570dba98b4b4f732dea5a
child 665331 714acc418092a8c77ef4e75480dd5afab6fa76f0
push id79953
push userjwwang@mozilla.com
push dateFri, 15 Sep 2017 00:49:52 +0000
bugs1399751
milestone57.0a1
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
dom/media/MediaResource.cpp
dom/media/MediaResource.h
--- 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);