48#define SDR_FILTER(name, type) \
49static int sdr_##name(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)\
51 AudioSDRContext *s = ctx->priv; \
52 AVFrame *u = s->cache[0]; \
53 AVFrame *v = s->cache[1]; \
54 const int channels = u->ch_layout.nb_channels; \
55 const int start = ff_slice_pos(channels, jobnr, nb_jobs); \
56 const int end = ff_slice_pos(channels, jobnr + 1, nb_jobs); \
57 const int nb_samples = u->nb_samples; \
59 for (int ch = start; ch < end; ch++) { \
60 ChanStats *chs = &s->chs[ch]; \
61 const type *const us = (type *)u->extended_data[ch]; \
62 const type *const vs = (type *)v->extended_data[ch]; \
66 for (int n = 0; n < nb_samples; n++) { \
67 sum_u += us[n] * us[n]; \
68 sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]); \
81#define SISDR_FILTER(name, type) \
82static int sisdr_##name(AVFilterContext *ctx, void *arg,int jobnr,int nb_jobs)\
84 AudioSDRContext *s = ctx->priv; \
85 AVFrame *u = s->cache[0]; \
86 AVFrame *v = s->cache[1]; \
87 const int channels = u->ch_layout.nb_channels; \
88 const int start = ff_slice_pos(channels, jobnr, nb_jobs); \
89 const int end = ff_slice_pos(channels, jobnr + 1, nb_jobs); \
90 const int nb_samples = u->nb_samples; \
92 for (int ch = start; ch < end; ch++) { \
93 ChanStats *chs = &s->chs[ch]; \
94 const type *const us = (type *)u->extended_data[ch]; \
95 const type *const vs = (type *)v->extended_data[ch]; \
100 for (int n = 0; n < nb_samples; n++) { \
101 sum_u += us[n] * us[n]; \
102 sum_v += vs[n] * vs[n]; \
103 sum_uv += us[n] * vs[n]; \
117#define PSNR_FILTER(name, type) \
118static int psnr_##name(AVFilterContext *ctx, void *arg, int jobnr,int nb_jobs)\
120 AudioSDRContext *s = ctx->priv; \
121 AVFrame *u = s->cache[0]; \
122 AVFrame *v = s->cache[1]; \
123 const int channels = u->ch_layout.nb_channels; \
124 const int start = ff_slice_pos(channels, jobnr, nb_jobs); \
125 const int end = ff_slice_pos(channels, jobnr + 1, nb_jobs); \
126 const int nb_samples = u->nb_samples; \
128 for (int ch = start; ch < end; ch++) { \
129 ChanStats *chs = &s->chs[ch]; \
130 const type *const us = (type *)u->extended_data[ch]; \
131 const type *const vs = (type *)v->extended_data[ch]; \
132 double sum_uv = 0.; \
134 for (int n = 0; n < nb_samples; n++) \
135 sum_uv += (us[n] - vs[n]) * (us[n] - vs[n]); \
150 int ret, status, available;
159 for (
int i = 0;
i < 2;
i++) {
168 if (!
ctx->is_disabled)
176 s->nb_samples += available;
180 for (
int i = 0;
i < 2;
i++) {
188 for (
int i = 0;
i < 2;
i++) {
207 if (!strcmp(
ctx->filter->name,
"asdr"))
209 else if (!strcmp(
ctx->filter->name,
"asisdr"))
226 if (!strcmp(
ctx->filter->name,
"asdr")) {
227 for (
int ch = 0; ch <
s->channels; ch++)
229 }
else if (!strcmp(
ctx->filter->name,
"asisdr")) {
230 for (
int ch = 0; ch <
s->channels; ch++) {
231 double scale =
s->chs[ch].uv /
s->chs[ch].v;
237 for (
int ch = 0; ch <
s->channels; ch++) {
238 double psnr =
s->chs[ch].uv > 0.0 ? 2.0 * log(
s->max) - log(
s->nb_samples /
s->chs[ch].uv) :
INFINITY;
301 .p.description =
NULL_IF_CONFIG_SMALL(
"Measure Audio Scale-Invariant Signal-to-Distortion Ratio."),
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
const FFFilter ff_af_apsnr
const FFFilter ff_af_asdr
static av_cold void uninit(AVFilterContext *ctx)
#define SISDR_FILTER(name, type)
#define SDR_FILTER(name, type)
static int config_output(AVFilterLink *outlink)
#define PSNR_FILTER(name, type)
const FFFilter ff_af_asisdr
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_outlink_frame_wanted(AVFilterLink *link)
Test if a frame is wanted on an output link.
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
int ff_inlink_queued_samples(AVFilterLink *link)
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
common internal and external API header
double fmax(double, double)
static double psnr(double d)
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_LOG_INFO
Standard information.
@ AV_SAMPLE_FMT_FLTP
float, planar
@ AV_SAMPLE_FMT_DBLP
double, planar
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FILTER_SAMPLEFMTS(...)
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
#define FFERROR_NOT_READY
Filters implementation helper functions and internal structures.
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
int nb_channels
Number of channels in this layout.
A link between two filters.
AVFilterContext * src
source filter
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
int format
agreed upon media format
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
int(* filter)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static AVFormatContext * ctx