From patchwork Tue Oct 1 10:54:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51963 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:cb8a:0:b0:48e:c0f8:d0de with SMTP id d10csp192079vqv; Tue, 1 Oct 2024 04:21:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWJAr1z+NSGvWW3FM6mowMGWF689GlthgsxUZaFHkxc/4kmEelwuHyoYKC15qyOTNca+ZvM8dsE5umURXpRLLWI@gmail.com X-Google-Smtp-Source: AGHT+IFb9rEZJm2/pdq8FQ5HDYD2VpOGN3CLeNVON2Tp8qG+vDsA6Gk1RjQxOASEdVrMN4fRwBRe X-Received: by 2002:a05:6402:2687:b0:5c3:cc7d:c29d with SMTP id 4fb4d7f45d1cf-5c8824d381cmr12584904a12.6.1727781674185; Tue, 01 Oct 2024 04:21:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727781674; cv=none; d=google.com; s=arc-20240605; b=jov95odpmukyNN0/Vr2zejODtMv/Tll4RzMCmfbxpgvdNvF8NHljRPxZ9WHoWaFNfN kzfOJI35/Lm1v6JpX5vBE/m6VC4Q9AxTTJYelnTMaBLiIc4ajJlulRWF0RZnmJ2mDriz YX6tml+iFTF6LHVTprVTeb6ium/bEl+Zw46oXZl+o5XkX6gPCx8/9eqLb/W+7v3HJXYh 9JLKia3OOlodNXKP4nUhw5856WR9aUw32KGjPcSLyUdrUuQt77ZL4F14IRQCFzl4Rszg kScq+Ppb4h1bPasDg6ZQhJRo2qzxLVb8PWCC7vs96L8WEbs5ECG1LuRqxJskkscdUvH1 actw== 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=VOe0kpjU1W+qxjsCD/KR/POpq0zGkxyygxAiBUJtO7I=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=MOWtVX24g0+Q4XONJEbrPHjv4iHjS2WHs8rBJRxAehuA853E2fGE1m2g6FFM71oniL tcCtkHvulA+BpUuhMF8PkWhmatHag3KVFWUp11Inw6Kmg3Afk67BdF8/VY9YYrxpt/a2 nYysMaHNA+zUgKvoVMzxX1nn5/MkP7awXpENNLU3W8gF2hTjsPCqooUu8VcIXsfzj3qC tq28BNwEnZhO6bTA0fHVxmcWmmnKhf1QHr0SCzed12MnCCVKa9LZp95IFJXm5K4wnfOv 8HRMPisfBBpJomZgXBt9QqT6U+DzlWTdfZ572CHrgBlhZIWb2nRP2Ybu+3GOuENEwQyd +/dw==; 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=jaVrMgju; 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 4fb4d7f45d1cf-5c8824a7144si7478284a12.593.2024.10.01.04.21.13; Tue, 01 Oct 2024 04:21:14 -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=jaVrMgju; 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 5585568DCC3; Tue, 1 Oct 2024 13:54:57 +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 888BE68DBEE for ; Tue, 1 Oct 2024 13:54:41 +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=jaVrMgju; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 6DAB44E27 for ; Tue, 1 Oct 2024 12:54:36 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id CP8Dg6or7C8L for ; Tue, 1 Oct 2024 12:54:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1727780073; bh=boHK35CVrAajXhMbNJO0R/6x/ckzy0bLcRbmIw/xSBo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jaVrMgju3mU0AXxUyo8nUa/hMaAXfG8bY41E1KJVeaq4auL/BAmxP2f04ZI0bT2sT our1ZQfLH7/5Y2/Gc6cDsPiR5WCpGrd8a1WrexlKkE0XP/jyxIxAcspAdRid7I1GP7 QHl1MMRiasSsv9WGVaVibGPT/D1z9jF61skJCe2XE1iSJRkzTPG0GBh5qvPPm6mjYa uN2XvrJ2LCcJ3ykQ4WfGiaT3Nn72m79/JSu2DfNznEvUq4cRtmDFPEMPXL3RtRCMVi JH2gEM9e69pC7DbyfEWWYchzO6h6CqcGEf980mjzSXO6oF2KPVOxFjIi+NScSX7Xzq lrADKde8jWEvA== 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 1C4264E2A for ; Tue, 1 Oct 2024 12:54:33 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C657B3A0F02 for ; Tue, 01 Oct 2024 12:54:25 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 1 Oct 2024 12:54:07 +0200 Message-ID: <20241001105421.28967-2-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241001105421.28967-1-anton@khirnov.net> References: <20241001105421.28967-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/16] lavfi/buffersink: move channel layout parsing to init 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: 9ODbwQKCi36d That is a more appropriate place for this, and will also be useful in future commits. --- libavfilter/buffersink.c | 75 ++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c index 95cb605712..0eded68b55 100644 --- a/libavfilter/buffersink.c +++ b/libavfilter/buffersink.c @@ -154,6 +154,7 @@ int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx, static av_cold int common_init(AVFilterContext *ctx) { BufferSinkContext *buf = ctx->priv; + int ret = 0; #if FF_API_BUFFERSINK_OPTS @@ -184,6 +185,44 @@ static av_cold int common_init(AVFilterContext *ctx) CHECK_LIST_SIZE(sample_fmts) CHECK_LIST_SIZE(sample_rates) + + if (buf->channel_layouts_str) { + const char *cur = buf->channel_layouts_str; + + if (buf->all_channel_counts) + av_log(ctx, AV_LOG_WARNING, + "Conflicting all_channel_counts and list in options\n"); + + while (cur) { + void *tmp; + char *next = strchr(cur, '|'); + if (next) + *next++ = 0; + + // +2 for the new element and terminator + tmp = av_realloc_array(buf->channel_layouts, buf->nb_channel_layouts + 2, + sizeof(*buf->channel_layouts)); + if (!tmp) + return AVERROR(ENOMEM); + + memset(&buf->channel_layouts[buf->nb_channel_layouts], 0, + sizeof(*buf->channel_layouts)); + buf->nb_channel_layouts++; + + ret = av_channel_layout_from_string(&buf->channel_layouts[buf->nb_channel_layouts - 1], cur); + if (ret < 0) { + av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: %s.\n", cur); + return ret; + } + if (ret < 0) + return ret; + + cur = next; + } + + if (buf->nb_channel_layouts) + buf->channel_layouts[buf->nb_channel_layouts] = (AVChannelLayout){ 0 }; + } } #undef CHECK_LIST_SIZE @@ -412,8 +451,6 @@ static int asink_query_formats(AVFilterContext *ctx) #if FF_API_BUFFERSINK_OPTS } else { AVFilterFormats *formats = NULL; - AVChannelLayout layout = { 0 }; - AVFilterChannelLayouts *layouts = NULL; unsigned i; if (buf->sample_fmts_size) { @@ -424,37 +461,9 @@ static int asink_query_formats(AVFilterContext *ctx) return ret; } - if (buf->channel_layouts_str || buf->all_channel_counts) { - if (buf->channel_layouts_str) { - const char *cur = buf->channel_layouts_str; - - while (cur) { - char *next = strchr(cur, '|'); - if (next) - *next++ = 0; - - ret = av_channel_layout_from_string(&layout, cur); - if (ret < 0) { - av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: %s.\n", cur); - return ret; - } - ret = ff_add_channel_layout(&layouts, &layout); - av_channel_layout_uninit(&layout); - if (ret < 0) - return ret; - - cur = next; - } - } - - if (buf->all_channel_counts) { - if (layouts) - av_log(ctx, AV_LOG_WARNING, - "Conflicting all_channel_counts and list in options\n"); - else if (!(layouts = ff_all_channel_counts())) - return AVERROR(ENOMEM); - } - if ((ret = ff_set_common_channel_layouts(ctx, layouts)) < 0) + if (buf->nb_channel_layouts) { + ret = ff_set_common_channel_layouts_from_list(ctx, buf->channel_layouts); + if (ret < 0) return ret; }