162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Helper functions for H264 codecs.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (c) 2019 Collabora, Ltd.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Author: Boris Brezillon <boris.brezillon@collabora.com>
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifndef _MEDIA_V4L2_H264_H
1162306a36Sopenharmony_ci#define _MEDIA_V4L2_H264_H
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include <media/v4l2-ctrls.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci/**
1662306a36Sopenharmony_ci * struct v4l2_h264_reflist_builder - Reference list builder object
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci * @refs.top_field_order_cnt: top field order count
1962306a36Sopenharmony_ci * @refs.bottom_field_order_cnt: bottom field order count
2062306a36Sopenharmony_ci * @refs.frame_num: reference frame number
2162306a36Sopenharmony_ci * @refs.longterm: set to true for a long term reference
2262306a36Sopenharmony_ci * @refs: array of references
2362306a36Sopenharmony_ci * @cur_pic_order_count: picture order count of the frame being decoded
2462306a36Sopenharmony_ci * @cur_pic_fields: fields present in the frame being decoded
2562306a36Sopenharmony_ci * @unordered_reflist: unordered list of references. Will be used to generate
2662306a36Sopenharmony_ci *		       ordered P/B0/B1 lists
2762306a36Sopenharmony_ci * @num_valid: number of valid references in the refs array
2862306a36Sopenharmony_ci *
2962306a36Sopenharmony_ci * This object stores the context of the P/B0/B1 reference list builder.
3062306a36Sopenharmony_ci * This procedure is described in section '8.2.4 Decoding process for reference
3162306a36Sopenharmony_ci * picture lists construction' of the H264 spec.
3262306a36Sopenharmony_ci */
3362306a36Sopenharmony_cistruct v4l2_h264_reflist_builder {
3462306a36Sopenharmony_ci	struct {
3562306a36Sopenharmony_ci		s32 top_field_order_cnt;
3662306a36Sopenharmony_ci		s32 bottom_field_order_cnt;
3762306a36Sopenharmony_ci		int frame_num;
3862306a36Sopenharmony_ci		u16 longterm : 1;
3962306a36Sopenharmony_ci	} refs[V4L2_H264_NUM_DPB_ENTRIES];
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci	s32 cur_pic_order_count;
4262306a36Sopenharmony_ci	u8 cur_pic_fields;
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci	struct v4l2_h264_reference unordered_reflist[V4L2_H264_REF_LIST_LEN];
4562306a36Sopenharmony_ci	u8 num_valid;
4662306a36Sopenharmony_ci};
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_civoid
4962306a36Sopenharmony_civ4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,
5062306a36Sopenharmony_ci		const struct v4l2_ctrl_h264_decode_params *dec_params,
5162306a36Sopenharmony_ci		const struct v4l2_ctrl_h264_sps *sps,
5262306a36Sopenharmony_ci		const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES]);
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci/**
5562306a36Sopenharmony_ci * v4l2_h264_build_b_ref_lists() - Build the B0/B1 reference lists
5662306a36Sopenharmony_ci *
5762306a36Sopenharmony_ci * @builder: reference list builder context
5862306a36Sopenharmony_ci * @b0_reflist: 32 sized array used to store the B0 reference list. Each entry
5962306a36Sopenharmony_ci *		is a v4l2_h264_reference structure
6062306a36Sopenharmony_ci * @b1_reflist: 32 sized array used to store the B1 reference list. Each entry
6162306a36Sopenharmony_ci *		is a v4l2_h264_reference structure
6262306a36Sopenharmony_ci *
6362306a36Sopenharmony_ci * This functions builds the B0/B1 reference lists. This procedure is described
6462306a36Sopenharmony_ci * in section '8.2.4 Decoding process for reference picture lists construction'
6562306a36Sopenharmony_ci * of the H264 spec. This function can be used by H264 decoder drivers that
6662306a36Sopenharmony_ci * need to pass B0/B1 reference lists to the hardware.
6762306a36Sopenharmony_ci */
6862306a36Sopenharmony_civoid
6962306a36Sopenharmony_civ4l2_h264_build_b_ref_lists(const struct v4l2_h264_reflist_builder *builder,
7062306a36Sopenharmony_ci			    struct v4l2_h264_reference *b0_reflist,
7162306a36Sopenharmony_ci			    struct v4l2_h264_reference *b1_reflist);
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci/**
7462306a36Sopenharmony_ci * v4l2_h264_build_p_ref_list() - Build the P reference list
7562306a36Sopenharmony_ci *
7662306a36Sopenharmony_ci * @builder: reference list builder context
7762306a36Sopenharmony_ci * @reflist: 32 sized array used to store the P reference list. Each entry
7862306a36Sopenharmony_ci *	     is a v4l2_h264_reference structure
7962306a36Sopenharmony_ci *
8062306a36Sopenharmony_ci * This functions builds the P reference lists. This procedure is describe in
8162306a36Sopenharmony_ci * section '8.2.4 Decoding process for reference picture lists construction'
8262306a36Sopenharmony_ci * of the H264 spec. This function can be used by H264 decoder drivers that
8362306a36Sopenharmony_ci * need to pass a P reference list to the hardware.
8462306a36Sopenharmony_ci */
8562306a36Sopenharmony_civoid
8662306a36Sopenharmony_civ4l2_h264_build_p_ref_list(const struct v4l2_h264_reflist_builder *builder,
8762306a36Sopenharmony_ci			   struct v4l2_h264_reference *reflist);
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci#endif /* _MEDIA_V4L2_H264_H */
90