xref: /linux/include/media/v4l2-h264.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
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.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
24adc8a8d6SNicolas Dufresne  * @cur_pic_fields: fields present in the frame being decoded
25624922a2SBoris Brezillon  * @unordered_reflist: unordered list of references. Will be used to generate
26624922a2SBoris Brezillon  *		       ordered P/B0/B1 lists
27624922a2SBoris Brezillon  * @num_valid: number of valid references in the refs array
28624922a2SBoris Brezillon  *
29624922a2SBoris Brezillon  * This object stores the context of the P/B0/B1 reference list builder.
30624922a2SBoris Brezillon  * This procedure is described in section '8.2.4 Decoding process for reference
31624922a2SBoris Brezillon  * picture lists construction' of the H264 spec.
32624922a2SBoris Brezillon  */
33624922a2SBoris Brezillon struct v4l2_h264_reflist_builder {
34624922a2SBoris Brezillon 	struct {
35*e5991e1fSNicolas Dufresne 		s32 top_field_order_cnt;
36*e5991e1fSNicolas Dufresne 		s32 bottom_field_order_cnt;
37624922a2SBoris Brezillon 		int frame_num;
38624922a2SBoris Brezillon 		u16 longterm : 1;
39624922a2SBoris Brezillon 	} refs[V4L2_H264_NUM_DPB_ENTRIES];
40adc8a8d6SNicolas Dufresne 
41624922a2SBoris Brezillon 	s32 cur_pic_order_count;
42adc8a8d6SNicolas Dufresne 	u8 cur_pic_fields;
43adc8a8d6SNicolas Dufresne 
4426e45205SNicolas Dufresne 	struct v4l2_h264_reference unordered_reflist[V4L2_H264_REF_LIST_LEN];
45624922a2SBoris Brezillon 	u8 num_valid;
46624922a2SBoris Brezillon };
47624922a2SBoris Brezillon 
48624922a2SBoris Brezillon void
49624922a2SBoris Brezillon v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,
50624922a2SBoris Brezillon 		const struct v4l2_ctrl_h264_decode_params *dec_params,
51624922a2SBoris Brezillon 		const struct v4l2_ctrl_h264_sps *sps,
52624922a2SBoris Brezillon 		const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES]);
53624922a2SBoris Brezillon 
54624922a2SBoris Brezillon /**
55624922a2SBoris Brezillon  * v4l2_h264_build_b_ref_lists() - Build the B0/B1 reference lists
56624922a2SBoris Brezillon  *
57624922a2SBoris Brezillon  * @builder: reference list builder context
5826e45205SNicolas Dufresne  * @b0_reflist: 32 sized array used to store the B0 reference list. Each entry
592e2c3d6cSNicolas Dufresne  *		is a v4l2_h264_reference structure
6026e45205SNicolas Dufresne  * @b1_reflist: 32 sized array used to store the B1 reference list. Each entry
612e2c3d6cSNicolas Dufresne  *		is a v4l2_h264_reference structure
62624922a2SBoris Brezillon  *
63624922a2SBoris Brezillon  * This functions builds the B0/B1 reference lists. This procedure is described
64624922a2SBoris Brezillon  * in section '8.2.4 Decoding process for reference picture lists construction'
65624922a2SBoris Brezillon  * of the H264 spec. This function can be used by H264 decoder drivers that
66624922a2SBoris Brezillon  * need to pass B0/B1 reference lists to the hardware.
67624922a2SBoris Brezillon  */
68624922a2SBoris Brezillon void
69624922a2SBoris Brezillon v4l2_h264_build_b_ref_lists(const struct v4l2_h264_reflist_builder *builder,
702e2c3d6cSNicolas Dufresne 			    struct v4l2_h264_reference *b0_reflist,
712e2c3d6cSNicolas Dufresne 			    struct v4l2_h264_reference *b1_reflist);
72624922a2SBoris Brezillon 
73624922a2SBoris Brezillon /**
74f12b81e4SHans Verkuil  * v4l2_h264_build_p_ref_list() - Build the P reference list
75624922a2SBoris Brezillon  *
76624922a2SBoris Brezillon  * @builder: reference list builder context
7726e45205SNicolas Dufresne  * @reflist: 32 sized array used to store the P reference list. Each entry
782e2c3d6cSNicolas Dufresne  *	     is a v4l2_h264_reference structure
79624922a2SBoris Brezillon  *
80624922a2SBoris Brezillon  * This functions builds the P reference lists. This procedure is describe in
81624922a2SBoris Brezillon  * section '8.2.4 Decoding process for reference picture lists construction'
82624922a2SBoris Brezillon  * of the H264 spec. This function can be used by H264 decoder drivers that
83624922a2SBoris Brezillon  * need to pass a P reference list to the hardware.
84624922a2SBoris Brezillon  */
85624922a2SBoris Brezillon void
86624922a2SBoris Brezillon v4l2_h264_build_p_ref_list(const struct v4l2_h264_reflist_builder *builder,
872e2c3d6cSNicolas Dufresne 			   struct v4l2_h264_reference *reflist);
88624922a2SBoris Brezillon 
89624922a2SBoris Brezillon #endif /* _MEDIA_V4L2_H264_H */
90