27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
28 |
* |
* |
29 |
****************************************************************************/ |
****************************************************************************/ |
30 |
|
|
31 |
/***************************************************************************** |
/***************************************************************************** |
32 |
* |
* |
33 |
* History |
* History |
34 |
* |
* |
35 |
|
* - 23.06.2002 added XVID_CPU_CHKONLY |
36 |
* - 17.03.2002 Added interpolate8x8_halfpel_hv_xmm |
* - 17.03.2002 Added interpolate8x8_halfpel_hv_xmm |
37 |
* - 22.12.2001 API change: added xvid_init() - Isibaar |
* - 22.12.2001 API change: added xvid_init() - Isibaar |
38 |
* - 16.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
* - 16.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
39 |
* |
* |
40 |
* $Id: xvid.c,v 1.17 2002-06-13 21:35:01 edgomez Exp $ |
* $Id: xvid.c,v 1.32 2002-07-21 23:34:08 chl Exp $ |
41 |
* |
* |
42 |
****************************************************************************/ |
****************************************************************************/ |
43 |
|
|
52 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
53 |
#include "quant/quant_h263.h" |
#include "quant/quant_h263.h" |
54 |
#include "quant/quant_mpeg4.h" |
#include "quant/quant_mpeg4.h" |
55 |
|
#include "motion/motion.h" |
56 |
#include "motion/sad.h" |
#include "motion/sad.h" |
57 |
#include "utils/emms.h" |
#include "utils/emms.h" |
58 |
#include "utils/timer.h" |
#include "utils/timer.h" |
59 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
60 |
|
|
61 |
|
#if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE) |
62 |
|
|
63 |
|
#ifdef WIN32 |
64 |
|
#include <windows.h> |
65 |
|
#else |
66 |
|
#include <signal.h> |
67 |
|
#include <setjmp.h> |
68 |
|
#endif |
69 |
|
|
70 |
|
|
71 |
|
#ifndef WIN32 |
72 |
|
|
73 |
|
static jmp_buf mark; |
74 |
|
|
75 |
|
static void |
76 |
|
sigill_handler(int signal) |
77 |
|
{ |
78 |
|
longjmp(mark, 1); |
79 |
|
} |
80 |
|
#endif |
81 |
|
|
82 |
|
|
83 |
|
/* |
84 |
|
calls the funcptr, and returns whether SIGILL (illegal instruction) was signalled |
85 |
|
return values: |
86 |
|
-1 : could not determine |
87 |
|
0 : SIGILL was *not* signalled |
88 |
|
1 : SIGILL was signalled |
89 |
|
*/ |
90 |
|
|
91 |
|
int |
92 |
|
sigill_check(void (*func)()) |
93 |
|
{ |
94 |
|
#ifdef WIN32 |
95 |
|
_try { |
96 |
|
func(); |
97 |
|
} |
98 |
|
_except(EXCEPTION_EXECUTE_HANDLER) { |
99 |
|
|
100 |
|
if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION) |
101 |
|
return 1; |
102 |
|
} |
103 |
|
return 0; |
104 |
|
#else |
105 |
|
void * old_handler; |
106 |
|
int jmpret; |
107 |
|
|
108 |
|
|
109 |
|
old_handler = signal(SIGILL, sigill_handler); |
110 |
|
if (old_handler == SIG_ERR) |
111 |
|
{ |
112 |
|
return -1; |
113 |
|
} |
114 |
|
|
115 |
|
jmpret = setjmp(mark); |
116 |
|
if (jmpret == 0) |
117 |
|
{ |
118 |
|
func(); |
119 |
|
} |
120 |
|
|
121 |
|
signal(SIGILL, old_handler); |
122 |
|
|
123 |
|
return jmpret; |
124 |
|
#endif |
125 |
|
} |
126 |
|
#endif |
127 |
|
|
128 |
/***************************************************************************** |
/***************************************************************************** |
129 |
* XviD Init Entry point |
* XviD Init Entry point |
130 |
* |
* |
150 |
|
|
151 |
init_param = (XVID_INIT_PARAM *) param1; |
init_param = (XVID_INIT_PARAM *) param1; |
152 |
|
|
153 |
|
/* Inform the client the API version */ |
154 |
|
init_param->api_version = API_VERSION; |
155 |
|
|
156 |
|
/* Inform the client the core build - unused because we're still alpha */ |
157 |
|
init_param->core_build = 1000; |
158 |
|
|
159 |
/* Do we have to force CPU features ? */ |
/* Do we have to force CPU features ? */ |
160 |
if ((init_param->cpu_flags & XVID_CPU_FORCE) > 0) { |
if ((init_param->cpu_flags & XVID_CPU_FORCE)) { |
161 |
|
|
162 |
cpu_flags = init_param->cpu_flags; |
cpu_flags = init_param->cpu_flags; |
163 |
|
|
164 |
} else { |
} else { |
165 |
|
|
|
#ifdef ARCH_X86 |
|
166 |
cpu_flags = check_cpu_features(); |
cpu_flags = check_cpu_features(); |
167 |
#else |
|
168 |
cpu_flags = 0; |
#if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE) |
169 |
|
if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger)) |
170 |
|
cpu_flags &= ~XVID_CPU_SSE; |
171 |
|
|
172 |
|
if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger)) |
173 |
|
cpu_flags &= ~XVID_CPU_SSE2; |
174 |
#endif |
#endif |
175 |
|
} |
176 |
|
|
177 |
|
if ((init_param->cpu_flags & XVID_CPU_CHKONLY)) |
178 |
|
{ |
179 |
init_param->cpu_flags = cpu_flags; |
init_param->cpu_flags = cpu_flags; |
180 |
|
return XVID_ERR_OK; |
181 |
} |
} |
182 |
|
|
183 |
|
init_param->cpu_flags = cpu_flags; |
184 |
|
|
185 |
|
|
186 |
/* Initialize the function pointers */ |
/* Initialize the function pointers */ |
187 |
idct_int32_init(); |
idct_int32_init(); |
188 |
init_vlc_tables(); |
init_vlc_tables(); |
248 |
sad16bi = sad16bi_c; |
sad16bi = sad16bi_c; |
249 |
sad8 = sad8_c; |
sad8 = sad8_c; |
250 |
dev16 = dev16_c; |
dev16 = dev16_c; |
251 |
|
sad8bi = sad8bi_c; |
252 |
|
Halfpel8_Refine = Halfpel8_Refine_c; |
253 |
|
|
254 |
#ifdef ARCH_X86 |
#ifdef ARCH_X86 |
255 |
if ((cpu_flags & XVID_CPU_MMX) > 0) { |
if ((cpu_flags & XVID_CPU_MMX) > 0) { |
276 |
transfer_8to16copy = transfer_8to16copy_mmx; |
transfer_8to16copy = transfer_8to16copy_mmx; |
277 |
transfer_16to8copy = transfer_16to8copy_mmx; |
transfer_16to8copy = transfer_16to8copy_mmx; |
278 |
transfer_8to16sub = transfer_8to16sub_mmx; |
transfer_8to16sub = transfer_8to16sub_mmx; |
279 |
|
transfer_8to16sub2 = transfer_8to16sub2_mmx; |
280 |
transfer_16to8add = transfer_16to8add_mmx; |
transfer_16to8add = transfer_16to8add_mmx; |
281 |
transfer8x8_copy = transfer8x8_copy_mmx; |
transfer8x8_copy = transfer8x8_copy_mmx; |
282 |
|
|
283 |
|
|
284 |
/* Image Interpolation related functions */ |
/* Image Interpolation related functions */ |
285 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx; |
286 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx; |
317 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
318 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
319 |
|
|
320 |
|
/* Quantization */ |
321 |
|
dequant_intra = dequant_intra_xmm; |
322 |
|
dequant_inter = dequant_inter_xmm; |
323 |
|
|
324 |
|
/* Buffer transfer */ |
325 |
|
transfer_8to16sub2 = transfer_8to16sub2_xmm; |
326 |
|
|
327 |
/* Colorspace transformation */ |
/* Colorspace transformation */ |
328 |
yuv_to_yv12 = yuv_to_yv12_xmm; |
yuv_to_yv12 = yuv_to_yv12_xmm; |
329 |
|
|
330 |
/* ME functions */ |
/* ME functions */ |
331 |
sad16 = sad16_xmm; |
sad16 = sad16_xmm; |
332 |
|
sad16bi = sad16bi_xmm; |
333 |
sad8 = sad8_xmm; |
sad8 = sad8_xmm; |
334 |
dev16 = dev16_xmm; |
dev16 = dev16_xmm; |
335 |
|
|
346 |
if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
347 |
#ifdef EXPERIMENTAL_SSE2_CODE |
#ifdef EXPERIMENTAL_SSE2_CODE |
348 |
|
|
349 |
|
calc_cbp = calc_cbp_sse2; |
350 |
|
|
351 |
/* Quantization */ |
/* Quantization */ |
352 |
quant_intra = quant_intra_sse2; |
quant_intra = quant_intra_sse2; |
353 |
dequant_intra = dequant_intra_sse2; |
dequant_intra = dequant_intra_sse2; |
355 |
dequant_inter = dequant_inter_sse2; |
dequant_inter = dequant_inter_sse2; |
356 |
|
|
357 |
/* ME */ |
/* ME */ |
|
calc_cbp = calc_cbp_sse2; |
|
358 |
sad16 = sad16_sse2; |
sad16 = sad16_sse2; |
359 |
dev16 = dev16_sse2; |
dev16 = dev16_sse2; |
360 |
|
|
366 |
|
|
367 |
#endif |
#endif |
368 |
|
|
369 |
|
#ifdef ARCH_IA64 |
370 |
|
if ((cpu_flags & XVID_CPU_IA64) > 0) { //use assembler routines? |
371 |
|
idct_ia64_init(); |
372 |
|
fdct = fdct_ia64; |
373 |
|
idct = idct_ia64; //not yet working, crashes |
374 |
|
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64; |
375 |
|
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64; |
376 |
|
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64; |
377 |
|
sad16 = sad16_ia64; |
378 |
|
sad16bi = sad16bi_ia64; |
379 |
|
sad8 = sad8_ia64; |
380 |
|
dev16 = dev16_ia64; |
381 |
|
Halfpel8_Refine = Halfpel8_Refine_ia64; |
382 |
|
quant_intra = quant_intra_ia64; |
383 |
|
dequant_intra = dequant_intra_ia64; |
384 |
|
quant_inter = quant_inter_ia64; |
385 |
|
dequant_inter = dequant_inter_ia64; |
386 |
|
transfer_8to16copy = transfer_8to16copy_ia64; |
387 |
|
transfer_16to8copy = transfer_16to8copy_ia64; |
388 |
|
transfer_8to16sub = transfer_8to16sub_ia64; |
389 |
|
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
390 |
|
transfer_16to8add = transfer_16to8add_ia64; |
391 |
|
transfer8x8_copy = transfer8x8_copy_ia64; |
392 |
|
DEBUG("Using IA-64 assembler routines.\n"); |
393 |
|
} |
394 |
|
#endif |
395 |
|
|
396 |
#ifdef ARCH_PPC |
#ifdef ARCH_PPC |
397 |
#ifdef ARCH_PPC_ALTIVEC |
#ifdef ARCH_PPC_ALTIVEC |
398 |
calc_cbp = calc_cbp_altivec; |
calc_cbp = calc_cbp_altivec; |
407 |
#endif |
#endif |
408 |
#endif |
#endif |
409 |
|
|
|
/* Inform the client the API version */ |
|
|
init_param->api_version = API_VERSION; |
|
|
|
|
|
/* Inform the client the core build - unused because we're still alpha */ |
|
|
init_param->core_build = 1000; |
|
|
|
|
410 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
411 |
} |
} |
412 |
|
|
460 |
{ |
{ |
461 |
switch (opt) { |
switch (opt) { |
462 |
case XVID_ENC_ENCODE: |
case XVID_ENC_ENCODE: |
463 |
|
#ifdef BFRAMES |
464 |
|
if (((Encoder *) handle)->mbParam.max_bframes >= 0) |
465 |
|
return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
466 |
|
(XVID_ENC_STATS *) param2); |
467 |
|
else |
468 |
|
#endif |
469 |
return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
470 |
(XVID_ENC_STATS *) param2); |
(XVID_ENC_STATS *) param2); |
471 |
|
|