[PATCH 01/14] media: h264: Add a more generic reflist builder init

Nicolas Dufresne nicolas.dufresne at collabora.com
Tue Nov 17 13:06:05 PST 2026


Hi,

Le vendredi 22 mai 2026 à 12:16 +0200, Paul Kocialkowski a écrit :
> This should become part of a larger reflist builder rework.

Maybe a tiny bit more meet would help? What am I reviewing, what is this new
builder used for?
> 
> Signed-off-by: Paul Kocialkowski <paulk at sys-base.io>
> ---
>  drivers/media/v4l2-core/v4l2-h264.c | 69 +++++++++++++++++++++++++++++
>  include/media/v4l2-h264.h           |  7 +++
>  2 files changed, 76 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-h264.c b/drivers/media/v4l2-core/v4l2-h264.c
> index c00197d095e7..4e5a177ca2c7 100644
> --- a/drivers/media/v4l2-core/v4l2-h264.c
> +++ b/drivers/media/v4l2-core/v4l2-h264.c
> @@ -105,6 +105,75 @@ v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,
>  }
>  EXPORT_SYMBOL_GPL(v4l2_h264_init_reflist_builder);
>  
> +void
> +v4l2_h264_init_reflist_builder_gen(struct v4l2_h264_reflist_builder *b,
> +		const struct v4l2_ctrl_h264_sps *sps,
> +		const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES],
> +		unsigned int pic_order_count, unsigned int frame_num, unsigned int fields)

Add a doc comment.

> +{
> +	int cur_frame_num, max_frame_num;
> +	unsigned int i;
> +
> +	max_frame_num = 1 << (sps->log2_max_frame_num_minus4 + 4);
> +	cur_frame_num = frame_num;
> +
> +	memset(b, 0, sizeof(*b));
> +	b->cur_pic_order_count = pic_order_count;
> +	b->cur_pic_fields = fields;
> +
> +	for (i = 0; i < V4L2_H264_NUM_DPB_ENTRIES; i++) {
> +		if (!(dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE))
> +			continue;
> +
> +		if (dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM)
> +			b->refs[i].longterm = true;
> +
> +		/*
> +		 * Handle frame_num wraparound as described in section
> +		 * '8.2.4.1 Decoding process for picture numbers' of the spec.
> +		 * For long term references, frame_num is set to
> +		 * long_term_frame_idx which requires no wrapping.
> +		 */
> +		if (!b->refs[i].longterm && dpb[i].frame_num > cur_frame_num)
> +			b->refs[i].frame_num = (int)dpb[i].frame_num -
> +					       max_frame_num;
> +		else
> +			b->refs[i].frame_num = dpb[i].frame_num;
> +
> +		b->refs[i].top_field_order_cnt = dpb[i].top_field_order_cnt;
> +		b->refs[i].bottom_field_order_cnt = dpb[i].bottom_field_order_cnt;
> +
> +		if (b->cur_pic_fields == V4L2_H264_FRAME_REF) {
> +			u8 fields = V4L2_H264_FRAME_REF;
> +
> +			b->unordered_reflist[b->num_valid].index = i;
> +			b->unordered_reflist[b->num_valid].fields = fields;
> +			b->num_valid++;
> +			continue;
> +		}
> +
> +		if (dpb[i].fields & V4L2_H264_TOP_FIELD_REF) {
> +			u8 fields = V4L2_H264_TOP_FIELD_REF;
> +
> +			b->unordered_reflist[b->num_valid].index = i;
> +			b->unordered_reflist[b->num_valid].fields = fields;
> +			b->num_valid++;
> +		}
> +
> +		if (dpb[i].fields & V4L2_H264_BOTTOM_FIELD_REF) {
> +			u8 fields = V4L2_H264_BOTTOM_FIELD_REF;
> +
> +			b->unordered_reflist[b->num_valid].index = i;
> +			b->unordered_reflist[b->num_valid].fields = fields;
> +			b->num_valid++;
> +		}
> +	}
> +
> +	for (i = b->num_valid; i < ARRAY_SIZE(b->unordered_reflist); i++)
> +		b->unordered_reflist[i].index = i;
> +}
> +EXPORT_SYMBOL_GPL(v4l2_h264_init_reflist_builder_gen);
> +
>  static s32 v4l2_h264_get_poc(const struct v4l2_h264_reflist_builder *b,
>  			     const struct v4l2_h264_reference *ref)
>  {
> diff --git a/include/media/v4l2-h264.h b/include/media/v4l2-h264.h
> index 0d9eaa956123..1833c0556963 100644
> --- a/include/media/v4l2-h264.h
> +++ b/include/media/v4l2-h264.h
> @@ -42,6 +42,7 @@ struct v4l2_h264_reflist_builder {
>  	u8 cur_pic_fields;
>  
>  	struct v4l2_h264_reference unordered_reflist[V4L2_H264_REF_LIST_LEN];
> +	/* FIXME: confusing with valid flag (active is checked). Proper terminology is "used" */

Just drop a patch before that rename it?

>  	u8 num_valid;

>  };
>  
> @@ -51,6 +52,12 @@ v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,
>  		const struct v4l2_ctrl_h264_sps *sps,
>  		const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES]);
>  
> +void
> +v4l2_h264_init_reflist_builder_gen(struct v4l2_h264_reflist_builder *b,
> +		const struct v4l2_ctrl_h264_sps *sps,
> +		const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES],
> +		unsigned int pic_order_count, unsigned int frame_num, unsigned int fields);
> +
>  /**
>   * v4l2_h264_build_b_ref_lists() - Build the B0/B1 reference lists
>   *
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20261117/bdf93ce3/attachment-0001.sig>


More information about the linux-arm-kernel mailing list