[FFmpeg-devel] [PATCH 4/4] lavfi: remove request_samples.

Nicolas George george at nsup.org
Wed Aug 12 20:25:58 EEST 2020


Filters can use min_samples/max_samples if the number is constant
or activate and ff_inlink_consume_samples().

Signed-off-by: Nicolas George <george at nsup.org>
---
 libavfilter/avfilter.h |  8 ----
 libavfilter/fifo.c     | 99 ++----------------------------------------
 2 files changed, 3 insertions(+), 104 deletions(-)

diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index fcab450f47..6acceb2a18 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -490,14 +490,6 @@ struct AVFilterLink {
     struct AVFilterChannelLayouts  *in_channel_layouts;
     struct AVFilterChannelLayouts *out_channel_layouts;
 
-    /**
-     * Audio only, the destination filter sets this to a non-zero value to
-     * request that buffers with the given number of samples should be sent to
-     * it.
-     * Last buffer before EOF will be padded with silence.
-     */
-    int request_samples;
-
     /** stage of the initialization of the link properties (dimensions, etc) */
     enum {
         AVLINK_UNINIT = 0,      ///< not started
diff --git a/libavfilter/fifo.c b/libavfilter/fifo.c
index f5587df62a..70f4876a50 100644
--- a/libavfilter/fifo.c
+++ b/libavfilter/fifo.c
@@ -143,112 +143,19 @@ static int calc_ptr_alignment(AVFrame *frame)
     return min_align;
 }
 
-static int return_audio_frame(AVFilterContext *ctx)
-{
-    AVFilterLink *link = ctx->outputs[0];
-    FifoContext *s = ctx->priv;
-    AVFrame *head = s->root.next ? s->root.next->frame : NULL;
-    AVFrame *out;
-    int ret;
-
-    /* if head is NULL then we're flushing the remaining samples in out */
-    if (!head && !s->out)
-        return AVERROR_EOF;
-
-    if (!s->out &&
-        head->nb_samples >= link->request_samples &&
-        calc_ptr_alignment(head) >= 32) {
-        if (head->nb_samples == link->request_samples) {
-            out = head;
-            queue_pop(s);
-        } else {
-            out = av_frame_clone(head);
-            if (!out)
-                return AVERROR(ENOMEM);
-
-            out->nb_samples = link->request_samples;
-            buffer_offset(link, head, link->request_samples);
-        }
-    } else {
-        int nb_channels = link->channels;
-
-        if (!s->out) {
-            s->out = ff_get_audio_buffer(link, link->request_samples);
-            if (!s->out)
-                return AVERROR(ENOMEM);
-
-            s->out->nb_samples = 0;
-            s->out->pts                   = head->pts;
-            s->allocated_samples          = link->request_samples;
-        } else if (link->request_samples != s->allocated_samples) {
-            av_log(ctx, AV_LOG_ERROR, "request_samples changed before the "
-                   "buffer was returned.\n");
-            return AVERROR(EINVAL);
-        }
-
-        while (s->out->nb_samples < s->allocated_samples) {
-            int len;
-
-            if (!s->root.next) {
-                ret = ff_request_frame(ctx->inputs[0]);
-                if (ret == AVERROR_EOF) {
-                    av_samples_set_silence(s->out->extended_data,
-                                           s->out->nb_samples,
-                                           s->allocated_samples -
-                                           s->out->nb_samples,
-                                           nb_channels, link->format);
-                    s->out->nb_samples = s->allocated_samples;
-                    break;
-                } else if (ret < 0)
-                    return ret;
-                if (!s->root.next)
-                    return 0;
-            }
-            head = s->root.next->frame;
-
-            len = FFMIN(s->allocated_samples - s->out->nb_samples,
-                        head->nb_samples);
-
-            av_samples_copy(s->out->extended_data, head->extended_data,
-                            s->out->nb_samples, 0, len, nb_channels,
-                            link->format);
-            s->out->nb_samples += len;
-
-            if (len == head->nb_samples) {
-                av_frame_free(&head);
-                queue_pop(s);
-            } else {
-                buffer_offset(link, head, len);
-            }
-        }
-        out = s->out;
-        s->out = NULL;
-    }
-    return ff_filter_frame(link, out);
-}
-
 static int request_frame(AVFilterLink *outlink)
 {
     FifoContext *s = outlink->src->priv;
     int ret = 0;
 
     if (!s->root.next) {
-        if ((ret = ff_request_frame(outlink->src->inputs[0])) < 0) {
-            if (ret == AVERROR_EOF && outlink->request_samples)
-                return return_audio_frame(outlink->src);
+        if ((ret = ff_request_frame(outlink->src->inputs[0])) < 0)
             return ret;
-        }
         if (!s->root.next)
             return 0;
     }
-
-    if (outlink->request_samples) {
-        return return_audio_frame(outlink->src);
-    } else {
-        ret = ff_filter_frame(outlink, s->root.next->frame);
-        queue_pop(s);
-    }
-
+    ret = ff_filter_frame(outlink, s->root.next->frame);
+    queue_pop(s);
     return ret;
 }
 
-- 
2.28.0



More information about the ffmpeg-devel mailing list