Bug 1309163: P2. Add AnnexB::HasPPS methods. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 24 Oct 2016 17:23:02 +1100
changeset 325345 99d76c84603d08dcccbd85630c5a62aebc909694
parent 325344 c58bfbe2800682c2c2c85716d3155e30a33997ad
child 325346 8930cf031f641559e69435b251eac3d134443c64
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersgerald
bugs1309163
milestone53.0a1
Bug 1309163: P2. Add AnnexB::HasPPS methods. r=gerald MozReview-Commit-ID: 7M58OXvCp5q
media/libstagefright/binding/AnnexB.cpp
media/libstagefright/binding/include/mp4_demuxer/AnnexB.h
--- a/media/libstagefright/binding/AnnexB.cpp
+++ b/media/libstagefright/binding/AnnexB.cpp
@@ -329,16 +329,57 @@ AnnexB::HasSPS(const mozilla::MediaByteB
     return false;
   }
   uint8_t numSps = reader.ReadU8() & 0x1f;
 
   return numSps > 0;
 }
 
 bool
+AnnexB::HasPPS(const mozilla::MediaRawData* aSample)
+{
+  return HasPPS(aSample->mExtraData);
+}
+
+bool
+AnnexB::HasPPS(const mozilla::MediaByteBuffer* aExtraData)
+{
+  if (!aExtraData) {
+    return false;
+  }
+
+  ByteReader reader(aExtraData);
+  const uint8_t* ptr = reader.Read(5);
+  if (!ptr || !reader.CanRead8()) {
+    return false;
+  }
+  uint8_t numSps = reader.ReadU8() & 0x1f;
+  // Skip over the included SPS.
+  for (uint8_t i = 0; i < numSps; i++) {
+    if (reader.Remaining() < 3) {
+      return false;
+    }
+    uint16_t length = reader.ReadU16();
+    if ((reader.PeekU8() & 0x1f) != 7) {
+      // Not an SPS NAL type.
+      return false;
+    }
+    if (!reader.Read(length)) {
+      return false;
+    }
+  }
+  if (!reader.CanRead8()) {
+    return false;
+  }
+  uint8_t numPps = reader.ReadU8();
+
+  return numPps > 0;
+}
+
+bool
 AnnexB::ConvertSampleTo4BytesAVCC(mozilla::MediaRawData* aSample)
 {
   MOZ_ASSERT(IsAVCC(aSample));
 
   int nalLenSize = ((*aSample->mExtraData)[4] & 3) + 1;
 
   if (nalLenSize == 4) {
     return true;
--- a/media/libstagefright/binding/include/mp4_demuxer/AnnexB.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/AnnexB.h
@@ -31,16 +31,18 @@ public:
     const mozilla::MediaByteBuffer* aExtraData);
   // Extract SPS and PPS NALs from aSample, aSample must be in AVCC format.
   // If aSample already contains an extradata with an SPS, it will be returned
   // otherwise the SPS/PPS NALs are searched in-band.
   static already_AddRefed<mozilla::MediaByteBuffer> ExtractExtraData(
     const mozilla::MediaRawData* aSample);
   static bool HasSPS(const mozilla::MediaRawData* aSample);
   static bool HasSPS(const mozilla::MediaByteBuffer* aExtraData);
+  static bool HasPPS(const mozilla::MediaRawData* aSample);
+  static bool HasPPS(const mozilla::MediaByteBuffer* aExtraData);
   // Returns true if format is AVCC and sample has valid extradata.
   static bool IsAVCC(const mozilla::MediaRawData* aSample);
   // Returns true if format is AnnexB.
   static bool IsAnnexB(const mozilla::MediaRawData* aSample);
   // Return true if both extradata are equal.
   static bool CompareExtraData(const mozilla::MediaByteBuffer* aExtraData1,
                                const mozilla::MediaByteBuffer* aExtraData2);