1 /*
2 * Copyright (c) 2016 Martin Storsjo
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #include <stdbool.h>
22 #include <string.h>
23
24 #include "config_components.h"
26
30
32
33 #define PIXEL_STRIDE 16
34
35 #define randomize_buffers(src, dst, stride, coef) \
36 do { \
37 int x, y; \
38 for (y = 0; y < 4; y++) { \
39 AV_WN32A((src) + y * (stride), rnd()); \
40 AV_WN32A((dst) + y * (stride), rnd()); \
41 for (x = 0; x < 4; x++) \
42 (coef)[y * 4 + x] = (src)[y * (stride) + x] - \
43 (dst)[y * (stride) + x]; \
44 } \
45 } while (0)
46
48 {
50 for (
i = 0;
i < 4;
i++) {
51 const int a1 = (coef[
i*4 + 0] + coef[
i*4 + 3]) * 8;
52 const int b1 = (coef[
i*4 + 1] + coef[
i*4 + 2]) * 8;
53 const int c1 = (coef[
i*4 + 1] - coef[
i*4 + 2]) * 8;
54 const int d1 = (coef[
i*4 + 0] - coef[
i*4 + 3]) * 8;
55 coef[
i*4 + 0] =
a1 +
b1;
56 coef[
i*4 + 1] = (
c1 * 2217 + d1 * 5352 + 14500) >> 12;
57 coef[
i*4 + 2] =
a1 -
b1;
58 coef[
i*4 + 3] = (d1 * 2217 -
c1 * 5352 + 7500) >> 12;
59 }
60 for (
i = 0;
i < 4;
i++) {
61 const int a1 = coef[
i + 0*4] + coef[
i + 3*4];
62 const int b1 = coef[
i + 1*4] + coef[
i + 2*4];
63 const int c1 = coef[
i + 1*4] - coef[
i + 2*4];
64 const int d1 = coef[
i + 0*4] - coef[
i + 3*4];
65 coef[
i + 0*4] = (
a1 +
b1 + 7) >> 4;
66 coef[
i + 1*4] = ((
c1 * 2217 + d1 * 5352 + 12000) >> 16) + !!d1;
67 coef[
i + 2*4] = (
a1 -
b1 + 7) >> 4;
68 coef[
i + 3*4] = (d1 * 2217 -
c1 * 5352 + 51000) >> 16;
69 }
70 }
71
73 {
75 for (
i = 0;
i < 4;
i++) {
76 int a1 = coef[0 * 4 +
i];
77 int b1 = coef[1 * 4 +
i];
78 int c1 = coef[2 * 4 +
i];
79 int d1 = coef[3 * 4 +
i];
80 int e1;
92 }
93 for (
i = 0;
i < 4;
i++) {
94 int a1 = coef[
i * 4 + 0];
95 int b1 = coef[
i * 4 + 1];
96 int c1 = coef[
i * 4 + 2];
97 int d1 = coef[
i * 4 + 3];
98 int e1;
106 coef[
i * 4 + 0] =
a1 * 2;
107 coef[
i * 4 + 1] =
c1 * 2;
108 coef[
i * 4 + 2] = d1 * 2;
109 coef[
i * 4 + 3] =
b1 * 2;
110 }
111 }
112
114 {
124
126
128
129 for (
dc = 0;
dc <= 1;
dc++) {
131
134 memset(subcoef0, 0, 4 * 4 * sizeof(int16_t));
135 subcoef0[0] = coef[0];
136 } else {
137 memcpy(subcoef0, coef, 4 * 4 * sizeof(int16_t));
138 }
139 memcpy(dst0,
dst, 4 * 4);
140 memcpy(dst1,
dst, 4 * 4);
141 memcpy(subcoef1, subcoef0, 4 * 4 * sizeof(int16_t));
142 // Note, this uses a pixel stride of 4, even though the real decoder uses a stride as a
143 // multiple of 16. If optimizations want to take advantage of that, this test needs to be
144 // updated to make it more like the h264dsp tests.
147 if (memcmp(dst0, dst1, 4 * 4) ||
148 memcmp(subcoef0, subcoef1, 4 * 4 * sizeof(int16_t)))
150
152 }
153 }
154 }
155
157 {
167
173 for (
i = 0;
i < 4;
i++) {
174 int blockx = 4 * (
i %
w);
175 int blocky = 4 * (
i /
w);
178 memset(&coef[
i][1], 0, 15 *
sizeof(int16_t));
179 }
180
181 memcpy(dst0,
dst, 4 * 4 * 4);
182 memcpy(dst1,
dst, 4 * 4 * 4);
183 memcpy(subcoef0, coef, 4 * 4 * 4 * sizeof(int16_t));
184 memcpy(subcoef1, coef, 4 * 4 * 4 * sizeof(int16_t));
187 if (memcmp(dst0, dst1, 4 * 4 * 4) ||
188 memcmp(subcoef0, subcoef1, 4 * 4 * 4 * sizeof(int16_t)))
191 }
192 }
193
194 }
195
197 {
201 int16_t
block[4][4][16];
204 int dc_only;
205 int blockx, blocky;
207
208 for (blocky = 0; blocky < 4; blocky++) {
209 for (blockx = 0; blockx < 4; blockx++) {
212
214 dc[blocky * 4 + blockx] =
block[blocky][blockx][0];
216 }
217 }
219
220 for (dc_only = 0; dc_only <= 1; dc_only++) {
222
223 if (
check_func(
idct,
"vp%d_luma_dc_wht%s", 8 - is_vp7, dc_only ?
"_dc" :
"")) {
224 if (dc_only) {
225 memset(dc0, 0, 16 * sizeof(int16_t));
227 } else {
228 memcpy(dc0,
dc, 16 *
sizeof(int16_t));
229 }
230 memcpy(dc1, dc0, 16 * sizeof(int16_t));
231 memcpy(block0,
block, 4 * 4 * 16 *
sizeof(int16_t));
232 memcpy(
block1,
block, 4 * 4 * 16 *
sizeof(int16_t));
235 if (memcmp(block0,
block1, 4 * 4 * 16 *
sizeof(int16_t)) ||
236 memcmp(dc0, dc1, 16 * sizeof(int16_t)))
239 }
240 }
241 }
242
243 #define SRC_BUF_STRIDE 32
244 #define SRC_BUF_SIZE (((size << (size < 16)) + 5) * SRC_BUF_STRIDE)
245 // The mc subpixel interpolation filter needs the 2 previous pixels in either
246 // direction, the +1 is to make sure the actual load addresses always are
247 // unaligned.
248 #define src (buf + 2 * SRC_BUF_STRIDE + 2 + 1)
249
250 #undef randomize_buffers
251 #define randomize_buffers() \
252 do { \
253 int k; \
254 for (k = 0; k < SRC_BUF_SIZE; k += 4) { \
255 AV_WN32A(buf + k, rnd()); \
256 } \
257 } while (0)
258
260 {
266 const uint8_t *, ptrdiff_t, int, int, int);
267
269 for (k = 1; k < 8; k++) {
270 int hsize = k / 3;
271 int size = 16 >> hsize;
272 int height = (size << 1) >> (k % 3);
273 for (dy = 0; dy < 3; dy++) {
274 for (dx = 0; dx < 3; dx++) {
275 char str[100];
277
278 if (dx || dy) {
280 static const char *dx_names[] = { "", "h4", "h6" };
281 static const char *dy_names[] = { "", "v4", "v6" };
282 snprintf(str,
sizeof(str),
"epel%d_%s%s",
size, dx_names[dx], dy_names[dy]);
283 } else {
284 snprintf(str,
sizeof(str),
"bilin%d_%s%s",
size, dx ?
"h" :
"", dy ?
"v" :
"");
285 }
286 } else {
288 }
289
294 mx = dx == 2 ? 2 + 2 * (
rnd() % 3) : dx == 1 ? 1 + 2 * (
rnd() % 4) : 0;
295 my = dy == 2 ? 2 + 2 * (
rnd() % 3) : dy == 1 ? 1 + 2 * (
rnd() % 4) : 0;
296 } else {
297 mx = dx ? 1 + (
rnd() % 7) : 0;
298 my = dy ? 1 + (
rnd() % 7) : 0;
299 }
301 for (
i = -2;
i <= 3;
i++) {
302 int val = (
i == -1 ||
i == 2) ? 0 : 0xff;
303 // Set pixels in the first row and column to the maximum pattern,
304 // to test for potential overflows in the filter.
307 }
314 }
315 }
316 }
317 }
318 }
319 }
320
321 #undef randomize_buffers
322
323 #define setpx(a, b, c) buf[(a) + (b) * jstride] = av_clip_uint8(c)
324 // Set the pixel to c +/- [0,d]
325 #define setdx(a, b, c, d) setpx(a, b, c - (d) + (rnd() % ((d) * 2 + 1)))
326 // Set the pixel to c +/- [d,d+e] (making sure it won't be clipped)
327 #define setdx2(a, b, o, c, d, e) setpx(a, b, o = c + ((d) + (rnd() % (e))) * (c >= 128 ? -1 : 1))
328
330 int dir, int flim_E, int flim_I,
331 int hev_thresh, uint8_t *buf,
332 int force_hev)
333 {
334 uint32_t
mask = 0xff;
335 int off = dir ? lineoff : lineoff * str;
336 int istride = dir ? 1 : str;
337 int jstride = dir ? str : 1;
339 for (
i = 0;
i < 8;
i += 2) {
340 // Row 0 will trigger hev for q0/q1, row 2 will trigger hev for p0/p1,
341 // rows 4 and 6 will not trigger hev.
342 // force_hev 1 will make sure all rows trigger hev, while force_hev -1
343 // makes none of them trigger it.
344 int idx = off +
i * istride, p2, p1, p0,
q0,
q1, q2;
346 if (
i == 0 && force_hev >= 0 || force_hev > 0)
347 setdx2(idx, 1,
q1,
q0, hev_thresh + 1, flim_I - hev_thresh - 1);
348 else
350 setdx(idx, 2, q2 =
q1, flim_I);
351 setdx(idx, 3, q2, flim_I);
352 setdx(idx, -1, p0 =
q0, flim_E >> 2);
353 if (
i == 2 && force_hev >= 0 || force_hev > 0)
354 setdx2(idx, -2, p1, p0, hev_thresh + 1, flim_I - hev_thresh - 1);
355 else
356 setdx(idx, -2, p1 = p0, hev_thresh);
357 setdx(idx, -3, p2 = p1, flim_I);
358 setdx(idx, -4, p2, flim_I);
359 }
360 }
361
362 // Fill the buffer with random pixels
364 {
365 int x, y;
366 for (y = 0; y <
h; y++)
367 for (x = 0; x <
w; x++)
369 }
370
371 #define randomize_buffers(buf, lineoff, str, force_hev) \
372 randomize_loopfilter_buffers(lineoff, str, dir, flim_E, flim_I, hev_thresh, buf, force_hev)
373
375 {
378 int dir, edge, force_hev;
379 int flim_E = 20, flim_I = 10, hev_thresh = 7;
380 declare_func(
void, uint8_t *, ptrdiff_t,
int,
int,
int);
381
382 for (dir = 0; dir < 2; dir++) {
383 int midoff = dir ? 4 * 16 : 4;
384 int midoff_aligned = dir ? 4 * 16 : 16;
385 uint8_t *buf0 = base0 + midoff_aligned;
386 uint8_t *buf1 = base1 + midoff_aligned;
387 for (edge = 0; edge < 2; edge++) {
388 void (*
func)(uint8_t *, ptrdiff_t, int, int, int) =
NULL;
389 switch (dir << 1 | edge) {
394 }
395 if (
check_func(
func,
"vp%d_loop_filter16y%s_%s", 8 - is_vp7, edge ?
"_inner" :
"", dir ?
"v" :
"h")) {
396 for (force_hev = -1; force_hev <= 1; force_hev++) {
400 memcpy(buf1 - midoff, buf0 - midoff, 16 * 16);
401 call_ref(buf0, 16, flim_E, flim_I, hev_thresh);
402 call_new(buf1, 16, flim_E, flim_I, hev_thresh);
403 if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16))
405 }
409 bench_new(buf0, 16, flim_E, flim_I, hev_thresh);
410 }
411 }
412 }
413 }
414
416 {
421 int dir, edge, force_hev;
422 int flim_E = 20, flim_I = 10, hev_thresh = 7;
423 declare_func(
void, uint8_t *, uint8_t *, ptrdiff_t,
int,
int,
int);
424
425 for (dir = 0; dir < 2; dir++) {
426 int midoff = dir ? 4 * 16 : 4;
427 int midoff_aligned = dir ? 4 * 16 : 16;
428 uint8_t *buf0u = base0u + midoff_aligned;
429 uint8_t *buf0v = base0v + midoff_aligned;
430 uint8_t *buf1u = base1u + midoff_aligned;
431 uint8_t *buf1v = base1v + midoff_aligned;
432 for (edge = 0; edge < 2; edge++) {
433 void (*
func)(uint8_t *, uint8_t *, ptrdiff_t, int, int, int) =
NULL;
434 switch (dir << 1 | edge) {
439 }
440 if (
check_func(
func,
"vp%d_loop_filter8uv%s_%s", 8 - is_vp7, edge ?
"_inner" :
"", dir ?
"v" :
"h")) {
441 for (force_hev = -1; force_hev <= 1; force_hev++) {
446 memcpy(buf1u - midoff, buf0u - midoff, 16 * 16);
447 memcpy(buf1v - midoff, buf0v - midoff, 16 * 16);
448
449 call_ref(buf0u, buf0v, 16, flim_E, flim_I, hev_thresh);
450 call_new(buf1u, buf1v, 16, flim_E, flim_I, hev_thresh);
451 if (memcmp(buf0u - midoff, buf1u - midoff, 16 * 16) ||
452 memcmp(buf0v - midoff, buf1v - midoff, 16 * 16))
454 }
459 bench_new(buf0u, buf0v, 16, flim_E, flim_I, hev_thresh);
460 }
461 }
462 }
463 }
464
466 {
469 int dir;
470 int flim_E = 20, flim_I = 30, hev_thresh = 0;
472
473 for (dir = 0; dir < 2; dir++) {
474 int midoff = dir ? 4 * 16 : 4;
475 int midoff_aligned = dir ? 4 * 16 : 16;
476 uint8_t *buf0 = base0 + midoff_aligned;
477 uint8_t *buf1 = base1 + midoff_aligned;
479 if (
check_func(
func,
"vp%d_loop_filter_simple_%s", 8 - is_vp7, dir ?
"v" :
"h")) {
483 memcpy(buf1 - midoff, buf0 - midoff, 16 * 16);
486 if (memcmp(buf0 - midoff, buf1 - midoff, 16 * 16))
489 }
490 }
491 }
492
494 {
495 #if CONFIG_VP7_DECODER
496 if (is_vp7)
498 else
499 #endif
509 }
510
512 {
514
519 #if CONFIG_VP7_DECODER
521 #endif
522 }