History

avfilter/af_anlmdn: support all options as commands

Paul B Mahol committed 5 years ago

Commit bb7bb441 parent 96f1b452 files · +77 −37Browse files

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/af_anlmdn.c+76−27
@@ -72,13 +72,12 @@ enum OutModes { · 71 unmodified lines
7272 };
7373
7474 #define OFFSET(x) offsetof(AudioNLMeansContext, x)
75−#define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
7675 #define AFT AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
7776
7877 static const AVOption anlmdn_options[] = {
7978 { "s", "set denoising strength", OFFSET(a), AV_OPT_TYPE_FLOAT, {.dbl=0.00001},0.00001, 10, AFT },
80− { "p", "set patch duration", OFFSET(pd), AV_OPT_TYPE_DURATION, {.i64=2000}, 1000, 100000, AF },
81− { "r", "set research duration", OFFSET(rd), AV_OPT_TYPE_DURATION, {.i64=6000}, 2000, 300000, AF },
79+ { "p", "set patch duration", OFFSET(pd), AV_OPT_TYPE_DURATION, {.i64=2000}, 1000, 100000, AFT },
80+ { "r", "set research duration", OFFSET(rd), AV_OPT_TYPE_DURATION, {.i64=6000}, 2000, 300000, AFT },
8281 { "o", "set output mode", OFFSET(om), AV_OPT_TYPE_INT, {.i64=OUT_MODE}, 0, NB_MODES-1, AFT, "mode" },
8382 { "i", "input", 0, AV_OPT_TYPE_CONST, {.i64=IN_MODE}, 0, 0, AFT, "mode" },
8483 { "o", "output", 0, AV_OPT_TYPE_CONST, {.i64=OUT_MODE}, 0, 0, AFT, "mode" },
@@ -147,32 +146,73 @@ void ff_anlmdn_init(AudioNLMDNDSPContext *dsp) · 62 unmodified lines
147146 ff_anlmdn_init_x86(dsp);
148147 }
149148
150−static int config_output(AVFilterLink *outlink)
149+static int config_filter(AVFilterContext *ctx)
151150 {
152− AVFilterContext *ctx = outlink->src;
153151 AudioNLMeansContext *s = ctx->priv;
154− int ret;
152+ AVFilterLink *outlink = ctx->outputs[0];
153+ int newK, newS, newH, newN;
154+ AVFrame *new_in, *new_cache;
155155
156− s->K = av_rescale(s->pd, outlink->sample_rate, AV_TIME_BASE);
157− s->S = av_rescale(s->rd, outlink->sample_rate, AV_TIME_BASE);
156+ newK = av_rescale(s->pd, outlink->sample_rate, AV_TIME_BASE);
157+ newS = av_rescale(s->rd, outlink->sample_rate, AV_TIME_BASE);
158158
159− s->eof_left = -1;
160− s->pts = AV_NOPTS_VALUE;
161− s->H = s->K * 2 + 1;
162− s->N = s->H + (s->K + s->S) * 2;
159+ newH = newK * 2 + 1;
160+ newN = newH + (newK + newS) * 2;
163161
164− av_log(ctx, AV_LOG_DEBUG, "K:%d S:%d H:%d N:%d\n", s->K, s->S, s->H, s->N);
162+ av_log(ctx, AV_LOG_DEBUG, "K:%d S:%d H:%d N:%d\n", newK, newS, newH, newN);
165163
166− av_frame_free(&s->in);
167− av_frame_free(&s->cache);
168− s->in = ff_get_audio_buffer(outlink, s->N);
169− if (!s->in)
164+ if (!s->cache || s->cache->nb_samples < newS * 2) {
165+ new_cache = ff_get_audio_buffer(outlink, newS * 2);
166+ if (new_cache) {
167+ av_frame_free(&s->cache);
168+ s->cache = new_cache;
169+ } else {
170+ return AVERROR(ENOMEM);
171+ }
172+ }
173+ if (!s->cache)
170174 return AVERROR(ENOMEM);
171175
172− s->cache = ff_get_audio_buffer(outlink, s->S * 2);
173− if (!s->cache)
176+ s->pdiff_lut_scale = 1.f / s->m * WEIGHT_LUT_SIZE;
177+ for (int i = 0; i < WEIGHT_LUT_SIZE; i++) {
178+ float w = -i / s->pdiff_lut_scale;
179+
180+ s->weight_lut[i] = expf(w);
181+ }
182+
183+ if (!s->in || s->in->nb_samples < newN) {
184+ new_in = ff_get_audio_buffer(outlink, newN);
185+ if (new_in) {
186+ av_frame_free(&s->in);
187+ s->in = new_in;
188+ } else {
189+ return AVERROR(ENOMEM);
190+ }
191+ }
192+ if (!s->in)
174193 return AVERROR(ENOMEM);
175194
195+ s->K = newK;
196+ s->S = newS;
197+ s->H = newH;
198+ s->N = newN;
199+
200+ return 0;
201+}
202+
203+static int config_output(AVFilterLink *outlink)
204+{
205+ AVFilterContext *ctx = outlink->src;
206+ AudioNLMeansContext *s = ctx->priv;
207+ int ret;
208+
209+ s->eof_left = -1;
210+ s->pts = AV_NOPTS_VALUE;
211+
212+ ret = config_filter(ctx);
213+ if (ret < 0)
214+ return ret;
215+
176216 s->fifo = av_audio_fifo_alloc(outlink->format, outlink->channels, s->N);
177217 if (!s->fifo)
178218 return AVERROR(ENOMEM);
@@ -181,13 +221,6 @@ static int config_output(AVFilterLink *outlink) · 2 unmodified lines
181221 if (ret < 0)
182222 return ret;
183223
184− s->pdiff_lut_scale = 1.f / s->m * WEIGHT_LUT_SIZE;
185− for (int i = 0; i < WEIGHT_LUT_SIZE; i++) {
186− float w = -i / s->pdiff_lut_scale;
187−
188− s->weight_lut[i] = expf(w);
189− }
190−
191224 ff_anlmdn_init(&s->dsp);
192225
193226 return 0;
@@ -331,6 +364,22 @@ static int request_frame(AVFilterLink *outlink) · 137 unmodified lines
331364 return ret;
332365 }
333366
367+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
368+ char *res, int res_len, int flags)
369+{
370+ int ret;
371+
372+ ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
373+ if (ret < 0)
374+ return ret;
375+
376+ ret = config_filter(ctx);
377+ if (ret < 0)
378+ return ret;
379+
380+ return 0;
381+}
382+
334383 static av_cold void uninit(AVFilterContext *ctx)
335384 {
336385 AudioNLMeansContext *s = ctx->priv;
@@ -368,7 +417,7 @@ AVFilter ff_af_anlmdn = { · 31 unmodified lines
368417 .uninit = uninit,
369418 .inputs = inputs,
370419 .outputs = outputs,
371− .process_command = ff_filter_process_command,
420+ .process_command = process_command,
372421 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL |
373422 AVFILTER_FLAG_SLICE_THREADS,
374423 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t