vl: add MJPEG picture description
[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_hash_table.h"
36 #include "util/u_inlines.h"
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 /*
43 * see table 6-12 in the spec
44 */
45 enum pipe_mpeg12_picture_coding_type
46 {
47 PIPE_MPEG12_PICTURE_CODING_TYPE_I = 0x01,
48 PIPE_MPEG12_PICTURE_CODING_TYPE_P = 0x02,
49 PIPE_MPEG12_PICTURE_CODING_TYPE_B = 0x03,
50 PIPE_MPEG12_PICTURE_CODING_TYPE_D = 0x04
51 };
52
53 /*
54 * see table 6-14 in the spec
55 */
56 enum pipe_mpeg12_picture_structure
57 {
58 PIPE_MPEG12_PICTURE_STRUCTURE_RESERVED = 0x00,
59 PIPE_MPEG12_PICTURE_STRUCTURE_FIELD_TOP = 0x01,
60 PIPE_MPEG12_PICTURE_STRUCTURE_FIELD_BOTTOM = 0x02,
61 PIPE_MPEG12_PICTURE_STRUCTURE_FRAME = 0x03
62 };
63
64 /*
65 * flags for macroblock_type, see section 6.3.17.1 in the spec
66 */
67 enum pipe_mpeg12_macroblock_type
68 {
69 PIPE_MPEG12_MB_TYPE_QUANT = 0x01,
70 PIPE_MPEG12_MB_TYPE_MOTION_FORWARD = 0x02,
71 PIPE_MPEG12_MB_TYPE_MOTION_BACKWARD = 0x04,
72 PIPE_MPEG12_MB_TYPE_PATTERN = 0x08,
73 PIPE_MPEG12_MB_TYPE_INTRA = 0x10
74 };
75
76 /*
77 * flags for motion_type, see table 6-17 and 6-18 in the spec
78 */
79 enum pipe_mpeg12_motion_type
80 {
81 PIPE_MPEG12_MO_TYPE_RESERVED = 0x00,
82 PIPE_MPEG12_MO_TYPE_FIELD = 0x01,
83 PIPE_MPEG12_MO_TYPE_FRAME = 0x02,
84 PIPE_MPEG12_MO_TYPE_16x8 = 0x02,
85 PIPE_MPEG12_MO_TYPE_DUAL_PRIME = 0x03
86 };
87
88 /*
89 * see section 6.3.17.1 and table 6-19 in the spec
90 */
91 enum pipe_mpeg12_dct_type
92 {
93 PIPE_MPEG12_DCT_TYPE_FRAME = 0,
94 PIPE_MPEG12_DCT_TYPE_FIELD = 1
95 };
96
97 enum pipe_mpeg12_field_select
98 {
99 PIPE_MPEG12_FS_FIRST_FORWARD = 0x01,
100 PIPE_MPEG12_FS_FIRST_BACKWARD = 0x02,
101 PIPE_MPEG12_FS_SECOND_FORWARD = 0x04,
102 PIPE_MPEG12_FS_SECOND_BACKWARD = 0x08
103 };
104
105 enum pipe_h264_slice_type
106 {
107 PIPE_H264_SLICE_TYPE_P = 0x0,
108 PIPE_H264_SLICE_TYPE_B = 0x1,
109 PIPE_H264_SLICE_TYPE_I = 0x2,
110 PIPE_H264_SLICE_TYPE_SP = 0x3,
111 PIPE_H264_SLICE_TYPE_SI = 0x4
112 };
113
114 enum pipe_h264_enc_picture_type
115 {
116 PIPE_H264_ENC_PICTURE_TYPE_P = 0x00,
117 PIPE_H264_ENC_PICTURE_TYPE_B = 0x01,
118 PIPE_H264_ENC_PICTURE_TYPE_I = 0x02,
119 PIPE_H264_ENC_PICTURE_TYPE_IDR = 0x03,
120 PIPE_H264_ENC_PICTURE_TYPE_SKIP = 0x04
121 };
122
123 enum pipe_h264_enc_rate_control_method
124 {
125 PIPE_H264_ENC_RATE_CONTROL_METHOD_DISABLE = 0x00,
126 PIPE_H264_ENC_RATE_CONTROL_METHOD_CONSTANT_SKIP = 0x01,
127 PIPE_H264_ENC_RATE_CONTROL_METHOD_VARIABLE_SKIP = 0x02,
128 PIPE_H264_ENC_RATE_CONTROL_METHOD_CONSTANT = 0x03,
129 PIPE_H264_ENC_RATE_CONTROL_METHOD_VARIABLE = 0x04
130 };
131
132 struct pipe_picture_desc
133 {
134 enum pipe_video_profile profile;
135 enum pipe_video_entrypoint entry_point;
136 };
137
138 struct pipe_quant_matrix
139 {
140 enum pipe_video_format codec;
141 };
142
143 struct pipe_macroblock
144 {
145 enum pipe_video_format codec;
146 };
147
148 struct pipe_mpeg12_picture_desc
149 {
150 struct pipe_picture_desc base;
151
152 unsigned picture_coding_type;
153 unsigned picture_structure;
154 unsigned frame_pred_frame_dct;
155 unsigned q_scale_type;
156 unsigned alternate_scan;
157 unsigned intra_vlc_format;
158 unsigned concealment_motion_vectors;
159 unsigned intra_dc_precision;
160 unsigned f_code[2][2];
161 unsigned top_field_first;
162 unsigned full_pel_forward_vector;
163 unsigned full_pel_backward_vector;
164 unsigned num_slices;
165
166 const uint8_t *intra_matrix;
167 const uint8_t *non_intra_matrix;
168
169 struct pipe_video_buffer *ref[2];
170 };
171
172 struct pipe_mpeg12_macroblock
173 {
174 struct pipe_macroblock base;
175
176 /* see section 6.3.17 in the spec */
177 unsigned short x, y;
178
179 /* see section 6.3.17.1 in the spec */
180 unsigned char macroblock_type;
181
182 union {
183 struct {
184 /* see table 6-17 in the spec */
185 unsigned int frame_motion_type:2;
186
187 /* see table 6-18 in the spec */
188 unsigned int field_motion_type:2;
189
190 /* see table 6-19 in the spec */
191 unsigned int dct_type:1;
192 } bits;
193 unsigned int value;
194 } macroblock_modes;
195
196 /* see section 6.3.17.2 in the spec */
197 unsigned char motion_vertical_field_select;
198
199 /* see Table 7-7 in the spec */
200 short PMV[2][2][2];
201
202 /* see figure 6.10-12 in the spec */
203 unsigned short coded_block_pattern;
204
205 /* see figure 6.10-12 in the spec */
206 short *blocks;
207
208 /* Number of skipped macroblocks after this macroblock */
209 unsigned short num_skipped_macroblocks;
210 };
211
212 struct pipe_mpeg4_picture_desc
213 {
214 struct pipe_picture_desc base;
215
216 int32_t trd[2];
217 int32_t trb[2];
218 uint16_t vop_time_increment_resolution;
219 uint8_t vop_coding_type;
220 uint8_t vop_fcode_forward;
221 uint8_t vop_fcode_backward;
222 uint8_t resync_marker_disable;
223 uint8_t interlaced;
224 uint8_t quant_type;
225 uint8_t quarter_sample;
226 uint8_t short_video_header;
227 uint8_t rounding_control;
228 uint8_t alternate_vertical_scan_flag;
229 uint8_t top_field_first;
230
231 const uint8_t *intra_matrix;
232 const uint8_t *non_intra_matrix;
233
234 struct pipe_video_buffer *ref[2];
235 };
236
237 struct pipe_vc1_picture_desc
238 {
239 struct pipe_picture_desc base;
240
241 uint32_t slice_count;
242 uint8_t picture_type;
243 uint8_t frame_coding_mode;
244 uint8_t postprocflag;
245 uint8_t pulldown;
246 uint8_t interlace;
247 uint8_t tfcntrflag;
248 uint8_t finterpflag;
249 uint8_t psf;
250 uint8_t dquant;
251 uint8_t panscan_flag;
252 uint8_t refdist_flag;
253 uint8_t quantizer;
254 uint8_t extended_mv;
255 uint8_t extended_dmv;
256 uint8_t overlap;
257 uint8_t vstransform;
258 uint8_t loopfilter;
259 uint8_t fastuvmc;
260 uint8_t range_mapy_flag;
261 uint8_t range_mapy;
262 uint8_t range_mapuv_flag;
263 uint8_t range_mapuv;
264 uint8_t multires;
265 uint8_t syncmarker;
266 uint8_t rangered;
267 uint8_t maxbframes;
268 uint8_t deblockEnable;
269 uint8_t pquant;
270
271 struct pipe_video_buffer *ref[2];
272 };
273
274 struct pipe_h264_sps
275 {
276 uint8_t level_idc;
277 uint8_t chroma_format_idc;
278 uint8_t separate_colour_plane_flag;
279 uint8_t bit_depth_luma_minus8;
280 uint8_t bit_depth_chroma_minus8;
281 uint8_t seq_scaling_matrix_present_flag;
282 uint8_t ScalingList4x4[6][16];
283 uint8_t ScalingList8x8[6][64];
284 uint8_t log2_max_frame_num_minus4;
285 uint8_t pic_order_cnt_type;
286 uint8_t log2_max_pic_order_cnt_lsb_minus4;
287 uint8_t delta_pic_order_always_zero_flag;
288 int32_t offset_for_non_ref_pic;
289 int32_t offset_for_top_to_bottom_field;
290 uint8_t num_ref_frames_in_pic_order_cnt_cycle;
291 int32_t offset_for_ref_frame[256];
292 uint8_t max_num_ref_frames;
293 uint8_t frame_mbs_only_flag;
294 uint8_t mb_adaptive_frame_field_flag;
295 uint8_t direct_8x8_inference_flag;
296 };
297
298 struct pipe_h264_pps
299 {
300 struct pipe_h264_sps *sps;
301
302 uint8_t entropy_coding_mode_flag;
303 uint8_t bottom_field_pic_order_in_frame_present_flag;
304 uint8_t num_slice_groups_minus1;
305 uint8_t slice_group_map_type;
306 uint8_t slice_group_change_rate_minus1;
307 uint8_t num_ref_idx_l0_default_active_minus1;
308 uint8_t num_ref_idx_l1_default_active_minus1;
309 uint8_t weighted_pred_flag;
310 uint8_t weighted_bipred_idc;
311 int8_t pic_init_qp_minus26;
312 int8_t chroma_qp_index_offset;
313 uint8_t deblocking_filter_control_present_flag;
314 uint8_t constrained_intra_pred_flag;
315 uint8_t redundant_pic_cnt_present_flag;
316 uint8_t ScalingList4x4[6][16];
317 uint8_t ScalingList8x8[6][64];
318 uint8_t transform_8x8_mode_flag;
319 int8_t second_chroma_qp_index_offset;
320 };
321
322 struct pipe_h264_picture_desc
323 {
324 struct pipe_picture_desc base;
325
326 struct pipe_h264_pps *pps;
327
328 /* slice header */
329 uint32_t frame_num;
330 uint8_t field_pic_flag;
331 uint8_t bottom_field_flag;
332 uint8_t num_ref_idx_l0_active_minus1;
333 uint8_t num_ref_idx_l1_active_minus1;
334
335 uint32_t slice_count;
336 int32_t field_order_cnt[2];
337 bool is_reference;
338 uint8_t num_ref_frames;
339
340 bool is_long_term[16];
341 bool top_is_reference[16];
342 bool bottom_is_reference[16];
343 uint32_t field_order_cnt_list[16][2];
344 uint32_t frame_num_list[16];
345
346 struct pipe_video_buffer *ref[16];
347 };
348
349 struct pipe_h264_enc_rate_control
350 {
351 enum pipe_h264_enc_rate_control_method rate_ctrl_method;
352 unsigned target_bitrate;
353 unsigned peak_bitrate;
354 unsigned frame_rate_num;
355 unsigned frame_rate_den;
356 unsigned vbv_buffer_size;
357 unsigned vbv_buf_lv;
358 unsigned target_bits_picture;
359 unsigned peak_bits_picture_integer;
360 unsigned peak_bits_picture_fraction;
361 unsigned fill_data_enable;
362 unsigned enforce_hrd;
363 };
364
365 struct pipe_h264_enc_motion_estimation
366 {
367 unsigned motion_est_quarter_pixel;
368 unsigned enc_disable_sub_mode;
369 unsigned lsmvert;
370 unsigned enc_en_ime_overw_dis_subm;
371 unsigned enc_ime_overw_dis_subm_no;
372 unsigned enc_ime2_search_range_x;
373 unsigned enc_ime2_search_range_y;
374 };
375
376 struct pipe_h264_enc_pic_control
377 {
378 unsigned enc_cabac_enable;
379 unsigned enc_constraint_set_flags;
380 };
381
382 struct pipe_h264_enc_picture_desc
383 {
384 struct pipe_picture_desc base;
385
386 struct pipe_h264_enc_rate_control rate_ctrl;
387
388 struct pipe_h264_enc_motion_estimation motion_est;
389 struct pipe_h264_enc_pic_control pic_ctrl;
390
391 unsigned quant_i_frames;
392 unsigned quant_p_frames;
393 unsigned quant_b_frames;
394
395 enum pipe_h264_enc_picture_type picture_type;
396 unsigned frame_num;
397 unsigned frame_num_cnt;
398 unsigned p_remain;
399 unsigned i_remain;
400 unsigned idr_pic_id;
401 unsigned gop_cnt;
402 unsigned pic_order_cnt;
403 unsigned ref_idx_l0;
404 unsigned ref_idx_l1;
405 unsigned gop_size;
406 unsigned ref_pic_mode;
407
408 bool not_referenced;
409 bool is_idr;
410 bool enable_vui;
411 struct util_hash_table *frame_idx;
412
413 };
414
415 struct pipe_h265_sps
416 {
417 uint8_t chroma_format_idc;
418 uint8_t separate_colour_plane_flag;
419 uint32_t pic_width_in_luma_samples;
420 uint32_t pic_height_in_luma_samples;
421 uint8_t bit_depth_luma_minus8;
422 uint8_t bit_depth_chroma_minus8;
423 uint8_t log2_max_pic_order_cnt_lsb_minus4;
424 uint8_t sps_max_dec_pic_buffering_minus1;
425 uint8_t log2_min_luma_coding_block_size_minus3;
426 uint8_t log2_diff_max_min_luma_coding_block_size;
427 uint8_t log2_min_transform_block_size_minus2;
428 uint8_t log2_diff_max_min_transform_block_size;
429 uint8_t max_transform_hierarchy_depth_inter;
430 uint8_t max_transform_hierarchy_depth_intra;
431 uint8_t scaling_list_enabled_flag;
432 uint8_t ScalingList4x4[6][16];
433 uint8_t ScalingList8x8[6][64];
434 uint8_t ScalingList16x16[6][64];
435 uint8_t ScalingList32x32[2][64];
436 uint8_t ScalingListDCCoeff16x16[6];
437 uint8_t ScalingListDCCoeff32x32[2];
438 uint8_t amp_enabled_flag;
439 uint8_t sample_adaptive_offset_enabled_flag;
440 uint8_t pcm_enabled_flag;
441 uint8_t pcm_sample_bit_depth_luma_minus1;
442 uint8_t pcm_sample_bit_depth_chroma_minus1;
443 uint8_t log2_min_pcm_luma_coding_block_size_minus3;
444 uint8_t log2_diff_max_min_pcm_luma_coding_block_size;
445 uint8_t pcm_loop_filter_disabled_flag;
446 uint8_t num_short_term_ref_pic_sets;
447 uint8_t long_term_ref_pics_present_flag;
448 uint8_t num_long_term_ref_pics_sps;
449 uint8_t sps_temporal_mvp_enabled_flag;
450 uint8_t strong_intra_smoothing_enabled_flag;
451 };
452
453 struct pipe_h265_pps
454 {
455 struct pipe_h265_sps *sps;
456
457 uint8_t dependent_slice_segments_enabled_flag;
458 uint8_t output_flag_present_flag;
459 uint8_t num_extra_slice_header_bits;
460 uint8_t sign_data_hiding_enabled_flag;
461 uint8_t cabac_init_present_flag;
462 uint8_t num_ref_idx_l0_default_active_minus1;
463 uint8_t num_ref_idx_l1_default_active_minus1;
464 int8_t init_qp_minus26;
465 uint8_t constrained_intra_pred_flag;
466 uint8_t transform_skip_enabled_flag;
467 uint8_t cu_qp_delta_enabled_flag;
468 uint8_t diff_cu_qp_delta_depth;
469 int8_t pps_cb_qp_offset;
470 int8_t pps_cr_qp_offset;
471 uint8_t pps_slice_chroma_qp_offsets_present_flag;
472 uint8_t weighted_pred_flag;
473 uint8_t weighted_bipred_flag;
474 uint8_t transquant_bypass_enabled_flag;
475 uint8_t tiles_enabled_flag;
476 uint8_t entropy_coding_sync_enabled_flag;
477 uint8_t num_tile_columns_minus1;
478 uint8_t num_tile_rows_minus1;
479 uint8_t uniform_spacing_flag;
480 uint16_t column_width_minus1[20];
481 uint16_t row_height_minus1[22];
482 uint8_t loop_filter_across_tiles_enabled_flag;
483 uint8_t pps_loop_filter_across_slices_enabled_flag;
484 uint8_t deblocking_filter_control_present_flag;
485 uint8_t deblocking_filter_override_enabled_flag;
486 uint8_t pps_deblocking_filter_disabled_flag;
487 int8_t pps_beta_offset_div2;
488 int8_t pps_tc_offset_div2;
489 uint8_t lists_modification_present_flag;
490 uint8_t log2_parallel_merge_level_minus2;
491 uint8_t slice_segment_header_extension_present_flag;
492 };
493
494 struct pipe_h265_picture_desc
495 {
496 struct pipe_picture_desc base;
497
498 struct pipe_h265_pps *pps;
499
500 uint8_t IDRPicFlag;
501 uint8_t RAPPicFlag;
502 uint8_t CurrRpsIdx;
503 uint32_t NumPocTotalCurr;
504 uint32_t NumDeltaPocsOfRefRpsIdx;
505 uint32_t NumShortTermPictureSliceHeaderBits;
506 uint32_t NumLongTermPictureSliceHeaderBits;
507
508 int32_t CurrPicOrderCntVal;
509 struct pipe_video_buffer *ref[16];
510 int32_t PicOrderCntVal[16];
511 uint8_t IsLongTerm[16];
512 uint8_t NumPocStCurrBefore;
513 uint8_t NumPocStCurrAfter;
514 uint8_t NumPocLtCurr;
515 uint8_t RefPicSetStCurrBefore[8];
516 uint8_t RefPicSetStCurrAfter[8];
517 uint8_t RefPicSetLtCurr[8];
518 uint8_t RefPicList[2][15];
519 bool UseRefPicList;
520 };
521
522 struct pipe_mjpeg_picture_desc
523 {
524 struct pipe_picture_desc base;
525
526 struct
527 {
528 uint16_t picture_width;
529 uint16_t picture_height;
530
531 struct {
532 uint8_t component_id;
533 uint8_t h_sampling_factor;
534 uint8_t v_sampling_factor;
535 uint8_t quantiser_table_selector;
536 } components[255];
537
538 uint8_t num_components;
539 } picture_parameter;
540
541 struct
542 {
543 uint8_t load_quantiser_table[4];
544 uint8_t quantiser_table[4][64];
545 } quantization_table;
546
547 struct
548 {
549 uint8_t load_huffman_table[2];
550
551 struct {
552 uint8_t num_dc_codes[16];
553 uint8_t dc_values[12];
554 uint8_t num_ac_codes[16];
555 uint8_t ac_values[162];
556 uint8_t pad[2];
557 } table[2];
558 } huffman_table;
559
560 struct
561 {
562 unsigned slice_data_size;
563 unsigned slice_data_offset;
564 unsigned slice_data_flag;
565 unsigned slice_horizontal_position;
566 unsigned slice_vertical_position;
567
568 struct {
569 uint8_t component_selector;
570 uint8_t dc_table_selector;
571 uint8_t ac_table_selector;
572 } components[4];
573
574 uint8_t num_components;
575
576 uint16_t restart_interval;
577 unsigned num_mcus;
578 } slice_parameter;
579 };
580
581 #ifdef __cplusplus
582 }
583 #endif
584
585 #endif /* PIPE_VIDEO_STATE_H */