af_resample.c
Go to the documentation of this file.
1 /*
2  *
3  * This file is part of Libav.
4  *
5  * Libav is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * Libav is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with Libav; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /**
21  * @file
22  * sample format and channel layout conversion audio filter
23  */
24 
25 #include "libavutil/avassert.h"
26 #include "libavutil/avstring.h"
27 #include "libavutil/common.h"
28 #include "libavutil/dict.h"
29 #include "libavutil/mathematics.h"
30 #include "libavutil/opt.h"
31 
33 
34 #include "audio.h"
35 #include "avfilter.h"
36 #include "formats.h"
37 #include "internal.h"
38 
39 typedef struct ResampleContext {
40  const AVClass *class;
43 
44  int64_t next_pts;
45 
46  /* set by filter_frame() to signal an output frame to request_frame() */
49 
50 static av_cold int init(AVFilterContext *ctx, AVDictionary **opts)
51 {
52  ResampleContext *s = ctx->priv;
53  const AVClass *avr_class = avresample_get_class();
55 
56  while ((e = av_dict_get(*opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
57  if (av_opt_find(&avr_class, e->key, NULL, 0,
59  av_dict_set(&s->options, e->key, e->value, 0);
60  }
61 
62  e = NULL;
63  while ((e = av_dict_get(s->options, "", e, AV_DICT_IGNORE_SUFFIX)))
64  av_dict_set(opts, e->key, NULL, 0);
65 
66  /* do not allow the user to override basic format options */
67  av_dict_set(&s->options, "in_channel_layout", NULL, 0);
68  av_dict_set(&s->options, "out_channel_layout", NULL, 0);
69  av_dict_set(&s->options, "in_sample_fmt", NULL, 0);
70  av_dict_set(&s->options, "out_sample_fmt", NULL, 0);
71  av_dict_set(&s->options, "in_sample_rate", NULL, 0);
72  av_dict_set(&s->options, "out_sample_rate", NULL, 0);
73 
74  return 0;
75 }
76 
77 static av_cold void uninit(AVFilterContext *ctx)
78 {
79  ResampleContext *s = ctx->priv;
80 
81  if (s->avr) {
83  avresample_free(&s->avr);
84  }
85  av_dict_free(&s->options);
86 }
87 
89 {
90  AVFilterLink *inlink = ctx->inputs[0];
91  AVFilterLink *outlink = ctx->outputs[0];
92 
95  AVFilterFormats *in_samplerates = ff_all_samplerates();
96  AVFilterFormats *out_samplerates = ff_all_samplerates();
99 
100  ff_formats_ref(in_formats, &inlink->out_formats);
101  ff_formats_ref(out_formats, &outlink->in_formats);
102 
103  ff_formats_ref(in_samplerates, &inlink->out_samplerates);
104  ff_formats_ref(out_samplerates, &outlink->in_samplerates);
105 
106  ff_channel_layouts_ref(in_layouts, &inlink->out_channel_layouts);
107  ff_channel_layouts_ref(out_layouts, &outlink->in_channel_layouts);
108 
109  return 0;
110 }
111 
112 static int config_output(AVFilterLink *outlink)
113 {
114  AVFilterContext *ctx = outlink->src;
115  AVFilterLink *inlink = ctx->inputs[0];
116  ResampleContext *s = ctx->priv;
117  char buf1[64], buf2[64];
118  int ret;
119 
120  if (s->avr) {
121  avresample_close(s->avr);
122  avresample_free(&s->avr);
123  }
124 
125  if (inlink->channel_layout == outlink->channel_layout &&
126  inlink->sample_rate == outlink->sample_rate &&
127  (inlink->format == outlink->format ||
130  av_get_planar_sample_fmt(inlink->format) ==
131  av_get_planar_sample_fmt(outlink->format))))
132  return 0;
133 
134  if (!(s->avr = avresample_alloc_context()))
135  return AVERROR(ENOMEM);
136 
137  if (s->options) {
138  AVDictionaryEntry *e = NULL;
139  while ((e = av_dict_get(s->options, "", e, AV_DICT_IGNORE_SUFFIX)))
140  av_log(ctx, AV_LOG_VERBOSE, "lavr option: %s=%s\n", e->key, e->value);
141 
142  av_opt_set_dict(s->avr, &s->options);
143  }
144 
145  av_opt_set_int(s->avr, "in_channel_layout", inlink ->channel_layout, 0);
146  av_opt_set_int(s->avr, "out_channel_layout", outlink->channel_layout, 0);
147  av_opt_set_int(s->avr, "in_sample_fmt", inlink ->format, 0);
148  av_opt_set_int(s->avr, "out_sample_fmt", outlink->format, 0);
149  av_opt_set_int(s->avr, "in_sample_rate", inlink ->sample_rate, 0);
150  av_opt_set_int(s->avr, "out_sample_rate", outlink->sample_rate, 0);
151 
152  if ((ret = avresample_open(s->avr)) < 0)
153  return ret;
154 
155  outlink->time_base = (AVRational){ 1, outlink->sample_rate };
157 
158  av_get_channel_layout_string(buf1, sizeof(buf1),
159  -1, inlink ->channel_layout);
160  av_get_channel_layout_string(buf2, sizeof(buf2),
161  -1, outlink->channel_layout);
162  av_log(ctx, AV_LOG_VERBOSE,
163  "fmt:%s srate:%d cl:%s -> fmt:%s srate:%d cl:%s\n",
164  av_get_sample_fmt_name(inlink ->format), inlink ->sample_rate, buf1,
165  av_get_sample_fmt_name(outlink->format), outlink->sample_rate, buf2);
166 
167  return 0;
168 }
169 
170 static int request_frame(AVFilterLink *outlink)
171 {
172  AVFilterContext *ctx = outlink->src;
173  ResampleContext *s = ctx->priv;
174  int ret = 0;
175 
176  s->got_output = 0;
177  while (ret >= 0 && !s->got_output)
178  ret = ff_request_frame(ctx->inputs[0]);
179 
180  /* flush the lavr delay buffer */
181  if (ret == AVERROR_EOF && s->avr) {
182  AVFrame *frame;
183  int nb_samples = av_rescale_rnd(avresample_get_delay(s->avr),
184  outlink->sample_rate,
185  ctx->inputs[0]->sample_rate,
186  AV_ROUND_UP);
187 
188  if (!nb_samples)
189  return ret;
190 
191  frame = ff_get_audio_buffer(outlink, nb_samples);
192  if (!frame)
193  return AVERROR(ENOMEM);
194 
195  ret = avresample_convert(s->avr, frame->extended_data,
196  frame->linesize[0], nb_samples,
197  NULL, 0, 0);
198  if (ret <= 0) {
199  av_frame_free(&frame);
200  return (ret == 0) ? AVERROR_EOF : ret;
201  }
202 
203  frame->pts = s->next_pts;
204  return ff_filter_frame(outlink, frame);
205  }
206  return ret;
207 }
208 
209 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
210 {
211  AVFilterContext *ctx = inlink->dst;
212  ResampleContext *s = ctx->priv;
213  AVFilterLink *outlink = ctx->outputs[0];
214  int ret;
215 
216  if (s->avr) {
217  AVFrame *out;
218  int delay, nb_samples;
219 
220  /* maximum possible samples lavr can output */
221  delay = avresample_get_delay(s->avr);
222  nb_samples = av_rescale_rnd(in->nb_samples + delay,
223  outlink->sample_rate, inlink->sample_rate,
224  AV_ROUND_UP);
225 
226  out = ff_get_audio_buffer(outlink, nb_samples);
227  if (!out) {
228  ret = AVERROR(ENOMEM);
229  goto fail;
230  }
231 
232  ret = avresample_convert(s->avr, out->extended_data, out->linesize[0],
233  nb_samples, in->extended_data, in->linesize[0],
234  in->nb_samples);
235  if (ret <= 0) {
236  av_frame_free(&out);
237  if (ret < 0)
238  goto fail;
239  }
240 
242 
243  if (s->next_pts == AV_NOPTS_VALUE) {
244  if (in->pts == AV_NOPTS_VALUE) {
245  av_log(ctx, AV_LOG_WARNING, "First timestamp is missing, "
246  "assuming 0.\n");
247  s->next_pts = 0;
248  } else
249  s->next_pts = av_rescale_q(in->pts, inlink->time_base,
250  outlink->time_base);
251  }
252 
253  if (ret > 0) {
254  out->nb_samples = ret;
255  if (in->pts != AV_NOPTS_VALUE) {
256  out->pts = av_rescale_q(in->pts, inlink->time_base,
257  outlink->time_base) -
258  av_rescale(delay, outlink->sample_rate,
259  inlink->sample_rate);
260  } else
261  out->pts = s->next_pts;
262 
263  s->next_pts = out->pts + out->nb_samples;
264 
265  ret = ff_filter_frame(outlink, out);
266  s->got_output = 1;
267  }
268 
269 fail:
270  av_frame_free(&in);
271  } else {
272  in->format = outlink->format;
273  ret = ff_filter_frame(outlink, in);
274  s->got_output = 1;
275  }
276 
277  return ret;
278 }
279 
280 static const AVClass *resample_child_class_next(const AVClass *prev)
281 {
282  return prev ? NULL : avresample_get_class();
283 }
284 
285 static void *resample_child_next(void *obj, void *prev)
286 {
287  ResampleContext *s = obj;
288  return prev ? NULL : s->avr;
289 }
290 
291 static const AVClass resample_class = {
292  .class_name = "resample",
293  .item_name = av_default_item_name,
294  .version = LIBAVUTIL_VERSION_INT,
295  .child_class_next = resample_child_class_next,
297 };
298 
300  {
301  .name = "default",
302  .type = AVMEDIA_TYPE_AUDIO,
303  .filter_frame = filter_frame,
304  },
305  { NULL }
306 };
307 
309  {
310  .name = "default",
311  .type = AVMEDIA_TYPE_AUDIO,
312  .config_props = config_output,
313  .request_frame = request_frame
314  },
315  { NULL }
316 };
317 
319  .name = "resample",
320  .description = NULL_IF_CONFIG_SMALL("Audio resampling and conversion."),
321  .priv_size = sizeof(ResampleContext),
322  .priv_class = &resample_class,
323 
324  .init_dict = init,
325  .uninit = uninit,
327 
328  .inputs = avfilter_af_resample_inputs,
329  .outputs = avfilter_af_resample_outputs,
330 };
const char * s
Definition: avisynth_c.h:668
AVAudioResampleContext * avr
Definition: af_resample.c:41
static const AVFilterPad avfilter_af_resample_outputs[]
Definition: af_resample.c:308
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
struct ResampleContext ResampleContext
av_default_item_name
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
Definition: mathematics.c:60
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
external API header
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
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
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:39
void avresample_free(AVAudioResampleContext **avr)
Free AVAudioResampleContext and associated AVOption values.
AVFilter avfilter_af_resample
Definition: af_resample.c:318
const AVClass * avresample_get_class(void)
Get the AVClass for AVAudioResampleContext.
const char * name
Pad name.
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:55
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:532
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Public dictionary API.
enum AVSampleFormat format
it can be given away to ff_start_frame *A reference passed to ff_filter_frame(or the deprecated ff_start_frame) is given away and must no longer be used.*A reference created with avfilter_ref_buffer belongs to the code that created it.*A reference obtained with ff_get_video_buffer or ff_get_audio_buffer belongs to the code that requested it.*A reference given as return value by the get_video_buffer or get_audio_buffer method is given away and must no longer be used.Link reference fields---------------------The AVFilterLink structure has a few AVFilterBufferRef fields.The cur_buf and out_buf were used with the deprecated start_frame/draw_slice/end_frame API and should no longer be used.src_buf
Round toward +infinity.
Definition: mathematics.h:71
#define av_cold
Definition: attributes.h:78
AVOptions.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:159
int64_t next_pts
Definition: af_resample.c:44
void ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:427
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 AVERROR_EOF
End of file.
Definition: error.h:55
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_resample.c:77
void avresample_close(AVAudioResampleContext *avr)
Close AVAudioResampleContext.
AVFilterFormats * ff_all_formats(enum AVMediaType type)
Return a list of all formats supported by FFmpeg for the given media type.
Definition: formats.c:357
static int config_output(AVFilterLink *outlink)
Definition: af_resample.c:112
frame
Definition: stft.m:14
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:130
void *(* child_next)(void *obj, void *prev)
Return next AVOptions-enabled child or NULL.
Definition: log.h:96
static av_cold int init(AVFilterContext *ctx, AVDictionary **opts)
Definition: af_resample.c:50
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:84
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
Definition: avfilter.h:545
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:162
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:394
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
AVDictionary * options
Definition: af_resample.c:42
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:1223
#define AV_LOG_VERBOSE
Definition: log.h:157
struct AVRational AVRational
rational number numerator/denominator
static const AVClass resample_class
Definition: af_resample.c:291
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:118
external API header
static void * resample_child_next(void *obj, void *prev)
Definition: af_resample.c:285
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:538
ret
Definition: avfilter.c:821
static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
Definition: af_aresample.c:46
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
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (...
Definition: formats.c:402
A list of supported channel layouts.
Definition: formats.h:85
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:134
int avresample_get_delay(AVAudioResampleContext *avr)
Return the number of samples currently in the resampling delay buffer.
NULL
Definition: eval.c:55
int avresample_available(AVAudioResampleContext *avr)
Return the number of available samples in the output FIFO.
sample_rate
void ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:432
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition: opt.c:1202
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
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:62
Describe the class of an AVClass context structure.
Definition: log.h:50
Filter definition.
Definition: avfilter.h:436
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.
const char * name
filter name
Definition: avfilter.h:437
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_resample.c:209
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 they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:539
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:396
static int request_frame(AVFilterLink *outlink)
Definition: af_resample.c:170
AVAudioResampleContext * avresample_alloc_context(void)
Allocate AVAudioResampleContext and set options.
static int query_formats(AVFilterContext *ctx)
Definition: af_resample.c:88
common internal and external API header
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:108
#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 poi...
Definition: opt.h:547
char * key
Definition: dict.h:81
char * value
Definition: dict.h:82
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:524
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:68
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
static const AVClass * resample_child_class_next(const AVClass *prev)
Definition: af_resample.c:280
static const AVFilterPad avfilter_af_resample_inputs[]
Definition: af_resample.c:299
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:319
internal API functions
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:117
int avresample_open(AVAudioResampleContext *avr)
Initialize AVAudioResampleContext.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:127
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:190
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.