FFmpeg
Loading...
Searching...
No Matches
motion.c
Go to the documentation of this file.
1/*
2 *
3 * This file is part of FFmpeg.
4 *
5 * FFmpeg is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * FFmpeg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#include <string.h>
21
22#include "libavutil/common.h"
25
26#include "libavcodec/me_cmp.h"
27
28#include "checkasm.h"
29
30static void fill_random(uint8_t *tab, size_t size)
31{
32 for (size_t i = 0; i < (size & ~3); i += 4)
33 AV_WN32A(tab + i, rnd());
34 for (size_t i = size & ~3; i < size; ++i)
35 tab[i] = rnd();
36}
37
38static void test_motion(const char *name, me_cmp_func test_func)
39{
40 /* test configurarion */
41#define ITERATIONS 16
42#define WIDTH 64
43#define HEIGHT 64
44
45 /* motion estimation can look up to 17 bytes ahead */
46 static const int look_ahead = 17;
47
48 int i, x, y, h, d1, d2;
49 uint8_t *ptr;
50
51 LOCAL_ALIGNED_16(uint8_t, img1, [WIDTH * HEIGHT]);
52 LOCAL_ALIGNED_16(uint8_t, img2, [WIDTH * HEIGHT]);
53
55 const uint8_t *blk1 /* align width (8 or 16) */,
56 const uint8_t *blk2 /* align 1 */, ptrdiff_t stride,
57 int h);
58
59 if (test_func == NULL) {
60 return;
61 }
62
63 /* test correctness */
64 if (check_func(test_func, "%s", name)) {
65 fill_random(img1, WIDTH * HEIGHT);
66 fill_random(img2, WIDTH * HEIGHT);
67
68 for (i = 0; i < ITERATIONS; i++) {
69 x = rnd() % (WIDTH - look_ahead);
70 y = rnd() % (HEIGHT - look_ahead);
71 // Pick a random h between 4 and 16; pick an even value.
72 h = 4 + ((rnd() % (16 + 1 - 4)) & ~1);
73
74 ptr = img2 + y * WIDTH + x;
75 d2 = call_ref(NULL, img1, ptr, WIDTH, h);
76 d1 = call_new(NULL, img1, ptr, WIDTH, h);
77
78 if (d1 != d2) {
79 fail();
80 printf("func: %s, x=%d y=%d h=%d, error: asm=%d c=%d\n", name, x, y, h, d1, d2);
81 break;
82 }
83 }
84 // Test with a fixed offset, for benchmark stability
85 ptr = img2 + 3 * WIDTH + 3;
86 bench_new(NULL, img1, ptr, WIDTH, 8);
87 }
88}
89
90#define ME_CMP_1D_ARRAYS(XX) \
91 XX(sad) \
92 XX(sse) \
93 XX(hadamard8_diff) \
94 XX(vsad) \
95 XX(vsse) \
96 XX(nsse) \
97 XX(median_sad)
98
99// tests for functions not yet implemented
100#if 0
101 XX(dct_sad) \
102 XX(quant_psnr) \
103 XX(bit) \
104 XX(rd) \
105 XX(w53) \
106 XX(w97) \
107 XX(dct_max) \
108 XX(dct264_sad) \
109
110#endif
111
112static void check_motion(void)
113{
114 char buf[64];
115 /* Setup AVCodecContext in a way that does not pull in all of libavcodec */
116 AVCodecContext av_ctx = { .codec_id = AV_CODEC_ID_NONE, .flags = AV_CODEC_FLAG_BITEXACT };
117 MECmpContext me_ctx;
118
119 ff_me_cmp_init(&me_ctx, &av_ctx);
120
121 for (int i = 0; i < FF_ARRAY_ELEMS(me_ctx.pix_abs); i++) {
122 for (int j = 0; j < FF_ARRAY_ELEMS(me_ctx.pix_abs[0]); j++) {
123 snprintf(buf, sizeof(buf), "pix_abs_%d_%d", i, j);
124 test_motion(buf, me_ctx.pix_abs[i][j]);
125 }
126 }
127 report("pix_abs");
128
129#define XX(me_cmp_array) \
130 for (int i = 0; i < FF_ARRAY_ELEMS(me_ctx.me_cmp_array); i++) { \
131 snprintf(buf, sizeof(buf), #me_cmp_array "_%d", i); \
132 test_motion(buf, me_ctx.me_cmp_array[i]); \
133 report(#me_cmp_array); \
134 }
136#undef XX
137}
138
140{
141 check_motion();
142}
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define bit(string, value)
Definition cbs_mpeg2.c:56
#define rnd
Definition checkasm.h:136
common internal and external API header
#define NULL
Definition coverity.c:32
__device__ int printf(const char *,...)
#define fail
Definition test.h:479
#define bench_new
Definition test.h:487
#define check_func
Definition test.h:481
#define call_new
Definition test.h:486
#define call_ref
Definition test.h:485
#define report
Definition test.h:480
#define declare_func_emms
Definition test.h:490
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition avcodec.h:322
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
#define AV_WN32A(p, v)
#define WIDTH
Definition c93.c:45
#define HEIGHT
Definition c93.c:46
#define AV_CPU_FLAG_MMX
standard MMX
Definition cpu.h:32
av_cold void ff_me_cmp_init(MECmpContext *c, AVCodecContext *avctx)
Definition me_cmp.c:961
int(* me_cmp_func)(MPVEncContext *c, const uint8_t *blk1, const uint8_t *blk2, ptrdiff_t stride, int h)
Definition me_cmp.h:45
#define LOCAL_ALIGNED_16(t, v,...)
static void fill_random(uint8_t *tab, size_t size)
Definition motion.c:30
static void check_motion(void)
Definition motion.c:112
#define ME_CMP_1D_ARRAYS(XX)
Definition motion.c:90
void checkasm_check_motion(void)
Definition motion.c:139
static void test_motion(const char *name, me_cmp_func test_func)
Definition motion.c:38
#define XX(me_cmp_array)
#define ITERATIONS
const char * name
Definition qsvenc.c:142
#define FF_ARRAY_ELEMS(a)
#define snprintf
Definition snprintf.h:34
main external API structure.
Definition avcodec.h:443
me_cmp_func pix_abs[2][4]
Definition me_cmp.h:68
#define stride
int size
static const struct twinvq_data tab
static double c[64]