Bug 1145517: Part2. Follow exactly ITU H.264 7.3.1. r=cpearce
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 20 Mar 2015 19:44:39 +1100
changeset 234641 63b94f124c880efe217a83646338c6e1ee54b6ad
parent 234640 45d65bb9e0ef3db8c4e0f35839c000a76fa2dc86
child 234642 78195e7115a296631c2a292b09590b53c1de6746
push id57186
push usercpearce@mozilla.com
push dateFri, 20 Mar 2015 10:38:25 +0000
treeherdermozilla-inbound@63b94f124c88 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1145517
milestone39.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 1145517: Part2. Follow exactly ITU H.264 7.3.1. r=cpearce We wouldn't have properly handled sequence of more than two zeros and 0x03.
media/libstagefright/binding/H264.cpp
media/libstagefright/binding/include/mp4_demuxer/H264.h
--- a/media/libstagefright/binding/H264.cpp
+++ b/media/libstagefright/binding/H264.cpp
@@ -108,27 +108,26 @@ H264::DecodeNALUnit(const ByteBuffer* aN
       nalUnitHeaderBytes += 2;
     } else {
       nalUnitHeaderBytes += 3;
     }
   }
   if (!reader.Read(nalUnitHeaderBytes - 1)) {
     return nullptr;
   }
-  uint32_t zeros = 0;
+  uint32_t lastbytes = 0xffff;
   while (reader.Remaining()) {
     uint8_t byte = reader.ReadU8();
-    if (zeros < 2 || byte != 0x03) {
+    if ((lastbytes & 0xffff) == 0 && byte == 0x03) {
+      // reset last two bytes, to detect the 0x000003 sequence again.
+      lastbytes = 0xffff;
+    } else {
       rbsp->AppendElement(byte);
     }
-    if (byte == 0) {
-      zeros++;
-    } else {
-      zeros = 0;
-    }
+    lastbytes = (lastbytes << 8) | byte;
   }
   return rbsp.forget();
 }
 
 static int32_t
 ConditionDimension(float aValue)
 {
   // This will exclude NaNs and too-big values.
--- a/media/libstagefright/binding/include/mp4_demuxer/H264.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/H264.h
@@ -316,17 +316,19 @@ struct SPSData
   SPSData();
 };
 
 class H264
 {
 public:
   static bool DecodeSPSFromExtraData(const ByteBuffer* aExtraData, SPSData& aDest);
   /* Extract RAW BYTE SEQUENCE PAYLOAD from NAL content.
-     Returns nullptr if invalid content. */
+     Returns nullptr if invalid content.
+     This is compliant to ITU H.264 7.3.1 Syntax in tabular form NAL unit syntax
+   */
   static already_AddRefed<ByteBuffer> DecodeNALUnit(const ByteBuffer* aNAL);
   /* Decode SPS NAL RBSP and fill SPSData structure */
   static bool DecodeSPS(const ByteBuffer* aSPS, SPSData& aDest);
   // Ensure that SPS data makes sense, Return true if SPS data was, and false
   // otherwise. If false, then content will be adjusted accordingly.
   static bool EnsureSPSIsSane(SPSData& aSPS);
 
 private: