xref: /openbmc/linux/include/media/v4l2-h264.h (revision 2e2c3d6c0ef88ffac0d6b5079ee88cf8408f5f3b)
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;
40*2e2c3d6cSNicolas Dufresne 	struct v4l2_h264_reference 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
54*2e2c3d6cSNicolas Dufresne  * @b0_reflist: 16 sized array used to store the B0 reference list. Each entry
55*2e2c3d6cSNicolas Dufresne  *		is a v4l2_h264_reference structure
56*2e2c3d6cSNicolas Dufresne  * @b1_reflist: 16 sized array used to store the B1 reference list. Each entry
57*2e2c3d6cSNicolas Dufresne  *		is a v4l2_h264_reference structure
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,
66*2e2c3d6cSNicolas Dufresne 			    struct v4l2_h264_reference *b0_reflist,
67*2e2c3d6cSNicolas Dufresne 			    struct v4l2_h264_reference *b1_reflist);
68624922a2SBoris Brezillon 
69624922a2SBoris Brezillon /**
70f12b81e4SHans Verkuil  * v4l2_h264_build_p_ref_list() - Build the P reference list
71624922a2SBoris Brezillon  *
72624922a2SBoris Brezillon  * @builder: reference list builder context
73*2e2c3d6cSNicolas Dufresne  * @reflist: 16 sized array used to store the P reference list. Each entry
74*2e2c3d6cSNicolas Dufresne  *	     is a v4l2_h264_reference structure
75624922a2SBoris Brezillon  *
76624922a2SBoris Brezillon  * This functions builds the P reference lists. This procedure is describe in
77624922a2SBoris Brezillon  * section '8.2.4 Decoding process for reference picture lists construction'
78624922a2SBoris Brezillon  * of the H264 spec. This function can be used by H264 decoder drivers that
79624922a2SBoris Brezillon  * need to pass a P reference list to the hardware.
80624922a2SBoris Brezillon  */
81624922a2SBoris Brezillon void
82624922a2SBoris Brezillon v4l2_h264_build_p_ref_list(const struct v4l2_h264_reflist_builder *builder,
83*2e2c3d6cSNicolas Dufresne 			   struct v4l2_h264_reference *reflist);
84624922a2SBoris Brezillon 
85624922a2SBoris Brezillon #endif /* _MEDIA_V4L2_H264_H */
86