[svn] / branches / dev-api-4 / xvidcore / examples / xvid_bench.c Repository:
ViewVC logotype

Diff of /branches/dev-api-4/xvidcore/examples/xvid_bench.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/xvidcore/examples/xvid_bench.c revision 860, Sun Feb 16 05:11:39 2003 UTC branches/dev-api-4/xvidcore/examples/xvid_bench.c revision 1122, Wed Aug 13 11:44:02 2003 UTC
# Line 1  Line 1 
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
# Line 14  Line 17 
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: xvid_bench.c,v 1.9.2.4 2003-08-13 11:43:45 edgomez Exp $
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
# Line 27  Line 32 
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>
39  #include <string.h>    // for memset  #include <string.h>    /* for memset */
40  #include <assert.h>  #include <assert.h>
41    
42  #ifndef WIN32  #ifndef WIN32
43  #include <sys/time.h>   // for gettimeofday  #include <sys/time.h>   /* for gettimeofday */
44  #else  #else
45  #include <time.h>  #include <time.h>
46  #endif  #endif
# Line 67  Line 68 
68  #define M_PI            3.14159265358979323846  #define M_PI            3.14159265358979323846
69  #endif  #endif
70    
71  const int speed_ref = 100;  // on slow machines, decrease this value  const int speed_ref = 100;  /* on slow machines, decrease this value */
72    
73  /*********************************************************************  /*********************************************************************
74   * misc   * misc
# Line 114  Line 115 
115    
116  CPU cpu_list[] =  CPU cpu_list[] =
117  { { "PLAINC", 0 }  { { "PLAINC", 0 }
118    #ifdef ARCH_IS_IA32
119  , { "MMX   ", XVID_CPU_MMX }  , { "MMX   ", XVID_CPU_MMX }
120  , { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX }  , { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX }
121  , { "SSE2  ", XVID_CPU_SSE2 | XVID_CPU_MMX }  , { "SSE2  ", XVID_CPU_SSE2 | XVID_CPU_MMX }
122  , { "3DNOW ", XVID_CPU_3DNOW }  , { "3DNOW ", XVID_CPU_3DNOW }
123  , { "3DNOWE", XVID_CPU_3DNOWEXT }  , { "3DNOWE", XVID_CPU_3DNOWEXT }
124  , { "IA64  ", XVID_CPU_IA64 }  #endif
125    //, { "IA64  ", XVID_CPU_IA64 }
126  //, { "TSC   ", XVID_CPU_TSC }  //, { "TSC   ", XVID_CPU_TSC }
127  , { 0, 0 } }    , { 0, 0 } };
128    
129  , cpu_short_list[] =  CPU  cpu_short_list[] =
130  { { "PLAINC", 0 }  { { "PLAINC", 0 }
131    #ifdef ARCH_IS_IA32
132  , { "MMX   ", XVID_CPU_MMX }  , { "MMX   ", XVID_CPU_MMX }
133  //, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX }  //, { "MMXEXT", XVID_CPU_MMXEXT | XVID_CPU_MMX }
134  , { "IA64  ", XVID_CPU_IA64 }  #endif
135  , { 0, 0 } }  //, { "IA64  ", XVID_CPU_IA64 }
136      , { 0, 0 } };
137    
138  , cpu_short_list2[] =  CPU cpu_short_list2[] =
139  { { "PLAINC", 0 }  { { "PLAINC", 0 }
140    #ifdef ARCH_IS_IA32
141  , { "MMX   ", XVID_CPU_MMX }  , { "MMX   ", XVID_CPU_MMX }
142  , { "SSE2  ", XVID_CPU_SSE2 | XVID_CPU_MMX }  , { "SSE2  ", XVID_CPU_SSE2 | XVID_CPU_MMX }
143    #endif
144  , { 0, 0 } };  , { 0, 0 } };
145    
146    
147  int init_cpu(CPU *cpu)  int init_cpu(CPU *cpu)
148  {  {
149    int xerr, cpu_type;    int xerr, cpu_type;
150    XVID_INIT_PARAM xinit;          xvid_gbl_init_t xinit;
151    
152    #ifdef ARCH_IS_IA32
153    cpu_type = check_cpu_features() & cpu->cpu;    cpu_type = check_cpu_features() & cpu->cpu;
154    #else
155            cpu_type = XVID_CPU_ASM;
156    #endif
157            memset(&xinit, 0, sizeof(xinit));
158    xinit.cpu_flags = cpu_type | XVID_CPU_FORCE;    xinit.cpu_flags = cpu_type | XVID_CPU_FORCE;
159    //    xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE;          xinit.version = XVID_VERSION;
160    xerr = xvid_init(NULL, 0, &xinit, NULL);          xerr = xvid_global(NULL, 0, &xinit, NULL);
161    if (cpu->cpu>0 && (cpu_type==0 || xerr!=XVID_ERR_OK)) {          if (cpu->cpu>0 && (cpu_type==0 || xerr==XVID_ERR_FAIL)) {
162      printf( "%s - skipped...\n", cpu->name );      printf( "%s - skipped...\n", cpu->name );
163      return 0;      return 0;
164    }    }
# Line 302  Line 314 
314    const int nb_tests = 2000*speed_ref;    const int nb_tests = 2000*speed_ref;
315    CPU *cpu;    CPU *cpu;
316    const uint8_t Src0[16*9] = {    const uint8_t Src0[16*9] = {
317          // try to have every possible combinaison of rounding...                  /* try to have every possible combinaison of rounding... */
318        0, 0, 1, 0, 2, 0, 3, 0, 4             ,0,0,0, 0,0,0,0        0, 0, 1, 0, 2, 0, 3, 0, 4             ,0,0,0, 0,0,0,0
319      , 0, 1, 1, 1, 2, 1, 3, 1, 3             ,0,0,0, 0,0,0,0      , 0, 1, 1, 1, 2, 1, 3, 1, 3             ,0,0,0, 0,0,0,0
320      , 0, 2, 1, 2, 2, 2, 3, 2, 2             ,0,0,0, 0,0,0,0      , 0, 2, 1, 2, 2, 2, 3, 2, 2             ,0,0,0, 0,0,0,0
# Line 352  Line 364 
364      if (iCrc!=8103) printf( "*** CRC ERROR! ***\n" );      if (iCrc!=8103) printf( "*** CRC ERROR! ***\n" );
365    
366    
367         // this is a new function, as of 06.06.2002                  /* this is a new function, as of 06.06.2002 */
368  #if 0  #if 0
369      TEST_MB2(interpolate8x8_avrg);      TEST_MB2(interpolate8x8_avrg);
370      printf( "%s - interpolate8x8_c %.3f usec       iCrc=%d\n", cpu->name, t, iCrc );      printf( "%s - interpolate8x8_c %.3f usec       iCrc=%d\n", cpu->name, t, iCrc );
# Line 528  Line 540 
540    
541    printf( "\n =====  test quant =====\n" );    printf( "\n =====  test quant =====\n" );
542    
543      // we deliberately enfringe the norm's specified range [-127,127],  /* we deliberately enfringe the norm's specified range [-127,127], */
544      // to test the robustness of the iquant module  /* to test the robustness of the iquant module */
545    for(i=0; i<64; ++i) {    for(i=0; i<64; ++i) {
546      Src[i] = 1 + (i-32) * (i&6);      Src[i] = 1 + (i-32) * (i&6);
547      Dst[i] = 0;      Dst[i] = 0;
# Line 616  Line 628 
628    printf( "\n =====  test cbp =====\n" );    printf( "\n =====  test cbp =====\n" );
629    
630    for(i=0; i<6*64; ++i) {    for(i=0; i<6*64; ++i) {
631      Src1[i] = (i*i*3/8192)&(i/64)&1;  // 'random'                  Src1[i] = (i*i*3/8192)&(i/64)&1;  /* 'random' */
632      Src2[i] = (i<3*64);               // half-full                  Src2[i] = (i<3*64);               /* half-full */
633      Src3[i] = ((i+32)>3*64);      Src3[i] = ((i+32)>3*64);
634      Src4[i] = (i==(3*64+2) || i==(5*64+9));      Src4[i] = (i==(3*64+2) || i==(5*64+9));
635    }    }
# Line 772  Line 784 
784    }    }
785  }  }
786    
787  //////////////////////////////////////////////////////////  ///* ////////////////////////////////////////////////////// */
788  /* Pseudo-random generator specified by IEEE 1180 */  /* Pseudo-random generator specified by IEEE 1180 */
789    
790  static long ieee_seed = 1;  static long ieee_seed = 1;
# Line 859  Line 871 
871    static const double ILimits[5] = { 1., 0.06, 0.02, 0.015, 0.0015 };    static const double ILimits[5] = { 1., 0.06, 0.02, 0.015, 0.0015 };
872    int Loops = 10000;    int Loops = 10000;
873    int i, m, n;    int i, m, n;
874    short Blk0[64];     // reference          short Blk0[64];     /* reference */
875    short Blk[64], iBlk[64];    short Blk[64], iBlk[64];
876    short Ref_FDCT[64];    short Ref_FDCT[64];
877    short Ref_IDCT[64];    short Ref_IDCT[64];
878    
879    STATS_8x8 FStats; // forward dct stats          STATS_8x8 FStats; /* forward dct stats */
880    STATS_8x8 IStats; // inverse dct stats          STATS_8x8 IStats; /* inverse dct stats */
881    
882    CPU *cpu;    CPU *cpu;
883    
# Line 888  Line 900 
900        for(i=0; i<64; ++i)        for(i=0; i<64; ++i)
901          Blk0[i] = (short)ieee_rand(Min,Max) * Sign;          Blk0[i] = (short)ieee_rand(Min,Max) * Sign;
902    
903          // hmm, I'm not quite sure this is exactly                          /* hmm, I'm not quite sure this is exactly */
904          // the tests described in the norm. check...                          /* the tests described in the norm. check... */
905    
906        memcpy(Ref_FDCT, Blk0, 64*sizeof(short));        memcpy(Ref_FDCT, Blk0, 64*sizeof(short));
907        ref_fdct(Ref_FDCT);        ref_fdct(Ref_FDCT);
# Line 916  Line 928 
928    
929      printf( "\n  -- FDCT report --\n" );      printf( "\n  -- FDCT report --\n" );
930  //    print_stats(&FStats);  //    print_stats(&FStats);
931      report_stats(&FStats, 0); // so far I know, IEEE1180 says nothing for fdct                  report_stats(&FStats, 0); /* so far I know, IEEE1180 says nothing for fdct */
932    
933      for(i=0; i<64; i++) Blk[i] = 0;      for(i=0; i<64; i++) Blk[i] = 0;
934      emms(); fdct(Blk); emms();      emms(); fdct(Blk); emms();
# Line 938  Line 950 
950    
951  void test_dct_saturation(int Min, int Max)  void test_dct_saturation(int Min, int Max)
952  {  {
953      // test behaviour on input range fringe  /* test behaviour on input range fringe */
954    
955    int i, n, p;    int i, n, p;
956    CPU *cpu;    CPU *cpu;
957  //  const short IDCT_MAX =  2047;  // 12bits input  //  const short IDCT_MAX =  2047;  /* 12bits input */
958  //  const short IDCT_MIN = -2048;  //  const short IDCT_MIN = -2048;
959  //  const short IDCT_OUT =   256;  // 9bits ouput  //  const short IDCT_OUT =   256;  /* 9bits ouput */
960    const int Partitions = 4;    const int Partitions = 4;
961    const int Loops = 10000 / Partitions;    const int Loops = 10000 / Partitions;
962    
# Line 961  Line 973 
973      printf( "\n===== IEEE test for %s Min=%d Max=%d =====\n",      printf( "\n===== IEEE test for %s Min=%d Max=%d =====\n",
974        cpu->name, Min, Max );        cpu->name, Min, Max );
975    
976                // FDCT tests //                  /* FDCT tests // */
977    
978      init_stats(&Stats);      init_stats(&Stats);
979    
980        // test each computation channels separately                  /* test each computation channels separately */
981      for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? Max : 0;      for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? Max : 0;
982      ref_fdct(Blk0);      ref_fdct(Blk0);
983      emms(); fdct(Blk); emms();      emms(); fdct(Blk); emms();
# Line 976  Line 988 
988      emms(); fdct(Blk); emms();      emms(); fdct(Blk); emms();
989      store_stats(&Stats, Blk, Blk0);      store_stats(&Stats, Blk, Blk0);
990    
991        // randomly saturated inputs                  /* randomly saturated inputs */
992      for(p=0; p<Partitions; ++p)      for(p=0; p<Partitions; ++p)
993      {      {
994        for(n=0; n<Loops; ++n)        for(n=0; n<Loops; ++n)
# Line 992  Line 1004 
1004      report_stats(&Stats, 0);      report_stats(&Stats, 0);
1005    
1006    
1007                // IDCT tests //                  /* IDCT tests // */
1008  #if 0  #if 0
1009        // no finished yet                  /* no finished yet */
1010    
1011      init_stats(&Stats);      init_stats(&Stats);
1012    
1013      // test each computation channel separately  /* test each computation channel separately */
1014      for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? IDCT_MAX : 0;      for(i=0; i<64; i++) Blk[i] = Blk0[i] = ((i/8)==(i%8)) ? IDCT_MAX : 0;
1015      ref_idct(Blk0);      ref_idct(Blk0);
1016      emms(); idct(Blk); emms();      emms(); idct(Blk); emms();
# Line 1011  Line 1023 
1023      for(i=0; i<64; i++) { CLAMP(Blk0[i], IDCT_OUT); CLAMP(Blk[i], IDCT_OUT); }      for(i=0; i<64; i++) { CLAMP(Blk0[i], IDCT_OUT); CLAMP(Blk[i], IDCT_OUT); }
1024      store_stats(&Stats, Blk, Blk0);      store_stats(&Stats, Blk, Blk0);
1025    
1026        // randomly saturated inputs                  /* randomly saturated inputs */
1027      for(p=0; p<Partitions; ++p)      for(p=0; p<Partitions; ++p)
1028      {      {
1029        for(n=0; n<Loops; ++n)        for(n=0; n<Loops; ++n)
# Line 1041  Line 1053 
1053    FILE *f = 0;    FILE *f = 0;
1054    void *dechandle = 0;    void *dechandle = 0;
1055    int xerr;    int xerr;
1056          XVID_INIT_PARAM xinit;          xvid_gbl_init_t xinit;
1057          XVID_DEC_PARAM xparam;          xvid_dec_create_t xparam;
1058          XVID_DEC_FRAME xframe;          xvid_dec_frame_t xframe;
1059          double t = 0.;          double t = 0.;
1060          int nb = 0;          int nb = 0;
1061    uint8_t *buf = 0;    uint8_t *buf = 0;
# Line 1051  Line 1063 
1063    int buf_size, pos;    int buf_size, pos;
1064    uint32_t chksum = 0;    uint32_t chksum = 0;
1065    
1066            memset(&xinit, 0, sizeof(xinit));
1067          xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE;          xinit.cpu_flags = XVID_CPU_MMX | XVID_CPU_FORCE;
1068          xvid_init(NULL, 0, &xinit, NULL);          xinit.version = XVID_VERSION;
1069          printf( "API version: %d, core build:%d\n", xinit.api_version, xinit.core_build);          xvid_global(NULL, 0, &xinit, NULL);
   
1070    
1071            memset(&xparam, 0, sizeof(xparam));
1072          xparam.width = width;          xparam.width = width;
1073          xparam.height = height;          xparam.height = height;
1074            xparam.version = XVID_VERSION;
1075          xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL);          xerr = xvid_decore(NULL, XVID_DEC_CREATE, &xparam, NULL);
1076          if (xerr!=XVID_ERR_OK) {          if (xerr==XVID_ERR_FAIL) {
1077            printf("can't init decoder (err=%d)\n", xerr);            printf("can't init decoder (err=%d)\n", xerr);
1078            return;            return;
1079          }          }
# Line 1080  Line 1094 
1094    }    }
1095    else printf( "Input size: %d\n", buf_size);    else printf( "Input size: %d\n", buf_size);
1096    
1097    buf = malloc(buf_size); // should be enuf'          buf = malloc(buf_size); /* should be enuf' */
1098    rgb_out = calloc(4, width*height);  // <-room for _RGB24          rgb_out = calloc(4, width*height);  /* <-room for _RGB24 */
1099    if (buf==0 || rgb_out==0) {    if (buf==0 || rgb_out==0) {
1100      printf( "malloc failed!\n" );      printf( "malloc failed!\n" );
1101      goto End;      goto End;
# Line 1096  Line 1110 
1110    pos = 0;    pos = 0;
1111    t = -gettime_usec();    t = -gettime_usec();
1112    while(1) {    while(1) {
1113                    memset(&xframe, 0, sizeof(xframe));
1114                    xframe.version = XVID_VERSION;
1115      xframe.bitstream = buf + pos;      xframe.bitstream = buf + pos;
1116      xframe.length = buf_size - pos;      xframe.length = buf_size - pos;
1117      xframe.image = rgb_out;                  xframe.output.plane[0] = rgb_out;
1118      xframe.stride = width;                  xframe.output.stride[0] = width;
1119      xframe.colorspace = XVID_CSP_RGB24;                  xframe.output.csp = XVID_CSP_BGR;
1120      xerr = xvid_decore(dechandle, XVID_DEC_DECODE, &xframe, 0);      xerr = xvid_decore(dechandle, XVID_DEC_DECODE, &xframe, 0);
1121      nb++;      nb++;
1122      pos += xframe.length;      pos += xframe.length;
# Line 1111  Line 1127 
1127      }      }
1128      if (pos==buf_size)      if (pos==buf_size)
1129        break;        break;
1130      if (xerr!=XVID_ERR_OK) {                  if (xerr==XVID_ERR_FAIL) {
1131            printf("decoding failed for frame #%d (err=%d)!\n", nb, xerr);            printf("decoding failed for frame #%d (err=%d)!\n", nb, xerr);
1132            break;            break;
1133          }          }
# Line 1127  Line 1143 
1143    if (buf!=0) free(buf);    if (buf!=0) free(buf);
1144    if (dechandle!=0) {    if (dechandle!=0) {
1145      xerr= xvid_decore(dechandle, XVID_DEC_DESTROY, NULL, NULL);      xerr= xvid_decore(dechandle, XVID_DEC_DESTROY, NULL, NULL);
1146      if (xerr!=XVID_ERR_OK)                  if (xerr==XVID_ERR_FAIL)
1147              printf("destroy-decoder failed (err=%d)!\n", xerr);              printf("destroy-decoder failed (err=%d)!\n", xerr);
1148    }    }
1149    if (f!=0) fclose(f);    if (f!=0) fclose(f);

Legend:
Removed from v.860  
changed lines
  Added in v.1122

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4