v4l2codecs: Deduplicate picture frame number to timestamp in ns

Add macro which converts picture frame number to suitable timestamp in
nanoseconds for use in V4L2 VB2 buffer lookup. Since multiple codecs do
the same operation and almost all got it wrong, do it in one place so it
can be fixed in one place again, if needed.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5791>
This commit is contained in:
Marek Vasut 2023-12-10 14:22:00 +01:00 committed by GStreamer Marge Bot
parent 552a171671
commit 3335af0efe
7 changed files with 22 additions and 14 deletions

View file

@ -547,7 +547,7 @@ gst_v4l2_codec_av1_fill_refs (GstV4l2CodecAV1Dec * self,
/* the decoder might not have filled all slots in the first few frames */
self->v4l2_frame.reference_frame_ts[i] =
ref_pic ? GST_CODEC_PICTURE_FRAME_NUMBER (ref_pic) * G_GUINT64_CONSTANT (1000) : 0;
ref_pic ? GST_CODEC_PICTURE_TS_NS (ref_pic) : 0;
}
memcpy (self->v4l2_frame.ref_frame_idx, frame_hdr->ref_frame_idx,

View file

@ -628,7 +628,7 @@ gst_v4l2_codec_h264_dec_fill_decoder_params (GstV4l2CodecH264Dec * self,
* The reference is multiplied by 1000 because it's was set as micro
* seconds and this TS is nanosecond.
*/
.reference_ts = GST_CODEC_PICTURE_FRAME_NUMBER (ref_pic) * G_GUINT64_CONSTANT (1000),
.reference_ts = GST_CODEC_PICTURE_TS_NS (ref_pic),
.frame_num = frame_num,
.pic_num = pic_num,
.flags = V4L2_H264_DPB_ENTRY_FLAG_VALID

View file

@ -814,7 +814,7 @@ lookup_dpb_index (struct v4l2_hevc_dpb_entry dpb[16], GstH265Picture * ref_pic)
if (!ref_pic)
return 0xff;
ref_ts = GST_CODEC_PICTURE_FRAME_NUMBER (ref_pic) * G_GUINT64_CONSTANT (1000);
ref_ts = GST_CODEC_PICTURE_TS_NS (ref_pic);
for (i = 0; i < 16; i++) {
if (dpb[i].timestamp == ref_ts)
return i;

View file

@ -578,9 +578,9 @@ gst_v4l2_codec_mpeg2_dec_start_picture (GstMpeg2Decoder * decoder,
/* *INDENT-OFF* */
self->v4l2_picture = (struct v4l2_ctrl_mpeg2_picture) {
.backward_ref_ts = next_picture ?
GST_CODEC_PICTURE_FRAME_NUMBER (next_picture) * G_GUINT64_CONSTANT (1000) : GST_CLOCK_TIME_NONE,
GST_CODEC_PICTURE_TS_NS (next_picture) : GST_CLOCK_TIME_NONE,
.forward_ref_ts = prev_picture ?
GST_CODEC_PICTURE_FRAME_NUMBER (prev_picture) * G_GUINT64_CONSTANT (1000) : GST_CLOCK_TIME_NONE,
GST_CODEC_PICTURE_TS_NS (prev_picture) : GST_CLOCK_TIME_NONE,
.intra_dc_precision = slice->pic_ext ? slice->pic_ext->intra_dc_precision : 0,
.flags = (slice->pic_ext && slice->pic_ext->top_field_first ? V4L2_MPEG2_PIC_FLAG_TOP_FIELD_FIRST : 0) |
(slice->pic_ext && slice->pic_ext->frame_pred_frame_dct ? V4L2_MPEG2_PIC_FLAG_FRAME_PRED_DCT : 0 ) |

View file

@ -446,17 +446,17 @@ gst_v4l2_codec_vp8_dec_fill_references (GstV4l2CodecVp8Dec * self)
if (decoder->last_picture) {
self->frame_header.last_frame_ts =
GST_CODEC_PICTURE_FRAME_NUMBER (decoder->last_picture) * G_GUINT64_CONSTANT (1000);
GST_CODEC_PICTURE_TS_NS (decoder->last_picture);
}
if (decoder->golden_ref_picture) {
self->frame_header.golden_frame_ts =
GST_CODEC_PICTURE_FRAME_NUMBER (decoder->golden_ref_picture) * G_GUINT64_CONSTANT (1000);
GST_CODEC_PICTURE_TS_NS (decoder->golden_ref_picture);
}
if (decoder->alt_ref_picture) {
self->frame_header.alt_frame_ts =
GST_CODEC_PICTURE_FRAME_NUMBER (decoder->alt_ref_picture) * G_GUINT64_CONSTANT (1000);
GST_CODEC_PICTURE_TS_NS (decoder->alt_ref_picture);
}
GST_DEBUG_OBJECT (self, "Passing references: last %u, golden %u, alt %u",

View file

@ -276,20 +276,17 @@ gst_v4l2_codecs_vp9_dec_fill_refs (GstV4l2CodecVp9Dec * self,
if (reference_frames->pic_list[h->ref_frame_idx[0]]) {
ref_pic = reference_frames->pic_list[h->ref_frame_idx[0]];
self->v4l2_vp9_frame.last_frame_ts =
GST_CODEC_PICTURE_FRAME_NUMBER (ref_pic) * G_GUINT64_CONSTANT (1000);
self->v4l2_vp9_frame.last_frame_ts = GST_CODEC_PICTURE_TS_NS (ref_pic);
}
if (reference_frames->pic_list[h->ref_frame_idx[1]]) {
ref_pic = reference_frames->pic_list[h->ref_frame_idx[1]];
self->v4l2_vp9_frame.golden_frame_ts =
GST_CODEC_PICTURE_FRAME_NUMBER (ref_pic) * G_GUINT64_CONSTANT (1000);
self->v4l2_vp9_frame.golden_frame_ts = GST_CODEC_PICTURE_TS_NS (ref_pic);
}
if (reference_frames->pic_list[h->ref_frame_idx[2]]) {
ref_pic = reference_frames->pic_list[h->ref_frame_idx[2]];
self->v4l2_vp9_frame.alt_frame_ts =
GST_CODEC_PICTURE_FRAME_NUMBER (ref_pic) * G_GUINT64_CONSTANT (1000);
self->v4l2_vp9_frame.alt_frame_ts = GST_CODEC_PICTURE_TS_NS (ref_pic);
}
}

View file

@ -26,6 +26,17 @@
#include "gstv4l2codecdevice.h"
#include "linux/videodev2.h"
/**
* GST_CODEC_PICTURE_TS_NS:
* @picture: a #GstCodecPicture
*
* Returns system_frame_number field of @picture converted to nanosecond.
*
* Since: 1.24
*/
#define GST_CODEC_PICTURE_TS_NS(picture) \
(GST_CODEC_PICTURE_FRAME_NUMBER(picture) * G_GUINT64_CONSTANT (1000))
G_BEGIN_DECLS
#define GST_TYPE_V4L2_DECODER gst_v4l2_decoder_get_type ()