Bug 1185115: P2. replace all stagefright::Vector with nsTArray. r=kentuckyfriedtakahe
authorJean-Yves Avenard <jyavenard@mozilla.com>
Sat, 12 Sep 2015 16:23:08 +1000
changeset 296469 f3c4899a67e48acc764993a368402b21f2745192
parent 296468 0105583c5ffd21c11f0e9f7afbba83e3a9b59653
child 296470 574a93c36fd8ac5bc9f803f622b30f472b8be0b0
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskentuckyfriedtakahe
bugs1185115
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 1185115: P2. replace all stagefright::Vector with nsTArray. r=kentuckyfriedtakahe
media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp
media/libstagefright/frameworks/av/media/libstagefright/SampleTable.cpp
media/libstagefright/frameworks/av/media/libstagefright/include/MPEG4Extractor.h
media/libstagefright/frameworks/av/media/libstagefright/include/SampleTable.h
--- a/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp
+++ b/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp
@@ -33,31 +33,30 @@
 #include <media/stagefright/foundation/ABuffer.h>
 #include <media/stagefright/foundation/ADebug.h>
 #include <media/stagefright/foundation/AMessage.h>
 #include <media/stagefright/MediaBuffer.h>
 #include <media/stagefright/MediaDefs.h>
 #include <media/stagefright/MediaSource.h>
 #include <media/stagefright/MetaData.h>
 #include <utils/String8.h>
-#include "nsTArray.h"
 
 static const uint32_t kMAX_ALLOCATION =
     (SIZE_MAX < INT32_MAX ? SIZE_MAX : INT32_MAX) - 128;
 
 namespace stagefright {
 
 class MPEG4Source : public MediaSource {
 public:
     // Caller retains ownership of both "dataSource" and "sampleTable".
     MPEG4Source(const sp<MetaData> &format,
                 const sp<DataSource> &dataSource,
                 int32_t timeScale,
                 const sp<SampleTable> &sampleTable,
-                Vector<SidxEntry> &sidx,
+                nsTArray<SidxEntry> &sidx,
                 MPEG4Extractor::TrackExtends &trackExtends);
 
     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);
@@ -71,17 +70,17 @@ private:
     Mutex mLock;
 
     sp<MetaData> mFormat;
     sp<DataSource> mDataSource;
     int32_t mTimescale;
     sp<SampleTable> mSampleTable;
     uint32_t mCurrentSampleIndex;
     uint32_t mCurrentFragmentIndex;
-    Vector<SidxEntry> &mSegments;
+    nsTArray<SidxEntry> &mSegments;
     bool mLookedForMoof;
     off64_t mFirstMoofOffset;
     off64_t mCurrentMoofOffset;
     off64_t mNextMoofOffset;
     uint32_t mCurrentTime;
     int32_t mLastParsedTrackId;
     int32_t mTrackId;
 
@@ -144,33 +143,33 @@ private:
 
     struct Sample {
         off64_t offset;
         uint32_t size;
         uint32_t duration;
         int32_t ctsOffset;
         uint32_t flags;
         uint8_t iv[16];
-        Vector<uint16_t> clearsizes;
-        Vector<uint32_t> encryptedsizes;
+        nsTArray<uint16_t> clearsizes;
+        nsTArray<uint32_t> encryptedsizes;
 
         bool isSync() const { return !(flags & 0x1010000); }
     };
-    Vector<Sample> mCurrentSamples;
+    nsTArray<Sample> mCurrentSamples;
     MPEG4Extractor::TrackExtends mTrackExtends;
 
     // XXX hack -- demuxer expects a track's trun to be seen before saio or
     // saiz. Here we store saiz/saio box offsets for parsing *after* the trun
     // has been parsed.
     struct AuxRange {
         off64_t mStart;
         off64_t mSize;
     };
-    Vector<AuxRange> mDeferredSaiz;
-    Vector<AuxRange> mDeferredSaio;
+    nsTArray<AuxRange> mDeferredSaiz;
+    nsTArray<AuxRange> mDeferredSaio;
 
     MPEG4Source(const MPEG4Source &);
     MPEG4Source &operator=(const MPEG4Source &);
 
     bool ensureSrcBufferAllocated(int32_t size);
     // Ensure that we have enough data in mMediaBuffer to copy our data.
     // Returns false if not and clear mMediaBuffer.
     bool ensureMediaBufferAllocated(int32_t size);
@@ -400,17 +399,17 @@ MPEG4Extractor::~MPEG4Extractor() {
     while (sinf) {
         SINF *next = sinf->next;
         delete sinf->IPMPData;
         delete sinf;
         sinf = next;
     }
     mFirstSINF = NULL;
 
-    for (size_t i = 0; i < mPssh.size(); i++) {
+    for (size_t i = 0; i < mPssh.Length(); i++) {
         delete [] mPssh[i].data;
     }
 }
 
 uint32_t MPEG4Extractor::flags() const {
     return CAN_PAUSE | CAN_SEEK_BACKWARD | CAN_SEEK_FORWARD | CAN_SEEK;
 }
 
@@ -504,23 +503,23 @@ status_t MPEG4Extractor::readMetaData() 
     } else {
         mInitCheck = err;
     }
 
     CHECK_NE(err, (status_t)NO_INIT);
 
     // copy pssh data into file metadata
     int psshsize = 0;
-    for (size_t i = 0; i < mPssh.size(); i++) {
+    for (size_t i = 0; i < mPssh.Length(); i++) {
         psshsize += 20 + mPssh[i].datalen;
     }
     if (psshsize) {
         char *buf = (char*)malloc(psshsize);
         char *ptr = buf;
-        for (size_t i = 0; i < mPssh.size(); i++) {
+        for (size_t i = 0; i < mPssh.Length(); i++) {
             memcpy(ptr, mPssh[i].uuid, 20); // uuid + length
             memcpy(ptr + 20, mPssh[i].data, mPssh[i].datalen);
             ptr += (20 + mPssh[i].datalen);
         }
         mFileMetaData->setData(kKeyPssh, 'pssh', buf, psshsize);
         free(buf);
     }
     return mInitCheck;
@@ -690,34 +689,34 @@ status_t MPEG4Extractor::parseDrmSINF(of
     if (size != 0) {
         return ERROR_MALFORMED;
     }
 
     return UNKNOWN_ERROR;  // Return a dummy error.
 }
 
 struct PathAdder {
-    PathAdder(Vector<uint32_t> *path, uint32_t chunkType)
+    PathAdder(nsTArray<uint32_t> *path, uint32_t chunkType)
         : mPath(path) {
-        mPath->push(chunkType);
+        mPath->AppendElement(chunkType);
     }
 
     ~PathAdder() {
-        mPath->pop();
+        mPath->RemoveElementAt(mPath->Length() - 1);
     }
 
 private:
-    Vector<uint32_t> *mPath;
+    nsTArray<uint32_t> *mPath;
 
     PathAdder(const PathAdder &);
     PathAdder &operator=(const PathAdder &);
 };
 
-static bool underMetaDataPath(const Vector<uint32_t> &path) {
-    return path.size() >= 5
+static bool underMetaDataPath(const nsTArray<uint32_t> &path) {
+    return path.Length() >= 5
         && path[0] == FOURCC('m', 'o', 'o', 'v')
         && path[1] == FOURCC('u', 'd', 't', 'a')
         && path[2] == FOURCC('m', 'e', 't', 'a')
         && path[3] == FOURCC('i', 'l', 's', 't');
 }
 
 // Given a time in seconds since Jan 1 1904, produce a human-readable string.
 static bool convertTimeToDate(int64_t time_1904, String8 *s) {
@@ -802,17 +801,17 @@ status_t MPEG4Extractor::parseChunk(off6
 #endif
 
     PathAdder autoAdder(&mPath, chunk_type);
 
     off64_t chunk_data_size = *offset + chunk_size - data_offset;
 
     if (chunk_type != FOURCC('c', 'p', 'r', 't')
             && chunk_type != FOURCC('c', 'o', 'v', 'r')
-            && mPath.size() == 5 && underMetaDataPath(mPath)) {
+            && mPath.Length() == 5 && underMetaDataPath(mPath)) {
         off64_t stop_offset = *offset + chunk_size;
         *offset = data_offset;
         while (*offset < stop_offset) {
             status_t err = parseChunk(offset, depth + 1);
             if (err != OK) {
                 return err;
             }
         }
@@ -1130,17 +1129,17 @@ status_t MPEG4Extractor::parseChunk(off6
 
             // Copy the contents of the box (including header) verbatim.
             pssh.datalen = chunk_data_size + 8;
             pssh.data = new uint8_t[pssh.datalen];
             if (mDataSource->readAt(data_offset - 8, pssh.data, pssh.datalen) < pssh.datalen) {
                 return ERROR_IO;
             }
 
-            mPssh.push_back(pssh);
+            mPssh.AppendElement(pssh);
 
             *offset += chunk_size;
             break;
         }
 
         case FOURCC('m', 'd', 'h', 'd'):
         {
             if (chunk_data_size < 4) {
@@ -1686,19 +1685,19 @@ status_t MPEG4Extractor::parseChunk(off6
             }
 
             if (!mLastTrack) {
               return ERROR_MALFORMED;
             }
             mLastTrack->meta->setData(
                     kKeyESDS, kTypeESDS, &buffer[4], chunk_data_size - 4);
 
-            if (mPath.size() >= 2
-                    && (mPath[mPath.size() - 2] == FOURCC('m', 'p', '4', 'a') ||
-                       (mPath[mPath.size() - 2] == FOURCC('e', 'n', 'c', 'a')))) {
+            if (mPath.Length() >= 2
+                    && (mPath[mPath.Length() - 2] == FOURCC('m', 'p', '4', 'a') ||
+                       (mPath[mPath.Length() - 2] == FOURCC('e', 'n', 'c', 'a')))) {
                 // Information from the ESDS must be relied on for proper
                 // setup of sample rate and channel count for MPEG4 Audio.
                 // The generic header appears to only contain generic
                 // information...
 
                 status_t err = updateAudioTrackInfoFromESDS_MPEG4Audio(
                         &buffer[4], chunk_data_size - 4);
 
@@ -1806,17 +1805,17 @@ status_t MPEG4Extractor::parseChunk(off6
             }
             break;
         }
 
         case FOURCC('m', 'e', 'a', 'n'):
         case FOURCC('n', 'a', 'm', 'e'):
         case FOURCC('d', 'a', 't', 'a'):
         {
-            if (mPath.size() == 6 && underMetaDataPath(mPath)) {
+            if (mPath.Length() == 6 && underMetaDataPath(mPath)) {
                 status_t err = parseMetaData(data_offset, chunk_data_size);
 
                 if (err != OK) {
                     return err;
                 }
             }
 
             *offset += chunk_size;
@@ -2170,17 +2169,17 @@ status_t MPEG4Extractor::parseSegmentInd
             ALOGW("not a stream access point, or unsupported type");
         }
         total_duration += d2;
         offset += 12;
         ALOGV(" item %d, %08x %08x %08x", i, d1, d2, d3);
         SidxEntry se;
         se.mSize = d1 & 0x7fffffff;
         se.mDurationUs = 1000000LL * d2 / timeScale;
-        mSidxEntries.add(se);
+        mSidxEntries.AppendElement(se);
     }
 
     mSidxDuration = total_duration * 1000000 / timeScale;
     ALOGV("duration: %lld", mSidxDuration);
 
     if (!mLastTrack) {
       return ERROR_MALFORMED;
     }
@@ -2683,17 +2682,17 @@ status_t MPEG4Extractor::updateAudioTrac
 
 ////////////////////////////////////////////////////////////////////////////////
 
 MPEG4Source::MPEG4Source(
         const sp<MetaData> &format,
         const sp<DataSource> &dataSource,
         int32_t timeScale,
         const sp<SampleTable> &sampleTable,
-        Vector<SidxEntry> &sidx,
+        nsTArray<SidxEntry> &sidx,
         MPEG4Extractor::TrackExtends &trackExtends)
     : mFormat(format),
       mDataSource(dataSource),
       mTimescale(timeScale),
       mSampleTable(sampleTable),
       mCurrentSampleIndex(0),
       mCurrentFragmentIndex(0),
       mSegments(sidx),
@@ -2920,24 +2919,24 @@ status_t MPEG4Source::parseChunk(off64_t
     }
     return OK;
 }
 
 status_t MPEG4Source::parseSampleAuxiliaryInformationSizes(off64_t offset, off64_t size) {
     ALOGV("parseSampleAuxiliaryInformationSizes");
     // 14496-12 8.7.12
 
-    if (mCurrentSamples.isEmpty()) {
+    if (mCurrentSamples.IsEmpty()) {
         // XXX hack -- we haven't seen trun yet; defer parsing this box until
         // after trun.
         ALOGW("deferring processing of saiz box");
         AuxRange range;
         range.mStart = offset;
         range.mSize = size;
-        mDeferredSaiz.add(range);
+        mDeferredSaiz.AppendElement(range);
         return OK;
     }
 
     uint8_t version;
     if (mDataSource->readAt(
             offset, &version, sizeof(version))
             < (ssize_t)sizeof(version)) {
         return ERROR_IO;
@@ -2994,24 +2993,24 @@ status_t MPEG4Source::parseSampleAuxilia
     mDataSource->readAt(offset, mCurrentSampleInfoSizes, smplcnt);
     return OK;
 }
 
 status_t MPEG4Source::parseSampleAuxiliaryInformationOffsets(off64_t offset, off64_t size) {
     ALOGV("parseSampleAuxiliaryInformationOffsets");
     // 14496-12 8.7.13
 
-    if (mCurrentSamples.isEmpty()) {
+    if (mCurrentSamples.IsEmpty()) {
         // XXX hack -- we haven't seen trun yet; defer parsing this box until
         // after trun.
         ALOGW("deferring processing of saio box");
         AuxRange range;
         range.mStart = offset;
         range.mSize = size;
-        mDeferredSaio.add(range);
+        mDeferredSaio.AppendElement(range);
         return OK;
     }
 
     uint8_t version;
     if (mDataSource->readAt(offset, &version, sizeof(version)) != 1) {
         return ERROR_IO;
     }
     offset++;
@@ -3062,17 +3061,17 @@ status_t MPEG4Source::parseSampleAuxilia
     off64_t drmoffset = mCurrentSampleInfoOffsets[0]; // from moof
 
     drmoffset += mCurrentMoofOffset;
     int ivlength;
     CHECK(mFormat->findInt32(kKeyCryptoDefaultIVSize, &ivlength));
 
     // read CencSampleAuxiliaryDataFormats
     for (size_t i = 0; i < mCurrentSampleInfoCount; i++) {
-        Sample *smpl = &mCurrentSamples.editItemAt(i);
+        Sample *smpl = &mCurrentSamples[i];
 
         memset(smpl->iv, 0, 16);
         if (mDataSource->readAt(drmoffset, smpl->iv, ivlength) != ivlength) {
             return ERROR_IO;
         }
 
         drmoffset += ivlength;
 
@@ -3092,22 +3091,22 @@ status_t MPEG4Source::parseSampleAuxilia
                 if (!mDataSource->getUInt16(drmoffset, &numclear)) {
                     return ERROR_IO;
                 }
                 drmoffset += 2;
                 if (!mDataSource->getUInt32(drmoffset, &numencrypted)) {
                     return ERROR_IO;
                 }
                 drmoffset += 4;
-                smpl->clearsizes.add(numclear);
-                smpl->encryptedsizes.add(numencrypted);
+                smpl->clearsizes.AppendElement(numclear);
+                smpl->encryptedsizes.AppendElement(numencrypted);
             }
         } else {
-            smpl->clearsizes.add(0);
-            smpl->encryptedsizes.add(smpl->size);
+            smpl->clearsizes.AppendElement(0);
+            smpl->encryptedsizes.AppendElement(smpl->size);
         }
     }
 
 
     return OK;
 }
 
 status_t MPEG4Source::parseTrackFragmentData(off64_t offset, off64_t size) {
@@ -3396,24 +3395,24 @@ status_t MPEG4Source::parseTrackFragment
                 (flags & kFirstSampleFlagsPresent) && i == 0
                     ? firstSampleFlags : sampleFlags);
         tmp.flags = (flags & kFirstSampleFlagsPresent) && i == 0
                 ? firstSampleFlags : sampleFlags;
         tmp.offset = dataOffset;
         tmp.size = sampleSize;
         tmp.duration = sampleDuration;
         tmp.ctsOffset = (int32_t)sampleCtsOffset;
-        mCurrentSamples.add(tmp);
+        mCurrentSamples.AppendElement(tmp);
 
         dataOffset += sampleSize;
     }
 
     mTrackFragmentHeaderInfo.mDataOffset = dataOffset;
 
-    for (size_t i = 0; i < mDeferredSaio.size() && i < mDeferredSaiz.size(); i++) {
+    for (size_t i = 0; i < mDeferredSaio.Length() && i < mDeferredSaiz.Length(); i++) {
         const auto& saio = mDeferredSaio[i];
         const auto& saiz = mDeferredSaiz[i];
         parseSampleAuxiliaryInformationSizes(saiz.mStart, saiz.mSize);
         parseSampleAuxiliaryInformationOffsets(saio.mStart, saio.mSize);
     }
 
     return OK;
 }
@@ -3653,31 +3652,31 @@ status_t MPEG4Source::read(
                         kKeyTargetTime, targetSampleTimeUs);
             }
 
             if (isSyncSample) {
                 mBuffer->meta_data()->setInt32(kKeyIsSyncFrame, 1);
             }
 
             if (mSampleTable->hasCencInfo()) {
-                Vector<uint16_t> clearSizes;
-                Vector<uint32_t> cipherSizes;
+                nsTArray<uint16_t> clearSizes;
+                nsTArray<uint32_t> cipherSizes;
                 uint8_t iv[16];
                 status_t err = mSampleTable->getSampleCencInfo(
                         mCurrentSampleIndex, clearSizes, cipherSizes, iv);
 
                 if (err != OK) {
                     return err;
                 }
 
                 const auto& meta = mBuffer->meta_data();
-                meta->setData(kKeyPlainSizes, 0, clearSizes.array(),
-                              clearSizes.size() * sizeof(uint16_t));
-                meta->setData(kKeyEncryptedSizes, 0, cipherSizes.array(),
-                              cipherSizes.size() * sizeof(uint32_t));
+                meta->setData(kKeyPlainSizes, 0, clearSizes.Elements(),
+                              clearSizes.Length() * sizeof(uint16_t));
+                meta->setData(kKeyEncryptedSizes, 0, cipherSizes.Elements(),
+                              cipherSizes.Length() * sizeof(uint32_t));
                 meta->setData(kKeyCryptoIV, 0, iv, sizeof(iv));
                 meta->setInt32(kKeyCryptoDefaultIVSize, mDefaultIVSize);
                 meta->setInt32(kKeyCryptoMode, mCryptoMode);
                 meta->setData(kKeyCryptoKey, 0, mCryptoKey, 16);
             }
 
             ++mCurrentSampleIndex;
         }
@@ -3819,31 +3818,31 @@ status_t MPEG4Source::read(
                     kKeyTargetTime, targetSampleTimeUs);
         }
 
         if (isSyncSample) {
             mBuffer->meta_data()->setInt32(kKeyIsSyncFrame, 1);
         }
 
         if (mSampleTable->hasCencInfo()) {
-            Vector<uint16_t> clearSizes;
-            Vector<uint32_t> cipherSizes;
+            nsTArray<uint16_t> clearSizes;
+            nsTArray<uint32_t> cipherSizes;
             uint8_t iv[16];
             status_t err = mSampleTable->getSampleCencInfo(
                     mCurrentSampleIndex, clearSizes, cipherSizes, iv);
 
             if (err != OK) {
                 return err;
             }
 
             const auto& meta = mBuffer->meta_data();
-            meta->setData(kKeyPlainSizes, 0, clearSizes.array(),
-                          clearSizes.size() * sizeof(uint16_t));
-            meta->setData(kKeyEncryptedSizes, 0, cipherSizes.array(),
-                          cipherSizes.size() * sizeof(uint32_t));
+            meta->setData(kKeyPlainSizes, 0, clearSizes.Elements(),
+                          clearSizes.Length() * sizeof(uint16_t));
+            meta->setData(kKeyEncryptedSizes, 0, cipherSizes.Elements(),
+                          cipherSizes.Length() * sizeof(uint32_t));
             meta->setData(kKeyCryptoIV, 0, iv, sizeof(iv));
             meta->setInt32(kKeyCryptoDefaultIVSize, mDefaultIVSize);
             meta->setInt32(kKeyCryptoMode, mCryptoMode);
             meta->setData(kKeyCryptoKey, 0, mCryptoKey, 16);
         }
 
         ++mCurrentSampleIndex;
 
@@ -3851,19 +3850,19 @@ status_t MPEG4Source::read(
         mBuffer = NULL;
 
         return OK;
     }
 }
 
 status_t MPEG4Source::moveToNextFragment() {
     off64_t nextMoof = mNextMoofOffset;
-    mCurrentSamples.clear();
-    mDeferredSaio.clear();
-    mDeferredSaiz.clear();
+    mCurrentSamples.Clear();
+    mDeferredSaio.Clear();
+    mDeferredSaiz.Clear();
     mCurrentSampleIndex = 0;
     uint32_t hdr[2];
     do {
         if (mDataSource->readAt(nextMoof, hdr, 8) < 8) {
             return ERROR_END_OF_STREAM;
         }
         uint64_t chunk_size = ntohl(hdr[0]);
         uint32_t chunk_type = ntohl(hdr[1]);
@@ -3873,17 +3872,17 @@ status_t MPEG4Source::moveToNextFragment
             nextMoof += chunk_size;
             continue;
         }
         mCurrentMoofOffset = nextMoof;
         status_t ret = parseChunk(&nextMoof);
         if (ret != OK) {
             return ret;
         }
-    } while (mCurrentSamples.size() == 0);
+    } while (mCurrentSamples.Length() == 0);
     return OK;
 }
 
 status_t MPEG4Source::fragmentedRead(
         MediaBuffer **out, const ReadOptions *options) {
 
     ALOGV("MPEG4Source::fragmentedRead");
 
@@ -3892,17 +3891,17 @@ status_t MPEG4Source::fragmentedRead(
     *out = NULL;
 
     int64_t targetSampleTimeUs = -1;
 
     int64_t seekTimeUs;
     ReadOptions::SeekMode mode;
     if (options && options->getSeekTo(&seekTimeUs, &mode)) {
 
-        int numSidxEntries = mSegments.size();
+        int numSidxEntries = mSegments.Length();
         if (numSidxEntries != 0) {
             int64_t totalTime = 0;
             off64_t totalOffset = mFirstMoofOffset;
             for (int i = 0; i < numSidxEntries; i++) {
                 const SidxEntry *se = &mSegments[i];
                 if (totalTime + se->mDurationUs > seekTimeUs) {
                     // The requested time is somewhere in this segment
                     if ((mode == ReadOptions::SEEK_NEXT_SYNC) ||
@@ -3914,42 +3913,42 @@ status_t MPEG4Source::fragmentedRead(
                         totalOffset += se->mSize;
                     }
                     break;
                 }
                 totalTime += se->mDurationUs;
                 totalOffset += se->mSize;
             }
             mCurrentMoofOffset = totalOffset;
-            mCurrentSamples.clear();
-            mDeferredSaio.clear();
-            mDeferredSaiz.clear();
+            mCurrentSamples.Clear();
+            mDeferredSaio.Clear();
+            mDeferredSaiz.Clear();
             mCurrentSampleIndex = 0;
             mCurrentTime = totalTime * mTimescale / 1000000ll;
             mNextMoofOffset = totalOffset;
         }
         else {
             mNextMoofOffset = mFirstMoofOffset;
             uint32_t seekTime = (int32_t) ((seekTimeUs * mTimescale) / 1000000ll);
             while (true) {
                 status_t ret = moveToNextFragment();
                 if (ret != OK) {
                     return ret;
                 }
                 uint32_t time = mCurrentTime;
                 int i;
-                for (i = 0; i < mCurrentSamples.size() && time <= seekTime; i++) {
+                for (i = 0; i < mCurrentSamples.Length() && time <= seekTime; i++) {
                     const Sample *smpl = &mCurrentSamples[i];
                     if (smpl->isSync()) {
                         mCurrentSampleIndex = i;
                         mCurrentTime = time;
                     }
                     time += smpl->duration;
                 }
-                if (i != mCurrentSamples.size()) {
+                if (i != mCurrentSamples.Length()) {
                     break;
                 }
             }
             ALOGV("Seeking offset %d; %ldus\n", mCurrentTime - seekTime,
                     (((int64_t) mCurrentTime - seekTime) * 1000000ll) / mTimescale);
         }
 
         if (mBuffer != NULL) {
@@ -3965,17 +3964,17 @@ status_t MPEG4Source::fragmentedRead(
     uint32_t dts = 0;
     int64_t cts = 0;
     uint32_t duration = 0;
     bool isSyncSample = false;
     bool newBuffer = false;
     if (mBuffer == NULL) {
         newBuffer = true;
 
-        if (mCurrentSampleIndex >= mCurrentSamples.size()) {
+        if (mCurrentSampleIndex >= mCurrentSamples.Length()) {
             status_t ret = moveToNextFragment();
             if (ret != OK) {
                 return ret;
             }
         }
 
         const Sample *smpl = &mCurrentSamples[mCurrentSampleIndex];
         offset = smpl->offset;
@@ -3989,22 +3988,22 @@ status_t MPEG4Source::fragmentedRead(
         int32_t max_size;
         CHECK(mFormat->findInt32(kKeyMaxInputSize, &max_size));
         mBuffer = new MediaBuffer(std::min(max_size, 1024 * 1024));
     }
 
     const Sample *smpl = &mCurrentSamples[mCurrentSampleIndex];
     const sp<MetaData> bufmeta = mBuffer->meta_data();
     bufmeta->clear();
-    if (smpl->encryptedsizes.size()) {
+    if (smpl->encryptedsizes.Length()) {
         // store clear/encrypted lengths in metadata
         bufmeta->setData(kKeyPlainSizes, 0,
-                smpl->clearsizes.array(), smpl->clearsizes.size() * 2);
+                smpl->clearsizes.Elements(), smpl->clearsizes.Length() * 2);
         bufmeta->setData(kKeyEncryptedSizes, 0,
-                smpl->encryptedsizes.array(), smpl->encryptedsizes.size() * 4);
+                smpl->encryptedsizes.Elements(), smpl->encryptedsizes.Length() * 4);
         bufmeta->setData(kKeyCryptoIV, 0, smpl->iv, 16); // use 16 or the actual size?
         bufmeta->setInt32(kKeyCryptoDefaultIVSize, mDefaultIVSize);
         bufmeta->setInt32(kKeyCryptoMode, mCryptoMode);
         bufmeta->setData(kKeyCryptoKey, 0, mCryptoKey, 16);
     }
 
     if (!mIsAVC || mWantsNALFragments) {
         if (newBuffer) {
--- a/media/libstagefright/frameworks/av/media/libstagefright/SampleTable.cpp
+++ b/media/libstagefright/frameworks/av/media/libstagefright/SampleTable.cpp
@@ -509,17 +509,17 @@ SampleTable::setSampleAuxiliaryInformati
         return err;
     }
 
     if (aux_type && aux_type != kAuxTypeCenc && drm_scheme != kAuxTypeCenc) {
         // Quietly skip aux types we don't care about.
         return OK;
     }
 
-    if (!mCencSizes.isEmpty() || mCencDefaultSize) {
+    if (!mCencSizes.IsEmpty() || mCencDefaultSize) {
         ALOGE("duplicate cenc saiz box");
         return ERROR_MALFORMED;
     }
 
     if (version) {
         ALOGV("unsupported cenc saiz version");
         return ERROR_UNSUPPORTED;
     }
@@ -531,19 +531,21 @@ SampleTable::setSampleAuxiliaryInformati
     }
 
     if (!mDataSource->getUInt32(data_offset, &mCencInfoCount)) {
         return ERROR_IO;
     }
     data_offset += 4;
 
     if (!mCencDefaultSize) {
-        mCencSizes.insertAt(0, 0, mCencInfoCount);
+        if (!mCencSizes.InsertElementsAt(0, mCencInfoCount, mozilla::fallible)) {
+          return ERROR_IO;
+        }
         if (mDataSource->readAt(
-                    data_offset, mCencSizes.editArray(), mCencInfoCount)
+                    data_offset, mCencSizes.Elements(), mCencInfoCount)
                     < mCencInfoCount) {
             return ERROR_IO;
         }
         data_offset += mCencInfoCount;
     }
 
     CHECK(data_offset == data_end);
 
@@ -563,84 +565,91 @@ SampleTable::setSampleAuxiliaryInformati
         return err;
     }
 
     if (aux_type && aux_type != kAuxTypeCenc && drm_scheme != kAuxTypeCenc) {
         // Quietly skip aux types we don't care about.
         return OK;
     }
 
-    if (!mCencOffsets.isEmpty()) {
+    if (!mCencOffsets.IsEmpty()) {
         ALOGE("duplicate cenc saio box");
         return ERROR_MALFORMED;
     }
 
     uint32_t cencOffsetCount;
     if (!mDataSource->getUInt32(data_offset, &cencOffsetCount)) {
         ALOGE("error reading cenc aux info offset count");
         return ERROR_IO;
     }
     data_offset += 4;
 
-    if (mCencOffsets.setCapacity(cencOffsetCount) < 0) {
+    if (cencOffsetCount >= kMAX_ALLOCATION) {
         return ERROR_MALFORMED;
     }
     if (!version) {
+        if (!mCencOffsets.SetCapacity(cencOffsetCount, mozilla::fallible)) {
+            return ERROR_MALFORMED;
+        }
         for (uint32_t i = 0; i < cencOffsetCount; i++) {
             uint32_t tmp;
             if (!mDataSource->getUInt32(data_offset, &tmp)) {
                 ALOGE("error reading cenc aux info offsets");
                 return ERROR_IO;
             }
-            mCencOffsets.push(tmp);
+            // FIXME: Make this infallible after bug 968520 is done.
+            MOZ_ALWAYS_TRUE(mCencOffsets.AppendElement(tmp, mozilla::fallible));
             data_offset += 4;
         }
     } else {
+        if (!mCencOffsets.SetLength(cencOffsetCount, mozilla::fallible)) {
+          return ERROR_MALFORMED;
+        }
         for (uint32_t i = 0; i < cencOffsetCount; i++) {
-            if (!mDataSource->getUInt64(data_offset, &mCencOffsets.editItemAt(i))) {
+            if (!mDataSource->getUInt64(data_offset, &mCencOffsets[i])) {
                 ALOGE("error reading cenc aux info offsets");
                 return ERROR_IO;
             }
             data_offset += 8;
         }
     }
 
     CHECK(data_offset == data_end);
 
     return parseSampleCencInfo();
 }
 
 status_t
 SampleTable::parseSampleCencInfo() {
-    if ((!mCencDefaultSize && !mCencInfoCount) || mCencOffsets.isEmpty()) {
+    if ((!mCencDefaultSize && !mCencInfoCount) || mCencOffsets.IsEmpty()) {
         // We don't have all the cenc information we need yet. Quietly fail and
         // hope we get the data we need later in the track header.
         ALOGV("Got half of cenc saio/saiz pair. Deferring parse until we get the other half.");
         return OK;
     }
 
-    if (!mCencSizes.isEmpty() && mCencOffsets.size() > 1 &&
-        mCencSizes.size() != mCencOffsets.size()) {
+    if (!mCencSizes.IsEmpty() && mCencOffsets.Length() > 1 &&
+        mCencSizes.IsEmpty() != mCencOffsets.Length()) {
         return ERROR_MALFORMED;
     }
 
     if (mCencInfoCount > kMAX_ALLOCATION / sizeof(SampleCencInfo)) {
         // Avoid future OOM.
         return ERROR_MALFORMED;
     }
 
     mCencInfo = new SampleCencInfo[mCencInfoCount];
     for (uint32_t i = 0; i < mCencInfoCount; i++) {
         mCencInfo[i].mSubsamples = NULL;
     }
 
     uint64_t nextOffset = mCencOffsets[0];
     for (uint32_t i = 0; i < mCencInfoCount; i++) {
         uint8_t size = mCencDefaultSize ? mCencDefaultSize : mCencSizes[i];
-        uint64_t offset = mCencOffsets.size() == 1 ? nextOffset : mCencOffsets[i];
+        uint64_t offset = mCencOffsets.Length() == 1 ? nextOffset : mCencOffsets[i];
         nextOffset = offset + size;
 
         auto& info = mCencInfo[i];
 
         if (size < IV_BYTES) {
             ALOGE("cenc aux info too small");
             return ERROR_MALFORMED;
         }
@@ -1091,36 +1100,32 @@ status_t SampleTable::getMetaDataForSamp
 }
 
 uint32_t SampleTable::getCompositionTimeOffset(uint32_t sampleIndex) {
     return mCompositionDeltaLookup->getCompositionTimeOffset(sampleIndex);
 }
 
 status_t
 SampleTable::getSampleCencInfo(
-        uint32_t sample_index, Vector<uint16_t>& clear_sizes,
-        Vector<uint32_t>& cipher_sizes, uint8_t iv[]) {
-    CHECK(clear_sizes.isEmpty() && cipher_sizes.isEmpty());
+        uint32_t sample_index, nsTArray<uint16_t>& clear_sizes,
+        nsTArray<uint32_t>& cipher_sizes, uint8_t iv[]) {
+    CHECK(clear_sizes.IsEmpty() && cipher_sizes.IsEmpty());
 
     if (sample_index >= mCencInfoCount) {
         ALOGE("cenc info requested for out of range sample index");
         return ERROR_MALFORMED;
     }
 
     auto& info = mCencInfo[sample_index];
-    if (clear_sizes.setCapacity(info.mSubsampleCount) < 0) {
-        return ERROR_MALFORMED;
-    }
-    if (cipher_sizes.setCapacity(info.mSubsampleCount) < 0) {
-        return ERROR_MALFORMED;
-    }
+    clear_sizes.SetCapacity(info.mSubsampleCount);
+    cipher_sizes.SetCapacity(info.mSubsampleCount);
 
     for (uint32_t i = 0; i < info.mSubsampleCount; i++) {
-        clear_sizes.push(info.mSubsamples[i].mClearBytes);
-        cipher_sizes.push(info.mSubsamples[i].mCipherBytes);
+        clear_sizes.AppendElement(info.mSubsamples[i].mClearBytes);
+        cipher_sizes.AppendElement(info.mSubsamples[i].mCipherBytes);
     }
 
     memcpy(iv, info.mIV, IV_BYTES);
 
     return OK;
 }
 
 }  // namespace stagefright
--- a/media/libstagefright/frameworks/av/media/libstagefright/include/MPEG4Extractor.h
+++ b/media/libstagefright/frameworks/av/media/libstagefright/include/MPEG4Extractor.h
@@ -19,18 +19,18 @@
 #define MPEG4_EXTRACTOR_H_
 
 #include <arpa/inet.h>
 
 #include <media/stagefright/DataSource.h>
 #include <media/stagefright/MediaExtractor.h>
 #include <media/stagefright/Utils.h>
 #include <utils/List.h>
-#include <utils/Vector.h>
 #include <utils/String8.h>
+#include "nsTArray.h"
 
 namespace stagefright {
 
 struct AMessage;
 class DataSource;
 class SampleTable;
 class String8;
 
@@ -92,31 +92,31 @@ private:
         uint64_t segment_duration;
         int64_t media_time;
 
         sp<SampleTable> sampleTable;
         bool includes_expensive_metadata;
         bool skipTrack;
     };
 
-    Vector<SidxEntry> mSidxEntries;
+    nsTArray<SidxEntry> mSidxEntries;
     uint64_t mSidxDuration;
 
-    Vector<PsshInfo> mPssh;
+    nsTArray<PsshInfo> mPssh;
 
     sp<DataSource> mDataSource;
     status_t mInitCheck;
     bool mHasVideo;
     uint32_t mHeaderTimescale;
 
     Track *mFirstTrack, *mLastTrack;
 
     sp<MetaData> mFileMetaData;
 
-    Vector<uint32_t> mPath;
+    nsTArray<uint32_t> mPath;
     String8 mLastCommentMean;
     String8 mLastCommentName;
     String8 mLastCommentData;
 
     status_t readMetaData();
     status_t parseChunk(off64_t *offset, int depth);
     status_t parseMetaData(off64_t offset, size_t size);
 
--- a/media/libstagefright/frameworks/av/media/libstagefright/include/SampleTable.h
+++ b/media/libstagefright/frameworks/av/media/libstagefright/include/SampleTable.h
@@ -19,17 +19,16 @@
 #define SAMPLE_TABLE_H_
 
 #include <sys/types.h>
 #include <stdint.h>
 
 #include <media/stagefright/MediaErrors.h>
 #include <utils/RefBase.h>
 #include <utils/threads.h>
-#include <utils/Vector.h>
 
 namespace stagefright {
 
 class DataSource;
 struct SampleIterator;
 
 class SampleTable : public RefBase {
 public:
@@ -91,18 +90,18 @@ public:
             uint32_t start_sample_index, uint32_t *sample_index,
             uint32_t flags);
 
     status_t findThumbnailSample(uint32_t *sample_index);
 
     bool hasCencInfo() const { return !!mCencInfo; }
 
     status_t getSampleCencInfo(uint32_t aSampleIndex,
-                               Vector<uint16_t>& aClearSizes,
-                               Vector<uint32_t>& aCipherSizes,
+                               nsTArray<uint16_t>& aClearSizes,
+                               nsTArray<uint32_t>& aCipherSizes,
                                uint8_t aIV[]);
 
 protected:
     ~SampleTable();
 
 private:
     struct CompositionDeltaLookup;
 
@@ -161,18 +160,18 @@ private:
         struct SubsampleSizes {
             uint16_t mClearBytes;
             uint32_t mCipherBytes;
         } * mSubsamples;
     } * mCencInfo;
     uint32_t mCencInfoCount;
 
     uint8_t mCencDefaultSize;
-    Vector<uint8_t> mCencSizes;
-    Vector<uint64_t> mCencOffsets;
+    FallibleTArray<uint8_t> mCencSizes;
+    FallibleTArray<uint64_t> mCencOffsets;
 
     friend struct SampleIterator;
 
     status_t getSampleSize_l(uint32_t sample_index, size_t *sample_size);
     uint32_t getCompositionTimeOffset(uint32_t sampleIndex);
 
     static int CompareIncreasingTime(const void *, const void *);