FFmpeg
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 
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 
79 {
80  ResampleContext *s = ctx->priv;
81 
82  if (s->avr) {
83  avresample_close(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  AVFilterFormats *in_formats, *out_formats, *in_samplerates, *out_samplerates;
94  AVFilterChannelLayouts *in_layouts, *out_layouts;
95  int ret;
96 
97  if (!(in_formats = ff_all_formats (AVMEDIA_TYPE_AUDIO)) ||
98  !(out_formats = ff_all_formats (AVMEDIA_TYPE_AUDIO)) ||
99  !(in_samplerates = ff_all_samplerates ( )) ||
100  !(out_samplerates = ff_all_samplerates ( )) ||
101  !(in_layouts = ff_all_channel_layouts ( )) ||
102  !(out_layouts = ff_all_channel_layouts ( )))
103  return AVERROR(ENOMEM);
104 
105  if ((ret = ff_formats_ref (in_formats, &inlink->outcfg.formats )) < 0 ||
106  (ret = ff_formats_ref (out_formats, &outlink->incfg.formats )) < 0 ||
107  (ret = ff_formats_ref (in_samplerates, &inlink->outcfg.samplerates )) < 0 ||
108  (ret = ff_formats_ref (out_samplerates, &outlink->incfg.samplerates )) < 0 ||
109  (ret = ff_channel_layouts_ref (in_layouts, &inlink->outcfg.channel_layouts)) < 0 ||
110  (ret = ff_channel_layouts_ref (out_layouts, &outlink->incfg.channel_layouts)) < 0)
111  return ret;
112 
113  return 0;
114 }
115 
116 static int config_output(AVFilterLink *outlink)
117 {
118  AVFilterContext *ctx = outlink->src;
119  AVFilterLink *inlink = ctx->inputs[0];
120  ResampleContext *s = ctx->priv;
121  char buf1[64], buf2[64];
122  int ret;
123 
124  int64_t resampling_forced;
125 
126  if (s->avr) {
127  avresample_close(s->avr);
128  avresample_free(&s->avr);
129  }
130 
131  if (inlink->channel_layout == outlink->channel_layout &&
132  inlink->sample_rate == outlink->sample_rate &&
133  (inlink->format == outlink->format ||
134  (av_get_channel_layout_nb_channels(inlink->channel_layout) == 1 &&
136  av_get_planar_sample_fmt(inlink->format) ==
137  av_get_planar_sample_fmt(outlink->format))))
138  return 0;
139 
140  if (!(s->avr = avresample_alloc_context()))
141  return AVERROR(ENOMEM);
142 
143  if (s->options) {
144  int ret;
145  AVDictionaryEntry *e = NULL;
146  while ((e = av_dict_get(s->options, "", e, AV_DICT_IGNORE_SUFFIX)))
147  av_log(ctx, AV_LOG_VERBOSE, "lavr option: %s=%s\n", e->key, e->value);
148 
149  ret = av_opt_set_dict(s->avr, &s->options);
150  if (ret < 0)
151  return ret;
152  }
153 
154  av_opt_set_int(s->avr, "in_channel_layout", inlink ->channel_layout, 0);
155  av_opt_set_int(s->avr, "out_channel_layout", outlink->channel_layout, 0);
156  av_opt_set_int(s->avr, "in_sample_fmt", inlink ->format, 0);
157  av_opt_set_int(s->avr, "out_sample_fmt", outlink->format, 0);
158  av_opt_set_int(s->avr, "in_sample_rate", inlink ->sample_rate, 0);
159  av_opt_set_int(s->avr, "out_sample_rate", outlink->sample_rate, 0);
160 
161  if ((ret = avresample_open(s->avr)) < 0)
162  return ret;
163 
164  av_opt_get_int(s->avr, "force_resampling", 0, &resampling_forced);
165  s->resampling = resampling_forced || (inlink->sample_rate != outlink->sample_rate);
166 
167  if (s->resampling) {
168  outlink->time_base = (AVRational){ 1, outlink->sample_rate };
169  s->next_pts = AV_NOPTS_VALUE;
170  s->next_in_pts = AV_NOPTS_VALUE;
171  } else
172  outlink->time_base = inlink->time_base;
173 
174  av_get_channel_layout_string(buf1, sizeof(buf1),
175  -1, inlink ->channel_layout);
176  av_get_channel_layout_string(buf2, sizeof(buf2),
177  -1, outlink->channel_layout);
179  "fmt:%s srate:%d cl:%s -> fmt:%s srate:%d cl:%s\n",
181  av_get_sample_fmt_name(outlink->format), outlink->sample_rate, buf2);
182 
183  return 0;
184 }
185 
186 static int request_frame(AVFilterLink *outlink)
187 {
188  AVFilterContext *ctx = outlink->src;
189  ResampleContext *s = ctx->priv;
190  int ret = 0;
191 
192  s->got_output = 0;
193  while (ret >= 0 && !s->got_output)
194  ret = ff_request_frame(ctx->inputs[0]);
195 
196  /* flush the lavr delay buffer */
197  if (ret == AVERROR_EOF && s->avr) {
198  AVFrame *frame;
199  int nb_samples = avresample_get_out_samples(s->avr, 0);
200 
201  if (!nb_samples)
202  return ret;
203 
204  frame = ff_get_audio_buffer(outlink, nb_samples);
205  if (!frame)
206  return AVERROR(ENOMEM);
207 
208  ret = avresample_convert(s->avr, frame->extended_data,
209  frame->linesize[0], nb_samples,
210  NULL, 0, 0);
211  if (ret <= 0) {
213  return (ret == 0) ? AVERROR_EOF : ret;
214  }
215 
216  frame->nb_samples = ret;
217  frame->pts = s->next_pts;
218  return ff_filter_frame(outlink, frame);
219  }
220  return ret;
221 }
222 
224 {
225  AVFilterContext *ctx = inlink->dst;
226  ResampleContext *s = ctx->priv;
227  AVFilterLink *outlink = ctx->outputs[0];
228  int ret;
229 
230  if (s->avr) {
231  AVFrame *out;
232  int delay, nb_samples;
233 
234  /* maximum possible samples lavr can output */
235  delay = avresample_get_delay(s->avr);
236  nb_samples = avresample_get_out_samples(s->avr, in->nb_samples);
237 
238  out = ff_get_audio_buffer(outlink, nb_samples);
239  if (!out) {
240  ret = AVERROR(ENOMEM);
241  goto fail;
242  }
243 
244  ret = avresample_convert(s->avr, out->extended_data, out->linesize[0],
245  nb_samples, in->extended_data, in->linesize[0],
246  in->nb_samples);
247  if (ret <= 0) {
248  av_frame_free(&out);
249  if (ret < 0)
250  goto fail;
251  }
252 
254 
255  if (s->resampling && s->next_pts == AV_NOPTS_VALUE) {
256  if (in->pts == AV_NOPTS_VALUE) {
257  av_log(ctx, AV_LOG_WARNING, "First timestamp is missing, "
258  "assuming 0.\n");
259  s->next_pts = 0;
260  } else
261  s->next_pts = av_rescale_q(in->pts, inlink->time_base,
262  outlink->time_base);
263  }
264 
265  if (ret > 0) {
266  out->nb_samples = ret;
267 
269  if (ret < 0) {
270  av_frame_free(&out);
271  goto fail;
272  }
273 
274  if (s->resampling) {
275  out->sample_rate = outlink->sample_rate;
276  /* Only convert in->pts if there is a discontinuous jump.
277  This ensures that out->pts tracks the number of samples actually
278  output by the resampler in the absence of such a jump.
279  Otherwise, the rounding in av_rescale_q() and av_rescale()
280  causes off-by-1 errors. */
281  if (in->pts != AV_NOPTS_VALUE && in->pts != s->next_in_pts) {
282  out->pts = av_rescale_q(in->pts, inlink->time_base,
283  outlink->time_base) -
284  av_rescale(delay, outlink->sample_rate,
285  inlink->sample_rate);
286  } else
287  out->pts = s->next_pts;
288 
289  s->next_pts = out->pts + out->nb_samples;
290  s->next_in_pts = in->pts + in->nb_samples;
291  } else
292  out->pts = in->pts;
293 
294  ret = ff_filter_frame(outlink, out);
295  s->got_output = 1;
296  }
297 
298 fail:
299  av_frame_free(&in);
300  } else {
301  in->format = outlink->format;
302  ret = ff_filter_frame(outlink, in);
303  s->got_output = 1;
304  }
305 
306  return ret;
307 }
308 
309 #if FF_API_CHILD_CLASS_NEXT
310 static const AVClass *resample_child_class_next(const AVClass *prev)
311 {
312  return prev ? NULL : avresample_get_class();
313 }
314 #endif
315 
316 static const AVClass *resample_child_class_iterate(void **iter)
317 {
318  const AVClass *c = *iter ? NULL : avresample_get_class();
319  *iter = (void*)(uintptr_t)c;
320  return c;
321 }
322 
323 static void *resample_child_next(void *obj, void *prev)
324 {
325  ResampleContext *s = obj;
326  return prev ? NULL : s->avr;
327 }
328 
329 static const AVClass resample_class = {
330  .class_name = "resample",
331  .item_name = av_default_item_name,
332  .version = LIBAVUTIL_VERSION_INT,
333 #if FF_API_CHILD_CLASS_NEXT
334  .child_class_next = resample_child_class_next,
335 #endif
336  .child_class_iterate = resample_child_class_iterate,
338 };
339 
341  {
342  .name = "default",
343  .type = AVMEDIA_TYPE_AUDIO,
344  .filter_frame = filter_frame,
345  },
346  { NULL }
347 };
348 
350  {
351  .name = "default",
352  .type = AVMEDIA_TYPE_AUDIO,
353  .config_props = config_output,
354  .request_frame = request_frame
355  },
356  { NULL }
357 };
358 
360  .name = "resample",
361  .description = NULL_IF_CONFIG_SMALL("Audio resampling and conversion."),
362  .priv_size = sizeof(ResampleContext),
363  .priv_class = &resample_class,
364  .init_dict = init,
365  .uninit = uninit,
369 };
ff_get_audio_buffer
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:86
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:86
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
avresample_alloc_context
attribute_deprecated AVAudioResampleContext * avresample_alloc_context(void)
Definition: options.c:96
AVFilterFormatsConfig::samplerates
AVFilterFormats * samplerates
Lists of supported sample rates, only for audio.
Definition: avfilter.h:450
resample_class
static const AVClass resample_class
Definition: af_resample.c:329
init
static av_cold int init(AVFilterContext *ctx, AVDictionary **opts)
Definition: af_resample.c:51
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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. Frame references ownership and permissions
opt.h
AVFilterFormatsConfig::channel_layouts
AVFilterChannelLayouts * channel_layouts
Lists of supported channel layouts, only for audio.
Definition: avfilter.h:455
out
FILE * out
Definition: movenc.c:54
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1094
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:461
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:204
ResampleContext::resampling
int resampling
Definition: af_resample.c:43
av_get_channel_layout_string
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.
Definition: channel_layout.c:217
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:324
ff_request_frame
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:408
AV_DICT_IGNORE_SUFFIX
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
Definition: dict.h:70
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:210
avresample.h
mathematics.h
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_resample.c:89
AVDictionary
Definition: dict.c:30
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:149
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_resample.c:116
sample_rate
sample_rate
Definition: ffmpeg_filter.c:158
avresample_get_delay
attribute_deprecated int avresample_get_delay(AVAudioResampleContext *avr)
Definition: resample.c:438
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:65
formats.h
AVAudioResampleContext
Definition: internal.h:53
fail
#define fail()
Definition: checkasm.h:134
resample_child_next
static void * resample_child_next(void *obj, void *prev)
Definition: af_resample.c:323
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_resample.c:223
ff_all_formats
AVFilterFormats * ff_all_formats(enum AVMediaType type)
Return a list of all formats supported by FFmpeg for the given media type.
Definition: formats.c:345
avresample_get_out_samples
attribute_deprecated int avresample_get_out_samples(AVAudioResampleContext *avr, int in_nb_samples)
Definition: utils.c:753
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: af_resample.c:186
av_get_planar_sample_fmt
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
Definition: samplefmt.c:84
avassert.h
av_cold
#define av_cold
Definition: attributes.h:90
inputs
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
Definition: filter_design.txt:243
av_dict_get
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:40
av_opt_set_dict
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition: opt.c:1656
avresample_open
attribute_deprecated int avresample_open(AVAudioResampleContext *avr)
Definition: utils.c:36
s
#define s(width, name)
Definition: cbs_vp9.c:257
ResampleContext
Definition: af_resample.c:38
AVDictionaryEntry::key
char * key
Definition: dict.h:82
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:466
avresample_get_class
const attribute_deprecated AVClass * avresample_get_class(void)
Definition: options.c:110
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
ctx
AVFormatContext * ctx
Definition: movenc.c:48
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
ResampleContext::next_in_pts
int64_t next_in_pts
Definition: af_resample.c:45
av_get_sample_fmt_name
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:49
av_opt_find
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:1661
opts
AVDictionary * opts
Definition: movenc.c:50
ResampleContext::next_pts
int64_t next_pts
Definition: af_resample.c:44
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:659
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
init_dict
static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts)
Definition: af_aresample.c:46
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
av_opt_get_int
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
Definition: opt.c:912
ResampleContext::got_output
int got_output
Definition: af_resample.c:48
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
av_get_channel_layout_nb_channels
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
Definition: channel_layout.c:226
av_opt_set_int
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:586
AV_OPT_SEARCH_FAKE_OBJ
#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:568
avresample_free
attribute_deprecated void avresample_free(AVAudioResampleContext **avr)
Definition: utils.c:278
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AVClass::child_next
void *(* child_next)(void *obj, void *prev)
Return next AVOptions-enabled child or NULL.
Definition: log.h:113
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
avresample_convert
attribute_deprecated int avresample_convert(AVAudioResampleContext *avr, uint8_t **output, int out_plane_size, int out_samples, uint8_t *const *input, int in_plane_size, int in_samples)
Definition: utils.c:330
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:560
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:203
ff_all_channel_layouts
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition: formats.c:427
internal.h
avresample_close
attribute_deprecated void avresample_close(AVAudioResampleContext *avr)
Definition: utils.c:262
in
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=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;} 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_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);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_log(ac->avr, AV_LOG_TRACE, "%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-> in
Definition: audio_convert.c:326
avresample_available
attribute_deprecated int avresample_available(AVAudioResampleContext *avr)
Definition: utils.c:748
common.h
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
av_rescale
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:129
AVFilter
Filter definition.
Definition: avfilter.h:145
ret
ret
Definition: filter_design.txt:187
AVClass::class_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:72
frame
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 the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
avfilter_af_resample_inputs
static const AVFilterPad avfilter_af_resample_inputs[]
Definition: af_resample.c:340
dict.h
ResampleContext::avr
AVAudioResampleContext * avr
Definition: af_resample.c:40
avfilter_af_resample_outputs
static const AVFilterPad avfilter_af_resample_outputs[]
Definition: af_resample.c:349
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:421
avfilter.h
AVFilterContext
An instance of a filter.
Definition: avfilter.h:341
audio.h
AVFilterFormatsConfig::formats
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition: avfilter.h:445
ResampleContext::options
AVDictionary * options
Definition: af_resample.c:41
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_resample.c:78
AVDictionaryEntry
Definition: dict.h:81
resample_child_class_iterate
static const AVClass * resample_child_class_iterate(void **iter)
Definition: af_resample.c:316
av_dict_set
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:70
format
fg outputs[0] format
Definition: ffmpeg_filter.c:177
ff_af_resample
AVFilter ff_af_resample
Definition: af_resample.c:359
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVDictionaryEntry::value
char * value
Definition: dict.h:83
avstring.h