swresample-test.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011-2012 Michael Niedermayer (michaelni@gmx.at)
3  * Copyright (c) 2002 Fabrice Bellard
4  *
5  * This file is part of libswresample
6  *
7  * libswresample is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * libswresample is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with libswresample; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/avassert.h"
24 #include "libavutil/common.h"
25 #include "libavutil/opt.h"
26 #include "swresample.h"
27 
28 #undef time
29 #include "time.h"
30 #undef fprintf
31 
32 #define SAMPLES 1000
33 
34 #define ASSERT_LEVEL 2
35 
36 static double get(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f){
37  const uint8_t *p;
40  p= a[ch];
41  }else{
42  p= a[0];
43  index= ch + index*ch_count;
44  }
45 
46  switch(f){
47  case AV_SAMPLE_FMT_U8 : return ((const uint8_t*)p)[index]/127.0-1.0;
48  case AV_SAMPLE_FMT_S16: return ((const int16_t*)p)[index]/32767.0;
49  case AV_SAMPLE_FMT_S32: return ((const int32_t*)p)[index]/2147483647.0;
50  case AV_SAMPLE_FMT_FLT: return ((const float *)p)[index];
51  case AV_SAMPLE_FMT_DBL: return ((const double *)p)[index];
52  default: av_assert0(0);
53  }
54 }
55 
56 static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v){
57  uint8_t *p;
60  p= a[ch];
61  }else{
62  p= a[0];
63  index= ch + index*ch_count;
64  }
65  switch(f){
66  case AV_SAMPLE_FMT_U8 : ((uint8_t*)p)[index]= av_clip_uint8 (lrint((v+1.0)*127)); break;
67  case AV_SAMPLE_FMT_S16: ((int16_t*)p)[index]= av_clip_int16 (lrint(v*32767)); break;
68  case AV_SAMPLE_FMT_S32: ((int32_t*)p)[index]= av_clipl_int32(llrint(v*2147483647)); break;
69  case AV_SAMPLE_FMT_FLT: ((float *)p)[index]= v; break;
70  case AV_SAMPLE_FMT_DBL: ((double *)p)[index]= v; break;
71  default: av_assert2(0);
72  }
73 }
74 
75 static void shift(uint8_t *a[], int index, int ch_count, enum AVSampleFormat f){
76  int ch;
77 
79  f= av_get_alt_sample_fmt(f, 0);
80  for(ch= 0; ch<ch_count; ch++)
81  a[ch] += index*av_get_bytes_per_sample(f);
82  }else{
83  a[0] += index*ch_count*av_get_bytes_per_sample(f);
84  }
85 }
86 
87 static const enum AVSampleFormat formats[] = {
98 };
99 
100 static const int rates[] = {
101  8000,
102  11025,
103  16000,
104  22050,
105  32000,
106  48000,
107 };
108 
109 uint64_t layouts[]={
124 };
125 
127  if(av_sample_fmt_is_planar(format)){
128  int i;
129  int plane_size= av_get_bytes_per_sample(format&0xFF)*samples;
130  format&=0xFF;
131  for(i=0; i<SWR_CH_MAX; i++){
132  out[i]= in + i*plane_size;
133  }
134  }else{
135  out[0]= in;
136  }
137 }
138 
139 static int cmp(const int *a, const int *b){
140  return *a - *b;
141 }
142 
143 static void audiogen(void *data, enum AVSampleFormat sample_fmt,
144  int channels, int sample_rate, int nb_samples)
145 {
146  int i, ch, k;
147  double v, f, a, ampa;
148  double tabf1[SWR_CH_MAX];
149  double tabf2[SWR_CH_MAX];
150  double taba[SWR_CH_MAX];
151  unsigned static rnd;
152 
153 #define PUT_SAMPLE set(data, ch, k, channels, sample_fmt, v);
154 #define uint_rand(x) (x = x * 1664525 + 1013904223)
155 #define dbl_rand(x) (uint_rand(x)*2.0 / (double)UINT_MAX - 1)
156  k = 0;
157 
158  /* 1 second of single freq sinus at 1000 Hz */
159  a = 0;
160  for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
161  v = sin(a) * 0.30;
162  for (ch = 0; ch < channels; ch++)
163  PUT_SAMPLE
164  a += M_PI * 1000.0 * 2.0 / sample_rate;
165  }
166 
167  /* 1 second of varing frequency between 100 and 10000 Hz */
168  a = 0;
169  for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
170  v = sin(a) * 0.30;
171  for (ch = 0; ch < channels; ch++)
172  PUT_SAMPLE
173  f = 100.0 + (((10000.0 - 100.0) * i) / sample_rate);
174  a += M_PI * f * 2.0 / sample_rate;
175  }
176 
177  /* 0.5 second of low amplitude white noise */
178  for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) {
179  v = dbl_rand(rnd) * 0.30;
180  for (ch = 0; ch < channels; ch++)
181  PUT_SAMPLE
182  }
183 
184  /* 0.5 second of high amplitude white noise */
185  for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) {
186  v = dbl_rand(rnd);
187  for (ch = 0; ch < channels; ch++)
188  PUT_SAMPLE
189  }
190 
191  /* 1 second of unrelated ramps for each channel */
192  for (ch = 0; ch < channels; ch++) {
193  taba[ch] = 0;
194  tabf1[ch] = 100 + uint_rand(rnd) % 5000;
195  tabf2[ch] = 100 + uint_rand(rnd) % 5000;
196  }
197  for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) {
198  for (ch = 0; ch < channels; ch++) {
199  v = sin(taba[ch]) * 0.30;
200  PUT_SAMPLE
201  f = tabf1[ch] + (((tabf2[ch] - tabf1[ch]) * i) / sample_rate);
202  taba[ch] += M_PI * f * 2.0 / sample_rate;
203  }
204  }
205 
206  /* 2 seconds of 500 Hz with varying volume */
207  a = 0;
208  ampa = 0;
209  for (i = 0; i < 2 * sample_rate && k < nb_samples; i++, k++) {
210  for (ch = 0; ch < channels; ch++) {
211  double amp = (1.0 + sin(ampa)) * 0.15;
212  if (ch & 1)
213  amp = 0.30 - amp;
214  v = sin(a) * amp;
215  PUT_SAMPLE
216  a += M_PI * 500.0 * 2.0 / sample_rate;
217  ampa += M_PI * 2.0 / sample_rate;
218  }
219  }
220 }
221 
222 int main(int argc, char **argv){
223  int in_sample_rate, out_sample_rate, ch ,i, flush_count;
224  uint64_t in_ch_layout, out_ch_layout;
225  enum AVSampleFormat in_sample_fmt, out_sample_fmt;
226  uint8_t array_in[SAMPLES*8*8];
227  uint8_t array_mid[SAMPLES*8*8*3];
228  uint8_t array_out[SAMPLES*8*8+100];
229  uint8_t *ain[SWR_CH_MAX];
230  uint8_t *aout[SWR_CH_MAX];
231  uint8_t *amid[SWR_CH_MAX];
232  int flush_i=0;
233  int mode;
234  int num_tests = 10000;
235  uint32_t seed = 0;
236  uint32_t rand_seed = 0;
238  int max_tests = FF_ARRAY_ELEMS(remaining_tests);
239  int test;
240  int specific_test= -1;
241 
242  struct SwrContext * forw_ctx= NULL;
243  struct SwrContext *backw_ctx= NULL;
244 
245  if (argc > 1) {
246  if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
247  av_log(NULL, AV_LOG_INFO, "Usage: swresample-test [<num_tests>[ <test>]] \n"
248  "num_tests Default is %d\n", num_tests);
249  return 0;
250  }
251  num_tests = strtol(argv[1], NULL, 0);
252  if(num_tests < 0) {
253  num_tests = -num_tests;
254  rand_seed = time(0);
255  }
256  if(num_tests<= 0 || num_tests>max_tests)
257  num_tests = max_tests;
258  if(argc > 2) {
259  specific_test = strtol(argv[1], NULL, 0);
260  }
261  }
262 
263  for(i=0; i<max_tests; i++)
264  remaining_tests[i] = i;
265 
266  for(test=0; test<num_tests; test++){
267  unsigned r;
268  uint_rand(seed);
269  r = (seed * (uint64_t)(max_tests - test)) >>32;
270  FFSWAP(int, remaining_tests[r], remaining_tests[max_tests - test - 1]);
271  }
272  qsort(remaining_tests + max_tests - num_tests, num_tests, sizeof(remaining_tests[0]), (void*)cmp);
273  in_sample_rate=16000;
274  for(test=0; test<num_tests; test++){
275  char in_layout_string[256];
276  char out_layout_string[256];
277  unsigned vector= remaining_tests[max_tests - test - 1];
278  int in_ch_count;
279  int out_count, mid_count, out_ch_count;
280 
281  in_ch_layout = layouts[vector % FF_ARRAY_ELEMS(layouts)]; vector /= FF_ARRAY_ELEMS(layouts);
282  out_ch_layout = layouts[vector % FF_ARRAY_ELEMS(layouts)]; vector /= FF_ARRAY_ELEMS(layouts);
283  in_sample_fmt = formats[vector % FF_ARRAY_ELEMS(formats)]; vector /= FF_ARRAY_ELEMS(formats);
284  out_sample_fmt = formats[vector % FF_ARRAY_ELEMS(formats)]; vector /= FF_ARRAY_ELEMS(formats);
285  out_sample_rate = rates [vector % FF_ARRAY_ELEMS(rates )]; vector /= FF_ARRAY_ELEMS(rates);
286  av_assert0(!vector);
287 
288  if(specific_test == 0){
289  if(out_sample_rate != in_sample_rate || in_ch_layout != out_ch_layout)
290  continue;
291  }
292 
293  in_ch_count= av_get_channel_layout_nb_channels(in_ch_layout);
294  out_ch_count= av_get_channel_layout_nb_channels(out_ch_layout);
295  av_get_channel_layout_string( in_layout_string, sizeof( in_layout_string), in_ch_count, in_ch_layout);
296  av_get_channel_layout_string(out_layout_string, sizeof(out_layout_string), out_ch_count, out_ch_layout);
297  fprintf(stderr, "TEST: %s->%s, rate:%5d->%5d, fmt:%s->%s\n",
298  in_layout_string, out_layout_string,
299  in_sample_rate, out_sample_rate,
300  av_get_sample_fmt_name(in_sample_fmt), av_get_sample_fmt_name(out_sample_fmt));
301  forw_ctx = swr_alloc_set_opts(forw_ctx, out_ch_layout, out_sample_fmt, out_sample_rate,
302  in_ch_layout, in_sample_fmt, in_sample_rate,
303  0, 0);
304  backw_ctx = swr_alloc_set_opts(backw_ctx, in_ch_layout, in_sample_fmt, in_sample_rate,
305  out_ch_layout, out_sample_fmt, out_sample_rate,
306  0, 0);
307  if(!forw_ctx) {
308  fprintf(stderr, "Failed to init forw_cts\n");
309  return 1;
310  }
311  if(!backw_ctx) {
312  fprintf(stderr, "Failed to init backw_ctx\n");
313  return 1;
314  }
315  if(swr_init( forw_ctx) < 0)
316  fprintf(stderr, "swr_init(->) failed\n");
317  if(swr_init(backw_ctx) < 0)
318  fprintf(stderr, "swr_init(<-) failed\n");
319  //FIXME test planar
320  setup_array(ain , array_in , in_sample_fmt, SAMPLES);
321  setup_array(amid, array_mid, out_sample_fmt, 3*SAMPLES);
322  setup_array(aout, array_out, in_sample_fmt , SAMPLES);
323 #if 0
324  for(ch=0; ch<in_ch_count; ch++){
325  for(i=0; i<SAMPLES; i++)
326  set(ain, ch, i, in_ch_count, in_sample_fmt, sin(i*i*3/SAMPLES));
327  }
328 #else
329  audiogen(ain, in_sample_fmt, in_ch_count, SAMPLES/6+1, SAMPLES);
330 #endif
331  mode = uint_rand(rand_seed) % 3;
332  if(mode==0 /*|| out_sample_rate == in_sample_rate*/) {
333  mid_count= swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, SAMPLES);
334  } else if(mode==1){
335  mid_count= swr_convert(forw_ctx, amid, 0, (const uint8_t **)ain, SAMPLES);
336  mid_count+=swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, 0);
337  } else {
338  int tmp_count;
339  mid_count= swr_convert(forw_ctx, amid, 0, (const uint8_t **)ain, 1);
340  av_assert0(mid_count==0);
341  shift(ain, 1, in_ch_count, in_sample_fmt);
342  mid_count+=swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, 0);
343  shift(amid, mid_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
344  mid_count+=swr_convert(forw_ctx, amid, 2, (const uint8_t **)ain, 2);
345  shift(amid, mid_count-tmp_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
346  shift(ain, 2, in_ch_count, in_sample_fmt);
347  mid_count+=swr_convert(forw_ctx, amid, 1, (const uint8_t **)ain, SAMPLES-3);
348  shift(amid, mid_count-tmp_count, out_ch_count, out_sample_fmt); tmp_count = mid_count;
349  shift(ain, -3, in_ch_count, in_sample_fmt);
350  mid_count+=swr_convert(forw_ctx, amid, 3*SAMPLES, (const uint8_t **)ain, 0);
351  shift(amid, -tmp_count, out_ch_count, out_sample_fmt);
352  }
353  out_count= swr_convert(backw_ctx,aout, SAMPLES, (const uint8_t **)amid, mid_count);
354 
355  for(ch=0; ch<in_ch_count; ch++){
356  double sse, maxdiff=0;
357  double sum_a= 0;
358  double sum_b= 0;
359  double sum_aa= 0;
360  double sum_bb= 0;
361  double sum_ab= 0;
362  for(i=0; i<out_count; i++){
363  double a= get(ain , ch, i, in_ch_count, in_sample_fmt);
364  double b= get(aout, ch, i, in_ch_count, in_sample_fmt);
365  sum_a += a;
366  sum_b += b;
367  sum_aa+= a*a;
368  sum_bb+= b*b;
369  sum_ab+= a*b;
370  maxdiff= FFMAX(maxdiff, FFABS(a-b));
371  }
372  sse= sum_aa + sum_bb - 2*sum_ab;
373  if(sse < 0 && sse > -0.00001) sse=0; //fix rounding error
374 
375  fprintf(stderr, "[e:%f c:%f max:%f] len:%5d\n", out_count ? sqrt(sse/out_count) : 0, sum_ab/(sqrt(sum_aa*sum_bb)), maxdiff, out_count);
376  }
377 
378  flush_i++;
379  flush_i%=21;
380  flush_count = swr_convert(backw_ctx,aout, flush_i, 0, 0);
381  shift(aout, flush_i, in_ch_count, in_sample_fmt);
382  flush_count+= swr_convert(backw_ctx,aout, SAMPLES-flush_i, 0, 0);
383  shift(aout, -flush_i, in_ch_count, in_sample_fmt);
384  if(flush_count){
385  for(ch=0; ch<in_ch_count; ch++){
386  double sse, maxdiff=0;
387  double sum_a= 0;
388  double sum_b= 0;
389  double sum_aa= 0;
390  double sum_bb= 0;
391  double sum_ab= 0;
392  for(i=0; i<flush_count; i++){
393  double a= get(ain , ch, i+out_count, in_ch_count, in_sample_fmt);
394  double b= get(aout, ch, i, in_ch_count, in_sample_fmt);
395  sum_a += a;
396  sum_b += b;
397  sum_aa+= a*a;
398  sum_bb+= b*b;
399  sum_ab+= a*b;
400  maxdiff= FFMAX(maxdiff, FFABS(a-b));
401  }
402  sse= sum_aa + sum_bb - 2*sum_ab;
403  if(sse < 0 && sse > -0.00001) sse=0; //fix rounding error
404 
405  fprintf(stderr, "[e:%f c:%f max:%f] len:%5d F:%3d\n", sqrt(sse/flush_count), sum_ab/(sqrt(sum_aa*sum_bb)), maxdiff, flush_count, flush_i);
406  }
407  }
408 
409 
410  fprintf(stderr, "\n");
411  }
412 
413  return 0;
414 }
#define AV_CH_LAYOUT_7POINT1
float v
int swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_count, const uint8_t *in_arg[SWR_CH_MAX], int in_count)
Definition: swresample.c:735
#define AV_CH_LAYOUT_SURROUND
Sinusoidal phase f
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
Definition: git-howto.txt:5
static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride)
#define AV_CH_LAYOUT_4POINT0
#define AV_CH_LAYOUT_7POINT0
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL),};static void cpy1(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, len);}static void cpy2(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 2 *len);}static void cpy4(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 4 *len);}static void cpy8(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;}}if(HAVE_YASM &&HAVE_MMX) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);return ctx;}void swri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len){int ch;int off=0;const int os=(out->planar?1:out->ch_count)*out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){int planes=in->planar?in->ch_count:1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){int planes=out->planar?out-> ch_count
#define FF_ARRAY_ELEMS(a)
#define AV_CH_LAYOUT_STEREO
signed 16 bits
Definition: samplefmt.h:52
#define AV_CH_LAYOUT_5POINT0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static void shift(uint8_t *a[], int index, int ch_count, enum AVSampleFormat f)
uint8_t
AV_SAMPLE_FMT_U8
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:63
mode
Definition: f_perms.c:27
AVOptions.
#define b
Definition: input.c:42
integer sqrt
Definition: avutil.txt:2
static enum AVSampleFormat formats[]
int main(int argc, char **argv)
signed 32 bits, planar
Definition: samplefmt.h:59
float, planar
Definition: samplefmt.h:60
static const int rates[]
#define AV_CH_LAYOUT_5POINT1
static int cmp(const int *a, const int *b)
libswresample public header
Spectrum Plot time data
const char * r
Definition: vf_curves.c:94
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
simple assert() macros that are a bit more flexible than ISO C assert().
#define AV_CH_LAYOUT_QUAD
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
FFmpeg Automated Testing Environment ************************************Table of Contents *****************FFmpeg Automated Testing Environment Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the test
Definition: fate.txt:34
uint64_t layouts[]
#define FFMAX(a, b)
Definition: common.h:56
#define uint_rand(x)
#define AV_CH_LAYOUT_2_1
#define AV_CH_LAYOUT_2_2
signed 32 bits
Definition: samplefmt.h:53
audio channel layout utility functions
#define dbl_rand(x)
int32_t
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
struct SwrContext * swr_alloc_set_opts(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx)
Allocate SwrContext if needed and set/reset common parameters.
Definition: swresample.c:186
#define FFABS(a)
Definition: common.h:53
#define AV_CH_LAYOUT_5POINT1_BACK
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:47
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:104
for k
NULL
Definition: eval.c:55
sample_rate
static unsigned int seed
Definition: videogen.c:78
#define llrint(x)
Definition: libm.h:112
int index
Definition: gxfenc.c:89
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:118
synthesis window for stochastic i
#define AV_CH_LAYOUT_5POINT0_BACK
static av_always_inline av_const long int lrint(double x)
Definition: libm.h:148
enum AVSampleFormat in_sample_fmt
input sample format
#define AV_CH_LAYOUT_7POINT1_WIDE
#define PUT_SAMPLE
common internal and external API header
#define SWR_CH_MAX
Maximum number of channels.
Definition: swresample.h:102
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
static void setup_array(uint8_t *out[SWR_CH_MAX], uint8_t *in, enum AVSampleFormat format, int samples)
static void audiogen(void *data, enum AVSampleFormat sample_fmt, int channels, int sample_rate, int nb_samples)
unsigned 8 bits, planar
Definition: samplefmt.h:57
signed 16 bits, planar
Definition: samplefmt.h:58
#define AV_LOG_INFO
Definition: log.h:156
Filter the word “frame” indicates either a video frame or a group of audio samples
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
#define M_PI
Definition: mathematics.h:46
#define FFSWAP(type, a, b)
Definition: common.h:61
enum AVSampleFormat av_get_alt_sample_fmt(enum AVSampleFormat sample_fmt, int planar)
Return the planar<->packed alternative form of the given sample format, or AV_SAMPLE_FMT_NONE on erro...
Definition: samplefmt.c:64
#define AV_CH_LAYOUT_MONO
double, planar
Definition: samplefmt.h:61
av_cold int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.
Definition: swresample.c:242
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
#define SAMPLES