FFmpeg: libavfilter/aeval.c Source File
Go to the documentation of this file. 1 /*
2 * Copyright (c) 2011 Stefano Sabatini
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * eval audio source
24 */
25
26 #include "config_components.h"
27
37
39 "ch", ///< the value of the current channel
40 "n", ///< number of frame
41 "nb_in_channels",
42 "nb_out_channels",
43 "t", ///< timestamp expressed in seconds
44 "s", ///< sample rate
46 };
47
56 };
57
70 int nb_samples;
///< number of samples per requested frame
76
77 static double val(
void *priv,
double ch)
78 {
81 }
82
85
86 #define OFFSET(x) offsetof(EvalContext, x)
87 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
88
91 {
"nb_samples",
"set the number of samples per requested frame",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64 = 1024}, 0, INT_MAX,
FLAGS },
92 {
"n",
"set the number of samples per requested frame",
OFFSET(nb_samples),
AV_OPT_TYPE_INT, {.i64 = 1024}, 0, INT_MAX,
FLAGS },
100 };
101
103
105 int expected_nb_channels)
106 {
109 char *expr, *last_expr =
NULL, *buf;
113
114 if (!args1)
116
120 goto end;
121 }
122
123 if (!strcmp(
ctx->filter->name,
"aeval")) {
126 }
127
128 #define ADD_EXPRESSION(expr_) do { \
129 ret = av_dynarray_add_nofree(&eval->expr, \
130 &eval->nb_channels, NULL); \
131 if (ret < 0) \
132 goto end; \
133 eval->expr[eval->nb_channels-1] = NULL; \
134 ret = av_expr_parse(&eval->expr[eval->nb_channels - 1], expr_, \
135 var_names, func1_names, func1, \
136 NULL, NULL, 0, ctx); \
137 if (ret < 0) \
138 goto end; \
139 } while (0)
140
141 /* reset expressions */
145 }
148
149 buf = args1;
150 while (expr =
av_strtok(buf,
"|", &buf)) {
152 last_expr = expr;
153 }
154
158
159 if (expected_nb_channels > 0 && eval->
nb_channels != expected_nb_channels) {
161 "Mismatch between the specified number of channel expressions '%d' "
162 "and the number of expected output channels '%d' for the specified channel layout\n",
165 goto end;
166 }
167
168 end:
171 }
172
174 {
177
179 if (!strcmp(eval->
chlayout_str,
"same") && !strcmp(
ctx->filter->name,
"aeval")) {
181 } else {
185
189 }
190 } else {
191 /* guess channel layout from nb expressions/channels */
194
200 }
201 }
202
207
209 }
210
212 {
215
219 }
223 }
224
226 {
228 char buf[128];
229
232
236
238
240 "sample_rate:%d chlayout:%s duration:%"PRId64"\n",
242
243 return 0;
244 }
245
249 {
255
259
263
265 }
266
268 {
274 int nb_samples;
275
278
281 return 0;
282 }
283
286 if (!nb_samples) {
288 return 0;
289 }
290 } else {
292 }
294 if (!samplesref)
296
297 /* evaluate expression for each single sample and for each channel */
298 for (
i = 0;
i < nb_samples;
i++, eval->
n++) {
301
305 }
306 }
307
308 samplesref->
pts = eval->
pts;
310 eval->
pts += nb_samples;
311
313 }
314
315 #if CONFIG_AEVALSRC_FILTER
317 {
321 },
322 };
323
325 .
p.
name =
"aevalsrc",
327 .p.priv_class = &aevalsrc_class,
334 };
335
336 #endif /* CONFIG_AEVALSRC_FILTER */
337
338 #define OFFSET(x) offsetof(EvalContext, x)
339 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
340
346 };
347
349
353 {
358 };
360
361 // inlink supports any channel layout
365
367 // outlink supports only requested output channel layout
373 }
374
377
378 return 0;
379 }
380
382 {
387
391
394 }
395
401
406
407 return 0;
408 }
409
411 {
416 double t0;
418
423 }
425
427
428 /* evaluate expression for each single sample and for each channel */
429 for (
i = 0;
i < nb_samples;
i++, eval->
n++) {
432
433 for (j = 0; j <
inlink->ch_layout.nb_channels; j++)
435
438 *((
double *)
out->extended_data[j] +
i) =
440 }
441 }
442
445 }
446
447 #if CONFIG_AEVAL_FILTER
448
450 {
454 },
455 };
456
458 {
462 },
463 };
464
467 .p.description =
NULL_IF_CONFIG_SMALL(
"Filter audio signal according to a specified expression."),
468 .p.priv_class = &aeval_class,
476 };
477
478 #endif /* CONFIG_AEVAL_FILTER */
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.
static enum AVSampleFormat sample_fmts[]
enum MovChannelLayoutTag * layouts
#define AVERROR_EOF
End of file.
static int aeval_query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
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.
static av_cold int init(AVFilterContext *ctx)
#define FILTER_INPUTS(array)
static const int sample_rates[]
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).
#define ADD_EXPRESSION(expr_)
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
static const char *const aeval_func1_names[]
#define AV_LOG_VERBOSE
Detailed information.
const char * name
Filter name.
static int config_props(AVFilterLink *outlink)
int nb_channels
Number of channels in this layout.
A link between two filters.
static av_cold void uninit(AVFilterContext *ctx)
void * priv
private data for use by the filter
int same_chlayout
set output as input channel layout
static double val(void *priv, double ch)
static const char *const func1_names[]
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
A filter pad used for either input or output.
double var_values[VAR_VARS_NB]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
const FFFilter ff_af_aeval
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
#define FILTER_OUTPUTS(array)
int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg, void *log_ctx)
Parse a channel layout or a corresponding integer representation.
#define av_realloc_f(p, o, n)
static const AVOption aevalsrc_options[]
int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
Parse a sample rate.
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.
static int aeval_config_output(AVFilterLink *outlink)
Rational number (pair of numerator and denominator).
int nb_in_channels
number of input channels
static const AVOption aeval_options[]
#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.
int sample_rate
Sample rate of the audio data.
int nb_channels
number of output channels
AVFilterContext * src
source filter
static double(*const aeval_func1[])(void *, double)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
int sample_rate
samples per second
int nb_samples
number of audio samples (per channel) described by this frame
static double(*const func1[])(void *, double)
#define i(width, name, range_min, range_max)
#define AV_TIME_BASE
Internal time base represented as integer.
uint8_t ** extended_data
pointers to the data planes/channels.
AVSampleFormat
Audio sample formats.
#define FILTER_QUERY_FUNC2(func)
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.
AVFILTER_DEFINE_CLASS(aevalsrc)
static const char *const var_names[]
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
@ 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.
@ AV_SAMPLE_FMT_DBLP
double, planar
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
static int activate(AVFilterContext *ctx)
const FFFilter ff_asrc_aevalsrc
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
char * av_strdup(const char *s)
Duplicate a string.
AVFilter p
The public AVFilter.
static int parse_channel_expressions(AVFilterContext *ctx, int expected_nb_channels)
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
static const uint16_t channel_layouts[7]
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
int nb_samples
number of samples per requested frame
Generated on Thu Oct 16 2025 19:22:57 for FFmpeg by
doxygen
1.8.17