Bug 1321164 - part2 : use enum for NAL types. r=jya
authorAlastor Wu <alwu@mozilla.com>
Thu, 08 Dec 2016 08:50:42 -1000
changeset 325421 06552bcdabecef7cd6c9a4a82ea390a231c04977
parent 325420 9169c83424aa17f2e05ef3f2ee2857b0e9fec24c
child 325422 9d41238dabf42896e32ab1df01cb477f25e207f8
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersjya
bugs1321164
milestone53.0a1
Bug 1321164 - part2 : use enum for NAL types. r=jya In order to increase the readability, use enum value for the NAL types. MozReview-Commit-ID: 8iwFbB7BEOM
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
@@ -146,20 +146,22 @@ H264::DecodeNALUnit(const mozilla::Media
   if (aNAL->Length() < 4) {
     return nullptr;
   }
 
   RefPtr<mozilla::MediaByteBuffer> rbsp = new mozilla::MediaByteBuffer;
   ByteReader reader(aNAL);
   uint8_t nal_unit_type = reader.ReadU8() & 0x1f;
   uint32_t nalUnitHeaderBytes = 1;
-  if (nal_unit_type == 14 || nal_unit_type == 20 || nal_unit_type == 21) {
+  if (nal_unit_type == H264_NAL_PREFIX ||
+      nal_unit_type == H264_NAL_SLICE_EXT ||
+      nal_unit_type == H264_NAL_SLICE_EXT_DVC) {
     bool svc_extension_flag = false;
     bool avc_3d_extension_flag = false;
-    if (nal_unit_type != 21) {
+    if (nal_unit_type != H264_NAL_SLICE_EXT_DVC) {
       svc_extension_flag = reader.PeekU8() & 0x80;
     } else {
       avc_3d_extension_flag = reader.PeekU8() & 0x80;
     }
     if (svc_extension_flag) {
       nalUnitHeaderBytes += 3;
     } else if (avc_3d_extension_flag) {
       nalUnitHeaderBytes += 2;
@@ -571,17 +573,17 @@ H264::DecodeSPSDataSetFromExtraData(cons
     // No SPS.
     return false;
   }
   NS_ASSERTION(numSps <= MAX_SPS_COUNT, "Exceed the maximum SPS counts!");
 
   for (uint32_t idx = 0; idx < numSps; idx++) {
     uint16_t length = reader.ReadU16();
 
-    if ((reader.PeekU8() & 0x1f) != 7) {
+    if ((reader.PeekU8() & 0x1f) != H264_NAL_SPS) {
       // Not a SPS NAL type.
       return false;
     }
     const uint8_t* ptr = reader.Read(length);
     if (!ptr) {
       return false;
     }
 
@@ -642,17 +644,17 @@ H264::DecodePPSDataSetFromExtraData(cons
   if (!numSps) {
     // No SPS.
     return false;
   }
   NS_ASSERTION(numSps == 1, "More than one SPS in extradata");
   for (uint8_t i = 0; i < numSps; i++) {
     uint16_t length = reader.ReadU16();
 
-    if ((reader.PeekU8() & 0x1f) != 7) {
+    if ((reader.PeekU8() & 0x1f) != H264_NAL_SPS) {
       // Not a SPS NAL type.
       return false;
     }
     const uint8_t* ptr = reader.Read(length);
     if (!ptr) {
       return false;
     }
   }
@@ -661,17 +663,17 @@ H264::DecodePPSDataSetFromExtraData(cons
     // No PPs.
     return false;
   }
   NS_ASSERTION(numPps <= MAX_PPS_COUNT, "Exceed the maximum PPS counts!");
 
   for (uint32_t idx = 0; idx < numPps; idx++) {
     uint16_t length = reader.ReadU16();
 
-    if ((reader.PeekU8() & 0x1f) != 8) {
+    if ((reader.PeekU8() & 0x1f) != H264_NAL_PPS) {
       // Not a PPS NAL type.
       return false;
     }
     const uint8_t* ptr = reader.Read(length);
     if (!ptr) {
       return false;
     }
 
@@ -876,17 +878,17 @@ H264::GetFrameType(const mozilla::MediaR
     }
     if (!nalLen) {
       continue;
     }
     const uint8_t* p = reader.Read(nalLen);
     if (!p) {
       return FrameType::INVALID;
     }
-    if ((p[0] & 0x1f) == 5) {
+    if ((p[0] & 0x1f) == H264_NAL_IDR_SLICE) {
       // IDR NAL.
       return FrameType::I_FRAME;
     }
   }
 
   return FrameType::OTHER;
 }
 
--- a/media/libstagefright/binding/include/mp4_demuxer/H264.h
+++ b/media/libstagefright/binding/include/mp4_demuxer/H264.h
@@ -8,16 +8,37 @@
 #include "mp4_demuxer/DecoderData.h"
 
 namespace mp4_demuxer {
 
 // Spec 7.4.2.1
 #define MAX_SPS_COUNT 32
 #define MAX_PPS_COUNT 256
 
+// NAL unit types
+enum NAL_TYPES {
+    H264_NAL_SLICE           = 1,
+    H264_NAL_DPA             = 2,
+    H264_NAL_DPB             = 3,
+    H264_NAL_DPC             = 4,
+    H264_NAL_IDR_SLICE       = 5,
+    H264_NAL_SEI             = 6,
+    H264_NAL_SPS             = 7,
+    H264_NAL_PPS             = 8,
+    H264_NAL_AUD             = 9,
+    H264_NAL_END_SEQUENCE    = 10,
+    H264_NAL_END_STREAM      = 11,
+    H264_NAL_FILLER_DATA     = 12,
+    H264_NAL_SPS_EXT         = 13,
+    H264_NAL_PREFIX          = 14,
+    H264_NAL_AUXILIARY_SLICE = 19,
+    H264_NAL_SLICE_EXT       = 20,
+    H264_NAL_SLICE_EXT_DVC   = 21,
+};
+
 class BitReader;
 
 struct SPSData
 {
   /* Decoded Members */
   /*
     pic_width is the decoded width according to:
     pic_width = ((pic_width_in_mbs_minus1 + 1) * 16)