FFmpeg: libavfilter/af_aresample.c Source File
Go to the documentation of this file. 1 /*
2 * Copyright (c) 2011 Stefano Sabatini
3 * Copyright (c) 2011 Mina Nagy Zaki
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * resampling audio filter
25 */
26
37
47
49 {
51
56
57 return 0;
58 }
59
61 {
64 }
65
69 {
74
79
84
88
92
96
97 if(out_rate > 0) {
98 int ratelist[] = { out_rate, -1 };
100 } else {
102 }
103
106
108 int formatlist[] = { out_format, -1 };
110 } else
114
119 } else
122
124 }
125
126
128 {
136 char inchl_buf[128], outchl_buf[128];
137
144
148
153
157
159
161
164
168 return 0;
169 }
170
172 {
177 int n_out = n_in * aresample->
ratio + 32;
181
183 if (delay > 0)
185
187
188 if(!outsamplesref) {
191 }
192
200 }
202
208 } else {
210 }
213 if (n_out <= 0) {
217 return 0;
218 }
219
220 aresample->
more_data = outsamplesref->
nb_samples == n_out;
// Indicate that there is probably more data in our buffers
221
223
227 }
228
230 {
235 int n_out = 4096;
237
239 *outsamplesref_ret = outsamplesref;
240 if (!outsamplesref)
242
245
247 if (n_out <= 0) {
250 }
251
254
256
257 return 0;
258 }
259
261 {
267
268 // First try to get data from the internal buffers
271
272 if (
flush_frame(outlink, 0, &outsamplesref) >= 0) {
274 }
275 }
277
280
281 // Second request more data from the input
284
285 // Third if we hit the end flush
286 if (aresample->
eof) {
288
292 return 0;
293 }
295 }
296
298 }
299
301 return 0;
302 }
303
305 {
309
311
315
321 }
322
324 }
325
327 {
329 *iter = (
void*)(uintptr_t)
c;
331 }
332
334 {
336 return prev ?
NULL :
s->swr;
337 }
338
339 #define OFFSET(x) offsetof(AResampleContext, x)
340 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
341
345 };
346
354 };
355
357 {
361 },
362 };
363
375 };
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
A list of supported channel layouts.
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
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define AVERROR_EOF
End of file.
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static int config_output(AVFilterLink *outlink)
#define AV_LOG_VERBOSE
Detailed information.
static av_cold int preinit(AVFilterContext *ctx)
const char * name
Filter name.
int nb_channels
Number of channels in this layout.
A link between two filters.
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
static int activate(AVFilterContext *ctx)
AVChannelLayout ch_layout
Channel layout of the audio data.
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...
A filter pad used for either input or output.
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.
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.
static const AVOption options[]
static void * resample_child_next(void *obj, void *prev)
av_cold int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.
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.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
av_cold struct SwrContext * swr_alloc(void)
Allocate SwrContext.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static const AVClass * resample_child_class_iterate(void **iter)
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.
The libswresample context.
#define FILTER_OUTPUTS(array)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
const AVClass * swr_get_class(void)
Get the AVClass for SwrContext.
Rational number (pair of numerator and denominator).
AVFilterLink ** inputs
array of pointers to input links
#define ROUNDED_DIV(a, b)
const char * av_default_item_name(void *ptr)
Return the context name.
int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
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
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
size_t ff_inlink_queued_frames(AVFilterLink *link)
Get the number of frames available on the link.
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static av_cold void uninit(AVFilterContext *ctx)
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.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
An AVChannelLayout holds information about the channel layout of audio data.
void *(* child_next)(void *obj, void *prev)
Return next AVOptions-enabled child or NULL.
int sample_rate
Sample rate of the audio data.
int format
agreed upon media format
#define AV_NOPTS_VALUE
Undefined timestamp value.
static const AVFilterPad aresample_outputs[]
av_cold void swr_free(SwrContext **ss)
Free the given SwrContext and set the pointer to NULL.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
AVFilterContext * src
source filter
FF_FILTER_FORWARD_WANTED(outlink, inlink)
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
static int flush_frame(AVFilterLink *outlink, int final, AVFrame **outsamplesref_ret)
static const AVClass aresample_class
int sample_rate
samples per second
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t ** extended_data
pointers to the data planes/channels.
AVSampleFormat
Audio sample formats.
#define FILTER_QUERY_FUNC2(func)
static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref)
const char * name
Pad name.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
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
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
@ AV_OPT_TYPE_INT
Underlying C type is int.
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_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
static const uint16_t channel_layouts[7]
const AVFilter ff_af_aresample
static int request_frame(AVFilterLink *outlink)
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Generated on Fri Aug 22 2025 13:59:05 for FFmpeg by
doxygen
1.8.17