1 |
/***************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Global structures, constants - |
* - Global definitions - |
5 |
* |
* |
6 |
* Copyright(C) 2002 Michael Militzer <isibaar@xvid.org> |
* Copyright(C) 2002-2010 Michael Militzer <michael@xvid.org> |
7 |
* |
* |
8 |
* This file is part of XviD, a free MPEG-4 video encoder/decoder |
* This program is free software ; you can redistribute it and/or modify |
9 |
* |
* it under the terms of the GNU General Public License as published by |
|
* XviD is free software; you can redistribute it and/or modify it |
|
|
* under the terms of the GNU General Public License as published by |
|
10 |
* the Free Software Foundation; either version 2 of the License, or |
* the Free Software Foundation; either version 2 of the License, or |
11 |
* (at your option) any later version. |
* (at your option) any later version. |
12 |
* |
* |
19 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
* |
* |
22 |
* Under section 8 of the GNU General Public License, the copyright |
* $Id: global.h,v 1.27 2010-11-28 15:18:21 Isibaar Exp $ |
|
* holders of XVID explicitly forbid distribution in the following |
|
|
* countries: |
|
|
* |
|
|
* - Japan |
|
|
* - United States of America |
|
|
* |
|
|
* Linking XviD statically or dynamically with other modules is making a |
|
|
* combined work based on XviD. Thus, the terms and conditions of the |
|
|
* GNU General Public License cover the whole combination. |
|
|
* |
|
|
* As a special exception, the copyright holders of XviD give you |
|
|
* permission to link XviD with independent modules that communicate with |
|
|
* XviD solely through the VFW1.1 and DShow interfaces, regardless of the |
|
|
* license terms of these independent modules, and to copy and distribute |
|
|
* the resulting combined work under terms of your choice, provided that |
|
|
* every copy of the combined work is accompanied by a complete copy of |
|
|
* the source code of XviD (the version of XviD used to produce the |
|
|
* combined work), being distributed under the terms of the GNU General |
|
|
* Public License plus this exception. An independent module is a module |
|
|
* which is not derived from or based on XviD. |
|
|
* |
|
|
* Note that people who make modified versions of XviD are not obligated |
|
|
* to grant this special exception for their modified versions; it is |
|
|
* their choice whether to do so. The GNU General Public License gives |
|
|
* permission to release a modified version without this exception; this |
|
|
* exception also makes it possible to release a modified version which |
|
|
* carries forward this exception. |
|
|
* |
|
|
* $Id: global.h,v 1.18 2002-12-15 01:21:12 edgomez Exp $ |
|
23 |
* |
* |
24 |
****************************************************************************/ |
****************************************************************************/ |
25 |
|
|
36 |
#define MODE_INTER4V 2 |
#define MODE_INTER4V 2 |
37 |
#define MODE_INTRA 3 |
#define MODE_INTRA 3 |
38 |
#define MODE_INTRA_Q 4 |
#define MODE_INTRA_Q 4 |
|
#define MODE_STUFFING 7 |
|
39 |
#define MODE_NOT_CODED 16 |
#define MODE_NOT_CODED 16 |
40 |
|
#define MODE_NOT_CODED_GMC 17 |
41 |
|
|
42 |
/* --- bframe specific --- */ |
/* --- bframe specific --- */ |
43 |
|
|
46 |
#define MODE_BACKWARD 2 |
#define MODE_BACKWARD 2 |
47 |
#define MODE_FORWARD 3 |
#define MODE_FORWARD 3 |
48 |
#define MODE_DIRECT_NONE_MV 4 |
#define MODE_DIRECT_NONE_MV 4 |
49 |
|
#define MODE_DIRECT_NO4V 5 |
50 |
|
|
51 |
|
/* |
52 |
|
* vop coding types |
53 |
|
* intra, prediction, backward, sprite, not_coded |
54 |
|
*/ |
55 |
|
#define I_VOP 0 |
56 |
|
#define P_VOP 1 |
57 |
|
#define B_VOP 2 |
58 |
|
#define S_VOP 3 |
59 |
|
#define N_VOP 4 |
60 |
|
|
61 |
|
/* convert mpeg-4 coding type i/p/b/s_VOP to XVID_TYPE_xxx */ |
62 |
|
static __inline int |
63 |
|
coding2type(int coding_type) |
64 |
|
{ |
65 |
|
return coding_type + 1; |
66 |
|
} |
67 |
|
|
68 |
|
/* convert XVID_TYPE_xxx to bitstream coding type i/p/b/s_VOP */ |
69 |
|
static __inline int |
70 |
|
type2coding(int xvid_type) |
71 |
|
{ |
72 |
|
return xvid_type - 1; |
73 |
|
} |
74 |
|
|
75 |
|
typedef struct |
76 |
|
{ |
77 |
|
int x; |
78 |
|
int y; |
79 |
|
} |
80 |
|
VECTOR; |
81 |
|
|
82 |
|
typedef struct |
83 |
|
{ |
84 |
|
VECTOR duv[3]; |
85 |
|
} |
86 |
|
WARPPOINTS; |
87 |
|
|
88 |
|
/* save all warping parameters for GMC once and for all, instead of |
89 |
|
recalculating for every block. This is needed for encoding&decoding |
90 |
|
When switching to incremental calculations, this will get much shorter |
91 |
|
*/ |
92 |
|
|
93 |
|
/* we don't include WARPPOINTS wp here, but in FRAMEINFO itself */ |
94 |
|
|
95 |
|
typedef struct |
96 |
|
{ |
97 |
|
int num_wp; /* [input]: 0=none, 1=translation, 2,3 = warping */ |
98 |
|
/* a value of -1 means: "structure not initialized!" */ |
99 |
|
int s; /* [input]: calc is done with 1/s pel resolution */ |
100 |
|
|
101 |
|
int W; |
102 |
|
int H; |
103 |
|
|
104 |
|
int ss; |
105 |
|
int smask; |
106 |
|
int sigma; |
107 |
|
|
108 |
|
int r; |
109 |
|
int rho; |
110 |
|
|
111 |
|
int i0s; |
112 |
|
int j0s; |
113 |
|
int i1s; |
114 |
|
int j1s; |
115 |
|
int i2s; |
116 |
|
int j2s; |
117 |
|
|
118 |
|
int i1ss; |
119 |
|
int j1ss; |
120 |
|
int i2ss; |
121 |
|
int j2ss; |
122 |
|
|
123 |
|
int alpha; |
124 |
|
int beta; |
125 |
|
int Ws; |
126 |
|
int Hs; |
127 |
|
|
128 |
|
int dxF, dyF, dxG, dyG; |
129 |
|
int Fo, Go; |
130 |
|
int cFo, cGo; |
131 |
|
} GMC_DATA; |
132 |
|
|
133 |
|
typedef struct _NEW_GMC_DATA |
134 |
|
{ |
135 |
|
/* 0=none, 1=translation, 2,3 = warping |
136 |
|
* a value of -1 means: "structure not initialized!" */ |
137 |
|
int num_wp; |
138 |
|
|
139 |
|
/* {0,1,2,3} => {1/2,1/4,1/8,1/16} pel */ |
140 |
|
int accuracy; |
141 |
|
|
142 |
|
/* sprite size * 16 */ |
143 |
|
int sW, sH; |
144 |
|
|
145 |
|
/* gradient, calculated from warp points */ |
146 |
|
int dU[2], dV[2], Uo, Vo, Uco, Vco; |
147 |
|
|
148 |
|
void (*predict_16x16)(const struct _NEW_GMC_DATA * const This, |
149 |
|
uint8_t *dst, const uint8_t *src, |
150 |
|
int dststride, int srcstride, int x, int y, int rounding); |
151 |
|
void (*predict_8x8) (const struct _NEW_GMC_DATA * const This, |
152 |
|
uint8_t *uDst, const uint8_t *uSrc, |
153 |
|
uint8_t *vDst, const uint8_t *vSrc, |
154 |
|
int dststride, int srcstride, int x, int y, int rounding); |
155 |
|
void (*get_average_mv)(const struct _NEW_GMC_DATA * const Dsp, VECTOR * const mv, |
156 |
|
int x, int y, int qpel); |
157 |
|
} NEW_GMC_DATA; |
158 |
|
|
159 |
|
typedef struct |
160 |
|
{ |
161 |
|
uint8_t *y; |
162 |
|
uint8_t *u; |
163 |
|
uint8_t *v; |
164 |
|
} |
165 |
|
IMAGE; |
166 |
|
|
167 |
typedef struct |
typedef struct |
168 |
{ |
{ |
173 |
uint32_t *tail; |
uint32_t *tail; |
174 |
uint32_t *start; |
uint32_t *start; |
175 |
uint32_t length; |
uint32_t length; |
176 |
|
uint32_t initpos; |
177 |
} |
} |
178 |
Bitstream; |
Bitstream; |
179 |
|
|
|
|
|
180 |
#define MBPRED_SIZE 15 |
#define MBPRED_SIZE 15 |
181 |
|
|
|
|
|
182 |
typedef struct |
typedef struct |
183 |
{ |
{ |
184 |
/* decoder/encoder */ |
/* decoder/encoder */ |
197 |
|
|
198 |
/* encoder specific */ |
/* encoder specific */ |
199 |
|
|
|
VECTOR mv16; |
|
200 |
VECTOR pmvs[4]; |
VECTOR pmvs[4]; |
201 |
|
VECTOR qmvs[4]; /* mvs in quarter pixel resolution */ |
202 |
|
|
203 |
int32_t sad8[4]; /* SAD values for inter4v-VECTORs */ |
int32_t sad8[4]; /* SAD values for inter4v-VECTORs */ |
204 |
int32_t sad16; /* SAD value for inter-VECTOR */ |
int32_t sad16; /* SAD value for inter-VECTOR */ |
205 |
|
|
206 |
|
int32_t var16; /* Variance of the 16x16 luma block */ |
207 |
|
int32_t rel_var8[6]; /* Relative variances of the 8x8 sub-blocks */ |
208 |
|
|
209 |
int dquant; |
int dquant; |
210 |
int cbp; |
int cbp; |
211 |
|
|
212 |
|
/* lambda for these blocks */ |
213 |
|
int lambda[6]; |
214 |
|
|
215 |
/* bframe stuff */ |
/* bframe stuff */ |
216 |
|
|
217 |
VECTOR b_mvs[4]; |
VECTOR b_mvs[4]; |
218 |
VECTOR b_pmvs[4]; |
VECTOR b_qmvs[4]; |
|
|
|
|
/* bframe direct mode */ |
|
|
|
|
|
VECTOR directmv[4]; |
|
|
VECTOR deltamv; |
|
|
|
|
|
int mb_type; |
|
|
int dbquant; |
|
219 |
|
|
220 |
/* stuff for block based ME (needed for Qpel ME) */ |
VECTOR amv; /* average motion vectors from GMC */ |
221 |
/* backup of last integer ME vectors/sad */ |
int32_t mcsel; |
222 |
|
|
223 |
VECTOR i_mv16; |
VECTOR mvs_avg; //CK average of field motion vectors |
|
VECTOR i_mvs[4]; |
|
224 |
|
|
225 |
int32_t i_sad8[4]; /* SAD values for inter4v-VECTORs */ |
/* This structure has become way to big! What to do? Split it up? */ |
|
int32_t i_sad16; /* SAD value for inter-VECTOR */ |
|
226 |
|
|
227 |
} |
} |
228 |
MACROBLOCK; |
MACROBLOCK; |
229 |
|
|
230 |
static __inline int8_t |
static __inline uint32_t |
231 |
get_dc_scaler(uint32_t quant, |
get_dc_scaler(uint32_t quant, |
232 |
uint32_t lum) |
uint32_t lum) |
233 |
{ |
{ |
235 |
return 8; |
return 8; |
236 |
|
|
237 |
if (quant < 25 && !lum) |
if (quant < 25 && !lum) |
238 |
return (int8_t)((quant + 13) / 2); |
return (quant + 13) / 2; |
239 |
|
|
240 |
if (quant < 9) |
if (quant < 9) |
241 |
return (int8_t)(2 * quant); |
return 2 * quant; |
242 |
|
|
243 |
if (quant < 25) |
if (quant < 25) |
244 |
return (int8_t)(quant + 8); |
return quant + 8; |
245 |
|
|
246 |
if (lum) |
if (lum) |
247 |
return (int8_t)(2 * quant - 16); |
return 2 * quant - 16; |
248 |
else |
else |
249 |
return (int8_t)(quant - 6); |
return quant - 6; |
250 |
} |
} |
251 |
|
|
252 |
/* useful macros */ |
/* useful macros */ |
253 |
|
|
254 |
#define MIN(X, Y) ((X)<(Y)?(X):(Y)) |
#define MIN(X, Y) ((X)<(Y)?(X):(Y)) |
255 |
#define MAX(X, Y) ((X)>(Y)?(X):(Y)) |
#define MAX(X, Y) ((X)>(Y)?(X):(Y)) |
256 |
#define ABS(X) (((X)>0)?(X):-(X)) |
/* #define ABS(X) (((X)>0)?(X):-(X)) */ |
257 |
#define SIGN(X) (((X)>0)?1:-1) |
#define SIGN(X) (((X)>0)?1:-1) |
258 |
|
#define CLIP(X,AMIN,AMAX) (((X)<(AMIN)) ? (AMIN) : ((X)>(AMAX)) ? (AMAX) : (X)) |
259 |
|
#define DIV_DIV(a,b) (((a)>0) ? ((a)+((b)>>1))/(b) : ((a)-((b)>>1))/(b)) |
260 |
|
#define SWAP(_T_,A,B) { _T_ tmp = A; A = B; B = tmp; } |
261 |
|
|
262 |
|
static __inline uint32_t |
263 |
|
isqrt(unsigned long n) |
264 |
|
{ |
265 |
|
uint32_t c = 0x8000; |
266 |
|
uint32_t g = 0x8000; |
267 |
|
|
268 |
|
for(;;) { |
269 |
|
if(g*g > n) |
270 |
|
g ^= c; |
271 |
|
c >>= 1; |
272 |
|
if(c == 0) |
273 |
|
return g; |
274 |
|
g |= c; |
275 |
|
} |
276 |
|
} |
277 |
|
|
278 |
#endif /* _GLOBAL_H_ */ |
#endif /* _GLOBAL_H_ */ |