Bug 1365227: P2. Enforce that ExtractExtra data works on AVCC only. r?JamesCheng draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 16 May 2017 14:51:24 +0200
changeset 578770 961506dbbcf9b0986596eca95ecc16e503786854
parent 578769 a8b5459fb39883da0e3252babc55390ddb01b20b
child 581045 8906491f10b2b62c78ce261cfaa4a189357e0ba3
push id59047
push userbmo:jyavenard@mozilla.com
push dateTue, 16 May 2017 12:54:26 +0000
reviewersJamesCheng
bugs1365227
milestone55.0a1
Bug 1365227: P2. Enforce that ExtractExtra data works on AVCC only. r?JamesCheng MozReview-Commit-ID: ox5oaDvdfx
media/libstagefright/binding/AnnexB.cpp
--- a/media/libstagefright/binding/AnnexB.cpp
+++ b/media/libstagefright/binding/AnnexB.cpp
@@ -269,45 +269,35 @@ AnnexB::ConvertSampleToAVCC(mozilla::Med
   }
   aSample->mExtraData = extradata;
   return true;
 }
 
 already_AddRefed<mozilla::MediaByteBuffer>
 AnnexB::ExtractExtraData(const mozilla::MediaRawData* aSample)
 {
+  MOZ_ASSERT(IsAVCC(aSample));
+
   RefPtr<mozilla::MediaByteBuffer> extradata = new mozilla::MediaByteBuffer;
   if (HasSPS(aSample->mExtraData)) {
     // We already have an explicit extradata, re-use it.
     extradata = aSample->mExtraData;
     return extradata.forget();
   }
 
-  if (IsAnnexB(aSample)) {
-    // We can't extract data from AnnexB.
-    return extradata.forget();
-  }
-
   // SPS content
   mozilla::Vector<uint8_t> sps;
   ByteWriter spsw(sps);
   int numSps = 0;
   // PPS content
   mozilla::Vector<uint8_t> pps;
   ByteWriter ppsw(pps);
   int numPps = 0;
 
-  int nalLenSize;
-  if (IsAVCC(aSample)) {
-    nalLenSize = ((*aSample->mExtraData)[4] & 3) + 1;
-  } else {
-    // We do not have an extradata, assume it's AnnexB converted to AVCC via
-    // ConvertSampleToAVCC.
-    nalLenSize = 4;
-  }
+  int nalLenSize = ((*aSample->mExtraData)[4] & 3) + 1;
   ByteReader reader(aSample->Data(), aSample->Size());
 
   // Find SPS and PPS NALUs in AVCC data
   while (reader.Remaining() > nalLenSize) {
     uint32_t nalLen;
     switch (nalLenSize) {
       case 1: nalLen = reader.ReadU8();  break;
       case 2: nalLen = reader.ReadU16(); break;