vl: add interface for H264 B-frame encoding
[mesa.git] / src / gallium / include / pipe / p_video_state.h
1 /**************************************************************************
2 *
3 * Copyright 2009 Younes Manton.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef PIPE_VIDEO_STATE_H
29 #define PIPE_VIDEO_STATE_H
30
31 #include "pipe/p_defines.h"
32 #include "pipe/p_format.h"
33 #include "pipe/p_state.h"
34 #include "pipe/p_screen.h"
35 #include "util/u_inlines.h"
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 /*
42 * see table 6-12 in the spec
43 */
44 enum pipe_mpeg12_picture_coding_type
45 {
46 PIPE_MPEG12_PICTURE_CODING_TYPE_I = 0x01,
47 PIPE_MPEG12_PICTURE_CODING_TYPE_P = 0x02,
48 PIPE_MPEG12_PICTURE_CODING_TYPE_B = 0x03,
49 PIPE_MPEG12_PICTURE_CODING_TYPE_D = 0x04
50 };
51
52 /*
53 * see table 6-14 in the spec
54 */
55 enum pipe_mpeg12_picture_structure
56 {
57 PIPE_MPEG12_PICTURE_STRUCTURE_RESERVED = 0x00,
58 PIPE_MPEG12_PICTURE_STRUCTURE_FIELD_TOP = 0x01,
59 PIPE_MPEG12_PICTURE_STRUCTURE_FIELD_BOTTOM = 0x02,
60 PIPE_MPEG12_PICTURE_STRUCTURE_FRAME = 0x03
61 };
62
63 /*
64 * flags for macroblock_type, see section 6.3.17.1 in the spec
65 */
66 enum pipe_mpeg12_macroblock_type
67 {
68 PIPE_MPEG12_MB_TYPE_QUANT = 0x01,
69 PIPE_MPEG12_MB_TYPE_MOTION_FORWARD = 0x02,
70 PIPE_MPEG12_MB_TYPE_MOTION_BACKWARD = 0x04,
71 PIPE_MPEG12_MB_TYPE_PATTERN = 0x08,
72 PIPE_MPEG12_MB_TYPE_INTRA = 0x10
73 };
74
75 /*
76 * flags for motion_type, see table 6-17 and 6-18 in the spec
77 */
78 enum pipe_mpeg12_motion_type
79 {
80 PIPE_MPEG12_MO_TYPE_RESERVED = 0x00,
81 PIPE_MPEG12_MO_TYPE_FIELD = 0x01,
82 PIPE_MPEG12_MO_TYPE_FRAME = 0x02,
83 PIPE_MPEG12_MO_TYPE_16x8 = 0x02,
84 PIPE_MPEG12_MO_TYPE_DUAL_PRIME = 0x03
85 };
86
87 /*
88 * see section 6.3.17.1 and table 6-19 in the spec
89 */
90 enum pipe_mpeg12_dct_type
91 {
92 PIPE_MPEG12_DCT_TYPE_FRAME = 0,
93 PIPE_MPEG12_DCT_TYPE_FIELD = 1
94 };
95
96 enum pipe_mpeg12_field_select
97 {
98 PIPE_MPEG12_FS_FIRST_FORWARD = 0x01,
99 PIPE_MPEG12_FS_FIRST_BACKWARD = 0x02,
100 PIPE_MPEG12_FS_SECOND_FORWARD = 0x04,
101 PIPE_MPEG12_FS_SECOND_BACKWARD = 0x08
102 };
103
104 enum pipe_h264_slice_type
105 {
106 PIPE_H264_SLICE_TYPE_P = 0x0,
107 PIPE_H264_SLICE_TYPE_B = 0x1,
108 PIPE_H264_SLICE_TYPE_I = 0x2,
109 PIPE_H264_SLICE_TYPE_SP = 0x3,
110 PIPE_H264_SLICE_TYPE_SI = 0x4
111 };
112
113 enum pipe_h264_enc_picture_type
114 {
115 PIPE_H264_ENC_PICTURE_TYPE_P = 0x00,
116 PIPE_H264_ENC_PICTURE_TYPE_B = 0x01,
117 PIPE_H264_ENC_PICTURE_TYPE_I = 0x02,
118 PIPE_H264_ENC_PICTURE_TYPE_IDR = 0x03,
119 PIPE_H264_ENC_PICTURE_TYPE_SKIP = 0x04
120 };
121
122 enum pipe_h264_enc_rate_control_method
123 {
124 PIPE_H264_ENC_RATE_CONTROL_METHOD_DISABLE = 0x00,
125 PIPE_H264_ENC_RATE_CONTROL_METHOD_CONSTANT_SKIP = 0x01,
126 PIPE_H264_ENC_RATE_CONTROL_METHOD_VARIABLE_SKIP = 0x02,
127 PIPE_H264_ENC_RATE_CONTROL_METHOD_CONSTANT = 0x03,
128 PIPE_H264_ENC_RATE_CONTROL_METHOD_VARIABLE = 0x04
129 };
130
131 struct pipe_picture_desc
132 {
133 enum pipe_video_profile profile;
134 };
135
136 struct pipe_quant_matrix
137 {
138 enum pipe_video_format codec;
139 };
140
141 struct pipe_macroblock
142 {
143 enum pipe_video_format codec;
144 };
145
146 struct pipe_mpeg12_picture_desc
147 {
148 struct pipe_picture_desc base;
149
150 unsigned picture_coding_type;
151 unsigned picture_structure;
152 unsigned frame_pred_frame_dct;
153 unsigned q_scale_type;
154 unsigned alternate_scan;
155 unsigned intra_vlc_format;
156 unsigned concealment_motion_vectors;
157 unsigned intra_dc_precision;
158 unsigned f_code[2][2];
159 unsigned top_field_first;
160 unsigned full_pel_forward_vector;
161 unsigned full_pel_backward_vector;
162 unsigned num_slices;
163
164 const uint8_t *intra_matrix;
165 const uint8_t *non_intra_matrix;
166
167 struct pipe_video_buffer *ref[2];
168 };
169
170 struct pipe_mpeg12_macroblock
171 {
172 struct pipe_macroblock base;
173
174 /* see section 6.3.17 in the spec */
175 unsigned short x, y;
176
177 /* see section 6.3.17.1 in the spec */
178 unsigned char macroblock_type;
179
180 union {
181 struct {
182 /* see table 6-17 in the spec */
183 unsigned int frame_motion_type:2;
184
185 /* see table 6-18 in the spec */
186 unsigned int field_motion_type:2;
187
188 /* see table 6-19 in the spec */
189 unsigned int dct_type:1;
190 } bits;
191 unsigned int value;
192 } macroblock_modes;
193
194 /* see section 6.3.17.2 in the spec */
195 unsigned char motion_vertical_field_select;
196
197 /* see Table 7-7 in the spec */
198 short PMV[2][2][2];
199
200 /* see figure 6.10-12 in the spec */
201 unsigned short coded_block_pattern;
202
203 /* see figure 6.10-12 in the spec */
204 short *blocks;
205
206 /* Number of skipped macroblocks after this macroblock */
207 unsigned short num_skipped_macroblocks;
208 };
209
210 struct pipe_mpeg4_picture_desc
211 {
212 struct pipe_picture_desc base;
213
214 int32_t trd[2];
215 int32_t trb[2];
216 uint16_t vop_time_increment_resolution;
217 uint8_t vop_coding_type;
218 uint8_t vop_fcode_forward;
219 uint8_t vop_fcode_backward;
220 uint8_t resync_marker_disable;
221 uint8_t interlaced;
222 uint8_t quant_type;
223 uint8_t quarter_sample;
224 uint8_t short_video_header;
225 uint8_t rounding_control;
226 uint8_t alternate_vertical_scan_flag;
227 uint8_t top_field_first;
228
229 const uint8_t *intra_matrix;
230 const uint8_t *non_intra_matrix;
231
232 struct pipe_video_buffer *ref[2];
233 };
234
235 struct pipe_vc1_picture_desc
236 {
237 struct pipe_picture_desc base;
238
239 uint32_t slice_count;
240 uint8_t picture_type;
241 uint8_t frame_coding_mode;
242 uint8_t postprocflag;
243 uint8_t pulldown;
244 uint8_t interlace;
245 uint8_t tfcntrflag;
246 uint8_t finterpflag;
247 uint8_t psf;
248 uint8_t dquant;
249 uint8_t panscan_flag;
250 uint8_t refdist_flag;
251 uint8_t quantizer;
252 uint8_t extended_mv;
253 uint8_t extended_dmv;
254 uint8_t overlap;
255 uint8_t vstransform;
256 uint8_t loopfilter;
257 uint8_t fastuvmc;
258 uint8_t range_mapy_flag;
259 uint8_t range_mapy;
260 uint8_t range_mapuv_flag;
261 uint8_t range_mapuv;
262 uint8_t multires;
263 uint8_t syncmarker;
264 uint8_t rangered;
265 uint8_t maxbframes;
266 uint8_t deblockEnable;
267 uint8_t pquant;
268
269 struct pipe_video_buffer *ref[2];
270 };
271
272 struct pipe_h264_sps
273 {
274 uint8_t chroma_format_idc;
275 uint8_t separate_colour_plane_flag;
276 uint8_t bit_depth_luma_minus8;
277 uint8_t bit_depth_chroma_minus8;
278 uint8_t seq_scaling_matrix_present_flag;
279 uint8_t ScalingList4x4[6][16];
280 uint8_t ScalingList8x8[6][64];
281 uint8_t log2_max_frame_num_minus4;
282 uint8_t pic_order_cnt_type;
283 uint8_t log2_max_pic_order_cnt_lsb_minus4;
284 uint8_t delta_pic_order_always_zero_flag;
285 int32_t offset_for_non_ref_pic;
286 int32_t offset_for_top_to_bottom_field;
287 uint8_t num_ref_frames_in_pic_order_cnt_cycle;
288 int32_t offset_for_ref_frame[256];
289 uint8_t max_num_ref_frames;
290 uint8_t frame_mbs_only_flag;
291 uint8_t mb_adaptive_frame_field_flag;
292 uint8_t direct_8x8_inference_flag;
293 };
294
295 struct pipe_h264_pps
296 {
297 struct pipe_h264_sps *sps;
298
299 uint8_t entropy_coding_mode_flag;
300 uint8_t bottom_field_pic_order_in_frame_present_flag;
301 uint8_t num_slice_groups_minus1;
302 uint8_t slice_group_map_type;
303 uint8_t slice_group_change_rate_minus1;
304 uint8_t num_ref_idx_l0_default_active_minus1;
305 uint8_t num_ref_idx_l1_default_active_minus1;
306 uint8_t weighted_pred_flag;
307 uint8_t weighted_bipred_idc;
308 int8_t pic_init_qp_minus26;
309 int8_t chroma_qp_index_offset;
310 uint8_t deblocking_filter_control_present_flag;
311 uint8_t constrained_intra_pred_flag;
312 uint8_t redundant_pic_cnt_present_flag;
313 uint8_t ScalingList4x4[6][16];
314 uint8_t ScalingList8x8[6][64];
315 uint8_t transform_8x8_mode_flag;
316 int8_t second_chroma_qp_index_offset;
317 };
318
319 struct pipe_h264_picture_desc
320 {
321 struct pipe_picture_desc base;
322
323 struct pipe_h264_pps *pps;
324
325 /* slice header */
326 uint32_t frame_num;
327 uint8_t field_pic_flag;
328 uint8_t bottom_field_flag;
329 uint8_t num_ref_idx_l0_active_minus1;
330 uint8_t num_ref_idx_l1_active_minus1;
331
332 uint32_t slice_count;
333 int32_t field_order_cnt[2];
334 bool is_reference;
335 uint8_t num_ref_frames;
336
337 bool is_long_term[16];
338 bool top_is_reference[16];
339 bool bottom_is_reference[16];
340 uint32_t field_order_cnt_list[16][2];
341 uint32_t frame_num_list[16];
342
343 struct pipe_video_buffer *ref[16];
344 };
345
346 struct pipe_h264_enc_rate_control
347 {
348 enum pipe_h264_enc_rate_control_method rate_ctrl_method;
349 unsigned target_bitrate;
350 unsigned peak_bitrate;
351 unsigned frame_rate_num;
352 unsigned frame_rate_den;
353 unsigned vbv_buffer_size;
354 unsigned target_bits_picture;
355 unsigned peak_bits_picture_integer;
356 unsigned peak_bits_picture_fraction;
357 };
358
359 struct pipe_h264_enc_picture_desc
360 {
361 struct pipe_picture_desc base;
362
363 struct pipe_h264_enc_rate_control rate_ctrl;
364
365 unsigned quant_i_frames;
366 unsigned quant_p_frames;
367 unsigned quant_b_frames;
368
369 enum pipe_h264_enc_picture_type picture_type;
370 unsigned frame_num;
371 unsigned pic_order_cnt;
372 unsigned ref_idx_l0;
373 unsigned ref_idx_l1;
374 };
375
376 #ifdef __cplusplus
377 }
378 #endif
379
380 #endif /* PIPE_VIDEO_STATE_H */