Bug 1227396: P2. Rename some MediaByteRange methods. r=cpearce
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 24 Nov 2015 16:26:38 +1100
changeset 274532 fb6bf94d90846562c3bafc7f2e8e3157282d74c2
parent 274531 043380f2cc5764d1ac91e701b7038720b46ad26f
child 274533 c5689e8fe1e442de8d8cd8bb2843cef34c8eac11
push id68621
push userjyavenard@mozilla.com
push dateMon, 30 Nov 2015 00:49:17 +0000
treeherdermozilla-inbound@fd4d78b89cc0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1227396
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1227396: P2. Rename some MediaByteRange methods. r=cpearce Will facilitate the replacement of MediaByteRange by Interval<int64_t>
dom/media/MediaResource.cpp
dom/media/MediaResource.h
dom/media/mediasource/ContainerParser.cpp
dom/media/mediasource/TrackBuffersManager.cpp
media/libstagefright/binding/Index.cpp
media/libstagefright/binding/MoofParser.cpp
media/libstagefright/binding/include/mp4_demuxer/Box.h
media/libstagefright/gtest/TestParser.cpp
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -231,17 +231,17 @@ ChannelMediaResource::OnStartRequest(nsI
       // Since that's bounded, we know we have a finite-length resource.
       dataIsBounded = true;
     }
 
     // Assume Range requests have a bounded upper limit unless the
     // Content-Range header tells us otherwise.
     bool boundedSeekLimit = true;
     // Check response code for byte-range requests (seeking, chunk requests).
-    if (!mByteRange.IsNull() && (responseStatus == HTTP_PARTIAL_RESPONSE_CODE)) {
+    if (!mByteRange.IsEmpty() && (responseStatus == HTTP_PARTIAL_RESPONSE_CODE)) {
       // Parse Content-Range header.
       int64_t rangeStart = 0;
       int64_t rangeEnd = 0;
       int64_t rangeTotal = 0;
       rv = ParseContentRangeHeader(hc, rangeStart, rangeEnd, rangeTotal);
       if (NS_FAILED(rv)) {
         // Content-Range header text should be parse-able.
         CMLOG("Error processing \'Content-Range' for "
@@ -268,17 +268,17 @@ ChannelMediaResource::OnStartRequest(nsI
       } else {
         mCacheStream.NotifyDataLength(rangeTotal);
       }
       mCacheStream.NotifyDataStarted(rangeStart);
 
       mOffset = rangeStart;
       // We received 'Content-Range', so the server accepts range requests.
       acceptsRanges = true;
-    } else if (((mOffset > 0) || !mByteRange.IsNull())
+    } else if (((mOffset > 0) || !mByteRange.IsEmpty())
                && (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.
@@ -529,17 +529,17 @@ 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.IsNull()) {
+  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) {
@@ -578,24 +578,24 @@ nsresult ChannelMediaResource::SetupChan
   // 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.
     nsAutoCString rangeString("bytes=");
-    if (!mByteRange.IsNull()) {
+    if (!mByteRange.IsEmpty()) {
       rangeString.AppendInt(mByteRange.mStart);
       mOffset = mByteRange.mStart;
     } else {
       rangeString.AppendInt(mOffset);
     }
     rangeString.Append('-');
-    if (!mByteRange.IsNull()) {
+    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();
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -135,17 +135,17 @@ public:
   MediaByteRange() : mStart(0), mEnd(0) {}
 
   MediaByteRange(int64_t aStart, int64_t aEnd)
     : mStart(aStart), mEnd(aEnd)
   {
     NS_ASSERTION(mStart <= mEnd, "Range should end after start!");
   }
 
-  bool IsNull() const {
+  bool IsEmpty() const {
     return mStart == 0 && mEnd == 0;
   }
 
   bool operator==(const MediaByteRange& aRange) const {
     return mStart == aRange.mStart && mEnd == aRange.mEnd;
   }
 
   // Clears byte range values.
@@ -153,18 +153,18 @@ public:
     mStart = 0;
     mEnd = 0;
   }
 
   bool Contains(const MediaByteRange& aByteRange) const {
     return aByteRange.mStart >= mStart && aByteRange.mEnd <= mEnd;
   }
 
-  MediaByteRange Extents(const MediaByteRange& aByteRange) const {
-    if (IsNull()) {
+  MediaByteRange Span(const MediaByteRange& aByteRange) const {
+    if (IsEmpty()) {
       return aByteRange;
     }
     return MediaByteRange(std::min(mStart, aByteRange.mStart),
                           std::max(mEnd, aByteRange.mEnd));
   }
 
   int64_t Length() const {
     return mEnd - mStart;
--- a/dom/media/mediasource/ContainerParser.cpp
+++ b/dom/media/mediasource/ContainerParser.cpp
@@ -262,17 +262,17 @@ public:
     mOverlappedMapping.AppendElements(mapping.Elements() + completeIdx + 1,
                                       mapping.Length() - completeIdx - 1);
 
     if (completeIdx < 0) {
       mLastMapping.reset();
       return false;
     }
 
-    if (mCompleteMediaHeaderRange.IsNull()) {
+    if (mCompleteMediaHeaderRange.IsEmpty()) {
       mCompleteMediaHeaderRange = MediaByteRange(mapping[0].mSyncOffset,
                                                  mapping[0].mEndOffset);
     }
 
     if (foundNewCluster && mOffset >= mapping[endIdx].mEndOffset) {
       // We now have all information required to delimit a complete cluster.
       int64_t endOffset = mapping[endIdx+1].mSyncOffset;
       if (mapping[endIdx+1].mInitOffset > mapping[endIdx].mInitOffset) {
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -675,17 +675,17 @@ TrackBuffersManager::SegmentParserLoop()
 
     int64_t start, end;
     bool newData = mParser->ParseStartAndEndTimestamps(mInputBuffer, start, end);
     mProcessedInput += mInputBuffer->Length();
 
     // 5. If the append state equals PARSING_INIT_SEGMENT, then run the
     // following steps:
     if (mAppendState == AppendState::PARSING_INIT_SEGMENT) {
-      if (mParser->InitSegmentRange().IsNull()) {
+      if (mParser->InitSegmentRange().IsEmpty()) {
         mInputBuffer = nullptr;
         NeedMoreData();
         return;
       }
       InitializationSegmentReceived();
       return;
     }
     if (mAppendState == AppendState::PARSING_MEDIA_SEGMENT) {
@@ -702,17 +702,17 @@ TrackBuffersManager::SegmentParserLoop()
       // monotonically increasing data.
       if (mNewMediaSegmentStarted) {
         if (newData && mLastParsedEndTime.isSome() &&
             start < mLastParsedEndTime.ref().ToMicroseconds()) {
           MSE_DEBUG("Re-creating demuxer");
           ResetDemuxingState();
           return;
         }
-        if (newData || !mParser->MediaSegmentRange().IsNull()) {
+        if (newData || !mParser->MediaSegmentRange().IsEmpty()) {
           if (mPendingInputBuffer) {
             // We now have a complete media segment header. We can resume parsing
             // the data.
             AppendDataToCurrentInputBuffer(mPendingInputBuffer);
             mPendingInputBuffer = nullptr;
           }
           mNewMediaSegmentStarted = false;
         } else {
@@ -1130,17 +1130,17 @@ TrackBuffersManager::OnDemuxerInitFailed
 
 RefPtr<TrackBuffersManager::CodedFrameProcessingPromise>
 TrackBuffersManager::CodedFrameProcessing()
 {
   MOZ_ASSERT(OnTaskQueue());
   MOZ_ASSERT(mProcessingPromise.IsEmpty());
 
   MediaByteRange mediaRange = mParser->MediaSegmentRange();
-  if (mediaRange.IsNull()) {
+  if (mediaRange.IsEmpty()) {
     AppendDataToCurrentInputBuffer(mInputBuffer);
     mInputBuffer = nullptr;
   } else {
     MOZ_ASSERT(mProcessedInput >= mInputBuffer->Length());
     if (int64_t(mProcessedInput - mInputBuffer->Length()) > mediaRange.mEnd) {
       // Something is not quite right with the data appended. Refuse it.
       // This would typically happen if the previous media segment was partial
       // yet a new complete media segment was added.
@@ -1304,17 +1304,17 @@ TrackBuffersManager::CompleteCodedFrameP
   // Return to step 6.4 of Segment Parser Loop algorithm
   // 4. If this SourceBuffer is full and cannot accept more media data, then set the buffer full flag to true.
   if (mSizeSourceBuffer >= mEvictionThreshold) {
     mBufferFull = true;
     mEvictionOccurred = false;
   }
 
   // 5. If the input buffer does not contain a complete media segment, then jump to the need more data step below.
-  if (mParser->MediaSegmentRange().IsNull()) {
+  if (mParser->MediaSegmentRange().IsEmpty()) {
     ResolveProcessing(true, __func__);
     return;
   }
 
   mLastParsedEndTime = Some(std::max(mAudioTracks.mLastParsedEndTime,
                                      mVideoTracks.mLastParsedEndTime));
 
   // 6. Remove the media segment bytes from the beginning of the input buffer.
--- a/media/libstagefright/binding/Index.cpp
+++ b/media/libstagefright/binding/Index.cpp
@@ -112,17 +112,17 @@ already_AddRefed<MediaRawData> SampleIte
   }
 
   size_t bytesRead;
   if (!mIndex->mSource->ReadAt(sample->mOffset, writer->Data(), sample->Size(),
                                &bytesRead) || bytesRead != sample->Size()) {
     return nullptr;
   }
 
-  if (!s->mCencRange.IsNull()) {
+  if (!s->mCencRange.IsEmpty()) {
     MoofParser* parser = mIndex->mMoofParser.get();
 
     if (!parser || !parser->mSinf.IsValid()) {
       return nullptr;
     }
 
     uint8_t ivSize = parser->mSinf.mDefaultIVSize;
 
--- a/media/libstagefright/binding/MoofParser.cpp
+++ b/media/libstagefright/binding/MoofParser.cpp
@@ -36,17 +36,17 @@ MoofParser::RebuildFragmentedIndex(
 
 bool
 MoofParser::RebuildFragmentedIndex(BoxContext& aContext)
 {
   bool foundValidMoof = false;
   bool foundMdat = false;
 
   for (Box box(&aContext, mOffset); box.IsAvailable(); box = box.Next()) {
-    if (box.IsType("moov") && mInitRange.IsNull()) {
+    if (box.IsType("moov") && mInitRange.IsEmpty()) {
       mInitRange = MediaByteRange(0, box.Range().mEnd);
       ParseMoov(box);
     } else if (box.IsType("moof")) {
       Moof moof(box, mTrex, mMvhd, mMdhd, mEdts, mSinf, mIsAudio);
 
       if (!moof.IsValid() && !box.Next().IsAvailable()) {
         // Moof isn't valid abort search for now.
         break;
@@ -63,17 +63,17 @@ MoofParser::RebuildFragmentedIndex(BoxCo
       foundValidMoof = true;
     } else if (box.IsType("mdat") && !Moofs().IsEmpty()) {
       // Check if we have all our data from last moof.
       Moof& moof = Moofs().LastElement();
       media::Interval<int64_t> datarange(moof.mMdatRange.mStart, moof.mMdatRange.mEnd, 0);
       media::Interval<int64_t> mdat(box.Range().mStart, box.Range().mEnd, 0);
       if (datarange.Intersects(mdat)) {
         mMediaRanges.LastElement() =
-          mMediaRanges.LastElement().Extents(box.Range());
+          mMediaRanges.LastElement().Span(box.Range());
       }
     }
     mOffset = box.NextOffset();
   }
   return foundValidMoof;
 }
 
 MediaByteRange
@@ -159,17 +159,17 @@ MoofParser::ScanForMetadata(mozilla::Med
       aFtyp = box.Range();
       continue;
     }
     if (box.IsType("moov")) {
       aMoov = box.Range();
       break;
     }
   }
-  mInitRange = aFtyp.Extents(aMoov);
+  mInitRange = aFtyp.Span(aMoov);
 }
 
 bool
 MoofParser::HasMetadata()
 {
   MediaByteRange ftyp;
   MediaByteRange moov;
   ScanForMetadata(ftyp, moov);
@@ -554,17 +554,17 @@ Moof::ParseTrun(Box& aBox, Tfhd& aTfhd, 
 
     // Sometimes audio streams don't properly mark their samples as keyframes,
     // because every audio sample is a keyframe.
     sample.mSync = !(sampleFlags & 0x1010000) || aIsAudio;
 
     // FIXME: Make this infallible after bug 968520 is done.
     MOZ_ALWAYS_TRUE(mIndex.AppendElement(sample, fallible));
 
-    mMdatRange = mMdatRange.Extents(sample.mByteRange);
+    mMdatRange = mMdatRange.Span(sample.mByteRange);
   }
   mMaxRoundingError += aMdhd.ToMicroseconds(sampleCount);
 
   nsTArray<Sample*> ctsOrder;
   for (int i = 0; i < mIndex.Length(); i++) {
     ctsOrder.AppendElement(&mIndex[i]);
   }
   ctsOrder.Sort(CtsComparator());
--- a/media/libstagefright/binding/include/mp4_demuxer/Box.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/Box.h
@@ -33,17 +33,17 @@ public:
 };
 
 class Box
 {
 public:
   Box(BoxContext* aContext, uint64_t aOffset, const Box* aParent = nullptr);
   Box();
 
-  bool IsAvailable() const { return !mRange.IsNull(); }
+  bool IsAvailable() const { return !mRange.IsEmpty(); }
   uint64_t Offset() const { return mRange.mStart; }
   uint64_t Length() const { return mRange.mEnd - mRange.mStart; }
   uint64_t NextOffset() const { return mRange.mEnd; }
   const MediaByteRange& Range() const { return mRange; }
   const Box* Parent() const { return mParent; }
   bool IsType(const char* aType) const { return mType == AtomType(aType); }
 
   Box Next() const;
--- a/media/libstagefright/gtest/TestParser.cpp
+++ b/media/libstagefright/gtest/TestParser.cpp
@@ -102,24 +102,24 @@ TEST(stagefright_MoofParser, EmptyStream
   EXPECT_EQ(0u, parser.mOffset);
   EXPECT_TRUE(parser.ReachedEnd());
 
   nsTArray<MediaByteRange> byteRanges;
   byteRanges.AppendElement(MediaByteRange(0, 0));
   EXPECT_FALSE(parser.RebuildFragmentedIndex(byteRanges));
 
   EXPECT_TRUE(parser.GetCompositionRange(byteRanges).IsNull());
-  EXPECT_TRUE(parser.mInitRange.IsNull());
+  EXPECT_TRUE(parser.mInitRange.IsEmpty());
   EXPECT_EQ(0u, parser.mOffset);
   EXPECT_TRUE(parser.ReachedEnd());
   EXPECT_FALSE(parser.HasMetadata());
   RefPtr<MediaByteBuffer> metadataBuffer = parser.Metadata();
   EXPECT_FALSE(metadataBuffer);
-  EXPECT_TRUE(parser.FirstCompleteMediaSegment().IsNull());
-  EXPECT_TRUE(parser.FirstCompleteMediaHeader().IsNull());
+  EXPECT_TRUE(parser.FirstCompleteMediaSegment().IsEmpty());
+  EXPECT_TRUE(parser.FirstCompleteMediaHeader().IsEmpty());
 }
 
 nsTArray<uint8_t>
 ReadTestFile(const char* aFilename)
 {
   if (!aFilename) {
     return {};
   }
@@ -292,24 +292,24 @@ TEST(stagefright_MoofParser, test_case_m
     EXPECT_EQ(0u, parser.mOffset);
     EXPECT_FALSE(parser.ReachedEnd());
 
     nsTArray<MediaByteRange> byteRanges;
     byteRanges.AppendElement(MediaByteRange(0, 0));
     EXPECT_FALSE(parser.RebuildFragmentedIndex(byteRanges));
 
     EXPECT_TRUE(parser.GetCompositionRange(byteRanges).IsNull());
-    EXPECT_TRUE(parser.mInitRange.IsNull());
+    EXPECT_TRUE(parser.mInitRange.IsEmpty());
     EXPECT_EQ(0u, parser.mOffset);
     EXPECT_FALSE(parser.ReachedEnd());
     EXPECT_TRUE(parser.HasMetadata());
     RefPtr<MediaByteBuffer> metadataBuffer = parser.Metadata();
     EXPECT_TRUE(metadataBuffer);
-    EXPECT_TRUE(parser.FirstCompleteMediaSegment().IsNull());
-    EXPECT_TRUE(parser.FirstCompleteMediaHeader().IsNull());
+    EXPECT_TRUE(parser.FirstCompleteMediaSegment().IsEmpty());
+    EXPECT_TRUE(parser.FirstCompleteMediaHeader().IsEmpty());
   }
 }
 
 // Bug 1224019: This test produces way to much output, disabling for now.
 #if 0
 TEST(stagefright_MoofParser, test_case_mp4_subsets)
 {
   const size_t step = 1u;