From patchwork Mon Dec 2 16:40:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 16536 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 1EA9344A89F for ; Mon, 2 Dec 2019 18:41:06 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EF4F368AFF7; Mon, 2 Dec 2019 18:41:05 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D763D68AB43 for ; Mon, 2 Dec 2019 18:40:58 +0200 (EET) X-ENS-nef-client: 129.199.129.80 Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id xB2GewDD030693 for ; Mon, 2 Dec 2019 17:40:58 +0100 Received: by phare.normalesup.org (Postfix, from userid 1001) id 03706EB5B5; Mon, 2 Dec 2019 17:40:57 +0100 (CET) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Dec 2019 17:40:52 +0100 Message-Id: <20191202164056.15926-1-george@nsup.org> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Mon, 02 Dec 2019 17:40:58 +0100 (CET) Subject: [FFmpeg-devel] [PATCH 1/5] lavfi/buffersrc: remove fifo. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The frame is immediately pushed, the fifo has never more than one. Signed-off-by: Nicolas George --- libavfilter/buffersrc.c | 45 ++++++++++------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index bae7d86695..d0ddc6b950 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -25,9 +25,9 @@ #include +#include "libavutil/avassert.h" #include "libavutil/channel_layout.h" #include "libavutil/common.h" -#include "libavutil/fifo.h" #include "libavutil/frame.h" #include "libavutil/imgutils.h" #include "libavutil/internal.h" @@ -43,7 +43,7 @@ typedef struct BufferSourceContext { const AVClass *class; - AVFifoBuffer *fifo; + AVFrame *queued_frame; AVRational time_base; ///< time_base to set in the output link AVRational frame_rate; ///< frame_rate to set in the output link unsigned nb_failed_requests; @@ -228,11 +228,6 @@ static int av_buffersrc_add_frame_internal(AVFilterContext *ctx, } - if (!av_fifo_space(s->fifo) && - (ret = av_fifo_realloc2(s->fifo, av_fifo_size(s->fifo) + - sizeof(copy))) < 0) - return ret; - if (!(copy = av_frame_alloc())) return AVERROR(ENOMEM); @@ -246,15 +241,11 @@ static int av_buffersrc_add_frame_internal(AVFilterContext *ctx, } } - if ((ret = av_fifo_generic_write(s->fifo, ©, sizeof(copy), NULL)) < 0) { - if (refcounted) - av_frame_move_ref(frame, copy); - av_frame_free(©); - return ret; - } - + av_assert0(s->queued_frame == NULL); + s->queued_frame = copy; if ((ret = ctx->output_pads[0].request_frame(ctx->outputs[0])) < 0) return ret; + av_assert0(s->queued_frame == NULL); if ((flags & AV_BUFFERSRC_FLAG_PUSH)) { ret = push_frame(ctx->graph); @@ -284,9 +275,6 @@ static av_cold int init_video(AVFilterContext *ctx) return AVERROR(EINVAL); } - if (!(c->fifo = av_fifo_alloc(sizeof(AVFrame*)))) - return AVERROR(ENOMEM); - av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d pixfmt:%s tb:%d/%d fr:%d/%d sar:%d/%d sws_param:%s\n", c->w, c->h, av_get_pix_fmt_name(c->pix_fmt), c->time_base.num, c->time_base.den, c->frame_rate.num, c->frame_rate.den, @@ -367,9 +355,6 @@ static av_cold int init_audio(AVFilterContext *ctx) return AVERROR(EINVAL); } - if (!(s->fifo = av_fifo_alloc(sizeof(AVFrame*)))) - return AVERROR(ENOMEM); - if (!s->time_base.num) s->time_base = (AVRational){1, s->sample_rate}; @@ -384,13 +369,8 @@ static av_cold int init_audio(AVFilterContext *ctx) static av_cold void uninit(AVFilterContext *ctx) { BufferSourceContext *s = ctx->priv; - while (s->fifo && av_fifo_size(s->fifo)) { - AVFrame *frame; - av_fifo_generic_read(s->fifo, &frame, sizeof(frame), NULL); - av_frame_free(&frame); - } + av_assert0(s->queued_frame == NULL); av_buffer_unref(&s->hw_frames_ctx); - av_fifo_freep(&s->fifo); } static int query_formats(AVFilterContext *ctx) @@ -463,26 +443,23 @@ static int request_frame(AVFilterLink *link) AVFrame *frame; int ret; - if (!av_fifo_size(c->fifo)) { + if (!c->queued_frame) { if (c->eof) return AVERROR_EOF; c->nb_failed_requests++; return AVERROR(EAGAIN); } - av_fifo_generic_read(c->fifo, &frame, sizeof(frame), NULL); - + frame = c->queued_frame; + c->queued_frame = NULL; ret = ff_filter_frame(link, frame); - return ret; } static int poll_frame(AVFilterLink *link) { BufferSourceContext *c = link->src->priv; - int size = av_fifo_size(c->fifo); - if (!size && c->eof) - return AVERROR_EOF; - return size/sizeof(AVFrame*); + av_assert0(c->queued_frame == NULL); + return c->eof ? AVERROR_EOF : 0; } static const AVFilterPad avfilter_vsrc_buffer_outputs[] = {