From patchwork Sun Jun 18 11:17:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 42190 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:be15:b0:121:b37c:e101 with SMTP id ge21csp56722pzb; Sun, 18 Jun 2023 04:21:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6f4F80x94nGfAbHVP/Z2RWw16xfUb+dF/iTYKinQDOgHlSE0qa2gV9SWbD4bU3x9FiWvXi X-Received: by 2002:a17:907:7e95:b0:987:350e:7726 with SMTP id qb21-20020a1709077e9500b00987350e7726mr4399861ejc.34.1687087280179; Sun, 18 Jun 2023 04:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687087280; cv=none; d=google.com; s=arc-20160816; b=fVfoyVlSrwNyJ2FFW5nGIySUgi42Sk4SPjP3JhZkvXgrCBJ0X9UA8SmtQIaq9szCkW Ztibq6XVpda5I/lkSkLc9MVNDyb7zdfrbRv9T/bDvO3h8pjvuBQ9cQUyZ558JDx+pZ29 IfCiLXxm4eMom6YDxxnZv1A/x2D96Hrkx2xPZYvqK+8W+MsMT6GVRX0N/gjVg53wbZsI oiJAPlwfWtEFyfnfrFraLa2V56e6I6/D96/tTmDEmTG9TDepqNXDyKENy2GWPPuytOb3 wZRakO0g+KtcGV+xp+y4pBsElYC456aH2q+PI4/WHRKyDJ2zX5eIT8T2FkqecNzm1QMN PJXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=tzEqiH2emPq2Btg/JW2Dg4r1YVOpdbHRDJaI0fv8NJY=; b=jtUQF9+YmE/ihPYHXVfp1Sk6FYE9foGW3//Qz5/ZswSrdYP05yOMANbBVYxpY/0JCz 8Ec3px3bnhpTUl2d6PCXZ90KIYB+Il6rhklC1lN2oTLrTMQPjyBmSVq6ENAGrfUvzYK1 0TDXO6vue5X0qOEqdahPLqTDBykKVc6GtzyGs1sDhwK+cwRU23HZWHkXF+DQ3Nm7bqk9 DRtofUARzvxGcfw/U61APPWCwib2r4i/MkdaTwE5XDug3TlE2s0GU54Wv10kiEkj77dG P/7RKv+3pqTMoF8dZR5CqmEJXMcGgmNGCOwTYshQ7jefS0cJ//KcjzIQKnKW5kRCuWs/ UDZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=eNUoM77X; 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 j5-20020aa7de85000000b005184ac0d978si7462971edv.604.2023.06.18.04.21.19; Sun, 18 Jun 2023 04:21:20 -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; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=eNUoM77X; 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 BAA2168BF68; Sun, 18 Jun 2023 14:20:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F3AAD68BFA1 for ; Sun, 18 Jun 2023 14:20:15 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 102A64B7CA; Sun, 18 Jun 2023 13:20:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1687087212; bh=GeArb8zyDlWrbyV4ieIdPX6owzjNSaA3cH9Dq2yIhAI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eNUoM77XqlK5vm1+MuJ3kJhZzB9AiSm+x25j7qWcSlKViJMVsjMKJJJmXFqPiQMxI 4Qx0kX+24Tsm+u+mFT1w4w2CH8BDhotyZ8PRTSdOH6ru0ZV2SlcZgOqlCqHKjaQNvT jN0hA3009TJ9/sZxaYESoFTwXWWoaOBmDeCwx7VU= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Jun 2023 13:17:07 +0200 Message-ID: <20230618111955.40994-17-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230618111955.40994-2-ffmpeg@haasn.xyz> References: <20230618111955.40994-2-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 15/22] lavfi/vf_libplacebo: generalize frame update to multiple inputs X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: qgNgWLZol7N9 From: Niklas Haas In the event that some frame mixes are OK while others are not, the priority goes: 1. Errors in updating any frame -> return error 2. Any input incomplete -> request frames and return 3. Any inputs OK -> ignore EOF streams and render remaining inputs 4. No inputs OK -> set output to most recent status This logic ensures that we can continue rendering the remaining streams, no matter which streams reach their end of life, until we have no streams left at which point we forward the last EOF. --- libavfilter/vf_libplacebo.c | 52 ++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 753d6f3cc79..6399aae0c67 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -980,9 +980,8 @@ static void drain_input_pts(LibplaceboInput *in, int64_t until) static int libplacebo_activate(AVFilterContext *ctx) { - int ret, retry = 0; + int ret, ok = 0, retry = 0; LibplaceboContext *s = ctx->priv; - LibplaceboInput *in = &s->inputs[0]; AVFilterLink *outlink = ctx->outputs[0]; int64_t pts, out_pts; @@ -1014,26 +1013,43 @@ static int libplacebo_activate(AVFilterContext *ctx) return 0; } - if (s->status && out_pts >= s->status_pts) { - ff_outlink_set_status(outlink, s->status, s->status_pts); - return 0; - } + /* Update all input queues to the chosen out_pts */ + for (int i = 0; i < s->nb_inputs; i++) { + LibplaceboInput *in = &s->inputs[i]; + if (in->status && out_pts >= in->status_pts) { + in->qstatus = PL_QUEUE_EOF; + continue; + } - in->qstatus = pl_queue_update(in->queue, &in->mix, pl_queue_params( - .pts = out_pts * av_q2d(outlink->time_base), - .radius = pl_frame_mix_radius(&s->params), - .vsync_duration = av_q2d(av_inv_q(outlink->frame_rate)), - )); + in->qstatus = pl_queue_update(in->queue, &in->mix, pl_queue_params( + .pts = out_pts * av_q2d(outlink->time_base), + .radius = pl_frame_mix_radius(&s->params), + .vsync_duration = av_q2d(av_inv_q(outlink->frame_rate)), + )); + + switch (in->qstatus) { + case PL_QUEUE_MORE: + ff_inlink_request_frame(in->link); + retry = true; + break; + case PL_QUEUE_OK: + ok = true; + break; + case PL_QUEUE_ERR: + return AVERROR_EXTERNAL; + } + } - switch (in->qstatus) { - case PL_QUEUE_MORE: - ff_inlink_request_frame(in->link); + if (retry) { return 0; - case PL_QUEUE_OK: - drain_input_pts(in, out_pts); + } else if (ok) { + /* Got any valid frame mixes, drain PTS queue and render output */ + for (int i = 0; i < s->nb_inputs; i++) + drain_input_pts(&s->inputs[i], out_pts); return output_frame(ctx, out_pts); - case PL_QUEUE_ERR: - return AVERROR_EXTERNAL; + } else if (s->status) { + ff_outlink_set_status(outlink, s->status, s->status_pts); + return 0; } return AVERROR_BUG;