1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* native api |
* - Native API implementation - |
5 |
* |
* |
6 |
* This program is an implementation of a part of one or more MPEG-4 |
* This program is an implementation of a part of one or more MPEG-4 |
7 |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
24 |
* |
* |
25 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
26 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
27 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
* |
* |
29 |
*************************************************************************/ |
****************************************************************************/ |
30 |
|
/***************************************************************************** |
|
/************************************************************************** |
|
31 |
* |
* |
32 |
* History: |
* History |
33 |
* |
* |
34 |
* 22.12.2001 API change: added xvid_init() - Isibaar |
* - 17.03.2002 Added interpolate8x8_halfpel_hv_xmm |
35 |
* 16.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
* - 22.12.2001 API change: added xvid_init() - Isibaar |
36 |
|
* - 16.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
37 |
* |
* |
38 |
*************************************************************************/ |
* $Id: xvid.c,v 1.18 2002-06-14 13:27:52 Isibaar Exp $ |
39 |
|
* |
40 |
|
****************************************************************************/ |
41 |
|
|
42 |
#include "xvid.h" |
#include "xvid.h" |
43 |
#include "decoder.h" |
#include "decoder.h" |
53 |
#include "motion/sad.h" |
#include "motion/sad.h" |
54 |
#include "utils/emms.h" |
#include "utils/emms.h" |
55 |
#include "utils/timer.h" |
#include "utils/timer.h" |
56 |
|
#include "bitstream/mbcoding.h" |
57 |
|
|
58 |
int xvid_init(void *handle, int opt, void *param1, void *param2) |
/***************************************************************************** |
59 |
|
* XviD Init Entry point |
60 |
|
* |
61 |
|
* Well this function initialize all internal function pointers according |
62 |
|
* to the CPU features forced by the library client or autodetected (depending |
63 |
|
* on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all |
64 |
|
* image colorspace transformation tables. |
65 |
|
* |
66 |
|
* Returned value : XVID_ERR_OK |
67 |
|
* + API_VERSION in the input XVID_INIT_PARAM structure |
68 |
|
* + core build " " " " " |
69 |
|
* |
70 |
|
****************************************************************************/ |
71 |
|
|
72 |
|
int |
73 |
|
xvid_init(void *handle, |
74 |
|
int opt, |
75 |
|
void *param1, |
76 |
|
void *param2) |
77 |
{ |
{ |
78 |
int cpu_flags; |
int cpu_flags; |
79 |
XVID_INIT_PARAM *init_param; |
XVID_INIT_PARAM *init_param; |
80 |
|
|
81 |
init_param = (XVID_INIT_PARAM *) param1; |
init_param = (XVID_INIT_PARAM *) param1; |
82 |
|
|
83 |
// force specific cpu settings? |
/* Do we have to force CPU features ? */ |
84 |
if((init_param->cpu_flags & XVID_CPU_FORCE) > 0) |
if ((init_param->cpu_flags & XVID_CPU_FORCE) > 0) { |
85 |
cpu_flags = init_param->cpu_flags; |
cpu_flags = init_param->cpu_flags; |
86 |
else { |
} else { |
87 |
|
|
88 |
#ifdef ARCH_X86 |
#ifdef ARCH_X86 |
89 |
cpu_flags = check_cpu_features(); |
cpu_flags = check_cpu_features(); |
93 |
init_param->cpu_flags = cpu_flags; |
init_param->cpu_flags = cpu_flags; |
94 |
} |
} |
95 |
|
|
96 |
// initialize the function pointers |
/* Initialize the function pointers */ |
97 |
idct_int32_init(); |
idct_int32_init(); |
98 |
|
init_vlc_tables(); |
99 |
|
|
100 |
|
/* Fixed Point Forward/Inverse DCT transformations */ |
101 |
fdct = fdct_int32; |
fdct = fdct_int32; |
102 |
idct = idct_int32; |
idct = idct_int32; |
103 |
|
|
104 |
|
/* Only needed on PPC Altivec archs */ |
105 |
|
sadInit = 0; |
106 |
|
|
107 |
|
/* Restore FPU context : emms_c is a nop functions */ |
108 |
emms = emms_c; |
emms = emms_c; |
109 |
|
|
110 |
|
/* Quantization functions */ |
111 |
quant_intra = quant_intra_c; |
quant_intra = quant_intra_c; |
112 |
dequant_intra = dequant_intra_c; |
dequant_intra = dequant_intra_c; |
113 |
quant_inter = quant_inter_c; |
quant_inter = quant_inter_c; |
118 |
quant4_inter = quant4_inter_c; |
quant4_inter = quant4_inter_c; |
119 |
dequant4_inter = dequant4_inter_c; |
dequant4_inter = dequant4_inter_c; |
120 |
|
|
121 |
|
/* Block transfer related functions */ |
122 |
transfer_8to16copy = transfer_8to16copy_c; |
transfer_8to16copy = transfer_8to16copy_c; |
123 |
transfer_16to8copy = transfer_16to8copy_c; |
transfer_16to8copy = transfer_16to8copy_c; |
124 |
transfer_8to16sub = transfer_8to16sub_c; |
transfer_8to16sub = transfer_8to16sub_c; |
125 |
|
transfer_8to16sub2 = transfer_8to16sub2_c; |
126 |
transfer_16to8add = transfer_16to8add_c; |
transfer_16to8add = transfer_16to8add_c; |
127 |
transfer8x8_copy = transfer8x8_copy_c; |
transfer8x8_copy = transfer8x8_copy_c; |
128 |
|
|
129 |
|
/* Image interpolation related functions */ |
130 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c; |
131 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c; |
132 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c; |
133 |
|
|
134 |
|
/* Initialize internal colorspace transformation tables */ |
135 |
colorspace_init(); |
colorspace_init(); |
136 |
|
|
137 |
|
/* All colorspace transformation functions User Format->YV12 */ |
138 |
rgb555_to_yv12 = rgb555_to_yv12_c; |
rgb555_to_yv12 = rgb555_to_yv12_c; |
139 |
rgb565_to_yv12 = rgb565_to_yv12_c; |
rgb565_to_yv12 = rgb565_to_yv12_c; |
140 |
rgb24_to_yv12 = rgb24_to_yv12_c; |
rgb24_to_yv12 = rgb24_to_yv12_c; |
143 |
yuyv_to_yv12 = yuyv_to_yv12_c; |
yuyv_to_yv12 = yuyv_to_yv12_c; |
144 |
uyvy_to_yv12 = uyvy_to_yv12_c; |
uyvy_to_yv12 = uyvy_to_yv12_c; |
145 |
|
|
146 |
|
/* All colorspace transformation functions YV12->User format */ |
147 |
yv12_to_rgb555 = yv12_to_rgb555_c; |
yv12_to_rgb555 = yv12_to_rgb555_c; |
148 |
yv12_to_rgb565 = yv12_to_rgb565_c; |
yv12_to_rgb565 = yv12_to_rgb565_c; |
149 |
yv12_to_rgb24 = yv12_to_rgb24_c; |
yv12_to_rgb24 = yv12_to_rgb24_c; |
152 |
yv12_to_yuyv = yv12_to_yuyv_c; |
yv12_to_yuyv = yv12_to_yuyv_c; |
153 |
yv12_to_uyvy = yv12_to_uyvy_c; |
yv12_to_uyvy = yv12_to_uyvy_c; |
154 |
|
|
155 |
|
/* Functions used in motion estimation algorithms */ |
156 |
calc_cbp = calc_cbp_c; |
calc_cbp = calc_cbp_c; |
157 |
sad16 = sad16_c; |
sad16 = sad16_c; |
158 |
|
sad16bi = sad16bi_c; |
159 |
sad8 = sad8_c; |
sad8 = sad8_c; |
160 |
dev16 = dev16_c; |
dev16 = dev16_c; |
161 |
|
|
162 |
#ifdef ARCH_X86 |
#ifdef ARCH_X86 |
163 |
if((cpu_flags & XVID_CPU_MMX) > 0) { |
if((cpu_flags & XVID_CPU_MMX) > 0) { |
164 |
|
|
165 |
|
/* Forward and Inverse Discrete Cosine Transformation functions */ |
166 |
fdct = fdct_mmx; |
fdct = fdct_mmx; |
167 |
idct = idct_mmx; |
idct = idct_mmx; |
168 |
|
|
169 |
|
/* To restore FPU context after mmx use */ |
170 |
emms = emms_mmx; |
emms = emms_mmx; |
171 |
|
|
172 |
|
/* Quantization related functions */ |
173 |
quant_intra = quant_intra_mmx; |
quant_intra = quant_intra_mmx; |
174 |
dequant_intra = dequant_intra_mmx; |
dequant_intra = dequant_intra_mmx; |
175 |
quant_inter = quant_inter_mmx; |
quant_inter = quant_inter_mmx; |
180 |
quant4_inter = quant4_inter_mmx; |
quant4_inter = quant4_inter_mmx; |
181 |
dequant4_inter = dequant4_inter_mmx; |
dequant4_inter = dequant4_inter_mmx; |
182 |
|
|
183 |
|
/* Block related functions */ |
184 |
transfer_8to16copy = transfer_8to16copy_mmx; |
transfer_8to16copy = transfer_8to16copy_mmx; |
185 |
transfer_16to8copy = transfer_16to8copy_mmx; |
transfer_16to8copy = transfer_16to8copy_mmx; |
186 |
transfer_8to16sub = transfer_8to16sub_mmx; |
transfer_8to16sub = transfer_8to16sub_mmx; |
187 |
transfer_16to8add = transfer_16to8add_mmx; |
transfer_16to8add = transfer_16to8add_mmx; |
188 |
transfer8x8_copy = transfer8x8_copy_mmx; |
transfer8x8_copy = transfer8x8_copy_mmx; |
189 |
|
|
190 |
|
/* Image Interpolation related functions */ |
191 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx; |
192 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx; |
193 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx; |
194 |
|
|
195 |
|
/* Image RGB->YV12 related functions */ |
196 |
rgb24_to_yv12 = rgb24_to_yv12_mmx; |
rgb24_to_yv12 = rgb24_to_yv12_mmx; |
197 |
rgb32_to_yv12 = rgb32_to_yv12_mmx; |
rgb32_to_yv12 = rgb32_to_yv12_mmx; |
198 |
yuv_to_yv12 = yuv_to_yv12_mmx; |
yuv_to_yv12 = yuv_to_yv12_mmx; |
199 |
yuyv_to_yv12 = yuyv_to_yv12_mmx; |
yuyv_to_yv12 = yuyv_to_yv12_mmx; |
200 |
uyvy_to_yv12 = uyvy_to_yv12_mmx; |
uyvy_to_yv12 = uyvy_to_yv12_mmx; |
201 |
|
|
202 |
|
/* Image YV12->RGB related functions */ |
203 |
yv12_to_rgb24 = yv12_to_rgb24_mmx; |
yv12_to_rgb24 = yv12_to_rgb24_mmx; |
204 |
yv12_to_rgb32 = yv12_to_rgb32_mmx; |
yv12_to_rgb32 = yv12_to_rgb32_mmx; |
205 |
yv12_to_yuyv = yv12_to_yuyv_mmx; |
yv12_to_yuyv = yv12_to_yuyv_mmx; |
206 |
yv12_to_uyvy = yv12_to_uyvy_mmx; |
yv12_to_uyvy = yv12_to_uyvy_mmx; |
207 |
|
|
208 |
|
/* Motion estimation related functions */ |
209 |
calc_cbp = calc_cbp_mmx; |
calc_cbp = calc_cbp_mmx; |
210 |
sad16 = sad16_mmx; |
sad16 = sad16_mmx; |
211 |
sad8 = sad8_mmx; |
sad8 = sad8_mmx; |
214 |
} |
} |
215 |
|
|
216 |
if((cpu_flags & XVID_CPU_MMXEXT) > 0) { |
if((cpu_flags & XVID_CPU_MMXEXT) > 0) { |
217 |
|
|
218 |
|
/* Inverse DCT */ |
219 |
idct = idct_xmm; |
idct = idct_xmm; |
220 |
|
|
221 |
|
/* Interpolation */ |
222 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm; |
223 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
224 |
|
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
225 |
|
|
226 |
|
/* Colorspace transformation */ |
227 |
yuv_to_yv12 = yuv_to_yv12_xmm; |
yuv_to_yv12 = yuv_to_yv12_xmm; |
228 |
|
|
229 |
|
/* ME functions */ |
230 |
sad16 = sad16_xmm; |
sad16 = sad16_xmm; |
231 |
sad8 = sad8_xmm; |
sad8 = sad8_xmm; |
232 |
dev16 = dev16_xmm; |
dev16 = dev16_xmm; |
234 |
} |
} |
235 |
|
|
236 |
if((cpu_flags & XVID_CPU_3DNOW) > 0) { |
if((cpu_flags & XVID_CPU_3DNOW) > 0) { |
237 |
|
|
238 |
|
/* Interpolation */ |
239 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn; |
240 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn; |
241 |
|
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn; |
242 |
|
} |
243 |
|
|
244 |
|
if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
245 |
|
#ifdef EXPERIMENTAL_SSE2_CODE |
246 |
|
|
247 |
|
/* Quantization */ |
248 |
|
quant_intra = quant_intra_sse2; |
249 |
|
dequant_intra = dequant_intra_sse2; |
250 |
|
quant_inter = quant_inter_sse2; |
251 |
|
dequant_inter = dequant_inter_sse2; |
252 |
|
|
253 |
|
/* ME */ |
254 |
|
calc_cbp = calc_cbp_sse2; |
255 |
|
sad16 = sad16_sse2; |
256 |
|
dev16 = dev16_sse2; |
257 |
|
|
258 |
|
/* Forward and Inverse DCT */ |
259 |
|
idct = idct_sse2; |
260 |
|
fdct = fdct_sse2; |
261 |
|
#endif |
262 |
} |
} |
263 |
|
|
264 |
#endif |
#endif |
265 |
|
|
266 |
// API version |
#ifdef ARCH_IA64 |
267 |
|
if ((cpu_flags & XVID_CPU_IA64) > 0) { //use assembler routines? |
268 |
|
idct_ia64_init(); |
269 |
|
fdct = fdct_ia64; |
270 |
|
idct = idct_ia64; //not yet working, crashes |
271 |
|
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64; |
272 |
|
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64; |
273 |
|
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64; |
274 |
|
sad16 = sad16_ia64; |
275 |
|
sad16bi = sad16bi_ia64; |
276 |
|
sad8 = sad8_ia64; |
277 |
|
dev16 = dev16_ia64; |
278 |
|
quant_intra = quant_intra_ia64; |
279 |
|
dequant_intra = dequant_intra_ia64; |
280 |
|
quant_inter = quant_inter_ia64; |
281 |
|
dequant_inter = dequant_inter_ia64; |
282 |
|
transfer_8to16copy = transfer_8to16copy_ia64; |
283 |
|
transfer_16to8copy = transfer_16to8copy_ia64; |
284 |
|
transfer_8to16sub = transfer_8to16sub_ia64; |
285 |
|
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
286 |
|
transfer_16to8add = transfer_16to8add_ia64; |
287 |
|
transfer8x8_copy = transfer8x8_copy_ia64; |
288 |
|
DEBUG("Using IA-64 assembler routines.\n"); |
289 |
|
} |
290 |
|
#endif |
291 |
|
|
292 |
|
#ifdef ARCH_PPC |
293 |
|
#ifdef ARCH_PPC_ALTIVEC |
294 |
|
calc_cbp = calc_cbp_altivec; |
295 |
|
fdct = fdct_altivec; |
296 |
|
idct = idct_altivec; |
297 |
|
sadInit = sadInit_altivec; |
298 |
|
sad16 = sad16_altivec; |
299 |
|
sad8 = sad8_altivec; |
300 |
|
dev16 = dev16_altivec; |
301 |
|
#else |
302 |
|
calc_cbp = calc_cbp_ppc; |
303 |
|
#endif |
304 |
|
#endif |
305 |
|
|
306 |
|
/* Inform the client the API version */ |
307 |
init_param->api_version = API_VERSION; |
init_param->api_version = API_VERSION; |
308 |
|
|
309 |
// something clever has to be done for this |
/* Inform the client the core build - unused because we're still alpha */ |
310 |
init_param->core_build = 1000; |
init_param->core_build = 1000; |
311 |
|
|
312 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
313 |
} |
} |
314 |
|
|
315 |
int xvid_decore(void * handle, int opt, void * param1, void * param2) |
/***************************************************************************** |
316 |
{ |
* XviD Native decoder entry point |
317 |
switch (opt) |
* |
318 |
|
* This function is just a wrapper to all the option cases. |
319 |
|
* |
320 |
|
* Returned values : XVID_ERR_FAIL when opt is invalid |
321 |
|
* else returns the wrapped function result |
322 |
|
* |
323 |
|
****************************************************************************/ |
324 |
|
|
325 |
|
int |
326 |
|
xvid_decore(void *handle, |
327 |
|
int opt, |
328 |
|
void *param1, |
329 |
|
void *param2) |
330 |
{ |
{ |
331 |
|
switch (opt) { |
332 |
case XVID_DEC_DECODE : |
case XVID_DEC_DECODE : |
333 |
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1); |
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1); |
334 |
|
|
344 |
} |
} |
345 |
|
|
346 |
|
|
347 |
int xvid_encore(void * handle, int opt, void * param1, void * param2) |
/***************************************************************************** |
348 |
{ |
* XviD Native encoder entry point |
349 |
switch (opt) |
* |
350 |
|
* This function is just a wrapper to all the option cases. |
351 |
|
* |
352 |
|
* Returned values : XVID_ERR_FAIL when opt is invalid |
353 |
|
* else returns the wrapped function result |
354 |
|
* |
355 |
|
****************************************************************************/ |
356 |
|
|
357 |
|
int |
358 |
|
xvid_encore(void *handle, |
359 |
|
int opt, |
360 |
|
void *param1, |
361 |
|
void *param2) |
362 |
{ |
{ |
363 |
|
switch (opt) { |
364 |
case XVID_ENC_ENCODE : |
case XVID_ENC_ENCODE : |
365 |
return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, (XVID_ENC_STATS *) param2); |
return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
366 |
|
(XVID_ENC_STATS *) param2); |
367 |
|
|
368 |
case XVID_ENC_CREATE : |
case XVID_ENC_CREATE : |
369 |
return encoder_create((XVID_ENC_PARAM *) param1); |
return encoder_create((XVID_ENC_PARAM *) param1); |