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 |
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 |
* |
* |
31 |
****************************************************************************/ |
****************************************************************************/ |
|
/***************************************************************************** |
|
|
* |
|
|
* 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> |
|
|
* |
|
|
* $Id: xvid.c,v 1.18 2002-06-14 13:27:52 Isibaar Exp $ |
|
|
* |
|
|
****************************************************************************/ |
|
32 |
|
|
33 |
#include "xvid.h" |
#include "xvid.h" |
34 |
#include "decoder.h" |
#include "decoder.h" |
41 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
42 |
#include "quant/quant_h263.h" |
#include "quant/quant_h263.h" |
43 |
#include "quant/quant_mpeg4.h" |
#include "quant/quant_mpeg4.h" |
44 |
|
#include "motion/motion.h" |
45 |
#include "motion/sad.h" |
#include "motion/sad.h" |
46 |
#include "utils/emms.h" |
#include "utils/emms.h" |
47 |
#include "utils/timer.h" |
#include "utils/timer.h" |
48 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
49 |
|
|
50 |
|
#if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE) |
51 |
|
|
52 |
|
#ifdef WIN32 |
53 |
|
#include <windows.h> |
54 |
|
#else |
55 |
|
#include <signal.h> |
56 |
|
#include <setjmp.h> |
57 |
|
#endif |
58 |
|
|
59 |
|
|
60 |
|
#ifndef WIN32 |
61 |
|
|
62 |
|
static jmp_buf mark; |
63 |
|
|
64 |
|
static void |
65 |
|
sigill_handler(int signal) |
66 |
|
{ |
67 |
|
longjmp(mark, 1); |
68 |
|
} |
69 |
|
#endif |
70 |
|
|
71 |
|
|
72 |
|
/* |
73 |
|
* Calls the funcptr, and returns whether SIGILL (illegal instruction) was signalled |
74 |
|
* Return values: |
75 |
|
* -1 : could not determine |
76 |
|
* 0 : SIGILL was *not* signalled |
77 |
|
* 1 : SIGILL was signalled |
78 |
|
*/ |
79 |
|
|
80 |
|
int |
81 |
|
sigill_check(void (*func)()) |
82 |
|
{ |
83 |
|
#ifdef WIN32 |
84 |
|
_try { |
85 |
|
func(); |
86 |
|
} |
87 |
|
_except(EXCEPTION_EXECUTE_HANDLER) { |
88 |
|
|
89 |
|
if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION) |
90 |
|
return 1; |
91 |
|
} |
92 |
|
return 0; |
93 |
|
#else |
94 |
|
void * old_handler; |
95 |
|
int jmpret; |
96 |
|
|
97 |
|
|
98 |
|
old_handler = signal(SIGILL, sigill_handler); |
99 |
|
if (old_handler == SIG_ERR) |
100 |
|
{ |
101 |
|
return -1; |
102 |
|
} |
103 |
|
|
104 |
|
jmpret = setjmp(mark); |
105 |
|
if (jmpret == 0) |
106 |
|
{ |
107 |
|
func(); |
108 |
|
} |
109 |
|
|
110 |
|
signal(SIGILL, old_handler); |
111 |
|
|
112 |
|
return jmpret; |
113 |
|
#endif |
114 |
|
} |
115 |
|
#endif |
116 |
|
|
117 |
/***************************************************************************** |
/***************************************************************************** |
118 |
* XviD Init Entry point |
* XviD Init Entry point |
119 |
* |
* |
139 |
|
|
140 |
init_param = (XVID_INIT_PARAM *) param1; |
init_param = (XVID_INIT_PARAM *) param1; |
141 |
|
|
142 |
|
/* Inform the client the API version */ |
143 |
|
init_param->api_version = API_VERSION; |
144 |
|
|
145 |
|
/* Inform the client the core build - unused because we're still alpha */ |
146 |
|
init_param->core_build = 1000; |
147 |
|
|
148 |
/* Do we have to force CPU features ? */ |
/* Do we have to force CPU features ? */ |
149 |
if ((init_param->cpu_flags & XVID_CPU_FORCE) > 0) { |
if ((init_param->cpu_flags & XVID_CPU_FORCE)) { |
150 |
|
|
151 |
cpu_flags = init_param->cpu_flags; |
cpu_flags = init_param->cpu_flags; |
152 |
|
|
153 |
} else { |
} else { |
154 |
|
|
|
#ifdef ARCH_X86 |
|
155 |
cpu_flags = check_cpu_features(); |
cpu_flags = check_cpu_features(); |
156 |
#else |
|
157 |
cpu_flags = 0; |
#if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE) |
158 |
|
if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger)) |
159 |
|
cpu_flags &= ~XVID_CPU_SSE; |
160 |
|
|
161 |
|
if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger)) |
162 |
|
cpu_flags &= ~XVID_CPU_SSE2; |
163 |
#endif |
#endif |
164 |
|
} |
165 |
|
|
166 |
|
if ((init_param->cpu_flags & XVID_CPU_CHKONLY)) |
167 |
|
{ |
168 |
init_param->cpu_flags = cpu_flags; |
init_param->cpu_flags = cpu_flags; |
169 |
|
return XVID_ERR_OK; |
170 |
} |
} |
171 |
|
|
172 |
|
init_param->cpu_flags = cpu_flags; |
173 |
|
|
174 |
|
|
175 |
/* Initialize the function pointers */ |
/* Initialize the function pointers */ |
176 |
idct_int32_init(); |
idct_int32_init(); |
177 |
init_vlc_tables(); |
init_vlc_tables(); |
234 |
/* Functions used in motion estimation algorithms */ |
/* Functions used in motion estimation algorithms */ |
235 |
calc_cbp = calc_cbp_c; |
calc_cbp = calc_cbp_c; |
236 |
sad16 = sad16_c; |
sad16 = sad16_c; |
|
sad16bi = sad16bi_c; |
|
237 |
sad8 = sad8_c; |
sad8 = sad8_c; |
238 |
|
sad16bi = sad16bi_c; |
239 |
|
sad8bi = sad8bi_c; |
240 |
dev16 = dev16_c; |
dev16 = dev16_c; |
241 |
|
|
242 |
|
Halfpel8_Refine = Halfpel8_Refine_c; |
243 |
|
|
244 |
#ifdef ARCH_X86 |
#ifdef ARCH_X86 |
245 |
if ((cpu_flags & XVID_CPU_MMX) > 0) { |
if ((cpu_flags & XVID_CPU_MMX) > 0) { |
246 |
|
|
266 |
transfer_8to16copy = transfer_8to16copy_mmx; |
transfer_8to16copy = transfer_8to16copy_mmx; |
267 |
transfer_16to8copy = transfer_16to8copy_mmx; |
transfer_16to8copy = transfer_16to8copy_mmx; |
268 |
transfer_8to16sub = transfer_8to16sub_mmx; |
transfer_8to16sub = transfer_8to16sub_mmx; |
269 |
|
transfer_8to16sub2 = transfer_8to16sub2_mmx; |
270 |
transfer_16to8add = transfer_16to8add_mmx; |
transfer_16to8add = transfer_16to8add_mmx; |
271 |
transfer8x8_copy = transfer8x8_copy_mmx; |
transfer8x8_copy = transfer8x8_copy_mmx; |
272 |
|
|
273 |
|
|
274 |
/* Image Interpolation related functions */ |
/* Image Interpolation related functions */ |
275 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx; |
276 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx; |
293 |
calc_cbp = calc_cbp_mmx; |
calc_cbp = calc_cbp_mmx; |
294 |
sad16 = sad16_mmx; |
sad16 = sad16_mmx; |
295 |
sad8 = sad8_mmx; |
sad8 = sad8_mmx; |
296 |
|
sad16bi = sad16bi_mmx; |
297 |
|
sad8bi = sad8bi_mmx; |
298 |
dev16 = dev16_mmx; |
dev16 = dev16_mmx; |
299 |
|
|
300 |
} |
} |
301 |
|
|
302 |
|
/* these 3dnow functions are faster than mmx, but slower than xmm. */ |
303 |
|
if ((cpu_flags & XVID_CPU_3DNOW) > 0) { |
304 |
|
|
305 |
|
/* ME functions */ |
306 |
|
sad16bi = sad16bi_3dn; |
307 |
|
sad8bi = sad8bi_3dn; |
308 |
|
} |
309 |
|
|
310 |
|
|
311 |
if ((cpu_flags & XVID_CPU_MMXEXT) > 0) { |
if ((cpu_flags & XVID_CPU_MMXEXT) > 0) { |
312 |
|
|
313 |
/* Inverse DCT */ |
/* Inverse DCT */ |
318 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
319 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
320 |
|
|
321 |
|
/* Quantization */ |
322 |
|
dequant_intra = dequant_intra_xmm; |
323 |
|
dequant_inter = dequant_inter_xmm; |
324 |
|
|
325 |
|
/* Buffer transfer */ |
326 |
|
transfer_8to16sub2 = transfer_8to16sub2_xmm; |
327 |
|
|
328 |
/* Colorspace transformation */ |
/* Colorspace transformation */ |
329 |
yuv_to_yv12 = yuv_to_yv12_xmm; |
yuv_to_yv12 = yuv_to_yv12_xmm; |
330 |
|
|
331 |
/* ME functions */ |
/* ME functions */ |
332 |
sad16 = sad16_xmm; |
sad16 = sad16_xmm; |
333 |
sad8 = sad8_xmm; |
sad8 = sad8_xmm; |
334 |
|
sad16bi = sad16bi_xmm; |
335 |
|
sad8bi = sad8bi_xmm; |
336 |
dev16 = dev16_xmm; |
dev16 = dev16_xmm; |
337 |
|
|
338 |
} |
} |
348 |
if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
349 |
#ifdef EXPERIMENTAL_SSE2_CODE |
#ifdef EXPERIMENTAL_SSE2_CODE |
350 |
|
|
351 |
|
calc_cbp = calc_cbp_sse2; |
352 |
|
|
353 |
/* Quantization */ |
/* Quantization */ |
354 |
quant_intra = quant_intra_sse2; |
quant_intra = quant_intra_sse2; |
355 |
dequant_intra = dequant_intra_sse2; |
dequant_intra = dequant_intra_sse2; |
357 |
dequant_inter = dequant_inter_sse2; |
dequant_inter = dequant_inter_sse2; |
358 |
|
|
359 |
/* ME */ |
/* ME */ |
|
calc_cbp = calc_cbp_sse2; |
|
360 |
sad16 = sad16_sse2; |
sad16 = sad16_sse2; |
361 |
dev16 = dev16_sse2; |
dev16 = dev16_sse2; |
362 |
|
|
380 |
sad16bi = sad16bi_ia64; |
sad16bi = sad16bi_ia64; |
381 |
sad8 = sad8_ia64; |
sad8 = sad8_ia64; |
382 |
dev16 = dev16_ia64; |
dev16 = dev16_ia64; |
383 |
|
Halfpel8_Refine = Halfpel8_Refine_ia64; |
384 |
quant_intra = quant_intra_ia64; |
quant_intra = quant_intra_ia64; |
385 |
dequant_intra = dequant_intra_ia64; |
dequant_intra = dequant_intra_ia64; |
386 |
quant_inter = quant_inter_ia64; |
quant_inter = quant_inter_ia64; |
409 |
#endif |
#endif |
410 |
#endif |
#endif |
411 |
|
|
|
/* 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; |
|
|
|
|
412 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
413 |
} |
} |
414 |
|
|
462 |
{ |
{ |
463 |
switch (opt) { |
switch (opt) { |
464 |
case XVID_ENC_ENCODE: |
case XVID_ENC_ENCODE: |
465 |
|
#ifdef BFRAMES |
466 |
|
if (((Encoder *) handle)->mbParam.max_bframes >= 0) |
467 |
|
return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
468 |
|
(XVID_ENC_STATS *) param2); |
469 |
|
else |
470 |
|
#endif |
471 |
return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
472 |
(XVID_ENC_STATS *) param2); |
(XVID_ENC_STATS *) param2); |
473 |
|
|