~rexbron/ffmpeg/debian.libavcore

« back to all changes in this revision

Viewing changes to libavcodec/motion-test.c

  • Committer: Andrew Hunter
  • Date: 2010-08-29 06:49:36 UTC
  • Revision ID: andrew@aehunter.net-20100829064936-gyq5l5n2eu0595do
Remove dupe code base

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * (c) 2001 Fabrice Bellard
3
 
 *
4
 
 * This file is part of FFmpeg.
5
 
 *
6
 
 * FFmpeg is free software; you can redistribute it and/or
7
 
 * modify it under the terms of the GNU Lesser General Public
8
 
 * License as published by the Free Software Foundation; either
9
 
 * version 2.1 of the License, or (at your option) any later version.
10
 
 *
11
 
 * FFmpeg is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
 * Lesser General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU Lesser General Public
17
 
 * License along with FFmpeg; if not, write to the Free Software
18
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 
 */
20
 
 
21
 
/**
22
 
 * @file libavcodec/motion-test.c
23
 
 * motion test.
24
 
 */
25
 
 
26
 
#include <stdlib.h>
27
 
#include <stdio.h>
28
 
#include <string.h>
29
 
#include <sys/time.h>
30
 
#include <unistd.h>
31
 
 
32
 
#include "dsputil.h"
33
 
 
34
 
#undef exit
35
 
#undef printf
36
 
#undef random
37
 
 
38
 
#define WIDTH 64
39
 
#define HEIGHT 64
40
 
 
41
 
uint8_t img1[WIDTH * HEIGHT];
42
 
uint8_t img2[WIDTH * HEIGHT];
43
 
 
44
 
void fill_random(uint8_t *tab, int size)
45
 
{
46
 
    int i;
47
 
    for(i=0;i<size;i++) {
48
 
#if 1
49
 
        tab[i] = random() % 256;
50
 
#else
51
 
        tab[i] = i;
52
 
#endif
53
 
    }
54
 
}
55
 
 
56
 
void help(void)
57
 
{
58
 
    printf("motion-test [-h]\n"
59
 
           "test motion implementations\n");
60
 
    exit(1);
61
 
}
62
 
 
63
 
int64_t gettime(void)
64
 
{
65
 
    struct timeval tv;
66
 
    gettimeofday(&tv,NULL);
67
 
    return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
68
 
}
69
 
 
70
 
#define NB_ITS 500
71
 
 
72
 
int dummy;
73
 
 
74
 
void test_motion(const char *name,
75
 
                 me_cmp_func test_func, me_cmp_func ref_func)
76
 
{
77
 
    int x, y, d1, d2, it;
78
 
    uint8_t *ptr;
79
 
    int64_t ti;
80
 
    printf("testing '%s'\n", name);
81
 
 
82
 
    /* test correctness */
83
 
    for(it=0;it<20;it++) {
84
 
 
85
 
        fill_random(img1, WIDTH * HEIGHT);
86
 
        fill_random(img2, WIDTH * HEIGHT);
87
 
 
88
 
        for(y=0;y<HEIGHT-17;y++) {
89
 
            for(x=0;x<WIDTH-17;x++) {
90
 
                ptr = img2 + y * WIDTH + x;
91
 
                d1 = test_func(NULL, img1, ptr, WIDTH, 1);
92
 
                d2 = ref_func(NULL, img1, ptr, WIDTH, 1);
93
 
                if (d1 != d2) {
94
 
                    printf("error: mmx=%d c=%d\n", d1, d2);
95
 
                }
96
 
            }
97
 
        }
98
 
    }
99
 
    emms_c();
100
 
 
101
 
    /* speed test */
102
 
    ti = gettime();
103
 
    d1 = 0;
104
 
    for(it=0;it<NB_ITS;it++) {
105
 
        for(y=0;y<HEIGHT-17;y++) {
106
 
            for(x=0;x<WIDTH-17;x++) {
107
 
                ptr = img2 + y * WIDTH + x;
108
 
                d1 += test_func(NULL, img1, ptr, WIDTH, 1);
109
 
            }
110
 
        }
111
 
    }
112
 
    emms_c();
113
 
    dummy = d1; /* avoid optimization */
114
 
    ti = gettime() - ti;
115
 
 
116
 
    printf("  %0.0f kop/s\n",
117
 
           (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
118
 
           (double)(ti / 1000.0));
119
 
}
120
 
 
121
 
 
122
 
int main(int argc, char **argv)
123
 
{
124
 
    AVCodecContext *ctx;
125
 
    int c;
126
 
    DSPContext cctx, mmxctx;
127
 
    int flags[2] = { FF_MM_MMX, FF_MM_MMXEXT };
128
 
 
129
 
    for(;;) {
130
 
        c = getopt(argc, argv, "h");
131
 
        if (c == -1)
132
 
            break;
133
 
        switch(c) {
134
 
        case 'h':
135
 
            help();
136
 
            break;
137
 
        }
138
 
    }
139
 
 
140
 
    printf("ffmpeg motion test\n");
141
 
 
142
 
    ctx = avcodec_alloc_context();
143
 
    ctx->dsp_mask = FF_MM_FORCE;
144
 
    dsputil_init(&cctx, ctx);
145
 
    for (c = 0; c < 2; c++) {
146
 
        int x;
147
 
        ctx->dsp_mask = FF_MM_FORCE | flags[c];
148
 
        dsputil_init(&mmxctx, ctx);
149
 
 
150
 
        for (x = 0; x < 2; x++) {
151
 
            printf("%s for %dx%d pixels\n", c ? "mmx2" : "mmx",
152
 
                   x ? 8 : 16, x ? 8 : 16);
153
 
            test_motion("mmx",     mmxctx.pix_abs[x][0], cctx.pix_abs[x][0]);
154
 
            test_motion("mmx_x2",  mmxctx.pix_abs[x][1], cctx.pix_abs[x][1]);
155
 
            test_motion("mmx_y2",  mmxctx.pix_abs[x][2], cctx.pix_abs[x][2]);
156
 
            test_motion("mmx_xy2", mmxctx.pix_abs[x][3], cctx.pix_abs[x][3]);
157
 
        }
158
 
    }
159
 
    av_free(ctx);
160
 
 
161
 
    return 0;
162
 
}