3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Native API implementation - |
* - Native API implementation - |
5 |
* |
* |
6 |
|
* Copyright(C) 2001-2003 Peter Ross <pross@xvid.org> |
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 |
10 |
* the Free Software Foundation ; either version 2 of the License, or |
* the Free Software Foundation ; either version 2 of the License, or |
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 |
* |
* |
22 |
* $Id: xvid.c,v 1.44 2003-02-20 22:46:18 edgomez Exp $ |
* $Id: xvid.c,v 1.45.2.19 2003-11-02 23:02:52 edgomez Exp $ |
23 |
* |
* |
24 |
****************************************************************************/ |
****************************************************************************/ |
25 |
|
|
39 |
#include "image/reduced.h" |
#include "image/reduced.h" |
40 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
41 |
#include "utils/mbfunctions.h" |
#include "utils/mbfunctions.h" |
42 |
#include "quant/quant_h263.h" |
#include "quant/quant.h" |
|
#include "quant/quant_mpeg4.h" |
|
43 |
#include "motion/motion.h" |
#include "motion/motion.h" |
44 |
#include "motion/sad.h" |
#include "motion/sad.h" |
45 |
#include "utils/emms.h" |
#include "utils/emms.h" |
46 |
#include "utils/timer.h" |
#include "utils/timer.h" |
47 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
48 |
|
#include "image/qpel.h" |
49 |
|
|
50 |
#if defined(ARCH_IS_IA32) |
#if defined(_DEBUG) |
51 |
|
unsigned int xvid_debug = 0; /* xvid debug mask */ |
52 |
|
#endif |
53 |
|
|
54 |
|
#if defined(ARCH_IS_IA32) |
55 |
#if defined(_MSC_VER) |
#if defined(_MSC_VER) |
56 |
# include <windows.h> |
# include <windows.h> |
57 |
#else |
#else |
158 |
|
|
159 |
|
|
160 |
static |
static |
161 |
int xvid_init_init(XVID_INIT_PARAM * init_param) |
int xvid_gbl_init(xvid_gbl_init_t * init) |
162 |
{ |
{ |
163 |
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; |
|
164 |
|
|
165 |
/* Do we have to force CPU features ? */ |
if (XVID_VERSION_MAJOR(init->version) != 1) /* v1.x.x */ |
166 |
if ((init_param->cpu_flags & XVID_CPU_FORCE)) { |
return XVID_ERR_VERSION; |
|
|
|
|
cpu_flags = init_param->cpu_flags; |
|
|
|
|
|
} else { |
|
|
|
|
|
cpu_flags = detect_cpu_flags(); |
|
|
} |
|
|
|
|
|
if ((init_param->cpu_flags & XVID_CPU_CHKONLY)) |
|
|
{ |
|
|
init_param->cpu_flags = cpu_flags; |
|
|
return XVID_ERR_OK; |
|
|
} |
|
|
|
|
|
init_param->cpu_flags = cpu_flags; |
|
167 |
|
|
168 |
|
cpu_flags = (init->cpu_flags & XVID_CPU_FORCE) ? init->cpu_flags : detect_cpu_flags(); |
169 |
|
|
170 |
/* Initialize the function pointers */ |
/* Initialize the function pointers */ |
171 |
idct_int32_init(); |
idct_int32_init(); |
181 |
/* Restore FPU context : emms_c is a nop functions */ |
/* Restore FPU context : emms_c is a nop functions */ |
182 |
emms = emms_c; |
emms = emms_c; |
183 |
|
|
184 |
|
/* Qpel stuff */ |
185 |
|
xvid_QP_Funcs = &xvid_QP_Funcs_C; |
186 |
|
xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_C; |
187 |
|
xvid_Init_QP(); |
188 |
|
|
189 |
/* Quantization functions */ |
/* Quantization functions */ |
190 |
quant_intra = quant_intra_c; |
quant_h263_intra = quant_h263_intra_c; |
191 |
dequant_intra = dequant_intra_c; |
quant_h263_inter = quant_h263_inter_c; |
192 |
quant_inter = quant_inter_c; |
dequant_h263_intra = dequant_h263_intra_c; |
193 |
dequant_inter = dequant_inter_c; |
dequant_h263_inter = dequant_h263_inter_c; |
194 |
|
|
195 |
quant4_intra = quant4_intra_c; |
quant_mpeg_intra = quant_mpeg_intra_c; |
196 |
dequant4_intra = dequant4_intra_c; |
quant_mpeg_inter = quant_mpeg_inter_c; |
197 |
quant4_inter = quant4_inter_c; |
dequant_mpeg_intra = dequant_mpeg_intra_c; |
198 |
dequant4_inter = dequant4_inter_c; |
dequant_mpeg_inter = dequant_mpeg_inter_c; |
199 |
|
|
200 |
/* Block transfer related functions */ |
/* Block transfer related functions */ |
201 |
transfer_8to16copy = transfer_8to16copy_c; |
transfer_8to16copy = transfer_8to16copy_c; |
228 |
interpolate8x8_avg2 = interpolate8x8_avg2_c; |
interpolate8x8_avg2 = interpolate8x8_avg2_c; |
229 |
interpolate8x8_avg4 = interpolate8x8_avg4_c; |
interpolate8x8_avg4 = interpolate8x8_avg4_c; |
230 |
|
|
231 |
/* reduced resoltuion */ |
/* reduced resolution */ |
232 |
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C; |
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C; |
233 |
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C; |
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C; |
234 |
vfilter_31 = xvid_VFilter_31_C; |
vfilter_31 = xvid_VFilter_31_C; |
292 |
|
|
293 |
#if defined(ARCH_IS_IA32) |
#if defined(ARCH_IS_IA32) |
294 |
|
|
295 |
if ((cpu_flags & XVID_CPU_ASM)) |
if ((cpu_flags & XVID_CPU_ASM)) { |
|
{ |
|
296 |
vfilter_31 = xvid_VFilter_31_x86; |
vfilter_31 = xvid_VFilter_31_x86; |
297 |
hfilter_31 = xvid_HFilter_31_x86; |
hfilter_31 = xvid_HFilter_31_x86; |
298 |
} |
} |
308 |
if ((cpu_flags & XVID_CPU_MMX)) { |
if ((cpu_flags & XVID_CPU_MMX)) { |
309 |
|
|
310 |
/* Forward and Inverse Discrete Cosine Transformation functions */ |
/* Forward and Inverse Discrete Cosine Transformation functions */ |
311 |
fdct = fdct_mmx; |
fdct = fdct_mmx_skal; |
312 |
idct = idct_mmx; |
idct = idct_mmx; |
313 |
|
|
314 |
|
/* Qpel stuff */ |
315 |
|
xvid_QP_Funcs = &xvid_QP_Funcs_mmx; |
316 |
|
xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_mmx; |
317 |
|
|
318 |
/* Quantization related functions */ |
/* Quantization related functions */ |
319 |
quant_intra = quant_intra_mmx; |
quant_h263_intra = quant_h263_intra_mmx; |
320 |
dequant_intra = dequant_intra_mmx; |
quant_h263_inter = quant_h263_inter_mmx; |
321 |
quant_inter = quant_inter_mmx; |
dequant_h263_intra = dequant_h263_intra_mmx; |
322 |
dequant_inter = dequant_inter_mmx; |
dequant_h263_inter = dequant_h263_inter_mmx; |
323 |
|
|
324 |
quant4_intra = quant4_intra_mmx; |
quant_mpeg_intra = quant_mpeg_intra_mmx; |
325 |
dequant4_intra = dequant4_intra_mmx; |
quant_mpeg_inter = quant_mpeg_inter_mmx; |
326 |
quant4_inter = quant4_inter_mmx; |
dequant_mpeg_intra = dequant_mpeg_intra_mmx; |
327 |
dequant4_inter = dequant4_inter_mmx; |
dequant_mpeg_inter = dequant_mpeg_inter_mmx; |
328 |
|
|
329 |
/* Block related functions */ |
/* Block related functions */ |
330 |
transfer_8to16copy = transfer_8to16copy_mmx; |
transfer_8to16copy = transfer_8to16copy_mmx; |
398 |
|
|
399 |
if ((cpu_flags & XVID_CPU_MMXEXT)) { |
if ((cpu_flags & XVID_CPU_MMXEXT)) { |
400 |
|
|
401 |
/* Inverse DCT */ |
/* DCT */ |
402 |
|
fdct = fdct_xmm_skal; |
403 |
idct = idct_xmm; |
idct = idct_xmm; |
404 |
|
|
405 |
/* Interpolation */ |
/* Interpolation */ |
412 |
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_xmm; |
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_xmm; |
413 |
|
|
414 |
/* Quantization */ |
/* Quantization */ |
415 |
quant4_intra = quant4_intra_xmm; |
quant_mpeg_intra = quant_mpeg_intra_xmm; |
416 |
quant4_inter = quant4_inter_xmm; |
quant_mpeg_inter = quant_mpeg_inter_xmm; |
417 |
|
|
418 |
dequant_intra = dequant_intra_xmm; |
dequant_h263_intra = dequant_h263_intra_xmm; |
419 |
dequant_inter = dequant_inter_xmm; |
dequant_h263_inter = dequant_h263_inter_xmm; |
420 |
|
|
421 |
/* Buffer transfer */ |
/* Buffer transfer */ |
422 |
transfer_8to16sub2 = transfer_8to16sub2_xmm; |
transfer_8to16sub2 = transfer_8to16sub2_xmm; |
458 |
transfer8x8_copy = transfer8x8_copy_3dne; |
transfer8x8_copy = transfer8x8_copy_3dne; |
459 |
|
|
460 |
/* Quantization */ |
/* Quantization */ |
461 |
dequant4_intra = dequant4_intra_3dne; |
quant_h263_intra = quant_h263_intra_3dne; |
462 |
dequant4_inter = dequant4_inter_3dne; |
quant_h263_inter = quant_h263_inter_3dne; |
463 |
quant_intra = quant_intra_3dne; |
dequant_mpeg_intra = dequant_mpeg_intra_3dne; |
464 |
quant_inter = quant_inter_3dne; |
dequant_mpeg_inter = dequant_mpeg_inter_3dne; |
465 |
dequant_intra = dequant_intra_3dne; |
dequant_h263_intra = dequant_h263_intra_3dne; |
466 |
dequant_inter = dequant_inter_3dne; |
dequant_h263_inter = dequant_h263_inter_3dne; |
467 |
|
|
468 |
/* ME functions */ |
/* ME functions */ |
469 |
calc_cbp = calc_cbp_3dne; |
calc_cbp = calc_cbp_3dne; |
479 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dne; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dne; |
480 |
} |
} |
481 |
|
|
482 |
|
#if defined(EXPERIMENTAL_SSE2_CODE) /* mark the whole SSE2 stuff as experimental. At least on |
483 |
|
my P4, it crashes... */ |
484 |
if ((cpu_flags & XVID_CPU_SSE2)) { |
if ((cpu_flags & XVID_CPU_SSE2)) { |
485 |
|
|
486 |
calc_cbp = calc_cbp_sse2; |
calc_cbp = calc_cbp_sse2; |
487 |
|
|
488 |
/* Quantization */ |
/* Quantization */ |
489 |
quant_intra = quant_intra_sse2; |
quant_h263_intra = quant_h263_intra_sse2; |
490 |
dequant_intra = dequant_intra_sse2; |
quant_h263_inter = quant_h263_inter_sse2; |
491 |
quant_inter = quant_inter_sse2; |
dequant_h263_intra = dequant_h263_intra_sse2; |
492 |
dequant_inter = dequant_inter_sse2; |
dequant_h263_inter = dequant_h263_inter_sse2; |
493 |
|
|
494 |
#if defined(EXPERIMENTAL_SSE2_CODE) |
/* SAD operators */ |
|
/* ME; slower than xmm */ |
|
495 |
sad16 = sad16_sse2; |
sad16 = sad16_sse2; |
496 |
dev16 = dev16_sse2; |
dev16 = dev16_sse2; |
497 |
#endif |
|
498 |
/* Forward and Inverse DCT */ |
/* DCT operators */ |
499 |
idct = idct_sse2; |
fdct = fdct_sse2_skal; |
500 |
fdct = fdct_sse2; |
idct = idct_sse2_dmitry; |
501 |
} |
} |
502 |
#endif |
#endif |
503 |
|
#endif |
504 |
|
|
505 |
#if defined(ARCH_IS_IA64) |
#if defined(ARCH_IS_IA64) |
506 |
if ((cpu_flags & XVID_CPU_ASM)) { /* use assembler routines? */ |
if ((cpu_flags & XVID_CPU_ASM)) { /* use assembler routines? */ |
515 |
sad8 = sad8_ia64; |
sad8 = sad8_ia64; |
516 |
dev16 = dev16_ia64; |
dev16 = dev16_ia64; |
517 |
/* Halfpel8_Refine = Halfpel8_Refine_ia64; */ |
/* Halfpel8_Refine = Halfpel8_Refine_ia64; */ |
518 |
quant_intra = quant_intra_ia64; |
quant_h263_intra = quant_h263_intra_ia64; |
519 |
dequant_intra = dequant_intra_ia64; |
quant_h263_inter = quant_h263_inter_ia64; |
520 |
quant_inter = quant_inter_ia64; |
dequant_h263_intra = dequant_h263_intra_ia64; |
521 |
dequant_inter = dequant_inter_ia64; |
dequant_h263_inter = dequant_h263_inter_ia64; |
522 |
transfer_8to16copy = transfer_8to16copy_ia64; |
transfer_8to16copy = transfer_8to16copy_ia64; |
523 |
transfer_16to8copy = transfer_16to8copy_ia64; |
transfer_16to8copy = transfer_16to8copy_ia64; |
524 |
transfer_8to16sub = transfer_8to16sub_ia64; |
transfer_8to16sub = transfer_8to16sub_ia64; |
525 |
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
526 |
transfer_16to8add = transfer_16to8add_ia64; |
transfer_16to8add = transfer_16to8add_ia64; |
527 |
transfer8x8_copy = transfer8x8_copy_ia64; |
transfer8x8_copy = transfer8x8_copy_ia64; |
|
DPRINTF(DPRINTF_DEBUG, "Using IA-64 assembler routines."); |
|
528 |
} |
} |
529 |
#endif |
#endif |
530 |
|
|
546 |
} |
} |
547 |
#endif |
#endif |
548 |
|
|
549 |
return XVID_ERR_OK; |
#if defined(_DEBUG) |
550 |
} |
xvid_debug = init->debug; |
551 |
|
#endif |
|
|
|
|
|
|
|
static int |
|
|
xvid_init_convert(XVID_INIT_CONVERTINFO* convert) |
|
|
{ |
|
|
/* |
|
|
const int flip1 = |
|
|
(convert->input.colorspace & XVID_CSP_VFLIP) ^ |
|
|
(convert->output.colorspace & XVID_CSP_VFLIP); |
|
|
*/ |
|
|
const int width = convert->width; |
|
|
const int height = convert->height; |
|
|
const int width2 = convert->width/2; |
|
|
const int height2 = convert->height/2; |
|
|
IMAGE img; |
|
|
|
|
|
switch (convert->input.colorspace & ~XVID_CSP_VFLIP) |
|
|
{ |
|
|
case XVID_CSP_YV12 : |
|
|
img.y = convert->input.y; |
|
|
img.v = (uint8_t*)convert->input.y + width*height; |
|
|
img.u = (uint8_t*)convert->input.y + width*height + width2*height2; |
|
|
image_output(&img, width, height, width, |
|
|
convert->output.y, convert->output.y_stride, |
|
|
convert->output.colorspace, convert->interlacing); |
|
|
break; |
|
|
|
|
|
default : |
|
|
return XVID_ERR_FORMAT; |
|
|
} |
|
|
|
|
|
|
|
|
emms(); |
|
|
return XVID_ERR_OK; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void fill8(uint8_t * block, int size, int value) |
|
|
{ |
|
|
int i; |
|
|
for (i = 0; i < size; i++) |
|
|
block[i] = value; |
|
|
} |
|
|
|
|
|
void fill16(int16_t * block, int size, int value) |
|
|
{ |
|
|
int i; |
|
|
for (i = 0; i < size; i++) |
|
|
block[i] = value; |
|
|
} |
|
|
|
|
|
#define RANDOM(min,max) min + (rand() % (max-min)) |
|
|
|
|
|
void random8(uint8_t * block, int size, int min, int max) |
|
|
{ |
|
|
int i; |
|
|
for (i = 0; i < size; i++) |
|
|
block[i] = RANDOM(min,max); |
|
|
} |
|
|
|
|
|
void random16(int16_t * block, int size, int min, int max) |
|
|
{ |
|
|
int i; |
|
|
for (i = 0; i < size; i++) |
|
|
block[i] = RANDOM(min,max); |
|
|
} |
|
|
|
|
|
int compare16(const int16_t * blockA, const int16_t * blockB, int size) |
|
|
{ |
|
|
int i; |
|
|
for (i = 0; i < size; i++) |
|
|
if (blockA[i] != blockB[i]) |
|
|
return 1; |
|
552 |
|
|
553 |
return 0; |
return 0; |
554 |
} |
} |
555 |
|
|
|
int diff16(const int16_t * blockA, const int16_t * blockB, int size) |
|
|
{ |
|
|
int i, diff = 0; |
|
|
for (i = 0; i < size; i++) |
|
|
diff += ABS(blockA[i]-blockB[i]); |
|
|
return diff; |
|
|
} |
|
|
|
|
|
|
|
|
#define XVID_TEST_RANDOM 0x00000001 /* random input data */ |
|
|
#define XVID_TEST_VERBOSE 0x00000002 /* verbose error output */ |
|
|
|
|
|
|
|
|
#define TEST_FORWARD 0x00000001 /* intra */ |
|
|
#define TEST_FDCT (TEST_FORWARD) |
|
|
#define TEST_IDCT (0) |
|
|
|
|
|
static int test_transform(void * funcA, void * funcB, const char * nameB, |
|
|
int test, int flags) |
|
|
{ |
|
|
int i; |
|
|
int64_t timeSTART; |
|
|
int64_t timeA = 0; |
|
|
int64_t timeB = 0; |
|
|
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
|
|
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
|
|
int min, max; |
|
|
int count = 0; |
|
|
|
|
|
int tmp; |
|
|
int min_error = 0x10000*64; |
|
|
int max_error = 0; |
|
|
|
|
|
|
|
|
if ((test & TEST_FORWARD)) /* forward */ |
|
|
{ |
|
|
min = -256; |
|
|
max = 255; |
|
|
}else{ /* inverse */ |
|
|
min = -2048; |
|
|
max = 2047; |
|
|
} |
|
|
|
|
|
for (i = 0; i < 64*64; i++) |
|
|
{ |
|
|
if ((flags & XVID_TEST_RANDOM)) |
|
|
{ |
|
|
random16(arrayA, 64, min, max); |
|
|
}else{ |
|
|
fill16(arrayA, 64, i); |
|
|
} |
|
|
memcpy(arrayB, arrayA, 64*sizeof(int16_t)); |
|
556 |
|
|
557 |
if ((test & TEST_FORWARD)) |
static int |
558 |
{ |
xvid_gbl_info(xvid_gbl_info_t * info) |
|
timeSTART = read_counter(); |
|
|
((fdctFunc*)funcA)(arrayA); |
|
|
timeA += read_counter() - timeSTART; |
|
|
|
|
|
timeSTART = read_counter(); |
|
|
((fdctFunc*)funcB)(arrayB); |
|
|
timeB += read_counter() - timeSTART; |
|
|
} |
|
|
else |
|
559 |
{ |
{ |
560 |
timeSTART = read_counter(); |
if (XVID_VERSION_MAJOR(info->version) != 1) /* v1.x.x */ |
561 |
((idctFunc*)funcA)(arrayA); |
return XVID_ERR_VERSION; |
|
timeA += read_counter() - timeSTART; |
|
562 |
|
|
563 |
timeSTART = read_counter(); |
info->actual_version = XVID_VERSION; |
564 |
((idctFunc*)funcB)(arrayB); |
info->build = "dev-api-4"; |
565 |
timeB += read_counter() - timeSTART; |
info->cpu_flags = detect_cpu_flags(); |
|
} |
|
|
|
|
|
tmp = diff16(arrayA, arrayB, 64) / 64; |
|
|
if (tmp > max_error) |
|
|
max_error = tmp; |
|
|
if (tmp < min_error) |
|
|
min_error = tmp; |
|
566 |
|
|
567 |
count++; |
#if defined(_SMP) && defined(WIN32) |
568 |
} |
info->num_threads = pthread_num_processors_np();; |
569 |
|
#else |
570 |
/* print the "average difference" of best/worst transforms */ |
info->num_threads = 0; |
571 |
printf("%s:\t%i\t(min_error:%i, max_error:%i)\n", nameB, (int)(timeB / count), min_error, max_error); |
#endif |
572 |
|
|
573 |
return 0; |
return 0; |
574 |
} |
} |
575 |
|
|
576 |
|
|
577 |
#define TEST_QUANT 0x00000001 /* forward quantization */ |
static int |
578 |
#define TEST_INTRA 0x00000002 /* intra */ |
xvid_gbl_convert(xvid_gbl_convert_t* convert) |
|
#define TEST_QUANT_INTRA (TEST_QUANT|TEST_INTRA) |
|
|
#define TEST_QUANT_INTER (TEST_QUANT) |
|
|
#define TEST_DEQUANT_INTRA (TEST_INTRA) |
|
|
#define TEST_DEQUANT_INTER (0) |
|
|
|
|
|
static int test_quant(void * funcA, void * funcB, const char * nameB, |
|
|
int test, int flags) |
|
|
{ |
|
|
int q,i; |
|
|
int64_t timeSTART; |
|
|
int64_t timeA = 0; |
|
|
int64_t timeB = 0; |
|
|
int retA = 0, retB = 0; |
|
|
DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); |
|
|
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
|
|
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
|
|
int min, max; |
|
|
int count = 0; |
|
|
int errors = 0; |
|
|
|
|
|
if ((test & TEST_QUANT)) /* quant */ |
|
579 |
{ |
{ |
580 |
min = -2048; |
int width; |
581 |
max = 2047; |
int height; |
582 |
}else{ /* dequant */ |
int width2; |
583 |
min = -256; |
int height2; |
584 |
max = 255; |
IMAGE img; |
|
} |
|
585 |
|
|
586 |
for (q = 1; q <= 31; q++) /* quantizer */ |
if (XVID_VERSION_MAJOR(convert->version) != 1) /* v1.x.x */ |
587 |
{ |
return XVID_ERR_VERSION; |
|
for (i = min; i < max; i++) /* input coeff */ |
|
|
{ |
|
|
if ((flags & XVID_TEST_RANDOM)) |
|
|
{ |
|
|
random16(arrayX, 64, min, max); |
|
|
}else{ |
|
|
fill16(arrayX, 64, i); |
|
|
} |
|
588 |
|
|
589 |
if ((test & TEST_INTRA)) /* intra */ |
#if 0 |
590 |
{ |
const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); |
591 |
timeSTART = read_counter(); |
#endif |
592 |
((quanth263_intraFunc*)funcA)(arrayA, arrayX, q, q); |
width = convert->width; |
593 |
timeA += read_counter() - timeSTART; |
height = convert->height; |
594 |
|
width2 = convert->width/2; |
595 |
timeSTART = read_counter(); |
height2 = convert->height/2; |
|
((quanth263_intraFunc*)funcB)(arrayB, arrayX, q, q); |
|
|
timeB += read_counter() - timeSTART; |
|
|
} |
|
|
else /* inter */ |
|
|
{ |
|
|
timeSTART = read_counter(); |
|
|
retA = ((quanth263_interFunc*)funcA)(arrayA, arrayX, q); |
|
|
timeA += read_counter() - timeSTART; |
|
|
|
|
|
timeSTART = read_counter(); |
|
|
retB = ((quanth263_interFunc*)funcB)(arrayB, arrayX, q); |
|
|
timeB += read_counter() - timeSTART; |
|
|
} |
|
596 |
|
|
597 |
/* compare return value from quant_inter, and compare (de)quantiz'd arrays */ |
switch (convert->input.csp & ~XVID_CSP_VFLIP) |
|
if ( ((test&TEST_QUANT) && !(test&TEST_INTRA) && retA != retB ) || |
|
|
compare16(arrayA, arrayB, 64)) |
|
598 |
{ |
{ |
599 |
errors++; |
case XVID_CSP_YV12 : |
600 |
if ((flags & XVID_TEST_VERBOSE)) |
img.y = convert->input.plane[0]; |
601 |
printf("%s error: q=%i, i=%i\n", nameB, q, i); |
img.v = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height; |
602 |
} |
img.u = (uint8_t*)convert->input.plane[0] + convert->input.stride[0]*height + (convert->input.stride[0]/2)*height2; |
603 |
|
image_output(&img, width, height, width, |
604 |
|
(uint8_t**)convert->output.plane, convert->output.stride, |
605 |
|
convert->output.csp, convert->interlacing); |
606 |
|
break; |
607 |
|
|
608 |
count++; |
default : |
609 |
} |
return XVID_ERR_FORMAT; |
610 |
} |
} |
611 |
|
|
|
printf("%s:\t%i", nameB, (int)(timeB / count)); |
|
|
if (errors>0) |
|
|
printf("\t(%i errors out of %i)", errors, count); |
|
|
printf("\n"); |
|
612 |
|
|
613 |
|
emms(); |
614 |
return 0; |
return 0; |
615 |
} |
} |
616 |
|
|
617 |
|
/***************************************************************************** |
618 |
|
* XviD Global Entry point |
619 |
int xvid_init_test(int flags) |
* |
620 |
{ |
* Well this function initialize all internal function pointers according |
621 |
int cpu_flags = 0; |
* to the CPU features forced by the library client or autodetected (depending |
622 |
|
* on the XVID_CPU_FORCE flag). It also initializes vlc coding tables and all |
623 |
srand(time(0)); |
* image colorspace transformation tables. |
624 |
|
* |
625 |
printf("XviD tests\n\n"); |
****************************************************************************/ |
|
|
|
|
#if defined(ARCH_IS_IA32) |
|
|
cpu_flags = detect_cpu_flags(); |
|
|
#endif |
|
|
|
|
|
idct_int32_init(); |
|
|
emms(); |
|
|
|
|
|
/* fDCT test */ |
|
|
printf("--- fdct ---\n"); |
|
|
test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags); |
|
|
|
|
|
#if defined(ARCH_IS_IA32) |
|
|
if (cpu_flags & XVID_CPU_MMX) |
|
|
test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags); |
|
|
if (cpu_flags & XVID_CPU_SSE2) |
|
|
test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags); |
|
|
#endif |
|
|
|
|
|
/* iDCT test */ |
|
|
printf("\n--- idct ---\n"); |
|
|
test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags); |
|
|
|
|
|
#if defined(ARCH_IS_IA32) |
|
|
if (cpu_flags & XVID_CPU_MMX) |
|
|
test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags); |
|
|
if (cpu_flags & XVID_CPU_MMXEXT) |
|
|
test_transform(idct_int32, idct_xmm, "xmm", TEST_IDCT, flags); |
|
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
|
|
test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags); |
|
|
if (cpu_flags & XVID_CPU_SSE2) |
|
|
test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags); |
|
|
#endif |
|
|
|
|
|
/* Intra quantization test */ |
|
|
printf("\n--- quant intra ---\n"); |
|
|
test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags); |
|
|
|
|
|
#if defined(ARCH_IS_IA32) |
|
|
if (cpu_flags & XVID_CPU_MMX) |
|
|
test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
|
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
|
|
test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags); |
|
|
if (cpu_flags & XVID_CPU_SSE2) |
|
|
test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags); |
|
|
#endif |
|
|
|
|
|
/* Inter quantization test */ |
|
|
printf("\n--- quant inter ---\n"); |
|
|
test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags); |
|
|
|
|
|
#if defined(ARCH_IS_IA32) |
|
|
if (cpu_flags & XVID_CPU_MMX) |
|
|
test_quant(quant_inter_c, quant_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
|
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
|
|
test_quant(quant_inter_c, quant_inter_3dne, "3dne", TEST_QUANT_INTER, flags); |
|
|
if (cpu_flags & XVID_CPU_SSE2) |
|
|
test_quant(quant_inter_c, quant_inter_sse2, "sse2", TEST_QUANT_INTER, flags); |
|
|
#endif |
|
|
|
|
|
/* Intra dequantization test */ |
|
|
printf("\n--- dequant intra ---\n"); |
|
|
test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
|
|
|
|
|
#if defined(ARCH_IS_IA32) |
|
|
if (cpu_flags & XVID_CPU_MMX) |
|
|
test_quant(dequant_intra_c, dequant_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
|
|
if (cpu_flags & XVID_CPU_MMXEXT) |
|
|
test_quant(dequant_intra_c, dequant_intra_xmm, "xmm", TEST_DEQUANT_INTRA, flags); |
|
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
|
|
test_quant(dequant_intra_c, dequant_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
|
|
if (cpu_flags & XVID_CPU_SSE2) |
|
|
test_quant(dequant_intra_c, dequant_intra_sse2, "sse2", TEST_DEQUANT_INTRA, flags); |
|
|
#endif |
|
|
|
|
|
/* Inter dequantization test */ |
|
|
printf("\n--- dequant inter ---\n"); |
|
|
test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags); |
|
|
|
|
|
#if defined(ARCH_IS_IA32) |
|
|
if (cpu_flags & XVID_CPU_MMX) |
|
|
test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
|
|
if (cpu_flags & XVID_CPU_MMXEXT) |
|
|
test_quant(dequant_inter_c, dequant_inter_xmm, "xmm", TEST_DEQUANT_INTER, flags); |
|
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
|
|
test_quant(dequant_inter_c, dequant_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
|
|
if (cpu_flags & XVID_CPU_SSE2) |
|
|
test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags); |
|
|
#endif |
|
|
|
|
|
/* Intra quantization test */ |
|
|
printf("\n--- quant4 intra ---\n"); |
|
|
test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags); |
|
|
|
|
|
#if defined(ARCH_IS_IA32) |
|
|
if (cpu_flags & XVID_CPU_MMX) |
|
|
test_quant(quant4_intra_c, quant4_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
|
|
if (cpu_flags & XVID_CPU_MMXEXT) |
|
|
test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags); |
|
|
#endif |
|
|
|
|
|
/* Inter quantization test */ |
|
|
printf("\n--- quant4 inter ---\n"); |
|
|
test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags); |
|
|
|
|
|
#if defined(ARCH_IS_IA32) |
|
|
if (cpu_flags & XVID_CPU_MMX) |
|
|
test_quant(quant4_inter_c, quant4_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
|
|
if (cpu_flags & XVID_CPU_MMXEXT) |
|
|
test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags); |
|
|
#endif |
|
|
|
|
|
/* Intra dequantization test */ |
|
|
printf("\n--- dequant4 intra ---\n"); |
|
|
test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
|
|
|
|
|
#if defined(ARCH_IS_IA32) |
|
|
if (cpu_flags & XVID_CPU_MMX) |
|
|
test_quant(dequant4_intra_c, dequant4_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
|
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
|
|
test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
|
|
#endif |
|
|
|
|
|
/* Inter dequantization test */ |
|
|
printf("\n--- dequant4 inter ---\n"); |
|
|
test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags); |
|
|
|
|
|
#if defined(ARCH_IS_IA32) |
|
|
if (cpu_flags & XVID_CPU_MMX) |
|
|
test_quant(dequant4_inter_c, dequant4_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
|
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
|
|
test_quant(dequant4_inter_c, dequant4_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
|
|
#endif |
|
|
|
|
|
emms(); |
|
|
|
|
|
return XVID_ERR_OK; |
|
|
} |
|
626 |
|
|
627 |
|
|
628 |
int |
int |
629 |
xvid_init(void *handle, |
xvid_global(void *handle, |
630 |
int opt, |
int opt, |
631 |
void *param1, |
void *param1, |
632 |
void *param2) |
void *param2) |
633 |
{ |
{ |
634 |
switch(opt) |
switch(opt) |
635 |
{ |
{ |
636 |
case XVID_INIT_INIT : |
case XVID_GBL_INIT : |
637 |
return xvid_init_init((XVID_INIT_PARAM*)param1); |
return xvid_gbl_init((xvid_gbl_init_t*)param1); |
638 |
|
|
639 |
case XVID_INIT_CONVERT : |
case XVID_GBL_INFO : |
640 |
return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1); |
return xvid_gbl_info((xvid_gbl_info_t*)param1); |
641 |
|
|
642 |
|
case XVID_GBL_CONVERT : |
643 |
|
return xvid_gbl_convert((xvid_gbl_convert_t*)param1); |
644 |
|
|
|
case XVID_INIT_TEST : |
|
|
{ |
|
|
ptr_t flags = (ptr_t)param1; |
|
|
return xvid_init_test((int)flags); |
|
|
} |
|
645 |
default : |
default : |
646 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
647 |
} |
} |
664 |
void *param2) |
void *param2) |
665 |
{ |
{ |
666 |
switch (opt) { |
switch (opt) { |
|
case XVID_DEC_DECODE: |
|
|
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2); |
|
|
|
|
667 |
case XVID_DEC_CREATE: |
case XVID_DEC_CREATE: |
668 |
return decoder_create((XVID_DEC_PARAM *) param1); |
return decoder_create((xvid_dec_create_t *) param1); |
669 |
|
|
670 |
case XVID_DEC_DESTROY: |
case XVID_DEC_DESTROY: |
671 |
return decoder_destroy((DECODER *) handle); |
return decoder_destroy((DECODER *) handle); |
672 |
|
|
673 |
|
case XVID_DEC_DECODE: |
674 |
|
return decoder_decode((DECODER *) handle, (xvid_dec_frame_t *) param1, (xvid_dec_stats_t*) param2); |
675 |
|
|
676 |
default: |
default: |
677 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
678 |
} |
} |
698 |
switch (opt) { |
switch (opt) { |
699 |
case XVID_ENC_ENCODE: |
case XVID_ENC_ENCODE: |
700 |
|
|
701 |
if (((Encoder *) handle)->mbParam.max_bframes >= 0) |
return enc_encode((Encoder *) handle, |
702 |
return encoder_encode_bframes((Encoder *) handle, |
(xvid_enc_frame_t *) param1, |
703 |
(XVID_ENC_FRAME *) param1, |
(xvid_enc_stats_t *) param2); |
|
(XVID_ENC_STATS *) param2); |
|
|
else |
|
|
return encoder_encode((Encoder *) handle, |
|
|
(XVID_ENC_FRAME *) param1, |
|
|
(XVID_ENC_STATS *) param2); |
|
704 |
|
|
705 |
case XVID_ENC_CREATE: |
case XVID_ENC_CREATE: |
706 |
return encoder_create((XVID_ENC_PARAM *) param1); |
return enc_create((xvid_enc_create_t *) param1); |
707 |
|
|
708 |
case XVID_ENC_DESTROY: |
case XVID_ENC_DESTROY: |
709 |
return encoder_destroy((Encoder *) handle); |
return enc_destroy((Encoder *) handle); |
710 |
|
|
711 |
default: |
default: |
712 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |