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 TUNGSTEN GRAPHICS 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 struct pipe_picture_desc
105 {
106    enum pipe_video_profile profile;
107 };
108 
109 struct pipe_quant_matrix
110 {
111    enum pipe_video_codec codec;
112 };
113 
114 struct pipe_macroblock
115 {
116    enum pipe_video_codec codec;
117 };
118 
119 struct pipe_mpeg12_picture_desc
120 {
121    struct pipe_picture_desc base;
122 
123    unsigned picture_coding_type;
124    unsigned picture_structure;
125    unsigned frame_pred_frame_dct;
126    unsigned q_scale_type;
127    unsigned alternate_scan;
128    unsigned intra_vlc_format;
129    unsigned concealment_motion_vectors;
130    unsigned intra_dc_precision;
131    unsigned f_code[2][2];
132    unsigned top_field_first;
133    unsigned full_pel_forward_vector;
134    unsigned full_pel_backward_vector;
135    unsigned num_slices;
136 
137    const uint8_t *intra_matrix;
138    const uint8_t *non_intra_matrix;
139 
140    struct pipe_video_buffer *ref[2];
141 };
142 
143 struct pipe_mpeg12_macroblock
144 {
145    struct pipe_macroblock base;
146 
147    /* see section 6.3.17 in the spec */
148    unsigned short x, y;
149 
150    /* see section 6.3.17.1 in the spec */
151    unsigned char macroblock_type;
152 
153    union {
154       struct {
155          /* see table 6-17 in the spec */
156          unsigned int frame_motion_type:2;
157 
158          /* see table 6-18 in the spec */
159          unsigned int field_motion_type:2;
160 
161          /* see table 6-19 in the spec */
162          unsigned int dct_type:1;
163       } bits;
164       unsigned int value;
165    } macroblock_modes;
166 
167     /* see section 6.3.17.2 in the spec */
168    unsigned char motion_vertical_field_select;
169 
170    /* see Table 7-7 in the spec */
171    short PMV[2][2][2];
172 
173    /* see figure 6.10-12 in the spec */
174    unsigned short coded_block_pattern;
175 
176    /* see figure 6.10-12 in the spec */
177    short *blocks;
178 
179    /* Number of skipped macroblocks after this macroblock */
180    unsigned short num_skipped_macroblocks;
181 };
182 
183 struct pipe_mpeg4_picture_desc
184 {
185    struct pipe_picture_desc base;
186 
187    int32_t trd[2];
188    int32_t trb[2];
189    uint16_t vop_time_increment_resolution;
190    uint8_t vop_coding_type;
191    uint8_t vop_fcode_forward;
192    uint8_t vop_fcode_backward;
193    uint8_t resync_marker_disable;
194    uint8_t interlaced;
195    uint8_t quant_type;
196    uint8_t quarter_sample;
197    uint8_t short_video_header;
198    uint8_t rounding_control;
199    uint8_t alternate_vertical_scan_flag;
200    uint8_t top_field_first;
201 
202    const uint8_t *intra_matrix;
203    const uint8_t *non_intra_matrix;
204 
205    struct pipe_video_buffer *ref[2];
206 };
207 
208 struct pipe_vc1_picture_desc
209 {
210    struct pipe_picture_desc base;
211 
212    uint32_t slice_count;
213    uint8_t picture_type;
214    uint8_t frame_coding_mode;
215    uint8_t postprocflag;
216    uint8_t pulldown;
217    uint8_t interlace;
218    uint8_t tfcntrflag;
219    uint8_t finterpflag;
220    uint8_t psf;
221    uint8_t dquant;
222    uint8_t panscan_flag;
223    uint8_t refdist_flag;
224    uint8_t quantizer;
225    uint8_t extended_mv;
226    uint8_t extended_dmv;
227    uint8_t overlap;
228    uint8_t vstransform;
229    uint8_t loopfilter;
230    uint8_t fastuvmc;
231    uint8_t range_mapy_flag;
232    uint8_t range_mapy;
233    uint8_t range_mapuv_flag;
234    uint8_t range_mapuv;
235    uint8_t multires;
236    uint8_t syncmarker;
237    uint8_t rangered;
238    uint8_t maxbframes;
239    uint8_t deblockEnable;
240    uint8_t pquant;
241 
242    struct pipe_video_buffer *ref[2];
243 };
244 
245 struct pipe_h264_picture_desc
246 {
247    struct pipe_picture_desc base;
248 
249    uint32_t slice_count;
250    int32_t  field_order_cnt[2];
251    bool     is_reference;
252    uint32_t frame_num;
253    uint8_t  field_pic_flag;
254    uint8_t  bottom_field_flag;
255    uint8_t  num_ref_frames;
256    uint8_t  mb_adaptive_frame_field_flag;
257    uint8_t  constrained_intra_pred_flag;
258    uint8_t  weighted_pred_flag;
259    uint8_t  weighted_bipred_idc;
260    uint8_t  frame_mbs_only_flag;
261    uint8_t  transform_8x8_mode_flag;
262    int8_t   chroma_qp_index_offset;
263    int8_t   second_chroma_qp_index_offset;
264    int8_t   pic_init_qp_minus26;
265    uint8_t  num_ref_idx_l0_active_minus1;
266    uint8_t  num_ref_idx_l1_active_minus1;
267    uint8_t  log2_max_frame_num_minus4;
268    uint8_t  pic_order_cnt_type;
269    uint8_t  log2_max_pic_order_cnt_lsb_minus4;
270    uint8_t  delta_pic_order_always_zero_flag;
271    uint8_t  direct_8x8_inference_flag;
272    uint8_t  entropy_coding_mode_flag;
273    uint8_t  pic_order_present_flag;
274    uint8_t  deblocking_filter_control_present_flag;
275    uint8_t  redundant_pic_cnt_present_flag;
276    uint8_t  scaling_lists_4x4[6][16];
277    uint8_t  scaling_lists_8x8[2][64];
278 
279    bool     is_long_term[16];
280    bool     top_is_reference[16];
281    bool     bottom_is_reference[16];
282    uint32_t field_order_cnt_list[16][2];
283    uint32_t frame_num_list[16];
284 
285    struct pipe_video_buffer *ref[16];
286 };
287 
288 #ifdef __cplusplus
289 }
290 #endif
291 
292 #endif /* PIPE_VIDEO_STATE_H */
293