[FFmpeg-cvslog] avfilter/avf_showfreqs: switch to activate
Paul B Mahol
git at videolan.org
Sun May 26 18:14:51 EEST 2019
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun May 26 17:11:17 2019 +0200| [fc0de1c04be47ddb977eca449a3d62f3600466a4] | committer: Paul B Mahol
avfilter/avf_showfreqs: switch to activate
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fc0de1c04be47ddb977eca449a3d62f3600466a4
---
libavfilter/avf_showfreqs.c | 74 +++++++++++++++++++++++++++++----------------
1 file changed, 48 insertions(+), 26 deletions(-)
diff --git a/libavfilter/avf_showfreqs.c b/libavfilter/avf_showfreqs.c
index ff6a762547..e65aa60eec 100644
--- a/libavfilter/avf_showfreqs.c
+++ b/libavfilter/avf_showfreqs.c
@@ -30,6 +30,7 @@
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "audio.h"
+#include "filters.h"
#include "video.h"
#include "avfilter.h"
#include "internal.h"
@@ -439,45 +440,66 @@ static int plot_freqs(AVFilterLink *inlink, AVFrame *in)
return ff_filter_frame(outlink, out);
}
-static int filter_frame(AVFilterLink *inlink, AVFrame *in)
+static int filter_frame(AVFilterLink *inlink)
{
AVFilterContext *ctx = inlink->dst;
ShowFreqsContext *s = ctx->priv;
AVFrame *fin = NULL;
- int consumed = 0;
int ret = 0;
- if (s->pts == AV_NOPTS_VALUE)
- s->pts = in->pts - av_audio_fifo_size(s->fifo);
+ fin = ff_get_audio_buffer(inlink, s->win_size);
+ if (!fin) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
- av_audio_fifo_write(s->fifo, (void **)in->extended_data, in->nb_samples);
- while (av_audio_fifo_size(s->fifo) >= s->win_size) {
- fin = ff_get_audio_buffer(inlink, s->win_size);
- if (!fin) {
- ret = AVERROR(ENOMEM);
- goto fail;
- }
+ fin->pts = s->pts;
+ s->pts += s->hop_size;
+ ret = av_audio_fifo_peek(s->fifo, (void **)fin->extended_data, s->win_size);
+ if (ret < 0)
+ goto fail;
- fin->pts = s->pts + consumed;
- consumed += s->hop_size;
- ret = av_audio_fifo_peek(s->fifo, (void **)fin->extended_data, s->win_size);
- if (ret < 0)
- goto fail;
-
- ret = plot_freqs(inlink, fin);
- av_frame_free(&fin);
- av_audio_fifo_drain(s->fifo, s->hop_size);
- if (ret < 0)
- goto fail;
- }
+ ret = plot_freqs(inlink, fin);
+ av_frame_free(&fin);
+ av_audio_fifo_drain(s->fifo, s->hop_size);
fail:
- s->pts = AV_NOPTS_VALUE;
av_frame_free(&fin);
- av_frame_free(&in);
return ret;
}
+static int activate(AVFilterContext *ctx)
+{
+ AVFilterLink *inlink = ctx->inputs[0];
+ AVFilterLink *outlink = ctx->outputs[0];
+ ShowFreqsContext *s = ctx->priv;
+ AVFrame *in = NULL;
+ int ret = 0;
+
+ FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
+
+ if (av_audio_fifo_size(s->fifo) < s->win_size)
+ ret = ff_inlink_consume_samples(inlink, s->win_size, s->win_size, &in);
+ if (ret < 0)
+ return ret;
+ if (ret > 0) {
+ av_audio_fifo_write(s->fifo, (void **)in->extended_data, in->nb_samples);
+ if (s->pts == AV_NOPTS_VALUE)
+ s->pts = in->pts;
+ }
+
+ if (av_audio_fifo_size(s->fifo) >= s->win_size) {
+ ret = filter_frame(inlink);
+ if (ret <= 0)
+ return ret;
+ }
+
+ FF_FILTER_FORWARD_STATUS(inlink, outlink);
+ FF_FILTER_FORWARD_WANTED(outlink, inlink);
+
+ return FFERROR_NOT_READY;
+}
+
static av_cold void uninit(AVFilterContext *ctx)
{
ShowFreqsContext *s = ctx->priv;
@@ -500,7 +522,6 @@ static const AVFilterPad showfreqs_inputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_AUDIO,
- .filter_frame = filter_frame,
},
{ NULL }
};
@@ -521,6 +542,7 @@ AVFilter ff_avf_showfreqs = {
.uninit = uninit,
.query_formats = query_formats,
.priv_size = sizeof(ShowFreqsContext),
+ .activate = activate,
.inputs = showfreqs_inputs,
.outputs = showfreqs_outputs,
.priv_class = &showfreqs_class,
More information about the ffmpeg-cvslog
mailing list