Bug 1539182 - check slice type to decide frame type. r=jya

Sometime we would encouter a file putting all its samples on the type1 NAL, so we have to check its slice type in order to know if it's a keyframe or not.

The slice type is defined in the ITU-T Rec H.264 table 7.3, and it could be found in the slice_header in table 7.3.3.

Differential Revision: https://phabricator.services.mozilla.com/D35572

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alastor Wu 2019-08-30 01:08:09 +00:00
Родитель 4875d42d23
Коммит 4ec8d0a594
2 изменённых файлов: 22 добавлений и 0 удалений

Просмотреть файл

@ -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<mozilla::MediaByteBuffer> 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;
}
}
}

Просмотреть файл

@ -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;