xref: /openbmc/linux/include/media/v4l2-h264.h (revision e5991e1fd90295b1eb8326a4a6c09012d6c5fc8d)
1624922a2SBoris Brezillon /* SPDX-License-Identifier: GPL-2.0-or-later */
2624922a2SBoris Brezillon /*
3624922a2SBoris Brezillon  * Helper functions for H264 codecs.
4624922a2SBoris Brezillon  *
5624922a2SBoris Brezillon  * Copyright (c) 2019 Collabora, Ltd.
6624922a2SBoris Brezillon  *
7624922a2SBoris Brezillon  * Author: Boris Brezillon <boris.brezillon@collabora.com>
8624922a2SBoris Brezillon  */
9624922a2SBoris Brezillon 
10624922a2SBoris Brezillon #ifndef _MEDIA_V4L2_H264_H
11624922a2SBoris Brezillon #define _MEDIA_V4L2_H264_H
12624922a2SBoris Brezillon 
138917a5f6SEzequiel Garcia #include <media/v4l2-ctrls.h>
14624922a2SBoris Brezillon 
15624922a2SBoris Brezillon /**
16624922a2SBoris Brezillon  * struct v4l2_h264_reflist_builder - Reference list builder object
17624922a2SBoris Brezillon  *
18*e5991e1fSNicolas Dufresne  * @refs.top_field_order_cnt: top field order count
19*e5991e1fSNicolas Dufresne  * @refs.bottom_field_order_cnt: bottom field order count
20624922a2SBoris Brezillon  * @refs.frame_num: reference frame number
21624922a2SBoris Brezillon  * @refs.pic_num: reference picture number
22624922a2SBoris Brezillon  * @refs.longterm: set to true for a long term reference
23624922a2SBoris Brezillon  * @refs: array of references
24624922a2SBoris Brezillon  * @cur_pic_order_count: picture order count of the frame being decoded
25adc8a8d6SNicolas Dufresne  * @cur_pic_fields: fields present in the frame being decoded
26624922a2SBoris Brezillon  * @unordered_reflist: unordered list of references. Will be used to generate
27624922a2SBoris Brezillon  *		       ordered P/B0/B1 lists
28624922a2SBoris Brezillon  * @num_valid: number of valid references in the refs array
29624922a2SBoris Brezillon  *
30624922a2SBoris Brezillon  * This object stores the context of the P/B0/B1 reference list builder.
31624922a2SBoris Brezillon  * This procedure is described in section '8.2.4 Decoding process for reference
32624922a2SBoris Brezillon  * picture lists construction' of the H264 spec.
33624922a2SBoris Brezillon  */
34624922a2SBoris Brezillon struct v4l2_h264_reflist_builder {
35624922a2SBoris Brezillon 	struct {
36*e5991e1fSNicolas Dufresne 		s32 top_field_order_cnt;
37*e5991e1fSNicolas Dufresne 		s32 bottom_field_order_cnt;
38624922a2SBoris Brezillon 		int frame_num;
39f9879eb3SEzequiel Garcia 		u32 pic_num;
40624922a2SBoris Brezillon 		u16 longterm : 1;
41624922a2SBoris Brezillon 	} refs[V4L2_H264_NUM_DPB_ENTRIES];
42adc8a8d6SNicolas Dufresne 
43624922a2SBoris Brezillon 	s32 cur_pic_order_count;
44adc8a8d6SNicolas Dufresne 	u8 cur_pic_fields;
45adc8a8d6SNicolas Dufresne 
4626e45205SNicolas Dufresne 	struct v4l2_h264_reference unordered_reflist[V4L2_H264_REF_LIST_LEN];
47624922a2SBoris Brezillon 	u8 num_valid;
48624922a2SBoris Brezillon };
49624922a2SBoris Brezillon 
50624922a2SBoris Brezillon void
51624922a2SBoris Brezillon v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,
52624922a2SBoris Brezillon 		const struct v4l2_ctrl_h264_decode_params *dec_params,
53624922a2SBoris Brezillon 		const struct v4l2_ctrl_h264_sps *sps,
54624922a2SBoris Brezillon 		const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES]);
55624922a2SBoris Brezillon 
56624922a2SBoris Brezillon /**
57624922a2SBoris Brezillon  * v4l2_h264_build_b_ref_lists() - Build the B0/B1 reference lists
58624922a2SBoris Brezillon  *
59624922a2SBoris Brezillon  * @builder: reference list builder context
6026e45205SNicolas Dufresne  * @b0_reflist: 32 sized array used to store the B0 reference list. Each entry
612e2c3d6cSNicolas Dufresne  *		is a v4l2_h264_reference structure
6226e45205SNicolas Dufresne  * @b1_reflist: 32 sized array used to store the B1 reference list. Each entry
632e2c3d6cSNicolas Dufresne  *		is a v4l2_h264_reference structure
64624922a2SBoris Brezillon  *
65624922a2SBoris Brezillon  * This functions builds the B0/B1 reference lists. This procedure is described
66624922a2SBoris Brezillon  * in section '8.2.4 Decoding process for reference picture lists construction'
67624922a2SBoris Brezillon  * of the H264 spec. This function can be used by H264 decoder drivers that
68624922a2SBoris Brezillon  * need to pass B0/B1 reference lists to the hardware.
69624922a2SBoris Brezillon  */
70624922a2SBoris Brezillon void
71624922a2SBoris Brezillon v4l2_h264_build_b_ref_lists(const struct v4l2_h264_reflist_builder *builder,
722e2c3d6cSNicolas Dufresne 			    struct v4l2_h264_reference *b0_reflist,
732e2c3d6cSNicolas Dufresne 			    struct v4l2_h264_reference *b1_reflist);
74624922a2SBoris Brezillon 
75624922a2SBoris Brezillon /**
76f12b81e4SHans Verkuil  * v4l2_h264_build_p_ref_list() - Build the P reference list
77624922a2SBoris Brezillon  *
78624922a2SBoris Brezillon  * @builder: reference list builder context
7926e45205SNicolas Dufresne  * @reflist: 32 sized array used to store the P reference list. Each entry
802e2c3d6cSNicolas Dufresne  *	     is a v4l2_h264_reference structure
81624922a2SBoris Brezillon  *
82624922a2SBoris Brezillon  * This functions builds the P reference lists. This procedure is describe in
83624922a2SBoris Brezillon  * section '8.2.4 Decoding process for reference picture lists construction'
84624922a2SBoris Brezillon  * of the H264 spec. This function can be used by H264 decoder drivers that
85624922a2SBoris Brezillon  * need to pass a P reference list to the hardware.
86624922a2SBoris Brezillon  */
87624922a2SBoris Brezillon void
88624922a2SBoris Brezillon v4l2_h264_build_p_ref_list(const struct v4l2_h264_reflist_builder *builder,
892e2c3d6cSNicolas Dufresne 			   struct v4l2_h264_reference *reflist);
90624922a2SBoris Brezillon 
91624922a2SBoris Brezillon #endif /* _MEDIA_V4L2_H264_H */
92