From c8c275cee2b774750557c15800c75792f653f162 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Tue, 24 Nov 2015 20:16:52 +1100 Subject: [PATCH] Bug 1227396: P7. Replace nsTArray with dedicated MediaByteRangeSet object. r=cpearce --- dom/media/BufferMediaResource.h | 4 ++-- dom/media/MediaCache.cpp | 4 ++-- dom/media/MediaCache.h | 5 +++-- dom/media/MediaResource.cpp | 8 ++++---- dom/media/MediaResource.h | 6 ++++-- dom/media/RtspMediaResource.h | 2 +- dom/media/directshow/DirectShowReader.cpp | 2 +- dom/media/fmp4/MP4Demuxer.cpp | 4 ++-- dom/media/gstreamer/GStreamerReader.cpp | 4 ++-- dom/media/gtest/MockMediaResource.cpp | 7 +++---- dom/media/gtest/MockMediaResource.h | 4 ++-- dom/media/mediasource/ContainerParser.cpp | 5 ++--- dom/media/mediasource/MediaSourceResource.h | 4 ++-- dom/media/mediasource/SourceBufferResource.h | 6 +++--- dom/media/ogg/OggReader.cpp | 6 +++--- dom/media/omx/MediaOmxReader.cpp | 2 +- dom/media/webm/WebMBufferedParser.cpp | 2 +- dom/media/webm/WebMBufferedParser.h | 2 +- dom/media/webm/WebMDemuxer.cpp | 4 ++-- dom/media/webm/WebMReader.cpp | 4 ++-- media/libstagefright/binding/Box.cpp | 4 ++-- media/libstagefright/binding/Index.cpp | 10 +++++----- media/libstagefright/binding/MoofParser.cpp | 20 +++++++++---------- .../binding/include/mp4_demuxer/Box.h | 4 ++-- .../binding/include/mp4_demuxer/Index.h | 6 +++--- .../binding/include/mp4_demuxer/MoofParser.h | 8 ++++---- media/libstagefright/gtest/TestParser.cpp | 9 +++------ 27 files changed, 72 insertions(+), 74 deletions(-) diff --git a/dom/media/BufferMediaResource.h b/dom/media/BufferMediaResource.h index 82ff184fdf1f..a5bf11b30fc6 100644 --- a/dom/media/BufferMediaResource.h +++ b/dom/media/BufferMediaResource.h @@ -99,9 +99,9 @@ private: return NS_ERROR_FAILURE; } - virtual nsresult GetCachedRanges(nsTArray& aRanges) override + virtual nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override { - aRanges.AppendElement(MediaByteRange(0, mLength)); + aRanges += MediaByteRange(0, mLength); return NS_OK; } diff --git a/dom/media/MediaCache.cpp b/dom/media/MediaCache.cpp index 0ebe1578fd12..e42a236f8cd5 100644 --- a/dom/media/MediaCache.cpp +++ b/dom/media/MediaCache.cpp @@ -2442,7 +2442,7 @@ MediaCacheStream::InitAsClone(MediaCacheStream* aOriginal) return NS_OK; } -nsresult MediaCacheStream::GetCachedRanges(nsTArray& aRanges) +nsresult MediaCacheStream::GetCachedRanges(MediaByteRangeSet& aRanges) { // Take the monitor, so that the cached data ranges can't grow while we're // trying to loop over them. @@ -2457,7 +2457,7 @@ nsresult MediaCacheStream::GetCachedRanges(nsTArray& aRanges) int64_t endOffset = GetCachedDataEndInternal(startOffset); NS_ASSERTION(startOffset < endOffset, "Buffered range must end after its start"); // Bytes [startOffset..endOffset] are cached. - aRanges.AppendElement(MediaByteRange(startOffset, endOffset)); + aRanges += MediaByteRange(startOffset, endOffset); startOffset = GetNextCachedDataInternal(endOffset); NS_ASSERTION(startOffset == -1 || startOffset > endOffset, "Must have advanced to start of next range, or hit end of stream"); diff --git a/dom/media/MediaCache.h b/dom/media/MediaCache.h index 36b96a8cebaa..0c49986f39e8 100644 --- a/dom/media/MediaCache.h +++ b/dom/media/MediaCache.h @@ -11,13 +11,14 @@ #include "nsCOMPtr.h" #include "nsHashKeys.h" #include "nsTHashtable.h" +#include "Intervals.h" class nsIPrincipal; namespace mozilla { // defined in MediaResource.h class ChannelMediaResource; -class MediaByteRange; +typedef media::IntervalSet MediaByteRangeSet; class MediaResource; class ReentrantMonitorAutoEnter; @@ -300,7 +301,7 @@ public: // cached. Locks the media cache while running, to prevent any ranges // growing. The stream should be pinned while this runs and while its results // are used, to ensure no data is evicted. - nsresult GetCachedRanges(nsTArray& aRanges); + nsresult GetCachedRanges(MediaByteRangeSet& aRanges); // Reads from buffered data only. Will fail if not all data to be read is // in the cache. Will not mark blocks as read. Can be called from the main diff --git a/dom/media/MediaResource.cpp b/dom/media/MediaResource.cpp index cef5b242eed3..ed40054e1bce 100644 --- a/dom/media/MediaResource.cpp +++ b/dom/media/MediaResource.cpp @@ -738,7 +738,7 @@ int64_t ChannelMediaResource::Tell() return mCacheStream.Tell(); } -nsresult ChannelMediaResource::GetCachedRanges(nsTArray& aRanges) +nsresult ChannelMediaResource::GetCachedRanges(MediaByteRangeSet& aRanges) { return mCacheStream.GetCachedRanges(aRanges); } @@ -1202,7 +1202,7 @@ public: virtual bool IsSuspended() override { return true; } virtual bool IsTransportSeekable() override { return true; } - nsresult GetCachedRanges(nsTArray& aRanges) override; + nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override; virtual size_t SizeOfExcludingThis( MallocSizeOf aMallocSizeOf) const override @@ -1274,7 +1274,7 @@ void FileMediaResource::EnsureSizeInitialized() } } -nsresult FileMediaResource::GetCachedRanges(nsTArray& aRanges) +nsresult FileMediaResource::GetCachedRanges(MediaByteRangeSet& aRanges) { MutexAutoLock lock(mLock); @@ -1282,7 +1282,7 @@ nsresult FileMediaResource::GetCachedRanges(nsTArray& aRanges) if (mSize == -1) { return NS_ERROR_FAILURE; } - aRanges.AppendElement(MediaByteRange(0, mSize)); + aRanges += MediaByteRange(0, mSize); return NS_OK; } diff --git a/dom/media/MediaResource.h b/dom/media/MediaResource.h index 21b81e11dcc6..845cccca7bf5 100644 --- a/dom/media/MediaResource.h +++ b/dom/media/MediaResource.h @@ -153,6 +153,8 @@ public: MediaByteRange() = default; }; +typedef media::IntervalSet MediaByteRangeSet; + class RtspMediaResource; /** @@ -343,7 +345,7 @@ public: * in the media cache. Stream should be pinned during call and while * aRanges is being used. */ - virtual nsresult GetCachedRanges(nsTArray& aRanges) = 0; + virtual nsresult GetCachedRanges(MediaByteRangeSet& aRanges) = 0; // Ensure that the media cache writes any data held in its partial block. // Called on the main thread only. @@ -655,7 +657,7 @@ public: }; friend class Listener; - virtual nsresult GetCachedRanges(nsTArray& aRanges) override; + virtual nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override; protected: // These are called on the main thread by Listener. diff --git a/dom/media/RtspMediaResource.h b/dom/media/RtspMediaResource.h index 224da67b5ec9..04ed36c00f09 100644 --- a/dom/media/RtspMediaResource.h +++ b/dom/media/RtspMediaResource.h @@ -162,7 +162,7 @@ public: return false; } // dummy - nsresult GetCachedRanges(nsTArray& aRanges) override { + nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override { return NS_ERROR_FAILURE; } diff --git a/dom/media/directshow/DirectShowReader.cpp b/dom/media/directshow/DirectShowReader.cpp index ed6390a79e5c..14d7b368cd42 100644 --- a/dom/media/directshow/DirectShowReader.cpp +++ b/dom/media/directshow/DirectShowReader.cpp @@ -384,7 +384,7 @@ DirectShowReader::NotifyDataArrivedInternal() } AutoPinned resource(mDecoder->GetResource()); - nsTArray byteRanges; + MediaByteRangeSet byteRanges; nsresult rv = resource->GetCachedRanges(byteRanges); if (NS_FAILED(rv)) { diff --git a/dom/media/fmp4/MP4Demuxer.cpp b/dom/media/fmp4/MP4Demuxer.cpp index 6c11eca7bbb1..a853182e5c58 100644 --- a/dom/media/fmp4/MP4Demuxer.cpp +++ b/dom/media/fmp4/MP4Demuxer.cpp @@ -264,7 +264,7 @@ MP4TrackDemuxer::EnsureUpToDateIndex() return; } AutoPinned resource(mParent->mResource); - nsTArray byteRanges; + MediaByteRangeSet byteRanges; nsresult rv = resource->GetCachedRanges(byteRanges); if (NS_FAILED(rv)) { return; @@ -413,7 +413,7 @@ MP4TrackDemuxer::GetBuffered() { EnsureUpToDateIndex(); AutoPinned resource(mParent->mResource); - nsTArray byteRanges; + MediaByteRangeSet byteRanges; nsresult rv = resource->GetCachedRanges(byteRanges); if (NS_FAILED(rv)) { diff --git a/dom/media/gstreamer/GStreamerReader.cpp b/dom/media/gstreamer/GStreamerReader.cpp index aff07e085819..f6d61cbf111f 100644 --- a/dom/media/gstreamer/GStreamerReader.cpp +++ b/dom/media/gstreamer/GStreamerReader.cpp @@ -885,7 +885,7 @@ media::TimeIntervals GStreamerReader::GetBuffered() GstFormat format = GST_FORMAT_TIME; #endif AutoPinned resource(mDecoder->GetResource()); - nsTArray ranges; + MediaByteRangeSet ranges; resource->GetCachedRanges(ranges); if (resource->IsDataCachedToEndOfResource(0)) { @@ -1286,7 +1286,7 @@ void GStreamerReader::NotifyDataArrivedInternal() } AutoPinned resource(mResource.GetResource()); - nsTArray byteRanges; + MediaByteRangeSet byteRanges; nsresult rv = resource->GetCachedRanges(byteRanges); if (NS_FAILED(rv)) { diff --git a/dom/media/gtest/MockMediaResource.cpp b/dom/media/gtest/MockMediaResource.cpp index 32a77c916ded..951f44bb1250 100644 --- a/dom/media/gtest/MockMediaResource.cpp +++ b/dom/media/gtest/MockMediaResource.cpp @@ -77,7 +77,7 @@ MockMediaResource::MockClearBufferedRanges() void MockMediaResource::MockAddBufferedRange(int64_t aStart, int64_t aEnd) { - mRanges.AppendElement(MediaByteRange(aStart, aEnd)); + mRanges += MediaByteRange(aStart, aEnd); } int64_t @@ -107,10 +107,9 @@ MockMediaResource::GetCachedDataEnd(int64_t aOffset) } nsresult -MockMediaResource::GetCachedRanges(nsTArray& aRanges) +MockMediaResource::GetCachedRanges(MediaByteRangeSet& aRanges) { - aRanges.Clear(); - aRanges.AppendElements(mRanges); + aRanges = mRanges; return NS_OK; } diff --git a/dom/media/gtest/MockMediaResource.h b/dom/media/gtest/MockMediaResource.h index 20a0ea4cab01..331e32640f66 100644 --- a/dom/media/gtest/MockMediaResource.h +++ b/dom/media/gtest/MockMediaResource.h @@ -58,7 +58,7 @@ public: virtual bool IsTransportSeekable() override { return true; } virtual nsresult Open(nsIStreamListener** aStreamListener) override; - virtual nsresult GetCachedRanges(nsTArray& aRanges) + virtual nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override; virtual const nsCString& GetContentType() const override { @@ -74,7 +74,7 @@ protected: private: FILE* mFileHandle; const char* mFileName; - nsTArray mRanges; + MediaByteRangeSet mRanges; Atomic mEntry; nsCString mContentType; }; diff --git a/dom/media/mediasource/ContainerParser.cpp b/dom/media/mediasource/ContainerParser.cpp index 6fe9caaea6db..cf86937fd087 100644 --- a/dom/media/mediasource/ContainerParser.cpp +++ b/dom/media/mediasource/ContainerParser.cpp @@ -438,10 +438,9 @@ public: } mResource->AppendData(aData); - nsTArray byteRanges; - MediaByteRange mbr = + MediaByteRangeSet byteRanges; + byteRanges += MediaByteRange(mParser->mOffset, mResource->GetLength()); - byteRanges.AppendElement(mbr); mParser->RebuildFragmentedIndex(byteRanges); if (initSegment || !HasCompleteInitData()) { diff --git a/dom/media/mediasource/MediaSourceResource.h b/dom/media/mediasource/MediaSourceResource.h index 467232117d08..6349f81d4a30 100644 --- a/dom/media/mediasource/MediaSourceResource.h +++ b/dom/media/mediasource/MediaSourceResource.h @@ -54,10 +54,10 @@ public: return RefPtr(mPrincipal).forget(); } - virtual nsresult GetCachedRanges(nsTArray& aRanges) override + virtual nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override { UNIMPLEMENTED(); - aRanges.AppendElement(MediaByteRange(0, GetLength())); + aRanges += MediaByteRange(0, GetLength()); return NS_OK; } diff --git a/dom/media/mediasource/SourceBufferResource.h b/dom/media/mediasource/SourceBufferResource.h index bac9b4c08a20..0faea0ad2aa7 100644 --- a/dom/media/mediasource/SourceBufferResource.h +++ b/dom/media/mediasource/SourceBufferResource.h @@ -70,12 +70,12 @@ public: virtual bool IsTransportSeekable() override { UNIMPLEMENTED(); return true; } virtual nsresult Open(nsIStreamListener** aStreamListener) override { UNIMPLEMENTED(); return NS_ERROR_FAILURE; } - virtual nsresult GetCachedRanges(nsTArray& aRanges) override + virtual nsresult GetCachedRanges(MediaByteRangeSet& aRanges) override { ReentrantMonitorAutoEnter mon(mMonitor); if (mInputBuffer.GetLength()) { - aRanges.AppendElement(MediaByteRange(mInputBuffer.GetOffset(), - mInputBuffer.GetLength())); + aRanges += MediaByteRange(mInputBuffer.GetOffset(), + mInputBuffer.GetLength()); } return NS_OK; } diff --git a/dom/media/ogg/OggReader.cpp b/dom/media/ogg/OggReader.cpp index 338990038a27..f0f379a55517 100644 --- a/dom/media/ogg/OggReader.cpp +++ b/dom/media/ogg/OggReader.cpp @@ -1160,12 +1160,12 @@ nsresult OggReader::GetSeekRanges(nsTArray& aRanges) { MOZ_ASSERT(OnTaskQueue()); AutoPinned resource(mDecoder->GetResource()); - nsTArray cached; + MediaByteRangeSet cached; nsresult res = resource->GetCachedRanges(cached); NS_ENSURE_SUCCESS(res, res); for (uint32_t index = 0; index < cached.Length(); index++) { - MediaByteRange& range = cached[index]; + auto& range = cached[index]; int64_t startTime = -1; int64_t endTime = -1; if (NS_FAILED(ResetDecode())) { @@ -1841,7 +1841,7 @@ media::TimeIntervals OggReader::GetBuffered() } AutoPinned resource(mDecoder->GetResource()); - nsTArray ranges; + MediaByteRangeSet ranges; nsresult res = resource->GetCachedRanges(ranges); NS_ENSURE_SUCCESS(res, media::TimeIntervals::Invalid()); diff --git a/dom/media/omx/MediaOmxReader.cpp b/dom/media/omx/MediaOmxReader.cpp index 65a370b260b1..aa37beeccee0 100644 --- a/dom/media/omx/MediaOmxReader.cpp +++ b/dom/media/omx/MediaOmxReader.cpp @@ -464,7 +464,7 @@ void MediaOmxReader::NotifyDataArrivedInternal() } AutoPinned resource(mDecoder->GetResource()); - nsTArray byteRanges; + MediaByteRangeSet byteRanges; nsresult rv = resource->GetCachedRanges(byteRanges); if (NS_FAILED(rv)) { diff --git a/dom/media/webm/WebMBufferedParser.cpp b/dom/media/webm/WebMBufferedParser.cpp index 9c7049a427c2..3d9679a24276 100644 --- a/dom/media/webm/WebMBufferedParser.cpp +++ b/dom/media/webm/WebMBufferedParser.cpp @@ -383,7 +383,7 @@ void WebMBufferedState::Reset() { mTimeMapping.Clear(); } -void WebMBufferedState::UpdateIndex(const nsTArray& aRanges, MediaResource* aResource) +void WebMBufferedState::UpdateIndex(const MediaByteRangeSet& aRanges, MediaResource* aResource) { for (uint32_t index = 0; index < aRanges.Length(); index++) { const MediaByteRange& range = aRanges[index]; diff --git a/dom/media/webm/WebMBufferedParser.h b/dom/media/webm/WebMBufferedParser.h index d33f66468a2e..c65897407d63 100644 --- a/dom/media/webm/WebMBufferedParser.h +++ b/dom/media/webm/WebMBufferedParser.h @@ -266,7 +266,7 @@ public: void NotifyDataArrived(const unsigned char* aBuffer, uint32_t aLength, int64_t aOffset); void Reset(); - void UpdateIndex(const nsTArray& aRanges, MediaResource* aResource); + void UpdateIndex(const MediaByteRangeSet& aRanges, MediaResource* aResource); bool CalculateBufferedForRange(int64_t aStartOffset, int64_t aEndOffset, uint64_t* aStartTime, uint64_t* aEndTime); diff --git a/dom/media/webm/WebMDemuxer.cpp b/dom/media/webm/WebMDemuxer.cpp index be95e933734e..ec109d71e5fc 100644 --- a/dom/media/webm/WebMDemuxer.cpp +++ b/dom/media/webm/WebMDemuxer.cpp @@ -439,7 +439,7 @@ WebMDemuxer::EnsureUpToDateIndex() return; } AutoPinned resource(mResource.GetResource()); - nsTArray byteRanges; + MediaByteRangeSet byteRanges; nsresult rv = resource->GetCachedRanges(byteRanges); if (NS_FAILED(rv) || !byteRanges.Length()) { return; @@ -732,7 +732,7 @@ WebMDemuxer::GetBuffered() media::TimeIntervals buffered; - nsTArray ranges; + MediaByteRangeSet ranges; nsresult rv = resource->GetCachedRanges(ranges); if (NS_FAILED(rv)) { return media::TimeIntervals(); diff --git a/dom/media/webm/WebMReader.cpp b/dom/media/webm/WebMReader.cpp index 4083d49483f3..fdee7285d6f2 100644 --- a/dom/media/webm/WebMReader.cpp +++ b/dom/media/webm/WebMReader.cpp @@ -749,7 +749,7 @@ media::TimeIntervals WebMReader::GetBuffered() // Either we the file is not fully cached, or we couldn't find a duration in // the WebM bitstream. - nsTArray ranges; + MediaByteRangeSet ranges; nsresult res = resource->GetCachedRanges(ranges); NS_ENSURE_SUCCESS(res, media::TimeIntervals::Invalid()); @@ -788,7 +788,7 @@ void WebMReader::NotifyDataArrivedInternal() { MOZ_ASSERT(OnTaskQueue()); AutoPinned resource(mDecoder->GetResource()); - nsTArray byteRanges; + MediaByteRangeSet byteRanges; nsresult rv = resource->GetCachedRanges(byteRanges); if (NS_FAILED(rv)) { diff --git a/media/libstagefright/binding/Box.cpp b/media/libstagefright/binding/Box.cpp index fdc2665cdf67..46a46b4e427e 100644 --- a/media/libstagefright/binding/Box.cpp +++ b/media/libstagefright/binding/Box.cpp @@ -56,7 +56,7 @@ Box::Box(BoxContext* aContext, uint64_t aOffset, const Box* aParent) return; } - byteRange = &mContext->mByteRanges[i]; + byteRange = static_cast(&mContext->mByteRanges[i]); if (byteRange->Contains(headerRange)) { break; } @@ -88,7 +88,7 @@ Box::Box(BoxContext* aContext, uint64_t aOffset, const Box* aParent) mBodyOffset = bigLengthRange.mEnd; } else if (size == 0) { // box extends to end of file. - size = mContext->mByteRanges.LastElement().mEnd - aOffset; + size = mContext->mByteRanges.LastInterval().mEnd - aOffset; mBodyOffset = headerRange.mEnd; } else { mBodyOffset = headerRange.mEnd; diff --git a/media/libstagefright/binding/Index.cpp b/media/libstagefright/binding/Index.cpp index de8dff497383..13e689133e8e 100644 --- a/media/libstagefright/binding/Index.cpp +++ b/media/libstagefright/binding/Index.cpp @@ -25,7 +25,7 @@ public: // Given that we're processing this in order we don't use a binary search // to find the apropriate time range. Instead we search linearly from the // last used point. - explicit RangeFinder(const nsTArray& ranges) + explicit RangeFinder(const MediaByteRangeSet& ranges) : mRanges(ranges), mIndex(0) { // Ranges must be normalised for this to work @@ -34,7 +34,7 @@ public: bool Contains(MediaByteRange aByteRange); private: - const nsTArray& mRanges; + const MediaByteRangeSet& mRanges; size_t mIndex; }; @@ -266,7 +266,7 @@ Index::Index(const nsTArray& aIndex, Index::~Index() {} void -Index::UpdateMoofIndex(const nsTArray& aByteRanges) +Index::UpdateMoofIndex(const MediaByteRangeSet& aByteRanges) { if (!mMoofParser) { return; @@ -276,7 +276,7 @@ Index::UpdateMoofIndex(const nsTArray& aByteRanges) } Microseconds -Index::GetEndCompositionIfBuffered(const nsTArray& aByteRanges) +Index::GetEndCompositionIfBuffered(const MediaByteRangeSet& aByteRanges) { FallibleTArray* index; if (mMoofParser) { @@ -305,7 +305,7 @@ Index::GetEndCompositionIfBuffered(const nsTArray& aByteRanges) void Index::ConvertByteRangesToTimeRanges( - const nsTArray& aByteRanges, + const MediaByteRangeSet& aByteRanges, nsTArray>* aTimeRanges) { RangeFinder rangeFinder(aByteRanges); diff --git a/media/libstagefright/binding/MoofParser.cpp b/media/libstagefright/binding/MoofParser.cpp index c3c0b8bd4589..310539048e44 100644 --- a/media/libstagefright/binding/MoofParser.cpp +++ b/media/libstagefright/binding/MoofParser.cpp @@ -28,7 +28,7 @@ using namespace mozilla; bool MoofParser::RebuildFragmentedIndex( - const nsTArray& aByteRanges) + const MediaByteRangeSet& aByteRanges) { BoxContext context(mSource, aByteRanges); return RebuildFragmentedIndex(context); @@ -59,7 +59,7 @@ MoofParser::RebuildFragmentedIndex(BoxContext& aContext) } mMoofs.AppendElement(moof); - mMediaRanges.AppendElement(moof.mRange); + mMediaRanges += moof.mRange; foundValidMoof = true; } else if (box.IsType("mdat") && !Moofs().IsEmpty()) { // Check if we have all our data from last moof. @@ -67,8 +67,8 @@ MoofParser::RebuildFragmentedIndex(BoxContext& aContext) media::Interval datarange(moof.mMdatRange.mStart, moof.mMdatRange.mEnd, 0); media::Interval mdat(box.Range().mStart, box.Range().mEnd, 0); if (datarange.Intersects(mdat)) { - mMediaRanges.LastElement() = - mMediaRanges.LastElement().Span(box.Range()); + mMediaRanges.LastInterval() = + mMediaRanges.LastInterval().Span(box.Range()); } } mOffset = box.NextOffset(); @@ -128,15 +128,15 @@ MoofParser::BlockingReadNextMoof() { int64_t length = std::numeric_limits::max(); mSource->Length(&length); - nsTArray byteRanges; - byteRanges.AppendElement(MediaByteRange(0, length)); + MediaByteRangeSet byteRanges; + byteRanges += MediaByteRange(0, length); RefPtr stream = new BlockingStream(mSource); BoxContext context(stream, byteRanges); for (Box box(&context, mOffset); box.IsAvailable(); box = box.Next()) { if (box.IsType("moof")) { byteRanges.Clear(); - byteRanges.AppendElement(MediaByteRange(mOffset, box.Range().mEnd)); + byteRanges += MediaByteRange(mOffset, box.Range().mEnd); return RebuildFragmentedIndex(context); } } @@ -149,8 +149,8 @@ MoofParser::ScanForMetadata(mozilla::MediaByteRange& aFtyp, { int64_t length = std::numeric_limits::max(); mSource->Length(&length); - nsTArray byteRanges; - byteRanges.AppendElement(MediaByteRange(0, length)); + MediaByteRangeSet byteRanges; + byteRanges += MediaByteRange(0, length); RefPtr stream = new BlockingStream(mSource); BoxContext context(stream, byteRanges); @@ -207,7 +207,7 @@ MoofParser::Metadata() } Interval -MoofParser::GetCompositionRange(const nsTArray& aByteRanges) +MoofParser::GetCompositionRange(const MediaByteRangeSet& aByteRanges) { Interval compositionRange; BoxContext context(mSource, aByteRanges); diff --git a/media/libstagefright/binding/include/mp4_demuxer/Box.h b/media/libstagefright/binding/include/mp4_demuxer/Box.h index b2899a70250e..e79b0130f83e 100644 --- a/media/libstagefright/binding/include/mp4_demuxer/Box.h +++ b/media/libstagefright/binding/include/mp4_demuxer/Box.h @@ -23,13 +23,13 @@ class Stream; class BoxContext { public: - BoxContext(Stream* aSource, const nsTArray& aByteRanges) + BoxContext(Stream* aSource, const MediaByteRangeSet& aByteRanges) : mSource(aSource), mByteRanges(aByteRanges) { } RefPtr mSource; - const nsTArray& mByteRanges; + const MediaByteRangeSet& mByteRanges; }; class Box diff --git a/media/libstagefright/binding/include/mp4_demuxer/Index.h b/media/libstagefright/binding/include/mp4_demuxer/Index.h index c2e4b878b808..b7375087c5c9 100644 --- a/media/libstagefright/binding/include/mp4_demuxer/Index.h +++ b/media/libstagefright/binding/include/mp4_demuxer/Index.h @@ -60,11 +60,11 @@ public: bool aIsAudio, mozilla::Monitor* aMonitor); - void UpdateMoofIndex(const nsTArray& aByteRanges); + void UpdateMoofIndex(const mozilla::MediaByteRangeSet& aByteRanges); Microseconds GetEndCompositionIfBuffered( - const nsTArray& aByteRanges); + const mozilla::MediaByteRangeSet& aByteRanges); void ConvertByteRangesToTimeRanges( - const nsTArray& aByteRanges, + const mozilla::MediaByteRangeSet& aByteRanges, nsTArray>* aTimeRanges); uint64_t GetEvictionOffset(Microseconds aTime); bool IsFragmented() { return mMoofParser; } diff --git a/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h b/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h index ee2a22d7fa49..9feba016d6a3 100644 --- a/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h +++ b/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h @@ -165,7 +165,7 @@ public: class AuxInfo { public: AuxInfo(int64_t aMoofOffset, Saiz& aSaiz, Saio& aSaio); - bool GetByteRanges(nsTArray* aByteRanges); + bool GetByteRanges(MediaByteRangeSet* aByteRanges); private: int64_t mMoofOffset; @@ -212,10 +212,10 @@ public: // the composition range for MSE. We need an array of tracks. } bool RebuildFragmentedIndex( - const nsTArray& aByteRanges); + const mozilla::MediaByteRangeSet& aByteRanges); bool RebuildFragmentedIndex(BoxContext& aContext); Interval GetCompositionRange( - const nsTArray& aByteRanges); + const mozilla::MediaByteRangeSet& aByteRanges); bool ReachedEnd(); void ParseMoov(Box& aBox); void ParseTrak(Box& aBox); @@ -250,7 +250,7 @@ private: void ScanForMetadata(mozilla::MediaByteRange& aFtyp, mozilla::MediaByteRange& aMoov); nsTArray mMoofs; - nsTArray mMediaRanges; + MediaByteRangeSet mMediaRanges; bool mIsAudio; }; } diff --git a/media/libstagefright/gtest/TestParser.cpp b/media/libstagefright/gtest/TestParser.cpp index 8f40ee06f71d..4903121c0198 100644 --- a/media/libstagefright/gtest/TestParser.cpp +++ b/media/libstagefright/gtest/TestParser.cpp @@ -102,8 +102,7 @@ TEST(stagefright_MoofParser, EmptyStream) EXPECT_EQ(0u, parser.mOffset); EXPECT_TRUE(parser.ReachedEnd()); - nsTArray byteRanges; - byteRanges.AppendElement(MediaByteRange(0, 0)); + MediaByteRangeSet byteRanges; EXPECT_FALSE(parser.RebuildFragmentedIndex(byteRanges)); EXPECT_TRUE(parser.GetCompositionRange(byteRanges).IsNull()); @@ -292,8 +291,7 @@ TEST(stagefright_MoofParser, test_case_mp4) EXPECT_EQ(0u, parser.mOffset); EXPECT_FALSE(parser.ReachedEnd()); - nsTArray byteRanges; - byteRanges.AppendElement(MediaByteRange(0, 0)); + MediaByteRangeSet byteRanges; EXPECT_FALSE(parser.RebuildFragmentedIndex(byteRanges)); EXPECT_TRUE(parser.GetCompositionRange(byteRanges).IsNull()); @@ -329,8 +327,7 @@ TEST(stagefright_MoofParser, test_case_mp4_subsets) new TestStream(buffer.Elements() + offset, size); MoofParser parser(stream, 0, false, &monitor); - nsTArray byteRanges; - byteRanges.AppendElement(MediaByteRange(0, 0)); + MediaByteRangeSet byteRanges; EXPECT_FALSE(parser.RebuildFragmentedIndex(byteRanges)); parser.GetCompositionRange(byteRanges); parser.HasMetadata();