Showing the changes to libavfilter (1 of 2 files). Show all
Unified · Split
| @@ -72,13 +72,12 @@ enum OutModes { · 71 unmodified lines | ||
| 72 | 72 | }; |
| 73 | 73 | |
| 74 | 74 | #define OFFSET(x) offsetof(AudioNLMeansContext, x) |
| 75 | −#define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM | |
| 76 | 75 | #define AFT AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM |
| 77 | 76 | |
| 78 | 77 | static const AVOption anlmdn_options[] = { |
| 79 | 78 | { "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 }, | |
| 82 | 81 | { "o", "set output mode", OFFSET(om), AV_OPT_TYPE_INT, {.i64=OUT_MODE}, 0, NB_MODES-1, AFT, "mode" }, |
| 83 | 82 | { "i", "input", 0, AV_OPT_TYPE_CONST, {.i64=IN_MODE}, 0, 0, AFT, "mode" }, |
| 84 | 83 | { "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 | ||
| 147 | 146 | ff_anlmdn_init_x86(dsp); |
| 148 | 147 | } |
| 149 | 148 | |
| 150 | −static int config_output(AVFilterLink *outlink) | |
| 149 | +static int config_filter(AVFilterContext *ctx) | |
| 151 | 150 | { |
| 152 | − AVFilterContext *ctx = outlink->src; | |
| 153 | 151 | 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; | |
| 155 | 155 | |
| 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); | |
| 158 | 158 | |
| 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; | |
| 163 | 161 | |
| 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); | |
| 165 | 163 | |
| 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) | |
| 170 | 174 | return AVERROR(ENOMEM); |
| 171 | 175 | |
| 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) | |
| 174 | 193 | return AVERROR(ENOMEM); |
| 175 | 194 | |
| 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 | + | |
| 176 | 216 | s->fifo = av_audio_fifo_alloc(outlink->format, outlink->channels, s->N); |
| 177 | 217 | if (!s->fifo) |
| 178 | 218 | return AVERROR(ENOMEM); |
| @@ -181,13 +221,6 @@ static int config_output(AVFilterLink *outlink) · 2 unmodified lines | ||
| 181 | 221 | if (ret < 0) |
| 182 | 222 | return ret; |
| 183 | 223 | |
| 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 | − | |
| 191 | 224 | ff_anlmdn_init(&s->dsp); |
| 192 | 225 | |
| 193 | 226 | return 0; |
| @@ -331,6 +364,22 @@ static int request_frame(AVFilterLink *outlink) · 137 unmodified lines | ||
| 331 | 364 | return ret; |
| 332 | 365 | } |
| 333 | 366 | |
| 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 | + | |
| 334 | 383 | static av_cold void uninit(AVFilterContext *ctx) |
| 335 | 384 | { |
| 336 | 385 | AudioNLMeansContext *s = ctx->priv; |
| @@ -368,7 +417,7 @@ AVFilter ff_af_anlmdn = { · 31 unmodified lines | ||
| 368 | 417 | .uninit = uninit, |
| 369 | 418 | .inputs = inputs, |
| 370 | 419 | .outputs = outputs, |
| 371 | − .process_command = ff_filter_process_command, | |
| 420 | + .process_command = process_command, | |
| 372 | 421 | .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | |
| 373 | 422 | AVFILTER_FLAG_SLICE_THREADS, |
| 374 | 423 | }; |