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 |
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.28 2002-07-09 01:44:44 chenm001 Exp $ |
* $Id: xvid.c,v 1.33.2.1 2002-09-23 20:36:01 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 |
* |
* |
156 |
/* Inform the client the core build - unused because we're still alpha */ |
/* Inform the client the core build - unused because we're still alpha */ |
157 |
init_param->core_build = 1000; |
init_param->core_build = 1000; |
158 |
|
|
159 |
printf("init_param->cpu_flags %x\n",init_param->cpu_flags);//NIC |
/* Do we have to force CPU features ? */ |
160 |
|
if ((init_param->cpu_flags & XVID_CPU_FORCE)) { |
161 |
|
|
162 |
|
cpu_flags = init_param->cpu_flags; |
163 |
|
|
164 |
|
} else { |
165 |
|
|
166 |
|
cpu_flags = check_cpu_features(); |
167 |
|
|
168 |
|
#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 |
175 |
|
} |
176 |
|
|
177 |
if ((init_param->cpu_flags & XVID_CPU_CHKONLY)) |
if ((init_param->cpu_flags & XVID_CPU_CHKONLY)) |
178 |
{ |
{ |
179 |
//init_param->cpu_flags = check_cpu_features();//nic |
init_param->cpu_flags = cpu_flags; |
180 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
181 |
} |
} |
182 |
|
|
|
/* Do we have to force CPU features ? */ |
|
|
if ((init_param->cpu_flags & XVID_CPU_FORCE) > 0) { |
|
|
cpu_flags = init_param->cpu_flags; |
|
|
} else { |
|
|
|
|
|
//cpu_flags = check_cpu_features();//nic |
|
183 |
init_param->cpu_flags = cpu_flags; |
init_param->cpu_flags = cpu_flags; |
184 |
} |
|
185 |
|
|
186 |
/* Initialize the function pointers */ |
/* Initialize the function pointers */ |
187 |
idct_int32_init(); |
idct_int32_init(); |
245 |
/* Functions used in motion estimation algorithms */ |
/* Functions used in motion estimation algorithms */ |
246 |
calc_cbp = calc_cbp_c; |
calc_cbp = calc_cbp_c; |
247 |
sad16 = sad16_c; |
sad16 = sad16_c; |
|
sad16bi = sad16bi_c; |
|
248 |
sad8 = sad8_c; |
sad8 = sad8_c; |
249 |
|
sad16bi = sad16bi_c; |
250 |
|
sad8bi = sad8bi_c; |
251 |
dev16 = dev16_c; |
dev16 = dev16_c; |
252 |
|
sad16v = sad16v_c; |
253 |
|
|
254 |
|
// Halfpel8_Refine = Halfpel8_Refine_c; |
255 |
|
|
256 |
#ifdef ARCH_X86 |
#ifdef ARCH_X86 |
257 |
if ((cpu_flags & XVID_CPU_MMX) > 0) { |
if ((cpu_flags & XVID_CPU_MMX) > 0) { |
305 |
calc_cbp = calc_cbp_mmx; |
calc_cbp = calc_cbp_mmx; |
306 |
sad16 = sad16_mmx; |
sad16 = sad16_mmx; |
307 |
sad8 = sad8_mmx; |
sad8 = sad8_mmx; |
308 |
|
sad16bi = sad16bi_mmx; |
309 |
|
sad8bi = sad8bi_mmx; |
310 |
dev16 = dev16_mmx; |
dev16 = dev16_mmx; |
311 |
|
|
312 |
} |
} |
313 |
|
|
314 |
|
/* these 3dnow functions are faster than mmx, but slower than xmm. */ |
315 |
|
if ((cpu_flags & XVID_CPU_3DNOW) > 0) { |
316 |
|
|
317 |
|
/* ME functions */ |
318 |
|
sad16bi = sad16bi_3dn; |
319 |
|
sad8bi = sad8bi_3dn; |
320 |
|
} |
321 |
|
|
322 |
|
|
323 |
if ((cpu_flags & XVID_CPU_MMXEXT) > 0) { |
if ((cpu_flags & XVID_CPU_MMXEXT) > 0) { |
324 |
|
|
325 |
/* Inverse DCT */ |
/* Inverse DCT */ |
330 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
331 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
332 |
|
|
333 |
|
/* Quantization */ |
334 |
|
dequant_intra = dequant_intra_xmm; |
335 |
|
dequant_inter = dequant_inter_xmm; |
336 |
|
|
337 |
/* Buffer transfer */ |
/* Buffer transfer */ |
338 |
transfer_8to16sub2 = transfer_8to16sub2_xmm; |
transfer_8to16sub2 = transfer_8to16sub2_xmm; |
339 |
|
|
343 |
/* ME functions */ |
/* ME functions */ |
344 |
sad16 = sad16_xmm; |
sad16 = sad16_xmm; |
345 |
sad8 = sad8_xmm; |
sad8 = sad8_xmm; |
346 |
|
sad16bi = sad16bi_xmm; |
347 |
|
sad8bi = sad8bi_xmm; |
348 |
dev16 = dev16_xmm; |
dev16 = dev16_xmm; |
349 |
|
sad16v = sad16v_xmm; |
350 |
|
fprintf(stderr,"sad16v=XMM\n"); |
351 |
|
|
352 |
} |
} |
353 |
|
|
362 |
if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
363 |
#ifdef EXPERIMENTAL_SSE2_CODE |
#ifdef EXPERIMENTAL_SSE2_CODE |
364 |
|
|
365 |
|
calc_cbp = calc_cbp_sse2; |
366 |
|
|
367 |
/* Quantization */ |
/* Quantization */ |
368 |
quant_intra = quant_intra_sse2; |
quant_intra = quant_intra_sse2; |
369 |
dequant_intra = dequant_intra_sse2; |
dequant_intra = dequant_intra_sse2; |
371 |
dequant_inter = dequant_inter_sse2; |
dequant_inter = dequant_inter_sse2; |
372 |
|
|
373 |
/* ME */ |
/* ME */ |
|
calc_cbp = calc_cbp_sse2; |
|
374 |
sad16 = sad16_sse2; |
sad16 = sad16_sse2; |
375 |
dev16 = dev16_sse2; |
dev16 = dev16_sse2; |
376 |
|
|
394 |
sad16bi = sad16bi_ia64; |
sad16bi = sad16bi_ia64; |
395 |
sad8 = sad8_ia64; |
sad8 = sad8_ia64; |
396 |
dev16 = dev16_ia64; |
dev16 = dev16_ia64; |
397 |
|
// Halfpel8_Refine = Halfpel8_Refine_ia64; |
398 |
quant_intra = quant_intra_ia64; |
quant_intra = quant_intra_ia64; |
399 |
dequant_intra = dequant_intra_ia64; |
dequant_intra = dequant_intra_ia64; |
400 |
quant_inter = quant_inter_ia64; |
quant_inter = quant_inter_ia64; |
447 |
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1); |
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1); |
448 |
|
|
449 |
case XVID_DEC_CREATE: |
case XVID_DEC_CREATE: |
450 |
/* *************************************************************************** |
return decoder_create((XVID_DEC_PARAM *) param1); |
|
NIC uso il secondo parametro 'param2' ma in realta` non so bene per cosa e` |
|
|
stato pensato ..... e quindi in futuro potrebbe essere un problema |
|
|
*************************************************************************** */ |
|
|
if(param2!=NULL) |
|
|
return IM1_decoder_create((XVID_DEC_PARAM *) param1,(XVID_DEC_FRAME *) param2); |
|
|
else |
|
|
return decoder_create((XVID_DEC_PARAM *) param1); //NIC commentata |
|
451 |
|
|
452 |
case XVID_DEC_DESTROY: |
case XVID_DEC_DESTROY: |
453 |
return decoder_destroy((DECODER *) handle); |
return decoder_destroy((DECODER *) handle); |