Bug 1384026 - Reduce memory usage. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 25 Jul 2017 18:36:52 +0200
changeset 615683 a28e337baece3653f3fd3aaac439c099da09e991
parent 615105 07484bfdb96bc7297c404e377eea93f1d8ca4442
child 639240 44f363ffeafbc3a807a9b7ada2bd03e173a6ace4
child 641268 5c6c7f0f79eadece0f5907cf3244aa1362d58f30
push id70432
push userbmo:jyavenard@mozilla.com
push dateWed, 26 Jul 2017 07:38:53 +0000
reviewersgerald
bugs1384026
milestone56.0a1
Bug 1384026 - Reduce memory usage. r?gerald We dynamically allocate the memory we need and abort if OOM. MozReview-Commit-ID: FMGWbOXoN8P
media/libstagefright/binding/H264.cpp
--- a/media/libstagefright/binding/H264.cpp
+++ b/media/libstagefright/binding/H264.cpp
@@ -841,18 +841,17 @@ H264::ExtractExtraData(const mozilla::Me
       // This is invalid content.
       return nullptr;
     }
     sampleSize = aSample->mCrypto.mPlainSizes[0];
   }
 
   ByteReader reader(aSample->Data(), sampleSize);
 
-  nsTArray<SPSData> SPSTable(MAX_SPS_COUNT);
-  SPSTable.SetLength(MAX_SPS_COUNT);
+  nsTArray<SPSData> SPSTable;
   // If we encounter SPS with the same id but different content, we will stop
   // attempting to detect duplicates.
   bool checkDuplicate = true;
 
   // Find SPS and PPS NALUs in AVCC data
   while (reader.Remaining() > nalLenSize) {
     uint32_t nalLen;
     switch (nalLenSize) {
@@ -870,16 +869,22 @@ H264::ExtractExtraData(const mozilla::Me
     if (nalType == H264_NAL_SPS) {
       RefPtr<mozilla::MediaByteBuffer> sps = DecodeNALUnit(p, nalLen);
       SPSData data;
       if (!DecodeSPS(sps, data)) {
         // Invalid SPS, ignore.
         continue;
       }
       uint8_t spsId = data.seq_parameter_set_id;
+      if (spsId >= SPSTable.Length()) {
+        if (!SPSTable.SetLength(spsId + 1, fallible)) {
+          // OOM.
+          return nullptr;
+        }
+      }
       if (checkDuplicate && SPSTable[spsId].valid && SPSTable[spsId] == data) {
         // Duplicate ignore.
         continue;
       }
       if (SPSTable[spsId].valid) {
         // We already have detected a SPS with this Id. Just to be safe we
         // disable SPS duplicate detection.
         checkDuplicate = false;