X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Faf_sofalizer.c;h=e62cad24994b02d63583a20089ea77c0185b2e93;hb=bd96c54fe4819b3ca9a975e2083d67f4443c559b;hp=109cf5695b32db91fa3188684aa9514e0724db0c;hpb=0dda0f3bdb7e8a2d5bef7457375f72f38a100ccb;p=ffmpeg diff --git a/libavfilter/af_sofalizer.c b/libavfilter/af_sofalizer.c index 109cf5695b3..e62cad24994 100644 --- a/libavfilter/af_sofalizer.c +++ b/libavfilter/af_sofalizer.c @@ -35,6 +35,7 @@ #include "libavutil/intmath.h" #include "libavutil/opt.h" #include "avfilter.h" +#include "filters.h" #include "internal.h" #include "audio.h" @@ -81,6 +82,7 @@ typedef struct SOFAlizerContext { int buffer_length; /* is: longest IR plus max. delay in all SOFA files */ /* then choose next power of 2 */ int n_fft; /* number of samples in one FFT block */ + int nb_samples; /* netCDF variables */ int *delay[2]; /* broadband delay for each channel/IR to be convolved */ @@ -181,10 +183,11 @@ static int preload_sofa(AVFilterContext *ctx, char *filename, int *samplingrate) return 0; } -static int parse_channel_name(char **arg, int *rchannel, char *buf) +static int parse_channel_name(AVFilterContext *ctx, char **arg, int *rchannel) { int len, i, channel_id = 0; int64_t layout, layout0; + char buf[8] = {0}; /* try to parse a channel name, e.g. "FL" */ if (av_sscanf(*arg, "%7[A-Z]%n", buf, &len)) { @@ -197,8 +200,18 @@ static int parse_channel_name(char **arg, int *rchannel, char *buf) } } /* reject layouts that are not a single channel */ - if (channel_id >= 64 || layout0 != 1LL << channel_id) + if (channel_id >= 64 || layout0 != 1LL << channel_id) { + av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", buf); return AVERROR(EINVAL); + } + *rchannel = channel_id; + *arg += len; + return 0; + } else if (av_sscanf(*arg, "%d%n", &channel_id, &len) == 1) { + if (channel_id < 0 || channel_id >= 64) { + av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%d\' as channel number.\n", channel_id); + return AVERROR(EINVAL); + } *rchannel = channel_id; *arg += len; return 0; @@ -216,13 +229,11 @@ static void parse_speaker_pos(AVFilterContext *ctx, int64_t in_channel_layout) p = args; while ((arg = av_strtok(p, "|", &tokenizer))) { - char buf[8]; float azim, elev; int out_ch_id; p = NULL; - if (parse_channel_name(&arg, &out_ch_id, buf)) { - av_log(ctx, AV_LOG_WARNING, "Failed to parse \'%s\' as channel name.\n", buf); + if (parse_channel_name(ctx, &arg, &out_ch_id)) { continue; } if (av_sscanf(arg, "%f %f", &azim, &elev) == 2) { @@ -244,11 +255,11 @@ static int get_speaker_pos(AVFilterContext *ctx, { struct SOFAlizerContext *s = ctx->priv; uint64_t channels_layout = ctx->inputs[0]->channel_layout; - float azim[16] = { 0 }; - float elev[16] = { 0 }; + float azim[64] = { 0 }; + float elev[64] = { 0 }; int m, ch, n_conv = ctx->inputs[0]->channels; /* get no. input channels */ - if (n_conv > 16) + if (n_conv < 0 || n_conv > 64) return AVERROR(EINVAL); s->lfe_channel = -1; @@ -349,7 +360,7 @@ static int sofalizer_convolute(AVFilterContext *ctx, void *arg, int jobnr, int n const int buffer_length = s->buffer_length; /* -1 for AND instead of MODULO (applied to powers of 2): */ const uint32_t modulo = (uint32_t)buffer_length - 1; - float *buffer[16]; /* holds ringbuffer for each input channel */ + float *buffer[64]; /* holds ringbuffer for each input channel */ int wr = *write; int read; int i, l; @@ -603,6 +614,31 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) return ff_filter_frame(outlink, out); } +static int activate(AVFilterContext *ctx) +{ + AVFilterLink *inlink = ctx->inputs[0]; + AVFilterLink *outlink = ctx->outputs[0]; + SOFAlizerContext *s = ctx->priv; + AVFrame *in; + int ret; + + FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); + + if (s->nb_samples) + ret = ff_inlink_consume_samples(inlink, s->nb_samples, s->nb_samples, &in); + else + ret = ff_inlink_consume_frame(inlink, &in); + if (ret < 0) + return ret; + if (ret > 0) + return filter_frame(inlink, in); + + FF_FILTER_FORWARD_STATUS(inlink, outlink); + FF_FILTER_FORWARD_WANTED(outlink, inlink); + + return FFERROR_NOT_READY; +} + static int query_formats(AVFilterContext *ctx) { struct SOFAlizerContext *s = ctx->priv; @@ -625,7 +661,7 @@ static int query_formats(AVFilterContext *ctx) if (!layouts) return AVERROR(ENOMEM); - ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->out_channel_layouts); + ret = ff_channel_layouts_ref(layouts, &ctx->inputs[0]->outcfg.channel_layouts); if (ret) return ret; @@ -634,7 +670,7 @@ static int query_formats(AVFilterContext *ctx) if (ret) return ret; - ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts); + ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts); if (ret) return ret; @@ -964,11 +1000,8 @@ static int config_input(AVFilterLink *inlink) SOFAlizerContext *s = ctx->priv; int ret; - if (s->type == FREQUENCY_DOMAIN) { - inlink->partial_buf_size = - inlink->min_samples = - inlink->max_samples = s->framesize; - } + if (s->type == FREQUENCY_DOMAIN) + s->nb_samples = s->framesize; /* gain -3 dB per channel */ s->gain_lfe = expf((s->gain - 3 * inlink->channels + s->lfe_gain) / 20 * M_LN10); @@ -1047,7 +1080,6 @@ static const AVFilterPad inputs[] = { .name = "default", .type = AVMEDIA_TYPE_AUDIO, .config_props = config_input, - .filter_frame = filter_frame, }, { NULL } }; @@ -1060,12 +1092,13 @@ static const AVFilterPad outputs[] = { { NULL } }; -AVFilter ff_af_sofalizer = { +const AVFilter ff_af_sofalizer = { .name = "sofalizer", .description = NULL_IF_CONFIG_SMALL("SOFAlizer (Spatially Oriented Format for Acoustics)."), .priv_size = sizeof(SOFAlizerContext), .priv_class = &sofalizer_class, .init = init, + .activate = activate, .uninit = uninit, .query_formats = query_formats, .inputs = inputs,