FFmpeg
af_volume.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Stefano Sabatini
3  * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
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  * audio volume filter
25  */
26 
28 #include "libavutil/common.h"
29 #include "libavutil/eval.h"
30 #include "libavutil/ffmath.h"
31 #include "libavutil/float_dsp.h"
32 #include "libavutil/mem.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/replaygain.h"
35 
36 #include "audio.h"
37 #include "avfilter.h"
38 #include "formats.h"
39 #include "internal.h"
40 #include "af_volume.h"
41 
42 static const char * const precision_str[] = {
43  "fixed", "float", "double"
44 };
45 
46 static const char *const var_names[] = {
47  "n", ///< frame number (starting at zero)
48  "nb_channels", ///< number of channels
49  "nb_consumed_samples", ///< number of samples consumed by the filter
50  "nb_samples", ///< number of samples in the current frame
51 #if FF_API_FRAME_PKT
52  "pos", ///< position in the file of the frame
53 #endif
54  "pts", ///< frame presentation timestamp
55  "sample_rate", ///< sample rate
56  "startpts", ///< PTS at start of stream
57  "startt", ///< time at start of stream
58  "t", ///< time in the file of the frame
59  "tb", ///< timebase
60  "volume", ///< last set value
61  NULL
62 };
63 
64 #define OFFSET(x) offsetof(VolumeContext, x)
65 #define A AV_OPT_FLAG_AUDIO_PARAM
66 #define F AV_OPT_FLAG_FILTERING_PARAM
67 #define T AV_OPT_FLAG_RUNTIME_PARAM
68 
69 static const AVOption volume_options[] = {
70  { "volume", "set volume adjustment expression",
71  OFFSET(volume_expr), AV_OPT_TYPE_STRING, { .str = "1.0" }, .flags = A|F|T },
72  { "precision", "select mathematical precision",
73  OFFSET(precision), AV_OPT_TYPE_INT, { .i64 = PRECISION_FLOAT }, PRECISION_FIXED, PRECISION_DOUBLE, A|F, .unit = "precision" },
74  { "fixed", "select 8-bit fixed-point", 0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_FIXED }, INT_MIN, INT_MAX, A|F, .unit = "precision" },
75  { "float", "select 32-bit floating-point", 0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_FLOAT }, INT_MIN, INT_MAX, A|F, .unit = "precision" },
76  { "double", "select 64-bit floating-point", 0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_DOUBLE }, INT_MIN, INT_MAX, A|F, .unit = "precision" },
77  { "eval", "specify when to evaluate expressions", OFFSET(eval_mode), AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_ONCE}, 0, EVAL_MODE_NB-1, .flags = A|F, .unit = "eval" },
78  { "once", "eval volume expression once", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_ONCE}, .flags = A|F, .unit = "eval" },
79  { "frame", "eval volume expression per-frame", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags = A|F, .unit = "eval" },
80  { "replaygain", "Apply replaygain side data when present",
81  OFFSET(replaygain), AV_OPT_TYPE_INT, { .i64 = REPLAYGAIN_DROP }, REPLAYGAIN_DROP, REPLAYGAIN_ALBUM, A|F, .unit = "replaygain" },
82  { "drop", "replaygain side data is dropped", 0, AV_OPT_TYPE_CONST, { .i64 = REPLAYGAIN_DROP }, 0, 0, A|F, .unit = "replaygain" },
83  { "ignore", "replaygain side data is ignored", 0, AV_OPT_TYPE_CONST, { .i64 = REPLAYGAIN_IGNORE }, 0, 0, A|F, .unit = "replaygain" },
84  { "track", "track gain is preferred", 0, AV_OPT_TYPE_CONST, { .i64 = REPLAYGAIN_TRACK }, 0, 0, A|F, .unit = "replaygain" },
85  { "album", "album gain is preferred", 0, AV_OPT_TYPE_CONST, { .i64 = REPLAYGAIN_ALBUM }, 0, 0, A|F, .unit = "replaygain" },
86  { "replaygain_preamp", "Apply replaygain pre-amplification",
87  OFFSET(replaygain_preamp), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, -15.0, 15.0, A|F },
88  { "replaygain_noclip", "Apply replaygain clipping prevention",
89  OFFSET(replaygain_noclip), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, A|F },
90  { NULL }
91 };
92 
93 AVFILTER_DEFINE_CLASS(volume);
94 
95 static int set_expr(AVExpr **pexpr, const char *expr, void *log_ctx)
96 {
97  int ret;
98  AVExpr *old = NULL;
99 
100  if (*pexpr)
101  old = *pexpr;
102  ret = av_expr_parse(pexpr, expr, var_names,
103  NULL, NULL, NULL, NULL, 0, log_ctx);
104  if (ret < 0) {
105  av_log(log_ctx, AV_LOG_ERROR,
106  "Error when evaluating the volume expression '%s'\n", expr);
107  *pexpr = old;
108  return ret;
109  }
110 
111  av_expr_free(old);
112  return 0;
113 }
114 
116 {
117  VolumeContext *vol = ctx->priv;
118 
119  vol->fdsp = avpriv_float_dsp_alloc(0);
120  if (!vol->fdsp)
121  return AVERROR(ENOMEM);
122 
123  return set_expr(&vol->volume_pexpr, vol->volume_expr, ctx);
124 }
125 
127 {
128  VolumeContext *vol = ctx->priv;
130  av_freep(&vol->fdsp);
131 }
132 
134 {
135  VolumeContext *vol = ctx->priv;
136  static const enum AVSampleFormat sample_fmts[][7] = {
137  [PRECISION_FIXED] = {
145  },
146  [PRECISION_FLOAT] = {
150  },
151  [PRECISION_DOUBLE] = {
155  }
156  };
158  if (ret < 0)
159  return ret;
160 
162  if (ret < 0)
163  return ret;
164 
166 }
167 
168 static inline void scale_samples_u8(uint8_t *dst, const uint8_t *src,
169  int nb_samples, int volume)
170 {
171  int i;
172  for (i = 0; i < nb_samples; i++)
173  dst[i] = av_clip_uint8(((((int64_t)src[i] - 128) * volume + 128) >> 8) + 128);
174 }
175 
176 static inline void scale_samples_u8_small(uint8_t *dst, const uint8_t *src,
177  int nb_samples, int volume)
178 {
179  int i;
180  for (i = 0; i < nb_samples; i++)
181  dst[i] = av_clip_uint8((((src[i] - 128) * volume + 128) >> 8) + 128);
182 }
183 
184 static inline void scale_samples_s16(uint8_t *dst, const uint8_t *src,
185  int nb_samples, int volume)
186 {
187  int i;
188  int16_t *smp_dst = (int16_t *)dst;
189  const int16_t *smp_src = (const int16_t *)src;
190  for (i = 0; i < nb_samples; i++)
191  smp_dst[i] = av_clip_int16(((int64_t)smp_src[i] * volume + 128) >> 8);
192 }
193 
194 static inline void scale_samples_s16_small(uint8_t *dst, const uint8_t *src,
195  int nb_samples, int volume)
196 {
197  int i;
198  int16_t *smp_dst = (int16_t *)dst;
199  const int16_t *smp_src = (const int16_t *)src;
200  for (i = 0; i < nb_samples; i++)
201  smp_dst[i] = av_clip_int16((smp_src[i] * volume + 128) >> 8);
202 }
203 
204 static inline void scale_samples_s32(uint8_t *dst, const uint8_t *src,
205  int nb_samples, int volume)
206 {
207  int i;
208  int32_t *smp_dst = (int32_t *)dst;
209  const int32_t *smp_src = (const int32_t *)src;
210  for (i = 0; i < nb_samples; i++)
211  smp_dst[i] = av_clipl_int32((((int64_t)smp_src[i] * volume + 128) >> 8));
212 }
213 
215 {
216  vol->samples_align = 1;
217 
218  switch (av_get_packed_sample_fmt(vol->sample_fmt)) {
219  case AV_SAMPLE_FMT_U8:
220  if (vol->volume_i < 0x1000000)
222  else
224  break;
225  case AV_SAMPLE_FMT_S16:
226  if (vol->volume_i < 0x10000)
228  else
230  break;
231  case AV_SAMPLE_FMT_S32:
233  break;
234  case AV_SAMPLE_FMT_FLT:
235  vol->samples_align = 4;
236  break;
237  case AV_SAMPLE_FMT_DBL:
238  vol->samples_align = 8;
239  break;
240  }
241 
242 #if ARCH_X86
243  ff_volume_init_x86(vol);
244 #endif
245 }
246 
248 {
249  VolumeContext *vol = ctx->priv;
250 
251  vol->volume = av_expr_eval(vol->volume_pexpr, vol->var_values, NULL);
252  if (isnan(vol->volume)) {
253  if (vol->eval_mode == EVAL_MODE_ONCE) {
254  av_log(ctx, AV_LOG_ERROR, "Invalid value NaN for volume\n");
255  return AVERROR(EINVAL);
256  } else {
257  av_log(ctx, AV_LOG_WARNING, "Invalid value NaN for volume, setting to 0\n");
258  vol->volume = 0;
259  }
260  }
261  vol->var_values[VAR_VOLUME] = vol->volume;
262 
263  av_log(ctx, AV_LOG_VERBOSE, "n:%f t:%f pts:%f precision:%s ",
264  vol->var_values[VAR_N], vol->var_values[VAR_T], vol->var_values[VAR_PTS],
265  precision_str[vol->precision]);
266 
267  if (vol->precision == PRECISION_FIXED) {
268  vol->volume_i = (int)(vol->volume * 256 + 0.5);
269  vol->volume = vol->volume_i / 256.0;
270  av_log(ctx, AV_LOG_VERBOSE, "volume_i:%d/255 ", vol->volume_i);
271  }
272  av_log(ctx, AV_LOG_VERBOSE, "volume:%f volume_dB:%f\n",
273  vol->volume, 20.0*log10(vol->volume));
274 
275  volume_init(vol);
276  return 0;
277 }
278 
279 static int config_output(AVFilterLink *outlink)
280 {
281  AVFilterContext *ctx = outlink->src;
282  VolumeContext *vol = ctx->priv;
283  AVFilterLink *inlink = ctx->inputs[0];
284 
285  vol->sample_fmt = inlink->format;
286  vol->channels = inlink->ch_layout.nb_channels;
287  vol->planes = av_sample_fmt_is_planar(inlink->format) ? vol->channels : 1;
288 
289  vol->var_values[VAR_N] =
291  vol->var_values[VAR_NB_SAMPLES] =
292 #if FF_API_FRAME_PKT
293  vol->var_values[VAR_POS] =
294 #endif
295  vol->var_values[VAR_PTS] =
296  vol->var_values[VAR_STARTPTS] =
297  vol->var_values[VAR_STARTT] =
298  vol->var_values[VAR_T] =
299  vol->var_values[VAR_VOLUME] = NAN;
300 
301  vol->var_values[VAR_NB_CHANNELS] = inlink->ch_layout.nb_channels;
302  vol->var_values[VAR_TB] = av_q2d(inlink->time_base);
303  vol->var_values[VAR_SAMPLE_RATE] = inlink->sample_rate;
304 
305  av_log(inlink->src, AV_LOG_VERBOSE, "tb:%f sample_rate:%f nb_channels:%f\n",
306  vol->var_values[VAR_TB],
309 
310  return set_volume(ctx);
311 }
312 
313 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
314  char *res, int res_len, int flags)
315 {
316  VolumeContext *vol = ctx->priv;
317  int ret = AVERROR(ENOSYS);
318 
319  if (!strcmp(cmd, "volume")) {
320  if ((ret = set_expr(&vol->volume_pexpr, args, ctx)) < 0)
321  return ret;
322  if (vol->eval_mode == EVAL_MODE_ONCE)
323  set_volume(ctx);
324  }
325 
326  return ret;
327 }
328 
330 {
331  AVFilterContext *ctx = inlink->dst;
332  VolumeContext *vol = inlink->dst->priv;
333  AVFilterLink *outlink = inlink->dst->outputs[0];
334  int nb_samples = buf->nb_samples;
335  AVFrame *out_buf;
337  int ret;
338 
339  if (sd && vol->replaygain != REPLAYGAIN_IGNORE) {
340  if (vol->replaygain != REPLAYGAIN_DROP) {
341  AVReplayGain *replaygain = (AVReplayGain*)sd->data;
342  int32_t gain = 100000;
343  uint32_t peak = 100000;
344  float g, p;
345 
346  if (vol->replaygain == REPLAYGAIN_TRACK &&
347  replaygain->track_gain != INT32_MIN) {
348  gain = replaygain->track_gain;
349 
350  if (replaygain->track_peak != 0)
351  peak = replaygain->track_peak;
352  } else if (replaygain->album_gain != INT32_MIN) {
353  gain = replaygain->album_gain;
354 
355  if (replaygain->album_peak != 0)
356  peak = replaygain->album_peak;
357  } else {
358  av_log(inlink->dst, AV_LOG_WARNING, "Both ReplayGain gain "
359  "values are unknown.\n");
360  }
361  g = gain / 100000.0f;
362  p = peak / 100000.0f;
363 
365  "Using gain %f dB from replaygain side data.\n", g);
366 
367  vol->volume = ff_exp10((g + vol->replaygain_preamp) / 20);
368  if (vol->replaygain_noclip)
369  vol->volume = FFMIN(vol->volume, 1.0 / p);
370  vol->volume_i = (int)(vol->volume * 256 + 0.5);
371 
372  volume_init(vol);
373  }
375  }
376 
377  if (isnan(vol->var_values[VAR_STARTPTS])) {
378  vol->var_values[VAR_STARTPTS] = TS2D(buf->pts);
379  vol->var_values[VAR_STARTT ] = TS2T(buf->pts, inlink->time_base);
380  }
381  vol->var_values[VAR_PTS] = TS2D(buf->pts);
382  vol->var_values[VAR_T ] = TS2T(buf->pts, inlink->time_base);
383  vol->var_values[VAR_N ] = inlink->frame_count_out;
384 
385 #if FF_API_FRAME_PKT
387  {
388  int64_t pos;
389  pos = buf->pkt_pos;
390  vol->var_values[VAR_POS] = pos == -1 ? NAN : pos;
391  }
393 #endif
394  if (vol->eval_mode == EVAL_MODE_FRAME)
395  set_volume(ctx);
396 
397  if (vol->volume == 1.0 || vol->volume_i == 256) {
398  out_buf = buf;
399  goto end;
400  }
401 
402  /* do volume scaling in-place if input buffer is writable */
403  if (av_frame_is_writable(buf)
404  && (vol->precision != PRECISION_FIXED || vol->volume_i > 0)) {
405  out_buf = buf;
406  } else {
407  out_buf = ff_get_audio_buffer(outlink, nb_samples);
408  if (!out_buf) {
409  av_frame_free(&buf);
410  return AVERROR(ENOMEM);
411  }
412  ret = av_frame_copy_props(out_buf, buf);
413  if (ret < 0) {
414  av_frame_free(&out_buf);
415  av_frame_free(&buf);
416  return ret;
417  }
418  }
419 
420  if (vol->precision != PRECISION_FIXED || vol->volume_i > 0) {
421  int p, plane_samples;
422 
424  plane_samples = FFALIGN(nb_samples, vol->samples_align);
425  else
426  plane_samples = FFALIGN(nb_samples * vol->channels, vol->samples_align);
427 
428  if (vol->precision == PRECISION_FIXED) {
429  for (p = 0; p < vol->planes; p++) {
430  vol->scale_samples(out_buf->extended_data[p],
431  buf->extended_data[p], plane_samples,
432  vol->volume_i);
433  }
435  for (p = 0; p < vol->planes; p++) {
436  vol->fdsp->vector_fmul_scalar((float *)out_buf->extended_data[p],
437  (const float *)buf->extended_data[p],
438  vol->volume, plane_samples);
439  }
440  } else {
441  for (p = 0; p < vol->planes; p++) {
442  vol->fdsp->vector_dmul_scalar((double *)out_buf->extended_data[p],
443  (const double *)buf->extended_data[p],
444  vol->volume, plane_samples);
445  }
446  }
447  }
448 
449  if (buf != out_buf)
450  av_frame_free(&buf);
451 
452 end:
454  return ff_filter_frame(outlink, out_buf);
455 }
456 
458  {
459  .name = "default",
460  .type = AVMEDIA_TYPE_AUDIO,
461  .filter_frame = filter_frame,
462  },
463 };
464 
466  {
467  .name = "default",
468  .type = AVMEDIA_TYPE_AUDIO,
469  .config_props = config_output,
470  },
471 };
472 
474  .name = "volume",
475  .description = NULL_IF_CONFIG_SMALL("Change input volume."),
476  .priv_size = sizeof(VolumeContext),
477  .priv_class = &volume_class,
478  .init = init,
479  .uninit = uninit,
484  .process_command = process_command,
485 };
PRECISION_FIXED
@ PRECISION_FIXED
Definition: af_volume.h:34
OFFSET
#define OFFSET(x)
Definition: af_volume.c:64
REPLAYGAIN_ALBUM
@ REPLAYGAIN_ALBUM
Definition: af_volume.h:67
af_volume.h
init
static av_cold int init(AVFilterContext *ctx)
Definition: af_volume.c:115
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:97
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
ff_exp10
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
Definition: ffmath.h:42
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
VolumeContext::planes
int planes
Definition: af_volume.h:85
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:947
VolumeContext
Definition: af_volume.h:70
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1015
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:948
var_names
static const char *const var_names[]
Definition: af_volume.c:46
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: af_volume.c:329
VAR_NB_CONSUMED_SAMPLES
@ VAR_NB_CONSUMED_SAMPLES
Definition: af_volume.h:48
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:160
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:486
AVOption
AVOption.
Definition: opt.h:357
AVReplayGain::album_gain
int32_t album_gain
Same as track_gain, but for the whole album.
Definition: replaygain.h:43
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:159
AV_SAMPLE_FMT_S32P
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:65
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
ff_set_common_all_samplerates
int ff_set_common_all_samplerates(AVFilterContext *ctx)
Equivalent to ff_set_common_samplerates(ctx, ff_all_samplerates())
Definition: formats.c:822
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
replaygain.h
REPLAYGAIN_DROP
@ REPLAYGAIN_DROP
Definition: af_volume.h:64
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_volume.c:126
formats.h
av_expr_parse
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition: eval.c:710
VAR_T
@ VAR_T
Definition: aeval.c:54
volume_init
static av_cold void volume_init(VolumeContext *vol)
Definition: af_volume.c:214
scale_samples_s32
static void scale_samples_s32(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
Definition: af_volume.c:204
scale_samples_s16
static void scale_samples_s16(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
Definition: af_volume.c:184
VolumeContext::volume_pexpr
AVExpr * volume_pexpr
Definition: af_volume.h:76
VolumeContext::replaygain_noclip
int replaygain_noclip
Definition: af_volume.h:81
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_volume.c:279
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(volume)
VAR_TB
@ VAR_TB
Definition: noise.c:49
VolumeContext::eval_mode
int eval_mode
Definition: af_volume.h:74
VolumeContext::channels
int channels
Definition: af_volume.h:84
av_expr_free
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:358
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:33
TS2T
#define TS2T(ts, tb)
Definition: internal.h:259
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_volume.c:133
av_cold
#define av_cold
Definition: attributes.h:90
g
const char * g
Definition: vf_curves.c:128
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:247
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
ff_set_common_formats_from_list
int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts)
Equivalent to ff_set_common_formats(ctx, ff_make_format_list(fmts))
Definition: formats.c:874
av_sample_fmt_is_planar
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:114
ctx
AVFormatContext * ctx
Definition: movenc.c:49
av_expr_eval
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:792
AVExpr
Definition: eval.c:158
PRECISION_DOUBLE
@ PRECISION_DOUBLE
Definition: af_volume.h:36
VAR_N
@ VAR_N
Definition: noise.c:48
VAR_VOLUME
@ VAR_VOLUME
Definition: af_volume.h:59
set_volume
static int set_volume(AVFilterContext *ctx)
Definition: af_volume.c:247
AVReplayGain::track_peak
uint32_t track_peak
Peak track amplitude, with 100000 representing full scale (but values may overflow).
Definition: replaygain.h:39
NAN
#define NAN
Definition: mathematics.h:115
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:182
scale_samples_u8_small
static void scale_samples_u8_small(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
Definition: af_volume.c:176
scale_samples_u8
static void scale_samples_u8(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
Definition: af_volume.c:168
VolumeContext::volume_expr
const char * volume_expr
Definition: af_volume.h:75
if
if(ret)
Definition: filter_design.txt:179
av_clip_int16
#define av_clip_int16
Definition: common.h:115
TS2D
#define TS2D(ts)
Definition: internal.h:258
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:709
VAR_POS
@ VAR_POS
Definition: noise.c:56
AVFloatDSPContext::vector_fmul_scalar
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
Definition: float_dsp.h:85
isnan
#define isnan(x)
Definition: libm.h:340
ff_af_volume
const AVFilter ff_af_volume
Definition: af_volume.c:473
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_volume.c:313
ff_set_common_all_channel_counts
int ff_set_common_all_channel_counts(AVFilterContext *ctx)
Equivalent to ff_set_common_channel_layouts(ctx, ff_all_channel_counts())
Definition: formats.c:804
VolumeContext::var_values
double var_values[VAR_VARS_NB]
Definition: af_volume.h:77
VolumeContext::volume_i
int volume_i
Definition: af_volume.h:83
float_dsp.h
VolumeContext::replaygain_preamp
double replaygain_preamp
Definition: af_volume.h:80
VAR_STARTPTS
@ VAR_STARTPTS
Definition: noise.c:53
eval.h
AV_FRAME_DATA_REPLAYGAIN
@ AV_FRAME_DATA_REPLAYGAIN
ReplayGain information in the form of the AVReplayGain struct.
Definition: frame.h:77
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:94
AV_SAMPLE_FMT_U8P
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
Definition: samplefmt.h:63
av_clipl_int32
#define av_clipl_int32
Definition: common.h:118
VolumeContext::replaygain
int replaygain
Definition: af_volume.h:79
REPLAYGAIN_IGNORE
@ REPLAYGAIN_IGNORE
Definition: af_volume.h:65
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
VAR_NB_SAMPLES
@ VAR_NB_SAMPLES
Definition: af_volume.h:49
F
#define F
Definition: af_volume.c:66
AVFrameSideData::data
uint8_t * data
Definition: frame.h:252
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:645
scale_samples_s16_small
static void scale_samples_s16_small(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
Definition: af_volume.c:194
AVFrame::pkt_pos
attribute_deprecated int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder
Definition: frame.h:684
AVReplayGain::track_gain
int32_t track_gain
Track replay gain in microbels (divide by 100000 to get the value in dB).
Definition: replaygain.h:34
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:461
precision_str
static const char *const precision_str[]
Definition: af_volume.c:42
av_frame_remove_side_data
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
Definition: frame.c:1013
VolumeContext::samples_align
int samples_align
Definition: af_volume.h:90
VolumeContext::scale_samples
void(* scale_samples)(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
Definition: af_volume.h:88
VolumeContext::volume
double volume
Definition: af_volume.h:82
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:64
internal.h
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:147
VAR_PTS
@ VAR_PTS
Definition: noise.c:50
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:454
avfilter_af_volume_outputs
static const AVFilterPad avfilter_af_volume_outputs[]
Definition: af_volume.c:465
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
VAR_STARTT
@ VAR_STARTT
Definition: af_volume.h:56
AV_SAMPLE_FMT_U8
@ AV_SAMPLE_FMT_U8
unsigned 8 bits
Definition: samplefmt.h:57
set_expr
static int set_expr(AVExpr **pexpr, const char *expr, void *log_ctx)
Definition: af_volume.c:95
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:435
common.h
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:39
VAR_NB_CHANNELS
@ VAR_NB_CHANNELS
Definition: af_adrc.c:47
AVFilter
Filter definition.
Definition: avfilter.h:166
EVAL_MODE_ONCE
@ EVAL_MODE_ONCE
Definition: af_volume.h:40
ret
ret
Definition: filter_design.txt:187
volume_options
static const AVOption volume_options[]
Definition: af_volume.c:69
pos
unsigned int pos
Definition: spdifenc.c:414
AVFloatDSPContext::vector_dmul_scalar
void(* vector_dmul_scalar)(double *dst, const double *src, double mul, int len)
Multiply a vector of double by a scalar double.
Definition: float_dsp.h:100
EVAL_MODE_NB
@ EVAL_MODE_NB
Definition: af_volume.h:42
T
#define T
Definition: af_volume.c:67
channel_layout.h
EVAL_MODE_FRAME
@ EVAL_MODE_FRAME
Definition: af_volume.h:41
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:245
avfilter.h
VolumeContext::precision
int precision
Definition: af_volume.h:73
ff_volume_init_x86
void ff_volume_init_x86(VolumeContext *vol)
Definition: af_volume_init.c:36
AVReplayGain::album_peak
uint32_t album_peak
Same as track_peak, but for the whole album,.
Definition: replaygain.h:47
VolumeContext::fdsp
AVFloatDSPContext * fdsp
Definition: af_volume.h:72
av_get_packed_sample_fmt
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
Definition: samplefmt.c:77
AV_SAMPLE_FMT_DBLP
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:67
ffmath.h
av_clip_uint8
#define av_clip_uint8
Definition: common.h:106
AVFilterContext
An instance of a filter.
Definition: avfilter.h:407
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
AVReplayGain
ReplayGain information (see http://wiki.hydrogenaudio.org/index.php?title=ReplayGain_1....
Definition: replaygain.h:29
VolumeContext::sample_fmt
enum AVSampleFormat sample_fmt
Definition: af_volume.h:86
mem.h
audio.h
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:250
PRECISION_FLOAT
@ PRECISION_FLOAT
Definition: af_volume.h:35
A
#define A
Definition: af_volume.c:65
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:261
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:183
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:146
int32_t
int32_t
Definition: audioconvert.c:56
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
avfilter_af_volume_inputs
static const AVFilterPad avfilter_af_volume_inputs[]
Definition: af_volume.c:457
AV_SAMPLE_FMT_DBL
@ AV_SAMPLE_FMT_DBL
double
Definition: samplefmt.h:61
VAR_SAMPLE_RATE
@ VAR_SAMPLE_RATE
Definition: af_afftfilt.c:58
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:249
int
int
Definition: ffmpeg_filter.c:424
AV_SAMPLE_FMT_S32
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:59
REPLAYGAIN_TRACK
@ REPLAYGAIN_TRACK
Definition: af_volume.h:66
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:254
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:60