00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00026 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include <string.h>
00029 
00030 #include "config.h"
00031 #include "dsputil.h"
00032 #include "libavutil/internal.h"
00033 #include "libavutil/lfg.h"
00034 #include "libavutil/mem.h"
00035 #include "libavutil/time.h"
00036 
00037 #undef printf
00038 
00039 #define WIDTH 64
00040 #define HEIGHT 64
00041 
00042 static uint8_t img1[WIDTH * HEIGHT];
00043 static uint8_t img2[WIDTH * HEIGHT];
00044 
00045 static void fill_random(uint8_t *tab, int size)
00046 {
00047     int i;
00048     AVLFG prng;
00049 
00050     av_lfg_init(&prng, 1);
00051     for(i=0;i<size;i++) {
00052         tab[i] = av_lfg_get(&prng) % 256;
00053     }
00054 }
00055 
00056 static void help(void)
00057 {
00058     printf("motion-test [-h]\n"
00059            "test motion implementations\n");
00060 }
00061 
00062 #define NB_ITS 500
00063 
00064 int dummy;
00065 
00066 static void test_motion(const char *name,
00067                  me_cmp_func test_func, me_cmp_func ref_func)
00068 {
00069     int x, y, d1, d2, it;
00070     uint8_t *ptr;
00071     int64_t ti;
00072     printf("testing '%s'\n", name);
00073 
00074     
00075     for(it=0;it<20;it++) {
00076 
00077         fill_random(img1, WIDTH * HEIGHT);
00078         fill_random(img2, WIDTH * HEIGHT);
00079 
00080         for(y=0;y<HEIGHT-17;y++) {
00081             for(x=0;x<WIDTH-17;x++) {
00082                 ptr = img2 + y * WIDTH + x;
00083                 d1 = test_func(NULL, img1, ptr, WIDTH, 1);
00084                 d2 = ref_func(NULL, img1, ptr, WIDTH, 1);
00085                 if (d1 != d2) {
00086                     printf("error: mmx=%d c=%d\n", d1, d2);
00087                 }
00088             }
00089         }
00090     }
00091     emms_c();
00092 
00093     
00094     ti = av_gettime();
00095     d1 = 0;
00096     for(it=0;it<NB_ITS;it++) {
00097         for(y=0;y<HEIGHT-17;y++) {
00098             for(x=0;x<WIDTH-17;x++) {
00099                 ptr = img2 + y * WIDTH + x;
00100                 d1 += test_func(NULL, img1, ptr, WIDTH, 1);
00101             }
00102         }
00103     }
00104     emms_c();
00105     dummy = d1; 
00106     ti = av_gettime() - ti;
00107 
00108     printf("  %0.0f kop/s\n",
00109            (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
00110            (double)(ti / 1000.0));
00111 }
00112 
00113 
00114 int main(int argc, char **argv)
00115 {
00116     AVCodecContext *ctx;
00117     int c;
00118     DSPContext cctx, mmxctx;
00119     int flags[2] = { AV_CPU_FLAG_MMX, AV_CPU_FLAG_MMXEXT };
00120     int flags_size = HAVE_MMXEXT ? 2 : 1;
00121 
00122     if (argc > 1) {
00123         help();
00124         return 1;
00125     }
00126 
00127     printf("ffmpeg motion test\n");
00128 
00129     ctx = avcodec_alloc_context3(NULL);
00130     ctx->dsp_mask = AV_CPU_FLAG_FORCE;
00131     ff_dsputil_init(&cctx, ctx);
00132     for (c = 0; c < flags_size; c++) {
00133         int x;
00134         ctx->dsp_mask = AV_CPU_FLAG_FORCE | flags[c];
00135         ff_dsputil_init(&mmxctx, ctx);
00136 
00137         for (x = 0; x < 2; x++) {
00138             printf("%s for %dx%d pixels\n", c ? "mmx2" : "mmx",
00139                    x ? 8 : 16, x ? 8 : 16);
00140             test_motion("mmx",     mmxctx.pix_abs[x][0], cctx.pix_abs[x][0]);
00141             test_motion("mmx_x2",  mmxctx.pix_abs[x][1], cctx.pix_abs[x][1]);
00142             test_motion("mmx_y2",  mmxctx.pix_abs[x][2], cctx.pix_abs[x][2]);
00143             test_motion("mmx_xy2", mmxctx.pix_abs[x][3], cctx.pix_abs[x][3]);
00144         }
00145     }
00146     av_free(ctx);
00147 
00148     return 0;
00149 }