Bug 1181651 - Replace use of stagefright::Vector with nsTArray. r=kentuckyfriedtakahe, a=ritu
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 20 Aug 2015 15:29:39 +1000
changeset 288912 08739e933fa89870477333fcdef6c627d81e4d37
parent 288911 87594f1a9a2189e7dd9fe1629acac555b52fdb36
child 288913 922b540401d4562ab7b908f42516e2bcf0e2559a
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskentuckyfriedtakahe, ritu
bugs1181651
milestone42.0a2
Bug 1181651 - Replace use of stagefright::Vector with nsTArray. r=kentuckyfriedtakahe, a=ritu
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;
 }