|
|
@ -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,68 +547,57 @@ 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; |
|
|
|
|
|
|
|
ThreadData td; |
|
|
|
|
|
|
|
|
|
|
|
if (s->pts == AV_NOPTS_VALUE) |
|
|
|
out = ff_get_audio_buffer(outlink, s->hop_size); |
|
|
|
s->pts = in->pts; |
|
|
|
if (!out) |
|
|
|
|
|
|
|
return AVERROR(ENOMEM); |
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out = ff_get_audio_buffer(outlink, s->hop_size); |
|
|
|
|
|
|
|
if (!out) |
|
|
|
|
|
|
|
return AVERROR(ENOMEM); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
if (ret < 0) |
|
|
|
if (ret < 0) |
|
|
|
goto fail; |
|
|
|
goto fail; |
|
|
|
|
|
|
|
|
|
|
|
for (ch = 0; ch < s->in->channels; ch++) { |
|
|
|
for (ch = 0; ch < s->in->channels; ch++) { |
|
|
|
double *is = (double *)s->is->extended_data[ch]; |
|
|
|
double *is = (double *)s->is->extended_data[ch]; |
|
|
|
|
|
|
|
|
|
|
|
for (j = 0; j < s->hop_size; j++) { |
|
|
|
for (j = 0; j < s->hop_size; j++) { |
|
|
|
if (is[j]) |
|
|
|
if (is[j]) |
|
|
|
detected_errors++; |
|
|
|
detected_errors++; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
av_audio_fifo_drain(s->fifo, s->hop_size); |
|
|
|
av_audio_fifo_drain(s->fifo, s->hop_size); |
|
|
|
|
|
|
|
|
|
|
|
if (s->samples_left > 0) |
|
|
|
if (s->samples_left > 0) |
|
|
|
out->nb_samples = FFMIN(s->hop_size, s->samples_left); |
|
|
|
out->nb_samples = FFMIN(s->hop_size, s->samples_left); |
|
|
|
|
|
|
|
|
|
|
|
out->pts = s->pts; |
|
|
|
out->pts = s->pts; |
|
|
|
s->pts += s->hop_size; |
|
|
|
s->pts += s->hop_size; |
|
|
|
|
|
|
|
|
|
|
|
s->detected_errors += detected_errors; |
|
|
|
s->detected_errors += detected_errors; |
|
|
|
s->nb_samples += out->nb_samples * inlink->channels; |
|
|
|
s->nb_samples += out->nb_samples * inlink->channels; |
|
|
|
|
|
|
|
|
|
|
|
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: |
|
|
@ -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) { |
|
|
|
ret = ff_inlink_consume_samples(inlink, s->window_size, s->window_size, &in); |
|
|
|
if (!s->samples_left) |
|
|
|
if (ret < 0) |
|
|
|
s->samples_left = av_audio_fifo_size(s->fifo) - s->overlap_skip; |
|
|
|
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 (s->samples_left > 0) { |
|
|
|
if (av_audio_fifo_size(s->fifo) >= s->window_size) { |
|
|
|
AVFrame *in = ff_get_audio_buffer(outlink, s->window_size - s->samples_left); |
|
|
|
ff_filter_set_ready(ctx, 100); |
|
|
|
if (!in) |
|
|
|
return 0; |
|
|
|
return AVERROR(ENOMEM); |
|
|
|
} |
|
|
|
ret = filter_frame(ctx->inputs[0], in); |
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ret; |
|
|
|
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, |
|
|
|