diff --git a/dom/media/platforms/agnostic/bytestreams/H264.cpp b/dom/media/platforms/agnostic/bytestreams/H264.cpp index a6e258876d4f..197ce2537b1b 100644 --- a/dom/media/platforms/agnostic/bytestreams/H264.cpp +++ b/dom/media/platforms/agnostic/bytestreams/H264.cpp @@ -984,6 +984,19 @@ uint32_t H264::ComputeMaxRefFrames(const mozilla::MediaByteBuffer* aExtraData) { if (DecodeRecoverySEI(decodedNAL, data)) { return FrameType::I_FRAME; } + } else if (nalType == H264_NAL_SLICE) { + // According to ITU-T Rec H.264 Table 7.3.3, read the slice type from + // slice_header, and the slice type 2 and 7 are representing I slice. + RefPtr decodedNAL = DecodeNALUnit(p, nalLen); + BitReader br(decodedNAL); + // Skip `first_mb_in_slice` + br.ReadUE(); + // The value of slice type can go from 0 to 9, but the value between 5 to + // 9 are actually equal to 0 to 4. + const uint32_t sliceType = br.ReadUE() % 5; + if (sliceType == SLICE_TYPES::I_SLICE || sliceType == SI_SLICE) { + return FrameType::I_FRAME; + } } } diff --git a/dom/media/platforms/agnostic/bytestreams/H264.h b/dom/media/platforms/agnostic/bytestreams/H264.h index 6a771ce2dfbe..277714a61b61 100644 --- a/dom/media/platforms/agnostic/bytestreams/H264.h +++ b/dom/media/platforms/agnostic/bytestreams/H264.h @@ -36,6 +36,15 @@ enum NAL_TYPES { H264_NAL_SLICE_EXT_DVC = 21, }; +// According to ITU-T Rec H.264 (2017/04) Table 7.6. +enum SLICE_TYPES { + P_SLICE = 0, + B_SLICE = 1, + I_SLICE = 2, + SP_SLICE = 3, + SI_SLICE = 4, +}; + struct SPSData { bool operator==(const SPSData& aOther) const; bool operator!=(const SPSData& aOther) const;