From b2098849dc21c3615cb15b1e26bbbe77feb76476 Mon Sep 17 00:00:00 2001 From: Daniel Morin Date: Sun, 11 Feb 2024 22:08:12 -0500 Subject: [PATCH] h264parse: correct NAL mode backlog processing - Only process what is left in backlog when AU was completed, draining or next nal is AUD. Part-of: --- .../gst/videoparsers/gsth264parse.c | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst/videoparsers/gsth264parse.c b/subprojects/gst-plugins-bad/gst/videoparsers/gsth264parse.c index e348fa471f..ccddd963aa 100644 --- a/subprojects/gst-plugins-bad/gst/videoparsers/gsth264parse.c +++ b/subprojects/gst-plugins-bad/gst/videoparsers/gsth264parse.c @@ -1699,11 +1699,11 @@ gst_h264_parse_process_backlog_loop (GstH264Parse * h264parse, static gboolean gst_h264_parse_process_backlog_nal (GstH264Parse * h264parse, gint * proc_size, - gboolean * aud_insert, guint8 * data, gboolean clear_bl, - gboolean au_completed) + gboolean * aud_insert, guint8 * data, gboolean drain, gboolean au_completed) { GstH264NalUnit *bnalu; gint framesize = 0; + gboolean next_is_aud = FALSE; g_assert (h264parse->nal_backlog != NULL); g_assert (h264parse->nal_backlog->len > 0); @@ -1733,14 +1733,19 @@ gst_h264_parse_process_backlog_nal (GstH264Parse * h264parse, gint * proc_size, gst_h264_parse_trim_backlog (h264parse); } - /* Process all backlog. Used when draining or output in NAL mode. */ - if (!gst_h264_parse_process_backlog_loop (h264parse, - h264parse->nal_backlog->len, TRUE, aud_insert, data, &framesize)) { - goto fail; + if (h264parse->bl_next_nal < h264parse->nal_backlog->len) { + bnalu = &g_array_index (h264parse->nal_backlog, GstH264NalUnit, + h264parse->bl_next_nal); + next_is_aud = bnalu->type == GST_H264_NAL_AU_DELIMITER; } - if (clear_bl) { - gst_h264_parse_clear_backlog (h264parse); + /* Process all backlog. Used when draining or in NAL mode and nals still + * in backlog after completing or next is AUD. */ + if ((au_completed || drain || next_is_aud)) { + if (!gst_h264_parse_process_backlog_loop (h264parse, + h264parse->nal_backlog->len, TRUE, aud_insert, data, &framesize)) { + goto fail; + } } /* Backlog content doesn't need to parsed again, adjust offset accordingly. */ @@ -2027,7 +2032,7 @@ gst_h264_parse_handle_frame (GstBaseParse * parse, if (h264parse->align == GST_H264_PARSE_ALIGN_NAL) { if (!gst_h264_parse_process_backlog_nal (h264parse, &framesize, - &h264parse->aud_insert, data, FALSE, + &h264parse->aud_insert, data, drain, blstatus == GST_H264_PARSE_BACKLOG_STATUS_AU_COMPLETE)) { *skipsize = current_off; }