Bug 1384026 - Reduce memory usage. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 25 Jul 2017 18:36:52 +0200
changeset 371144 bcae431edab2c42d7e1a3dd49631ca9ed334d74d
parent 371143 4e1a1565e4175024b713b04bf20cef1fe34b4cb2
child 371145 16d3556f49050cd42087f4dbfbe924f50a71dab7
push id93039
push userkwierso@gmail.com
push dateThu, 27 Jul 2017 01:33:28 +0000
treeherdermozilla-inbound@35b0bdaacb0d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1384026
milestone56.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 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;