From f3d14d33a8bfcd434beaa35e45de272004d4b35b Mon Sep 17 00:00:00 2001 From: He Junyan Date: Mon, 8 Apr 2024 21:38:19 +0800 Subject: [PATCH] vah264enc: Fix intra only stream bug When we set "ref-frames=0" to generate an intra only stream, the current encoder just generates an assert and exit with error. Part-of: --- .../gst-plugins-bad/sys/va/gstvah264enc.c | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c b/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c index 5e7a1c75c2..f50525c788 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvah264enc.c @@ -1155,17 +1155,31 @@ create_poc: self->gop.log2_max_frame_num = _get_log2_max_num (self->gop.idr_period); self->gop.max_frame_num = (1 << self->gop.log2_max_frame_num); self->gop.log2_max_pic_order_cnt = self->gop.log2_max_frame_num + 1; + /* 8.2.1.1 Decoding process for picture order count type 0: + For intra only stream, because all frames are non-ref, poc is + easy to wrap. Need to increase the max poc. */ + if (self->gop.ip_period == 0) + self->gop.log2_max_pic_order_cnt++; self->gop.max_pic_order_cnt = (1 << self->gop.log2_max_pic_order_cnt); - self->gop.num_reorder_frames = self->gop.b_pyramid ? - self->gop.highest_pyramid_level + 1 /* the last P frame. */ : - self->gop.ref_num_list1; - self->gop.num_reorder_frames = MIN (self->gop.num_reorder_frames, 16); - /* Let the DPB contain total refs plus the current frame. */ - self->gop.max_dec_frame_buffering = self->gop.b_pyramid ? - self->gop.highest_pyramid_level + 2 + 1 : self->gop.num_ref_frames + 1; - g_assert (self->gop.max_dec_frame_buffering <= 16); - self->gop.max_num_ref_frames = self->gop.max_dec_frame_buffering - 1; + /* Intra only stream. */ + if (self->gop.ip_period == 0) { + self->gop.num_reorder_frames = 0; + + self->gop.max_dec_frame_buffering = 1 + 1; /* IDR and current frame. */ + self->gop.max_num_ref_frames = 0; + } else { + self->gop.num_reorder_frames = self->gop.b_pyramid ? + self->gop.highest_pyramid_level + 1 /* the last P frame. */ : + self->gop.ref_num_list1; + self->gop.num_reorder_frames = MIN (self->gop.num_reorder_frames, 16); + + /* Let the DPB contain total refs plus the current frame. */ + self->gop.max_dec_frame_buffering = self->gop.b_pyramid ? + self->gop.highest_pyramid_level + 2 + 1 : self->gop.num_ref_frames + 1; + g_assert (self->gop.max_dec_frame_buffering <= 16); + self->gop.max_num_ref_frames = self->gop.max_dec_frame_buffering - 1; + } _create_gop_frame_types (self); _print_gop_structure (self);