FFmpeg
vp3dsp.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #include <assert.h>
20 #include <stddef.h>
21 
22 #include "checkasm.h"
23 #include "libavutil/intreadwrite.h"
24 #include "libavutil/macros.h"
25 #include "libavutil/mem_internal.h"
26 #include "libavcodec/vp3dsp.h"
27 
28 enum {
29  MAX_STRIDE = 64,
31  /// Horizontal tests operate on 4x8 blocks
32  HORIZONTAL_BUF_SIZE = ((8 /* lines */ - 1) * MAX_STRIDE + 4 /* width */ + 7 /* misalignment */),
33  /// Vertical tests operate on 8x4 blocks
34  VERTICAL_BUF_SIZE = ((4 /* lines */ - 1) * MAX_STRIDE + 8 /* width */ + 7 /* misalignment */),
35 };
36 
37 #define randomize_buffers(buf0, buf1, size) \
38  do { \
39  static_assert(sizeof(buf0[0]) == 1 && sizeof(buf1[0]) == 1, \
40  "Pointer arithmetic needs to be adapted"); \
41  for (size_t k = 0; k < (size & ~3); k += 4) { \
42  uint32_t r = rnd(); \
43  AV_WN32A(buf0 + k, r); \
44  AV_WN32A(buf1 + k, r); \
45  } \
46  for (size_t k = size & ~3; k < size; ++k) \
47  buf0[k] = buf1[k] = rnd(); \
48  } while (0)
49 
50 
51 static void vp3_check_loop_filter(void)
52 {
53  DECLARE_ALIGNED(8, uint8_t, hor_buf0)[HORIZONTAL_BUF_SIZE];
54  DECLARE_ALIGNED(8, uint8_t, hor_buf1)[HORIZONTAL_BUF_SIZE];
55  DECLARE_ALIGNED(8, uint8_t, ver_buf0)[VERTICAL_BUF_SIZE];
56  DECLARE_ALIGNED(8, uint8_t, ver_buf1)[VERTICAL_BUF_SIZE];
57  DECLARE_ALIGNED(16, int, bounding_values_array)[256 + 4];
58  int *const bounding_values = bounding_values_array + 127;
59  VP3DSPContext vp3dsp;
60  static const struct {
61  const char *name;
62  size_t offset;
63  int lines_above, lines_below;
64  int pixels_left, pixels_right;
65  unsigned alignment;
66  int horizontal;
67  } tests[] = {
68 #define TEST(NAME) .name = #NAME, .offset = offsetof(VP3DSPContext, NAME)
69  { TEST(v_loop_filter_unaligned), 2, 1, 0, 7, 1, 0 },
70  { TEST(h_loop_filter_unaligned), 0, 7, 2, 1, 1, 1 },
71  { TEST(v_loop_filter), 2, 1, 0, 7, VP3_LOOP_FILTER_NO_UNALIGNED_SUPPORT ? 8 : 1, 0 },
72  { TEST(h_loop_filter), 0, 7, 2, 1, VP3_LOOP_FILTER_NO_UNALIGNED_SUPPORT ? 8 : 1, 1 },
73  };
74  declare_func(void, uint8_t *src, ptrdiff_t stride, int *bounding_values);
75 
76  ff_vp3dsp_init(&vp3dsp);
77 
78  int filter_limit = rnd() % 128;
79 
80  ff_vp3dsp_set_bounding_values(bounding_values_array, filter_limit);
81 
82  for (size_t i = 0; i < FF_ARRAY_ELEMS(tests); ++i) {
83  void (*loop_filter)(uint8_t *, ptrdiff_t, int*) = *(void(**)(uint8_t *, ptrdiff_t, int*))((char*)&vp3dsp + tests[i].offset);
84 
85  if (check_func(loop_filter, "%s", tests[i].name)) {
86  uint8_t *buf0 = tests[i].horizontal ? hor_buf0 : ver_buf0;
87  uint8_t *buf1 = tests[i].horizontal ? hor_buf1 : ver_buf1;
88  size_t bufsize = tests[i].horizontal ? HORIZONTAL_BUF_SIZE : VERTICAL_BUF_SIZE;
89  ptrdiff_t stride = (rnd() % (MAX_STRIDE / MIN_STRIDE) + 1) * MIN_STRIDE;
90  // Don't always use pointers that are aligned to 8.
91  size_t offset = FFALIGN(tests[i].pixels_left, tests[i].alignment) +
92  (rnd() % (MIN_STRIDE / tests[i].alignment)) * tests[i].alignment
93  + stride * tests[i].lines_above;
94  uint8_t *dst0 = buf0 + offset, *dst1 = buf1 + offset;
95 
96  if (rnd() & 1) {
97  // Flip stride.
98  dst1 += (tests[i].lines_below - tests[i].lines_above) * stride;
99  dst0 += (tests[i].lines_below - tests[i].lines_above) * stride;
100  stride = -stride;
101  }
102 
103  randomize_buffers(buf0, buf1, bufsize);
104  call_ref(dst0, stride, bounding_values);
105  call_new(dst1, stride, bounding_values);
106  if (memcmp(buf0, buf1, bufsize))
107  fail();
108  bench_new(dst0, stride, bounding_values);
109  }
110  }
111 }
112 
114 {
116 }
TEST
#define TEST(NAME)
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
VP3DSPContext
Definition: vp3dsp.h:29
mem_internal.h
MAX_STRIDE
@ MAX_STRIDE
Definition: vp3dsp.c:29
vp3dsp.h
check_func
#define check_func(func,...)
Definition: checkasm.h:197
call_ref
#define call_ref(...)
Definition: checkasm.h:212
macros.h
fail
#define fail()
Definition: checkasm.h:206
checkasm.h
checkasm_check_vp3dsp
void checkasm_check_vp3dsp(void)
Definition: vp3dsp.c:113
rnd
#define rnd()
Definition: checkasm.h:190
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
intreadwrite.h
call_new
#define call_new(...)
Definition: checkasm.h:315
ff_vp3dsp_set_bounding_values
void ff_vp3dsp_set_bounding_values(int *bounding_values_array, int filter_limit)
Definition: vp3dsp.c:477
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:104
offset
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 offset
Definition: writing_filters.txt:86
loop_filter
static void loop_filter(const H264Context *h, H264SliceContext *sl, int start_x, int end_x)
Definition: h264_slice.c:2432
tests
const TestCase tests[]
Definition: fifo_muxer.c:363
bench_new
#define bench_new(...)
Definition: checkasm.h:400
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
MIN_STRIDE
@ MIN_STRIDE
Definition: vp3dsp.c:30
stride
#define stride
Definition: h264pred_template.c:536
HORIZONTAL_BUF_SIZE
@ HORIZONTAL_BUF_SIZE
Horizontal tests operate on 4x8 blocks.
Definition: vp3dsp.c:32
VP3_LOOP_FILTER_NO_UNALIGNED_SUPPORT
#define VP3_LOOP_FILTER_NO_UNALIGNED_SUPPORT
Definition: vp3dsp.h:27
randomize_buffers
#define randomize_buffers(buf0, buf1, size)
Definition: vp3dsp.c:37
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:201
vp3_check_loop_filter
static void vp3_check_loop_filter(void)
Definition: vp3dsp.c:51
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
VERTICAL_BUF_SIZE
@ VERTICAL_BUF_SIZE
Vertical tests operate on 8x4 blocks.
Definition: vp3dsp.c:34
ff_vp3dsp_init
av_cold void ff_vp3dsp_init(VP3DSPContext *c)
Definition: vp3dsp.c:448
src
#define src
Definition: vp8dsp.c:248