v4l2codecs: h264: Properly set pic_num/frame_num
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Wed, 24 Nov 2021 16:17:40 +0000 (11:17 -0500)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 30 Nov 2021 00:28:34 +0000 (00:28 +0000)
The V4L2 uAPI uses pic_num for both PicNum and ShortTermPicNum. It also
doe the same for both FrameNum and LongTermFrameIdx. This change does
not change the fluster score, but fixed a visual corruption noticed
with some third party streams.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1387>

subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2codech264dec.c

index 7b4a5c1..bfbfc99 100644 (file)
@@ -582,6 +582,7 @@ gst_v4l2_codec_h264_dec_fill_decoder_params (GstV4l2CodecH264Dec * self,
   for (i = 0; i < refs->len; i++) {
     GstH264Picture *ref_pic = g_array_index (refs, GstH264Picture *, i);
     gint pic_num = ref_pic->pic_num;
+    gint frame_num = ref_pic->frame_num;
     struct v4l2_h264_dpb_entry *entry;
 
     /* Skip non-reference as they are not useful to decoding */
@@ -592,6 +593,13 @@ gst_v4l2_codec_h264_dec_fill_decoder_params (GstV4l2CodecH264Dec * self,
     if (ref_pic->second_field)
       continue;
 
+    /* V4L2 uAPI uses pic_num for both PicNum and LongTermPicNum, and
+     * frame_num for both FrameNum and LongTermFrameIdx */
+    if (GST_H264_PICTURE_IS_LONG_TERM_REF (ref_pic)) {
+      pic_num = ref_pic->long_term_pic_num;
+      frame_num = ref_pic->long_term_frame_idx;
+    }
+
     entry = &self->decode_params.dpb[entry_id++];
     *entry = (struct v4l2_h264_dpb_entry) {
       /*
@@ -599,7 +607,7 @@ gst_v4l2_codec_h264_dec_fill_decoder_params (GstV4l2CodecH264Dec * self,
        * seconds and this TS is nanosecond.
        */
       .reference_ts = (guint64) ref_pic->system_frame_number * 1000,
-      .frame_num = ref_pic->frame_num,
+      .frame_num = frame_num,
       .pic_num = pic_num,
       .flags = V4L2_H264_DPB_ENTRY_FLAG_VALID
           | (GST_H264_PICTURE_IS_REF (ref_pic) ? V4L2_H264_DPB_ENTRY_FLAG_ACTIVE : 0)