summaryrefslogtreecommitdiffstats
path: root/common/impeg2_defs.h
blob: f1523f2a68a5e59dada3de89452305d0f23cf2f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/******************************************************************************
 *
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *****************************************************************************
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/

#ifndef __IMPEG2_DEFS_H__
#define __IMPEG2_DEFS_H__

#include <assert.h>

/* Decoder needs at least 4 reference buffers in order to support format conversion in a thread and
to support B pictures. Because of format conversion in a thread, codec delay is now 2 frames instead of 1.
To reduce this delay, format conversion has to wait for MB status before converting for B pictures.
To avoid this check the delay is increased to 2 and hence number of reference frames minimum is 4 */
#define NUM_INT_FRAME_BUFFERS                     4


#define MAX_WIDTH               4096
#define MAX_HEIGHT              2160

#define MIN_WIDTH               16
#define MIN_HEIGHT              16


#define MAX_FRM_SIZE            (MAX_WIDTH * MAX_HEIGHT * 2)  /* Supports only 420P and 422ILE */

#define DEC_ORDER               0

#define MAX_BITSTREAM_BUFFER_SIZE       2000 * 1024


/******************************************************************************
* MPEG2 Start code and other code definitions
*******************************************************************************/
#define START_CODE_PREFIX               0x000001
#define SEQUENCE_HEADER_CODE            0x000001B3
#define EXTENSION_START_CODE            0x000001B5
#define USER_DATA_START_CODE            0x000001B2
#define GOP_START_CODE                  0x000001B8
#define PICTURE_START_CODE              0x00000100
#define SEQUENCE_END_CODE               0x000001B7
#define RESERVED_START_CODE             0x000001B0
#define MB_ESCAPE_CODE                  0x008

/******************************************************************************
* MPEG2 Length of various codes definitions
*******************************************************************************/
#define START_CODE_LEN                  32
#define START_CODE_PREFIX_LEN           24
#define MB_ESCAPE_CODE_LEN              11
#define EXT_ID_LEN                      4
#define MB_QUANT_SCALE_CODE_LEN         5
#define MB_DCT_TYPE_LEN                 1
#define MB_MOTION_TYPE_LEN              2
#define BYTE_LEN                        8

/******************************************************************************
* MPEG1 code definitions
*******************************************************************************/
#define MB_STUFFING_CODE                0x00F

/******************************************************************************
* MPEG1 Length of various codes definitions
*******************************************************************************/
#define MB_STUFFING_CODE_LEN             11

/******************************************************************************
* MPEG2 MB definitions
*******************************************************************************/
#define MPEG2_INTRA_MB                  0x04
#define MPEG2_INTRAQ_MB                 0x44
#define MPEG2_INTER_MB                  0x28
#define MB_MOTION_BIDIRECT              0x30
#define MB_INTRA_OR_PATTERN             0x0C

/******************************************************************************
* Tools definitions
*******************************************************************************/
#define SPATIAL_SCALABILITY             0x01
#define TEMPORAL_SCALABILITY            0x03

/******************************************************************************
* Extension IDs definitions
*******************************************************************************/
#define SEQ_DISPLAY_EXT_ID              0x02
#define SEQ_SCALABLE_EXT_ID             0x05
#define QUANT_MATRIX_EXT_ID             0x03
#define COPYRIGHT_EXT_ID                0x04
#define PIC_DISPLAY_EXT_ID              0x07
#define PIC_SPATIAL_SCALABLE_EXT_ID     0x09
#define PIC_TEMPORAL_SCALABLE_EXT_ID    0x0A
#define CAMERA_PARAM_EXT_ID             0x0B
#define ITU_T_EXT_ID                    0x0C
/******************************************************************************
* Extension IDs Length definitions
*******************************************************************************/
#define CAMERA_PARAMETER_EXTENSION_LEN  377
#define COPYRIGHT_EXTENSION_LEN          88
#define GROUP_OF_PICTURE_LEN             59


/******************************************************************************
* MPEG2 Picture structure definitions
*******************************************************************************/
#define TOP_FIELD                       1
#define BOTTOM_FIELD                    2
#define FRAME_PICTURE                   3

/******************************************************************************
* MPEG2 Profile definitions
*******************************************************************************/
#define MPEG2_SIMPLE_PROFILE            0x05
#define MPEG2_MAIN_PROFILE              0x04

/******************************************************************************
* MPEG2 Level definitions
*******************************************************************************/
#define MPEG2_LOW_LEVEL                 0x0a
#define MPEG2_MAIN_LEVEL                0x08

/******************************************************************************
* MPEG2 Prediction types
*******************************************************************************/
#define FIELD_PRED                      0
#define FRAME_PRED                      1
#define DUAL_PRED                       2
#define RESERVED                        -1
#define MC_16X8_PRED                    3

/*****************************************************************************
* MPEG2 Motion vector format
******************************************************************************/
#define FIELD_MV                        0
#define FRAME_MV                        1

/******************************************************************************/
/* General Video related definitions                                          */
/******************************************************************************/

#define BLK_SIZE 8
#define NUM_COEFFS ((BLK_SIZE)*(BLK_SIZE))
#define LUMA_BLK_SIZE (2 * (BLK_SIZE))
#define CHROMA_BLK_SIZE (BLK_SIZE)
#define  BLOCKS_IN_MB            6
#define  MB_SIZE                16
#define  MB_CHROMA_SIZE          8
#define  NUM_PELS_IN_BLOCK      64
#define  NUM_LUMA_BLKS           4
#define  NUM_CHROMA_BLKS         2
#define  MAX_COLR_COMPS          3
#define  Y_LUMA                  0
#define  U_CHROMA                1
#define  V_CHROMA                2
#define  MB_LUMA_MEM_SIZE           ((MB_SIZE) * (MB_SIZE))
#define  MB_CHROMA_MEM_SIZE         ((MB_SIZE/2) * (MB_SIZE/2))

#define BITS_IN_INT     32
/******************************************************************************/
/* MPEG2 Motion compensation related definitions                              */
/******************************************************************************/
#define REF_FRM_MB_WIDTH        18
#define REF_FRM_MB_HEIGHT       18
#define REF_FLD_MB_HEIGHT       10
#define REF_FLD_MB_WIDTH        18

/******************************************************************************/
/* Maximum number of bits per MB                                              */
/******************************************************************************/
#define I_MB_BIT_SIZE 90
#define P_MB_BIT_SIZE 90
#define B_MB_BIT_SIZE 150

/******************************************************************************/
/* Aspect ratio related definitions                                           */
/******************************************************************************/
#define MPG1_NTSC_4_3       0x8
#define MPG1_PAL_4_3        0xc
#define MPG1_NTSC_16_9      0x6
#define MPG1_PAL_16_9       0x3
#define MPG1_1_1            0x1

#define MPG2_4_3            0x2
#define MPG2_16_9           0x3
#define MPG2_1_1            0x1

/******************************************************************************/
/* Inverse Quantizer Output range                                             */
/******************************************************************************/
#define IQ_OUTPUT_MAX 2047
#define IQ_OUTPUT_MIN -2048

/******************************************************************************/
/* IDCT Output range                                                          */
/******************************************************************************/
#define IDCT_OUTPUT_MAX  255
#define IDCT_OUTPUT_MIN -256

/******************************************************************************/
/* Output pixel range                                                         */
/******************************************************************************/
#define PEL_VALUE_MAX 255
#define PEL_VALUE_MIN 0

/******************************************************************************/
/* inv scan types                                                             */
/******************************************************************************/
#define ZIG_ZAG_SCAN        0
#define VERTICAL_SCAN       1

/******************************************************************************/
/* Related VLD codes                                                          */
/******************************************************************************/
#define ESC_CODE_VALUE 0x0058
#define EOB_CODE_VALUE 0x07d0

#define END_OF_BLOCK                    0x01
#define ESCAPE_CODE                     0x06

#define END_OF_BLOCK_ZERO               0x01ff
#define END_OF_BLOCK_ONE                0x01ff

/******************** Idct Specific ***************/
#define TRANS_SIZE_8            8
#define IDCT_STG1_SHIFT        12
#define IDCT_STG2_SHIFT        16

#define IDCT_STG1_ROUND        ((1 << IDCT_STG1_SHIFT) >> 1)
#define IDCT_STG2_ROUND        ((1 << IDCT_STG2_SHIFT) >> 1)


/******************************************************************************
* Sample Version Definitions
*******************************************************************************/
#define SAMPLE_VERS_MAX_FRAMES_DECODE   999

#define MAX_FRAME_BUFFER                     7

/* vop coding type */
typedef enum
{
    I_PIC = 1,
    P_PIC,
    B_PIC,
    D_PIC
} e_pic_type_t;

typedef enum
{
    MPEG_2_VIDEO,
    MPEG_1_VIDEO
} e_video_type_t;

typedef enum
{
    FORW,
    BACK,
    BIDIRECT
} e_pred_direction_t;

typedef enum
{
    TOP,
    BOTTOM
} e_field_t;

/* Motion vectors (first/second) */
enum
{
    FIRST,
    SECOND,
    THIRD,
    FOURTH
};

enum
{
    MV_X,
    MV_Y
};

/* Enumeration defining the various kinds of interpolation possible in
motion compensation */
typedef enum
{
  FULL_XFULL_Y,
    FULL_XHALF_Y,
    HALF_XFULL_Y,
    HALF_XHALF_Y
} e_sample_type_t;
typedef enum
{
    /* Params of the reference buffer used as input to MC */
    /* frame prediction in P frame picture */
    MC_FRM_FW_OR_BK_1MV,
    /* field prediction in P frame picture */
    MC_FRM_FW_OR_BK_2MV,
    /* frame prediction in B frame picture */
    MC_FRM_FW_AND_BK_2MV,
    /* field prediction in B frame picture */
    MC_FRM_FW_AND_BK_4MV,
    /* dual prime prediction in P frame picture */
    MC_FRM_FW_DUAL_PRIME_1MV,
    /* frame prediction in P field picture */
    MC_FLD_FW_OR_BK_1MV,
    /* 16x8 prediction in P field picture */
    MC_FLD_FW_OR_BK_2MV,
    /* field prediction in B field picture */
    MC_FLD_FW_AND_BK_2MV,
    /* 16x8 prediction in B field picture */
    MC_FLD_FW_AND_BK_4MV,
    /* dual prime prediction in P field picture */
    MC_FLD_FW_DUAL_PRIME_1MV,
} e_mb_type_t;

#endif /* __IMPEG2_DEFS_H__ */