Bug 1251044: P2. Remove dead code and generalise the use of content-range header. r?roc draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 25 Feb 2016 17:51:12 +1100
changeset 334496 5955db23f2c2b62715af11aa310007d0f4cf7513
parent 334495 9812b6f0acf5d101a8ea1d7207d135923aabb0a3
child 514914 5741a8f090aeebff841f8e7b03a123ee1056d961
push id11553
push userbmo:jyavenard@mozilla.com
push dateThu, 25 Feb 2016 08:46:15 +0000
reviewersroc
bugs1251044
milestone47.0a1
Bug 1251044: P2. Remove dead code and generalise the use of content-range header. r?roc MozReview-Commit-ID: ESMlcBOQKsy
dom/media/MediaResource.cpp
dom/media/MediaResource.h
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -241,51 +241,35 @@ ChannelMediaResource::OnStartRequest(nsI
       int64_t rangeStart = 0;
       int64_t rangeEnd = 0;
       int64_t rangeTotal = 0;
       rv = ParseContentRangeHeader(hc, rangeStart, rangeEnd, rangeTotal);
 
       // We received 'Content-Range', so the server accepts range requests.
       bool gotRangeHeader = NS_SUCCEEDED(rv);
 
-      if (!mByteRange.IsEmpty()) {
-        if (!gotRangeHeader) {
-          // Content-Range header text should be parse-able when processing a
-          // range requests.
-          CMLOG("Error processing \'Content-Range' for "
-                "HTTP_PARTIAL_RESPONSE_CODE: rv[%x] channel[%p] decoder[%p]",
-                rv, hc.get(), mCallback.get());
-          mCallback->NotifyNetworkError();
-          CloseChannel();
-          return NS_OK;
-        }
-        // Give some warnings if the ranges are unexpected.
-        // XXX These could be error conditions.
-        NS_WARN_IF_FALSE(mByteRange.mStart == rangeStart,
-                         "response range start does not match request");
-        NS_WARN_IF_FALSE(mOffset == rangeStart,
-                         "response range start does not match current offset");
-        NS_WARN_IF_FALSE(mByteRange.mEnd == rangeEnd,
-                         "response range end does not match request");
+      if (gotRangeHeader) {
+        // We received 'Content-Range', so the server accepts range requests.
         // Notify media cache about the length and start offset of data received.
         // 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) {
           boundedSeekLimit = false;
         } else {
-          mCacheStream.NotifyDataLength(rangeTotal);
+          contentLength = std::max(contentLength, rangeTotal);
         }
+        // Give some warnings if the ranges are unexpected.
+        // XXX These could be error conditions.
+        NS_WARN_IF_FALSE(mOffset == rangeStart,
+                         "response range start does not match current offset");
+        mOffset = rangeStart;
         mCacheStream.NotifyDataStarted(rangeStart);
-        mOffset = rangeStart;
-      } else if (gotRangeHeader && rangeTotal > 0) {
-        contentLength = std::max(contentLength, rangeTotal);
       }
       acceptsRanges = gotRangeHeader;
-    } else if (((mOffset > 0) || !mByteRange.IsEmpty())
-               && (responseStatus == HTTP_OK_CODE)) {
+    } else if (mOffset > 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);
       mOffset = 0;
 
       // The server claimed it supported range requests.  It lied.
       acceptsRanges = false;
@@ -296,18 +280,17 @@ ChannelMediaResource::OnStartRequest(nsI
       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,
     // and the server isn't sending Accept-Ranges:bytes then we don't
     // support seeking.
-    seekable =
-      responseStatus == HTTP_PARTIAL_RESPONSE_CODE || acceptsRanges;
+    seekable = acceptsRanges;
     if (seekable && boundedSeekLimit) {
       // If range requests are supported, and we did not see an unbounded
       // upper range limit, we assume the resource is bounded.
       dataIsBounded = true;
     }
 
     mCallback->SetInfinite(!dataIsBounded);
   }
@@ -534,27 +517,25 @@ nsresult ChannelMediaResource::OpenChann
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
   NS_ENSURE_TRUE(mChannel, NS_ERROR_NULL_POINTER);
   NS_ASSERTION(!mListener, "Listener should have been removed by now");
 
   if (aStreamListener) {
     *aStreamListener = nullptr;
   }
 
-  if (mByteRange.IsEmpty()) {
-    // We're not making a byte range request, so set the content length,
-    // if it's available as an HTTP header. This ensures that MediaResource
-    // wrapping objects for platform libraries that expect to know
-    // the length of a resource can get it before OnStartRequest() fires.
-    nsCOMPtr<nsIHttpChannel> hc = do_QueryInterface(mChannel);
-    if (hc) {
-      int64_t cl = -1;
-      if (NS_SUCCEEDED(hc->GetContentLength(&cl)) && cl != -1) {
-        mCacheStream.NotifyDataLength(cl);
-      }
+  // Set the content length, if it's available as an HTTP header.
+  // This ensures that MediaResource wrapping objects for platform libraries
+  // that expect to know the length of a resource can get it before
+  // OnStartRequest() fires.
+  nsCOMPtr<nsIHttpChannel> hc = do_QueryInterface(mChannel);
+  if (hc) {
+    int64_t cl = -1;
+    if (NS_SUCCEEDED(hc->GetContentLength(&cl)) && cl != -1) {
+      mCacheStream.NotifyDataLength(cl);
     }
   }
 
   mListener = new Listener(this);
   if (aStreamListener) {
     *aStreamListener = mListener;
     NS_ADDREF(*aStreamListener);
   } else {
@@ -580,29 +561,20 @@ nsresult ChannelMediaResource::OpenChann
 nsresult ChannelMediaResource::SetupChannelHeaders()
 {
   // Always use a byte range request even if we're reading from the start
   // of the resource.
   // This enables us to detect if the stream supports byte range
   // requests, and therefore seeking, early.
   nsCOMPtr<nsIHttpChannel> hc = do_QueryInterface(mChannel);
   if (hc) {
-    // Use |mByteRange| for a specific chunk, or |mOffset| if seeking in a
-    // complete file download.
+    // Use |mOffset| if seeking in a complete file download.
     nsAutoCString rangeString("bytes=");
-    if (!mByteRange.IsEmpty()) {
-      rangeString.AppendInt(mByteRange.mStart);
-      mOffset = mByteRange.mStart;
-    } else {
-      rangeString.AppendInt(mOffset);
-    }
+    rangeString.AppendInt(mOffset);
     rangeString.Append('-');
-    if (!mByteRange.IsEmpty()) {
-      rangeString.AppendInt(mByteRange.mEnd);
-    }
     nsresult rv = hc->SetRequestHeader(NS_LITERAL_CSTRING("Range"), rangeString, false);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Send Accept header for video and audio types only (Bug 489071)
     NS_ASSERTION(NS_IsMainThread(), "Don't call on non-main thread");
     MediaDecoderOwner* owner = mCallback->GetMediaOwner();
     NS_ENSURE_TRUE(owner, NS_ERROR_FAILURE);
     dom::HTMLMediaElement* element = owner->GetMediaElement();
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -695,19 +695,16 @@ protected:
   Mutex               mLock;
   RefPtr<MediaChannelStatistics> mChannelStatistics;
 
   // True if we couldn't suspend the stream and we therefore don't want
   // to resume later. This is usually due to the channel not being in the
   // isPending state at the time of the suspend request.
   bool mIgnoreResume;
 
-  // Start and end offset of the bytes to be requested.
-  MediaByteRange mByteRange;
-
   // True if the stream can seek into unbuffered ranged, i.e. if the
   // connection supports byte range requests.
   bool mIsTransportSeekable;
 
   ChannelSuspendAgent mSuspendAgent;
 };
 
 /**