media: uapi: HEVC: Add SEI pic struct flags
[platform/kernel/linux-starfive.git] / include / media / hevc-ctrls.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * These are the HEVC state controls for use with stateless HEVC
4  * codec drivers.
5  *
6  * It turns out that these structs are not stable yet and will undergo
7  * more changes. So keep them private until they are stable and ready to
8  * become part of the official public API.
9  */
10
11 #ifndef _HEVC_CTRLS_H_
12 #define _HEVC_CTRLS_H_
13
14 #include <linux/videodev2.h>
15
16 /* The pixel format isn't stable at the moment and will likely be renamed. */
17 #define V4L2_PIX_FMT_HEVC_SLICE v4l2_fourcc('S', '2', '6', '5') /* HEVC parsed slices */
18
19 #define V4L2_CID_STATELESS_HEVC_SPS             (V4L2_CID_CODEC_BASE + 1008)
20 #define V4L2_CID_STATELESS_HEVC_PPS             (V4L2_CID_CODEC_BASE + 1009)
21 #define V4L2_CID_STATELESS_HEVC_SLICE_PARAMS    (V4L2_CID_CODEC_BASE + 1010)
22 #define V4L2_CID_STATELESS_HEVC_SCALING_MATRIX  (V4L2_CID_CODEC_BASE + 1011)
23 #define V4L2_CID_STATELESS_HEVC_DECODE_PARAMS   (V4L2_CID_CODEC_BASE + 1012)
24 #define V4L2_CID_STATELESS_HEVC_DECODE_MODE     (V4L2_CID_CODEC_BASE + 1015)
25 #define V4L2_CID_STATELESS_HEVC_START_CODE      (V4L2_CID_CODEC_BASE + 1016)
26
27 /* enum v4l2_ctrl_type type values */
28 #define V4L2_CTRL_TYPE_HEVC_SPS 0x0120
29 #define V4L2_CTRL_TYPE_HEVC_PPS 0x0121
30 #define V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS 0x0122
31 #define V4L2_CTRL_TYPE_HEVC_SCALING_MATRIX 0x0123
32 #define V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS 0x0124
33
34 enum v4l2_stateless_hevc_decode_mode {
35         V4L2_STATELESS_HEVC_DECODE_MODE_SLICE_BASED,
36         V4L2_STATELESS_HEVC_DECODE_MODE_FRAME_BASED,
37 };
38
39 enum v4l2_stateless_hevc_start_code {
40         V4L2_STATELESS_HEVC_START_CODE_NONE,
41         V4L2_STATELESS_HEVC_START_CODE_ANNEX_B,
42 };
43
44 #define V4L2_HEVC_SLICE_TYPE_B  0
45 #define V4L2_HEVC_SLICE_TYPE_P  1
46 #define V4L2_HEVC_SLICE_TYPE_I  2
47
48 #define V4L2_HEVC_SPS_FLAG_SEPARATE_COLOUR_PLANE                (1ULL << 0)
49 #define V4L2_HEVC_SPS_FLAG_SCALING_LIST_ENABLED                 (1ULL << 1)
50 #define V4L2_HEVC_SPS_FLAG_AMP_ENABLED                          (1ULL << 2)
51 #define V4L2_HEVC_SPS_FLAG_SAMPLE_ADAPTIVE_OFFSET               (1ULL << 3)
52 #define V4L2_HEVC_SPS_FLAG_PCM_ENABLED                          (1ULL << 4)
53 #define V4L2_HEVC_SPS_FLAG_PCM_LOOP_FILTER_DISABLED             (1ULL << 5)
54 #define V4L2_HEVC_SPS_FLAG_LONG_TERM_REF_PICS_PRESENT           (1ULL << 6)
55 #define V4L2_HEVC_SPS_FLAG_SPS_TEMPORAL_MVP_ENABLED             (1ULL << 7)
56 #define V4L2_HEVC_SPS_FLAG_STRONG_INTRA_SMOOTHING_ENABLED       (1ULL << 8)
57
58 /* The controls are not stable at the moment and will likely be reworked. */
59 struct v4l2_ctrl_hevc_sps {
60         /* ISO/IEC 23008-2, ITU-T Rec. H.265: Sequence parameter set */
61         __u8    video_parameter_set_id;
62         __u8    seq_parameter_set_id;
63         __u16   pic_width_in_luma_samples;
64         __u16   pic_height_in_luma_samples;
65         __u8    bit_depth_luma_minus8;
66         __u8    bit_depth_chroma_minus8;
67         __u8    log2_max_pic_order_cnt_lsb_minus4;
68         __u8    sps_max_dec_pic_buffering_minus1;
69         __u8    sps_max_num_reorder_pics;
70         __u8    sps_max_latency_increase_plus1;
71         __u8    log2_min_luma_coding_block_size_minus3;
72         __u8    log2_diff_max_min_luma_coding_block_size;
73         __u8    log2_min_luma_transform_block_size_minus2;
74         __u8    log2_diff_max_min_luma_transform_block_size;
75         __u8    max_transform_hierarchy_depth_inter;
76         __u8    max_transform_hierarchy_depth_intra;
77         __u8    pcm_sample_bit_depth_luma_minus1;
78         __u8    pcm_sample_bit_depth_chroma_minus1;
79         __u8    log2_min_pcm_luma_coding_block_size_minus3;
80         __u8    log2_diff_max_min_pcm_luma_coding_block_size;
81         __u8    num_short_term_ref_pic_sets;
82         __u8    num_long_term_ref_pics_sps;
83         __u8    chroma_format_idc;
84         __u8    sps_max_sub_layers_minus1;
85
86         __u64   flags;
87 };
88
89 #define V4L2_HEVC_PPS_FLAG_DEPENDENT_SLICE_SEGMENT_ENABLED      (1ULL << 0)
90 #define V4L2_HEVC_PPS_FLAG_OUTPUT_FLAG_PRESENT                  (1ULL << 1)
91 #define V4L2_HEVC_PPS_FLAG_SIGN_DATA_HIDING_ENABLED             (1ULL << 2)
92 #define V4L2_HEVC_PPS_FLAG_CABAC_INIT_PRESENT                   (1ULL << 3)
93 #define V4L2_HEVC_PPS_FLAG_CONSTRAINED_INTRA_PRED               (1ULL << 4)
94 #define V4L2_HEVC_PPS_FLAG_TRANSFORM_SKIP_ENABLED               (1ULL << 5)
95 #define V4L2_HEVC_PPS_FLAG_CU_QP_DELTA_ENABLED                  (1ULL << 6)
96 #define V4L2_HEVC_PPS_FLAG_PPS_SLICE_CHROMA_QP_OFFSETS_PRESENT  (1ULL << 7)
97 #define V4L2_HEVC_PPS_FLAG_WEIGHTED_PRED                        (1ULL << 8)
98 #define V4L2_HEVC_PPS_FLAG_WEIGHTED_BIPRED                      (1ULL << 9)
99 #define V4L2_HEVC_PPS_FLAG_TRANSQUANT_BYPASS_ENABLED            (1ULL << 10)
100 #define V4L2_HEVC_PPS_FLAG_TILES_ENABLED                        (1ULL << 11)
101 #define V4L2_HEVC_PPS_FLAG_ENTROPY_CODING_SYNC_ENABLED          (1ULL << 12)
102 #define V4L2_HEVC_PPS_FLAG_LOOP_FILTER_ACROSS_TILES_ENABLED     (1ULL << 13)
103 #define V4L2_HEVC_PPS_FLAG_PPS_LOOP_FILTER_ACROSS_SLICES_ENABLED (1ULL << 14)
104 #define V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_OVERRIDE_ENABLED   (1ULL << 15)
105 #define V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER        (1ULL << 16)
106 #define V4L2_HEVC_PPS_FLAG_LISTS_MODIFICATION_PRESENT           (1ULL << 17)
107 #define V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT (1ULL << 18)
108 #define V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT    (1ULL << 19)
109 #define V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING                      (1ULL << 20)
110
111 struct v4l2_ctrl_hevc_pps {
112         /* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */
113         __u8    pic_parameter_set_id;
114         __u8    num_extra_slice_header_bits;
115         __u8    num_ref_idx_l0_default_active_minus1;
116         __u8    num_ref_idx_l1_default_active_minus1;
117         __s8    init_qp_minus26;
118         __u8    diff_cu_qp_delta_depth;
119         __s8    pps_cb_qp_offset;
120         __s8    pps_cr_qp_offset;
121         __u8    num_tile_columns_minus1;
122         __u8    num_tile_rows_minus1;
123         __u8    column_width_minus1[20];
124         __u8    row_height_minus1[22];
125         __s8    pps_beta_offset_div2;
126         __s8    pps_tc_offset_div2;
127         __u8    log2_parallel_merge_level_minus2;
128
129         __u8    padding[4];
130         __u64   flags;
131 };
132
133 #define V4L2_HEVC_DPB_ENTRY_LONG_TERM_REFERENCE 0x01
134
135 #define V4L2_HEVC_SEI_PIC_STRUCT_FRAME                          0
136 #define V4L2_HEVC_SEI_PIC_STRUCT_TOP_FIELD                      1
137 #define V4L2_HEVC_SEI_PIC_STRUCT_BOTTOM_FIELD                   2
138 #define V4L2_HEVC_SEI_PIC_STRUCT_TOP_BOTTOM                     3
139 #define V4L2_HEVC_SEI_PIC_STRUCT_BOTTOM_TOP                     4
140 #define V4L2_HEVC_SEI_PIC_STRUCT_TOP_BOTTOM_TOP                 5
141 #define V4L2_HEVC_SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM              6
142 #define V4L2_HEVC_SEI_PIC_STRUCT_FRAME_DOUBLING                 7
143 #define V4L2_HEVC_SEI_PIC_STRUCT_FRAME_TRIPLING                 8
144 #define V4L2_HEVC_SEI_PIC_STRUCT_TOP_PAIRED_PREVIOUS_BOTTOM     9
145 #define V4L2_HEVC_SEI_PIC_STRUCT_BOTTOM_PAIRED_PREVIOUS_TOP     10
146 #define V4L2_HEVC_SEI_PIC_STRUCT_TOP_PAIRED_NEXT_BOTTOM         11
147 #define V4L2_HEVC_SEI_PIC_STRUCT_BOTTOM_PAIRED_NEXT_TOP         12
148
149 #define V4L2_HEVC_DPB_ENTRIES_NUM_MAX           16
150
151 struct v4l2_hevc_dpb_entry {
152         __u64   timestamp;
153         __u8    flags;
154         __u8    field_pic;
155         __s32   pic_order_cnt_val;
156         __u8    padding[2];
157 };
158
159 struct v4l2_hevc_pred_weight_table {
160         __s8    delta_luma_weight_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
161         __s8    luma_offset_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
162         __s8    delta_chroma_weight_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2];
163         __s8    chroma_offset_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2];
164
165         __s8    delta_luma_weight_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
166         __s8    luma_offset_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
167         __s8    delta_chroma_weight_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2];
168         __s8    chroma_offset_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2];
169
170         __u8    padding[6];
171
172         __u8    luma_log2_weight_denom;
173         __s8    delta_chroma_log2_weight_denom;
174 };
175
176 #define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_SAO_LUMA              (1ULL << 0)
177 #define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_SAO_CHROMA            (1ULL << 1)
178 #define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_TEMPORAL_MVP_ENABLED  (1ULL << 2)
179 #define V4L2_HEVC_SLICE_PARAMS_FLAG_MVD_L1_ZERO                 (1ULL << 3)
180 #define V4L2_HEVC_SLICE_PARAMS_FLAG_CABAC_INIT                  (1ULL << 4)
181 #define V4L2_HEVC_SLICE_PARAMS_FLAG_COLLOCATED_FROM_L0          (1ULL << 5)
182 #define V4L2_HEVC_SLICE_PARAMS_FLAG_USE_INTEGER_MV              (1ULL << 6)
183 #define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_DEBLOCKING_FILTER_DISABLED (1ULL << 7)
184 #define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_LOOP_FILTER_ACROSS_SLICES_ENABLED (1ULL << 8)
185 #define V4L2_HEVC_SLICE_PARAMS_FLAG_DEPENDENT_SLICE_SEGMENT     (1ULL << 9)
186
187 struct v4l2_ctrl_hevc_slice_params {
188         __u32   bit_size;
189         __u32   data_bit_offset;
190
191         /* ISO/IEC 23008-2, ITU-T Rec. H.265: NAL unit header */
192         __u8    nal_unit_type;
193         __u8    nuh_temporal_id_plus1;
194
195         /* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */
196         __u8    slice_type;
197         __u8    colour_plane_id;
198         __s32   slice_pic_order_cnt;
199         __u8    num_ref_idx_l0_active_minus1;
200         __u8    num_ref_idx_l1_active_minus1;
201         __u8    collocated_ref_idx;
202         __u8    five_minus_max_num_merge_cand;
203         __s8    slice_qp_delta;
204         __s8    slice_cb_qp_offset;
205         __s8    slice_cr_qp_offset;
206         __s8    slice_act_y_qp_offset;
207         __s8    slice_act_cb_qp_offset;
208         __s8    slice_act_cr_qp_offset;
209         __s8    slice_beta_offset_div2;
210         __s8    slice_tc_offset_div2;
211
212         /* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture timing SEI message */
213         __u8    pic_struct;
214
215         /* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */
216         __u32   slice_segment_addr;
217         __u8    ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
218         __u8    ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
219         __u16   short_term_ref_pic_set_size;
220         __u16   long_term_ref_pic_set_size;
221         __u8    padding;
222
223         /* ISO/IEC 23008-2, ITU-T Rec. H.265: Weighted prediction parameter */
224         struct v4l2_hevc_pred_weight_table pred_weight_table;
225
226         __u64   flags;
227 };
228
229 #define V4L2_HEVC_DECODE_PARAM_FLAG_IRAP_PIC            0x1
230 #define V4L2_HEVC_DECODE_PARAM_FLAG_IDR_PIC             0x2
231 #define V4L2_HEVC_DECODE_PARAM_FLAG_NO_OUTPUT_OF_PRIOR  0x4
232
233 struct v4l2_ctrl_hevc_decode_params {
234         __s32   pic_order_cnt_val;
235         __u16   short_term_ref_pic_set_size;
236         __u16   long_term_ref_pic_set_size;
237         __u8    num_active_dpb_entries;
238         struct  v4l2_hevc_dpb_entry dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
239         __u8    num_poc_st_curr_before;
240         __u8    num_poc_st_curr_after;
241         __u8    num_poc_lt_curr;
242         __u8    poc_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
243         __u8    poc_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
244         __u8    poc_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
245         __u64   flags;
246 };
247
248 struct v4l2_ctrl_hevc_scaling_matrix {
249         __u8    scaling_list_4x4[6][16];
250         __u8    scaling_list_8x8[6][64];
251         __u8    scaling_list_16x16[6][64];
252         __u8    scaling_list_32x32[2][64];
253         __u8    scaling_list_dc_coef_16x16[6];
254         __u8    scaling_list_dc_coef_32x32[2];
255 };
256
257 /*  MPEG-class control IDs specific to the Hantro driver as defined by V4L2 */
258 #define V4L2_CID_CODEC_HANTRO_BASE                              (V4L2_CTRL_CLASS_CODEC | 0x1200)
259 /*
260  * V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP -
261  * the number of data (in bits) to skip in the
262  * slice segment header.
263  * If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
264  * to before syntax element "slice_temporal_mvp_enabled_flag".
265  * If IDR, the skipped bits are just "pic_output_flag"
266  * (separate_colour_plane_flag is not supported).
267  */
268 #define V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP  (V4L2_CID_CODEC_HANTRO_BASE + 0)
269
270 #endif