video lavd: skip leading AUD NALU for H.264

H264_mf encoder (Windows) produces single byte AUD unit prior to SPS
NALU. Because only first NALU was evaluated to assess whether to pass
the frame further, it took 10 frames (+ additional 10 for probe) before
decoding started before it surrendered the checks.
This commit is contained in:
Martin Pulec
2023-08-11 10:55:25 +02:00
parent 72ab033473
commit d2fedd724c
3 changed files with 18 additions and 9 deletions

View File

@@ -356,6 +356,8 @@ get_nalu_name(int type)
return "H264 SEI";
case NAL_SPS:
return "H264 SPS";
case NAL_AUD:
return "H264 AUD";
case NAL_HEVC_VPS:
return "HEVC VPS";
default:

View File

@@ -54,6 +54,7 @@ enum {
NAL_IDR = 5,
NAL_SEI = 6,
NAL_SPS = 7,
NAL_AUD = 9,
NAL_MAX = 23,
// HEVC
NAL_HEVC_VPS = 32,

View File

@@ -806,16 +806,22 @@ static _Bool check_first_sps_vps(struct state_libavcodec_decompress *s, unsigned
s->sps_vps_found = 1;
return 1;
}
const unsigned char *first_nal = rtpenc_h264_get_next_nal(src, src_len, NULL);
if (!first_nal) {
return 0;
}
int nalu_type = 0;
if (s->desc.color_spec == H264) {
nalu_type = NALU_HDR_GET_TYPE(first_nal[0]);
} else {
nalu_type = first_nal[0] >> 1;
}
const unsigned char *nal = src;
do {
nal =
rtpenc_h264_get_next_nal(nal, src_len - (nal - src), NULL);
if (!nal) {
return 0;
}
if (s->desc.color_spec == H264) {
nalu_type = NALU_HDR_GET_TYPE(nal[0]);
} else {
nalu_type = nal[0] >> 1;
}
debug_msg("Received %s NALU.", get_nalu_name(nalu_type));
} while (nalu_type == NAL_AUD);
switch (nalu_type) {
case NAL_SPS: