FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
af_resample.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 /**
20  * @file
21  * sample format and channel layout conversion audio filter
22  */
23 
24 #include "libavutil/avassert.h"
25 #include "libavutil/avstring.h"
26 #include "libavutil/common.h"
27 #include "libavutil/dict.h"
28 #include "libavutil/mathematics.h"
29 #include "libavutil/opt.h"
30 
32 
33 #include "audio.h"
34 #include "avfilter.h"
35 #include "formats.h"
36 #include "internal.h"
37 
38 typedef struct ResampleContext {
39  const AVClass *class;
42 
44  int64_t next_pts;
45  int64_t next_in_pts;
46 
47  /* set by filter_frame() to signal an output frame to request_frame() */
50 
51 static av_cold int init(AVFilterContext *ctx, AVDictionary **opts)
52 {
53  ResampleContext *s = ctx->priv;
54  const AVClass *avr_class = avresample_get_class();
56 
57  while ((e = av_dict_get(*opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
58  if (av_opt_find(&avr_class, e->key, NULL, 0,
60  av_dict_set(&s->options, e->key, e->value, 0);
61  }
62 
63  e = NULL;
64  while ((e = av_dict_get(s->options, "", e, AV_DICT_IGNORE_SUFFIX)))
65  av_dict_set(opts, e->key, NULL, 0);
66 
67  /* do not allow the user to override basic format options */
68  av_dict_set(&s->options, "in_channel_layout", NULL, 0);
69  av_dict_set(&s->options, "out_channel_layout", NULL, 0);
70  av_dict_set(&s->options, "in_sample_fmt", NULL, 0);
71  av_dict_set(&s->options, "out_sample_fmt", NULL, 0);
72  av_dict_set(&s->options, "in_sample_rate", NULL, 0);
73  av_dict_set(&s->options, "out_sample_rate", NULL, 0);
74 
75  return 0;
76 }
77 
78 static av_cold void uninit(AVFilterContext *ctx)
79 {
80  ResampleContext *s = ctx->priv;
81 
82  if (s->avr) {
84  avresample_free(&s->avr);
85  }
86  av_dict_free(&s->options);
87 }
88 
90 {
91  AVFilterLink *inlink = ctx->inputs[0];
92  AVFilterLink *outlink = ctx->outputs[0];
93 
96  AVFilterFormats *in_samplerates = ff_all_samplerates();
97  AVFilterFormats *out_samplerates = ff_all_samplerates();
100 
101  ff_formats_ref(in_formats, &inlink->out_formats);
102  ff_formats_ref(out_formats, &outlink->in_formats);
103 
104  ff_formats_ref(in_samplerates, &inlink->out_samplerates);
105  ff_formats_ref(out_samplerates, &outlink->in_samplerates);
106 
107  ff_channel_layouts_ref(in_layouts, &inlink->out_channel_layouts);
108  ff_channel_layouts_ref(out_layouts, &outlink->in_channel_layouts);
109 
110  return 0;
111 }
112 
113 static int config_output(AVFilterLink *outlink)
114 {
115  AVFilterContext *ctx = outlink->src;
116  AVFilterLink *inlink = ctx->inputs[0];
117  ResampleContext *s = ctx->priv;
118  char buf1[64], buf2[64];
119  int ret;
120 
121  int64_t resampling_forced;
122 
123  if (s->avr) {
124  avresample_close(s->avr);
125  avresample_free(&s->avr);
126  }
127 
128  if (inlink->channel_layout == outlink->channel_layout &&
129  inlink->sample_rate == outlink->sample_rate &&
130  (inlink->format == outlink->format ||
133  av_get_planar_sample_fmt(inlink->format) ==
134  av_get_planar_sample_fmt(outlink->format))))
135  return 0;
136 
137  if (!(s->avr = avresample_alloc_context()))
138  return AVERROR(ENOMEM);
139 
140  if (s->options) {
141  int ret;
142  AVDictionaryEntry *e = NULL;
143  while ((e = av_dict_get(s->options, "", e, AV_DICT_IGNORE_SUFFIX)))
144  av_log(ctx, AV_LOG_VERBOSE, "lavr option: %s=%s\n", e->key, e->value);
145 
146  ret = av_opt_set_dict(s->avr, &s->options);
147  if (ret < 0)
148  return ret;
149  }
150 
151  av_opt_set_int(s->avr, "in_channel_layout", inlink ->channel_layout, 0);
152  av_opt_set_int(s->avr, "out_channel_layout", outlink->channel_layout, 0);
153  av_opt_set_int(s->avr, "in_sample_fmt", inlink ->format, 0);
154  av_opt_set_int(s->avr, "out_sample_fmt", outlink->format, 0);
155  av_opt_set_int(s->avr, "in_sample_rate", inlink ->sample_rate, 0);
156  av_opt_set_int(s->avr, "out_sample_rate", outlink->sample_rate, 0);
157 
158  if ((ret = avresample_open(s->avr)) < 0)
159  return ret;
160 
161  av_opt_get_int(s->avr, "force_resampling", 0, &resampling_forced);
162  s->resampling = resampling_forced || (inlink->sample_rate != outlink->sample_rate);
163 
164  if (s->resampling) {
165  outlink->time_base = (AVRational){ 1, outlink->sample_rate };
168  } else
169  outlink->time_base = inlink->time_base;
170 
171  av_get_channel_layout_string(buf1, sizeof(buf1),
172  -1, inlink ->channel_layout);
173  av_get_channel_layout_string(buf2, sizeof(buf2),
174  -1, outlink->channel_layout);
175  av_log(ctx, AV_LOG_VERBOSE,
176  "fmt:%s srate:%d cl:%s -> fmt:%s srate:%d cl:%s\n",
177  av_get_sample_fmt_name(inlink ->format), inlink ->sample_rate, buf1,
178  av_get_sample_fmt_name(outlink->format), outlink->sample_rate, buf2);
179 
180  return 0;
181 }
182 
183 static int request_frame(AVFilterLink *outlink)
184 {
185  AVFilterContext *ctx = outlink->src;
186  ResampleContext *s = ctx->priv;
187  int ret = 0;
188 
189  s->got_output = 0;
190  while (ret >= 0 && !s->got_output)
191  ret = ff_request_frame(ctx->inputs[0]);
192 
193  /* flush the lavr delay buffer */
194  if (ret == AVERROR_EOF && s->avr) {
195  AVFrame *frame;
196  int nb_samples = avresample_get_out_samples(s->avr, 0);
197 
198  if (!nb_samples)
199  return ret;
200 
201  frame = ff_get_audio_buffer(outlink, nb_samples);
202  if (!frame)
203  return AVERROR(ENOMEM);
204 
205  ret = avresample_convert(s->avr, frame->extended_data,
206  frame->linesize[0], nb_samples,
207  NULL, 0, 0);
208  if (ret <= 0) {
209  av_frame_free(&frame);
210  return (ret == 0) ? AVERROR_EOF : ret;
211  }
212 
213  frame->nb_samples = ret;
214  frame->pts = s->next_pts;
215  return ff_filter_frame(outlink, frame);
216  }
217  return ret;
218 }
219 
220 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
221 {
222  AVFilterContext *ctx = inlink->dst;
223  ResampleContext *s = ctx->priv;
224  AVFilterLink *outlink = ctx->outputs[0];
225  int ret;
226 
227  if (s->avr) {
228  AVFrame *out;
229  int delay, nb_samples;
230 
231  /* maximum possible samples lavr can output */
232  delay = avresample_get_delay(s->avr);
233  nb_samples = avresample_get_out_samples(s->avr, in->nb_samples);
234 
235  out = ff_get_audio_buffer(outlink, nb_samples);
236  if (!out) {
237  ret = AVERROR(ENOMEM);
238  goto fail;
239  }
240 
241  ret = avresample_convert(s->avr, out->extended_data, out->linesize[0],
242  nb_samples, in->extended_data, in->linesize[0],
243  in->nb_samples);
244  if (ret <= 0) {
245  av_frame_free(&out);
246  if (ret < 0)
247  goto fail;
248  }
249 
251 
252  if (s->resampling && s->next_pts == AV_NOPTS_VALUE) {
253  if (in->pts == AV_NOPTS_VALUE) {
254  av_log(ctx, AV_LOG_WARNING, "First timestamp is missing, "
255  "assuming 0.\n");
256  s->next_pts = 0;
257  } else
258  s->next_pts = av_rescale_q(in->pts, inlink->time_base,
259  outlink->time_base);
260  }
261 
262  if (ret > 0) {
263  out->nb_samples = ret;
264 
265  ret = av_frame_copy_props(out, in);
266  if (ret < 0) {
267  av_frame_free(&out);
268  goto fail;
269  }
270 
271  if (s->resampling) {
272  out->sample_rate = outlink->sample_rate;
273  /* Only convert in->pts if there is a discontinuous jump.
274  This ensures that out->pts tracks the number of samples actually
275  output by the resampler in the absence of such a jump.
276  Otherwise, the rounding in av_rescale_q() and av_rescale()
277  causes off-by-1 errors. */
278  if (in->pts != AV_NOPTS_VALUE && in->pts != s->next_in_pts) {
279  out->pts = av_rescale_q(in->pts, inlink->time_base,
280  outlink->time_base) -
281  av_rescale(delay, outlink->sample_rate,
282  inlink->sample_rate);
283  } else
284  out->pts = s->next_pts;
285 
286  s->next_pts = out->pts + out->nb_samples;
287  s->next_in_pts = in->pts + in->nb_samples;
288  } else
289  out->pts = in->pts;
290 
291  ret = ff_filter_frame(outlink, out);
292  s->got_output = 1;
293  }
294 
295 fail:
296  av_frame_free(&in);
297  } else {
298  in->format = outlink->format;
299  ret = ff_filter_frame(outlink, in);
300  s->got_output = 1;
301  }
302 
303  return ret;
304 }
305 
306 static const AVClass *resample_child_class_next(const AVClass *prev)
307 {
308  return prev ? NULL : avresample_get_class();
309 }
310 
311 static void *resample_child_next(void *obj, void *prev)
312 {
313  ResampleContext *s = obj;
314  return prev ? NULL : s->avr;
315 }
316 
317 static const AVClass resample_class = {
318  .class_name = "resample",
319  .item_name = av_default_item_name,
320  .version = LIBAVUTIL_VERSION_INT,
321  .child_class_next = resample_child_class_next,
323 };
324 
326  {
327  .name = "default",
328  .type = AVMEDIA_TYPE_AUDIO,
329  .filter_frame = filter_frame,
330  },
331  { NULL }
332 };
333 
335  {
336  .name = "default",
337  .type = AVMEDIA_TYPE_AUDIO,
338  .config_props = config_output,
339  .request_frame = request_frame
340  },
341  { NULL }
342 };
343 
345  .name = "resample",
346  .description = NULL_IF_CONFIG_SMALL("Audio resampling and conversion."),
347  .priv_size = sizeof(ResampleContext),
348  .priv_class = &resample_class,
349  .init_dict = init,
350  .uninit = uninit,
352  .inputs = avfilter_af_resample_inputs,
353  .outputs = avfilter_af_resample_outputs,
354 };
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
static const AVFilterPad avfilter_af_resample_outputs[]
Definition: af_resample.c:334
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
#define LIBAVUTIL_VERSION_INT
Definition: version.h:62
Main libavfilter public API header.
void avresample_free(AVAudioResampleContext **avr)
Free AVAudioResampleContext and associated AVOption values.
Definition: utils.c:278
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
const AVClass * avresample_get_class(void)
Get the AVClass for AVAudioResampleContext.
Definition: options.c:110
const char * name
Pad name.
Definition: internal.h:69
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:641
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Public dictionary API.
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:417
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1158
#define av_cold
Definition: attributes.h:74
AVAudioResampleContext * avr
Definition: af_resample.c:40
AVOptions.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:257
static AVFrame * frame
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:39
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
Definition: samplefmt.c:82
#define av_log(a,...)
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_resample.c:78
void avresample_close(AVAudioResampleContext *avr)
Close AVAudioResampleContext.
Definition: utils.c:262
AVFilterFormats * ff_all_formats(enum AVMediaType type)
Return a list of all formats supported by FFmpeg for the given media type.
Definition: formats.c:336
static int config_output(AVFilterLink *outlink)
Definition: af_resample.c:113
A filter pad used for either input or output.
Definition: internal.h:63
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:140
static av_cold int init(AVFilterContext *ctx, AVDictionary **opts)
Definition: af_resample.c:51
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:74
av_default_item_name
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:148
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
void * priv
private data for use by the filter
Definition: avfilter.h:654
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:199
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:491
simple assert() macros that are a bit more flexible than ISO C assert().
AVDictionary * options
Definition: af_resample.c:41
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
AVFilter ff_af_resample
Definition: af_resample.c:344
#define fail()
Definition: checkasm.h:57
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition: opt.c:1481
static const AVClass resample_class
Definition: af_resample.c:317
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:127
external API header
static void * resample_child_next(void *obj, void *prev)
Definition: af_resample.c:311
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:611
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:422
static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
Definition: af_aresample.c:47
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition: formats.c:385
A list of supported channel layouts.
Definition: formats.h:85
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.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:232
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
Definition: opt.c:823
int avresample_get_delay(AVAudioResampleContext *avr)
Return the number of samples currently in the resampling delay buffer.
Definition: resample.c:497
int avresample_available(AVAudioResampleContext *avr)
Return the number of available samples in the output FIFO.
Definition: utils.c:747
sample_rate
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition: opt.c:1476
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
int avresample_get_out_samples(AVAudioResampleContext *avr, int in_nb_samples)
Provide the upper bound on the number of samples the configured conversion would output.
Definition: utils.c:752
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:69
Describe the class of an AVClass context structure.
Definition: log.h:67
int sample_rate
Sample rate of the audio data.
Definition: frame.h:422
Filter definition.
Definition: avfilter.h:470
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
rational number numerator/denominator
Definition: rational.h:43
int avresample_convert(AVAudioResampleContext *avr, uint8_t **output, int out_plane_size, int out_samples, uint8_t **input, int in_plane_size, int in_samples)
Convert input samples and write them to the output FIFO.
Definition: utils.c:330
const char * name
Filter name.
Definition: avfilter.h:474
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_resample.c:220
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:379
static int request_frame(AVFilterLink *outlink)
Definition: af_resample.c:183
AVAudioResampleContext * avresample_alloc_context(void)
Allocate AVAudioResampleContext and set options.
Definition: options.c:96
static int query_formats(AVFilterContext *ctx)
Definition: af_resample.c:89
common internal and external API header
int64_t next_in_pts
Definition: af_resample.c:45
void *(* child_next)(void *obj, void *prev)
Return next AVOptions-enabled child or NULL.
Definition: log.h:113
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() is fake – only a double pointer to AVClass instead of a required poin...
Definition: opt.h:620
char * key
Definition: dict.h:87
char * value
Definition: dict.h:88
A list of supported formats for one end of a filter link.
Definition: formats.h:64
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
An instance of a filter.
Definition: avfilter.h:633
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
Definition: dict.h:72
static const AVClass * resample_child_class_next(const AVClass *prev)
Definition: af_resample.c:306
static const AVFilterPad avfilter_af_resample_inputs[]
Definition: af_resample.c:325
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:343
internal API functions
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:215
int avresample_open(AVAudioResampleContext *avr)
Initialize AVAudioResampleContext.
Definition: utils.c:36
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:225
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:553
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:240
int64_t next_pts
Definition: af_resample.c:44