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

--HG--
extra : rebase_source : 4bfecd012904942f6ad38be9b6b69786d2d732d1
This commit is contained in:
Alastor Wu 2016-12-08 08:50:42 -10:00
parent 1a51e913a5
commit 10799fa4e0
2 changed files with 29 additions and 6 deletions

View File

@ -151,10 +151,12 @@ H264::DecodeNALUnit(const mozilla::MediaByteBuffer* aNAL)
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;
@ -576,7 +578,7 @@ H264::DecodeSPSDataSetFromExtraData(const mozilla::MediaByteBuffer* aExtraData,
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;
}
@ -647,7 +649,7 @@ H264::DecodePPSDataSetFromExtraData(const mozilla::MediaByteBuffer* aExtraData,
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;
}
@ -666,7 +668,7 @@ H264::DecodePPSDataSetFromExtraData(const mozilla::MediaByteBuffer* aExtraData,
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;
}
@ -881,7 +883,7 @@ H264::GetFrameType(const mozilla::MediaRawData* aSample)
if (!p) {
return FrameType::INVALID;
}
if ((p[0] & 0x1f) == 5) {
if ((p[0] & 0x1f) == H264_NAL_IDR_SLICE) {
// IDR NAL.
return FrameType::I_FRAME;
}

View File

@ -13,6 +13,27 @@ namespace mp4_demuxer {
#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