1 /******************************************************************************
2  *
3  * Copyright (C) 2015 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 
21 #ifndef __IMPEG2_DEFS_H__
22 #define __IMPEG2_DEFS_H__
23 
24 #include <assert.h>
25 
26 /******************************************************************************
27 * MPEG2 Start code and other code definitions
28 *******************************************************************************/
29 #define START_CODE_PREFIX               0x000001
30 #define SEQUENCE_HEADER_CODE            0x000001B3
31 #define EXTENSION_START_CODE            0x000001B5
32 #define USER_DATA_START_CODE            0x000001B2
33 #define GOP_START_CODE                  0x000001B8
34 #define PICTURE_START_CODE              0x00000100
35 #define SEQUENCE_END_CODE               0x000001B7
36 #define RESERVED_START_CODE             0x000001B0
37 #define MB_ESCAPE_CODE                  0x008
38 
39 /******************************************************************************
40 * MPEG2 Length of various codes definitions
41 *******************************************************************************/
42 #define START_CODE_LEN                  32
43 #define START_CODE_PREFIX_LEN           24
44 #define MB_ESCAPE_CODE_LEN              11
45 #define EXT_ID_LEN                      4
46 #define MB_QUANT_SCALE_CODE_LEN         5
47 #define MB_DCT_TYPE_LEN                 1
48 #define MB_MOTION_TYPE_LEN              2
49 #define BYTE_LEN                        8
50 
51 /******************************************************************************
52 * MPEG1 code definitions
53 *******************************************************************************/
54 #define MB_STUFFING_CODE                0x00F
55 
56 /******************************************************************************
57 * MPEG1 Length of various codes definitions
58 *******************************************************************************/
59 #define MB_STUFFING_CODE_LEN             11
60 
61 /******************************************************************************
62 * MPEG2 MB definitions
63 *******************************************************************************/
64 #define MPEG2_INTRA_MB                  0x04
65 #define MPEG2_INTRAQ_MB                 0x44
66 #define MPEG2_INTER_MB                  0x28
67 #define MB_MOTION_BIDIRECT              0x30
68 #define MB_INTRA_OR_PATTERN             0x0C
69 
70 /******************************************************************************
71 * Tools definitions
72 *******************************************************************************/
73 #define SPATIAL_SCALABILITY             0x01
74 #define TEMPORAL_SCALABILITY            0x03
75 
76 /******************************************************************************
77 * Extension IDs definitions
78 *******************************************************************************/
79 #define SEQ_DISPLAY_EXT_ID              0x02
80 #define SEQ_SCALABLE_EXT_ID             0x05
81 #define QUANT_MATRIX_EXT_ID             0x03
82 #define COPYRIGHT_EXT_ID                0x04
83 #define PIC_DISPLAY_EXT_ID              0x07
84 #define PIC_SPATIAL_SCALABLE_EXT_ID     0x09
85 #define PIC_TEMPORAL_SCALABLE_EXT_ID    0x0A
86 #define CAMERA_PARAM_EXT_ID             0x0B
87 #define ITU_T_EXT_ID                    0x0C
88 /******************************************************************************
89 * Extension IDs Length definitions
90 *******************************************************************************/
91 #define CAMERA_PARAMETER_EXTENSION_LEN  377
92 #define COPYRIGHT_EXTENSION_LEN          88
93 #define GROUP_OF_PICTURE_LEN             59
94 
95 
96 /******************************************************************************
97 * MPEG2 Picture structure definitions
98 *******************************************************************************/
99 #define TOP_FIELD                       1
100 #define BOTTOM_FIELD                    2
101 #define FRAME_PICTURE                   3
102 
103 /******************************************************************************
104 * MPEG2 Profile definitions
105 *******************************************************************************/
106 #define MPEG2_SIMPLE_PROFILE            0x05
107 #define MPEG2_MAIN_PROFILE              0x04
108 
109 /******************************************************************************
110 * MPEG2 Level definitions
111 *******************************************************************************/
112 #define MPEG2_LOW_LEVEL                 0x0a
113 #define MPEG2_MAIN_LEVEL                0x08
114 
115 /******************************************************************************
116 * MPEG2 Prediction types
117 *******************************************************************************/
118 #define FIELD_PRED                      0
119 #define FRAME_PRED                      1
120 #define DUAL_PRED                       2
121 #define RESERVED                        -1
122 #define MC_16X8_PRED                    3
123 
124 /*****************************************************************************
125 * MPEG2 Motion vector format
126 ******************************************************************************/
127 #define FIELD_MV                        0
128 #define FRAME_MV                        1
129 
130 /******************************************************************************/
131 /* General Video related definitions                                          */
132 /******************************************************************************/
133 
134 #define BLK_SIZE 8
135 #define NUM_COEFFS ((BLK_SIZE)*(BLK_SIZE))
136 #define LUMA_BLK_SIZE (2 * (BLK_SIZE))
137 #define CHROMA_BLK_SIZE (BLK_SIZE)
138 #define  BLOCKS_IN_MB            6
139 #define  MB_SIZE                16
140 #define  MB_CHROMA_SIZE          8
141 #define  NUM_PELS_IN_BLOCK      64
142 #define  NUM_LUMA_BLKS           4
143 #define  NUM_CHROMA_BLKS         2
144 #define  MAX_COLR_COMPS          3
145 #define  Y_LUMA                  0
146 #define  U_CHROMA                1
147 #define  V_CHROMA                2
148 #define  MB_LUMA_MEM_SIZE           ((MB_SIZE) * (MB_SIZE))
149 #define  MB_CHROMA_MEM_SIZE         ((MB_SIZE/2) * (MB_SIZE/2))
150 
151 #define BITS_IN_INT     32
152 /******************************************************************************/
153 /* MPEG2 Motion compensation related definitions                              */
154 /******************************************************************************/
155 #define REF_FRM_MB_WIDTH        18
156 #define REF_FRM_MB_HEIGHT       18
157 #define REF_FLD_MB_HEIGHT       10
158 #define REF_FLD_MB_WIDTH        18
159 
160 /******************************************************************************/
161 /* Maximum number of bits per MB                                              */
162 /******************************************************************************/
163 #define I_MB_BIT_SIZE 90
164 #define P_MB_BIT_SIZE 90
165 #define B_MB_BIT_SIZE 150
166 
167 /******************************************************************************/
168 /* Aspect ratio related definitions                                           */
169 /******************************************************************************/
170 #define MPG1_NTSC_4_3       0x8
171 #define MPG1_PAL_4_3        0xc
172 #define MPG1_NTSC_16_9      0x6
173 #define MPG1_PAL_16_9       0x3
174 #define MPG1_1_1            0x1
175 
176 #define MPG2_4_3            0x2
177 #define MPG2_16_9           0x3
178 #define MPG2_1_1            0x1
179 
180 /******************************************************************************/
181 /* Inverse Quantizer Output range                                             */
182 /******************************************************************************/
183 #define IQ_OUTPUT_MAX 2047
184 #define IQ_OUTPUT_MIN -2048
185 
186 /******************************************************************************/
187 /* IDCT Output range                                                          */
188 /******************************************************************************/
189 #define IDCT_OUTPUT_MAX  255
190 #define IDCT_OUTPUT_MIN -256
191 
192 /******************************************************************************/
193 /* Output pixel range                                                         */
194 /******************************************************************************/
195 #define PEL_VALUE_MAX 255
196 #define PEL_VALUE_MIN 0
197 
198 /******************************************************************************/
199 /* inv scan types                                                             */
200 /******************************************************************************/
201 #define ZIG_ZAG_SCAN        0
202 #define VERTICAL_SCAN       1
203 
204 /******************************************************************************/
205 /* Related VLD codes                                                          */
206 /******************************************************************************/
207 #define ESC_CODE_VALUE 0x0058
208 #define EOB_CODE_VALUE 0x07d0
209 
210 #define END_OF_BLOCK                    0x01
211 #define ESCAPE_CODE                     0x06
212 
213 #define END_OF_BLOCK_ZERO               0x01ff
214 #define END_OF_BLOCK_ONE                0x01ff
215 
216 /******************** Idct Specific ***************/
217 #define TRANS_SIZE_8            8
218 #define IDCT_STG1_SHIFT        12
219 #define IDCT_STG2_SHIFT        16
220 
221 #define IDCT_STG1_ROUND        ((1 << IDCT_STG1_SHIFT) >> 1)
222 #define IDCT_STG2_ROUND        ((1 << IDCT_STG2_SHIFT) >> 1)
223 
224 
225 /******************************************************************************
226 * Sample Version Definitions
227 *******************************************************************************/
228 #define SAMPLE_VERS_MAX_FRAMES_DECODE   999
229 
230 #define MAX_FRAME_BUFFER                     7
231 
232 /* vop coding type */
233 typedef enum
234 {
235     I_PIC = 1,
236     P_PIC,
237     B_PIC,
238     D_PIC
239 } e_pic_type_t;
240 
241 typedef enum
242 {
243     MPEG_2_VIDEO,
244     MPEG_1_VIDEO
245 } e_video_type_t;
246 
247 typedef enum
248 {
249     FORW,
250     BACK,
251     BIDIRECT
252 } e_pred_direction_t;
253 
254 typedef enum
255 {
256     TOP,
257     BOTTOM
258 } e_field_t;
259 
260 /* Motion vectors (first/second) */
261 enum
262 {
263     FIRST,
264     SECOND,
265     THIRD,
266     FOURTH
267 };
268 
269 enum
270 {
271     MV_X,
272     MV_Y
273 };
274 
275 /* Enumeration defining the various kinds of interpolation possible in
276 motion compensation */
277 typedef enum
278 {
279   FULL_XFULL_Y,
280     FULL_XHALF_Y,
281     HALF_XFULL_Y,
282     HALF_XHALF_Y
283 } e_sample_type_t;
284 typedef enum
285 {
286     /* Params of the reference buffer used as input to MC */
287     /* frame prediction in P frame picture */
288     MC_FRM_FW_OR_BK_1MV,
289     /* field prediction in P frame picture */
290     MC_FRM_FW_OR_BK_2MV,
291     /* frame prediction in B frame picture */
292     MC_FRM_FW_AND_BK_2MV,
293     /* field prediction in B frame picture */
294     MC_FRM_FW_AND_BK_4MV,
295     /* dual prime prediction in P frame picture */
296     MC_FRM_FW_DUAL_PRIME_1MV,
297     /* frame prediction in P field picture */
298     MC_FLD_FW_OR_BK_1MV,
299     /* 16x8 prediction in P field picture */
300     MC_FLD_FW_OR_BK_2MV,
301     /* field prediction in B field picture */
302     MC_FLD_FW_AND_BK_2MV,
303     /* 16x8 prediction in B field picture */
304     MC_FLD_FW_AND_BK_4MV,
305     /* dual prime prediction in P field picture */
306     MC_FLD_FW_DUAL_PRIME_1MV,
307 } e_mb_type_t;
308 
309 #endif /* __IMPEG2_DEFS_H__ */
310 
311