From patchwork Tue Sep 21 06:27:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30396 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp2136984iob; Mon, 20 Sep 2021 23:28:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAGhoHSDzJy54O+0Lb0BEkFrKPjeJArwCEKfWFzyCN0J8ZAJrGNDhx6tvi+cMz8s34T6D8 X-Received: by 2002:a50:d944:: with SMTP id u4mr21302503edj.327.1632205699973; Mon, 20 Sep 2021 23:28:19 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d19si19065145edn.202.2021.09.20.23.28.19; Mon, 20 Sep 2021 23:28:19 -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=@outlook.com header.s=selector1 header.b=K6fdysxu; arc=fail (body hash mismatch); 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6F8EC68AF98; Tue, 21 Sep 2021 09:28:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-oln040092075074.outbound.protection.outlook.com [40.92.75.74]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DD0A968ACAC for ; Tue, 21 Sep 2021 09:28:05 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kzNK5Nl+Tcr58+pYHsPdsjkC4V0slgUrt8OnEqDYu5bjLE17Z3ZQNKM5IjvIT4k79XTTUcFW/GUnPM8sc6gHr9QpHgVd3AW8VATKEBeBRwKgsrAIzbM9N71z+vqS55Dls1hPbLVtX2m91Mci3NjY9MyL9nnIiuywp9/EbRZdHWg0nBdimRiBDZ/B+qhj2D/hckgD9O0cykZrV1DGC2q6i/6Yu20coI/22POKqltDcwYpt00zgZ1bGWVr7438c4yavuWLtOHHv/Ha0MYEtsFGBoR4BnzAdvZpt1QJMRDaW3nupjNOYLnJCKQo349226T+DJ8+w3HAdbt9Gf5trpzHQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ay/c/DkuXZAHcg9dcFuD6QRkyKnweCRDztzylcNRnuQ=; b=ZnL4V4jF6qQA5vtwH+DsienawXDYMRy4QVosP9AZv2Cs2KW0OWK78JHn8N6IeJV7xocMEGVWqRoDLBOgoiDQLAAD1NLligvXkIoD4mikoRbfrDrNsribK5Eep+LTVsV7Jd1omJJUq9nT8dLBNIsfm3RT/v8JlwWGC8Zz8fqgHFwgUQH+gmZjRtVsJWPY/I21+kswSD8TEDLOlfwFS2abU/Kew3E67SaSAUbF8TbwhdFf8Akb9MOsYFYFbKVNatqiJ+DtlTA2ONTujF1dZn4kgiu2BUuA8kZDj7NOsDIaU0G53bh59p2mF9gaIiAOQLhIAFtghXjAk74oSGaZojaTFw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ay/c/DkuXZAHcg9dcFuD6QRkyKnweCRDztzylcNRnuQ=; b=K6fdysxu9EmGPfSbr9pJUVyQNUF+D/jg8rzTRFb3nwwt2Fs05dmszxXd8wQzUE4Ylo9EA05tAt033MB+BC0ZEJS4cD/nvPhWz9bU8KLjViWWYTxHWQkieGA777iQnL+1DXhB2XKoxa3+kuRYrKIQ1y2uIb55DmKCZDQ1nyK8UEJEnGS8V3PAeKvA36OYPRsmhoUBWblqwrrsPNjcxVCNgrpUZ2kYSWUtbIiWiIAOf8FYM8xNMd6En8uUwq0Zp6617gR3xdgGTmTAVmUeTdE5p5+GUufYUZrK/+yzPA3c2XTrCP+tUS1zle+s3S4Om6eraRtiMcxwkzQGm1TpeSJDag== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM7PR03MB6264.eurprd03.prod.outlook.com (2603:10a6:20b:13d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Tue, 21 Sep 2021 06:28:04 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::787b:2156:ca99:fe00]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::787b:2156:ca99:fe00%3]) with mapi id 15.20.4523.016; Tue, 21 Sep 2021 06:28:04 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Sep 2021 08:27:23 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [QgX5M0d0upA1lgN6W6SQIavMrqnWOf+G] X-ClientProxiedBy: PR0P264CA0075.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:18::15) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210921062746.3534685-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by PR0P264CA0075.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:18::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Tue, 21 Sep 2021 06:28:03 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 88dd02c9-972c-43ba-1c23-08d97cc8f7a7 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNUOze3FI6XN1geCeI3/T6dLlNbUSX1v3lGgyVp3PMdjyVM76F2XkHqKIOfO6NNs0vjbym3gAziY5Yuqo9b8mJVto7DlSmk/6lfV1NephyXCl6f60UF80UYqG1Jh27aCGIrZ4z5yO2CjWqhJMAptvEnfhybY8hUlZZeTB+C4zeHHkA+9t6rbHb0CgdH3EJfHzsXwalVt/hLZsIXgtT83uTOcZM5wmxvscceG0NeEgxOTRHpxG5W/e9YmDFo660bWvc5PP/l6hNRWeDFrezfkcWPbpYtq+9DUqQbcBgjmg7mDbMEc6V0DQnv+Z5BLg6PmrTnvEElUgGfhcb31D/+J/D8o6jVe62AXCzN1JhkjSZtgd6ESGPznpDqlVL0qa/m51QMkM5SdFg9uNiDNeEWYQ4v+cacgdBNPcQduG07kM9DEYIPvs+fPYy9sUQOeXSHIkKicBSs331331d2PYVGinm8W4AHiyUaDNve6va88e5uvY/MtPDy4wMhBUIIUsx7ctj6VOtSFIlEid/yN4WxH54FDhHGKxQ/46gKspXDuCZrXCiLvN+CXUQLVS1q3NTZMZF68cc2NVhg8iGAJ9OotCDVY0hXNticdvIvXf4KVmWc78ALgwuzdxKfyVAzv6hnereXqlnNhG3IHzW07VJHeQfQwRY+nH2A5ZyR/mhORo3KC15SlEaztFHkeDQqRjEJhi1qrW/t0BaDPHB35OBJcyDpaFu87wgMenV8= X-MS-TrafficTypeDiagnostic: AM7PR03MB6264: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wjQy/i4Z/E1776tTiAblSKLgY74awY3GNQB45gJ8xyHpS0y7WC6pmHGo3FnX88qCGMyThMJUNXkTQ8rAy4DNgSvPdlE9afgXSgmyoBXKCo4XAx/MAuyC3B34G/9yKSQh72qdsMjGJOOwih27uB106ySxk9XMVo4qEQothlF0/IDO3AGevgpt2H63tTaVC1u9qrjDlS4ojXIEDpfWaBJ7zjjj8+Pf57DByw/7VVAHewZpi8Wwb8wTWqwNQDbrhDLtT6xtJD1ujVdagbQSFY8ZLdGxG6TnHeK6lbTCic+tctRL4fz67ExvEQ0LF9Plrz+t9qJ7A8pKvQMp1P/ABwMf8Cwm8T1OecZ0b+njLAj9Q49VutIByU0aO+InzPpHK577zKQYkvpfM3x72jhdF+DvI5DNQU7mtVWexkIcYXw1Dnf8r4H9Y9K2hS8kIA0CyM4k X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9LjItkg5sas18H8fR66THgydzycXOcyqjPu7rPmKrhj2EqooEFlihXwjxrLsHYL4O47N8xliRHNcHDTnWHQTUH1JSleYbR4wBUgk0LUz5rP8jNwgmdjYciGiLEexxJ4Ht4t8fuTkgjMgM/xUc/nohQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 88dd02c9-972c-43ba-1c23-08d97cc8f7a7 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2021 06:28:04.1755 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR03MB6264 Subject: [FFmpeg-devel] [PATCH 03/26] avfilter/af_sidechaincompress: Honour query_formats API, fix segfault 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Y7SJVstAC6TR Just like the sidechaingate filter, the sidechaincompress filter overwrote the channel layout and channel count of its output in its config_output callback to match the channel layout of its main input instead of linking the main input and its output together in its query_formats callback. This is an API violation that can lead to segfaults, as in the following filtergraph, where stereotools rightly expects stereo, yet receives only mono: [in]aformat=channel_layouts=mono,aformat=channel_layouts=stereo|mono[out];\ [out][in2]sidechaincompress,stereotools Fix this by linking the channel layouts of the main input and the output in query_formats and remove the code overwriting it in config_output. Signed-off-by: Andreas Rheinhardt --- Will deduplicate af_agate.c and af_sidechaincompress.c later. libavfilter/af_sidechaincompress.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/libavfilter/af_sidechaincompress.c b/libavfilter/af_sidechaincompress.c index 48d450fd50..af4a90ea09 100644 --- a/libavfilter/af_sidechaincompress.c +++ b/libavfilter/af_sidechaincompress.c @@ -298,29 +298,19 @@ static int activate(AVFilterContext *ctx) static int query_formats(AVFilterContext *ctx) { - AVFilterChannelLayouts *layouts = NULL; static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_NONE }; - int ret, i; - - if (!ctx->inputs[0]->incfg.channel_layouts || - !ctx->inputs[0]->incfg.channel_layouts->nb_channel_layouts) { - av_log(ctx, AV_LOG_WARNING, - "No channel layout for input 1\n"); - return AVERROR(EAGAIN); - } - - if ((ret = ff_add_channel_layout(&layouts, ctx->inputs[0]->incfg.channel_layouts->channel_layouts[0])) < 0 || - (ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0) + int ret = ff_channel_layouts_ref(ff_all_channel_counts(), + &ctx->inputs[1]->outcfg.channel_layouts); + if (ret < 0) return ret; - for (i = 0; i < 2; i++) { - layouts = ff_all_channel_counts(); - if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->outcfg.channel_layouts)) < 0) - return ret; - } + /* This will link the channel properties of the main input and the output; + * it won't touch the second input as its channel_layouts is already set. */ + if ((ret = ff_set_common_all_channel_counts(ctx)) < 0) + return ret; if ((ret = ff_set_common_formats_from_list(ctx, sample_fmts)) < 0) return ret; @@ -343,8 +333,6 @@ static int config_output(AVFilterLink *outlink) outlink->sample_rate = ctx->inputs[0]->sample_rate; outlink->time_base = ctx->inputs[0]->time_base; - outlink->channel_layout = ctx->inputs[0]->channel_layout; - outlink->channels = ctx->inputs[0]->channels; s->fifo[0] = av_audio_fifo_alloc(ctx->inputs[0]->format, ctx->inputs[0]->channels, 1024); s->fifo[1] = av_audio_fifo_alloc(ctx->inputs[1]->format, ctx->inputs[1]->channels, 1024);