From patchwork Sun Sep 30 16:19:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 10520 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:ab0:73d2:0:0:0:0:0 with SMTP id m18csp753128uaq; Sun, 30 Sep 2018 09:19:33 -0700 (PDT) X-Google-Smtp-Source: ACcGV61FTckLnm2MTGmu/ko1xYSCZJDuvqUrLrpXUK4oaAVyHYwtu3ZYH1V4lk1Pg7n/jlM8rWse X-Received: by 2002:a1c:c64c:: with SMTP id w73-v6mr6316595wmf.98.1538324373295; Sun, 30 Sep 2018 09:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538324373; cv=none; d=google.com; s=arc-20160816; b=L8uuXDGx2oI9QdEtuoR+WvNz1kqYpoIkaM2NaAdLCBFoPwlkypbWI1T8ReDb7adSsT zhRTDXXAEOaS3M4bDqMKRNMeENAcuGpAaMc8BisEAkM5eOgsi+le3xUibj/yqdLq+/Rc z1nl1fUm+n1gFx4qv4F2Slps9LKTZ/9CKDWt3v19SkPaFolHDBOKUfYeDUCFZkN/Qjga pU6zUPZxwnYpdHYxwV+/hoGEqwViogiwwFyBKyst8cxxAWxB//mCItUwjcdxBC7I/yjC RuHK/RD6cIKIzA0cVoxOhB6PiJtksArdy+3Gk6Kr2kgPz1nTqMnP0vAwd+aV8PBfHO1b zuFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=ZwsOx/HKmeXNfXw7CfqFnZDMWKvI3gqq+zfZ8sT108s=; b=ivSWwPbZl5zuqBjS54gLnfV0UiKJ+SvI5eoxWSSjRUsunjY2U5fyWU9EJzurhqpnX+ A2K3kywpubJn+vikCb4EK0bHMFFhpIgxr+2AvL5x2vSiQ/l/oGHFFMaOtScmnSqAnXFc QeTeAXKa3NS+PLGegp7O9E5NkbA3JudCCFMoIitQFEnvhq7PcrVpPABAiN/pg9ECoHmg 4Yk0gm/Bq0O4lIjxL+ymlEFcFZ6pPVPGykx25aGX3Z3CPvTTN7D7RauGHB6rRGRbRALX 0bvkv8XVj41yNq34Y5TvFuRJ5sJOC9koumw5ila6YhfQaQgaZC9GGLsWdobZEiBciTCQ CYkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h73-v6si5979726wmd.23.2018.09.30.09.19.32; Sun, 30 Sep 2018 09:19:33 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D1E7068A154; Sun, 30 Sep 2018 19:19:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F174368A107 for ; Sun, 30 Sep 2018 19:19:04 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 22745E1458; Sun, 30 Sep 2018 18:19:23 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gCXBg8CqAL1B; Sun, 30 Sep 2018 18:19:22 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id EB5DAE1444; Sun, 30 Sep 2018 18:19:21 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sun, 30 Sep 2018 18:19:13 +0200 Message-Id: <20180930161913.14006-1-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: References: Subject: [FFmpeg-devel] [PATCH] avfilter/f_cue: use internal fifo for queueing frames 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 Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- libavfilter/f_cue.c | 90 +++++++++++++++++++---------------------------------- 1 file changed, 32 insertions(+), 58 deletions(-) diff --git a/libavfilter/f_cue.c b/libavfilter/f_cue.c index 732b5e218a..b2fff050da 100644 --- a/libavfilter/f_cue.c +++ b/libavfilter/f_cue.c @@ -18,11 +18,13 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#define FF_INTERNAL_FIELDS 1 +#include "framequeue.h" + #include "libavutil/opt.h" #include "libavutil/time.h" #include "avfilter.h" #include "filters.h" -#include "framequeue.h" #include "internal.h" typedef struct CueContext { @@ -32,73 +34,49 @@ typedef struct CueContext { int64_t preroll; int64_t buffer; int status; - FFFrameQueue queue; } CueContext; -static av_cold int init(AVFilterContext *ctx) -{ - CueContext *s = ctx->priv; - ff_framequeue_init(&s->queue, &ctx->graph->internal->frame_queues); - return 0; -} - -static av_cold void uninit(AVFilterContext *ctx) -{ - CueContext *s = ctx->priv; - ff_framequeue_free(&s->queue); -} - static int activate(AVFilterContext *ctx) { AVFilterLink *inlink = ctx->inputs[0]; AVFilterLink *outlink = ctx->outputs[0]; CueContext *s = ctx->priv; - int64_t pts; - AVFrame *frame = NULL; FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); - if (s->status < 3 || s->status == 5) { - int ret = ff_inlink_consume_frame(inlink, &frame); - if (ret < 0) - return ret; - if (frame) - pts = av_rescale_q(frame->pts, inlink->time_base, AV_TIME_BASE_Q); - } + if (ff_framequeue_queued_frames(&inlink->fifo)) { + AVFrame *frame = ff_framequeue_peek(&inlink->fifo, 0); + int64_t pts = av_rescale_q(frame->pts, inlink->time_base, AV_TIME_BASE_Q); - if (!s->status && frame) { - s->first_pts = pts; - s->status++; - } - if (s->status == 1 && frame) { - if (pts - s->first_pts < s->preroll) - return ff_filter_frame(outlink, frame); - s->first_pts = pts; - s->status++; - } - if (s->status == 2 && frame) { - int ret = ff_framequeue_add(&s->queue, frame); - if (ret < 0) { - av_frame_free(&frame); - return ret; + if (!s->status) { + s->first_pts = pts; + s->status++; } - frame = NULL; - if (!(pts - s->first_pts < s->buffer && (av_gettime() - s->cue) < 0)) + if (s->status == 1) { + if (pts - s->first_pts < s->preroll) { + ff_inlink_consume_frame(inlink, &frame); + return ff_filter_frame(outlink, frame); + } + s->first_pts = pts; s->status++; + } + if (s->status == 2) { + frame = ff_framequeue_peek(&inlink->fifo, ff_framequeue_queued_frames(&inlink->fifo) - 1); + pts = av_rescale_q(frame->pts, inlink->time_base, AV_TIME_BASE_Q); + if (!(pts - s->first_pts < s->buffer && (av_gettime() - s->cue) < 0)) + s->status++; + } + if (s->status == 3) { + int64_t diff; + while ((diff = (av_gettime() - s->cue)) < 0) + av_usleep(av_clip(-diff / 2, 100, 1000000)); + s->status++; + } + if (s->status == 4) { + ff_inlink_consume_frame(inlink, &frame); + return ff_filter_frame(outlink, frame); + } } - if (s->status == 3) { - int64_t diff; - while ((diff = (av_gettime() - s->cue)) < 0) - av_usleep(av_clip(-diff / 2, 100, 1000000)); - s->status++; - } - if (s->status == 4) { - if (ff_framequeue_queued_frames(&s->queue)) - return ff_filter_frame(outlink, ff_framequeue_take(&s->queue)); - s->status++; - } - if (s->status == 5 && frame) - return ff_filter_frame(outlink, frame); FF_FILTER_FORWARD_STATUS(inlink, outlink); FF_FILTER_FORWARD_WANTED(outlink, inlink); @@ -140,8 +118,6 @@ AVFilter ff_vf_cue = { .description = NULL_IF_CONFIG_SMALL("Delay filtering to match a cue."), .priv_size = sizeof(CueContext), .priv_class = &cue_class, - .init = init, - .uninit = uninit, .inputs = cue_inputs, .outputs = cue_outputs, .activate = activate, @@ -173,8 +149,6 @@ AVFilter ff_af_acue = { .description = NULL_IF_CONFIG_SMALL("Delay filtering to match a cue."), .priv_size = sizeof(CueContext), .priv_class = &acue_class, - .init = init, - .uninit = uninit, .inputs = acue_inputs, .outputs = acue_outputs, .activate = activate,