Bug 1365227: P1. Create AVCC header for converted annexB. r?JamesCheng draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 16 May 2017 14:22:43 +0200
changeset 578769 a8b5459fb39883da0e3252babc55390ddb01b20b
parent 578753 41002add7c469a73abd9e5cbcb744dbfd09a1870
child 578770 961506dbbcf9b0986596eca95ecc16e503786854
push id59047
push userbmo:jyavenard@mozilla.com
push dateTue, 16 May 2017 12:54:26 +0000
reviewersJamesCheng
bugs1365227
milestone55.0a1
Bug 1365227: P1. Create AVCC header for converted annexB. r?JamesCheng Otherwise AnnexB::IsAVCC will return false on those converted samples. MozReview-Commit-ID: 6OBV6L49InL
media/libstagefright/binding/AnnexB.cpp
--- a/media/libstagefright/binding/AnnexB.cpp
+++ b/media/libstagefright/binding/AnnexB.cpp
@@ -245,17 +245,35 @@ AnnexB::ConvertSampleToAVCC(mozilla::Med
   mozilla::Vector<uint8_t> nalu;
   ByteWriter writer(nalu);
   ByteReader reader(aSample->Data(), aSample->Size());
 
   if (!ParseNALUnits(writer, reader)) {
     return false;
   }
   nsAutoPtr<MediaRawDataWriter> samplewriter(aSample->CreateWriter());
-  return samplewriter->Replace(nalu.begin(), nalu.length());
+  if (!samplewriter->Replace(nalu.begin(), nalu.length())) {
+    return false;
+  }
+  // Create the AVCC header.
+  RefPtr<mozilla::MediaByteBuffer> extradata = new mozilla::MediaByteBuffer;
+  static const uint8_t kFakeExtraData[] = {
+    1 /* version */,
+    0x64 /* profile (High) */,
+    0 /* profile compat (0) */,
+    40 /* level (40) */,
+    0xfc | 3 /* nal size - 1 */,
+    0xe0 /* num SPS (0) */,
+    0 /* num PPS (0) */
+  };
+  if (!extradata->AppendElements(kFakeExtraData, ArrayLength(kFakeExtraData))) {
+    return false;
+  }
+  aSample->mExtraData = extradata;
+  return true;
 }
 
 already_AddRefed<mozilla::MediaByteBuffer>
 AnnexB::ExtractExtraData(const mozilla::MediaRawData* aSample)
 {
   RefPtr<mozilla::MediaByteBuffer> extradata = new mozilla::MediaByteBuffer;
   if (HasSPS(aSample->mExtraData)) {
     // We already have an explicit extradata, re-use it.