Bug 1384026 - Reduce memory usage. r?gerald
We dynamically allocate the memory we need and abort if OOM.
MozReview-Commit-ID: FMGWbOXoN8P
--- 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;