xref: /openbmc/linux/include/media/v4l2-h264.h (revision f12b81e47f48940a6ec82ff308a7d97cd2307442)
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  *
18624922a2SBoris Brezillon  * @refs.pic_order_count: reference picture order count
19624922a2SBoris Brezillon  * @refs.frame_num: reference frame number
20624922a2SBoris Brezillon  * @refs.pic_num: reference picture number
21624922a2SBoris Brezillon  * @refs.longterm: set to true for a long term reference
22624922a2SBoris Brezillon  * @refs: array of references
23624922a2SBoris Brezillon  * @cur_pic_order_count: picture order count of the frame being decoded
24624922a2SBoris Brezillon  * @unordered_reflist: unordered list of references. Will be used to generate
25624922a2SBoris Brezillon  *		       ordered P/B0/B1 lists
26624922a2SBoris Brezillon  * @num_valid: number of valid references in the refs array
27624922a2SBoris Brezillon  *
28624922a2SBoris Brezillon  * This object stores the context of the P/B0/B1 reference list builder.
29624922a2SBoris Brezillon  * This procedure is described in section '8.2.4 Decoding process for reference
30624922a2SBoris Brezillon  * picture lists construction' of the H264 spec.
31624922a2SBoris Brezillon  */
32624922a2SBoris Brezillon struct v4l2_h264_reflist_builder {
33624922a2SBoris Brezillon 	struct {
34624922a2SBoris Brezillon 		s32 pic_order_count;
35624922a2SBoris Brezillon 		int frame_num;
36f9879eb3SEzequiel Garcia 		u32 pic_num;
37624922a2SBoris Brezillon 		u16 longterm : 1;
38624922a2SBoris Brezillon 	} refs[V4L2_H264_NUM_DPB_ENTRIES];
39624922a2SBoris Brezillon 	s32 cur_pic_order_count;
40624922a2SBoris Brezillon 	u8 unordered_reflist[V4L2_H264_NUM_DPB_ENTRIES];
41624922a2SBoris Brezillon 	u8 num_valid;
42624922a2SBoris Brezillon };
43624922a2SBoris Brezillon 
44624922a2SBoris Brezillon void
45624922a2SBoris Brezillon v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,
46624922a2SBoris Brezillon 		const struct v4l2_ctrl_h264_decode_params *dec_params,
47624922a2SBoris Brezillon 		const struct v4l2_ctrl_h264_sps *sps,
48624922a2SBoris Brezillon 		const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES]);
49624922a2SBoris Brezillon 
50624922a2SBoris Brezillon /**
51624922a2SBoris Brezillon  * v4l2_h264_build_b_ref_lists() - Build the B0/B1 reference lists
52624922a2SBoris Brezillon  *
53624922a2SBoris Brezillon  * @builder: reference list builder context
54624922a2SBoris Brezillon  * @b0_reflist: 16-bytes array used to store the B0 reference list. Each entry
55624922a2SBoris Brezillon  *		is an index in the DPB
56624922a2SBoris Brezillon  * @b1_reflist: 16-bytes array used to store the B1 reference list. Each entry
57624922a2SBoris Brezillon  *		is an index in the DPB
58624922a2SBoris Brezillon  *
59624922a2SBoris Brezillon  * This functions builds the B0/B1 reference lists. This procedure is described
60624922a2SBoris Brezillon  * in section '8.2.4 Decoding process for reference picture lists construction'
61624922a2SBoris Brezillon  * of the H264 spec. This function can be used by H264 decoder drivers that
62624922a2SBoris Brezillon  * need to pass B0/B1 reference lists to the hardware.
63624922a2SBoris Brezillon  */
64624922a2SBoris Brezillon void
65624922a2SBoris Brezillon v4l2_h264_build_b_ref_lists(const struct v4l2_h264_reflist_builder *builder,
66624922a2SBoris Brezillon 			    u8 *b0_reflist, u8 *b1_reflist);
67624922a2SBoris Brezillon 
68624922a2SBoris Brezillon /**
69*f12b81e4SHans Verkuil  * v4l2_h264_build_p_ref_list() - Build the P reference list
70624922a2SBoris Brezillon  *
71624922a2SBoris Brezillon  * @builder: reference list builder context
72*f12b81e4SHans Verkuil  * @reflist: 16-bytes array used to store the P reference list. Each entry
73624922a2SBoris Brezillon  *	     is an index in the DPB
74624922a2SBoris Brezillon  *
75624922a2SBoris Brezillon  * This functions builds the P reference lists. This procedure is describe in
76624922a2SBoris Brezillon  * section '8.2.4 Decoding process for reference picture lists construction'
77624922a2SBoris Brezillon  * of the H264 spec. This function can be used by H264 decoder drivers that
78624922a2SBoris Brezillon  * need to pass a P reference list to the hardware.
79624922a2SBoris Brezillon  */
80624922a2SBoris Brezillon void
81624922a2SBoris Brezillon v4l2_h264_build_p_ref_list(const struct v4l2_h264_reflist_builder *builder,
82624922a2SBoris Brezillon 			   u8 *reflist);
83624922a2SBoris Brezillon 
84624922a2SBoris Brezillon #endif /* _MEDIA_V4L2_H264_H */
85