1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC - Unit tests and benches |
* XVID MPEG-4 VIDEO CODEC |
4 |
|
* - Unit tests and benches - |
5 |
|
* |
6 |
|
* Copyright(C) 2002 Pascal Massimino <skal@planet-d.net> |
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 |
17 |
* |
* |
18 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
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., 675 Mass Ave, Cambridge, MA 02139, USA. |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
|
* |
22 |
|
* $Id$ |
23 |
* |
* |
24 |
*************************************************************************/ |
****************************************************************************/ |
25 |
|
|
26 |
/************************************************************************ |
/***************************************************************************** |
27 |
* |
* |
28 |
* 'Reference' output is at the end of file. |
* 'Reference' output is at the end of file. |
29 |
* Don't take the checksums and crc too seriouly, they aren't |
* Don't take the checksums and crc too seriouly, they aren't |
32 |
* compiles with something like: |
* compiles with something like: |
33 |
* gcc -o xvid_bench xvid_bench.c -I../src/ -lxvidcore -lm |
* gcc -o xvid_bench xvid_bench.c -I../src/ -lxvidcore -lm |
34 |
* |
* |
35 |
* History: |
****************************************************************************/ |
|
* |
|
|
* 06.06.2002 initial coding -Skal- |
|
|
* |
|
|
*************************************************************************/ |
|
36 |
|
|
37 |
#include <stdio.h> |
#include <stdio.h> |
38 |
#include <stdlib.h> |
#include <stdlib.h> |
54 |
#include "image/colorspace.h" |
#include "image/colorspace.h" |
55 |
#include "image/interpolate8x8.h" |
#include "image/interpolate8x8.h" |
56 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
57 |
#include "quant/quant_h263.h" |
#include "quant/quant.h" |
|
#include "quant/quant_mpeg4.h" |
|
58 |
#include "motion/sad.h" |
#include "motion/sad.h" |
59 |
#include "utils/emms.h" |
#include "utils/emms.h" |
60 |
#include "utils/timer.h" |
#include "utils/timer.h" |
114 |
|
|
115 |
CPU cpu_list[] = |
CPU cpu_list[] = |
116 |
{ { "PLAINC", 0 } |
{ { "PLAINC", 0 } |
117 |
|
#ifdef ARCH_IS_IA32 |
118 |
, { "MMX ", XVID_CPU_MMX } |
, { "MMX ", XVID_CPU_MMX } |
119 |
, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX } |
, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX } |
120 |
, { "SSE2 ", XVID_CPU_SSE2 | XVID_CPU_MMX } |
, { "SSE2 ", XVID_CPU_SSE2 | XVID_CPU_MMX } |
121 |
, { "3DNOW ", XVID_CPU_3DNOW } |
, { "3DNOW ", XVID_CPU_3DNOW } |
122 |
, { "3DNOWE", XVID_CPU_3DNOWEXT } |
, { "3DNOWE", XVID_CPU_3DNOWEXT } |
123 |
, { "IA64 ", XVID_CPU_IA64 } |
#endif |
124 |
|
//, { "IA64 ", XVID_CPU_IA64 } |
125 |
//, { "TSC ", XVID_CPU_TSC } |
//, { "TSC ", XVID_CPU_TSC } |
126 |
, { 0, 0 } } |
, { 0, 0 } }; |
127 |
|
|
128 |
, cpu_short_list[] = |
CPU cpu_short_list[] = |
129 |
{ { "PLAINC", 0 } |
{ { "PLAINC", 0 } |
130 |
|
#ifdef ARCH_IS_IA32 |
131 |
, { "MMX ", XVID_CPU_MMX } |
, { "MMX ", XVID_CPU_MMX } |
132 |
//, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX } |
//, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX } |
133 |
, { "IA64 ", XVID_CPU_IA64 } |
#endif |
134 |
, { 0, 0 } } |
//, { "IA64 ", XVID_CPU_IA64 } |
135 |
|
, { 0, 0 } }; |
136 |
|
|
137 |
, cpu_short_list2[] = |
CPU cpu_short_list2[] = |
138 |
{ { "PLAINC", 0 } |
{ { "PLAINC", 0 } |
139 |
|
#ifdef ARCH_IS_IA32 |
140 |
, { "MMX ", XVID_CPU_MMX } |
, { "MMX ", XVID_CPU_MMX } |
141 |
, { "SSE2 ", XVID_CPU_SSE2 | XVID_CPU_MMX } |
, { "SSE2 ", XVID_CPU_SSE2 | XVID_CPU_MMX } |
142 |
|
#endif |
143 |
, { 0, 0 } }; |
, { 0, 0 } }; |
144 |
|
|
145 |
|
|
146 |
int init_cpu(CPU *cpu) |
int init_cpu(CPU *cpu) |
147 |
{ |
{ |
148 |
int xerr, cpu_type; |
int xerr, cpu_type; |
149 |
XVID_INIT_PARAM xinit; |
xvid_gbl_init_t xinit; |
150 |
|
|
151 |
cpu_type = check_cpu_features() & cpu->cpu; |
memset(&xinit, 0, sizeof(xinit)); |
152 |
xinit.cpu_flags = cpu_type | XVID_CPU_FORCE; |
xinit.cpu_flags = cpu->cpu | XVID_CPU_FORCE; |
153 |
/* xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE; */ |
xinit.version = XVID_VERSION; |
154 |
xerr = xvid_init(NULL, 0, &xinit, NULL); |
xerr = xvid_global(NULL, 0, &xinit, NULL); |
155 |
if (cpu->cpu>0 && (cpu_type==0 || xerr!=XVID_ERR_OK)) { |
if (cpu->cpu>0 && xerr==XVID_ERR_FAIL) { |
156 |
printf( "%s - skipped...\n", cpu->name ); |
printf( "%s - skipped...\n", cpu->name ); |
157 |
return 0; |
return 0; |
158 |
} |
} |
446 |
|
|
447 |
printf( "\n === test transfer ===\n" ); |
printf( "\n === test transfer ===\n" ); |
448 |
|
|
449 |
for(cpu = cpu_short_list; cpu->name!=0; ++cpu) |
for(cpu = cpu_list; cpu->name!=0; ++cpu) |
450 |
{ |
{ |
451 |
double t, overhead; |
double t, overhead; |
452 |
int tst, s; |
int tst, s; |
541 |
Dst[i] = 0; |
Dst[i] = 0; |
542 |
} |
} |
543 |
|
|
544 |
for(cpu = cpu_short_list; cpu->name!=0; ++cpu) |
for(cpu = cpu_list; cpu->name!=0; ++cpu) |
545 |
{ |
{ |
546 |
double t, overhead; |
double t, overhead; |
547 |
int tst, q; |
int tst, q; |
560 |
overhead += gettime_usec(); |
overhead += gettime_usec(); |
561 |
|
|
562 |
#if 1 |
#if 1 |
563 |
TEST_QUANT2(quant4_intra, Dst, Src); |
TEST_QUANT2(quant_mpeg_intra, Dst, Src); |
564 |
printf( "%s - quant4_intra %.3f usec crc=%d\n", cpu->name, t, s ); |
printf( "%s - quant_mpeg_intra %.3f usec crc=%d\n", cpu->name, t, s ); |
565 |
if (s!=29809) printf( "*** CRC ERROR! ***\n" ); |
if (s!=29809) printf( "*** CRC ERROR! ***\n" ); |
566 |
|
|
567 |
TEST_QUANT(quant4_inter, Dst, Src); |
TEST_QUANT(quant_mpeg_inter, Dst, Src); |
568 |
printf( "%s - quant4_inter %.3f usec crc=%d\n", cpu->name, t, s ); |
printf( "%s - quant_mpeg_inter %.3f usec crc=%d\n", cpu->name, t, s ); |
569 |
if (s!=12574) printf( "*** CRC ERROR! ***\n" ); |
if (s!=12574) printf( "*** CRC ERROR! ***\n" ); |
570 |
#endif |
#endif |
571 |
#if 1 |
#if 1 |
572 |
TEST_QUANT2(dequant4_intra, Dst, Src); |
TEST_QUANT2(dequant_mpeg_intra, Dst, Src); |
573 |
printf( "%s - dequant4_intra %.3f usec crc=%d\n", cpu->name, t, s ); |
printf( "%s - dequant_mpeg_intra %.3f usec crc=%d\n", cpu->name, t, s ); |
574 |
if (s!=24052) printf( "*** CRC ERROR! ***\n" ); |
if (s!=24052) printf( "*** CRC ERROR! ***\n" ); |
575 |
|
|
576 |
TEST_QUANT(dequant4_inter, Dst, Src); |
TEST_QUANT(dequant_mpeg_inter, Dst, Src); |
577 |
printf( "%s - dequant4_inter %.3f usec crc=%d\n", cpu->name, t, s ); |
printf( "%s - dequant_mpeg_inter %.3f usec crc=%d\n", cpu->name, t, s ); |
578 |
if (s!=63847) printf( "*** CRC ERROR! ***\n" ); |
if (s!=63847) printf( "*** CRC ERROR! ***\n" ); |
579 |
#endif |
#endif |
580 |
#if 1 |
#if 1 |
581 |
TEST_QUANT2(quant_intra, Dst, Src); |
TEST_QUANT2(quant_h263_intra, Dst, Src); |
582 |
printf( "%s - quant_intra %.3f usec crc=%d\n", cpu->name, t, s ); |
printf( "%s - quant_h263_intra %.3f usec crc=%d\n", cpu->name, t, s ); |
583 |
if (s!=25662) printf( "*** CRC ERROR! ***\n" ); |
if (s!=25662) printf( "*** CRC ERROR! ***\n" ); |
584 |
|
|
585 |
TEST_QUANT(quant_inter, Dst, Src); |
TEST_QUANT(quant_h263_inter, Dst, Src); |
586 |
printf( "%s - quant_inter %.3f usec crc=%d\n", cpu->name, t, s ); |
printf( "%s - quant_h263_inter %.3f usec crc=%d\n", cpu->name, t, s ); |
587 |
if (s!=23972) printf( "*** CRC ERROR! ***\n" ); |
if (s!=23972) printf( "*** CRC ERROR! ***\n" ); |
588 |
#endif |
#endif |
589 |
#if 1 |
#if 1 |
590 |
TEST_QUANT2(dequant_intra, Dst, Src); |
TEST_QUANT2(dequant_h263_intra, Dst, Src); |
591 |
printf( "%s - dequant_intra %.3f usec crc=%d\n", cpu->name, t, s ); |
printf( "%s - dequant_h263_intra %.3f usec crc=%d\n", cpu->name, t, s ); |
592 |
if (s!=49900) printf( "*** CRC ERROR! ***\n" ); |
if (s!=49900) printf( "*** CRC ERROR! ***\n" ); |
593 |
|
|
594 |
TEST_QUANT(dequant_inter, Dst, Src); |
TEST_QUANT(dequant_h263_inter, Dst, Src); |
595 |
printf( "%s - dequant_inter %.3f usec crc=%d\n", cpu->name, t, s ); |
printf( "%s - dequant_h263_inter %.3f usec crc=%d\n", cpu->name, t, s ); |
596 |
if (s!=48899) printf( "*** CRC ERROR! ***\n" ); |
if (s!=48899) printf( "*** CRC ERROR! ***\n" ); |
597 |
#endif |
#endif |
598 |
printf( " --- \n" ); |
printf( " --- \n" ); |
628 |
Src4[i] = (i==(3*64+2) || i==(5*64+9)); |
Src4[i] = (i==(3*64+2) || i==(5*64+9)); |
629 |
} |
} |
630 |
|
|
631 |
for(cpu = cpu_short_list2; cpu->name!=0; ++cpu) |
for(cpu = cpu_list; cpu->name!=0; ++cpu) |
632 |
{ |
{ |
633 |
double t; |
double t; |
634 |
int tst, cbp; |
int tst, cbp; |
1047 |
FILE *f = 0; |
FILE *f = 0; |
1048 |
void *dechandle = 0; |
void *dechandle = 0; |
1049 |
int xerr; |
int xerr; |
1050 |
XVID_INIT_PARAM xinit; |
xvid_gbl_init_t xinit; |
1051 |
XVID_DEC_PARAM xparam; |
xvid_dec_create_t xparam; |
1052 |
XVID_DEC_FRAME xframe; |
xvid_dec_frame_t xframe; |
1053 |
double t = 0.; |
double t = 0.; |
1054 |
int nb = 0; |
int nb = 0; |
1055 |
uint8_t *buf = 0; |
uint8_t *buf = 0; |
1057 |
int buf_size, pos; |
int buf_size, pos; |
1058 |
uint32_t chksum = 0; |
uint32_t chksum = 0; |
1059 |
|
|
1060 |
|
memset(&xinit, 0, sizeof(xinit)); |
1061 |
xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE; |
xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE; |
1062 |
xvid_init(NULL, 0, &xinit, NULL); |
xinit.version = XVID_VERSION; |
1063 |
printf( "API version: %d, core build:%d\n", xinit.api_version, xinit.core_build); |
xvid_global(NULL, 0, &xinit, NULL); |
|
|
|
1064 |
|
|
1065 |
|
memset(&xparam, 0, sizeof(xparam)); |
1066 |
xparam.width = width; |
xparam.width = width; |
1067 |
xparam.height = height; |
xparam.height = height; |
1068 |
|
xparam.version = XVID_VERSION; |
1069 |
xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL); |
xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL); |
1070 |
if (xerr!=XVID_ERR_OK) { |
if (xerr==XVID_ERR_FAIL) { |
1071 |
printf("can't init decoder (err=%d)\n", xerr); |
printf("can't init decoder (err=%d)\n", xerr); |
1072 |
return; |
return; |
1073 |
} |
} |
1104 |
pos = 0; |
pos = 0; |
1105 |
t = -gettime_usec(); |
t = -gettime_usec(); |
1106 |
while(1) { |
while(1) { |
1107 |
|
memset(&xframe, 0, sizeof(xframe)); |
1108 |
|
xframe.version = XVID_VERSION; |
1109 |
xframe.bitstream = buf + pos; |
xframe.bitstream = buf + pos; |
1110 |
xframe.length = buf_size - pos; |
xframe.length = buf_size - pos; |
1111 |
xframe.image = rgb_out; |
xframe.output.plane[0] = rgb_out; |
1112 |
xframe.stride = width; |
xframe.output.stride[0] = width; |
1113 |
xframe.colorspace = XVID_CSP_RGB24; |
xframe.output.csp = XVID_CSP_BGR; |
1114 |
xerr = xvid_decore(dechandle, XVID_DEC_DECODE, &xframe, 0); |
xerr = xvid_decore(dechandle, XVID_DEC_DECODE, &xframe, 0); |
1115 |
nb++; |
nb++; |
1116 |
pos += xframe.length; |
pos += xframe.length; |
1121 |
} |
} |
1122 |
if (pos==buf_size) |
if (pos==buf_size) |
1123 |
break; |
break; |
1124 |
if (xerr!=XVID_ERR_OK) { |
if (xerr==XVID_ERR_FAIL) { |
1125 |
printf("decoding failed for frame #%d (err=%d)!\n", nb, xerr); |
printf("decoding failed for frame #%d (err=%d)!\n", nb, xerr); |
1126 |
break; |
break; |
1127 |
} |
} |
1137 |
if (buf!=0) free(buf); |
if (buf!=0) free(buf); |
1138 |
if (dechandle!=0) { |
if (dechandle!=0) { |
1139 |
xerr= xvid_decore(dechandle, XVID_DEC_DESTROY, NULL, NULL); |
xerr= xvid_decore(dechandle, XVID_DEC_DESTROY, NULL, NULL); |
1140 |
if (xerr!=XVID_ERR_OK) |
if (xerr==XVID_ERR_FAIL) |
1141 |
printf("destroy-decoder failed (err=%d)!\n", xerr); |
printf("destroy-decoder failed (err=%d)!\n", xerr); |
1142 |
} |
} |
1143 |
if (f!=0) fclose(f); |
if (f!=0) fclose(f); |
1153 |
|
|
1154 |
printf( "\n ===== (de)quant4_intra saturation bug? =====\n" ); |
printf( "\n ===== (de)quant4_intra saturation bug? =====\n" ); |
1155 |
|
|
1156 |
for(cpu = cpu_short_list; cpu->name!=0; ++cpu) |
for(cpu = cpu_list; cpu->name!=0; ++cpu) |
1157 |
{ |
{ |
1158 |
int i; |
int i; |
1159 |
int16_t Src[8*8], Dst[8*8]; |
int16_t Src[8*8], Dst[8*8]; |
1163 |
|
|
1164 |
for(i=0; i<64; ++i) Src[i] = i-32; |
for(i=0; i<64; ++i) Src[i] = i-32; |
1165 |
set_intra_matrix( get_default_intra_matrix() ); |
set_intra_matrix( get_default_intra_matrix() ); |
1166 |
dequant4_intra(Dst, Src, 31, 5); |
dequant_mpeg_intra(Dst, Src, 31, 5); |
1167 |
printf( "dequant4_intra with CPU=%s: ", cpu->name); |
printf( "dequant_mpeg_intra with CPU=%s: ", cpu->name); |
1168 |
printf( " Out[]= " ); |
printf( " Out[]= " ); |
1169 |
for(i=0; i<64; ++i) printf( "[%d]", Dst[i]); |
for(i=0; i<64; ++i) printf( "[%d]", Dst[i]); |
1170 |
printf( "\n" ); |
printf( "\n" ); |
1172 |
|
|
1173 |
printf( "\n ===== (de)quant4_inter saturation bug? =====\n" ); |
printf( "\n ===== (de)quant4_inter saturation bug? =====\n" ); |
1174 |
|
|
1175 |
for(cpu = cpu_short_list; cpu->name!=0; ++cpu) |
for(cpu = cpu_list; cpu->name!=0; ++cpu) |
1176 |
{ |
{ |
1177 |
int i; |
int i; |
1178 |
int16_t Src[8*8], Dst[8*8]; |
int16_t Src[8*8], Dst[8*8]; |
1182 |
|
|
1183 |
for(i=0; i<64; ++i) Src[i] = i-32; |
for(i=0; i<64; ++i) Src[i] = i-32; |
1184 |
set_inter_matrix( get_default_inter_matrix() ); |
set_inter_matrix( get_default_inter_matrix() ); |
1185 |
dequant4_inter(Dst, Src, 31); |
dequant_mpeg_inter(Dst, Src, 31); |
1186 |
printf( "dequant4_inter with CPU=%s: ", cpu->name); |
printf( "dequant_mpeg_inter with CPU=%s: ", cpu->name); |
1187 |
printf( " Out[]= " ); |
printf( " Out[]= " ); |
1188 |
for(i=0; i<64; ++i) printf( "[%d]", Dst[i]); |
for(i=0; i<64; ++i) printf( "[%d]", Dst[i]); |
1189 |
printf( "\n" ); |
printf( "\n" ); |
1197 |
|
|
1198 |
printf( "\n ===== fdct/idct precision diffs =====\n" ); |
printf( "\n ===== fdct/idct precision diffs =====\n" ); |
1199 |
|
|
1200 |
for(cpu = cpu_short_list; cpu->name!=0; ++cpu) |
for(cpu = cpu_list; cpu->name!=0; ++cpu) |
1201 |
{ |
{ |
1202 |
int i; |
int i; |
1203 |
|
|
1250 |
|
|
1251 |
for(q=1; q<=max_Q; ++q) { |
for(q=1; q<=max_Q; ++q) { |
1252 |
emms(); |
emms(); |
1253 |
quant4_inter( Dst, Src, q ); |
quant_mpeg_inter( Dst, Src, q ); |
1254 |
emms(); |
emms(); |
1255 |
for(s=0, i=0; i<64; ++i) s+=((uint16_t)Dst[i])^i; |
for(s=0, i=0; i<64; ++i) s+=((uint16_t)Dst[i])^i; |
1256 |
Crcs_Inter[n][q] = s; |
Crcs_Inter[n][q] = s; |
1280 |
|
|
1281 |
for(q=1; q<=max_Q; ++q) { |
for(q=1; q<=max_Q; ++q) { |
1282 |
emms(); |
emms(); |
1283 |
quant4_intra( Dst, Src, q, q); |
quant_mpeg_intra( Dst, Src, q, q); |
1284 |
emms(); |
emms(); |
1285 |
for(s=0, i=0; i<64; ++i) s+=((uint16_t)Dst[i])^i; |
for(s=0, i=0; i<64; ++i) s+=((uint16_t)Dst[i])^i; |
1286 |
Crcs_Intra[n][q] = s; |
Crcs_Intra[n][q] = s; |