FFmpeg
Loading...
Searching...
No Matches
swresample.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2011-2013 Michael Niedermayer (michaelni@gmx.at)
3 *
4 * This file is part of libswresample
5 *
6 * libswresample is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * libswresample is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with libswresample; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "libavutil/mem.h"
22#include "libavutil/opt.h"
23#include "swresample_internal.h"
24#include "audioconvert.h"
25#include "libavutil/avassert.h"
27#include "libavutil/internal.h"
28
29#include <float.h>
30
31#define ALIGN 32
32
33int swri_check_chlayout(struct SwrContext *s, const AVChannelLayout *chl, const char *name) {
34 char l1[1024];
35 int ret;
36
37 if (!(ret = av_channel_layout_check(chl)) || chl->nb_channels > SWR_CH_MAX) {
38 if (ret)
39 av_channel_layout_describe(chl, l1, sizeof(l1));
40 av_log(s, AV_LOG_WARNING, "%s channel layout \"%s\" is invalid or unsupported.\n", name, ret ? l1 : "");
41 return AVERROR(EINVAL);
42 }
43
44 return 0;
45}
46
48 if(!s || s->in_convert) // s needs to be allocated but not initialized
49 return AVERROR(EINVAL);
50 s->channel_map = channel_map;
51 return 0;
52}
53
55 const AVChannelLayout *out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
56 const AVChannelLayout *in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate,
57 int log_offset, void *log_ctx) {
58 struct SwrContext *s = *ps;
59 int ret;
60
61 if (!s) s = swr_alloc();
62 if (!s) return AVERROR(ENOMEM);
63
64 *ps = s;
65
66 s->log_level_offset = log_offset;
67 s->log_ctx = log_ctx;
68
69 if ((ret = av_opt_set_chlayout(s, "ochl", out_ch_layout, 0)) < 0)
70 goto fail;
71 if ((ret = swri_check_chlayout(s, out_ch_layout, "ochl")) < 0)
72 goto fail;
73
74 if ((ret = av_opt_set_int(s, "osf", out_sample_fmt, 0)) < 0)
75 goto fail;
76
77 if ((ret = av_opt_set_int(s, "osr", out_sample_rate, 0)) < 0)
78 goto fail;
79
80 if ((ret = av_opt_set_chlayout(s, "ichl", in_ch_layout, 0)) < 0)
81 goto fail;
82 if ((ret = swri_check_chlayout(s, in_ch_layout, "ichl")) < 0)
83 goto fail;
84
85 if ((ret = av_opt_set_int(s, "isf", in_sample_fmt, 0)) < 0)
86 goto fail;
87
88 if ((ret = av_opt_set_int(s, "isr", in_sample_rate, 0)) < 0)
89 goto fail;
90
91 return 0;
92fail:
93 av_log(s, AV_LOG_ERROR, "Failed to set option\n");
94 swr_free(ps);
95 return ret;
96}
97
99 a->fmt = fmt;
100 a->bps = av_get_bytes_per_sample(fmt);
101 a->planar= av_sample_fmt_is_planar(fmt);
102 if (a->ch_count == 1)
103 a->planar = 1;
104}
105
106static void free_temp(AudioData *a){
107 av_free(a->data);
108 memset(a, 0, sizeof(*a));
109}
110
112 s->in_buffer_index= 0;
113 s->in_buffer_count= 0;
114 s->resample_in_constraint= 0;
115 memset(s->in.ch, 0, sizeof(s->in.ch));
116 memset(s->out.ch, 0, sizeof(s->out.ch));
117 free_temp(&s->postin);
118 free_temp(&s->midbuf);
119 free_temp(&s->preout);
120 free_temp(&s->in_buffer);
121 free_temp(&s->silence);
122 free_temp(&s->drop_temp);
123 free_temp(&s->dither.noise);
124 free_temp(&s->dither.temp);
125 av_channel_layout_uninit(&s->in_ch_layout);
126 av_channel_layout_uninit(&s->out_ch_layout);
127 av_channel_layout_uninit(&s->used_ch_layout);
129 swri_audio_convert_free(&s->out_convert);
130 swri_audio_convert_free(&s->full_convert);
132
133 s->delayed_samples_fixup = 0;
134 s->flushed = 0;
135}
136
138 SwrContext *s= *ss;
139 if(s){
141 av_channel_layout_uninit(&s->user_in_chlayout);
142 av_channel_layout_uninit(&s->user_out_chlayout);
143 av_channel_layout_uninit(&s->user_used_chlayout);
144
145 if (s->resampler)
146 s->resampler->free(&s->resample);
147 }
148
149 av_freep(ss);
150}
151
155
157 int ret, mixing;
158 char l1[1024], l2[1024];
159
161
162 if((unsigned) s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){
163 av_log(s, AV_LOG_ERROR, "Requested input sample format %d is invalid\n", s->in_sample_fmt);
164 return AVERROR(EINVAL);
165 }
166 if((unsigned) s->out_sample_fmt >= AV_SAMPLE_FMT_NB){
167 av_log(s, AV_LOG_ERROR, "Requested output sample format %d is invalid\n", s->out_sample_fmt);
168 return AVERROR(EINVAL);
169 }
170
171 if(s-> in_sample_rate <= 0){
172 av_log(s, AV_LOG_ERROR, "Requested input sample rate %d is invalid\n", s->in_sample_rate);
173 return AVERROR(EINVAL);
174 }
175 if(s->out_sample_rate <= 0){
176 av_log(s, AV_LOG_ERROR, "Requested output sample rate %d is invalid\n", s->out_sample_rate);
177 return AVERROR(EINVAL);
178 }
179
180 if (s->out_sample_fmt == AV_SAMPLE_FMT_DSD &&
181 !(s->in_sample_fmt == AV_SAMPLE_FMT_DSD &&
182 s->in_sample_rate == s->out_sample_rate &&
183 !(s->flags & SWR_FLAG_RESAMPLE))) {
184 av_log(s, AV_LOG_ERROR, "Conversion to DSD is not supported\n");
185 return AVERROR(EINVAL);
186 }
187
188 s->out.ch_count = s-> user_out_chlayout.nb_channels;
190
191 if (swri_check_chlayout(s, &s->user_in_chlayout , "input") ||
192 swri_check_chlayout(s, &s->user_out_chlayout, "output"))
193 return AVERROR(EINVAL);
194
195 ret = av_channel_layout_copy(&s->in_ch_layout, &s->user_in_chlayout);
196 ret |= av_channel_layout_copy(&s->out_ch_layout, &s->user_out_chlayout);
197 ret |= av_channel_layout_copy(&s->used_ch_layout, &s->user_used_chlayout);
198 if (ret < 0)
199 return ret;
200
201 s->int_sample_fmt= s->user_int_sample_fmt;
202
203 s->dither.method = s->user_dither_method;
204
205 switch(s->engine){
206#if CONFIG_LIBSOXR
207 case SWR_ENGINE_SOXR: s->resampler = &swri_soxr_resampler; break;
208#endif
209 case SWR_ENGINE_SWR : s->resampler = &swri_resampler; break;
210 default:
211 av_log(s, AV_LOG_ERROR, "Requested resampling engine is unavailable\n");
212 return AVERROR(EINVAL);
213 }
214
215 if (!av_channel_layout_check(&s->used_ch_layout))
216 av_channel_layout_default(&s->used_ch_layout, s->in.ch_count);
217
218 if (s->used_ch_layout.nb_channels != s->in_ch_layout.nb_channels)
219 av_channel_layout_uninit(&s->in_ch_layout);
220
221 if (s->used_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
222 av_channel_layout_default(&s->used_ch_layout, s->used_ch_layout.nb_channels);
223 if (s->in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) {
224 ret = av_channel_layout_copy(&s->in_ch_layout, &s->used_ch_layout);
225 if (ret < 0)
226 return ret;
227 }
228 if (s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
229 av_channel_layout_default(&s->out_ch_layout, s->out.ch_count);
230
231 s->rematrix = av_channel_layout_compare(&s->out_ch_layout, &s->in_ch_layout) ||
232 s->rematrix_volume!=1.0 ||
233 s->rematrix_custom;
234
235 av_channel_layout_describe(&s->out_ch_layout, l2, sizeof(l2));
236 av_channel_layout_describe(&s->in_ch_layout, l1, sizeof(l1));
237 if (( s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC
238 || s-> in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) && s->used_ch_layout.nb_channels != s->out.ch_count && !s->rematrix_custom) {
239 av_log(s, AV_LOG_ERROR, "Rematrix is needed between %s and %s "
240 "but there is not enough information to do it\n", l1, l2);
241 return AVERROR(EINVAL);
242 }
243
244 /* a matrix that only copies channels leaves the samples as they are,
245 * so the format in between is selected like without a matrix */
246 mixing = 0;
247 if (s->rematrix) {
248 mixing = swri_rematrix_build(s);
249 if (mixing < 0)
250 return mixing;
251 }
252
253 if(s->int_sample_fmt == AV_SAMPLE_FMT_NONE){
254 // DSD to PCM conversion is done in floating point
255 if( s->in_sample_fmt == AV_SAMPLE_FMT_DSD
256 && s->out_sample_fmt != AV_SAMPLE_FMT_DSD) {
257 s->int_sample_fmt= AV_SAMPLE_FMT_FLTP;
258 // 16bit or less to 16bit or less with the same sample rate
259 } else if( av_get_bytes_per_sample(s-> in_sample_fmt) <= 2
260 && av_get_bytes_per_sample(s->out_sample_fmt) <= 2
261 && s->out_sample_rate==s->in_sample_rate) {
262 s->int_sample_fmt= AV_SAMPLE_FMT_S16P;
263 // 8 -> 8, 16->8, 8->16bit
265 +av_get_bytes_per_sample(s->out_sample_fmt) <= 3 ) {
266 s->int_sample_fmt= AV_SAMPLE_FMT_S16P;
267 }else if( av_get_bytes_per_sample(s-> in_sample_fmt) <= 2
268 && !mixing
269 && s->out_sample_rate==s->in_sample_rate
270 && !(s->flags & SWR_FLAG_RESAMPLE)){
271 s->int_sample_fmt= AV_SAMPLE_FMT_S16P;
273 && av_get_planar_sample_fmt(s->out_sample_fmt) == AV_SAMPLE_FMT_S32P
274 && !mixing
275 && s->out_sample_rate == s->in_sample_rate
276 && !(s->flags & SWR_FLAG_RESAMPLE)
277 && s->engine != SWR_ENGINE_SOXR){
278 s->int_sample_fmt= AV_SAMPLE_FMT_S32P;
279 }else if(av_get_bytes_per_sample(s->in_sample_fmt) <= 4){
280 s->int_sample_fmt= AV_SAMPLE_FMT_FLTP;
281 }else{
282 s->int_sample_fmt= AV_SAMPLE_FMT_DBLP;
283 }
284 }
285 av_log(s, AV_LOG_DEBUG, "Using %s internally between filters\n", av_get_sample_fmt_name(s->int_sample_fmt));
286
287 if( s->int_sample_fmt != AV_SAMPLE_FMT_S16P
288 &&s->int_sample_fmt != AV_SAMPLE_FMT_S32P
289 &&s->int_sample_fmt != AV_SAMPLE_FMT_S64P
290 &&s->int_sample_fmt != AV_SAMPLE_FMT_FLTP
291 &&s->int_sample_fmt != AV_SAMPLE_FMT_DBLP){
292 av_log(s, AV_LOG_ERROR, "Requested sample format %s is not supported internally, s16p/s32p/s64p/fltp/dblp are supported\n", av_get_sample_fmt_name(s->int_sample_fmt));
293 return AVERROR(EINVAL);
294 }
295
297 set_audiodata_fmt(&s->out, s->out_sample_fmt);
298
299 if (s->firstpts_in_samples != AV_NOPTS_VALUE) {
300 if (!s->async && s->min_compensation >= FLT_MAX/2)
301 s->async = 1;
302 if (s->firstpts == AV_NOPTS_VALUE)
303 s->firstpts =
304 s->outpts = s->firstpts_in_samples * s->out_sample_rate;
305 } else
306 s->firstpts = AV_NOPTS_VALUE;
307
308 if (s->async) {
309 if (s->min_compensation >= FLT_MAX/2)
310 s->min_compensation = 0.001;
311 if (s->async > 1.0001) {
312 s->max_soft_compensation = s->async / (double) s->in_sample_rate;
313 }
314 }
315
316 if (s->out_sample_rate!=s->in_sample_rate || (s->flags & SWR_FLAG_RESAMPLE)){
317 s->resample = s->resampler->init(s->resample, s->out_sample_rate, s->in_sample_rate, s->filter_size, s->phase_shift, s->linear_interp, s->cutoff, s->int_sample_fmt, s->filter_type, s->kaiser_beta, s->precision, s->cheby, s->exact_rational);
318 if (!s->resample) {
319 av_log(s, AV_LOG_ERROR, "Failed to initialize resampler\n");
320 return AVERROR(ENOMEM);
321 }
322 }else
323 s->resampler->free(&s->resample);
324 if( s->int_sample_fmt != AV_SAMPLE_FMT_S16P
325 && s->int_sample_fmt != AV_SAMPLE_FMT_S32P
326 && s->int_sample_fmt != AV_SAMPLE_FMT_FLTP
327 && s->int_sample_fmt != AV_SAMPLE_FMT_DBLP
328 && s->resample){
329 av_log(s, AV_LOG_ERROR, "Resampling only supported with internal s16p/s32p/fltp/dblp\n");
330 ret = AVERROR(EINVAL);
331 goto fail;
332 }
333
334#define RSC 1 //FIXME finetune
335 if(!s-> in.ch_count)
336 s-> in.ch_count = s->in_ch_layout.nb_channels;
337 if (!av_channel_layout_check(&s->used_ch_layout))
338 av_channel_layout_default(&s->used_ch_layout, s->in.ch_count);
339 if(!s->out.ch_count)
340 s->out.ch_count = s->out_ch_layout.nb_channels;
341
342 if(!s-> in.ch_count){
343 av_assert0(s->in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC);
344 av_log(s, AV_LOG_ERROR, "Input channel count and layout are unset\n");
345 ret = AVERROR(EINVAL);
346 goto fail;
347 }
348
349 if (s->in_ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && s->used_ch_layout.nb_channels != s->in_ch_layout.nb_channels) {
350 av_log(s, AV_LOG_ERROR, "Input channel layout %s mismatches specified channel count %d\n", l1, s->used_ch_layout.nb_channels);
351 ret = AVERROR(EINVAL);
352 goto fail;
353 }
354
355av_assert0(s->used_ch_layout.nb_channels);
356av_assert0(s->out.ch_count);
357 s->resample_first= RSC*s->out.ch_count/s->used_ch_layout.nb_channels - RSC < s->out_sample_rate/(float)s-> in_sample_rate - 1.0;
358
359 s->in_buffer= s->in;
360 s->silence = s->in;
361 s->drop_temp= s->out;
362
363 if ((ret = swri_dither_init(s, s->out_sample_fmt, s->int_sample_fmt)) < 0)
364 goto fail;
365
366 if(!s->resample && !s->rematrix && !s->channel_map && !s->dither.method){
367 s->full_convert = swri_audio_convert_alloc(s->out_sample_fmt,
368 s-> in_sample_fmt, s-> in.ch_count, NULL, 0);
369 // fall through to the generic path for conversions that have no
370 // direct implementation (e.g. DSD input to non-float output)
371 if (s->full_convert)
372 return 0;
373 }
374
375 s->in_convert = swri_audio_convert_alloc(s->int_sample_fmt,
376 s-> in_sample_fmt, s->used_ch_layout.nb_channels, s->channel_map, 0);
377 s->out_convert= swri_audio_convert_alloc(s->out_sample_fmt,
378 s->int_sample_fmt, s->out.ch_count, NULL, 0);
379
380 if (!s->in_convert || !s->out_convert) {
381 av_log(s, AV_LOG_ERROR, "Cannot convert %s sample format to %s sample format\n",
382 av_get_sample_fmt_name(!s->in_convert ? s->in_sample_fmt : s->int_sample_fmt),
383 av_get_sample_fmt_name(!s->in_convert ? s->int_sample_fmt : s->out_sample_fmt));
384 ret = AVERROR(EINVAL);
385 goto fail;
386 }
387
388 s->postin= s->in;
389 s->preout= s->out;
390 s->midbuf= s->in;
391
392 if(s->channel_map){
393 s->postin.ch_count=
394 s->midbuf.ch_count= s->used_ch_layout.nb_channels;
395 if(s->resample)
396 s->in_buffer.ch_count= s->used_ch_layout.nb_channels;
397 }
398 if(!s->resample_first){
399 s->midbuf.ch_count= s->out.ch_count;
400 if(s->resample)
401 s->in_buffer.ch_count = s->out.ch_count;
402 }
403
404 set_audiodata_fmt(&s->postin, s->int_sample_fmt);
405 set_audiodata_fmt(&s->midbuf, s->int_sample_fmt);
406 set_audiodata_fmt(&s->preout, s->int_sample_fmt);
407
408 if(s->resample){
409 set_audiodata_fmt(&s->in_buffer, s->int_sample_fmt);
410 }
411
412 av_assert0(!s->preout.count);
413 s->dither.noise = s->preout;
414 s->dither.temp = s->preout;
415 if (s->dither.method > SWR_DITHER_NS) {
416 s->dither.noise.bps = 4;
417 s->dither.noise.fmt = AV_SAMPLE_FMT_FLTP;
418 s->dither.noise_scale = 1;
419 }
420
421 if(s->rematrix || s->dither.method) {
422 ret = swri_rematrix_init(s);
423 if (ret < 0)
424 goto fail;
425 }
426
427 return 0;
428fail:
429 swr_close(s);
430 return ret;
431
432}
433
435 int i, countb;
436 AudioData old;
437
438 if(count < 0 || count > INT_MAX/2/a->bps/a->ch_count)
439 return AVERROR(EINVAL);
440
441 if(a->count >= count)
442 return 0;
443
444 count*=2;
445
446 countb= FFALIGN(count*a->bps, ALIGN);
447 old= *a;
448
449 av_assert0(a->bps);
450 av_assert0(a->ch_count);
451
452 a->data = av_calloc(countb, a->ch_count);
453 if(!a->data)
454 return AVERROR(ENOMEM);
455 for(i=0; i<a->ch_count; i++){
456 a->ch[i]= a->data + i*(a->planar ? countb : a->bps);
457 if(a->count && a->planar) memcpy(a->ch[i], old.ch[i], a->count*a->bps);
458 }
459 if(a->count && !a->planar) memcpy(a->ch[0], old.ch[0], a->count*a->ch_count*a->bps);
460 av_freep(&old.data);
461 a->count= count;
462
463 return 1;
464}
465
467 int count){
468 av_assert0(out->planar == in->planar);
469 av_assert0(out->bps == in->bps);
470 av_assert0(out->ch_count == in->ch_count);
471 if(out->planar){
472 int ch;
473 for(ch=0; ch<out->ch_count; ch++)
474 memcpy(out->ch[ch], in->ch[ch], count*out->bps);
475 }else
476 memcpy(out->ch[0], in->ch[0], count*out->ch_count*out->bps);
477}
478
479static void fill_audiodata(AudioData *out, uint8_t *const in_arg [SWR_CH_MAX])
480{
481 int i;
482 if(!in_arg){
483 memset(out->ch, 0, sizeof(out->ch));
484 }else if(out->planar){
485 for(i=0; i<out->ch_count; i++)
486 out->ch[i]= in_arg[i];
487 }else{
488 for(i=0; i<out->ch_count; i++)
489 out->ch[i]= in_arg[0] + i*out->bps;
490 }
491}
492
493static void reversefill_audiodata(AudioData *out, uint8_t *in_arg [SWR_CH_MAX]){
494 int i;
495 if(out->planar){
496 for(i=0; i<out->ch_count; i++)
497 in_arg[i]= out->ch[i];
498 }else{
499 in_arg[0]= out->ch[0];
500 }
501}
502
503/**
504 *
505 * out may be equal in.
506 */
507static void buf_set(AudioData *out, AudioData *in, int count){
508 int ch;
509 if(in->planar){
510 for(ch=0; ch<out->ch_count; ch++)
511 out->ch[ch]= in->ch[ch] + count*out->bps;
512 }else{
513 for(ch=out->ch_count-1; ch>=0; ch--)
514 out->ch[ch]= in->ch[0] + (ch + count*out->ch_count) * out->bps;
515 }
516}
517
518/**
519 *
520 * @return number of samples output per channel
521 */
522static int resample(SwrContext *s, AudioData *out_param, int out_count,
523 const AudioData * in_param, int in_count){
525 int ret_sum=0;
526 int border=0;
527 int padless = ARCH_X86 && s->engine == SWR_ENGINE_SWR ? 7 : 0;
528
529 av_assert1(s->in_buffer.ch_count == in_param->ch_count);
530 av_assert1(s->in_buffer.planar == in_param->planar);
531 av_assert1(s->in_buffer.fmt == in_param->fmt);
532
533 tmp=out=*out_param;
534 in = *in_param;
535
536 border = s->resampler->invert_initial_buffer(s->resample, &s->in_buffer,
537 &in, in_count, &s->in_buffer_index, &s->in_buffer_count);
538 if (border == INT_MAX) {
539 return 0;
540 } else if (border < 0) {
541 return border;
542 } else if (border) {
543 buf_set(&in, &in, border);
544 in_count -= border;
545 s->resample_in_constraint = 0;
546 }
547
548 do{
549 int ret, size, consumed;
550 if(!s->resample_in_constraint && s->in_buffer_count){
551 buf_set(&tmp, &s->in_buffer, s->in_buffer_index);
552 ret= s->resampler->multiple_resample(s->resample, &out, out_count, &tmp, s->in_buffer_count, &consumed);
553 out_count -= ret;
554 ret_sum += ret;
555 buf_set(&out, &out, ret);
556 s->in_buffer_count -= consumed;
557 s->in_buffer_index += consumed;
558
559 if(!in_count)
560 break;
561 if(s->in_buffer_count <= border){
562 buf_set(&in, &in, -s->in_buffer_count);
563 in_count += s->in_buffer_count;
564 s->in_buffer_count=0;
565 s->in_buffer_index=0;
566 border = 0;
567 }
568 }
569
570 if((s->flushed || in_count > padless) && !s->in_buffer_count){
571 s->in_buffer_index=0;
572 ret= s->resampler->multiple_resample(s->resample, &out, out_count, &in, FFMAX(in_count-padless, 0), &consumed);
573 out_count -= ret;
574 ret_sum += ret;
575 buf_set(&out, &out, ret);
576 in_count -= consumed;
577 buf_set(&in, &in, consumed);
578 }
579
580 //TODO is this check sane considering the advanced copy avoidance below
581 size= s->in_buffer_index + s->in_buffer_count + in_count;
582 if( size > s->in_buffer.count
583 && s->in_buffer_count + in_count <= s->in_buffer_index){
584 buf_set(&tmp, &s->in_buffer, s->in_buffer_index);
585 copy(&s->in_buffer, &tmp, s->in_buffer_count);
586 s->in_buffer_index=0;
587 }else
588 if((ret=swri_realloc_audio(&s->in_buffer, size)) < 0)
589 return ret;
590
591 if(in_count){
592 int count= in_count;
593 if(s->in_buffer_count && s->in_buffer_count+2 < count && out_count) count= s->in_buffer_count+2;
594
595 buf_set(&tmp, &s->in_buffer, s->in_buffer_index + s->in_buffer_count);
596 copy(&tmp, &in, /*in_*/count);
597 s->in_buffer_count += count;
598 in_count -= count;
599 border += count;
600 buf_set(&in, &in, count);
601 s->resample_in_constraint= 0;
602 if(s->in_buffer_count != count || in_count)
603 continue;
604 if (padless) {
605 padless = 0;
606 continue;
607 }
608 }
609 break;
610 }while(1);
611
612 s->resample_in_constraint= !!out_count;
613
614 return ret_sum;
615}
616
617static int swr_convert_internal(struct SwrContext *s, AudioData *out, int out_count,
618 AudioData *in , int in_count){
620 int ret/*, in_max*/;
621 AudioData preout_tmp, midbuf_tmp;
622
623 if(s->full_convert){
624 av_assert0(!s->resample);
625 swri_audio_convert(s->full_convert, out, in, in_count);
626 return out_count;
627 }
628
629// in_max= out_count*(int64_t)s->in_sample_rate / s->out_sample_rate + resample_filter_taps;
630// in_count= FFMIN(in_count, in_in + 2 - s->hist_buffer_count);
631
632 if((ret=swri_realloc_audio(&s->postin, in_count))<0)
633 return ret;
634 if(s->resample_first){
635 av_assert0(s->midbuf.ch_count == s->used_ch_layout.nb_channels);
636 if((ret=swri_realloc_audio(&s->midbuf, out_count))<0)
637 return ret;
638 }else{
639 av_assert0(s->midbuf.ch_count == s->out.ch_count);
640 if((ret=swri_realloc_audio(&s->midbuf, in_count))<0)
641 return ret;
642 }
643 if((ret=swri_realloc_audio(&s->preout, out_count))<0)
644 return ret;
645
646 postin= &s->postin;
647
648 midbuf_tmp= s->midbuf;
649 midbuf= &midbuf_tmp;
650 preout_tmp= s->preout;
651 preout= &preout_tmp;
652
653 if(s->int_sample_fmt == s-> in_sample_fmt && s->in.planar && !s->channel_map)
654 postin= in;
655
656 if(s->resample_first ? !s->resample : !s->rematrix)
657 midbuf= postin;
658
659 if(s->resample_first ? !s->rematrix : !s->resample)
660 preout= midbuf;
661
662 if(s->int_sample_fmt == s->out_sample_fmt && s->out.planar
663 && !(s->out_sample_fmt==AV_SAMPLE_FMT_S32P && (s->dither.output_sample_bits&31))){
664 if(preout==in){
665 out_count= FFMIN(out_count, in_count); //TODO check at the end if this is needed or redundant
666 av_assert0(s->in.planar); //we only support planar internally so it has to be, we support copying non planar though
667 copy(out, in, out_count);
668 return out_count;
669 }
670 else if(preout==postin) preout= midbuf= postin= out;
671 else if(preout==midbuf) preout= midbuf= out;
672 else preout= out;
673 }
674
675 if(in != postin){
676 swri_audio_convert(s->in_convert, postin, in, in_count);
677 }
678
679 if(s->resample_first){
680 if(postin != midbuf)
681 if ((out_count = resample(s, midbuf, out_count, postin, in_count)) < 0)
682 return out_count;
683 if(midbuf != preout && out_count)
684 swri_rematrix(s, preout, midbuf, out_count, preout==out);
685 }else{
686 if(postin != midbuf && in_count)
687 swri_rematrix(s, midbuf, postin, in_count, midbuf==out);
688 if(midbuf != preout)
689 if ((out_count = resample(s, preout, out_count, midbuf, in_count)) < 0)
690 return out_count;
691 }
692
693 if(preout != out && out_count){
694 AudioData *conv_src = preout;
695 if(s->dither.method){
696 int ch;
697 int dither_count= FFMAX(out_count, 1<<16);
698
699 if (preout == in) {
700 conv_src = &s->dither.temp;
701 if((ret=swri_realloc_audio(&s->dither.temp, dither_count))<0)
702 return ret;
703 }
704
705 if((ret=swri_realloc_audio(&s->dither.noise, dither_count))<0)
706 return ret;
707 if(ret)
708 for(ch=0; ch<s->dither.noise.ch_count; ch++)
709 if((ret=swri_get_dither(s, s->dither.noise.ch[ch], s->dither.noise.count, (12345678913579ULL*ch + 3141592) % 2718281828U, s->dither.noise.fmt))<0)
710 return ret;
711 av_assert0(s->dither.noise.ch_count == preout->ch_count);
712
713 if(s->dither.noise_pos + out_count > s->dither.noise.count)
714 s->dither.noise_pos = 0;
715
716 if (s->dither.method < SWR_DITHER_NS){
717 if (s->mix_2_1_simd) {
718 int len1= out_count&~15;
719 int off = len1 * preout->bps;
720
721 if(len1)
722 for(ch=0; ch<preout->ch_count; ch++)
723 s->mix_2_1_simd(conv_src->ch[ch], preout->ch[ch], s->dither.noise.ch[ch] + s->dither.noise.bps * s->dither.noise_pos, &s->native_simd_one, 0, 0, len1);
724 if(out_count != len1)
725 for(ch=0; ch<preout->ch_count; ch++)
726 s->mix_2_1_f(conv_src->ch[ch] + off, preout->ch[ch] + off, s->dither.noise.ch[ch] + s->dither.noise.bps * s->dither.noise_pos + off, &s->native_one, 0, 0, out_count - len1);
727 } else {
728 for(ch=0; ch<preout->ch_count; ch++)
729 s->mix_2_1_f(conv_src->ch[ch], preout->ch[ch], s->dither.noise.ch[ch] + s->dither.noise.bps * s->dither.noise_pos, &s->native_one, 0, 0, out_count);
730 }
731 } else {
732 switch(s->int_sample_fmt) {
733 case AV_SAMPLE_FMT_S16P :swri_noise_shaping_int16(s, conv_src, preout, &s->dither.noise, out_count); break;
734 case AV_SAMPLE_FMT_S32P :swri_noise_shaping_int32(s, conv_src, preout, &s->dither.noise, out_count); break;
735 case AV_SAMPLE_FMT_FLTP :swri_noise_shaping_float(s, conv_src, preout, &s->dither.noise, out_count); break;
736 case AV_SAMPLE_FMT_DBLP :swri_noise_shaping_double(s,conv_src, preout, &s->dither.noise, out_count); break;
737 }
738 }
739 s->dither.noise_pos += out_count;
740 }
741//FIXME packed doesn't need more than 1 chan here!
742 swri_audio_convert(s->out_convert, out, conv_src, out_count);
743 }
744 return out_count;
745}
746
748 return !!s->in_buffer.ch_count;
749}
750
752 uint8_t * const *out_arg, int out_count,
753 const uint8_t * const *in_arg, int in_count)
754{
755 AudioData * in= &s->in;
756 AudioData *out= &s->out;
757
758 if (!swr_is_initialized(s)) {
759 av_log(s, AV_LOG_ERROR, "Context has not been initialized\n");
760 return AVERROR(EINVAL);
761 }
762#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >1
763 int max_output = swr_get_out_samples(s, in_count);
764#endif
765
766 while(s->drop_output > 0){
767 int ret;
768 uint8_t *tmp_arg[SWR_CH_MAX];
769#define MAX_DROP_STEP 16384
770 if((ret=swri_realloc_audio(&s->drop_temp, FFMIN(s->drop_output, MAX_DROP_STEP)))<0)
771 return ret;
772
773 reversefill_audiodata(&s->drop_temp, tmp_arg);
774 s->drop_output *= -1; //FIXME find a less hackish solution
775 ret = swr_convert(s, tmp_arg, FFMIN(-s->drop_output, MAX_DROP_STEP), in_arg, in_count); //FIXME optimize but this is as good as never called so maybe it doesn't matter
776 s->drop_output *= -1;
777 in_count = 0;
778 if(ret>0) {
779 s->drop_output -= ret;
780 if (!s->drop_output && !out_arg)
781 return 0;
782 continue;
783 }
784
785 av_assert0(s->drop_output);
786 return 0;
787 }
788
789 if(!in_arg){
790 if(s->resample){
791 if (!s->flushed)
792 s->resampler->flush(s);
793 s->resample_in_constraint = 0;
794 s->flushed = 1;
795 }else if(!s->in_buffer_count){
796 return 0;
797 }
798 }else
799 fill_audiodata(in , (void*)in_arg);
800
801 fill_audiodata(out, out_arg);
802
803 if(s->resample){
804 int ret = swr_convert_internal(s, out, out_count, in, in_count);
805 if(ret>0 && !s->drop_output)
806 s->outpts += ret * (int64_t)s->in_sample_rate;
807
808 av_assert2(max_output < 0 || ret <= max_output);
809
810 return ret;
811 }else{
812 AudioData tmp= *in;
813 int ret2=0;
814 int ret, size;
815 size = FFMIN(out_count, s->in_buffer_count);
816 if(size){
817 buf_set(&tmp, &s->in_buffer, s->in_buffer_index);
819 if(ret<0)
820 return ret;
821 ret2= ret;
822 s->in_buffer_count -= ret;
823 s->in_buffer_index += ret;
824 buf_set(out, out, ret);
825 out_count -= ret;
826 if(!s->in_buffer_count)
827 s->in_buffer_index = 0;
828 }
829
830 if(in_count){
831 size= s->in_buffer_index + s->in_buffer_count + in_count - out_count;
832
833 if(in_count > out_count) { //FIXME move after swr_convert_internal
834 if( size > s->in_buffer.count
835 && s->in_buffer_count + in_count - out_count <= s->in_buffer_index){
836 buf_set(&tmp, &s->in_buffer, s->in_buffer_index);
837 copy(&s->in_buffer, &tmp, s->in_buffer_count);
838 s->in_buffer_index=0;
839 }else
840 if((ret=swri_realloc_audio(&s->in_buffer, size)) < 0)
841 return ret;
842 }
843
844 if(out_count){
845 size = FFMIN(in_count, out_count);
847 if(ret<0)
848 return ret;
849 buf_set(in, in, ret);
850 in_count -= ret;
851 ret2 += ret;
852 }
853 if(in_count){
854 buf_set(&tmp, &s->in_buffer, s->in_buffer_index + s->in_buffer_count);
855 copy(&tmp, in, in_count);
856 s->in_buffer_count += in_count;
857 }
858 }
859 if(ret2>0 && !s->drop_output)
860 s->outpts += ret2 * (int64_t)s->in_sample_rate;
861 av_assert2(max_output < 0 || ret2 < 0 || ret2 <= max_output);
862 return ret2;
863 }
864}
865
866int swr_drop_output(struct SwrContext *s, int count){
867 const uint8_t *tmp_arg[SWR_CH_MAX];
868 s->drop_output += count;
869
870 if(s->drop_output <= 0)
871 return 0;
872
873 av_log(s, AV_LOG_VERBOSE, "discarding %d audio samples\n", count);
874 return swr_convert(s, NULL, s->drop_output, tmp_arg, 0);
875}
876
877int swr_inject_silence(struct SwrContext *s, int count){
878 int ret, i;
879 uint8_t *tmp_arg[SWR_CH_MAX];
880
881 if(count <= 0)
882 return 0;
883
884#define MAX_SILENCE_STEP 16384
885 while (count > MAX_SILENCE_STEP) {
886 if ((ret = swr_inject_silence(s, MAX_SILENCE_STEP)) < 0)
887 return ret;
888 count -= MAX_SILENCE_STEP;
889 }
890
891 if((ret=swri_realloc_audio(&s->silence, count))<0)
892 return ret;
893
894 {
895 int fill = s->silence.fmt == AV_SAMPLE_FMT_DSD ? 0x69 :
896 s->silence.bps == 1 ? 0x80 : 0;
897 if(s->silence.planar) for(i=0; i<s->silence.ch_count; i++) {
898 memset(s->silence.ch[i], fill, count*s->silence.bps);
899 } else
900 memset(s->silence.ch[0], fill, count*s->silence.bps*s->silence.ch_count);
901 }
902
903 reversefill_audiodata(&s->silence, tmp_arg);
904 av_log(s, AV_LOG_VERBOSE, "adding %d audio samples of silence\n", count);
905 ret = swr_convert(s, NULL, 0, (const uint8_t**)tmp_arg, count);
906 return ret;
907}
908
910 if (s->resampler && s->resample){
911 return s->resampler->get_delay(s, base);
912 }else{
913 return (s->in_buffer_count*base + (s->in_sample_rate>>1))/ s->in_sample_rate;
914 }
915}
916
917int swr_get_out_samples(struct SwrContext *s, int in_samples)
918{
919 int64_t out_samples;
920
921 if (in_samples < 0)
922 return AVERROR(EINVAL);
923
924 if (s->resampler && s->resample) {
925 if (!s->resampler->get_out_samples)
926 return AVERROR(ENOSYS);
927 out_samples = s->resampler->get_out_samples(s, in_samples);
928 } else {
929 out_samples = s->in_buffer_count + in_samples;
930 av_assert0(s->out_sample_rate == s->in_sample_rate);
931 }
932
933 if (out_samples > INT_MAX)
934 return AVERROR(EINVAL);
935
936 return out_samples;
937}
938
939int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance){
940 int ret;
941
942 if (!s || compensation_distance < 0)
943 return AVERROR(EINVAL);
944 if (!compensation_distance && sample_delta)
945 return AVERROR(EINVAL);
946 if (!s->resample) {
947 s->flags |= SWR_FLAG_RESAMPLE;
948 ret = swr_init(s);
949 if (ret < 0)
950 return ret;
951 }
952 if (!s->resampler->set_compensation){
953 return AVERROR(EINVAL);
954 }else{
955 return s->resampler->set_compensation(s->resample, sample_delta, compensation_distance);
956 }
957}
958
960 if(pts == INT64_MIN)
961 return s->outpts;
962
963 if (s->firstpts == AV_NOPTS_VALUE)
964 s->outpts = s->firstpts = pts;
965
966 if(s->min_compensation >= FLT_MAX) {
967 return (s->outpts = pts - swr_get_delay(s, s->in_sample_rate * (int64_t)s->out_sample_rate));
968 } else {
969 int64_t delta = pts - swr_get_delay(s, s->in_sample_rate * (int64_t)s->out_sample_rate) - s->outpts + s->drop_output*(int64_t)s->in_sample_rate;
970 double fdelta = delta /(double)(s->in_sample_rate * (int64_t)s->out_sample_rate);
971
972 if(fabs(fdelta) > s->min_compensation) {
973 if(s->outpts == s->firstpts || fabs(fdelta) > s->min_hard_compensation){
974 int ret;
975 if(delta > 0) ret = swr_inject_silence(s, delta / s->out_sample_rate);
976 else ret = swr_drop_output (s, -delta / s-> in_sample_rate);
977 if(ret<0){
978 av_log(s, AV_LOG_ERROR, "Failed to compensate for timestamp delta of %f\n", fdelta);
979 }
980 } else if(s->soft_compensation_duration && s->max_soft_compensation) {
981 int duration = s->out_sample_rate * s->soft_compensation_duration;
982 double max_soft_compensation = s->max_soft_compensation / (s->max_soft_compensation < 0 ? -s->in_sample_rate : 1);
984 av_log(s, AV_LOG_VERBOSE, "compensating audio timestamp drift:%f compensation:%d in:%d\n", fdelta, comp, duration);
986 }
987 }
988
989 return s->outpts;
990 }
991}
#define SWR_CH_MAX
Definition af_amerge.c:37
static FILE * out
static const uint8_t channel_map[8][8]
Audio format conversion routines.
AudioConvert * swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags)
Create an audio sample format converter context.
void swri_audio_convert_free(AudioConvert **ctx)
Free audio sample format converter context.
int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len)
Convert between audio sample formats.
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition avassert.h:68
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define ss(width, name, subs,...)
Definition cbs_vp9.c:202
#define s(width, name)
Definition cbs_vp9.c:198
Public libavutil channel layout APIs header.
#define ARCH_X86
#define av_clipf
Definition common.h:145
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static __device__ float fabs(float a)
av_cold int swri_dither_init(SwrContext *s, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt)
Definition dither.c:80
int swri_get_dither(SwrContext *s, void *dst, int len, unsigned seed, enum AVSampleFormat noise_fmt)
Definition dither.c:27
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition eamad.c:79
static int64_t duration
Definition ffplay.c:399
#define fail
Definition test.h:479
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition samplefmt.c:115
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition samplefmt.c:109
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
Definition samplefmt.c:87
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:52
AVSampleFormat
Audio sample formats.
Definition samplefmt.h:55
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition samplefmt.h:66
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition samplefmt.h:64
@ AV_SAMPLE_FMT_DSD
DSD (Direct Stream Digital) bitstream, interleaved.
Definition samplefmt.h:77
@ AV_SAMPLE_FMT_NB
Number of sample formats. DO NOT USE if linking dynamically.
Definition samplefmt.h:79
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition samplefmt.h:65
@ AV_SAMPLE_FMT_NONE
Definition samplefmt.h:56
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition samplefmt.h:67
@ AV_SAMPLE_FMT_S64P
signed 64 bits, planar
Definition samplefmt.h:69
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
av_cold struct SwrContext * swr_alloc(void)
Allocate SwrContext.
Definition options.c:148
int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map)
Set a customized input channel mapping.
Definition swresample.c:47
#define SWR_FLAG_RESAMPLE
Force resampling even if equal sample rate.
Definition swresample.h:143
int swr_drop_output(struct SwrContext *s, int count)
Drops the specified number of output samples.
Definition swresample.c:866
int swr_inject_silence(struct SwrContext *s, int count)
Injects the specified number of silence samples.
Definition swresample.c:877
int64_t swr_get_delay(struct SwrContext *s, int64_t base)
Gets the delay the next input sample will experience relative to the next output sample.
Definition swresample.c:909
int swr_alloc_set_opts2(struct SwrContext **ps, const AVChannelLayout *out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, const AVChannelLayout *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:54
av_cold void swr_free(SwrContext **ss)
Free the given SwrContext and set the pointer to NULL.
Definition swresample.c:137
int swr_get_out_samples(struct SwrContext *s, int in_samples)
Find an upper bound on the number of samples that the next swr_convert call will output,...
Definition swresample.c:917
av_cold void swr_close(SwrContext *s)
Closes the context so that swr_is_initialized() returns 0.
Definition swresample.c:152
int64_t swr_next_pts(struct SwrContext *s, int64_t pts)
Convert the next timestamp from input to output timestamps are in 1/(in_sample_rate * out_sample_rate...
Definition swresample.c:959
int swr_is_initialized(struct SwrContext *s)
Check whether an swr context has been initialized or not.
Definition swresample.c:747
int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance)
Activate resampling compensation ("soft" compensation).
Definition swresample.c:939
int attribute_align_arg swr_convert(struct SwrContext *s, uint8_t *const *out_arg, int out_count, const uint8_t *const *in_arg, int in_count)
Convert audio.
Definition swresample.c:751
av_cold int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.
Definition swresample.c:156
@ SWR_DITHER_NS
not part of API/ABI
Definition swresample.h:154
@ SWR_ENGINE_SWR
SW Resampler.
Definition swresample.h:167
@ SWR_ENGINE_SOXR
SoX Resampler.
Definition swresample.h:168
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition opt.c:938
int av_opt_set_chlayout(void *obj, const char *name, const AVChannelLayout *channel_layout, int search_flags)
Definition opt.c:1073
int a
#define ALIGN
Definition hashtable.c:32
#define av_cold
Definition attributes.h:117
common internal API header
#define attribute_align_arg
Definition internal.h:51
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define FFALIGN(x, a)
Definition macros.h:78
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:370
Memory handling functions.
AVOptions.
const char * name
Definition qsvenc.c:142
int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy)
Definition rematrix.c:867
av_cold int swri_rematrix_init(SwrContext *s)
Definition rematrix.c:753
av_cold int swri_rematrix_build(SwrContext *s)
Definition rematrix.c:713
av_cold void swri_rematrix_free(SwrContext *s)
Definition rematrix.c:862
const struct Resampler swri_resampler
Definition resample.c:504
const struct Resampler swri_soxr_resampler
An AVChannelLayout holds information about the channel layout of audio data.
enum AVChannelOrder order
Channel order used in this layout.
int nb_channels
Number of channels in this layout.
uint8_t * data
samples buffer
int ch_count
number of channels
int planar
1 if planar audio, 0 otherwise
uint8_t * ch[SWR_CH_MAX]
samples buffer per channel
int bps
bytes per sample
enum AVSampleFormat fmt
sample format
The libswresample context.
AVChannelLayout user_out_chlayout
User set output channel layout.
AudioData in
input audio data
AVChannelLayout user_in_chlayout
User set input channel layout.
float max_soft_compensation
swr maximum soft compensation in seconds over soft_compensation_duration
int out_sample_rate
output sample rate
int in_buffer_index
cached buffer position
AudioData postin
post-input audio data: used for rematrix/resample
int in_sample_rate
input sample rate
AudioData midbuf
intermediate audio data (postin/preout)
void * log_ctx
parent logging context
AudioData preout
pre-output audio data: used for rematrix/resample
AVChannelLayout out_ch_layout
output channel layout
enum AVSampleFormat in_sample_fmt
input sample format
struct AudioConvert * in_convert
input conversion context
AVChannelLayout in_ch_layout
input channel layout
enum AVSampleFormat out_sample_fmt
output sample format
static int swr_convert_internal(struct SwrContext *s, AudioData *out, int out_count, AudioData *in, int in_count)
Definition swresample.c:617
static void copy(AudioData *out, AudioData *in, int count)
Definition swresample.c:466
#define MAX_DROP_STEP
static void buf_set(AudioData *out, AudioData *in, int count)
out may be equal in.
Definition swresample.c:507
static void reversefill_audiodata(AudioData *out, uint8_t *in_arg[SWR_CH_MAX])
Definition swresample.c:493
static void fill_audiodata(AudioData *out, uint8_t *const in_arg[SWR_CH_MAX])
Definition swresample.c:479
static int resample(SwrContext *s, AudioData *out_param, int out_count, const AudioData *in_param, int in_count)
Definition swresample.c:522
static void clear_context(SwrContext *s)
Definition swresample.c:111
int swri_check_chlayout(struct SwrContext *s, const AVChannelLayout *chl, const char *name)
Definition swresample.c:33
static void free_temp(AudioData *a)
Definition swresample.c:106
#define MAX_SILENCE_STEP
static void set_audiodata_fmt(AudioData *a, enum AVSampleFormat fmt)
Definition swresample.c:98
int swri_realloc_audio(AudioData *a, int count)
Definition swresample.c:434
#define RSC
void swri_noise_shaping_int16(SwrContext *s, AudioData *dsts, const AudioData *srcs, const AudioData *noises, int count)
void swri_noise_shaping_int32(SwrContext *s, AudioData *dsts, const AudioData *srcs, const AudioData *noises, int count)
void swri_noise_shaping_float(SwrContext *s, AudioData *dsts, const AudioData *srcs, const AudioData *noises, int count)
void swri_noise_shaping_double(SwrContext *s, AudioData *dsts, const AudioData *srcs, const AudioData *noises, int count)
#define av_free(p)
#define av_freep(p)
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52
static int64_t pts
int size
float delta
uint8_t base
Definition vp3data.h:128