FFmpeg
Loading...
Searching...
No Matches
af_volume.c File Reference

audio volume filter More...

#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/eval.h"
#include "libavutil/ffmath.h"
#include "libavutil/float_dsp.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/replaygain.h"
#include "audio.h"
#include "avfilter.h"
#include "filters.h"
#include "formats.h"
#include "af_volume.h"

Go to the source code of this file.

Macros

#define OFFSET(x)
 
#define A   AV_OPT_FLAG_AUDIO_PARAM
 
#define F   AV_OPT_FLAG_FILTERING_PARAM
 
#define T   AV_OPT_FLAG_RUNTIME_PARAM
 

Functions

 AVFILTER_DEFINE_CLASS (volume)
 
static int set_expr (AVExpr **pexpr, const char *expr, void *log_ctx)
 
static av_cold int init (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int query_formats (const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
 
static void scale_samples_u8 (uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
 
static void scale_samples_u8_small (uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
 
static void scale_samples_s16 (uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
 
static void scale_samples_s16_small (uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
 
static void scale_samples_s32 (uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
 
static av_cold void volume_init (VolumeContext *vol)
 
static int set_volume (AVFilterContext *ctx)
 
static int config_output (AVFilterLink *outlink)
 
static int process_command (AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *buf)
 

Variables

static const char *const precision_str []
 
static const char *const var_names []
 
static const AVOption volume_options []
 
static const AVFilterPad avfilter_af_volume_inputs []
 
static const AVFilterPad avfilter_af_volume_outputs []
 
const FFFilter ff_af_volume
 

Detailed Description

audio volume filter

Definition in file af_volume.c.

Macro Definition Documentation

◆ OFFSET

#define OFFSET ( x)
Value:

Definition at line 61 of file af_volume.c.

◆ A

#define A   AV_OPT_FLAG_AUDIO_PARAM

Definition at line 62 of file af_volume.c.

◆ F

Definition at line 63 of file af_volume.c.

◆ T

#define T   AV_OPT_FLAG_RUNTIME_PARAM

Definition at line 64 of file af_volume.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( volume )

◆ set_expr()

static int set_expr ( AVExpr ** pexpr,
const char * expr,
void * log_ctx )
static

◆ init()

static av_cold int init ( AVFilterContext * ctx)
static

Definition at line 112 of file af_volume.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext * ctx)
static

Definition at line 123 of file af_volume.c.

◆ query_formats()

static int query_formats ( const AVFilterContext * ctx,
AVFilterFormatsConfig ** cfg_in,
AVFilterFormatsConfig ** cfg_out )
static

Definition at line 130 of file af_volume.c.

◆ scale_samples_u8()

static void scale_samples_u8 ( uint8_t * dst,
const uint8_t * src,
int nb_samples,
int volume )
inlinestatic

Definition at line 165 of file af_volume.c.

Referenced by volume_init().

◆ scale_samples_u8_small()

static void scale_samples_u8_small ( uint8_t * dst,
const uint8_t * src,
int nb_samples,
int volume )
inlinestatic

Definition at line 173 of file af_volume.c.

Referenced by volume_init().

◆ scale_samples_s16()

static void scale_samples_s16 ( uint8_t * dst,
const uint8_t * src,
int nb_samples,
int volume )
inlinestatic

Definition at line 181 of file af_volume.c.

Referenced by volume_init().

◆ scale_samples_s16_small()

static void scale_samples_s16_small ( uint8_t * dst,
const uint8_t * src,
int nb_samples,
int volume )
inlinestatic

Definition at line 191 of file af_volume.c.

Referenced by volume_init().

◆ scale_samples_s32()

static void scale_samples_s32 ( uint8_t * dst,
const uint8_t * src,
int nb_samples,
int volume )
inlinestatic

Definition at line 201 of file af_volume.c.

Referenced by volume_init().

◆ volume_init()

static av_cold void volume_init ( VolumeContext * vol)
static

Definition at line 211 of file af_volume.c.

Referenced by filter_frame(), and set_volume().

◆ set_volume()

static int set_volume ( AVFilterContext * ctx)
static

Definition at line 244 of file af_volume.c.

Referenced by config_output(), filter_frame(), and process_command().

◆ config_output()

static int config_output ( AVFilterLink * outlink)
static

Definition at line 276 of file af_volume.c.

◆ process_command()

static int process_command ( AVFilterContext * ctx,
const char * cmd,
const char * args,
char * res,
int res_len,
int flags )
static

Definition at line 307 of file af_volume.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink * inlink,
AVFrame * buf )
static

Definition at line 323 of file af_volume.c.

Variable Documentation

◆ precision_str

const char* const precision_str[]
static
Initial value:
= {
"fixed", "float", "double"
}

Definition at line 42 of file af_volume.c.

Referenced by set_volume().

◆ var_names

const char* const var_names[]
static
Initial value:
= {
"n",
"nb_channels",
"nb_consumed_samples",
"nb_samples",
"pts",
"sample_rate",
"startpts",
"startt",
"t",
"tb",
"volume",
}
#define NULL
Definition coverity.c:32

Definition at line 46 of file af_volume.c.

◆ volume_options

const AVOption volume_options[]
static
Initial value:
= {
{ "volume", "set volume adjustment expression",
OFFSET(volume_expr), AV_OPT_TYPE_STRING, { .str = "1.0" }, .flags = A|F|T },
{ "precision", "select mathematical precision",
OFFSET(precision), AV_OPT_TYPE_INT, { .i64 = PRECISION_FLOAT }, PRECISION_FIXED, PRECISION_DOUBLE, A|F, .unit = "precision" },
{ "fixed", "select 8-bit fixed-point", 0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_FIXED }, INT_MIN, INT_MAX, A|F, .unit = "precision" },
{ "float", "select 32-bit floating-point", 0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_FLOAT }, INT_MIN, INT_MAX, A|F, .unit = "precision" },
{ "double", "select 64-bit floating-point", 0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_DOUBLE }, INT_MIN, INT_MAX, A|F, .unit = "precision" },
{ "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" },
{ "once", "eval volume expression once", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_ONCE}, .flags = A|F, .unit = "eval" },
{ "frame", "eval volume expression per-frame", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags = A|F, .unit = "eval" },
{ "replaygain", "Apply replaygain side data when present",
OFFSET(replaygain), AV_OPT_TYPE_INT, { .i64 = REPLAYGAIN_DROP }, REPLAYGAIN_DROP, REPLAYGAIN_ALBUM, A|F, .unit = "replaygain" },
{ "drop", "replaygain side data is dropped", 0, AV_OPT_TYPE_CONST, { .i64 = REPLAYGAIN_DROP }, 0, 0, A|F, .unit = "replaygain" },
{ "ignore", "replaygain side data is ignored", 0, AV_OPT_TYPE_CONST, { .i64 = REPLAYGAIN_IGNORE }, 0, 0, A|F, .unit = "replaygain" },
{ "track", "track gain is preferred", 0, AV_OPT_TYPE_CONST, { .i64 = REPLAYGAIN_TRACK }, 0, 0, A|F, .unit = "replaygain" },
{ "album", "album gain is preferred", 0, AV_OPT_TYPE_CONST, { .i64 = REPLAYGAIN_ALBUM }, 0, 0, A|F, .unit = "replaygain" },
{ "replaygain_preamp", "Apply replaygain pre-amplification",
OFFSET(replaygain_preamp), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, -15.0, 15.0, A|F },
{ "replaygain_noclip", "Apply replaygain clipping prevention",
OFFSET(replaygain_noclip), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, A|F },
{ NULL }
}
@ PRECISION_FLOAT
Definition af_volume.h:35
@ PRECISION_FIXED
Definition af_volume.h:34
@ PRECISION_DOUBLE
Definition af_volume.h:36
@ EVAL_MODE_NB
Definition af_volume.h:42
@ EVAL_MODE_FRAME
Definition af_volume.h:41
@ EVAL_MODE_ONCE
Definition af_volume.h:40
@ REPLAYGAIN_IGNORE
Definition af_volume.h:62
@ REPLAYGAIN_TRACK
Definition af_volume.h:63
@ REPLAYGAIN_DROP
Definition af_volume.h:61
@ REPLAYGAIN_ALBUM
Definition af_volume.h:64
#define T(x)
Definition vpx_arith.h:29
#define A(x)
Definition vpx_arith.h:28
#define F(x)
#define OFFSET(x)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition opt.h:266
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ 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...
Definition opt.h:275

Definition at line 66 of file af_volume.c.

◆ avfilter_af_volume_inputs

const AVFilterPad avfilter_af_volume_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
},
}
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201

Definition at line 443 of file af_volume.c.

◆ avfilter_af_volume_outputs

const AVFilterPad avfilter_af_volume_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_output,
},
}
static int config_output(AVBitStreamFilterLink *outlink)

Definition at line 451 of file af_volume.c.

◆ ff_af_volume

const FFFilter ff_af_volume
Initial value:
= {
.p.name = "volume",
.p.description = NULL_IF_CONFIG_SMALL("Change input volume."),
.p.priv_class = &volume_class,
.priv_size = sizeof(VolumeContext),
.init = init,
.process_command = process_command,
}
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition aeval.c:246
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static const AVFilterPad avfilter_af_volume_inputs[]
Definition af_volume.c:443
static const AVFilterPad avfilter_af_volume_outputs[]
Definition af_volume.c:451
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#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:196
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:241
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88

Definition at line 459 of file af_volume.c.