]> git.sesse.net Git - ffmpeg/blob - tests/checkasm/av_tx.c
avutil: remove deprecated AVClass.child_class_next
[ffmpeg] / tests / checkasm / av_tx.c
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 "libavutil/mem_internal.h"
20 #include "libavutil/tx.h"
21 #include "libavutil/error.h"
22
23 #include "checkasm.h"
24
25 #define EPS 0.00005
26
27 #define SCALE_NOOP(x) (x)
28 #define SCALE_INT20(x) (av_clip64(lrintf((x) * 2147483648.0), INT32_MIN, INT32_MAX) >> 12)
29
30 #define randomize_complex(BUF, LEN, TYPE, SCALE)                \
31     do {                                                        \
32         TYPE *buf = (TYPE *)BUF;                                \
33         for (int i = 0; i < LEN; i++) {                         \
34             double fre = (double)rnd() / UINT_MAX;              \
35             double fim = (double)rnd() / UINT_MAX;              \
36             buf[i] = (TYPE){ SCALE(fre), SCALE(fim) };          \
37         }                                                       \
38     } while (0)
39
40 static const int check_lens[] = {
41     2, 4, 8, 16, 32, 64, 1024, 16384,
42 };
43
44 #define CHECK_TEMPLATE(PREFIX, TYPE, DATA_TYPE, SCALE, LENGTHS, CHECK_EXPRESSION) \
45     do {                                                                          \
46         int err;                                                                  \
47         AVTXContext *tx;                                                          \
48         av_tx_fn fn;                                                              \
49         int num_checks = 0;                                                       \
50         int last_check = 0;                                                       \
51         const void *scale = &SCALE;                                               \
52                                                                                   \
53         for (int i = 0; i < FF_ARRAY_ELEMS(LENGTHS); i++) {                       \
54             int len = LENGTHS[i];                                                 \
55                                                                                   \
56             if ((err = av_tx_init(&tx, &fn, TYPE, 0, len, &scale, 0x0)) < 0) {    \
57                 fprintf(stderr, "av_tx: %s\n", av_err2str(err));                  \
58                 return;                                                           \
59             }                                                                     \
60                                                                                   \
61             if (check_func(fn, PREFIX "_%i", len)) {                              \
62                 num_checks++;                                                     \
63                 last_check = len;                                                 \
64                 call_ref(tx, out_ref, in, sizeof(DATA_TYPE));                     \
65                 call_new(tx, out_new, in, sizeof(DATA_TYPE));                     \
66                 if (CHECK_EXPRESSION) {                                           \
67                     fail();                                                       \
68                     break;                                                        \
69                 }                                                                 \
70                 bench_new(tx, out_new, in, sizeof(DATA_TYPE));                    \
71             }                                                                     \
72                                                                                   \
73             av_tx_uninit(&tx);                                                    \
74             fn = NULL;                                                            \
75         }                                                                         \
76                                                                                   \
77         av_tx_uninit(&tx);                                                        \
78         fn = NULL;                                                                \
79                                                                                   \
80         if (num_checks == 1)                                                      \
81             report(PREFIX "_%i", last_check);                                     \
82         else if (num_checks)                                                      \
83             report(PREFIX);                                                       \
84     } while (0)
85
86 void checkasm_check_av_tx(void)
87 {
88     const float scale_float = 1.0f;
89     const double scale_double = 1.0f;
90
91     declare_func(void, AVTXContext *tx, void *out, void *in, ptrdiff_t stride);
92
93     void *in      = av_malloc(16384*2*8);
94     void *out_ref = av_malloc(16384*2*8);
95     void *out_new = av_malloc(16384*2*8);
96
97     randomize_complex(in, 16384, AVComplexFloat, SCALE_NOOP);
98     CHECK_TEMPLATE("float_fft", AV_TX_FLOAT_FFT, AVComplexFloat, scale_float, check_lens,
99                    !float_near_abs_eps_array(out_ref, out_new, EPS, len*2));
100
101     randomize_complex(in, 16384, AVComplexDouble, SCALE_NOOP);
102     CHECK_TEMPLATE("double_fft", AV_TX_DOUBLE_FFT, AVComplexDouble, scale_double, check_lens,
103                    !double_near_abs_eps_array(out_ref, out_new, EPS, len*2));
104
105     av_free(in);
106     av_free(out_ref);
107     av_free(out_new);
108 }