[FFmpeg-devel] [PATCH 2/3] lavfi/sine: switch to activate.

Nicolas George george at nsup.org
Tue Jun 2 21:35:05 EEST 2020


Allow to set the EOF timestamp.

Signed-off-by: Nicolas George <george at nsup.org>
---
 libavfilter/asrc_sine.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/libavfilter/asrc_sine.c b/libavfilter/asrc_sine.c
index 8fff1dda8b..947bc9a288 100644
--- a/libavfilter/asrc_sine.c
+++ b/libavfilter/asrc_sine.c
@@ -26,6 +26,7 @@
 #include "libavutil/opt.h"
 #include "audio.h"
 #include "avfilter.h"
+#include "filters.h"
 #include "internal.h"
 #include "intsine.h"
 
@@ -171,9 +172,10 @@ static av_cold int config_props(AVFilterLink *outlink)
     return 0;
 }
 
-static int request_frame(AVFilterLink *outlink)
+static int activate(AVFilterContext *ctx)
 {
-    SineContext *sine = outlink->src->priv;
+    AVFilterLink *outlink = ctx->outputs[0];
+    SineContext *sine = ctx->priv;
     AVFrame *frame;
     double values[VAR_VARS_NB] = {
         [VAR_N]   = outlink->frame_count_in,
@@ -184,6 +186,8 @@ static int request_frame(AVFilterLink *outlink)
     int i, nb_samples = lrint(av_expr_eval(sine->samples_per_frame_expr, values, sine));
     int16_t *samples;
 
+    if (!ff_outlink_frame_wanted(outlink))
+        return FFERROR_NOT_READY;
     if (nb_samples <= 0) {
         av_log(sine, AV_LOG_WARNING, "nb samples expression evaluated to %d, "
                "defaulting to 1024\n", nb_samples);
@@ -193,8 +197,10 @@ static int request_frame(AVFilterLink *outlink)
     if (sine->duration) {
         nb_samples = FFMIN(nb_samples, sine->duration - sine->pts);
         av_assert1(nb_samples >= 0);
-        if (!nb_samples)
-            return AVERROR_EOF;
+        if (!nb_samples) {
+            ff_outlink_set_status(outlink, AVERROR_EOF, sine->pts);
+            return 0;
+        }
     }
     if (!(frame = ff_get_audio_buffer(outlink, nb_samples)))
         return AVERROR(ENOMEM);
@@ -220,7 +226,6 @@ static const AVFilterPad sine_outputs[] = {
     {
         .name          = "default",
         .type          = AVMEDIA_TYPE_AUDIO,
-        .request_frame = request_frame,
         .config_props  = config_props,
     },
     { NULL }
@@ -232,6 +237,7 @@ AVFilter ff_asrc_sine = {
     .query_formats = query_formats,
     .init          = init,
     .uninit        = uninit,
+    .activate      = activate,
     .priv_size     = sizeof(SineContext),
     .inputs        = NULL,
     .outputs       = sine_outputs,
-- 
2.26.2



More information about the ffmpeg-devel mailing list