Bug 1181651: Replace use of stagefright::Vector with nsTArray. r=kentuckyfriedtakahe
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 20 Aug 2015 15:29:39 +1000
changeset 291191 6e758736c0c65821117d54a012b1a555bc9d2d7d
parent 291190 d72462f193b44eab7979134a80013026c04ae345
child 291192 d8e5f72da53aad99d4d4b67de44cb80f62754aa8
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskentuckyfriedtakahe
bugs1181651
milestone43.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 1181651: Replace use of stagefright::Vector with nsTArray. r=kentuckyfriedtakahe
media/libstagefright/binding/MP4Metadata.cpp
media/libstagefright/frameworks/av/include/media/stagefright/MediaSource.h
media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp
--- a/media/libstagefright/binding/MP4Metadata.cpp
+++ b/media/libstagefright/binding/MP4Metadata.cpp
@@ -63,23 +63,23 @@ public:
   virtual status_t reconnectAtOffset(off64_t offset) { return NO_ERROR; }
 
 private:
   nsRefPtr<Stream> mSource;
 };
 
 static inline bool
 ConvertIndex(FallibleTArray<Index::Indice>& aDest,
-             const stagefright::Vector<stagefright::MediaSource::Indice>& aIndex,
+             const nsTArray<stagefright::MediaSource::Indice>& 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;
     indice.end_offset = s_indice.end_offset;
     indice.start_composition = s_indice.start_composition - aMediaTime;
     indice.end_composition = s_indice.end_composition - aMediaTime;
     indice.sync = s_indice.sync;
     // FIXME: Make this infallible after bug 968520 is done.
--- a/media/libstagefright/frameworks/av/include/media/stagefright/MediaSource.h
+++ b/media/libstagefright/frameworks/av/include/media/stagefright/MediaSource.h
@@ -18,16 +18,17 @@
 
 #define MEDIA_SOURCE_H_
 
 #include <sys/types.h>
 
 #include <media/stagefright/MediaErrors.h>
 #include <utils/RefBase.h>
 #include <utils/Vector.h>
+#include "nsTArray.h"
 
 namespace stagefright {
 
 class MediaBuffer;
 class MetaData;
 
 struct MediaSource : public virtual RefBase {
     MediaSource();
@@ -113,17 +114,17 @@ struct MediaSource : public virtual RefB
     {
       uint64_t start_offset;
       uint64_t end_offset;
       uint64_t start_composition;
       uint64_t end_composition;
       bool sync;
     };
 
-    virtual Vector<Indice> exportIndex() = 0;
+    virtual nsTArray<Indice> exportIndex() = 0;
 
 protected:
     virtual ~MediaSource();
 
 private:
     MediaSource(const MediaSource &);
     MediaSource &operator=(const MediaSource &);
 };
--- a/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp
+++ b/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp
@@ -57,17 +57,17 @@ public:
 
     virtual status_t start(MetaData *params = NULL);
     virtual status_t stop();
 
     virtual sp<MetaData> getFormat();
 
     virtual status_t read(MediaBuffer **buffer, const ReadOptions *options = NULL);
     virtual status_t fragmentedRead(MediaBuffer **buffer, const ReadOptions *options = NULL);
-    virtual Vector<Indice> exportIndex();
+    virtual nsTArray<Indice> exportIndex();
 
 protected:
     virtual ~MPEG4Source();
 
 private:
     Mutex mLock;
 
     sp<MetaData> mFormat;
@@ -4103,23 +4103,40 @@ static int compositionOrder(MediaSource:
       return 1;
   } else if ((*indice0)->start_composition == (*indice1)->start_composition) {
       return 0;
   } else {
       return -1;
   }
 }
 
-Vector<MediaSource::Indice> MPEG4Source::exportIndex()
+class CompositionSorter
 {
-  Vector<Indice> 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<MediaSource::Indice> MPEG4Source::exportIndex()
+{
+  nsTArray<MediaSource::Indice> 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;
       size_t size;
       uint32_t compositionTime;
       uint32_t duration;
       bool isSyncSample;
       if (mSampleTable->getMetaDataForSample(sampleIndex, &offset, &size,
@@ -4133,30 +4150,31 @@ Vector<MediaSource::Indice> MPEG4Source:
       indice.start_offset = offset;
       indice.end_offset = offset + size;
       indice.start_composition = (compositionTime * 1000000ll) / mTimescale;
       // end_composition is overwritten everywhere except the last frame, where
       // the presentation duration is equal to the sample duration.
       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<Indice*> 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<Indice*> composition_order;
+      if (!composition_order.SetCapacity(index.Length(), mozilla::fallible)) {
+        return index;
       }
-
-      composition_order.sort(compositionOrder);
-      for (uint32_t i = 0; i + 1 < composition_order.size(); i++) {
+      for (uint32_t i = 0; i < index.Length(); i++) {
+        composition_order.AppendElement(&index[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;
       }
   }
 
   return index;
 }