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 |
****************************************************************************/ |
****************************************************************************/ |
25 |
|
|
26 |
|
#include <stdio.h> |
27 |
#include <stdlib.h> |
#include <stdlib.h> |
28 |
|
#include <string.h> |
29 |
#include <time.h> |
#include <time.h> |
30 |
|
|
31 |
#include "xvid.h" |
#include "xvid.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) |
#if defined(_DEBUG) |
51 |
|
unsigned int xvid_debug = 0; /* xvid debug mask */ |
52 |
|
#endif |
53 |
|
|
54 |
|
#if defined(ARCH_IS_IA32) |
55 |
|
|
56 |
#ifdef WIN32 |
#if defined(_MSC_VER) |
57 |
#include <windows.h> |
#include <windows.h> |
58 |
#else |
#else |
59 |
#include <signal.h> |
#include <signal.h> |
60 |
#include <setjmp.h> |
#include <setjmp.h> |
|
#endif |
|
|
|
|
|
|
|
|
#ifndef WIN32 |
|
61 |
|
|
62 |
static jmp_buf mark; |
static jmp_buf mark; |
63 |
|
|
70 |
|
|
71 |
|
|
72 |
/* |
/* |
73 |
calls the funcptr, and returns whether SIGILL (illegal instruction) was signalled |
* Calls the funcptr, and returns whether SIGILL (illegal instruction) was |
74 |
return values: |
* signalled |
75 |
-1 : could not determine |
* |
76 |
0 : SIGILL was *not* signalled |
* Return values: |
77 |
1 : SIGILL was signalled |
* -1 : could not determine |
78 |
|
* 0 : SIGILL was *not* signalled |
79 |
|
* 1 : SIGILL was signalled |
80 |
*/ |
*/ |
81 |
|
|
82 |
int |
int |
83 |
sigill_check(void (*func)()) |
sigill_check(void (*func)()) |
84 |
{ |
{ |
85 |
#ifdef WIN32 |
#if defined(_MSC_VER) |
86 |
_try { |
_try { |
87 |
func(); |
func(); |
88 |
} |
} |
116 |
} |
} |
117 |
#endif |
#endif |
118 |
|
|
119 |
|
|
120 |
|
/* detect cpu flags */ |
121 |
|
static unsigned int |
122 |
|
detect_cpu_flags() |
123 |
|
{ |
124 |
|
/* enable native assembly optimizations by default */ |
125 |
|
unsigned int cpu_flags = XVID_CPU_ASM; |
126 |
|
|
127 |
|
#if defined(ARCH_IS_IA32) |
128 |
|
cpu_flags |= check_cpu_features(); |
129 |
|
if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger)) |
130 |
|
cpu_flags &= ~XVID_CPU_SSE; |
131 |
|
|
132 |
|
if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger)) |
133 |
|
cpu_flags &= ~XVID_CPU_SSE2; |
134 |
|
#endif |
135 |
|
|
136 |
|
#if defined(ARCH_IS_PPC) |
137 |
|
#if defined(ARCH_IS_PPC_ALTIVEC) |
138 |
|
cpu_flags |= XVID_CPU_ALTIVEC; |
139 |
|
#endif |
140 |
|
#endif |
141 |
|
|
142 |
|
return cpu_flags; |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
/***************************************************************************** |
/***************************************************************************** |
147 |
* XviD Init Entry point |
* XviD Init Entry point |
148 |
* |
* |
159 |
|
|
160 |
|
|
161 |
static |
static |
162 |
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)) |
|
163 |
{ |
{ |
164 |
init_param->cpu_flags = cpu_flags; |
unsigned int cpu_flags; |
|
return XVID_ERR_OK; |
|
|
} |
|
165 |
|
|
166 |
init_param->cpu_flags = cpu_flags; |
if (XVID_MAJOR(init->version) != 1) /* v1.x.x */ |
167 |
|
return XVID_ERR_VERSION; |
168 |
|
|
169 |
|
cpu_flags = (init->cpu_flags & XVID_CPU_FORCE) ? init->cpu_flags : detect_cpu_flags(); |
170 |
|
|
171 |
/* Initialize the function pointers */ |
/* Initialize the function pointers */ |
172 |
idct_int32_init(); |
idct_int32_init(); |
197 |
transfer_8to16copy = transfer_8to16copy_c; |
transfer_8to16copy = transfer_8to16copy_c; |
198 |
transfer_16to8copy = transfer_16to8copy_c; |
transfer_16to8copy = transfer_16to8copy_c; |
199 |
transfer_8to16sub = transfer_8to16sub_c; |
transfer_8to16sub = transfer_8to16sub_c; |
200 |
|
transfer_8to16subro = transfer_8to16subro_c; |
201 |
transfer_8to16sub2 = transfer_8to16sub2_c; |
transfer_8to16sub2 = transfer_8to16sub2_c; |
202 |
transfer_16to8add = transfer_16to8add_c; |
transfer_16to8add = transfer_16to8add_c; |
203 |
transfer8x8_copy = transfer8x8_copy_c; |
transfer8x8_copy = transfer8x8_copy_c; |
225 |
interpolate8x8_avg4 = interpolate8x8_avg4_c; |
interpolate8x8_avg4 = interpolate8x8_avg4_c; |
226 |
|
|
227 |
/* reduced resoltuion */ |
/* reduced resoltuion */ |
|
|
|
228 |
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C; |
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C; |
229 |
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 |
|
230 |
vfilter_31 = xvid_VFilter_31_C; |
vfilter_31 = xvid_VFilter_31_C; |
231 |
hfilter_31 = xvid_HFilter_31_C; |
hfilter_31 = xvid_HFilter_31_C; |
|
#endif |
|
232 |
filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C; |
filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C; |
233 |
filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C; |
filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C; |
234 |
|
|
284 |
dev16 = dev16_c; |
dev16 = dev16_c; |
285 |
sad16v = sad16v_c; |
sad16v = sad16v_c; |
286 |
|
|
287 |
// Halfpel8_Refine = Halfpel8_Refine_c; |
/* Halfpel8_Refine = Halfpel8_Refine_c; */ |
288 |
|
|
289 |
#ifdef ARCH_X86 |
#if defined(ARCH_IS_IA32) |
290 |
|
|
291 |
|
if ((cpu_flags & XVID_CPU_ASM)) { |
292 |
|
vfilter_31 = xvid_VFilter_31_x86; |
293 |
|
hfilter_31 = xvid_HFilter_31_x86; |
294 |
|
} |
295 |
|
|
296 |
if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) || |
if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) || |
297 |
(cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) || |
(cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) || |
301 |
emms = emms_mmx; |
emms = emms_mmx; |
302 |
} |
} |
303 |
|
|
304 |
if ((cpu_flags & XVID_CPU_MMX) > 0) { |
if ((cpu_flags & XVID_CPU_MMX)) { |
305 |
|
|
306 |
/* Forward and Inverse Discrete Cosine Transformation functions */ |
/* Forward and Inverse Discrete Cosine Transformation functions */ |
307 |
fdct = fdct_mmx; |
fdct = fdct_mmx; |
322 |
transfer_8to16copy = transfer_8to16copy_mmx; |
transfer_8to16copy = transfer_8to16copy_mmx; |
323 |
transfer_16to8copy = transfer_16to8copy_mmx; |
transfer_16to8copy = transfer_16to8copy_mmx; |
324 |
transfer_8to16sub = transfer_8to16sub_mmx; |
transfer_8to16sub = transfer_8to16sub_mmx; |
325 |
|
transfer_8to16subro = transfer_8to16subro_mmx; |
326 |
transfer_8to16sub2 = transfer_8to16sub2_mmx; |
transfer_8to16sub2 = transfer_8to16sub2_mmx; |
327 |
transfer_16to8add = transfer_16to8add_mmx; |
transfer_16to8add = transfer_16to8add_mmx; |
328 |
transfer8x8_copy = transfer8x8_copy_mmx; |
transfer8x8_copy = transfer8x8_copy_mmx; |
372 |
sad8bi = sad8bi_mmx; |
sad8bi = sad8bi_mmx; |
373 |
dev16 = dev16_mmx; |
dev16 = dev16_mmx; |
374 |
sad16v = sad16v_mmx; |
sad16v = sad16v_mmx; |
|
|
|
375 |
} |
} |
376 |
|
|
377 |
/* these 3dnow functions are faster than mmx, but slower than xmm. */ |
/* these 3dnow functions are faster than mmx, but slower than xmm. */ |
378 |
if ((cpu_flags & XVID_CPU_3DNOW) > 0) { |
if ((cpu_flags & XVID_CPU_3DNOW)) { |
379 |
|
|
380 |
|
emms = emms_3dn; |
381 |
|
|
382 |
/* ME functions */ |
/* ME functions */ |
383 |
sad16bi = sad16bi_3dn; |
sad16bi = sad16bi_3dn; |
388 |
} |
} |
389 |
|
|
390 |
|
|
391 |
if ((cpu_flags & XVID_CPU_MMXEXT) > 0) { |
if ((cpu_flags & XVID_CPU_MMXEXT)) { |
392 |
|
|
393 |
/* Inverse DCT */ |
/* Inverse DCT */ |
394 |
idct = idct_xmm; |
idct = idct_xmm; |
403 |
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_xmm; |
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_xmm; |
404 |
|
|
405 |
/* Quantization */ |
/* Quantization */ |
406 |
quant4_intra = quant4_intra_xmm; |
// quant4_intra = quant4_intra_xmm; |
407 |
quant4_inter = quant4_inter_xmm; |
quant4_inter = quant4_inter_xmm; |
408 |
|
|
409 |
dequant_intra = dequant_intra_xmm; |
dequant_intra = dequant_intra_xmm; |
426 |
sad16v = sad16v_xmm; |
sad16v = sad16v_xmm; |
427 |
} |
} |
428 |
|
|
429 |
if ((cpu_flags & XVID_CPU_3DNOW) > 0) { |
if ((cpu_flags & XVID_CPU_3DNOW)) { |
430 |
|
|
431 |
/* Interpolation */ |
/* Interpolation */ |
432 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn; |
434 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn; |
435 |
} |
} |
436 |
|
|
437 |
if ((cpu_flags & XVID_CPU_3DNOWEXT) > 0) { |
if ((cpu_flags & XVID_CPU_3DNOWEXT)) { |
438 |
|
|
439 |
/* Inverse DCT */ |
/* Inverse DCT */ |
440 |
idct = idct_3dne; |
idct = idct_3dne; |
443 |
transfer_8to16copy = transfer_8to16copy_3dne; |
transfer_8to16copy = transfer_8to16copy_3dne; |
444 |
transfer_16to8copy = transfer_16to8copy_3dne; |
transfer_16to8copy = transfer_16to8copy_3dne; |
445 |
transfer_8to16sub = transfer_8to16sub_3dne; |
transfer_8to16sub = transfer_8to16sub_3dne; |
446 |
|
transfer_8to16subro = transfer_8to16subro_3dne; |
447 |
transfer_8to16sub2 = transfer_8to16sub2_3dne; |
transfer_8to16sub2 = transfer_8to16sub2_3dne; |
448 |
transfer_16to8add = transfer_16to8add_3dne; |
transfer_16to8add = transfer_16to8add_3dne; |
449 |
transfer8x8_copy = transfer8x8_copy_3dne; |
transfer8x8_copy = transfer8x8_copy_3dne; |
451 |
/* Quantization */ |
/* Quantization */ |
452 |
dequant4_intra = dequant4_intra_3dne; |
dequant4_intra = dequant4_intra_3dne; |
453 |
dequant4_inter = dequant4_inter_3dne; |
dequant4_inter = dequant4_inter_3dne; |
454 |
quant_intra = quant_intra_3dne; |
// quant_intra = quant_intra_3dne; |
455 |
quant_inter = quant_inter_3dne; |
quant_inter = quant_inter_3dne; |
456 |
dequant_intra = dequant_intra_3dne; |
dequant_intra = dequant_intra_3dne; |
457 |
dequant_inter = dequant_inter_3dne; |
dequant_inter = dequant_inter_3dne; |
471 |
} |
} |
472 |
|
|
473 |
|
|
474 |
if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
if ((cpu_flags & XVID_CPU_SSE2)) { |
|
#ifdef EXPERIMENTAL_SSE2_CODE |
|
475 |
|
|
476 |
calc_cbp = calc_cbp_sse2; |
calc_cbp = calc_cbp_sse2; |
477 |
|
|
481 |
quant_inter = quant_inter_sse2; |
quant_inter = quant_inter_sse2; |
482 |
dequant_inter = dequant_inter_sse2; |
dequant_inter = dequant_inter_sse2; |
483 |
|
|
484 |
/* ME */ |
#if defined(EXPERIMENTAL_SSE2_CODE) |
485 |
|
/* ME; slower than xmm */ |
486 |
sad16 = sad16_sse2; |
sad16 = sad16_sse2; |
487 |
dev16 = dev16_sse2; |
dev16 = dev16_sse2; |
488 |
|
#endif |
489 |
/* Forward and Inverse DCT */ |
/* Forward and Inverse DCT */ |
490 |
|
#if 0 /* Both function are known to be unprecise, better keep them deactivated */ |
491 |
idct = idct_sse2; |
idct = idct_sse2; |
492 |
fdct = fdct_sse2; |
fdct = fdct_sse2; |
493 |
#endif |
#endif |
494 |
} |
} |
|
|
|
495 |
#endif |
#endif |
496 |
|
|
497 |
#ifdef ARCH_IA64 |
#if defined(ARCH_IS_IA64) |
498 |
if ((cpu_flags & XVID_CPU_IA64) > 0) { //use assembler routines? |
if ((cpu_flags & XVID_CPU_ASM)) { /* use assembler routines? */ |
499 |
idct_ia64_init(); |
idct_ia64_init(); |
500 |
fdct = fdct_ia64; |
fdct = fdct_ia64; |
501 |
idct = idct_ia64; //not yet working, crashes |
idct = idct_ia64; /*not yet working, crashes */ |
502 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64; |
503 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64; |
504 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64; |
506 |
sad16bi = sad16bi_ia64; |
sad16bi = sad16bi_ia64; |
507 |
sad8 = sad8_ia64; |
sad8 = sad8_ia64; |
508 |
dev16 = dev16_ia64; |
dev16 = dev16_ia64; |
509 |
// Halfpel8_Refine = Halfpel8_Refine_ia64; |
/* Halfpel8_Refine = Halfpel8_Refine_ia64; */ |
510 |
quant_intra = quant_intra_ia64; |
quant_intra = quant_intra_ia64; |
511 |
dequant_intra = dequant_intra_ia64; |
dequant_intra = dequant_intra_ia64; |
512 |
quant_inter = quant_inter_ia64; |
quant_inter = quant_inter_ia64; |
517 |
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
518 |
transfer_16to8add = transfer_16to8add_ia64; |
transfer_16to8add = transfer_16to8add_ia64; |
519 |
transfer8x8_copy = transfer8x8_copy_ia64; |
transfer8x8_copy = transfer8x8_copy_ia64; |
|
DEBUG("Using IA-64 assembler routines.\n"); |
|
520 |
} |
} |
521 |
#endif |
#endif |
522 |
|
|
523 |
#ifdef ARCH_PPC |
#if defined(ARCH_IS_PPC) |
524 |
#ifdef ARCH_PPC_ALTIVEC |
if ((cpu_flags & XVID_CPU_ASM)) |
525 |
|
{ |
526 |
|
calc_cbp = calc_cbp_ppc; |
527 |
|
} |
528 |
|
|
529 |
|
if ((cpu_flags & XVID_CPU_ALTIVEC)) |
530 |
|
{ |
531 |
calc_cbp = calc_cbp_altivec; |
calc_cbp = calc_cbp_altivec; |
532 |
fdct = fdct_altivec; |
fdct = fdct_altivec; |
533 |
idct = idct_altivec; |
idct = idct_altivec; |
535 |
sad16 = sad16_altivec; |
sad16 = sad16_altivec; |
536 |
sad8 = sad8_altivec; |
sad8 = sad8_altivec; |
537 |
dev16 = dev16_altivec; |
dev16 = dev16_altivec; |
538 |
#else |
} |
|
calc_cbp = calc_cbp_ppc; |
|
539 |
#endif |
#endif |
540 |
|
|
541 |
|
#if defined(_DEBUG) |
542 |
|
xvid_debug = init->debug; |
543 |
#endif |
#endif |
544 |
|
|
545 |
return XVID_ERR_OK; |
return 0; |
546 |
} |
} |
547 |
|
|
548 |
|
|
549 |
|
static int |
550 |
|
xvid_gbl_info(xvid_gbl_info_t * info) |
551 |
|
{ |
552 |
|
if (XVID_MAJOR(info->version) != 1) /* v1.x.x */ |
553 |
|
return XVID_ERR_VERSION; |
554 |
|
|
555 |
|
info->actual_version = XVID_VERSION; |
556 |
|
info->build = "dev-api-4"; |
557 |
|
info->cpu_flags = detect_cpu_flags(); |
558 |
|
|
559 |
|
#if defined(_SMP) && defined(WIN32) |
560 |
|
info->num_threads = pthread_num_processors_np();; |
561 |
|
#else |
562 |
|
info->num_threads = 0; |
563 |
|
#endif |
564 |
|
|
565 |
|
return 0; |
566 |
|
} |
567 |
|
|
568 |
|
|
569 |
static int |
static int |
570 |
xvid_init_convert(XVID_INIT_CONVERTINFO* convert) |
xvid_gbl_convert(xvid_gbl_convert_t* convert) |
571 |
{ |
{ |
572 |
// const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); |
int width; |
573 |
const int width = convert->width; |
int height; |
574 |
const int height = convert->height; |
int width2; |
575 |
const int width2 = convert->width/2; |
int height2; |
|
const int height2 = convert->height/2; |
|
576 |
IMAGE img; |
IMAGE img; |
577 |
|
|
578 |
switch (convert->input.colorspace & ~XVID_CSP_VFLIP) |
if (XVID_MAJOR(convert->version) != 1) /* v1.x.x */ |
579 |
|
return XVID_ERR_VERSION; |
580 |
|
|
581 |
|
#if 0 |
582 |
|
const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); |
583 |
|
#endif |
584 |
|
width = convert->width; |
585 |
|
height = convert->height; |
586 |
|
width2 = convert->width/2; |
587 |
|
height2 = convert->height/2; |
588 |
|
|
589 |
|
switch (convert->input.csp & ~XVID_CSP_VFLIP) |
590 |
{ |
{ |
591 |
case XVID_CSP_YV12 : |
case XVID_CSP_YV12 : |
592 |
img.y = convert->input.y; |
img.y = convert->input.plane[0]; |
593 |
img.v = (uint8_t*)convert->input.y + width*height; |
img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height; |
594 |
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; |
595 |
image_output(&img, width, height, width, |
image_output(&img, width, height, width, |
596 |
convert->output.y, convert->output.y_stride, |
(uint8_t**)convert->output.plane, convert->output.stride, |
597 |
convert->output.colorspace, convert->interlacing); |
convert->output.csp, convert->interlacing); |
598 |
break; |
break; |
599 |
|
|
600 |
default : |
default : |
603 |
|
|
604 |
|
|
605 |
emms(); |
emms(); |
606 |
return XVID_ERR_OK; |
return 0; |
607 |
} |
} |
608 |
|
|
609 |
|
|
652 |
{ |
{ |
653 |
int i, diff = 0; |
int i, diff = 0; |
654 |
for (i = 0; i < size; i++) |
for (i = 0; i < size; i++) |
655 |
diff += ABS(blockA[i]-blockB[i]); |
diff += abs(blockA[i]-blockB[i]); |
656 |
return diff; |
return diff; |
657 |
} |
} |
658 |
|
|
665 |
#define TEST_FDCT (TEST_FORWARD) |
#define TEST_FDCT (TEST_FORWARD) |
666 |
#define TEST_IDCT (0) |
#define TEST_IDCT (0) |
667 |
|
|
668 |
int test_transform(void * funcA, void * funcB, const char * nameB, |
static int test_transform(void * funcA, void * funcB, const char * nameB, |
669 |
int test, int flags) |
int test, int flags) |
670 |
{ |
{ |
671 |
int i; |
int i; |
732 |
} |
} |
733 |
|
|
734 |
/* print the "average difference" of best/worst transforms */ |
/* print the "average difference" of best/worst transforms */ |
735 |
printf("%s:\t%I64i\t(min_error:%i, max_error:%i)\n", nameB, timeB / count, min_error, max_error); |
printf("%s:\t%i\t(min_error:%i, max_error:%i)\n", nameB, (int)(timeB / count), min_error, max_error); |
736 |
|
|
737 |
return 0; |
return 0; |
738 |
} |
} |
745 |
#define TEST_DEQUANT_INTRA (TEST_INTRA) |
#define TEST_DEQUANT_INTRA (TEST_INTRA) |
746 |
#define TEST_DEQUANT_INTER (0) |
#define TEST_DEQUANT_INTER (0) |
747 |
|
|
748 |
int test_quant(void * funcA, void * funcB, const char * nameB, |
static int test_quant(void * funcA, void * funcB, const char * nameB, |
749 |
int test, int flags) |
int test, int flags) |
750 |
{ |
{ |
751 |
int q,i; |
int q,i; |
752 |
int64_t timeSTART; |
int64_t timeSTART; |
753 |
int64_t timeA = 0; |
int64_t timeA = 0; |
754 |
int64_t timeB = 0; |
int64_t timeB = 0; |
755 |
int retA, retB; |
int retA = 0, retB = 0; |
756 |
DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); |
757 |
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
758 |
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
814 |
} |
} |
815 |
} |
} |
816 |
|
|
817 |
printf("%s:\t%I64i", nameB, timeB / count); |
printf("%s:\t%i", nameB, (int)(timeB / count)); |
818 |
if (errors>0) |
if (errors>0) |
819 |
printf("\t(%i errors out of %i)", errors, count); |
printf("\t(%i errors out of %i)", errors, count); |
820 |
printf("\n"); |
printf("\n"); |
826 |
|
|
827 |
int xvid_init_test(int flags) |
int xvid_init_test(int flags) |
828 |
{ |
{ |
829 |
|
#if defined(ARCH_IS_IA32) |
830 |
int cpu_flags; |
int cpu_flags; |
831 |
|
#endif |
832 |
|
|
833 |
srand(time(0)); |
printf("XviD tests\n\n"); |
834 |
|
|
835 |
printf("xvid_init_test\n"); |
#if defined(ARCH_IS_IA32) |
836 |
|
cpu_flags = detect_cpu_flags(); |
837 |
|
#endif |
838 |
|
|
|
#if defined(ARCH_X86) |
|
|
cpu_flags = check_cpu_features(); |
|
839 |
idct_int32_init(); |
idct_int32_init(); |
840 |
emms_mmx(); |
emms(); |
841 |
|
|
842 |
|
srand(time(0)); |
843 |
|
|
844 |
|
/* fDCT test */ |
845 |
printf("--- fdct ---\n"); |
printf("--- fdct ---\n"); |
846 |
test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags); |
test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags); |
847 |
|
|
848 |
|
#if defined(ARCH_IS_IA32) |
849 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
850 |
test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags); |
test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags); |
851 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
852 |
test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags); |
test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags); |
853 |
|
#endif |
854 |
|
|
855 |
|
/* iDCT test */ |
856 |
printf("\n--- idct ---\n"); |
printf("\n--- idct ---\n"); |
857 |
test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags); |
test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags); |
858 |
|
|
859 |
|
#if defined(ARCH_IS_IA32) |
860 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
861 |
test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags); |
test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags); |
862 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
865 |
test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags); |
test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags); |
866 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
867 |
test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags); |
test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags); |
868 |
|
#endif |
869 |
|
|
870 |
|
/* Intra quantization test */ |
871 |
printf("\n--- quant intra ---\n"); |
printf("\n--- quant intra ---\n"); |
872 |
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); |
873 |
|
|
874 |
|
#if defined(ARCH_IS_IA32) |
875 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
876 |
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); |
877 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
878 |
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); |
879 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
880 |
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); |
881 |
|
#endif |
882 |
|
|
883 |
|
/* Inter quantization test */ |
884 |
printf("\n--- quant inter ---\n"); |
printf("\n--- quant inter ---\n"); |
885 |
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); |
886 |
|
|
887 |
|
#if defined(ARCH_IS_IA32) |
888 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
889 |
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); |
890 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
891 |
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); |
892 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
893 |
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); |
894 |
|
#endif |
895 |
|
|
896 |
|
/* Intra dequantization test */ |
897 |
printf("\n--- dequant intra ---\n"); |
printf("\n--- dequant intra ---\n"); |
898 |
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); |
899 |
|
|
900 |
|
#if defined(ARCH_IS_IA32) |
901 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
902 |
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); |
903 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
906 |
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); |
907 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
908 |
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); |
909 |
|
#endif |
910 |
|
|
911 |
|
/* Inter dequantization test */ |
912 |
printf("\n--- dequant inter ---\n"); |
printf("\n--- dequant inter ---\n"); |
913 |
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); |
914 |
|
|
915 |
|
#if defined(ARCH_IS_IA32) |
916 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
917 |
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); |
918 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
921 |
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); |
922 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
923 |
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); |
924 |
|
#endif |
925 |
|
|
926 |
printf("\n--- quant4_intra ---\n"); |
/* Intra quantization test */ |
927 |
|
printf("\n--- quant4 intra ---\n"); |
928 |
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); |
929 |
|
|
930 |
|
#if defined(ARCH_IS_IA32) |
931 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
932 |
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); |
933 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
934 |
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); |
935 |
|
#endif |
936 |
|
|
937 |
printf("\n--- quant4_inter ---\n"); |
/* Inter quantization test */ |
938 |
|
printf("\n--- quant4 inter ---\n"); |
939 |
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); |
940 |
|
|
941 |
|
#if defined(ARCH_IS_IA32) |
942 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
943 |
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); |
944 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
945 |
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); |
946 |
|
#endif |
947 |
|
|
948 |
printf("\n--- dequant4_intra ---\n"); |
/* Intra dequantization test */ |
949 |
|
printf("\n--- dequant4 intra ---\n"); |
950 |
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); |
951 |
|
|
952 |
|
#if defined(ARCH_IS_IA32) |
953 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
954 |
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); |
955 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
956 |
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); |
957 |
|
#endif |
958 |
|
|
959 |
printf("\n--- dequant4_inter ---\n"); |
/* Inter dequantization test */ |
960 |
|
printf("\n--- dequant4 inter ---\n"); |
961 |
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); |
962 |
|
|
963 |
|
#if defined(ARCH_IS_IA32) |
964 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
965 |
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); |
966 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
967 |
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(); |
|
|
|
|
968 |
#endif |
#endif |
969 |
|
|
970 |
return XVID_ERR_OK; |
emms(); |
971 |
|
|
972 |
|
return 0; |
973 |
} |
} |
974 |
|
|
975 |
|
|
976 |
|
/***************************************************************************** |
977 |
|
* XviD Global Entry point |
978 |
|
* |
979 |
|
* Well this function initialize all internal function pointers according |
980 |
|
* to the CPU features forced by the library client or autodetected (depending |
981 |
|
* on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all |
982 |
|
* image colorspace transformation tables. |
983 |
|
* |
984 |
|
****************************************************************************/ |
985 |
|
|
986 |
|
|
987 |
int |
int |
988 |
xvid_init(void *handle, |
xvid_global(void *handle, |
989 |
int opt, |
int opt, |
990 |
void *param1, |
void *param1, |
991 |
void *param2) |
void *param2) |
992 |
{ |
{ |
993 |
switch(opt) |
switch(opt) |
994 |
{ |
{ |
995 |
case XVID_INIT_INIT : |
case XVID_GBL_INIT : |
996 |
return xvid_init_init((XVID_INIT_PARAM*)param1); |
return xvid_gbl_init((xvid_gbl_init_t*)param1); |
997 |
|
|
998 |
case XVID_INIT_CONVERT : |
case XVID_GBL_INFO : |
999 |
return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1); |
return xvid_gbl_info((xvid_gbl_info_t*)param1); |
1000 |
|
|
1001 |
case XVID_INIT_TEST : |
case XVID_GBL_CONVERT : |
1002 |
return xvid_init_test((int)param1); |
return xvid_gbl_convert((xvid_gbl_convert_t*)param1); |
1003 |
|
|
1004 |
|
case XVID_GBL_TEST : |
1005 |
|
{ |
1006 |
|
ptr_t flags = (ptr_t)param1; |
1007 |
|
return xvid_init_test((int)flags); |
1008 |
|
} |
1009 |
default : |
default : |
1010 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
1011 |
} |
} |
1028 |
void *param2) |
void *param2) |
1029 |
{ |
{ |
1030 |
switch (opt) { |
switch (opt) { |
|
case XVID_DEC_DECODE: |
|
|
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2); |
|
|
|
|
1031 |
case XVID_DEC_CREATE: |
case XVID_DEC_CREATE: |
1032 |
return decoder_create((XVID_DEC_PARAM *) param1); |
return decoder_create((xvid_dec_create_t *) param1); |
1033 |
|
|
1034 |
case XVID_DEC_DESTROY: |
case XVID_DEC_DESTROY: |
1035 |
return decoder_destroy((DECODER *) handle); |
return decoder_destroy((DECODER *) handle); |
1036 |
|
|
1037 |
|
case XVID_DEC_DECODE: |
1038 |
|
return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2); |
1039 |
|
|
1040 |
default: |
default: |
1041 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
1042 |
} |
} |
1062 |
switch (opt) { |
switch (opt) { |
1063 |
case XVID_ENC_ENCODE: |
case XVID_ENC_ENCODE: |
1064 |
|
|
1065 |
if (((Encoder *) handle)->mbParam.max_bframes >= 0) |
return enc_encode((Encoder *) handle, |
1066 |
return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
(xvid_enc_frame_t *) param1, |
1067 |
(XVID_ENC_STATS *) param2); |
(xvid_enc_stats_t *) param2); |
|
else |
|
|
return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
|
|
(XVID_ENC_STATS *) param2); |
|
1068 |
|
|
1069 |
case XVID_ENC_CREATE: |
case XVID_ENC_CREATE: |
1070 |
return encoder_create((XVID_ENC_PARAM *) param1); |
return enc_create((xvid_enc_create_t *) param1); |
1071 |
|
|
1072 |
case XVID_ENC_DESTROY: |
case XVID_ENC_DESTROY: |
1073 |
return encoder_destroy((Encoder *) handle); |
return enc_destroy((Encoder *) handle); |
1074 |
|
|
1075 |
default: |
default: |
1076 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |