FFmpeg
motion.c
Go to the documentation of this file.
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
23  * motion test.
24  */
25 
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
29 
30 #include "config.h"
31 #include "libavcodec/me_cmp.h"
32 #include "libavutil/cpu.h"
33 #include "libavutil/emms.h"
34 #include "libavutil/internal.h"
35 #include "libavutil/lfg.h"
36 #include "libavutil/mem.h"
37 #include "libavutil/time.h"
38 
39 #undef printf
40 
41 #define WIDTH 64
42 #define HEIGHT 64
43 
44 static uint8_t img1[WIDTH * HEIGHT];
45 static uint8_t img2[WIDTH * HEIGHT];
46 
47 static void fill_random(uint8_t *tab, int size)
48 {
49  int i;
50  AVLFG prng;
51 
52  av_lfg_init(&prng, 1);
53  for(i=0;i<size;i++) {
54  tab[i] = av_lfg_get(&prng) % 256;
55  }
56 }
57 
58 static void help(void)
59 {
60  printf("motion-test [-h]\n"
61  "test motion implementations\n");
62 }
63 
64 #define NB_ITS 500
65 
66 int dummy;
67 
68 static void test_motion(const char *name,
69  me_cmp_func test_func, me_cmp_func ref_func)
70 {
71  int x, y, d1, d2, it;
72  uint8_t *ptr;
73  int64_t ti;
74  printf("testing '%s'\n", name);
75 
76  /* test correctness */
77  for(it=0;it<20;it++) {
78 
81 
82  for(y=0;y<HEIGHT-17;y++) {
83  for(x=0;x<WIDTH-17;x++) {
84  ptr = img2 + y * WIDTH + x;
85  d1 = test_func(NULL, img1, ptr, WIDTH, 8);
86  d2 = ref_func(NULL, img1, ptr, WIDTH, 8);
87  if (d1 != d2) {
88  printf("error: mmx=%d c=%d\n", d1, d2);
89  }
90  }
91  }
92  }
93  emms_c();
94 
95  /* speed test */
96  ti = av_gettime_relative();
97  d1 = 0;
98  for(it=0;it<NB_ITS;it++) {
99  for(y=0;y<HEIGHT-17;y++) {
100  for(x=0;x<WIDTH-17;x++) {
101  ptr = img2 + y * WIDTH + x;
102  d1 += test_func(NULL, img1, ptr, WIDTH, 8);
103  }
104  }
105  }
106  emms_c();
107  dummy = d1; /* avoid optimization */
108  ti = av_gettime_relative() - ti;
109 
110  printf(" %0.0f kop/s\n",
111  (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
112  (double)(ti / 1000.0));
113 }
114 
115 
116 int main(int argc, char **argv)
117 {
119  int c;
120  MECmpContext cctx, mmxctx;
122  int flags_size = HAVE_MMXEXT ? 2 : 1;
123 
124  if (argc > 1) {
125  help();
126  return 1;
127  }
128 
129  printf("ffmpeg motion test\n");
130 
134  memset(&cctx, 0, sizeof(cctx));
135  ff_me_cmp_init(&cctx, ctx);
136  for (c = 0; c < flags_size; c++) {
137  int x;
139  memset(&mmxctx, 0, sizeof(mmxctx));
140  ff_me_cmp_init(&mmxctx, ctx);
141 
142  for (x = 0; x < 2; x++) {
143  printf("%s for %dx%d pixels\n", c ? "mmx2" : "mmx",
144  x ? 8 : 16, x ? 8 : 16);
145  test_motion("mmx", mmxctx.pix_abs[x][0], cctx.pix_abs[x][0]);
146  test_motion("mmx_x2", mmxctx.pix_abs[x][1], cctx.pix_abs[x][1]);
147  test_motion("mmx_y2", mmxctx.pix_abs[x][2], cctx.pix_abs[x][2]);
148  test_motion("mmx_xy2", mmxctx.pix_abs[x][3], cctx.pix_abs[x][3]);
149  }
150  }
151  av_free(ctx);
152 
153  return 0;
154 }
av_force_cpu_flags
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
Definition: cpu.c:75
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
av_lfg_init
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition: lfg.c:32
int64_t
long long int64_t
Definition: coverity.c:34
test_motion
static void test_motion(const char *name, me_cmp_func test_func, me_cmp_func ref_func)
Definition: motion.c:68
dummy
int dummy
Definition: motion.c:66
tab
static const struct twinvq_data tab
Definition: twinvq_data.h:10345
ff_me_cmp_init
av_cold void ff_me_cmp_init(MECmpContext *c, AVCodecContext *avctx)
Definition: me_cmp.c:1008
help
static void help(void)
Definition: motion.c:58
emms_c
#define emms_c()
Definition: emms.h:63
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:149
av_lfg_get
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:53
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1406
lfg.h
ctx
AVFormatContext * ctx
Definition: movenc.c:48
img1
static uint8_t img1[WIDTH *HEIGHT]
Definition: motion.c:44
MECmpContext
Definition: me_cmp.h:55
NULL
#define NULL
Definition: coverity.c:32
HEIGHT
#define HEIGHT
Definition: motion.c:42
time.h
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVLFG
Context structure for the Lagged Fibonacci PRNG.
Definition: lfg.h:33
cpu.h
size
int size
Definition: twinvq_data.h:10344
img2
static uint8_t img2[WIDTH *HEIGHT]
Definition: motion.c:45
printf
printf("static const uint8_t my_array[100] = {\n")
NB_ITS
#define NB_ITS
Definition: motion.c:64
MECmpContext::pix_abs
me_cmp_func pix_abs[2][4]
Definition: me_cmp.h:80
fill_random
static void fill_random(uint8_t *tab, int size)
Definition: motion.c:47
emms.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
internal.h
WIDTH
#define WIDTH
Definition: motion.c:41
me_cmp_func
int(* me_cmp_func)(struct MpegEncContext *c, const uint8_t *blk1, const uint8_t *blk2, ptrdiff_t stride, int h)
Definition: me_cmp.h:50
me_cmp.h
AV_CPU_FLAG_MMX
#define AV_CPU_FLAG_MMX
standard MMX
Definition: cpu.h:29
AVCodecContext
main external API structure.
Definition: avcodec.h:445
main
int main(int argc, char **argv)
Definition: motion.c:116
AV_CPU_FLAG_MMXEXT
#define AV_CPU_FLAG_MMXEXT
SSE integer functions or AMD MMX ext.
Definition: cpu.h:30
mem.h
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:342
it
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s it
Definition: writing_filters.txt:31
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482