3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Native API implementation - |
* - Native API implementation - |
5 |
* |
* |
6 |
* This program is an implementation of a part of one or more MPEG-4 |
* Copyright(C) 2001-2003 Peter Ross <pross@xvid.org> |
|
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
|
|
* to use this software module in hardware or software products are |
|
|
* advised that its use may infringe existing patents or copyrights, and |
|
|
* any such use would be at such party's own risk. The original |
|
|
* developer of this software module and his/her company, and subsequent |
|
|
* editors and their companies, will have no liability for use of this |
|
|
* software or modifications or derivatives thereof. |
|
7 |
* |
* |
8 |
* This program is free software ; you can redistribute it and/or modify |
* This program is free software ; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
19 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
* |
* |
|
****************************************************************************/ |
|
|
|
|
|
/***************************************************************************** |
|
|
* |
|
|
* History |
|
|
* |
|
|
* - 23.06.2002 added XVID_CPU_CHKONLY |
|
|
* - 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> |
|
|
* |
|
22 |
* $Id$ |
* $Id$ |
23 |
* |
* |
24 |
****************************************************************************/ |
****************************************************************************/ |
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 |
|
#include "image/qpel.h" |
50 |
|
|
51 |
|
#if defined(_DEBUG) |
52 |
|
unsigned int xvid_debug = 0; /* xvid debug mask */ |
53 |
|
#endif |
54 |
|
|
55 |
#if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE) |
#if defined(ARCH_IS_IA32) |
56 |
|
|
57 |
#ifdef WIN32 |
#if defined(_MSC_VER) |
58 |
#include <windows.h> |
#include <windows.h> |
59 |
#else |
#else |
60 |
#include <signal.h> |
#include <signal.h> |
61 |
#include <setjmp.h> |
#include <setjmp.h> |
|
#endif |
|
|
|
|
|
|
|
|
#ifndef WIN32 |
|
62 |
|
|
63 |
static jmp_buf mark; |
static jmp_buf mark; |
64 |
|
|
71 |
|
|
72 |
|
|
73 |
/* |
/* |
74 |
calls the funcptr, and returns whether SIGILL (illegal instruction) was signalled |
* Calls the funcptr, and returns whether SIGILL (illegal instruction) was |
75 |
return values: |
* signalled |
76 |
-1 : could not determine |
* |
77 |
0 : SIGILL was *not* signalled |
* Return values: |
78 |
1 : SIGILL was signalled |
* -1 : could not determine |
79 |
|
* 0 : SIGILL was *not* signalled |
80 |
|
* 1 : SIGILL was signalled |
81 |
*/ |
*/ |
82 |
|
|
83 |
int |
int |
84 |
sigill_check(void (*func)()) |
sigill_check(void (*func)()) |
85 |
{ |
{ |
86 |
#ifdef WIN32 |
#if defined(_MSC_VER) |
87 |
_try { |
_try { |
88 |
func(); |
func(); |
89 |
} |
} |
117 |
} |
} |
118 |
#endif |
#endif |
119 |
|
|
120 |
|
|
121 |
|
/* detect cpu flags */ |
122 |
|
static unsigned int |
123 |
|
detect_cpu_flags() |
124 |
|
{ |
125 |
|
/* enable native assembly optimizations by default */ |
126 |
|
unsigned int cpu_flags = XVID_CPU_ASM; |
127 |
|
|
128 |
|
#if defined(ARCH_IS_IA32) |
129 |
|
cpu_flags |= check_cpu_features(); |
130 |
|
if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger)) |
131 |
|
cpu_flags &= ~XVID_CPU_SSE; |
132 |
|
|
133 |
|
if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger)) |
134 |
|
cpu_flags &= ~XVID_CPU_SSE2; |
135 |
|
#endif |
136 |
|
|
137 |
|
#if defined(ARCH_IS_PPC) |
138 |
|
#if defined(ARCH_IS_PPC_ALTIVEC) |
139 |
|
cpu_flags |= XVID_CPU_ALTIVEC; |
140 |
|
#endif |
141 |
|
#endif |
142 |
|
|
143 |
|
return cpu_flags; |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
/***************************************************************************** |
/***************************************************************************** |
148 |
* XviD Init Entry point |
* XviD Init Entry point |
149 |
* |
* |
160 |
|
|
161 |
|
|
162 |
static |
static |
163 |
int xvid_init_init(XVID_INIT_PARAM * init_param) |
int xvid_gbl_init(xvid_gbl_init_t * init) |
|
{ |
|
|
int cpu_flags; |
|
|
|
|
|
/* 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; |
|
|
|
|
|
/* Do we have to force CPU features ? */ |
|
|
if ((init_param->cpu_flags & XVID_CPU_FORCE)) { |
|
|
|
|
|
cpu_flags = init_param->cpu_flags; |
|
|
|
|
|
} else { |
|
|
|
|
|
cpu_flags = check_cpu_features(); |
|
|
|
|
|
#if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE) |
|
|
if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger)) |
|
|
cpu_flags &= ~XVID_CPU_SSE; |
|
|
|
|
|
if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger)) |
|
|
cpu_flags &= ~XVID_CPU_SSE2; |
|
|
#endif |
|
|
} |
|
|
|
|
|
if ((init_param->cpu_flags & XVID_CPU_CHKONLY)) |
|
164 |
{ |
{ |
165 |
init_param->cpu_flags = cpu_flags; |
unsigned int cpu_flags; |
|
return XVID_ERR_OK; |
|
|
} |
|
166 |
|
|
167 |
init_param->cpu_flags = cpu_flags; |
if (XVID_VERSION_MAJOR(init->version) != 1) /* v1.x.x */ |
168 |
|
return XVID_ERR_VERSION; |
169 |
|
|
170 |
|
cpu_flags = (init->cpu_flags & XVID_CPU_FORCE) ? init->cpu_flags : detect_cpu_flags(); |
171 |
|
|
172 |
/* Initialize the function pointers */ |
/* Initialize the function pointers */ |
173 |
idct_int32_init(); |
idct_int32_init(); |
183 |
/* Restore FPU context : emms_c is a nop functions */ |
/* Restore FPU context : emms_c is a nop functions */ |
184 |
emms = emms_c; |
emms = emms_c; |
185 |
|
|
186 |
|
/* Qpel stuff */ |
187 |
|
xvid_QP_Funcs = &xvid_QP_Funcs_C; |
188 |
|
xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_C; |
189 |
|
xvid_Init_QP(); |
190 |
|
|
191 |
/* Quantization functions */ |
/* Quantization functions */ |
192 |
quant_intra = quant_intra_c; |
quant_intra = quant_intra_c; |
193 |
dequant_intra = dequant_intra_c; |
dequant_intra = dequant_intra_c; |
203 |
transfer_8to16copy = transfer_8to16copy_c; |
transfer_8to16copy = transfer_8to16copy_c; |
204 |
transfer_16to8copy = transfer_16to8copy_c; |
transfer_16to8copy = transfer_16to8copy_c; |
205 |
transfer_8to16sub = transfer_8to16sub_c; |
transfer_8to16sub = transfer_8to16sub_c; |
206 |
|
transfer_8to16subro = transfer_8to16subro_c; |
207 |
transfer_8to16sub2 = transfer_8to16sub2_c; |
transfer_8to16sub2 = transfer_8to16sub2_c; |
208 |
transfer_16to8add = transfer_16to8add_c; |
transfer_16to8add = transfer_16to8add_c; |
209 |
transfer8x8_copy = transfer8x8_copy_c; |
transfer8x8_copy = transfer8x8_copy_c; |
231 |
interpolate8x8_avg4 = interpolate8x8_avg4_c; |
interpolate8x8_avg4 = interpolate8x8_avg4_c; |
232 |
|
|
233 |
/* reduced resoltuion */ |
/* reduced resoltuion */ |
|
|
|
234 |
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C; |
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C; |
235 |
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C; |
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C; |
|
#ifdef ARCH_X86 |
|
|
vfilter_31 = xvid_VFilter_31_x86; |
|
|
hfilter_31 = xvid_HFilter_31_x86; |
|
|
#else |
|
236 |
vfilter_31 = xvid_VFilter_31_C; |
vfilter_31 = xvid_VFilter_31_C; |
237 |
hfilter_31 = xvid_HFilter_31_C; |
hfilter_31 = xvid_HFilter_31_C; |
|
#endif |
|
238 |
filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C; |
filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C; |
239 |
filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C; |
filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C; |
240 |
|
|
290 |
dev16 = dev16_c; |
dev16 = dev16_c; |
291 |
sad16v = sad16v_c; |
sad16v = sad16v_c; |
292 |
|
|
293 |
// Halfpel8_Refine = Halfpel8_Refine_c; |
/* Halfpel8_Refine = Halfpel8_Refine_c; */ |
294 |
|
|
295 |
#ifdef ARCH_X86 |
#if defined(ARCH_IS_IA32) |
296 |
|
|
297 |
|
if ((cpu_flags & XVID_CPU_ASM)) { |
298 |
|
vfilter_31 = xvid_VFilter_31_x86; |
299 |
|
hfilter_31 = xvid_HFilter_31_x86; |
300 |
|
} |
301 |
|
|
302 |
if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) || |
if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) || |
303 |
(cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) || |
(cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) || |
307 |
emms = emms_mmx; |
emms = emms_mmx; |
308 |
} |
} |
309 |
|
|
310 |
if ((cpu_flags & XVID_CPU_MMX) > 0) { |
if ((cpu_flags & XVID_CPU_MMX)) { |
311 |
|
|
312 |
/* Forward and Inverse Discrete Cosine Transformation functions */ |
/* Forward and Inverse Discrete Cosine Transformation functions */ |
313 |
fdct = fdct_mmx; |
fdct = fdct_mmx; |
314 |
idct = idct_mmx; |
idct = idct_mmx; |
315 |
|
|
316 |
|
/* Qpel stuff */ |
317 |
|
xvid_QP_Funcs = &xvid_QP_Funcs_mmx; |
318 |
|
xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_mmx; |
319 |
|
|
320 |
/* Quantization related functions */ |
/* Quantization related functions */ |
321 |
quant_intra = quant_intra_mmx; |
quant_intra = quant_intra_mmx; |
322 |
dequant_intra = dequant_intra_mmx; |
dequant_intra = dequant_intra_mmx; |
332 |
transfer_8to16copy = transfer_8to16copy_mmx; |
transfer_8to16copy = transfer_8to16copy_mmx; |
333 |
transfer_16to8copy = transfer_16to8copy_mmx; |
transfer_16to8copy = transfer_16to8copy_mmx; |
334 |
transfer_8to16sub = transfer_8to16sub_mmx; |
transfer_8to16sub = transfer_8to16sub_mmx; |
335 |
|
transfer_8to16subro = transfer_8to16subro_mmx; |
336 |
transfer_8to16sub2 = transfer_8to16sub2_mmx; |
transfer_8to16sub2 = transfer_8to16sub2_mmx; |
337 |
transfer_16to8add = transfer_16to8add_mmx; |
transfer_16to8add = transfer_16to8add_mmx; |
338 |
transfer8x8_copy = transfer8x8_copy_mmx; |
transfer8x8_copy = transfer8x8_copy_mmx; |
382 |
sad8bi = sad8bi_mmx; |
sad8bi = sad8bi_mmx; |
383 |
dev16 = dev16_mmx; |
dev16 = dev16_mmx; |
384 |
sad16v = sad16v_mmx; |
sad16v = sad16v_mmx; |
|
|
|
385 |
} |
} |
386 |
|
|
387 |
/* these 3dnow functions are faster than mmx, but slower than xmm. */ |
/* these 3dnow functions are faster than mmx, but slower than xmm. */ |
388 |
if ((cpu_flags & XVID_CPU_3DNOW) > 0) { |
if ((cpu_flags & XVID_CPU_3DNOW)) { |
389 |
|
|
390 |
|
emms = emms_3dn; |
391 |
|
|
392 |
/* ME functions */ |
/* ME functions */ |
393 |
sad16bi = sad16bi_3dn; |
sad16bi = sad16bi_3dn; |
398 |
} |
} |
399 |
|
|
400 |
|
|
401 |
if ((cpu_flags & XVID_CPU_MMXEXT) > 0) { |
if ((cpu_flags & XVID_CPU_MMXEXT)) { |
402 |
|
|
403 |
/* Inverse DCT */ |
/* Inverse DCT */ |
404 |
idct = idct_xmm; |
idct = idct_xmm; |
436 |
sad16v = sad16v_xmm; |
sad16v = sad16v_xmm; |
437 |
} |
} |
438 |
|
|
439 |
if ((cpu_flags & XVID_CPU_3DNOW) > 0) { |
if ((cpu_flags & XVID_CPU_3DNOW)) { |
440 |
|
|
441 |
/* Interpolation */ |
/* Interpolation */ |
442 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn; |
444 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn; |
445 |
} |
} |
446 |
|
|
447 |
if ((cpu_flags & XVID_CPU_3DNOWEXT) > 0) { |
if ((cpu_flags & XVID_CPU_3DNOWEXT)) { |
448 |
|
|
449 |
/* Inverse DCT */ |
/* Inverse DCT */ |
450 |
idct = idct_3dne; |
idct = idct_3dne; |
453 |
transfer_8to16copy = transfer_8to16copy_3dne; |
transfer_8to16copy = transfer_8to16copy_3dne; |
454 |
transfer_16to8copy = transfer_16to8copy_3dne; |
transfer_16to8copy = transfer_16to8copy_3dne; |
455 |
transfer_8to16sub = transfer_8to16sub_3dne; |
transfer_8to16sub = transfer_8to16sub_3dne; |
456 |
|
transfer_8to16subro = transfer_8to16subro_3dne; |
457 |
transfer_8to16sub2 = transfer_8to16sub2_3dne; |
transfer_8to16sub2 = transfer_8to16sub2_3dne; |
458 |
transfer_16to8add = transfer_16to8add_3dne; |
transfer_16to8add = transfer_16to8add_3dne; |
459 |
transfer8x8_copy = transfer8x8_copy_3dne; |
transfer8x8_copy = transfer8x8_copy_3dne; |
480 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dne; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dne; |
481 |
} |
} |
482 |
|
|
483 |
|
#if defined(EXPERIMENTAL_SSE2_CODE) /* mark the whole SSE2 stuff as experimental. At least on |
484 |
if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
my P4, it crashes... */ |
485 |
#ifdef EXPERIMENTAL_SSE2_CODE |
if ((cpu_flags & XVID_CPU_SSE2)) { |
486 |
|
|
487 |
calc_cbp = calc_cbp_sse2; |
calc_cbp = calc_cbp_sse2; |
488 |
|
|
492 |
quant_inter = quant_inter_sse2; |
quant_inter = quant_inter_sse2; |
493 |
dequant_inter = dequant_inter_sse2; |
dequant_inter = dequant_inter_sse2; |
494 |
|
|
495 |
/* ME */ |
/* ME; slower than xmm */ |
496 |
sad16 = sad16_sse2; |
sad16 = sad16_sse2; |
497 |
dev16 = dev16_sse2; |
dev16 = dev16_sse2; |
|
|
|
498 |
/* Forward and Inverse DCT */ |
/* Forward and Inverse DCT */ |
499 |
|
#if 0 /* Both function are known to be unprecise, better keep them deactivated */ |
500 |
idct = idct_sse2; |
idct = idct_sse2; |
501 |
fdct = fdct_sse2; |
fdct = fdct_sse2; |
502 |
#endif |
#endif |
503 |
} |
} |
504 |
|
#endif |
505 |
#endif |
#endif |
506 |
|
|
507 |
#ifdef ARCH_IA64 |
#if defined(ARCH_IS_IA64) |
508 |
if ((cpu_flags & XVID_CPU_IA64) > 0) { //use assembler routines? |
if ((cpu_flags & XVID_CPU_ASM)) { /* use assembler routines? */ |
509 |
idct_ia64_init(); |
idct_ia64_init(); |
510 |
fdct = fdct_ia64; |
fdct = fdct_ia64; |
511 |
idct = idct_ia64; //not yet working, crashes |
idct = idct_ia64; /*not yet working, crashes */ |
512 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64; |
513 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64; |
514 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64; |
516 |
sad16bi = sad16bi_ia64; |
sad16bi = sad16bi_ia64; |
517 |
sad8 = sad8_ia64; |
sad8 = sad8_ia64; |
518 |
dev16 = dev16_ia64; |
dev16 = dev16_ia64; |
519 |
// Halfpel8_Refine = Halfpel8_Refine_ia64; |
/* Halfpel8_Refine = Halfpel8_Refine_ia64; */ |
520 |
quant_intra = quant_intra_ia64; |
quant_intra = quant_intra_ia64; |
521 |
dequant_intra = dequant_intra_ia64; |
dequant_intra = dequant_intra_ia64; |
522 |
quant_inter = quant_inter_ia64; |
quant_inter = quant_inter_ia64; |
527 |
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
528 |
transfer_16to8add = transfer_16to8add_ia64; |
transfer_16to8add = transfer_16to8add_ia64; |
529 |
transfer8x8_copy = transfer8x8_copy_ia64; |
transfer8x8_copy = transfer8x8_copy_ia64; |
|
DEBUG("Using IA-64 assembler routines.\n"); |
|
530 |
} |
} |
531 |
#endif |
#endif |
532 |
|
|
533 |
#ifdef ARCH_PPC |
#if defined(ARCH_IS_PPC) |
534 |
#ifdef ARCH_PPC_ALTIVEC |
if ((cpu_flags & XVID_CPU_ASM)) |
535 |
|
{ |
536 |
|
calc_cbp = calc_cbp_ppc; |
537 |
|
} |
538 |
|
|
539 |
|
if ((cpu_flags & XVID_CPU_ALTIVEC)) |
540 |
|
{ |
541 |
calc_cbp = calc_cbp_altivec; |
calc_cbp = calc_cbp_altivec; |
542 |
fdct = fdct_altivec; |
fdct = fdct_altivec; |
543 |
idct = idct_altivec; |
idct = idct_altivec; |
545 |
sad16 = sad16_altivec; |
sad16 = sad16_altivec; |
546 |
sad8 = sad8_altivec; |
sad8 = sad8_altivec; |
547 |
dev16 = dev16_altivec; |
dev16 = dev16_altivec; |
548 |
#else |
} |
|
calc_cbp = calc_cbp_ppc; |
|
549 |
#endif |
#endif |
550 |
|
|
551 |
|
#if defined(_DEBUG) |
552 |
|
xvid_debug = init->debug; |
553 |
#endif |
#endif |
554 |
|
|
555 |
return XVID_ERR_OK; |
return 0; |
556 |
} |
} |
557 |
|
|
558 |
|
|
559 |
|
static int |
560 |
|
xvid_gbl_info(xvid_gbl_info_t * info) |
561 |
|
{ |
562 |
|
if (XVID_VERSION_MAJOR(info->version) != 1) /* v1.x.x */ |
563 |
|
return XVID_ERR_VERSION; |
564 |
|
|
565 |
|
info->actual_version = XVID_VERSION; |
566 |
|
info->build = "dev-api-4"; |
567 |
|
info->cpu_flags = detect_cpu_flags(); |
568 |
|
|
569 |
|
#if defined(_SMP) && defined(WIN32) |
570 |
|
info->num_threads = pthread_num_processors_np();; |
571 |
|
#else |
572 |
|
info->num_threads = 0; |
573 |
|
#endif |
574 |
|
|
575 |
|
return 0; |
576 |
|
} |
577 |
|
|
578 |
|
|
579 |
static int |
static int |
580 |
xvid_init_convert(XVID_INIT_CONVERTINFO* convert) |
xvid_gbl_convert(xvid_gbl_convert_t* convert) |
581 |
{ |
{ |
582 |
// const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); |
int width; |
583 |
const int width = convert->width; |
int height; |
584 |
const int height = convert->height; |
int width2; |
585 |
const int width2 = convert->width/2; |
int height2; |
|
const int height2 = convert->height/2; |
|
586 |
IMAGE img; |
IMAGE img; |
587 |
|
|
588 |
switch (convert->input.colorspace & ~XVID_CSP_VFLIP) |
if (XVID_VERSION_MAJOR(convert->version) != 1) /* v1.x.x */ |
589 |
|
return XVID_ERR_VERSION; |
590 |
|
|
591 |
|
#if 0 |
592 |
|
const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); |
593 |
|
#endif |
594 |
|
width = convert->width; |
595 |
|
height = convert->height; |
596 |
|
width2 = convert->width/2; |
597 |
|
height2 = convert->height/2; |
598 |
|
|
599 |
|
switch (convert->input.csp & ~XVID_CSP_VFLIP) |
600 |
{ |
{ |
601 |
case XVID_CSP_YV12 : |
case XVID_CSP_YV12 : |
602 |
img.y = convert->input.y; |
img.y = convert->input.plane[0]; |
603 |
img.v = (uint8_t*)convert->input.y + width*height; |
img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height; |
604 |
img.u = (uint8_t*)convert->input.y + width*height + width2*height2; |
img.u = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height + (convert->input.stride[0]/2)*height2; |
605 |
image_output(&img, width, height, width, |
image_output(&img, width, height, width, |
606 |
convert->output.y, convert->output.y_stride, |
(uint8_t**)convert->output.plane, convert->output.stride, |
607 |
convert->output.colorspace, convert->interlacing); |
convert->output.csp, convert->interlacing); |
608 |
break; |
break; |
609 |
|
|
610 |
default : |
default : |
613 |
|
|
614 |
|
|
615 |
emms(); |
emms(); |
616 |
return XVID_ERR_OK; |
return 0; |
617 |
} |
} |
618 |
|
|
619 |
|
|
662 |
{ |
{ |
663 |
int i, diff = 0; |
int i, diff = 0; |
664 |
for (i = 0; i < size; i++) |
for (i = 0; i < size; i++) |
665 |
diff += ABS(blockA[i]-blockB[i]); |
diff += abs(blockA[i]-blockB[i]); |
666 |
return diff; |
return diff; |
667 |
} |
} |
668 |
|
|
675 |
#define TEST_FDCT (TEST_FORWARD) |
#define TEST_FDCT (TEST_FORWARD) |
676 |
#define TEST_IDCT (0) |
#define TEST_IDCT (0) |
677 |
|
|
678 |
int test_transform(void * funcA, void * funcB, const char * nameB, |
static int test_transform(void * funcA, void * funcB, const char * nameB, |
679 |
int test, int flags) |
int test, int flags) |
680 |
{ |
{ |
681 |
int i; |
int i; |
755 |
#define TEST_DEQUANT_INTRA (TEST_INTRA) |
#define TEST_DEQUANT_INTRA (TEST_INTRA) |
756 |
#define TEST_DEQUANT_INTER (0) |
#define TEST_DEQUANT_INTER (0) |
757 |
|
|
758 |
int test_quant(void * funcA, void * funcB, const char * nameB, |
static int test_quant(void * funcA, void * funcB, const char * nameB, |
759 |
int test, int flags) |
int test, int flags) |
760 |
{ |
{ |
761 |
int q,i; |
int q,i; |
762 |
int64_t timeSTART; |
int64_t timeSTART; |
763 |
int64_t timeA = 0; |
int64_t timeA = 0; |
764 |
int64_t timeB = 0; |
int64_t timeB = 0; |
765 |
int retA, retB; |
int retA = 0, retB = 0; |
766 |
DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); |
767 |
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
768 |
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
836 |
|
|
837 |
int xvid_init_test(int flags) |
int xvid_init_test(int flags) |
838 |
{ |
{ |
839 |
|
#if defined(ARCH_IS_IA32) |
840 |
int cpu_flags; |
int cpu_flags; |
841 |
|
#endif |
842 |
|
|
843 |
srand(time(0)); |
printf("XviD tests\n\n"); |
844 |
|
|
845 |
printf("xvid_init_test\n"); |
#if defined(ARCH_IS_IA32) |
846 |
|
cpu_flags = detect_cpu_flags(); |
847 |
|
#endif |
848 |
|
|
|
#if defined(ARCH_X86) |
|
|
cpu_flags = check_cpu_features(); |
|
849 |
idct_int32_init(); |
idct_int32_init(); |
850 |
emms_mmx(); |
emms(); |
851 |
|
|
852 |
|
srand(time(0)); |
853 |
|
|
854 |
|
/* fDCT test */ |
855 |
printf("--- fdct ---\n"); |
printf("--- fdct ---\n"); |
856 |
test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags); |
test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags); |
857 |
|
|
858 |
|
#if defined(ARCH_IS_IA32) |
859 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
860 |
test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags); |
test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags); |
861 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
862 |
test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags); |
test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags); |
863 |
|
#endif |
864 |
|
|
865 |
|
/* iDCT test */ |
866 |
printf("\n--- idct ---\n"); |
printf("\n--- idct ---\n"); |
867 |
test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags); |
test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags); |
868 |
|
|
869 |
|
#if defined(ARCH_IS_IA32) |
870 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
871 |
test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags); |
test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags); |
872 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
875 |
test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags); |
test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags); |
876 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
877 |
test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags); |
test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags); |
878 |
|
#endif |
879 |
|
|
880 |
|
/* Intra quantization test */ |
881 |
printf("\n--- quant intra ---\n"); |
printf("\n--- quant intra ---\n"); |
882 |
test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags); |
test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags); |
883 |
|
|
884 |
|
#if defined(ARCH_IS_IA32) |
885 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
886 |
test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
887 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
888 |
test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags); |
test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags); |
889 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
890 |
test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags); |
test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags); |
891 |
|
#endif |
892 |
|
|
893 |
|
/* Inter quantization test */ |
894 |
printf("\n--- quant inter ---\n"); |
printf("\n--- quant inter ---\n"); |
895 |
test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags); |
test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags); |
896 |
|
|
897 |
|
#if defined(ARCH_IS_IA32) |
898 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
899 |
test_quant(quant_inter_c, quant_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
test_quant(quant_inter_c, quant_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
900 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
901 |
test_quant(quant_inter_c, quant_inter_3dne, "3dne", TEST_QUANT_INTER, flags); |
test_quant(quant_inter_c, quant_inter_3dne, "3dne", TEST_QUANT_INTER, flags); |
902 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
903 |
test_quant(quant_inter_c, quant_inter_sse2, "sse2", TEST_QUANT_INTER, flags); |
test_quant(quant_inter_c, quant_inter_sse2, "sse2", TEST_QUANT_INTER, flags); |
904 |
|
#endif |
905 |
|
|
906 |
|
/* Intra dequantization test */ |
907 |
printf("\n--- dequant intra ---\n"); |
printf("\n--- dequant intra ---\n"); |
908 |
test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
909 |
|
|
910 |
|
#if defined(ARCH_IS_IA32) |
911 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
912 |
test_quant(dequant_intra_c, dequant_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
test_quant(dequant_intra_c, dequant_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
913 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
916 |
test_quant(dequant_intra_c, dequant_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
test_quant(dequant_intra_c, dequant_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
917 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
918 |
test_quant(dequant_intra_c, dequant_intra_sse2, "sse2", TEST_DEQUANT_INTRA, flags); |
test_quant(dequant_intra_c, dequant_intra_sse2, "sse2", TEST_DEQUANT_INTRA, flags); |
919 |
|
#endif |
920 |
|
|
921 |
|
/* Inter dequantization test */ |
922 |
printf("\n--- dequant inter ---\n"); |
printf("\n--- dequant inter ---\n"); |
923 |
test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags); |
test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags); |
924 |
|
|
925 |
|
#if defined(ARCH_IS_IA32) |
926 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
927 |
test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
928 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
931 |
test_quant(dequant_inter_c, dequant_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
test_quant(dequant_inter_c, dequant_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
932 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
933 |
test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags); |
test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags); |
934 |
|
#endif |
935 |
|
|
936 |
printf("\n--- quant4_intra ---\n"); |
/* Intra quantization test */ |
937 |
|
printf("\n--- quant4 intra ---\n"); |
938 |
test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags); |
test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags); |
939 |
|
|
940 |
|
#if defined(ARCH_IS_IA32) |
941 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
942 |
test_quant(quant4_intra_c, quant4_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
test_quant(quant4_intra_c, quant4_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
943 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
944 |
test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags); |
test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags); |
945 |
|
#endif |
946 |
|
|
947 |
printf("\n--- quant4_inter ---\n"); |
/* Inter quantization test */ |
948 |
|
printf("\n--- quant4 inter ---\n"); |
949 |
test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags); |
test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags); |
950 |
|
|
951 |
|
#if defined(ARCH_IS_IA32) |
952 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
953 |
test_quant(quant4_inter_c, quant4_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
test_quant(quant4_inter_c, quant4_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
954 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
955 |
test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags); |
test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags); |
956 |
|
#endif |
957 |
|
|
958 |
printf("\n--- dequant4_intra ---\n"); |
/* Intra dequantization test */ |
959 |
|
printf("\n--- dequant4 intra ---\n"); |
960 |
test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
961 |
|
|
962 |
|
#if defined(ARCH_IS_IA32) |
963 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
964 |
test_quant(dequant4_intra_c, dequant4_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
test_quant(dequant4_intra_c, dequant4_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
965 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
966 |
test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
967 |
|
#endif |
968 |
|
|
969 |
printf("\n--- dequant4_inter ---\n"); |
/* Inter dequantization test */ |
970 |
|
printf("\n--- dequant4 inter ---\n"); |
971 |
test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags); |
test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags); |
972 |
|
|
973 |
|
#if defined(ARCH_IS_IA32) |
974 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
975 |
test_quant(dequant4_inter_c, dequant4_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
test_quant(dequant4_inter_c, dequant4_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
976 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
977 |
test_quant(dequant4_inter_c, dequant4_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
test_quant(dequant4_inter_c, dequant4_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
|
|
|
|
emms_mmx(); |
|
|
|
|
978 |
#endif |
#endif |
979 |
|
|
980 |
return XVID_ERR_OK; |
emms(); |
981 |
|
|
982 |
|
return 0; |
983 |
} |
} |
984 |
|
|
985 |
|
|
986 |
|
/***************************************************************************** |
987 |
|
* XviD Global Entry point |
988 |
|
* |
989 |
|
* Well this function initialize all internal function pointers according |
990 |
|
* to the CPU features forced by the library client or autodetected (depending |
991 |
|
* on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all |
992 |
|
* image colorspace transformation tables. |
993 |
|
* |
994 |
|
****************************************************************************/ |
995 |
|
|
996 |
|
|
997 |
int |
int |
998 |
xvid_init(void *handle, |
xvid_global(void *handle, |
999 |
int opt, |
int opt, |
1000 |
void *param1, |
void *param1, |
1001 |
void *param2) |
void *param2) |
1002 |
{ |
{ |
1003 |
switch(opt) |
switch(opt) |
1004 |
{ |
{ |
1005 |
case XVID_INIT_INIT : |
case XVID_GBL_INIT : |
1006 |
return xvid_init_init((XVID_INIT_PARAM*)param1); |
return xvid_gbl_init((xvid_gbl_init_t*)param1); |
1007 |
|
|
1008 |
case XVID_INIT_CONVERT : |
case XVID_GBL_INFO : |
1009 |
return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1); |
return xvid_gbl_info((xvid_gbl_info_t*)param1); |
1010 |
|
|
1011 |
case XVID_INIT_TEST : |
case XVID_GBL_CONVERT : |
1012 |
return xvid_init_test((int)param1); |
return xvid_gbl_convert((xvid_gbl_convert_t*)param1); |
1013 |
|
|
1014 |
|
case XVID_GBL_TEST : |
1015 |
|
{ |
1016 |
|
ptr_t flags = (ptr_t)param1; |
1017 |
|
return xvid_init_test((int)flags); |
1018 |
|
} |
1019 |
default : |
default : |
1020 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
1021 |
} |
} |
1038 |
void *param2) |
void *param2) |
1039 |
{ |
{ |
1040 |
switch (opt) { |
switch (opt) { |
|
case XVID_DEC_DECODE: |
|
|
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2); |
|
|
|
|
1041 |
case XVID_DEC_CREATE: |
case XVID_DEC_CREATE: |
1042 |
return decoder_create((XVID_DEC_PARAM *) param1); |
return decoder_create((xvid_dec_create_t *) param1); |
1043 |
|
|
1044 |
case XVID_DEC_DESTROY: |
case XVID_DEC_DESTROY: |
1045 |
return decoder_destroy((DECODER *) handle); |
return decoder_destroy((DECODER *) handle); |
1046 |
|
|
1047 |
|
case XVID_DEC_DECODE: |
1048 |
|
return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2); |
1049 |
|
|
1050 |
default: |
default: |
1051 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
1052 |
} |
} |
1072 |
switch (opt) { |
switch (opt) { |
1073 |
case XVID_ENC_ENCODE: |
case XVID_ENC_ENCODE: |
1074 |
|
|
1075 |
if (((Encoder *) handle)->mbParam.max_bframes >= 0) |
return enc_encode((Encoder *) handle, |
1076 |
return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
(xvid_enc_frame_t *) param1, |
1077 |
(XVID_ENC_STATS *) param2); |
(xvid_enc_stats_t *) param2); |
|
else |
|
|
return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
|
|
(XVID_ENC_STATS *) param2); |
|
1078 |
|
|
1079 |
case XVID_ENC_CREATE: |
case XVID_ENC_CREATE: |
1080 |
return encoder_create((XVID_ENC_PARAM *) param1); |
return enc_create((xvid_enc_create_t *) param1); |
1081 |
|
|
1082 |
case XVID_ENC_DESTROY: |
case XVID_ENC_DESTROY: |
1083 |
return encoder_destroy((Encoder *) handle); |
return enc_destroy((Encoder *) handle); |
1084 |
|
|
1085 |
default: |
default: |
1086 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |