FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/motion.c
Date: 2024-05-03 05:27:13
Exec Total Coverage
Lines: 37 40 92.5%
Functions: 4 4 100.0%
Branches: 42 50 84.0%

Line Branch Exec Source
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"
23 #include "libavutil/intreadwrite.h"
24 #include "libavutil/mem_internal.h"
25
26 #include "libavcodec/me_cmp.h"
27
28 #include "checkasm.h"
29
30 754 static void fill_random(uint8_t *tab, int size)
31 {
32 int i;
33
2/2
✓ Branch 0 taken 3088384 times.
✓ Branch 1 taken 754 times.
3089138 for (i = 0; i < size; i++) {
34 3088384 tab[i] = rnd() % 256;
35 }
36 754 }
37
38 1118 static 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 1118 LOCAL_ALIGNED_16(uint8_t, img1, [WIDTH * HEIGHT]);
52 1118 LOCAL_ALIGNED_16(uint8_t, img2, [WIDTH * HEIGHT]);
53
54
2/2
✓ Branch 1 taken 1032 times.
✓ Branch 2 taken 86 times.
1118 declare_func_emms(AV_CPU_FLAG_MMX, int, struct MpegEncContext *c,
55 uint8_t *blk1 /* align width (8 or 16) */,
56 uint8_t *blk2 /* align 1 */, ptrdiff_t stride,
57 int h);
58
59
2/2
✓ Branch 0 taken 741 times.
✓ Branch 1 taken 377 times.
1118 if (test_func == NULL) {
60 741 return;
61 }
62
63 /* test correctness */
64 377 fill_random(img1, WIDTH * HEIGHT);
65 377 fill_random(img2, WIDTH * HEIGHT);
66
67
2/2
✓ Branch 3 taken 54 times.
✓ Branch 4 taken 323 times.
377 if (check_func(test_func, "%s", name)) {
68
2/2
✓ Branch 0 taken 864 times.
✓ Branch 1 taken 54 times.
918 for (i = 0; i < ITERATIONS; i++) {
69 864 x = rnd() % (WIDTH - look_ahead);
70 864 y = rnd() % (HEIGHT - look_ahead);
71 // Pick a random h between 4 and 16; pick an even value.
72 864 h = 4 + ((rnd() % (16 + 1 - 4)) & ~1);
73
74 864 ptr = img2 + y * WIDTH + x;
75 864 d2 = call_ref(NULL, img1, ptr, WIDTH, h);
76 864 d1 = call_new(NULL, img1, ptr, WIDTH, h);
77
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 864 times.
864 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 54 ptr = img2 + 3 * WIDTH + 3;
86
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
54 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(me_pre_cmp) \
98 XX(me_cmp) \
99 XX(me_sub_cmp) \
100 XX(mb_cmp) \
101 XX(ildct_cmp) \
102 XX(frame_skip_cmp) \
103 XX(median_sad)
104
105 // tests for functions not yet implemented
106 #if 0
107 XX(dct_sad) \
108 XX(quant_psnr) \
109 XX(bit) \
110 XX(rd) \
111 XX(w53) \
112 XX(w97) \
113 XX(dct_max) \
114 XX(dct264_sad) \
115
116 #endif
117
118 13 static void check_motion(void)
119 {
120 char buf[64];
121 /* Setup AVCodecContext in a way that does not pull in all of libavcodec */
122 13 AVCodecContext av_ctx = { .codec_id = AV_CODEC_ID_NONE, .flags = AV_CODEC_FLAG_BITEXACT };
123 MECmpContext me_ctx;
124
125 13 memset(&me_ctx, 0, sizeof(me_ctx));
126
127
128 13 ff_me_cmp_init(&me_ctx, &av_ctx);
129
130
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 13 times.
39 for (int i = 0; i < FF_ARRAY_ELEMS(me_ctx.pix_abs); i++) {
131
2/2
✓ Branch 0 taken 104 times.
✓ Branch 1 taken 26 times.
130 for (int j = 0; j < FF_ARRAY_ELEMS(me_ctx.pix_abs[0]); j++) {
132 104 snprintf(buf, sizeof(buf), "pix_abs_%d_%d", i, j);
133 104 test_motion(buf, me_ctx.pix_abs[i][j]);
134 }
135 }
136
137 #define XX(me_cmp_array) \
138 for (int i = 0; i < FF_ARRAY_ELEMS(me_ctx.me_cmp_array); i++) { \
139 snprintf(buf, sizeof(buf), #me_cmp_array "_%d", i); \
140 test_motion(buf, me_ctx.me_cmp_array[i]); \
141 }
142
26/26
✓ Branch 1 taken 78 times.
✓ Branch 2 taken 13 times.
✓ Branch 4 taken 78 times.
✓ Branch 5 taken 13 times.
✓ Branch 7 taken 78 times.
✓ Branch 8 taken 13 times.
✓ Branch 10 taken 78 times.
✓ Branch 11 taken 13 times.
✓ Branch 13 taken 78 times.
✓ Branch 14 taken 13 times.
✓ Branch 16 taken 78 times.
✓ Branch 17 taken 13 times.
✓ Branch 19 taken 78 times.
✓ Branch 20 taken 13 times.
✓ Branch 22 taken 78 times.
✓ Branch 23 taken 13 times.
✓ Branch 25 taken 78 times.
✓ Branch 26 taken 13 times.
✓ Branch 28 taken 78 times.
✓ Branch 29 taken 13 times.
✓ Branch 31 taken 78 times.
✓ Branch 32 taken 13 times.
✓ Branch 34 taken 78 times.
✓ Branch 35 taken 13 times.
✓ Branch 37 taken 78 times.
✓ Branch 38 taken 13 times.
1027 ME_CMP_1D_ARRAYS(XX)
143 #undef XX
144 13 }
145
146 13 void checkasm_check_motion(void)
147 {
148 13 check_motion();
149 13 report("motion");
150 13 }
151