From d16ed17747269a1a64d4e6f2fdefb5146302b465 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Mon, 10 Apr 2023 20:10:50 +0900 Subject: [PATCH] h264decoder: Enable low-latency bumping in case of pic_order_cnt_type 2 In case of POC type 2, output order is equal to decoding order (no frame reordering) Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2447 Part-of: --- .../gst-libs/gst/codecs/gsth264decoder.c | 17 +++++++++++------ .../gst-libs/gst/codecs/gsth264picture.c | 6 ++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth264decoder.c b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth264decoder.c index a72d516..86a45aa 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth264decoder.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth264decoder.c @@ -2164,9 +2164,9 @@ gst_h264_decoder_finish_picture (GstH264Decoder * self, gst_h264_picture_unref (picture); - /* For the live mode, we try to bump here to avoid waiting - for another decoding circle. */ - if (priv->is_live && priv->compliance != GST_H264_DECODER_COMPLIANCE_STRICT) + /* For low-latency output, we try to bump here to avoid waiting + * for another decoding circle. */ + if (bump_level != GST_H264_DPB_BUMP_NORMAL_LATENCY) _bump_dpb (self, bump_level, NULL, ret); } @@ -2320,9 +2320,14 @@ gst_h264_decoder_set_latency (GstH264Decoder * self, const GstH264SPS * sps, bump_level = get_bump_level (self); if (bump_level != GST_H264_DPB_BUMP_NORMAL_LATENCY) { - guint32 max_reorder_frames = - gst_h264_dpb_get_max_num_reorder_frames (priv->dpb); - frames_delay = MIN (max_dpb_size, max_reorder_frames); + if (sps->pic_order_cnt_type == 2) { + /* POC type 2 has does not allow frame reordering */ + frames_delay = 0; + } else { + guint32 max_reorder_frames = + gst_h264_dpb_get_max_num_reorder_frames (priv->dpb); + frames_delay = MIN (max_dpb_size, max_reorder_frames); + } } /* Consider output delay wanted by subclass */ diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth264picture.c b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth264picture.c index 02f328b..7ab5ffe 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth264picture.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth264picture.c @@ -760,6 +760,12 @@ gst_h264_dpb_needs_bump (GstH264Dpb * dpb, GstH264Picture * to_insert, if (!gst_h264_dpb_has_empty_frame_buffer (dpb)) goto normal_bump; + /* In case of POC type 2, decoding order is equal to output order */ + if (picture->pic_order_cnt_type == 2) { + GST_TRACE ("POC type == 2, bumping"); + return TRUE; + } + /* 7.4.1.2.2: The values of picture order count for the coded pictures in consecutive access units in decoding order containing non-reference pictures shall be non-decreasing. Safe. */ -- 2.7.4