From patchwork Tue Nov 5 09:28:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 52605 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:288a:b0:48e:c0f8:d0de with SMTP id hy10csp341367vqb; Tue, 5 Nov 2024 01:28:58 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU2qJOQtQXFKJ8joWr9H1MVp1tAB26sBIHB/+KEk/gilm9rojkLc4Z2zvWr33wUQs8HFbYih9zMZaYOxQaF+WpZ@gmail.com X-Google-Smtp-Source: AGHT+IESMlVnXjstfeu7lDU/+g+nYjOBZHh0rXx43okVYzYaMcjubPUk78m6tmTKHevywAlFmcM3 X-Received: by 2002:a2e:a906:0:b0:2fb:51e0:953 with SMTP id 38308e7fff4ca-2fcbe0a5bc0mr50296611fa.12.1730798938460; Tue, 05 Nov 2024 01:28:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1730798938; cv=none; d=google.com; s=arc-20240605; b=cLjgByGVOaZHreXYCfRDZxbmYLgYMQN4b/y79GJkf24L7wMoQje6SEj71ubkvZwQ2B BnIs0WkFOanW2j/KmaCARBfDIRwg6R/ODF6Yvyf5njieEA2RLhgLzbTTQkJzjWiCMJ2Y uIL3gysmCDQM2s2srBVusf8eEhLAPoB57L1+EHqb+Q9TqEwGqlXRptrdBKI7PFd5qTgr rLDmsaqwHMCYNwsv5/OgzkXvkAjdm+UHrgi3v2m0bG1p358yNDXW4ylxiIxg6G9SzJyd jho1HftekWMpb5Rt/5LEBEthhTblqiswsKTtMfM2vrq4WADhI5O8/1eiv2tSn9uvupQx CNyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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:message-id:date:to:from :dkim-signature:delivered-to; bh=x6OH/RWUy3+kT1ndEIaC35GzU0/dAUjDgbd3rL2OX+s=; fh=9+5V1imiycJiT5azxiNRH94nOdHnEBV1p/NpmNUA0dg=; b=EPfg68yjUvRCh+2FxojYqZSOordZ43oycK6n9CewNm7ozGLBgnPkqUgqF8r0ifYI57 tdlhUIs/iChTXTS/obBJZrccZW7xNH1H9JIg8Z19dsaMW40qhKRdcc1wP2ayISFzKAp/ k7xXjBWY0caP6CuGwLu1AM8LIyiVlecaWRlxau8tjSgAAMWdzkHr5GOhWnhjdIE8a/fl uMCecID4h8dNlJwdJI76SqD92eS1r0voXwsiNszJUQDx/a+7WoFgp6yd0mQQnCaszJ0m SurV06EVBilQXK5V6++fGXAad6QlICAFLEZB1pQp81N4mrgCV4ELm/hq/Gn15xsZCq2K gL/Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=o5sibhP4; 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 2adb3069b0e04-53c7bdd04cesi4166129e87.388.2024.11.05.01.28.58; Tue, 05 Nov 2024 01:28:58 -0800 (PST) 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=@khirnov.net header.s=mail header.b=o5sibhP4; 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 B8F7668DD26; Tue, 5 Nov 2024 11:28:54 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E39DA68DB45 for ; Tue, 5 Nov 2024 11:28:47 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=o5sibhP4; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 1E04A4E27; Tue, 5 Nov 2024 10:28:47 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id lz1xcRPcoMOO; Tue, 5 Nov 2024 10:28:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1730798924; bh=vtEnbQqqsIlM8VvpBLv998FI1Eq45DYoueKgDMkoWmY=; h=From:To:Cc:Subject:Date:From; b=o5sibhP4Nv02FuBLw0CqLw+9EiIYytY2mqxsm+BkDxdJtd/16rdxntotJAGFJwUm+ 1MDbMt7oWyy9gOllVAXQI0wp2pAOwCYxh4ujNUiXgqjob06lv7WJy6Nzhk1fLcqV5G 6pHoh03lgnRPeBpM8RQNb2R7csCwKeQjrzz95A9kOafrCqa1mBYzFXlT19F1FaTv5l ikkMsn6WYQIDWgJZzFqckjWxrEyw9vmfraboNHpWQY+nt3b0kzGGxnjcOTdJcfprf0 MbNWQRUl2Msr8q95b2+O4ZTedy+fZL0kSkdp3rYwjl4Vn1HeGJis2sAf/OkDsxpHF5 zHn8oHCUYNikQ== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 2C069728; Tue, 5 Nov 2024 10:28:44 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C79673A01C1; Tue, 05 Nov 2024 10:28:37 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 5 Nov 2024 10:28:28 +0100 Message-ID: <20241105092828.21038-1-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavfi/vf_libplacebo: eliminate LibplaceboInput.link 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: llyyr Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: qAnTrrLqBT71 Setting it was broken in 8160178dfc0e6bdaacf80dec58e595a9d595eedc, since links are not yet set up during init. It is also redundant, as the struct also stores the input index. Reported-By: llyyr --- libavfilter/vf_libplacebo.c | 41 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 77219b830a..8f1787c123 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -143,7 +143,6 @@ typedef struct LibplaceboInput { pl_queue queue; enum pl_queue_status qstatus; struct pl_frame_mix mix; ///< temporary storage - AVFilterLink *link; AVFifo *out_pts; ///< timestamps of wanted output frames int64_t status_pts; int status; @@ -593,8 +592,7 @@ static void unlock_queue(void *priv, uint32_t qf, uint32_t qidx) } #endif -static int input_init(AVFilterContext *avctx, AVFilterLink *link, - LibplaceboInput *input, int idx) +static int input_init(AVFilterContext *avctx, LibplaceboInput *input, int idx) { LibplaceboContext *s = avctx->priv; @@ -603,7 +601,6 @@ static int input_init(AVFilterContext *avctx, AVFilterLink *link, return AVERROR(ENOMEM); input->queue = pl_queue_create(s->gpu); input->renderer = pl_renderer_create(s->log, s->gpu); - input->link = link; input->idx = idx; return 0; @@ -690,7 +687,7 @@ static int init_vulkan(AVFilterContext *avctx, const AVVulkanDeviceContext *hwct if (!s->inputs) return AVERROR(ENOMEM); for (int i = 0; i < s->nb_inputs; i++) - RET(input_init(avctx, avctx->inputs[i], &s->inputs[i], i)); + RET(input_init(avctx, &s->inputs[i], i)); /* fall through */ fail: @@ -756,6 +753,7 @@ static void update_crops(AVFilterContext *ctx, LibplaceboInput *in, { FilterLink *outl = ff_filter_link(ctx->outputs[0]); LibplaceboContext *s = ctx->priv; + const AVFilterLink *inlink = ctx->inputs[in->idx]; const AVFrame *ref = ref_frame(&in->mix); for (int i = 0; i < in->mix.num_frames; i++) { @@ -763,15 +761,15 @@ static void update_crops(AVFilterContext *ctx, LibplaceboInput *in, // own the entire pl_queue, and hence, the pointed-at frames. struct pl_frame *image = (struct pl_frame *) in->mix.frames[i]; const AVFrame *src = pl_get_mapped_avframe(image); - double image_pts = src->pts * av_q2d(in->link->time_base); + double image_pts = src->pts * av_q2d(inlink->time_base); /* Update dynamic variables */ s->var_values[VAR_IN_IDX] = s->var_values[VAR_IDX] = in->idx; - s->var_values[VAR_IN_W] = s->var_values[VAR_IW] = in->link->w; - s->var_values[VAR_IN_H] = s->var_values[VAR_IH] = in->link->h; - s->var_values[VAR_A] = (double) in->link->w / in->link->h; - s->var_values[VAR_SAR] = in->link->sample_aspect_ratio.num ? - av_q2d(in->link->sample_aspect_ratio) : 1.0; + s->var_values[VAR_IN_W] = s->var_values[VAR_IW] = inlink->w; + s->var_values[VAR_IN_H] = s->var_values[VAR_IH] = inlink->h; + s->var_values[VAR_A] = (double) inlink->w / inlink->h; + s->var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ? + av_q2d(inlink->sample_aspect_ratio) : 1.0; s->var_values[VAR_IN_T] = s->var_values[VAR_T] = image_pts; s->var_values[VAR_OUT_T] = s->var_values[VAR_OT] = target_pts; s->var_values[VAR_N] = outl->frame_count_out; @@ -809,7 +807,7 @@ static void update_crops(AVFilterContext *ctx, LibplaceboInput *in, target->crop.y1 = target->crop.y0 + s->var_values[VAR_POS_H]; if (s->normalize_sar) { float aspect = pl_rect2df_aspect(&image->crop); - aspect *= av_q2d(in->link->sample_aspect_ratio); + aspect *= av_q2d(inlink->sample_aspect_ratio); pl_rect2df_aspect_set(&target->crop, aspect, s->pad_crop_ratio); } } @@ -899,7 +897,7 @@ static int output_frame(AVFilterContext *ctx, int64_t pts) opts->params.blend_params = NULL; for (int i = 0; i < s->nb_inputs; i++) { LibplaceboInput *in = &s->inputs[i]; - FilterLink *il = ff_filter_link(in->link); + FilterLink *il = ff_filter_link(ctx->inputs[in->idx]); FilterLink *ol = ff_filter_link(outlink); int high_fps = av_cmp_q(il->frame_rate, ol->frame_rate) >= 0; if (in->qstatus != PL_QUEUE_OK) @@ -960,14 +958,15 @@ static int handle_input(AVFilterContext *ctx, LibplaceboInput *input) int ret, status; LibplaceboContext *s = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; + AVFilterLink *inlink = ctx->inputs[input->idx]; AVFrame *in; int64_t pts; - while ((ret = ff_inlink_consume_frame(input->link, &in)) > 0) { + while ((ret = ff_inlink_consume_frame(inlink, &in)) > 0) { in->opaque = s; pl_queue_push(input->queue, &(struct pl_source_frame) { - .pts = in->pts * av_q2d(input->link->time_base), - .duration = in->duration * av_q2d(input->link->time_base), + .pts = in->pts * av_q2d(inlink->time_base), + .duration = in->duration * av_q2d(inlink->time_base), .first_field = pl_field_from_avframe(in), .frame_data = in, .map = map_frame, @@ -977,7 +976,7 @@ static int handle_input(AVFilterContext *ctx, LibplaceboInput *input) if (!s->fps.num) { /* Internally queue an output frame for the same PTS */ - pts = av_rescale_q(in->pts, input->link->time_base, outlink->time_base); + pts = av_rescale_q(in->pts, inlink->time_base, outlink->time_base); av_fifo_write(input->out_pts, &pts, 1); } } @@ -985,8 +984,8 @@ static int handle_input(AVFilterContext *ctx, LibplaceboInput *input) if (ret < 0) return ret; - if (!input->status && ff_inlink_acknowledge_status(input->link, &status, &pts)) { - pts = av_rescale_q_rnd(pts, input->link->time_base, outlink->time_base, + if (!input->status && ff_inlink_acknowledge_status(inlink, &status, &pts)) { + pts = av_rescale_q_rnd(pts, inlink->time_base, outlink->time_base, AV_ROUND_UP); pl_queue_push(input->queue, NULL); /* Signal EOF to pl_queue */ input->status = status; @@ -1035,7 +1034,7 @@ static int libplacebo_activate(AVFilterContext *ctx) if (av_fifo_peek(in->out_pts, &pts, 1, 0) >= 0) { out_pts = FFMIN(out_pts, pts); } else if (!in->status) { - ff_inlink_request_frame(in->link); + ff_inlink_request_frame(ctx->inputs[in->idx]); retry = true; } } @@ -1061,7 +1060,7 @@ static int libplacebo_activate(AVFilterContext *ctx) switch (in->qstatus) { case PL_QUEUE_MORE: - ff_inlink_request_frame(in->link); + ff_inlink_request_frame(ctx->inputs[in->idx]); retry = true; break; case PL_QUEUE_OK: