FFmpeg
Loading...
Searching...
No Matches
mpegvideoencdsp.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
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "libavutil/common.h"
22
23#include "libavcodec/mathops.h"
25
26#include "checkasm.h"
27
28#define randomize_buffers(buf, size) \
29 do { \
30 for (int j = 0; j < size; j += 4) \
31 AV_WN32((char*)buf + j, rnd()); \
32 } while (0)
33
34#define randomize_buffer_clipped(buf, min, max) \
35 do { \
36 for (size_t j = 0; j < FF_ARRAY_ELEMS(buf); ++j) \
37 buf[j] = rnd() % (max - min + 1) + min; \
38 } while (0)
39
41{
42 declare_func(void, int16_t block[64], int dct_error_sum[64],
43 const uint16_t dct_offset[64]);
44
45 if (check_func(c->denoise_dct, "denoise_dct")) {
46 DECLARE_ALIGNED(16, int16_t, block_ref)[64];
47 DECLARE_ALIGNED(16, int16_t, block_new)[64];
48 DECLARE_ALIGNED(16, int, dct_error_sum_ref)[64];
49 DECLARE_ALIGNED(16, int, dct_error_sum_new)[64];
50 DECLARE_ALIGNED(16, uint16_t, dct_offset)[64];
51
52 for (size_t i = 0; i < FF_ARRAY_ELEMS(block_ref); ++i) {
53 unsigned random = rnd();
54 block_ref[i] = random & (1 << 16) ? random : 0;
55 }
56 randomize_buffers(dct_offset, sizeof(dct_offset));
57 randomize_buffer_clipped(dct_error_sum_ref, 0, (1 << 24) - 1);
58 memcpy(block_new, block_ref, sizeof(block_new));
59 memcpy(dct_error_sum_new, dct_error_sum_ref, sizeof(dct_error_sum_ref));
60
61 call_ref(block_ref, dct_error_sum_ref, dct_offset);
62 call_new(block_new, dct_error_sum_new, dct_offset);
63 if (memcmp(block_ref, block_new, sizeof(block_ref)) ||
64 memcmp(dct_error_sum_new, dct_error_sum_ref, sizeof(dct_error_sum_new)))
65 fail();
66
67 bench_new(block_new, dct_error_sum_new, dct_offset);
68 }
69}
70
72{
73 declare_func(void, int16_t rem[64], const int16_t basis[64], int scale);
74 if (check_func(c->add_8x8basis, "add_8x8basis")) {
75 // FIXME: What are the actual ranges for these values?
76 int scale = sign_extend(rnd(), 12);
77 DECLARE_ALIGNED(16, int16_t, rem1)[64];
78 DECLARE_ALIGNED(16, int16_t, rem2)[64];
79 DECLARE_ALIGNED(16, int16_t, basis)[64];
80
81 randomize_buffer_clipped(basis, -15760, 15760);
82 randomize_buffers(rem1, sizeof(rem1));
83 memcpy(rem2, rem1, sizeof(rem2));
84 call_ref(rem1, basis, scale);
85 call_new(rem2, basis, scale);
86 if (memcmp(rem1, rem2, sizeof(rem1)))
87 fail();
88 bench_new(rem1, basis, scale);
89 }
90}
91
93{
94 LOCAL_ALIGNED_16(uint8_t, src, [16 * 16]);
95
96 declare_func(int, const uint8_t *pix, ptrdiff_t line_size);
97
98 randomize_buffers(src, 16 * 16);
99
100 for (int n = 0; n < 2; n++) {
101 const char *negstride_str = n ? "_negstride" : "";
102 if (check_func(c->pix_sum, "pix_sum%s", negstride_str)) {
103 int sum0, sum1;
104 const uint8_t *pix = src + (n ? (15 * 16) : 0);
105 ptrdiff_t line_size = 16 * (n ? -1 : 1);
106 sum0 = call_ref(pix, line_size);
107 sum1 = call_new(pix, line_size);
108 if (sum0 != sum1)
109 fail();
110 bench_new(pix, line_size);
111 }
112 }
113}
114
116{
117 LOCAL_ALIGNED_16(uint8_t, src, [16 * 16]);
118
119 declare_func(int, const uint8_t *pix, ptrdiff_t line_size);
120
121 randomize_buffers(src, 16 * 16);
122
123 for (int n = 0; n < 2; n++) {
124 const char *negstride_str = n ? "_negstride" : "";
125 if (check_func(c->pix_norm1, "pix_norm1%s", negstride_str)) {
126 int sum0, sum1;
127 const uint8_t *pix = src + (n ? (15 * 16) : 0);
128 ptrdiff_t line_size = 16 * (n ? -1 : 1);
129 sum0 = call_ref(pix, line_size);
130 sum1 = call_new(pix, line_size);
131 if (sum0 != sum1)
132 fail();
133 bench_new(pix, line_size);
134 }
135 }
136}
137
138#define NUM_LINES 4
139#define MAX_LINE_SIZE 1920
140#define EDGE_WIDTH 16
141#define LINESIZE (EDGE_WIDTH + MAX_LINE_SIZE + EDGE_WIDTH)
142#define BUFSIZE ((EDGE_WIDTH + NUM_LINES + EDGE_WIDTH) * LINESIZE)
143
145{
146 static const int input_sizes[] = {8, 128, 1080, MAX_LINE_SIZE, -MAX_LINE_SIZE};
147 LOCAL_ALIGNED_16(uint8_t, buf0, [BUFSIZE]);
148 LOCAL_ALIGNED_16(uint8_t, buf1, [BUFSIZE]);
149
150 declare_func(void, uint8_t *buf, ptrdiff_t wrap, int width, int height,
151 int w, int h, int sides);
152
153 for (int isi = 0; isi < FF_ARRAY_ELEMS(input_sizes); isi++) {
154 int input_size = input_sizes[isi];
155 int negstride = input_size < 0;
156 const char *negstride_str = negstride ? "_negstride" : "";
157 int width = FFABS(input_size);
158 ptrdiff_t linesize = EDGE_WIDTH + width + EDGE_WIDTH;
159 /* calculate height based on specified width to use the entire buffer. */
160 int height = (BUFSIZE / linesize) - (2 * EDGE_WIDTH);
161 uint8_t *dst0 = buf0 + EDGE_WIDTH * linesize + EDGE_WIDTH;
162 uint8_t *dst1 = buf1 + EDGE_WIDTH * linesize + EDGE_WIDTH;
163
164 if (negstride) {
165 dst0 += (height - 1) * linesize;
166 dst1 += (height - 1) * linesize;
167 linesize *= -1;
168 }
169
170 for (int shift = 0; shift < 3; shift++) {
171 int edge = EDGE_WIDTH >> shift;
172 if (check_func(c->draw_edges, "draw_edges_%d_%d_%d%s", width, height, edge, negstride_str)) {
174 memcpy(buf1, buf0, BUFSIZE);
175 call_ref(dst0, linesize, width, height, edge, edge, EDGE_BOTTOM | EDGE_TOP);
176 call_new(dst1, linesize, width, height, edge, edge, EDGE_BOTTOM | EDGE_TOP);
177 if (memcmp(buf0, buf1, BUFSIZE))
178 fail();
179 bench_new(dst1, linesize, width, height, edge, edge, EDGE_BOTTOM | EDGE_TOP);
180 }
181 }
182 }
183}
184
185#undef NUM_LINES
186#undef MAX_LINE_SIZE
187#undef EDGE_WIDTH
188#undef LINESIZE
189#undef BUFSIZE
190
192{
193 AVCodecContext avctx = {
194 .bits_per_raw_sample = 8,
195 };
197
198 ff_mpegvideoencdsp_init(&c, &avctx);
199
201 report("denoise_dct");
203 report("pix_sum");
205 report("pix_norm1");
207 report("draw_edges");
209 report("add_8x8basis");
210}
#define wrap(func)
Definition neontest.h:65
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define rnd
Definition checkasm.h:135
common internal and external API header
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
static int16_t block[64]
Definition dct.c:125
#define declare_func
Definition test.h:489
#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 BUFSIZE
Definition hlsenc.c:78
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition intra.c:278
static int shift(int a, int b)
Definition bonk.c:261
#define EDGE_WIDTH
Definition diracdec.c:47
av_cold void ff_mpegvideoencdsp_init(MpegvideoEncDSPContext *c, AVCodecContext *avctx)
uint8_t w
Definition llvidencdsp.c:39
static av_const int sign_extend(int val, unsigned bits)
Definition mathops.h:135
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
#define LOCAL_ALIGNED_16(t, v,...)
static int16_t basis[64][64]
#define EDGE_BOTTOM
#define EDGE_TOP
enum AVPixelFormat pix
Definition ohcodec.c:55
#define FF_ARRAY_ELEMS(a)
main external API structure.
Definition avcodec.h:443
static const int input_sizes[]
Definition sw_rgb.c:351
static void check_add_8x8basis(MpegvideoEncDSPContext *c)
static void check_pix_norm1(MpegvideoEncDSPContext *c)
static void check_draw_edges(MpegvideoEncDSPContext *c)
#define randomize_buffer_clipped(buf, min, max)
static void check_pix_sum(MpegvideoEncDSPContext *c)
#define randomize_buffers(buf, size)
void checkasm_check_mpegvideoencdsp(void)
static void check_denoise_dct(MpegvideoEncDSPContext *c)
#define src
Definition vp8dsp.c:248
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
#define MAX_LINE_SIZE
Definition vf_lut3d.c:547
static double c[64]