3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Native API implementation - |
* - Native API implementation - |
5 |
* |
* |
|
* Copyright(C) 2001-2003 Peter Ross <pross@xvid.org> |
|
|
* |
|
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 |
37 |
#include "image/reduced.h" |
#include "image/reduced.h" |
38 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
39 |
#include "utils/mbfunctions.h" |
#include "utils/mbfunctions.h" |
40 |
#include "quant/quant.h" |
#include "quant/quant_h263.h" |
41 |
|
#include "quant/quant_mpeg4.h" |
42 |
#include "motion/motion.h" |
#include "motion/motion.h" |
43 |
#include "motion/sad.h" |
#include "motion/sad.h" |
44 |
#include "utils/emms.h" |
#include "utils/emms.h" |
46 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
47 |
#include "image/qpel.h" |
#include "image/qpel.h" |
48 |
|
|
|
#if defined(_DEBUG) |
|
|
unsigned int xvid_debug = 0; /* xvid debug mask */ |
|
|
#endif |
|
|
|
|
49 |
#if defined(ARCH_IS_IA32) |
#if defined(ARCH_IS_IA32) |
50 |
|
|
51 |
#if defined(_MSC_VER) |
#if defined(_MSC_VER) |
52 |
# include <windows.h> |
# include <windows.h> |
53 |
#else |
#else |
154 |
|
|
155 |
|
|
156 |
static |
static |
157 |
int xvid_gbl_init(xvid_gbl_init_t * init) |
int xvid_init_init(XVID_INIT_PARAM * init_param) |
158 |
{ |
{ |
159 |
unsigned int cpu_flags; |
int cpu_flags; |
160 |
|
|
161 |
|
/* Inform the client the API version */ |
162 |
|
init_param->api_version = API_VERSION; |
163 |
|
|
164 |
|
/* Inform the client the core build - unused because we're still alpha */ |
165 |
|
init_param->core_build = 1000; |
166 |
|
|
167 |
|
/* Do we have to force CPU features ? */ |
168 |
|
if ((init_param->cpu_flags & XVID_CPU_FORCE)) { |
169 |
|
|
170 |
if (XVID_VERSION_MAJOR(init->version) != 1) /* v1.x.x */ |
cpu_flags = init_param->cpu_flags; |
171 |
return XVID_ERR_VERSION; |
|
172 |
|
} else { |
173 |
|
|
174 |
|
cpu_flags = detect_cpu_flags(); |
175 |
|
} |
176 |
|
|
177 |
|
if ((init_param->cpu_flags & XVID_CPU_CHKONLY)) |
178 |
|
{ |
179 |
|
init_param->cpu_flags = cpu_flags; |
180 |
|
return XVID_ERR_OK; |
181 |
|
} |
182 |
|
|
183 |
cpu_flags = (init->cpu_flags & XVID_CPU_FORCE) ? init->cpu_flags : detect_cpu_flags(); |
init_param->cpu_flags = cpu_flags; |
184 |
|
|
185 |
|
/* Qpel stuff */ |
186 |
|
xvid_QP_Funcs = &xvid_QP_Funcs_C; |
187 |
|
xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_C; |
188 |
|
xvid_Init_QP_mmx(); |
189 |
|
|
190 |
/* Initialize the function pointers */ |
/* Initialize the function pointers */ |
191 |
idct_int32_init(); |
idct_int32_init(); |
201 |
/* Restore FPU context : emms_c is a nop functions */ |
/* Restore FPU context : emms_c is a nop functions */ |
202 |
emms = emms_c; |
emms = emms_c; |
203 |
|
|
|
/* Qpel stuff */ |
|
|
xvid_QP_Funcs = &xvid_QP_Funcs_C; |
|
|
xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_C; |
|
|
xvid_Init_QP(); |
|
|
|
|
204 |
/* Quantization functions */ |
/* Quantization functions */ |
205 |
quant_h263_intra = quant_h263_intra_c; |
quant_intra = quant_intra_c; |
206 |
quant_h263_inter = quant_h263_inter_c; |
dequant_intra = dequant_intra_c; |
207 |
dequant_h263_intra = dequant_h263_intra_c; |
quant_inter = quant_inter_c; |
208 |
dequant_h263_inter = dequant_h263_inter_c; |
dequant_inter = dequant_inter_c; |
209 |
|
|
210 |
quant_mpeg_intra = quant_mpeg_intra_c; |
quant4_intra = quant4_intra_c; |
211 |
quant_mpeg_inter = quant_mpeg_inter_c; |
dequant4_intra = dequant4_intra_c; |
212 |
dequant_mpeg_intra = dequant_mpeg_intra_c; |
quant4_inter = quant4_inter_c; |
213 |
dequant_mpeg_inter = dequant_mpeg_inter_c; |
dequant4_inter = dequant4_inter_c; |
214 |
|
|
215 |
/* Block transfer related functions */ |
/* Block transfer related functions */ |
216 |
transfer_8to16copy = transfer_8to16copy_c; |
transfer_8to16copy = transfer_8to16copy_c; |
243 |
interpolate8x8_avg2 = interpolate8x8_avg2_c; |
interpolate8x8_avg2 = interpolate8x8_avg2_c; |
244 |
interpolate8x8_avg4 = interpolate8x8_avg4_c; |
interpolate8x8_avg4 = interpolate8x8_avg4_c; |
245 |
|
|
246 |
/* reduced resolution */ |
/* reduced resoltuion */ |
247 |
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C; |
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C; |
248 |
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C; |
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C; |
249 |
vfilter_31 = xvid_VFilter_31_C; |
vfilter_31 = xvid_VFilter_31_C; |
302 |
sad8bi = sad8bi_c; |
sad8bi = sad8bi_c; |
303 |
dev16 = dev16_c; |
dev16 = dev16_c; |
304 |
sad16v = sad16v_c; |
sad16v = sad16v_c; |
|
sse8_16bit = sse8_16bit_c; |
|
305 |
|
|
306 |
/* Halfpel8_Refine = Halfpel8_Refine_c; */ |
/* Halfpel8_Refine = Halfpel8_Refine_c; */ |
307 |
|
|
308 |
#if defined(ARCH_IS_IA32) |
#if defined(ARCH_IS_IA32) |
309 |
|
|
310 |
if ((cpu_flags & XVID_CPU_ASM)) { |
if ((cpu_flags & XVID_CPU_ASM)) |
311 |
|
{ |
312 |
vfilter_31 = xvid_VFilter_31_x86; |
vfilter_31 = xvid_VFilter_31_x86; |
313 |
hfilter_31 = xvid_HFilter_31_x86; |
hfilter_31 = xvid_HFilter_31_x86; |
314 |
} |
} |
323 |
|
|
324 |
if ((cpu_flags & XVID_CPU_MMX)) { |
if ((cpu_flags & XVID_CPU_MMX)) { |
325 |
|
|
|
/* Forward and Inverse Discrete Cosine Transformation functions */ |
|
|
fdct = fdct_mmx_skal; |
|
|
idct = idct_mmx; |
|
|
|
|
326 |
/* Qpel stuff */ |
/* Qpel stuff */ |
327 |
xvid_QP_Funcs = &xvid_QP_Funcs_mmx; |
xvid_QP_Funcs = &xvid_QP_Funcs_mmx; |
328 |
xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_mmx; |
xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_mmx; |
329 |
|
xvid_Init_QP_mmx(); |
330 |
|
|
331 |
|
/* Forward and Inverse Discrete Cosine Transformation functions */ |
332 |
|
fdct = fdct_mmx; |
333 |
|
idct = idct_mmx; |
334 |
|
|
335 |
/* Quantization related functions */ |
/* Quantization related functions */ |
336 |
quant_h263_intra = quant_h263_intra_mmx; |
quant_intra = quant_intra_mmx; |
337 |
quant_h263_inter = quant_h263_inter_mmx; |
dequant_intra = dequant_intra_mmx; |
338 |
dequant_h263_intra = dequant_h263_intra_mmx; |
quant_inter = quant_inter_mmx; |
339 |
dequant_h263_inter = dequant_h263_inter_mmx; |
dequant_inter = dequant_inter_mmx; |
340 |
|
|
341 |
quant_mpeg_intra = quant_mpeg_intra_mmx; |
quant4_intra = quant4_intra_mmx; |
342 |
quant_mpeg_inter = quant_mpeg_inter_mmx; |
dequant4_intra = dequant4_intra_mmx; |
343 |
dequant_mpeg_intra = dequant_mpeg_intra_mmx; |
quant4_inter = quant4_inter_mmx; |
344 |
dequant_mpeg_inter = dequant_mpeg_inter_mmx; |
dequant4_inter = dequant4_inter_mmx; |
345 |
|
|
346 |
/* Block related functions */ |
/* Block related functions */ |
347 |
transfer_8to16copy = transfer_8to16copy_mmx; |
transfer_8to16copy = transfer_8to16copy_mmx; |
397 |
sad8bi = sad8bi_mmx; |
sad8bi = sad8bi_mmx; |
398 |
dev16 = dev16_mmx; |
dev16 = dev16_mmx; |
399 |
sad16v = sad16v_mmx; |
sad16v = sad16v_mmx; |
|
sse8_16bit = sse8_16bit_mmx; |
|
400 |
} |
} |
401 |
|
|
402 |
/* these 3dnow functions are faster than mmx, but slower than xmm. */ |
/* these 3dnow functions are faster than mmx, but slower than xmm. */ |
415 |
|
|
416 |
if ((cpu_flags & XVID_CPU_MMXEXT)) { |
if ((cpu_flags & XVID_CPU_MMXEXT)) { |
417 |
|
|
418 |
/* DCT */ |
/* Inverse DCT */ |
|
fdct = fdct_xmm_skal; |
|
419 |
idct = idct_xmm; |
idct = idct_xmm; |
420 |
|
|
421 |
/* Interpolation */ |
/* Interpolation */ |
428 |
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_xmm; |
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_xmm; |
429 |
|
|
430 |
/* Quantization */ |
/* Quantization */ |
431 |
quant_mpeg_intra = quant_mpeg_intra_xmm; |
quant4_intra = quant4_intra_xmm; |
432 |
quant_mpeg_inter = quant_mpeg_inter_xmm; |
quant4_inter = quant4_inter_xmm; |
433 |
|
|
434 |
dequant_h263_intra = dequant_h263_intra_xmm; |
dequant_intra = dequant_intra_xmm; |
435 |
dequant_h263_inter = dequant_h263_inter_xmm; |
dequant_inter = dequant_inter_xmm; |
436 |
|
|
437 |
/* Buffer transfer */ |
/* Buffer transfer */ |
438 |
transfer_8to16sub2 = transfer_8to16sub2_xmm; |
transfer_8to16sub2 = transfer_8to16sub2_xmm; |
474 |
transfer8x8_copy = transfer8x8_copy_3dne; |
transfer8x8_copy = transfer8x8_copy_3dne; |
475 |
|
|
476 |
/* Quantization */ |
/* Quantization */ |
477 |
quant_h263_intra = quant_h263_intra_3dne; |
dequant4_intra = dequant4_intra_3dne; |
478 |
quant_h263_inter = quant_h263_inter_3dne; |
dequant4_inter = dequant4_inter_3dne; |
479 |
dequant_mpeg_intra = dequant_mpeg_intra_3dne; |
quant_intra = quant_intra_3dne; |
480 |
dequant_mpeg_inter = dequant_mpeg_inter_3dne; |
quant_inter = quant_inter_3dne; |
481 |
dequant_h263_intra = dequant_h263_intra_3dne; |
dequant_intra = dequant_intra_3dne; |
482 |
dequant_h263_inter = dequant_h263_inter_3dne; |
dequant_inter = dequant_inter_3dne; |
483 |
|
|
484 |
/* ME functions */ |
/* ME functions */ |
485 |
calc_cbp = calc_cbp_3dne; |
calc_cbp = calc_cbp_3dne; |
495 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dne; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dne; |
496 |
} |
} |
497 |
|
|
498 |
#if defined(EXPERIMENTAL_SSE2_CODE) /* mark the whole SSE2 stuff as experimental. At least on |
|
|
my P4, it crashes... */ |
|
499 |
if ((cpu_flags & XVID_CPU_SSE2)) { |
if ((cpu_flags & XVID_CPU_SSE2)) { |
500 |
|
|
501 |
calc_cbp = calc_cbp_sse2; |
calc_cbp = calc_cbp_sse2; |
502 |
|
|
503 |
/* Quantization */ |
/* Quantization */ |
504 |
quant_h263_intra = quant_h263_intra_sse2; |
quant_intra = quant_intra_sse2; |
505 |
quant_h263_inter = quant_h263_inter_sse2; |
dequant_intra = dequant_intra_sse2; |
506 |
dequant_h263_intra = dequant_h263_intra_sse2; |
quant_inter = quant_inter_sse2; |
507 |
dequant_h263_inter = dequant_h263_inter_sse2; |
dequant_inter = dequant_inter_sse2; |
508 |
|
|
509 |
/* SAD operators */ |
#if defined(EXPERIMENTAL_SSE2_CODE) |
510 |
|
/* ME; slower than xmm */ |
511 |
sad16 = sad16_sse2; |
sad16 = sad16_sse2; |
512 |
dev16 = dev16_sse2; |
dev16 = dev16_sse2; |
|
|
|
|
/* DCT operators */ |
|
|
fdct = fdct_sse2_skal; |
|
|
idct = idct_sse2_dmitry; |
|
|
} |
|
513 |
#endif |
#endif |
514 |
|
/* Forward and Inverse DCT */ |
515 |
|
idct = idct_sse2; |
516 |
|
fdct = fdct_sse2; |
517 |
|
} |
518 |
#endif |
#endif |
519 |
|
|
520 |
#if defined(ARCH_IS_IA64) |
#if defined(ARCH_IS_IA64) |
530 |
sad8 = sad8_ia64; |
sad8 = sad8_ia64; |
531 |
dev16 = dev16_ia64; |
dev16 = dev16_ia64; |
532 |
/* Halfpel8_Refine = Halfpel8_Refine_ia64; */ |
/* Halfpel8_Refine = Halfpel8_Refine_ia64; */ |
533 |
quant_h263_intra = quant_h263_intra_ia64; |
quant_intra = quant_intra_ia64; |
534 |
quant_h263_inter = quant_h263_inter_ia64; |
dequant_intra = dequant_intra_ia64; |
535 |
dequant_h263_intra = dequant_h263_intra_ia64; |
quant_inter = quant_inter_ia64; |
536 |
dequant_h263_inter = dequant_h263_inter_ia64; |
dequant_inter = dequant_inter_ia64; |
537 |
transfer_8to16copy = transfer_8to16copy_ia64; |
transfer_8to16copy = transfer_8to16copy_ia64; |
538 |
transfer_16to8copy = transfer_16to8copy_ia64; |
transfer_16to8copy = transfer_16to8copy_ia64; |
539 |
transfer_8to16sub = transfer_8to16sub_ia64; |
transfer_8to16sub = transfer_8to16sub_ia64; |
540 |
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
541 |
transfer_16to8add = transfer_16to8add_ia64; |
transfer_16to8add = transfer_16to8add_ia64; |
542 |
transfer8x8_copy = transfer8x8_copy_ia64; |
transfer8x8_copy = transfer8x8_copy_ia64; |
543 |
|
DPRINTF(DPRINTF_DEBUG, "Using IA-64 assembler routines."); |
544 |
} |
} |
545 |
#endif |
#endif |
546 |
|
|
562 |
} |
} |
563 |
#endif |
#endif |
564 |
|
|
565 |
#if defined(_DEBUG) |
return XVID_ERR_OK; |
566 |
xvid_debug = init->debug; |
} |
567 |
#endif |
|
568 |
|
|
569 |
|
|
570 |
|
static int |
571 |
|
xvid_init_convert(XVID_INIT_CONVERTINFO* convert) |
572 |
|
{ |
573 |
|
/* |
574 |
|
const int flip1 = |
575 |
|
(convert->input.colorspace & XVID_CSP_VFLIP) ^ |
576 |
|
(convert->output.colorspace & XVID_CSP_VFLIP); |
577 |
|
*/ |
578 |
|
const int width = convert->width; |
579 |
|
const int height = convert->height; |
580 |
|
const int width2 = convert->width/2; |
581 |
|
const int height2 = convert->height/2; |
582 |
|
IMAGE img; |
583 |
|
|
584 |
|
switch (convert->input.colorspace & ~XVID_CSP_VFLIP) |
585 |
|
{ |
586 |
|
case XVID_CSP_YV12 : |
587 |
|
img.y = convert->input.y; |
588 |
|
img.v = (uint8_t*)convert->input.y + width*height; |
589 |
|
img.u = (uint8_t*)convert->input.y + width*height + width2*height2; |
590 |
|
image_output(&img, width, height, width, |
591 |
|
convert->output.y, convert->output.y_stride, |
592 |
|
convert->output.colorspace, convert->interlacing); |
593 |
|
break; |
594 |
|
|
595 |
|
default : |
596 |
|
return XVID_ERR_FORMAT; |
597 |
|
} |
598 |
|
|
599 |
|
|
600 |
|
emms(); |
601 |
|
return XVID_ERR_OK; |
602 |
|
} |
603 |
|
|
604 |
|
|
605 |
|
|
606 |
|
void fill8(uint8_t * block, int size, int value) |
607 |
|
{ |
608 |
|
int i; |
609 |
|
for (i = 0; i < size; i++) |
610 |
|
block[i] = value; |
611 |
|
} |
612 |
|
|
613 |
|
void fill16(int16_t * block, int size, int value) |
614 |
|
{ |
615 |
|
int i; |
616 |
|
for (i = 0; i < size; i++) |
617 |
|
block[i] = value; |
618 |
|
} |
619 |
|
|
620 |
|
#define RANDOM(min,max) min + (rand() % (max-min)) |
621 |
|
|
622 |
|
void random8(uint8_t * block, int size, int min, int max) |
623 |
|
{ |
624 |
|
int i; |
625 |
|
for (i = 0; i < size; i++) |
626 |
|
block[i] = RANDOM(min,max); |
627 |
|
} |
628 |
|
|
629 |
|
void random16(int16_t * block, int size, int min, int max) |
630 |
|
{ |
631 |
|
int i; |
632 |
|
for (i = 0; i < size; i++) |
633 |
|
block[i] = RANDOM(min,max); |
634 |
|
} |
635 |
|
|
636 |
|
int compare16(const int16_t * blockA, const int16_t * blockB, int size) |
637 |
|
{ |
638 |
|
int i; |
639 |
|
for (i = 0; i < size; i++) |
640 |
|
if (blockA[i] != blockB[i]) |
641 |
|
return 1; |
642 |
|
|
643 |
return 0; |
return 0; |
644 |
} |
} |
645 |
|
|
646 |
|
int diff16(const int16_t * blockA, const int16_t * blockB, int size) |
647 |
|
{ |
648 |
|
int i, diff = 0; |
649 |
|
for (i = 0; i < size; i++) |
650 |
|
diff += ABS(blockA[i]-blockB[i]); |
651 |
|
return diff; |
652 |
|
} |
653 |
|
|
654 |
|
|
655 |
static int |
#define XVID_TEST_RANDOM 0x00000001 /* random input data */ |
656 |
xvid_gbl_info(xvid_gbl_info_t * info) |
#define XVID_TEST_VERBOSE 0x00000002 /* verbose error output */ |
657 |
|
|
658 |
|
|
659 |
|
#define TEST_FORWARD 0x00000001 /* intra */ |
660 |
|
#define TEST_FDCT (TEST_FORWARD) |
661 |
|
#define TEST_IDCT (0) |
662 |
|
|
663 |
|
static int test_transform(void * funcA, void * funcB, const char * nameB, |
664 |
|
int test, int flags) |
665 |
{ |
{ |
666 |
if (XVID_VERSION_MAJOR(info->version) != 1) /* v1.x.x */ |
int i; |
667 |
return XVID_ERR_VERSION; |
int64_t timeSTART; |
668 |
|
int64_t timeA = 0; |
669 |
|
int64_t timeB = 0; |
670 |
|
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
671 |
|
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
672 |
|
int min, max; |
673 |
|
int count = 0; |
674 |
|
|
675 |
|
int tmp; |
676 |
|
int min_error = 0x10000*64; |
677 |
|
int max_error = 0; |
678 |
|
|
|
info->actual_version = XVID_VERSION; |
|
|
info->build = "xvid-1.0.0"; |
|
|
info->cpu_flags = detect_cpu_flags(); |
|
679 |
|
|
680 |
#if defined(_SMP) && defined(WIN32) |
if ((test & TEST_FORWARD)) /* forward */ |
681 |
info->num_threads = pthread_num_processors_np();; |
{ |
682 |
#else |
min = -256; |
683 |
info->num_threads = 0; |
max = 255; |
684 |
#endif |
}else{ /* inverse */ |
685 |
|
min = -2048; |
686 |
|
max = 2047; |
687 |
|
} |
688 |
|
|
689 |
|
for (i = 0; i < 64*64; i++) |
690 |
|
{ |
691 |
|
if ((flags & XVID_TEST_RANDOM)) |
692 |
|
{ |
693 |
|
random16(arrayA, 64, min, max); |
694 |
|
}else{ |
695 |
|
fill16(arrayA, 64, i); |
696 |
|
} |
697 |
|
memcpy(arrayB, arrayA, 64*sizeof(int16_t)); |
698 |
|
|
699 |
|
if ((test & TEST_FORWARD)) |
700 |
|
{ |
701 |
|
timeSTART = read_counter(); |
702 |
|
((fdctFunc*)funcA)(arrayA); |
703 |
|
timeA += read_counter() - timeSTART; |
704 |
|
|
705 |
|
timeSTART = read_counter(); |
706 |
|
((fdctFunc*)funcB)(arrayB); |
707 |
|
timeB += read_counter() - timeSTART; |
708 |
|
} |
709 |
|
else |
710 |
|
{ |
711 |
|
timeSTART = read_counter(); |
712 |
|
((idctFunc*)funcA)(arrayA); |
713 |
|
timeA += read_counter() - timeSTART; |
714 |
|
|
715 |
|
timeSTART = read_counter(); |
716 |
|
((idctFunc*)funcB)(arrayB); |
717 |
|
timeB += read_counter() - timeSTART; |
718 |
|
} |
719 |
|
|
720 |
|
tmp = diff16(arrayA, arrayB, 64) / 64; |
721 |
|
if (tmp > max_error) |
722 |
|
max_error = tmp; |
723 |
|
if (tmp < min_error) |
724 |
|
min_error = tmp; |
725 |
|
|
726 |
|
count++; |
727 |
|
} |
728 |
|
|
729 |
|
/* print the "average difference" of best/worst transforms */ |
730 |
|
printf("%s:\t%i\t(min_error:%i, max_error:%i)\n", nameB, (int)(timeB / count), min_error, max_error); |
731 |
|
|
732 |
return 0; |
return 0; |
733 |
} |
} |
734 |
|
|
735 |
|
|
736 |
static int |
#define TEST_QUANT 0x00000001 /* forward quantization */ |
737 |
xvid_gbl_convert(xvid_gbl_convert_t* convert) |
#define TEST_INTRA 0x00000002 /* intra */ |
738 |
|
#define TEST_QUANT_INTRA (TEST_QUANT|TEST_INTRA) |
739 |
|
#define TEST_QUANT_INTER (TEST_QUANT) |
740 |
|
#define TEST_DEQUANT_INTRA (TEST_INTRA) |
741 |
|
#define TEST_DEQUANT_INTER (0) |
742 |
|
|
743 |
|
static int test_quant(void * funcA, void * funcB, const char * nameB, |
744 |
|
int test, int flags) |
745 |
{ |
{ |
746 |
int width; |
int q,i; |
747 |
int height; |
int64_t timeSTART; |
748 |
int width2; |
int64_t timeA = 0; |
749 |
int height2; |
int64_t timeB = 0; |
750 |
IMAGE img; |
int retA = 0, retB = 0; |
751 |
|
DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); |
752 |
|
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
753 |
|
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
754 |
|
int min, max; |
755 |
|
int count = 0; |
756 |
|
int errors = 0; |
757 |
|
|
758 |
if (XVID_VERSION_MAJOR(convert->version) != 1) /* v1.x.x */ |
if ((test & TEST_QUANT)) /* quant */ |
759 |
return XVID_ERR_VERSION; |
{ |
760 |
|
min = -2048; |
761 |
|
max = 2047; |
762 |
|
}else{ /* dequant */ |
763 |
|
min = -256; |
764 |
|
max = 255; |
765 |
|
} |
766 |
|
|
767 |
#if 0 |
for (q = 1; q <= 31; q++) /* quantizer */ |
768 |
const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); |
{ |
769 |
#endif |
for (i = min; i < max; i++) /* input coeff */ |
770 |
width = convert->width; |
{ |
771 |
height = convert->height; |
if ((flags & XVID_TEST_RANDOM)) |
772 |
width2 = convert->width/2; |
{ |
773 |
height2 = convert->height/2; |
random16(arrayX, 64, min, max); |
774 |
|
}else{ |
775 |
|
fill16(arrayX, 64, i); |
776 |
|
} |
777 |
|
|
778 |
switch (convert->input.csp & ~XVID_CSP_VFLIP) |
if ((test & TEST_INTRA)) /* intra */ |
779 |
{ |
{ |
780 |
case XVID_CSP_YV12 : |
timeSTART = read_counter(); |
781 |
img.y = convert->input.plane[0]; |
((quanth263_intraFunc*)funcA)(arrayA, arrayX, q, q); |
782 |
img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height; |
timeA += read_counter() - timeSTART; |
783 |
img.u = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height + (convert->input.stride[0]/2)*height2; |
|
784 |
image_output(&img, width, height, width, |
timeSTART = read_counter(); |
785 |
(uint8_t**)convert->output.plane, convert->output.stride, |
((quanth263_intraFunc*)funcB)(arrayB, arrayX, q, q); |
786 |
convert->output.csp, convert->interlacing); |
timeB += read_counter() - timeSTART; |
787 |
break; |
} |
788 |
|
else /* inter */ |
789 |
|
{ |
790 |
|
timeSTART = read_counter(); |
791 |
|
retA = ((quanth263_interFunc*)funcA)(arrayA, arrayX, q); |
792 |
|
timeA += read_counter() - timeSTART; |
793 |
|
|
794 |
|
timeSTART = read_counter(); |
795 |
|
retB = ((quanth263_interFunc*)funcB)(arrayB, arrayX, q); |
796 |
|
timeB += read_counter() - timeSTART; |
797 |
|
} |
798 |
|
|
799 |
default : |
/* compare return value from quant_inter, and compare (de)quantiz'd arrays */ |
800 |
return XVID_ERR_FORMAT; |
if ( ((test&TEST_QUANT) && !(test&TEST_INTRA) && retA != retB ) || |
801 |
|
compare16(arrayA, arrayB, 64)) |
802 |
|
{ |
803 |
|
errors++; |
804 |
|
if ((flags & XVID_TEST_VERBOSE)) |
805 |
|
printf("%s error: q=%i, i=%i\n", nameB, q, i); |
806 |
} |
} |
807 |
|
|
808 |
|
count++; |
809 |
|
} |
810 |
|
} |
811 |
|
|
812 |
|
printf("%s:\t%i", nameB, (int)(timeB / count)); |
813 |
|
if (errors>0) |
814 |
|
printf("\t(%i errors out of %i)", errors, count); |
815 |
|
printf("\n"); |
816 |
|
|
|
emms(); |
|
817 |
return 0; |
return 0; |
818 |
} |
} |
819 |
|
|
820 |
/***************************************************************************** |
|
821 |
* XviD Global Entry point |
|
822 |
* |
int xvid_init_test(int flags) |
823 |
* Well this function initialize all internal function pointers according |
{ |
824 |
* to the CPU features forced by the library client or autodetected (depending |
#if defined(ARCH_IS_IA32) |
825 |
* on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all |
int cpu_flags; |
826 |
* image colorspace transformation tables. |
#endif |
827 |
* |
|
828 |
****************************************************************************/ |
printf("XviD tests\n\n"); |
829 |
|
|
830 |
|
#if defined(ARCH_IS_IA32) |
831 |
|
cpu_flags = detect_cpu_flags(); |
832 |
|
#endif |
833 |
|
|
834 |
|
idct_int32_init(); |
835 |
|
emms(); |
836 |
|
|
837 |
|
srand(time(0)); |
838 |
|
|
839 |
|
/* fDCT test */ |
840 |
|
printf("--- fdct ---\n"); |
841 |
|
test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags); |
842 |
|
|
843 |
|
#if defined(ARCH_IS_IA32) |
844 |
|
if (cpu_flags & XVID_CPU_MMX) |
845 |
|
test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags); |
846 |
|
if (cpu_flags & XVID_CPU_SSE2) |
847 |
|
test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags); |
848 |
|
#endif |
849 |
|
|
850 |
|
/* iDCT test */ |
851 |
|
printf("\n--- idct ---\n"); |
852 |
|
test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags); |
853 |
|
|
854 |
|
#if defined(ARCH_IS_IA32) |
855 |
|
if (cpu_flags & XVID_CPU_MMX) |
856 |
|
test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags); |
857 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
858 |
|
test_transform(idct_int32, idct_xmm, "xmm", TEST_IDCT, flags); |
859 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
860 |
|
test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags); |
861 |
|
if (cpu_flags & XVID_CPU_SSE2) |
862 |
|
test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags); |
863 |
|
#endif |
864 |
|
|
865 |
|
/* Intra quantization test */ |
866 |
|
printf("\n--- quant intra ---\n"); |
867 |
|
test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags); |
868 |
|
|
869 |
|
#if defined(ARCH_IS_IA32) |
870 |
|
if (cpu_flags & XVID_CPU_MMX) |
871 |
|
test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
872 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
873 |
|
test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags); |
874 |
|
if (cpu_flags & XVID_CPU_SSE2) |
875 |
|
test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags); |
876 |
|
#endif |
877 |
|
|
878 |
|
/* Inter quantization test */ |
879 |
|
printf("\n--- quant inter ---\n"); |
880 |
|
test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags); |
881 |
|
|
882 |
|
#if defined(ARCH_IS_IA32) |
883 |
|
if (cpu_flags & XVID_CPU_MMX) |
884 |
|
test_quant(quant_inter_c, quant_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
885 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
886 |
|
test_quant(quant_inter_c, quant_inter_3dne, "3dne", TEST_QUANT_INTER, flags); |
887 |
|
if (cpu_flags & XVID_CPU_SSE2) |
888 |
|
test_quant(quant_inter_c, quant_inter_sse2, "sse2", TEST_QUANT_INTER, flags); |
889 |
|
#endif |
890 |
|
|
891 |
|
/* Intra dequantization test */ |
892 |
|
printf("\n--- dequant intra ---\n"); |
893 |
|
test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
894 |
|
|
895 |
|
#if defined(ARCH_IS_IA32) |
896 |
|
if (cpu_flags & XVID_CPU_MMX) |
897 |
|
test_quant(dequant_intra_c, dequant_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
898 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
899 |
|
test_quant(dequant_intra_c, dequant_intra_xmm, "xmm", TEST_DEQUANT_INTRA, flags); |
900 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
901 |
|
test_quant(dequant_intra_c, dequant_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
902 |
|
if (cpu_flags & XVID_CPU_SSE2) |
903 |
|
test_quant(dequant_intra_c, dequant_intra_sse2, "sse2", TEST_DEQUANT_INTRA, flags); |
904 |
|
#endif |
905 |
|
|
906 |
|
/* Inter dequantization test */ |
907 |
|
printf("\n--- dequant inter ---\n"); |
908 |
|
test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags); |
909 |
|
|
910 |
|
#if defined(ARCH_IS_IA32) |
911 |
|
if (cpu_flags & XVID_CPU_MMX) |
912 |
|
test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
913 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
914 |
|
test_quant(dequant_inter_c, dequant_inter_xmm, "xmm", TEST_DEQUANT_INTER, flags); |
915 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
916 |
|
test_quant(dequant_inter_c, dequant_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
917 |
|
if (cpu_flags & XVID_CPU_SSE2) |
918 |
|
test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags); |
919 |
|
#endif |
920 |
|
|
921 |
|
/* Intra quantization test */ |
922 |
|
printf("\n--- quant4 intra ---\n"); |
923 |
|
test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags); |
924 |
|
|
925 |
|
#if defined(ARCH_IS_IA32) |
926 |
|
if (cpu_flags & XVID_CPU_MMX) |
927 |
|
test_quant(quant4_intra_c, quant4_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
928 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
929 |
|
test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags); |
930 |
|
#endif |
931 |
|
|
932 |
|
/* Inter quantization test */ |
933 |
|
printf("\n--- quant4 inter ---\n"); |
934 |
|
test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags); |
935 |
|
|
936 |
|
#if defined(ARCH_IS_IA32) |
937 |
|
if (cpu_flags & XVID_CPU_MMX) |
938 |
|
test_quant(quant4_inter_c, quant4_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
939 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
940 |
|
test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags); |
941 |
|
#endif |
942 |
|
|
943 |
|
/* Intra dequantization test */ |
944 |
|
printf("\n--- dequant4 intra ---\n"); |
945 |
|
test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
946 |
|
|
947 |
|
#if defined(ARCH_IS_IA32) |
948 |
|
if (cpu_flags & XVID_CPU_MMX) |
949 |
|
test_quant(dequant4_intra_c, dequant4_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
950 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
951 |
|
test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
952 |
|
#endif |
953 |
|
|
954 |
|
/* Inter dequantization test */ |
955 |
|
printf("\n--- dequant4 inter ---\n"); |
956 |
|
test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags); |
957 |
|
|
958 |
|
#if defined(ARCH_IS_IA32) |
959 |
|
if (cpu_flags & XVID_CPU_MMX) |
960 |
|
test_quant(dequant4_inter_c, dequant4_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
961 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
962 |
|
test_quant(dequant4_inter_c, dequant4_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
963 |
|
#endif |
964 |
|
|
965 |
|
emms(); |
966 |
|
|
967 |
|
return XVID_ERR_OK; |
968 |
|
} |
969 |
|
|
970 |
|
|
971 |
int |
int |
972 |
xvid_global(void *handle, |
xvid_init(void *handle, |
973 |
int opt, |
int opt, |
974 |
void *param1, |
void *param1, |
975 |
void *param2) |
void *param2) |
976 |
{ |
{ |
977 |
switch(opt) |
switch(opt) |
978 |
{ |
{ |
979 |
case XVID_GBL_INIT : |
case XVID_INIT_INIT : |
980 |
return xvid_gbl_init((xvid_gbl_init_t*)param1); |
return xvid_init_init((XVID_INIT_PARAM*)param1); |
|
|
|
|
case XVID_GBL_INFO : |
|
|
return xvid_gbl_info((xvid_gbl_info_t*)param1); |
|
981 |
|
|
982 |
case XVID_GBL_CONVERT : |
case XVID_INIT_CONVERT : |
983 |
return xvid_gbl_convert((xvid_gbl_convert_t*)param1); |
return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1); |
984 |
|
|
985 |
|
case XVID_INIT_TEST : |
986 |
|
{ |
987 |
|
ptr_t flags = (ptr_t)param1; |
988 |
|
return xvid_init_test((int)flags); |
989 |
|
} |
990 |
default : |
default : |
991 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
992 |
} |
} |
1009 |
void *param2) |
void *param2) |
1010 |
{ |
{ |
1011 |
switch (opt) { |
switch (opt) { |
1012 |
|
case XVID_DEC_DECODE: |
1013 |
|
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2); |
1014 |
|
|
1015 |
case XVID_DEC_CREATE: |
case XVID_DEC_CREATE: |
1016 |
return decoder_create((xvid_dec_create_t *) param1); |
return decoder_create((XVID_DEC_PARAM *) param1); |
1017 |
|
|
1018 |
case XVID_DEC_DESTROY: |
case XVID_DEC_DESTROY: |
1019 |
return decoder_destroy((DECODER *) handle); |
return decoder_destroy((DECODER *) handle); |
1020 |
|
|
|
case XVID_DEC_DECODE: |
|
|
return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2); |
|
|
|
|
1021 |
default: |
default: |
1022 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
1023 |
} |
} |
1043 |
switch (opt) { |
switch (opt) { |
1044 |
case XVID_ENC_ENCODE: |
case XVID_ENC_ENCODE: |
1045 |
|
|
1046 |
return enc_encode((Encoder *) handle, |
if (((Encoder *) handle)->mbParam.max_bframes >= 0) |
1047 |
(xvid_enc_frame_t *) param1, |
return encoder_encode_bframes((Encoder *) handle, |
1048 |
(xvid_enc_stats_t *) param2); |
(XVID_ENC_FRAME *) param1, |
1049 |
|
(XVID_ENC_STATS *) param2); |
1050 |
|
else |
1051 |
|
return encoder_encode((Encoder *) handle, |
1052 |
|
(XVID_ENC_FRAME *) param1, |
1053 |
|
(XVID_ENC_STATS *) param2); |
1054 |
|
|
1055 |
case XVID_ENC_CREATE: |
case XVID_ENC_CREATE: |
1056 |
return enc_create((xvid_enc_create_t *) param1); |
return encoder_create((XVID_ENC_PARAM *) param1); |
1057 |
|
|
1058 |
case XVID_ENC_DESTROY: |
case XVID_ENC_DESTROY: |
1059 |
return enc_destroy((Encoder *) handle); |
return encoder_destroy((Encoder *) handle); |
1060 |
|
|
1061 |
default: |
default: |
1062 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |