3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Native API implementation - |
* - Native API implementation - |
5 |
* |
* |
6 |
|
* Copyright(C) 2001-2002 Peter Ross <pross@cs.rmit.edu.au> |
7 |
|
* |
8 |
* 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 |
9 |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
10 |
* to use this software module in hardware or software products are |
* to use this software module in hardware or software products are |
28 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
29 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
30 |
* |
* |
|
****************************************************************************/ |
|
|
/***************************************************************************** |
|
|
* |
|
|
* History |
|
|
* |
|
|
* - 17.03.2002 Added interpolate8x8_halfpel_hv_xmm |
|
|
* - 22.12.2001 API change: added xvid_init() - Isibaar |
|
|
* - 16.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
|
|
* |
|
31 |
* $Id$ |
* $Id$ |
32 |
* |
* |
33 |
****************************************************************************/ |
****************************************************************************/ |
43 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
44 |
#include "quant/quant_h263.h" |
#include "quant/quant_h263.h" |
45 |
#include "quant/quant_mpeg4.h" |
#include "quant/quant_mpeg4.h" |
46 |
|
#include "motion/motion.h" |
47 |
#include "motion/sad.h" |
#include "motion/sad.h" |
48 |
#include "utils/emms.h" |
#include "utils/emms.h" |
49 |
#include "utils/timer.h" |
#include "utils/timer.h" |
50 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
51 |
|
|
52 |
|
#if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE) |
53 |
|
|
54 |
|
#ifdef WIN32 |
55 |
|
#include <windows.h> |
56 |
|
#else |
57 |
|
#include <signal.h> |
58 |
|
#include <setjmp.h> |
59 |
|
#endif |
60 |
|
|
61 |
|
|
62 |
|
#ifndef WIN32 |
63 |
|
|
64 |
|
static jmp_buf mark; |
65 |
|
|
66 |
|
static void |
67 |
|
sigill_handler(int signal) |
68 |
|
{ |
69 |
|
longjmp(mark, 1); |
70 |
|
} |
71 |
|
#endif |
72 |
|
|
73 |
|
|
74 |
|
/* |
75 |
|
* Calls the funcptr, and returns whether SIGILL (illegal instruction) was signalled |
76 |
|
* Return values: |
77 |
|
* -1 : could not determine |
78 |
|
* 0 : SIGILL was *not* signalled |
79 |
|
* 1 : SIGILL was signalled |
80 |
|
*/ |
81 |
|
|
82 |
|
int |
83 |
|
sigill_check(void (*func)()) |
84 |
|
{ |
85 |
|
#ifdef WIN32 |
86 |
|
_try { |
87 |
|
func(); |
88 |
|
} |
89 |
|
_except(EXCEPTION_EXECUTE_HANDLER) { |
90 |
|
|
91 |
|
if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION) |
92 |
|
return 1; |
93 |
|
} |
94 |
|
return 0; |
95 |
|
#else |
96 |
|
void * old_handler; |
97 |
|
int jmpret; |
98 |
|
|
99 |
|
|
100 |
|
old_handler = signal(SIGILL, sigill_handler); |
101 |
|
if (old_handler == SIG_ERR) |
102 |
|
{ |
103 |
|
return -1; |
104 |
|
} |
105 |
|
|
106 |
|
jmpret = setjmp(mark); |
107 |
|
if (jmpret == 0) |
108 |
|
{ |
109 |
|
func(); |
110 |
|
} |
111 |
|
|
112 |
|
signal(SIGILL, old_handler); |
113 |
|
|
114 |
|
return jmpret; |
115 |
|
#endif |
116 |
|
} |
117 |
|
#endif |
118 |
|
|
119 |
/***************************************************************************** |
/***************************************************************************** |
120 |
* XviD Init Entry point |
* XviD Init Entry point |
121 |
* |
* |
141 |
|
|
142 |
init_param = (XVID_INIT_PARAM *) param1; |
init_param = (XVID_INIT_PARAM *) param1; |
143 |
|
|
144 |
|
/* Inform the client the API version */ |
145 |
|
init_param->api_version = API_VERSION; |
146 |
|
|
147 |
|
/* Inform the client the core build - unused because we're still alpha */ |
148 |
|
init_param->core_build = 1000; |
149 |
|
|
150 |
/* Do we have to force CPU features ? */ |
/* Do we have to force CPU features ? */ |
151 |
if ((init_param->cpu_flags & XVID_CPU_FORCE) > 0) { |
if ((init_param->cpu_flags & XVID_CPU_FORCE)) { |
152 |
|
|
153 |
cpu_flags = init_param->cpu_flags; |
cpu_flags = init_param->cpu_flags; |
154 |
|
|
155 |
} else { |
} else { |
156 |
|
|
|
#ifdef ARCH_X86 |
|
157 |
cpu_flags = check_cpu_features(); |
cpu_flags = check_cpu_features(); |
158 |
#else |
|
159 |
cpu_flags = 0; |
#if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE) |
160 |
|
if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger)) |
161 |
|
cpu_flags &= ~XVID_CPU_SSE; |
162 |
|
|
163 |
|
if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger)) |
164 |
|
cpu_flags &= ~XVID_CPU_SSE2; |
165 |
#endif |
#endif |
166 |
|
} |
167 |
|
|
168 |
|
if ((init_param->cpu_flags & XVID_CPU_CHKONLY)) |
169 |
|
{ |
170 |
init_param->cpu_flags = cpu_flags; |
init_param->cpu_flags = cpu_flags; |
171 |
|
return XVID_ERR_OK; |
172 |
} |
} |
173 |
|
|
174 |
|
init_param->cpu_flags = cpu_flags; |
175 |
|
|
176 |
|
|
177 |
/* Initialize the function pointers */ |
/* Initialize the function pointers */ |
178 |
idct_int32_init(); |
idct_int32_init(); |
179 |
init_vlc_tables(); |
init_vlc_tables(); |
236 |
/* Functions used in motion estimation algorithms */ |
/* Functions used in motion estimation algorithms */ |
237 |
calc_cbp = calc_cbp_c; |
calc_cbp = calc_cbp_c; |
238 |
sad16 = sad16_c; |
sad16 = sad16_c; |
|
sad16bi = sad16bi_c; |
|
239 |
sad8 = sad8_c; |
sad8 = sad8_c; |
240 |
|
sad16bi = sad16bi_c; |
241 |
|
sad8bi = sad8bi_c; |
242 |
dev16 = dev16_c; |
dev16 = dev16_c; |
243 |
|
|
244 |
|
Halfpel8_Refine = Halfpel8_Refine_c; |
245 |
|
|
246 |
#ifdef ARCH_X86 |
#ifdef ARCH_X86 |
247 |
if ((cpu_flags & XVID_CPU_MMX) > 0) { |
if ((cpu_flags & XVID_CPU_MMX) > 0) { |
248 |
|
|
268 |
transfer_8to16copy = transfer_8to16copy_mmx; |
transfer_8to16copy = transfer_8to16copy_mmx; |
269 |
transfer_16to8copy = transfer_16to8copy_mmx; |
transfer_16to8copy = transfer_16to8copy_mmx; |
270 |
transfer_8to16sub = transfer_8to16sub_mmx; |
transfer_8to16sub = transfer_8to16sub_mmx; |
271 |
|
transfer_8to16sub2 = transfer_8to16sub2_mmx; |
272 |
transfer_16to8add = transfer_16to8add_mmx; |
transfer_16to8add = transfer_16to8add_mmx; |
273 |
transfer8x8_copy = transfer8x8_copy_mmx; |
transfer8x8_copy = transfer8x8_copy_mmx; |
274 |
|
|
275 |
|
|
276 |
/* Image Interpolation related functions */ |
/* Image Interpolation related functions */ |
277 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx; |
278 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx; |
295 |
calc_cbp = calc_cbp_mmx; |
calc_cbp = calc_cbp_mmx; |
296 |
sad16 = sad16_mmx; |
sad16 = sad16_mmx; |
297 |
sad8 = sad8_mmx; |
sad8 = sad8_mmx; |
298 |
|
sad16bi = sad16bi_mmx; |
299 |
|
sad8bi = sad8bi_mmx; |
300 |
dev16 = dev16_mmx; |
dev16 = dev16_mmx; |
301 |
|
|
302 |
} |
} |
303 |
|
|
304 |
|
/* these 3dnow functions are faster than mmx, but slower than xmm. */ |
305 |
|
if ((cpu_flags & XVID_CPU_3DNOW) > 0) { |
306 |
|
|
307 |
|
/* ME functions */ |
308 |
|
sad16bi = sad16bi_3dn; |
309 |
|
sad8bi = sad8bi_3dn; |
310 |
|
} |
311 |
|
|
312 |
|
|
313 |
if ((cpu_flags & XVID_CPU_MMXEXT) > 0) { |
if ((cpu_flags & XVID_CPU_MMXEXT) > 0) { |
314 |
|
|
315 |
/* Inverse DCT */ |
/* Inverse DCT */ |
320 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
321 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
322 |
|
|
323 |
|
/* Quantization */ |
324 |
|
dequant_intra = dequant_intra_xmm; |
325 |
|
dequant_inter = dequant_inter_xmm; |
326 |
|
|
327 |
|
/* Buffer transfer */ |
328 |
|
transfer_8to16sub2 = transfer_8to16sub2_xmm; |
329 |
|
|
330 |
/* Colorspace transformation */ |
/* Colorspace transformation */ |
331 |
yuv_to_yv12 = yuv_to_yv12_xmm; |
yuv_to_yv12 = yuv_to_yv12_xmm; |
332 |
|
|
333 |
/* ME functions */ |
/* ME functions */ |
334 |
sad16 = sad16_xmm; |
sad16 = sad16_xmm; |
335 |
sad8 = sad8_xmm; |
sad8 = sad8_xmm; |
336 |
|
sad16bi = sad16bi_xmm; |
337 |
|
sad8bi = sad8bi_xmm; |
338 |
dev16 = dev16_xmm; |
dev16 = dev16_xmm; |
339 |
|
|
340 |
} |
} |
350 |
if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
351 |
#ifdef EXPERIMENTAL_SSE2_CODE |
#ifdef EXPERIMENTAL_SSE2_CODE |
352 |
|
|
353 |
|
calc_cbp = calc_cbp_sse2; |
354 |
|
|
355 |
/* Quantization */ |
/* Quantization */ |
356 |
quant_intra = quant_intra_sse2; |
quant_intra = quant_intra_sse2; |
357 |
dequant_intra = dequant_intra_sse2; |
dequant_intra = dequant_intra_sse2; |
359 |
dequant_inter = dequant_inter_sse2; |
dequant_inter = dequant_inter_sse2; |
360 |
|
|
361 |
/* ME */ |
/* ME */ |
|
calc_cbp = calc_cbp_sse2; |
|
362 |
sad16 = sad16_sse2; |
sad16 = sad16_sse2; |
363 |
dev16 = dev16_sse2; |
dev16 = dev16_sse2; |
364 |
|
|
370 |
|
|
371 |
#endif |
#endif |
372 |
|
|
373 |
|
#ifdef ARCH_IA64 |
374 |
|
if ((cpu_flags & XVID_CPU_IA64) > 0) { //use assembler routines? |
375 |
|
idct_ia64_init(); |
376 |
|
fdct = fdct_ia64; |
377 |
|
idct = idct_ia64; //not yet working, crashes |
378 |
|
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64; |
379 |
|
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64; |
380 |
|
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64; |
381 |
|
sad16 = sad16_ia64; |
382 |
|
sad16bi = sad16bi_ia64; |
383 |
|
sad8 = sad8_ia64; |
384 |
|
dev16 = dev16_ia64; |
385 |
|
Halfpel8_Refine = Halfpel8_Refine_ia64; |
386 |
|
quant_intra = quant_intra_ia64; |
387 |
|
dequant_intra = dequant_intra_ia64; |
388 |
|
quant_inter = quant_inter_ia64; |
389 |
|
dequant_inter = dequant_inter_ia64; |
390 |
|
transfer_8to16copy = transfer_8to16copy_ia64; |
391 |
|
transfer_16to8copy = transfer_16to8copy_ia64; |
392 |
|
transfer_8to16sub = transfer_8to16sub_ia64; |
393 |
|
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
394 |
|
transfer_16to8add = transfer_16to8add_ia64; |
395 |
|
transfer8x8_copy = transfer8x8_copy_ia64; |
396 |
|
DEBUG("Using IA-64 assembler routines.\n"); |
397 |
|
} |
398 |
|
#endif |
399 |
|
|
400 |
#ifdef ARCH_PPC |
#ifdef ARCH_PPC |
401 |
#ifdef ARCH_PPC_ALTIVEC |
#ifdef ARCH_PPC_ALTIVEC |
402 |
calc_cbp = calc_cbp_altivec; |
calc_cbp = calc_cbp_altivec; |
411 |
#endif |
#endif |
412 |
#endif |
#endif |
413 |
|
|
|
/* 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; |
|
|
|
|
414 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
415 |
} |
} |
416 |
|
|