From e42ca2d177692adc3178d25381ee697a41a94f10 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Thu, 20 Aug 2015 15:29:39 +1000 Subject: [PATCH] Bug 1181651: Replace use of stagefright::Vector with nsTArray. r=kentuckyfriedtakahe --- media/libstagefright/binding/MP4Metadata.cpp | 6 +-- .../include/media/stagefright/MediaSource.h | 3 +- .../media/libstagefright/MPEG4Extractor.cpp | 42 +++++++++++++------ 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/media/libstagefright/binding/MP4Metadata.cpp b/media/libstagefright/binding/MP4Metadata.cpp index 22836191bd6f..5effe9f44998 100644 --- a/media/libstagefright/binding/MP4Metadata.cpp +++ b/media/libstagefright/binding/MP4Metadata.cpp @@ -68,13 +68,13 @@ private: static inline bool ConvertIndex(FallibleTArray& aDest, - const stagefright::Vector& aIndex, + const nsTArray& aIndex, int64_t aMediaTime) { - if (!aDest.SetCapacity(aIndex.size(), mozilla::fallible)) { + if (!aDest.SetCapacity(aIndex.Length(), mozilla::fallible)) { return false; } - for (size_t i = 0; i < aIndex.size(); i++) { + for (size_t i = 0; i < aIndex.Length(); i++) { Index::Indice indice; const stagefright::MediaSource::Indice& s_indice = aIndex[i]; indice.start_offset = s_indice.start_offset; diff --git a/media/libstagefright/frameworks/av/include/media/stagefright/MediaSource.h b/media/libstagefright/frameworks/av/include/media/stagefright/MediaSource.h index 65b7fecf0440..60473bf87f55 100644 --- a/media/libstagefright/frameworks/av/include/media/stagefright/MediaSource.h +++ b/media/libstagefright/frameworks/av/include/media/stagefright/MediaSource.h @@ -23,6 +23,7 @@ #include #include #include +#include "nsTArray.h" namespace stagefright { @@ -118,7 +119,7 @@ struct MediaSource : public virtual RefBase { bool sync; }; - virtual Vector exportIndex() = 0; + virtual nsTArray exportIndex() = 0; protected: virtual ~MediaSource(); diff --git a/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp b/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp index 3a011e28a050..2334f3a8480d 100644 --- a/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp +++ b/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp @@ -62,7 +62,7 @@ public: virtual status_t read(MediaBuffer **buffer, const ReadOptions *options = NULL); virtual status_t fragmentedRead(MediaBuffer **buffer, const ReadOptions *options = NULL); - virtual Vector exportIndex(); + virtual nsTArray exportIndex(); protected: virtual ~MPEG4Source(); @@ -4108,13 +4108,30 @@ static int compositionOrder(MediaSource::Indice* const* indice0, } } -Vector MPEG4Source::exportIndex() +class CompositionSorter { - Vector index; +public: + bool LessThan(MediaSource::Indice* aFirst, MediaSource::Indice* aSecond) const + { + return aFirst->start_composition < aSecond->start_composition; + } + + bool Equals(MediaSource::Indice* aFirst, MediaSource::Indice* aSecond) const + { + return aFirst->start_composition == aSecond->start_composition; + } +}; + +nsTArray MPEG4Source::exportIndex() +{ + nsTArray index; if (!mTimescale) { return index; } + if (!index.SetCapacity(mSampleTable->countSamples(), mozilla::fallible)) { + return index; + } for (uint32_t sampleIndex = 0; sampleIndex < mSampleTable->countSamples(); sampleIndex++) { off64_t offset; @@ -4138,20 +4155,21 @@ Vector MPEG4Source::exportIndex() indice.end_composition = (compositionTime * 1000000ll + duration * 1000000ll) / mTimescale; indice.sync = isSyncSample; - index.add(indice); + index.AppendElement(indice); } // Fix up composition durations so we don't end up with any unsightly gaps. - if (index.size() != 0) { - Indice* array = index.editArray(); - Vector composition_order; - composition_order.reserve(index.size()); - for (uint32_t i = 0; i < index.size(); i++) { - composition_order.add(&array[i]); + if (index.Length() != 0) { + nsTArray composition_order; + if (!composition_order.SetCapacity(index.Length(), mozilla::fallible)) { + return index; + } + for (uint32_t i = 0; i < index.Length(); i++) { + composition_order.AppendElement(&index[i]); } - composition_order.sort(compositionOrder); - for (uint32_t i = 0; i + 1 < composition_order.size(); i++) { + composition_order.Sort(CompositionSorter()); + for (uint32_t i = 0; i + 1 < composition_order.Length(); i++) { composition_order[i]->end_composition = composition_order[i + 1]->start_composition; }