FFmpeg
av_tx.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 "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 
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 
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 
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 }
stride
int stride
Definition: mace.c:144
scale_double
static int scale_double(void *log, double d, double m, int *r)
Definition: sbgdec.c:211
mem_internal.h
out
FILE * out
Definition: movenc.c:54
float_near_abs_eps_array
int float_near_abs_eps_array(const float *a, const float *b, float eps, unsigned len)
Definition: checkasm.c:339
AVTXContext
Definition: tx_priv.h:111
CHECK_TEMPLATE
#define CHECK_TEMPLATE(PREFIX, TYPE, DATA_TYPE, SCALE, LENGTHS, CHECK_EXPRESSION)
Definition: av_tx.c:44
AV_TX_DOUBLE_FFT
@ AV_TX_DOUBLE_FFT
Same as AV_TX_FLOAT_FFT with a data type of AVComplexDouble.
Definition: tx.h:66
AVComplexFloat
Definition: tx.h:27
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
checkasm.h
AV_TX_FLOAT_FFT
@ AV_TX_FLOAT_FFT
Standard complex to complex FFT with sample data type AVComplexFloat.
Definition: tx.h:45
double_near_abs_eps_array
int double_near_abs_eps_array(const double *a, const double *b, double eps, unsigned len)
Definition: checkasm.c:375
check_lens
static const int check_lens[]
Definition: av_tx.c:40
error.h
EPS
#define EPS
Definition: av_tx.c:25
SCALE_NOOP
#define SCALE_NOOP(x)
Definition: av_tx.c:27
len
int len
Definition: vorbis_enc_data.h:426
AVComplexDouble
Definition: tx.h:31
checkasm_check_av_tx
void checkasm_check_av_tx(void)
Definition: av_tx.c:86
randomize_complex
#define randomize_complex(BUF, LEN, TYPE, SCALE)
Definition: av_tx.c:30
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:129
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
tx.h