From patchwork Wed Sep 25 13:29:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51841 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:9548:0:b0:48e:c0f8:d0de with SMTP id t8csp466046vqk; Wed, 25 Sep 2024 06:29:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX6H0SO++wL7tKxHYLO80/miEfRLfpmd4Gl5jAEs5v62L1d6Bigzhi6upJaaXX2aR0XIIAzqhefelZBwJctPDzl@gmail.com X-Google-Smtp-Source: AGHT+IHanBHHFDdb1Lu6cWydMgxSS+Fbzp/12JO7Nukx9e/Gx/YAr/yYl0BXg61GZi5CWVla8x6C X-Received: by 2002:a2e:b893:0:b0:2f4:5d9:e8e3 with SMTP id 38308e7fff4ca-2f914bb8297mr17204751fa.7.1727270988899; Wed, 25 Sep 2024 06:29:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727270988; cv=none; d=google.com; s=arc-20240605; b=d1ynDx35rymXMVG8mhmVrnci8bmkurHwE9KEs/Gr/CUkd9sGxHEikyPfb7M5LgSRT2 hYlNZbrMU4dP0fzpOebVJkZ+zQfjKlKd7Kkk7InM2yOAuOubhIB9U+6TuSC9yVdakd8w V13H61llNBFhl0nbqbv+GCA4LcvMIT4WmW7bnH4T61VfVQ9m4vUpz3VLVlNfpwwjwkOY u4VxtDmeB22ssDNttWhIqD2OmpS/1rGslSAtv4NCZQGempuKSU0Jtd8n9Qj7UEOmmCZh xy6YXyWHGHnUzmOTF5Pu+GSvw2bjIHevZlhY001Vzs6zYySRI908VtiTZ2aJZSCU8lSa nGrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding: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=PE3DcP1Cfrx0Hhx8nu/gSpo202nJRU+47MeIWBcKuR0=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=BTaveut/iBpp2LFqi6bH22Q/B/XaJbM+EC/JdScldRwVYx6XYWhbs8hI3NY36SoSdv PlGKO6CPlCbpqeQJ2q2WA3YIS11dRh5ike9nf0IvDl/pS2Ov0QhMa6bEZ1IZtb4z/EtA cA1w76zGdOkAPLkm+EGFzvHujV8cbrmsdUb/BvL4E9dANWMzewhem0/L5nI6mek52p8t ueFBEMWSIVkqmPuxzhTeCUnQxMqMLlw/NunNAFWJAqMAOxdOgySMi/016JcyI3pyYhI0 2PAX0eGB6pnRBXkOuyq3G1hvqjYqNNxwEeKaj5edkBqJyLFmZ7xPuy+d/HMy9KEhcnIA OB+A==; 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=IOFcW8JU; 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 38308e7fff4ca-2f8d283b858si11166701fa.191.2024.09.25.06.29.48; Wed, 25 Sep 2024 06:29:48 -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=@khirnov.net header.s=mail header.b=IOFcW8JU; 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 25F7F68DB7A; Wed, 25 Sep 2024 16:29:35 +0300 (EEST) 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 D6FA868DA40 for ; Wed, 25 Sep 2024 16:29:26 +0300 (EEST) 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=IOFcW8JU; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 6ED6F4DE6 for ; Wed, 25 Sep 2024 15:29:26 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id y5J9wPTl8d9m for ; Wed, 25 Sep 2024 15:29:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727270964; bh=JDxxi1Du/3R+P2jiEGpqqFLz+rMv0xpUnoWReizbjwM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IOFcW8JUp1EsE7vgCcEzx04gpmT1ObHzWGdhGr8LUOTrVhOj9yPvKfFavtvdGZAU6 3k981LYVMRsnEo6kSgvb1U/CoquzXhZMn9oF7Y60hosdthSL453+eMwXxsjloLtDI+ GamGLHlOaBssrapCIXDTuRkSdIc73MfisyWYTsVMZSfECs5idS5W8IKuNll99OGiAK 4D3Y1xJlhIEdUvHbd6qUqXxRAIXnwv6ZLvlKBUhOJkwacJDg8kyPQj/ek+Bs6bsKIy B3gZ05fbkUdlbwH5zjKVYqzupmvhedmHXGHZirCVUpZFuBN4XMecyFs7M180Lloun/ UgLjXoWWOhz+Q== 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 DAF1F4E11 for ; Wed, 25 Sep 2024 15:29:24 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C09973A0F6F for ; Wed, 25 Sep 2024 15:29:24 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 25 Sep 2024 15:29:17 +0200 Message-ID: <20240925132921.11203-6-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240925132921.11203-1-anton@khirnov.net> References: <20240925132921.11203-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/10] lavfi/buffersink: allow av_buffersink_set_frame_size() to be called earlier 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: MgNNY4ghmNcj The function currently writes directly into the input link, which requires it to be called after the filter has been linked. However, the documentation does not mention this restriction and the natural place to call av_buffersink_set_frame_size() during the options-setting stage, that is before filter init (and so before the input link exists). --- libavfilter/buffersink.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index 5811720c61..af4dc38792 100644 --- a/libavfilter/buffersink.c +++ b/libavfilter/buffersink.c @@ -42,6 +42,7 @@ typedef struct BufferSinkContext { const AVClass *class; unsigned warning_limit; + unsigned frame_size; /* only used for video */ enum AVPixelFormat *pixel_fmts; ///< list of accepted pixel formats @@ -162,11 +163,25 @@ static int activate(AVFilterContext *ctx) return 0; } +static int config_input_audio(AVFilterLink *inlink) +{ + BufferSinkContext *buf = inlink->dst->priv; + FilterLink *l = ff_filter_link(inlink); + + l->min_samples = l->max_samples = buf->frame_size; + + return 0; +} + void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size) { - FilterLink *inlink = ff_filter_link(ctx->inputs[0]); + BufferSinkContext *buf = ctx->priv; + buf->frame_size = frame_size; - inlink->min_samples = inlink->max_samples = frame_size; + if (ctx->inputs && ctx->inputs[0]) { + FilterLink *l = ff_filter_link(ctx->inputs[0]); + l->min_samples = l->max_samples = buf->frame_size; + } } #define MAKE_AVFILTERLINK_ACCESSOR(type, field) \ @@ -368,6 +383,14 @@ const AVFilter ff_vsink_buffer = { FILTER_QUERY_FUNC(vsink_query_formats), }; +static const AVFilterPad inputs_audio[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_AUDIO, + .config_props = config_input_audio, + }, +}; + const AVFilter ff_asink_abuffer = { .name = "abuffersink", .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."), @@ -376,7 +399,7 @@ const AVFilter ff_asink_abuffer = { .init = common_init, .uninit = uninit, .activate = activate, - FILTER_INPUTS(ff_audio_default_filterpad), + FILTER_INPUTS(inputs_audio), .outputs = NULL, FILTER_QUERY_FUNC(asink_query_formats), };