From patchwork Fri Jun 16 09:29:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 42138 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp1391173pzb; Fri, 16 Jun 2023 02:31:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7YlF12gpXRlcRgk6VoW99VUPOqmQ8n/caAU1e8XAkXVDRRx9/ZxWoNY3EM8kr9p12pTa6k X-Received: by 2002:a17:907:97c3:b0:96f:cb13:8715 with SMTP id js3-20020a17090797c300b0096fcb138715mr1200627ejc.69.1686907891902; Fri, 16 Jun 2023 02:31:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686907891; cv=none; d=google.com; s=arc-20160816; b=QpiJiCv2noHSWEqUkBgNieX+9NooZDXA92gNYS8dU2ASbppavYFc2/em2cpWDgKMXv Lyr5gRtLhMkAdQJX59KlIqM7X0HoiK7r+RjWzd4XjCvd12QcglKMKS/330pW6T+m5uh2 mPqdGebf/zI2br7pqFyrpKvOfFmDvsHc6UJWXAceHkHE5x3DUBKJh60rRZW40XVHPnWd DxTCuktaYH94LYTWtRNhOSQlTlSkhEWytHVnysL5DhGog8icPjA3jAB9PXOO0p4HslK6 cjNdThn34AT45jIEVBhxMBjT4ITq+mGKv2vE62yeIncGAynN7gsEUnSI2Cwoa38rjHPH G2aA== 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=UvXm6K/+WuCQR+AkM+E4QkILl231PlVhf3YlOjMCbfk=; b=krnqvaL5au2sTpnYmq7P6sbxOfPkQwHQ/vES5r2p/xB9azwEVpzqZq/pa6W3kZgN64 glbVHTDS3Or684nUXhjflsvbo72Y+UuWMX7+CyGOsuNEpQsrQBz7/SyAfTcSMxTgRKg1 cQiTHX7SeCekj9sWm8X4Z7ao5Nmca7PUAOOnqiwARWHstPSqu718xqeAUEsfk5blpqdG TCTi1tvwFwbs8fVZ9NBB3c3RRcJ3vnrjQPHSzD2h5G0OE26UoXwSKSXPmaKUTKRweXpq yZzkYeotMnPC6C5xu/ehdONA0qMSATj87KynTgDOHRZ2YwGz6TGhZyHl9PD4JSHHScz6 MgwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=vg1prxRA; 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 a7-20020a1709065f8700b0098285fc55e1si2383045eju.340.2023.06.16.02.31.29; Fri, 16 Jun 2023 02:31:31 -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=vg1prxRA; 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 6071368C5BF; Fri, 16 Jun 2023 12:30:33 +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 1E8EF68C5AA for ; Fri, 16 Jun 2023 12:30:28 +0300 (EEST) Received: from localhost (217-74-0-168.hsi.r-kom.net [217.74.0.168]) by haasn.dev (Postfix) with ESMTPSA id DB5E2424F2; Fri, 16 Jun 2023 11:30:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1686907827; bh=WVldC3ir5z3UuiDb7PsTINiO7z8QIpNqUdgiss9pUb4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vg1prxRADdlMhkgz9apoUBslqdUdUGIFTcf+kCro/yZO+IZp9QLulxn/227j4WP5J GtErHvIv26JgHx69cKq6I4cZVgZWWft0DXx0kj+9c8NAan99MiqN509B+mchOqAfyq P4fQGuX0lM5SQoSciTas/r0MzKsO+uEKKLfpSGfM= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Jun 2023 11:29:52 +0200 Message-ID: <20230616092959.5247-15-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230616092959.5247-1-ffmpeg@haasn.xyz> References: <20230616092959.5247-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 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: Hjp56+sGofMZ 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 896bdb4eb8..5af8167bb3 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -978,9 +978,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; @@ -1012,26 +1011,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;