avfilter/af_adeclick: switch to activate

This commit is contained in:
Paul B Mahol 2019-04-29 22:19:15 +02:00
parent 12a284fa63
commit e6c7d838ea

View File

@ -22,7 +22,9 @@
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "avfilter.h" #include "avfilter.h"
#include "audio.h" #include "audio.h"
#include "filters.h"
#include "formats.h" #include "formats.h"
#include "internal.h"
typedef struct DeclickChannel { typedef struct DeclickChannel {
double *auxiliary; double *auxiliary;
@ -73,6 +75,7 @@ typedef struct AudioDeclickContext {
uint64_t nb_samples; uint64_t nb_samples;
uint64_t detected_errors; uint64_t detected_errors;
int samples_left; int samples_left;
int eof;
AVAudioFifo *fifo; AVAudioFifo *fifo;
double *window_func_lut; double *window_func_lut;
@ -544,23 +547,13 @@ static int filter_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
return 0; return 0;
} }
static int filter_frame(AVFilterLink *inlink, AVFrame *in) static int filter_frame(AVFilterLink *inlink)
{ {
AVFilterContext *ctx = inlink->dst; AVFilterContext *ctx = inlink->dst;
AVFilterLink *outlink = ctx->outputs[0]; AVFilterLink *outlink = ctx->outputs[0];
AudioDeclickContext *s = ctx->priv; AudioDeclickContext *s = ctx->priv;
AVFrame *out = NULL; AVFrame *out = NULL;
int ret = 0; int ret = 0, j, ch, detected_errors = 0;
if (s->pts == AV_NOPTS_VALUE)
s->pts = in->pts;
ret = av_audio_fifo_write(s->fifo, (void **)in->extended_data,
in->nb_samples);
av_frame_free(&in);
while (av_audio_fifo_size(s->fifo) >= s->window_size) {
int j, ch, detected_errors = 0;
ThreadData td; ThreadData td;
out = ff_get_audio_buffer(outlink, s->hop_size); out = ff_get_audio_buffer(outlink, s->hop_size);
@ -570,7 +563,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
ret = av_audio_fifo_peek(s->fifo, (void **)s->in->extended_data, ret = av_audio_fifo_peek(s->fifo, (void **)s->in->extended_data,
s->window_size); s->window_size);
if (ret < 0) if (ret < 0)
break; goto fail;
td.out = out; td.out = out;
ret = ctx->internal->execute(ctx, filter_channel, &td, NULL, inlink->channels); ret = ctx->internal->execute(ctx, filter_channel, &td, NULL, inlink->channels);
@ -599,14 +592,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
ret = ff_filter_frame(outlink, out); ret = ff_filter_frame(outlink, out);
if (ret < 0) if (ret < 0)
break; goto fail;
if (s->samples_left > 0) { if (s->samples_left > 0) {
s->samples_left -= s->hop_size; s->samples_left -= s->hop_size;
if (s->samples_left <= 0) if (s->samples_left <= 0)
av_audio_fifo_drain(s->fifo, av_audio_fifo_size(s->fifo)); av_audio_fifo_drain(s->fifo, av_audio_fifo_size(s->fifo));
} }
}
fail: fail:
if (ret < 0) if (ret < 0)
@ -614,27 +606,58 @@ fail:
return ret; return ret;
} }
static int request_frame(AVFilterLink *outlink) static int activate(AVFilterContext *ctx)
{ {
AVFilterContext *ctx = outlink->src; AVFilterLink *inlink = ctx->inputs[0];
AVFilterLink *outlink = ctx->outputs[0];
AudioDeclickContext *s = ctx->priv; AudioDeclickContext *s = ctx->priv;
int ret = 0; AVFrame *in;
int ret, status;
int64_t pts;
ret = ff_request_frame(ctx->inputs[0]); FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
if (ret == AVERROR_EOF && av_audio_fifo_size(s->fifo) > 0) {
if (!s->samples_left)
s->samples_left = av_audio_fifo_size(s->fifo) - s->overlap_skip;
if (s->samples_left > 0) {
AVFrame *in = ff_get_audio_buffer(outlink, s->window_size - s->samples_left);
if (!in)
return AVERROR(ENOMEM);
ret = filter_frame(ctx->inputs[0], in);
}
}
ret = ff_inlink_consume_samples(inlink, s->window_size, s->window_size, &in);
if (ret < 0)
return ret; return ret;
if (ret > 0) {
if (s->pts == AV_NOPTS_VALUE)
s->pts = in->pts;
ret = av_audio_fifo_write(s->fifo, (void **)in->extended_data,
in->nb_samples);
av_frame_free(&in);
if (ret < 0)
return ret;
}
if (av_audio_fifo_size(s->fifo) >= s->window_size ||
s->samples_left > 0)
return filter_frame(inlink);
if (av_audio_fifo_size(s->fifo) >= s->window_size) {
ff_filter_set_ready(ctx, 100);
return 0;
}
if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &pts)) {
if (status == AVERROR_EOF) {
s->eof = 1;
s->samples_left = av_audio_fifo_size(s->fifo) - s->overlap_skip;
ff_filter_set_ready(ctx, 100);
return 0;
}
}
if (s->eof && s->samples_left <= 0) {
ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
return 0;
}
if (!s->eof)
FF_FILTER_FORWARD_WANTED(outlink, inlink);
return FFERROR_NOT_READY;
} }
static av_cold int init(AVFilterContext *ctx) static av_cold int init(AVFilterContext *ctx)
@ -697,7 +720,6 @@ static const AVFilterPad inputs[] = {
{ {
.name = "default", .name = "default",
.type = AVMEDIA_TYPE_AUDIO, .type = AVMEDIA_TYPE_AUDIO,
.filter_frame = filter_frame,
.config_props = config_input, .config_props = config_input,
}, },
{ NULL } { NULL }
@ -707,7 +729,6 @@ static const AVFilterPad outputs[] = {
{ {
.name = "default", .name = "default",
.type = AVMEDIA_TYPE_AUDIO, .type = AVMEDIA_TYPE_AUDIO,
.request_frame = request_frame,
}, },
{ NULL } { NULL }
}; };
@ -719,6 +740,7 @@ AVFilter ff_af_adeclick = {
.priv_size = sizeof(AudioDeclickContext), .priv_size = sizeof(AudioDeclickContext),
.priv_class = &adeclick_class, .priv_class = &adeclick_class,
.init = init, .init = init,
.activate = activate,
.uninit = uninit, .uninit = uninit,
.inputs = inputs, .inputs = inputs,
.outputs = outputs, .outputs = outputs,
@ -746,6 +768,7 @@ AVFilter ff_af_adeclip = {
.priv_size = sizeof(AudioDeclickContext), .priv_size = sizeof(AudioDeclickContext),
.priv_class = &adeclip_class, .priv_class = &adeclip_class,
.init = init, .init = init,
.activate = activate,
.uninit = uninit, .uninit = uninit,
.inputs = inputs, .inputs = inputs,
.outputs = outputs, .outputs = outputs,