3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Native API implementation - |
* - Native API implementation - |
5 |
* |
* |
|
* This program is an implementation of a part of one or more MPEG-4 |
|
|
* 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. |
|
|
* |
|
6 |
* This program is free software ; you can redistribute it and/or modify |
* This program is free software ; you can redistribute it and/or modify |
7 |
* 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 |
8 |
* the Free Software Foundation ; either version 2 of the License, or |
* the Free Software Foundation ; either version 2 of the License, or |
17 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
* |
* |
|
****************************************************************************/ |
|
|
|
|
|
/***************************************************************************** |
|
|
* |
|
|
* 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> |
|
|
* |
|
20 |
* $Id$ |
* $Id$ |
21 |
* |
* |
22 |
****************************************************************************/ |
****************************************************************************/ |
45 |
#include "utils/timer.h" |
#include "utils/timer.h" |
46 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
47 |
|
|
48 |
#if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE) |
#if defined(ARCH_IS_IA32) |
49 |
|
|
50 |
#ifdef WIN32 |
#if defined(_MSC_VER) |
51 |
#include <windows.h> |
#include <windows.h> |
52 |
#else |
#else |
53 |
#include <signal.h> |
#include <signal.h> |
54 |
#include <setjmp.h> |
#include <setjmp.h> |
|
#endif |
|
|
|
|
|
|
|
|
#ifndef WIN32 |
|
55 |
|
|
56 |
static jmp_buf mark; |
static jmp_buf mark; |
57 |
|
|
64 |
|
|
65 |
|
|
66 |
/* |
/* |
67 |
calls the funcptr, and returns whether SIGILL (illegal instruction) was signalled |
* Calls the funcptr, and returns whether SIGILL (illegal instruction) was |
68 |
return values: |
* signalled |
69 |
-1 : could not determine |
* |
70 |
0 : SIGILL was *not* signalled |
* Return values: |
71 |
1 : SIGILL was signalled |
* -1 : could not determine |
72 |
|
* 0 : SIGILL was *not* signalled |
73 |
|
* 1 : SIGILL was signalled |
74 |
*/ |
*/ |
75 |
|
|
76 |
int |
int |
77 |
sigill_check(void (*func)()) |
sigill_check(void (*func)()) |
78 |
{ |
{ |
79 |
#ifdef WIN32 |
#if defined(_MSC_VER) |
80 |
_try { |
_try { |
81 |
func(); |
func(); |
82 |
} |
} |
110 |
} |
} |
111 |
#endif |
#endif |
112 |
|
|
113 |
|
|
114 |
|
/* detect cpu flags */ |
115 |
|
static unsigned int |
116 |
|
detect_cpu_flags() |
117 |
|
{ |
118 |
|
/* enable native assembly optimizations by default */ |
119 |
|
unsigned int cpu_flags = XVID_CPU_ASM; |
120 |
|
|
121 |
|
#if defined(ARCH_IS_IA32) |
122 |
|
cpu_flags |= check_cpu_features(); |
123 |
|
if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger)) |
124 |
|
cpu_flags &= ~XVID_CPU_SSE; |
125 |
|
|
126 |
|
if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger)) |
127 |
|
cpu_flags &= ~XVID_CPU_SSE2; |
128 |
|
#endif |
129 |
|
|
130 |
|
#if defined(ARCH_IS_PPC) |
131 |
|
#if defined(ARCH_IS_PPC_ALTIVEC) |
132 |
|
cpu_flags |= XVID_CPU_ALTIVEC; |
133 |
|
#endif |
134 |
|
#endif |
135 |
|
|
136 |
|
return cpu_flags; |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
/***************************************************************************** |
/***************************************************************************** |
141 |
* XviD Init Entry point |
* XviD Init Entry point |
142 |
* |
* |
153 |
|
|
154 |
|
|
155 |
static |
static |
156 |
int xvid_init_init(XVID_INIT_PARAM * init_param) |
int xvid_gbl_init(xvid_gbl_init_t * init) |
157 |
{ |
{ |
158 |
int cpu_flags; |
unsigned 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; |
|
159 |
|
|
160 |
/* Do we have to force CPU features ? */ |
if (XVID_MAJOR(init->version) != 1) /* v1.x.x */ |
161 |
if ((init_param->cpu_flags & XVID_CPU_FORCE)) { |
return XVID_ERR_VERSION; |
|
|
|
|
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)) |
|
|
{ |
|
|
init_param->cpu_flags = cpu_flags; |
|
|
return XVID_ERR_OK; |
|
|
} |
|
|
|
|
|
init_param->cpu_flags = cpu_flags; |
|
162 |
|
|
163 |
|
cpu_flags = (init->cpu_flags & XVID_CPU_FORCE) ? init->cpu_flags : detect_cpu_flags(); |
164 |
|
|
165 |
/* Initialize the function pointers */ |
/* Initialize the function pointers */ |
166 |
idct_int32_init(); |
idct_int32_init(); |
191 |
transfer_8to16copy = transfer_8to16copy_c; |
transfer_8to16copy = transfer_8to16copy_c; |
192 |
transfer_16to8copy = transfer_16to8copy_c; |
transfer_16to8copy = transfer_16to8copy_c; |
193 |
transfer_8to16sub = transfer_8to16sub_c; |
transfer_8to16sub = transfer_8to16sub_c; |
194 |
|
transfer_8to16subro = transfer_8to16subro_c; |
195 |
transfer_8to16sub2 = transfer_8to16sub2_c; |
transfer_8to16sub2 = transfer_8to16sub2_c; |
196 |
transfer_16to8add = transfer_16to8add_c; |
transfer_16to8add = transfer_16to8add_c; |
197 |
transfer8x8_copy = transfer8x8_copy_c; |
transfer8x8_copy = transfer8x8_copy_c; |
219 |
interpolate8x8_avg4 = interpolate8x8_avg4_c; |
interpolate8x8_avg4 = interpolate8x8_avg4_c; |
220 |
|
|
221 |
/* reduced resoltuion */ |
/* reduced resoltuion */ |
|
|
|
222 |
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C; |
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C; |
223 |
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 |
|
224 |
vfilter_31 = xvid_VFilter_31_C; |
vfilter_31 = xvid_VFilter_31_C; |
225 |
hfilter_31 = xvid_HFilter_31_C; |
hfilter_31 = xvid_HFilter_31_C; |
|
#endif |
|
226 |
filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C; |
filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C; |
227 |
filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C; |
filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C; |
228 |
|
|
278 |
dev16 = dev16_c; |
dev16 = dev16_c; |
279 |
sad16v = sad16v_c; |
sad16v = sad16v_c; |
280 |
|
|
281 |
// Halfpel8_Refine = Halfpel8_Refine_c; |
/* Halfpel8_Refine = Halfpel8_Refine_c; */ |
282 |
|
|
283 |
#ifdef ARCH_X86 |
#if defined(ARCH_IS_IA32) |
284 |
|
|
285 |
|
if ((cpu_flags & XVID_CPU_ASM)) |
286 |
|
{ |
287 |
|
vfilter_31 = xvid_VFilter_31_x86; |
288 |
|
hfilter_31 = xvid_HFilter_31_x86; |
289 |
|
} |
290 |
|
|
291 |
if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) || |
if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) || |
292 |
(cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) || |
(cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) || |
296 |
emms = emms_mmx; |
emms = emms_mmx; |
297 |
} |
} |
298 |
|
|
299 |
if ((cpu_flags & XVID_CPU_MMX) > 0) { |
if ((cpu_flags & XVID_CPU_MMX)) { |
300 |
|
|
301 |
/* Forward and Inverse Discrete Cosine Transformation functions */ |
/* Forward and Inverse Discrete Cosine Transformation functions */ |
302 |
fdct = fdct_mmx; |
fdct = fdct_mmx; |
317 |
transfer_8to16copy = transfer_8to16copy_mmx; |
transfer_8to16copy = transfer_8to16copy_mmx; |
318 |
transfer_16to8copy = transfer_16to8copy_mmx; |
transfer_16to8copy = transfer_16to8copy_mmx; |
319 |
transfer_8to16sub = transfer_8to16sub_mmx; |
transfer_8to16sub = transfer_8to16sub_mmx; |
320 |
|
transfer_8to16subro = transfer_8to16subro_mmx; |
321 |
transfer_8to16sub2 = transfer_8to16sub2_mmx; |
transfer_8to16sub2 = transfer_8to16sub2_mmx; |
322 |
transfer_16to8add = transfer_16to8add_mmx; |
transfer_16to8add = transfer_16to8add_mmx; |
323 |
transfer8x8_copy = transfer8x8_copy_mmx; |
transfer8x8_copy = transfer8x8_copy_mmx; |
367 |
sad8bi = sad8bi_mmx; |
sad8bi = sad8bi_mmx; |
368 |
dev16 = dev16_mmx; |
dev16 = dev16_mmx; |
369 |
sad16v = sad16v_mmx; |
sad16v = sad16v_mmx; |
|
|
|
370 |
} |
} |
371 |
|
|
372 |
/* these 3dnow functions are faster than mmx, but slower than xmm. */ |
/* these 3dnow functions are faster than mmx, but slower than xmm. */ |
373 |
if ((cpu_flags & XVID_CPU_3DNOW) > 0) { |
if ((cpu_flags & XVID_CPU_3DNOW)) { |
374 |
|
|
375 |
|
emms = emms_3dn; |
376 |
|
|
377 |
/* ME functions */ |
/* ME functions */ |
378 |
sad16bi = sad16bi_3dn; |
sad16bi = sad16bi_3dn; |
383 |
} |
} |
384 |
|
|
385 |
|
|
386 |
if ((cpu_flags & XVID_CPU_MMXEXT) > 0) { |
if ((cpu_flags & XVID_CPU_MMXEXT)) { |
387 |
|
|
388 |
/* Inverse DCT */ |
/* Inverse DCT */ |
389 |
idct = idct_xmm; |
idct = idct_xmm; |
421 |
sad16v = sad16v_xmm; |
sad16v = sad16v_xmm; |
422 |
} |
} |
423 |
|
|
424 |
if ((cpu_flags & XVID_CPU_3DNOW) > 0) { |
if ((cpu_flags & XVID_CPU_3DNOW)) { |
425 |
|
|
426 |
/* Interpolation */ |
/* Interpolation */ |
427 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn; |
429 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn; |
430 |
} |
} |
431 |
|
|
432 |
if ((cpu_flags & XVID_CPU_3DNOWEXT) > 0) { |
if ((cpu_flags & XVID_CPU_3DNOWEXT)) { |
433 |
|
|
434 |
/* Inverse DCT */ |
/* Inverse DCT */ |
435 |
idct = idct_3dne; |
idct = idct_3dne; |
438 |
transfer_8to16copy = transfer_8to16copy_3dne; |
transfer_8to16copy = transfer_8to16copy_3dne; |
439 |
transfer_16to8copy = transfer_16to8copy_3dne; |
transfer_16to8copy = transfer_16to8copy_3dne; |
440 |
transfer_8to16sub = transfer_8to16sub_3dne; |
transfer_8to16sub = transfer_8to16sub_3dne; |
441 |
|
transfer_8to16subro = transfer_8to16subro_3dne; |
442 |
transfer_8to16sub2 = transfer_8to16sub2_3dne; |
transfer_8to16sub2 = transfer_8to16sub2_3dne; |
443 |
transfer_16to8add = transfer_16to8add_3dne; |
transfer_16to8add = transfer_16to8add_3dne; |
444 |
transfer8x8_copy = transfer8x8_copy_3dne; |
transfer8x8_copy = transfer8x8_copy_3dne; |
466 |
} |
} |
467 |
|
|
468 |
|
|
469 |
if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
if ((cpu_flags & XVID_CPU_SSE2)) { |
|
#ifdef EXPERIMENTAL_SSE2_CODE |
|
470 |
|
|
471 |
calc_cbp = calc_cbp_sse2; |
calc_cbp = calc_cbp_sse2; |
472 |
|
|
476 |
quant_inter = quant_inter_sse2; |
quant_inter = quant_inter_sse2; |
477 |
dequant_inter = dequant_inter_sse2; |
dequant_inter = dequant_inter_sse2; |
478 |
|
|
479 |
/* ME */ |
#if defined(EXPERIMENTAL_SSE2_CODE) |
480 |
|
/* ME; slower than xmm */ |
481 |
sad16 = sad16_sse2; |
sad16 = sad16_sse2; |
482 |
dev16 = dev16_sse2; |
dev16 = dev16_sse2; |
483 |
|
#endif |
484 |
/* Forward and Inverse DCT */ |
/* Forward and Inverse DCT */ |
485 |
idct = idct_sse2; |
idct = idct_sse2; |
486 |
fdct = fdct_sse2; |
fdct = fdct_sse2; |
|
#endif |
|
487 |
} |
} |
|
|
|
488 |
#endif |
#endif |
489 |
|
|
490 |
#ifdef ARCH_IA64 |
#if defined(ARCH_IS_IA64) |
491 |
if ((cpu_flags & XVID_CPU_IA64) > 0) { //use assembler routines? |
if ((cpu_flags & XVID_CPU_ASM)) { /* use assembler routines? */ |
492 |
idct_ia64_init(); |
idct_ia64_init(); |
493 |
fdct = fdct_ia64; |
fdct = fdct_ia64; |
494 |
idct = idct_ia64; //not yet working, crashes |
idct = idct_ia64; /*not yet working, crashes */ |
495 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64; |
496 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64; |
497 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64; |
499 |
sad16bi = sad16bi_ia64; |
sad16bi = sad16bi_ia64; |
500 |
sad8 = sad8_ia64; |
sad8 = sad8_ia64; |
501 |
dev16 = dev16_ia64; |
dev16 = dev16_ia64; |
502 |
// Halfpel8_Refine = Halfpel8_Refine_ia64; |
/* Halfpel8_Refine = Halfpel8_Refine_ia64; */ |
503 |
quant_intra = quant_intra_ia64; |
quant_intra = quant_intra_ia64; |
504 |
dequant_intra = dequant_intra_ia64; |
dequant_intra = dequant_intra_ia64; |
505 |
quant_inter = quant_inter_ia64; |
quant_inter = quant_inter_ia64; |
510 |
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
511 |
transfer_16to8add = transfer_16to8add_ia64; |
transfer_16to8add = transfer_16to8add_ia64; |
512 |
transfer8x8_copy = transfer8x8_copy_ia64; |
transfer8x8_copy = transfer8x8_copy_ia64; |
513 |
DEBUG("Using IA-64 assembler routines.\n"); |
DPRINTF(DPRINTF_DEBUG, "Using IA-64 assembler routines."); |
514 |
} |
} |
515 |
#endif |
#endif |
516 |
|
|
517 |
#ifdef ARCH_PPC |
#if defined(ARCH_IS_PPC) |
518 |
#ifdef ARCH_PPC_ALTIVEC |
if ((cpu_flags & XVID_CPU_ASM)) |
519 |
|
{ |
520 |
|
calc_cbp = calc_cbp_ppc; |
521 |
|
} |
522 |
|
|
523 |
|
if ((cpu_flags & XVID_CPU_ALTIVEC)) |
524 |
|
{ |
525 |
calc_cbp = calc_cbp_altivec; |
calc_cbp = calc_cbp_altivec; |
526 |
fdct = fdct_altivec; |
fdct = fdct_altivec; |
527 |
idct = idct_altivec; |
idct = idct_altivec; |
529 |
sad16 = sad16_altivec; |
sad16 = sad16_altivec; |
530 |
sad8 = sad8_altivec; |
sad8 = sad8_altivec; |
531 |
dev16 = dev16_altivec; |
dev16 = dev16_altivec; |
532 |
#else |
} |
|
calc_cbp = calc_cbp_ppc; |
|
|
#endif |
|
533 |
#endif |
#endif |
534 |
|
|
535 |
return XVID_ERR_OK; |
return 0; |
536 |
} |
} |
537 |
|
|
538 |
|
|
539 |
|
static int |
540 |
|
xvid_gbl_info(xvid_gbl_info_t * info) |
541 |
|
{ |
542 |
|
if (XVID_MAJOR(info->version) != 1) /* v1.x.x */ |
543 |
|
return XVID_ERR_VERSION; |
544 |
|
|
545 |
|
info->actual_version = XVID_VERSION; |
546 |
|
info->build = "dev-api-4"; |
547 |
|
info->cpu_flags = detect_cpu_flags(); |
548 |
|
|
549 |
|
#if defined(_SMP) && defined(WIN32) |
550 |
|
info->num_threads = pthread_num_processors_np();; |
551 |
|
#else |
552 |
|
info->num_threads = 0; |
553 |
|
#endif |
554 |
|
|
555 |
|
return 0; |
556 |
|
} |
557 |
|
|
558 |
|
|
559 |
static int |
static int |
560 |
xvid_init_convert(XVID_INIT_CONVERTINFO* convert) |
xvid_gbl_convert(xvid_gbl_convert_t* convert) |
561 |
{ |
{ |
562 |
// const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); |
int width; |
563 |
const int width = convert->width; |
int height; |
564 |
const int height = convert->height; |
int width2; |
565 |
const int width2 = convert->width/2; |
int height2; |
|
const int height2 = convert->height/2; |
|
566 |
IMAGE img; |
IMAGE img; |
567 |
|
|
568 |
switch (convert->input.colorspace & ~XVID_CSP_VFLIP) |
if (XVID_MAJOR(convert->version) != 1) /* v1.x.x */ |
569 |
|
return XVID_ERR_VERSION; |
570 |
|
|
571 |
|
// const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); |
572 |
|
width = convert->width; |
573 |
|
height = convert->height; |
574 |
|
width2 = convert->width/2; |
575 |
|
height2 = convert->height/2; |
576 |
|
|
577 |
|
switch (convert->input.csp & ~XVID_CSP_VFLIP) |
578 |
{ |
{ |
579 |
case XVID_CSP_YV12 : |
case XVID_CSP_YV12 : |
580 |
img.y = convert->input.y; |
img.y = convert->input.plane[0]; |
581 |
img.v = (uint8_t*)convert->input.y + width*height; |
img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height; |
582 |
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; |
583 |
image_output(&img, width, height, width, |
image_output(&img, width, height, width, |
584 |
convert->output.y, convert->output.y_stride, |
(uint8_t**)convert->output.plane, convert->output.stride, |
585 |
convert->output.colorspace, convert->interlacing); |
convert->output.csp, convert->interlacing); |
586 |
break; |
break; |
587 |
|
|
588 |
default : |
default : |
591 |
|
|
592 |
|
|
593 |
emms(); |
emms(); |
594 |
return XVID_ERR_OK; |
return 0; |
595 |
} |
} |
596 |
|
|
597 |
|
|
653 |
#define TEST_FDCT (TEST_FORWARD) |
#define TEST_FDCT (TEST_FORWARD) |
654 |
#define TEST_IDCT (0) |
#define TEST_IDCT (0) |
655 |
|
|
656 |
int test_transform(void * funcA, void * funcB, const char * nameB, |
static int test_transform(void * funcA, void * funcB, const char * nameB, |
657 |
int test, int flags) |
int test, int flags) |
658 |
{ |
{ |
659 |
int i; |
int i; |
733 |
#define TEST_DEQUANT_INTRA (TEST_INTRA) |
#define TEST_DEQUANT_INTRA (TEST_INTRA) |
734 |
#define TEST_DEQUANT_INTER (0) |
#define TEST_DEQUANT_INTER (0) |
735 |
|
|
736 |
int test_quant(void * funcA, void * funcB, const char * nameB, |
static int test_quant(void * funcA, void * funcB, const char * nameB, |
737 |
int test, int flags) |
int test, int flags) |
738 |
{ |
{ |
739 |
int q,i; |
int q,i; |
740 |
int64_t timeSTART; |
int64_t timeSTART; |
741 |
int64_t timeA = 0; |
int64_t timeA = 0; |
742 |
int64_t timeB = 0; |
int64_t timeB = 0; |
743 |
int retA, retB; |
int retA = 0, retB = 0; |
744 |
DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); |
745 |
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
746 |
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
814 |
|
|
815 |
int xvid_init_test(int flags) |
int xvid_init_test(int flags) |
816 |
{ |
{ |
817 |
|
#if defined(ARCH_IS_IA32) |
818 |
int cpu_flags; |
int cpu_flags; |
819 |
|
#endif |
820 |
|
|
821 |
srand(time(0)); |
printf("XviD tests\n\n"); |
822 |
|
|
823 |
printf("xvid_init_test\n"); |
#if defined(ARCH_IS_IA32) |
824 |
|
cpu_flags = detect_cpu_flags(); |
825 |
|
#endif |
826 |
|
|
|
#if defined(ARCH_X86) |
|
|
cpu_flags = check_cpu_features(); |
|
827 |
idct_int32_init(); |
idct_int32_init(); |
828 |
emms_mmx(); |
emms(); |
829 |
|
|
830 |
|
srand(time(0)); |
831 |
|
|
832 |
|
/* fDCT test */ |
833 |
printf("--- fdct ---\n"); |
printf("--- fdct ---\n"); |
834 |
test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags); |
test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags); |
835 |
|
|
836 |
|
#if defined(ARCH_IS_IA32) |
837 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
838 |
test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags); |
test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags); |
839 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
840 |
test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags); |
test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags); |
841 |
|
#endif |
842 |
|
|
843 |
|
/* iDCT test */ |
844 |
printf("\n--- idct ---\n"); |
printf("\n--- idct ---\n"); |
845 |
test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags); |
test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags); |
846 |
|
|
847 |
|
#if defined(ARCH_IS_IA32) |
848 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
849 |
test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags); |
test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags); |
850 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
853 |
test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags); |
test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags); |
854 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
855 |
test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags); |
test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags); |
856 |
|
#endif |
857 |
|
|
858 |
|
/* Intra quantization test */ |
859 |
printf("\n--- quant intra ---\n"); |
printf("\n--- quant intra ---\n"); |
860 |
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); |
861 |
|
|
862 |
|
#if defined(ARCH_IS_IA32) |
863 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
864 |
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); |
865 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
866 |
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); |
867 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
868 |
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); |
869 |
|
#endif |
870 |
|
|
871 |
|
/* Inter quantization test */ |
872 |
printf("\n--- quant inter ---\n"); |
printf("\n--- quant inter ---\n"); |
873 |
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); |
874 |
|
|
875 |
|
#if defined(ARCH_IS_IA32) |
876 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
877 |
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); |
878 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
879 |
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); |
880 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
881 |
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); |
882 |
|
#endif |
883 |
|
|
884 |
|
/* Intra dequantization test */ |
885 |
printf("\n--- dequant intra ---\n"); |
printf("\n--- dequant intra ---\n"); |
886 |
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); |
887 |
|
|
888 |
|
#if defined(ARCH_IS_IA32) |
889 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
890 |
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); |
891 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
894 |
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); |
895 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
896 |
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); |
897 |
|
#endif |
898 |
|
|
899 |
|
/* Inter dequantization test */ |
900 |
printf("\n--- dequant inter ---\n"); |
printf("\n--- dequant inter ---\n"); |
901 |
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); |
902 |
|
|
903 |
|
#if defined(ARCH_IS_IA32) |
904 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
905 |
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); |
906 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
909 |
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); |
910 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
911 |
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); |
912 |
|
#endif |
913 |
|
|
914 |
printf("\n--- quant4_intra ---\n"); |
/* Intra quantization test */ |
915 |
|
printf("\n--- quant4 intra ---\n"); |
916 |
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); |
917 |
|
|
918 |
|
#if defined(ARCH_IS_IA32) |
919 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
920 |
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); |
921 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
922 |
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); |
923 |
|
#endif |
924 |
|
|
925 |
printf("\n--- quant4_inter ---\n"); |
/* Inter quantization test */ |
926 |
|
printf("\n--- quant4 inter ---\n"); |
927 |
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); |
928 |
|
|
929 |
|
#if defined(ARCH_IS_IA32) |
930 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
931 |
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); |
932 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
933 |
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); |
934 |
|
#endif |
935 |
|
|
936 |
printf("\n--- dequant4_intra ---\n"); |
/* Intra dequantization test */ |
937 |
|
printf("\n--- dequant4 intra ---\n"); |
938 |
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); |
939 |
|
|
940 |
|
#if defined(ARCH_IS_IA32) |
941 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
942 |
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); |
943 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
944 |
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); |
945 |
|
#endif |
946 |
|
|
947 |
printf("\n--- dequant4_inter ---\n"); |
/* Inter dequantization test */ |
948 |
|
printf("\n--- dequant4 inter ---\n"); |
949 |
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); |
950 |
|
|
951 |
|
#if defined(ARCH_IS_IA32) |
952 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
953 |
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); |
954 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
955 |
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(); |
|
|
|
|
956 |
#endif |
#endif |
957 |
|
|
958 |
return XVID_ERR_OK; |
emms(); |
959 |
|
|
960 |
|
return 0; |
961 |
} |
} |
962 |
|
|
963 |
|
|
964 |
|
/***************************************************************************** |
965 |
|
* XviD Global Entry point |
966 |
|
* |
967 |
|
* Well this function initialize all internal function pointers according |
968 |
|
* to the CPU features forced by the library client or autodetected (depending |
969 |
|
* on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all |
970 |
|
* image colorspace transformation tables. |
971 |
|
* |
972 |
|
****************************************************************************/ |
973 |
|
|
974 |
|
|
975 |
int |
int |
976 |
xvid_init(void *handle, |
xvid_global(void *handle, |
977 |
int opt, |
int opt, |
978 |
void *param1, |
void *param1, |
979 |
void *param2) |
void *param2) |
980 |
{ |
{ |
981 |
switch(opt) |
switch(opt) |
982 |
{ |
{ |
983 |
case XVID_INIT_INIT : |
case XVID_GBL_INIT : |
984 |
return xvid_init_init((XVID_INIT_PARAM*)param1); |
return xvid_gbl_init((xvid_gbl_init_t*)param1); |
985 |
|
|
986 |
case XVID_INIT_CONVERT : |
case XVID_GBL_INFO : |
987 |
return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1); |
return xvid_gbl_info((xvid_gbl_info_t*)param1); |
988 |
|
|
989 |
case XVID_INIT_TEST : |
case XVID_GBL_CONVERT : |
990 |
return xvid_init_test((int)param1); |
return xvid_gbl_convert((xvid_gbl_convert_t*)param1); |
991 |
|
|
992 |
|
case XVID_GBL_TEST : |
993 |
|
{ |
994 |
|
ptr_t flags = (ptr_t)param1; |
995 |
|
return xvid_init_test((int)flags); |
996 |
|
} |
997 |
default : |
default : |
998 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
999 |
} |
} |
1016 |
void *param2) |
void *param2) |
1017 |
{ |
{ |
1018 |
switch (opt) { |
switch (opt) { |
|
case XVID_DEC_DECODE: |
|
|
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2); |
|
|
|
|
1019 |
case XVID_DEC_CREATE: |
case XVID_DEC_CREATE: |
1020 |
return decoder_create((XVID_DEC_PARAM *) param1); |
return decoder_create((xvid_dec_create_t *) param1); |
1021 |
|
|
1022 |
case XVID_DEC_DESTROY: |
case XVID_DEC_DESTROY: |
1023 |
return decoder_destroy((DECODER *) handle); |
return decoder_destroy((DECODER *) handle); |
1024 |
|
|
1025 |
|
case XVID_DEC_DECODE: |
1026 |
|
return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2); |
1027 |
|
|
1028 |
default: |
default: |
1029 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
1030 |
} |
} |
1050 |
switch (opt) { |
switch (opt) { |
1051 |
case XVID_ENC_ENCODE: |
case XVID_ENC_ENCODE: |
1052 |
|
|
1053 |
if (((Encoder *) handle)->mbParam.max_bframes >= 0) |
return enc_encode((Encoder *) handle, |
1054 |
return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
(xvid_enc_frame_t *) param1, |
1055 |
(XVID_ENC_STATS *) param2); |
(xvid_enc_stats_t *) param2); |
|
else |
|
|
return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
|
|
(XVID_ENC_STATS *) param2); |
|
1056 |
|
|
1057 |
case XVID_ENC_CREATE: |
case XVID_ENC_CREATE: |
1058 |
return encoder_create((XVID_ENC_PARAM *) param1); |
return enc_create((xvid_enc_create_t *) param1); |
1059 |
|
|
1060 |
case XVID_ENC_DESTROY: |
case XVID_ENC_DESTROY: |
1061 |
return encoder_destroy((Encoder *) handle); |
return enc_destroy((Encoder *) handle); |
1062 |
|
|
1063 |
default: |
default: |
1064 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |