From patchwork Mon Sep 13 23:23:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30232 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp4466596iov; Mon, 13 Sep 2021 16:24:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytaECEWtubocz9oxbW5AtiYY8a9RfMwtPTshDRp7vnxF39FUB37gKvVpi8hOnrc/lGuTOS X-Received: by 2002:a17:906:16d4:: with SMTP id t20mr3952445ejd.482.1631575476008; Mon, 13 Sep 2021 16:24:36 -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 mq9si8696727ejc.683.2021.09.13.16.24.31; Mon, 13 Sep 2021 16:24:36 -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=kqgFC2GC; 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 CBB7B68AEC8; Tue, 14 Sep 2021 02:24:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-oln040092071014.outbound.protection.outlook.com [40.92.71.14]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BA22B68AAFE for ; Tue, 14 Sep 2021 02:24:10 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MNoCcZVFFkamBLPb4QPIanwnJFvXIEBMW2CjWfKi1n5eFRt7qt6/I1NmKv2uzXG/4QA95DYY6cCWUpFsVg4TSgOpzfWPZ2VtA3SsNq+xflTrgTH3ANMlsGchsbkh5uakFWOhF+sLZQNNKBseHc376TqhaVDJut3adIYTFfyUIr7aol99DQ3foyJTj+XlKdr0Y8LFv01qdyMG/gPT7YonN4Sr47Gx6oGfgrDEp9e0aXZintATVvR4rrU53uhZ8MvvGLIsXxkoRxDz8hYN2xHCFc95zQ0zGvnvsDCFPuBfjsxbW/yHt+BesbMV9CwZoalV9qfOchKo1zVaz/nHXG9AAw== 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=HlmwhWBBI4g2otoLu+McLcp71qGIR8imQusJfGJntFU=; b=ixR5wTllM8JKH7irh45ZpHdrkoVCA8/7P85JaF/dmZ8ytLT4l9w00kouPhlmX1jxmcwBdAJHXoaNG6eChv8WgGxkw4Ry5EbhhFAtOoEQ0SzWWrYf+ICikSF4fGeopAsoJv1pqGPCmG549VYpzlFScovI0iv5IqUj/HRjR0jvGUDK9C5zCSaU5/X6gN8BUHteRPCjfFEWBNyygmhW514NvR2B6LmdYigu/n2bkIqE3i2FCpyyYlNSBVLa0h5dS1GmMPR8Kg6/K0pRci3Q7P9tLUQDJLZfljIZLgjl/rJfY6NFqRRdn710PLiCvD8u5ZEgqHyYG54xIwiFTJHlbPwedw== 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=HlmwhWBBI4g2otoLu+McLcp71qGIR8imQusJfGJntFU=; b=kqgFC2GCZeYc1xlBNcj1rNcxtrDzY26njgHejTg0YCdp9/36o7E3cnMxh2lj3SxacpGR+ZbKR4Bc+FwFDm8Er59AF2n6EeMGk9SY4hoZgHVED6KP/xmgrrNkYwfF5z6Ymwb8vuXF9FZZsTas9XBh1/HUuJNQ0x6vfctG281JAkQZHv18xyARfz2TjEF/uqrBrlmOGnEU4DYqbhbA0IREUL3SY5DzSB3Z/avWM+JM3jNWRvgLcr8RMVnYYJ6GPWsaRX7C+8m9HbksTwjD3TaYf5loUJKvW8q6n4mHkA6f87Od8n+pZKNctavpHY0LqvKoEpb/Z86ZhV57wmQGXkZIzw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB4216.eurprd03.prod.outlook.com (2603:10a6:20b:d::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.18; Mon, 13 Sep 2021 23:24:09 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::787b:2156:ca99:fe00]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::787b:2156:ca99:fe00%4]) with mapi id 15.20.4500.019; Mon, 13 Sep 2021 23:24:09 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 14 Sep 2021 01:23:30 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [tuyr+h3r0l53K2dWtLzpcuc8CIwNXUio] X-ClientProxiedBy: AM4P190CA0008.EURP190.PROD.OUTLOOK.COM (2603:10a6:200:56::18) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210913232339.3115725-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM4P190CA0008.EURP190.PROD.OUTLOOK.COM (2603:10a6:200:56::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 23:24:08 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3fe2e810-de89-4abb-7910-08d9770d9632 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNXSr2fKdz7sYt6AgME9bwCs/KSzd5g3dswfpeFttlBxAlefOKWyAvZpQuvK/3iVI38ORcJxlW+siA/lSQXh5BcZoiiRWS9A4+N68yWusdb9WFKCvvkDQVgAh++aqMgul1OCUrfuHwNqVN+kAsZ5qg1OTqItgCDTqoJ1aYcgeQ8d7aAFB29AlaVIV1ATTrd1abHqLQaEJRuM2V1cHFHbckvRxJchEEd+uxPl225U7rA5txyghJF8Mm6iV93r7lmpCXXrPkPz1Un1vdLsOkDt6diT6gZtSjncNmj5RJ/PAuLfSe2DaeXkuGCuUlt3F0kFTUlQ1v+Lm0zvxZr9w58cf5gEjbjPXu2yUapXSWkA9SvSmyAX+k6ID9fFvTgltpi+Buj8MU/JmdANgCrIfNeZCM5ajKA8+2JyuxUAUsfHV1m0jbcJSHww9TdmQCLKYOU8xoq+IM9HeIH1/HyyTyoYBJD9YlF7wARXg2F/8T/2+kriS0xXBPzXkQ3IHaFF83L/pYqPgEYl/R5M6PbNB134XufRrjfQZ9Lp8AjUSGHgCnlATEK3P1psieW9DA7r9BzPgVGv5/ShDLKpMqP5vVTP3f+Kn81cLcvEN4FiHSXIzMma+9Z1Dn++1gofnZAix7oopBeFgeFTGL4bqrgxKn5Sg9UbNJXzSc4Vwcr06IpYCx5hw0yrx5e4LmxnVxb26YWynp8g8YknDv4Hd69WFbMXWw463GVIvgQr17U= X-MS-TrafficTypeDiagnostic: AM6PR03MB4216: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: N2Wfrpbk0AdVFvad6qevQvHHVrGURch1M2rtb9Dj/zu1bihnkEXr6B3rATB7cPCqhx9FpcRPvxaOFNwa/nZa5qX+EN+PY7qkr2NzdIf+UVoh2RUYFgoCXLhlACVG2bdqbIaY8CTjUtGSwLJ6rpZlF3fF/UnlEzFhR12FmRh88XBKKE6xFUyFFPavX5qSQJ4iqdyOwtopwaLxYM+tUmYlwmb/cxNNab42JNoLQmFh5DwfsRZyvdM4PRJihAPiUZGwU5RzCyUpSIzEnoqTOp9xY6h+4RFpv/TgSBgS35Hprq6vtZmK5/EjhrEhM9OTzNWeIh3Di366zmspnOJ1Qtd/a+CczNJCtTUzeh+8wWN/2Klu1b8TsyoaFc5XjqPgAERHxpHAAxIM2rdZg9w4/V8ZLAYsK71p4gUrHLe2Yw6egMCfQ4bzf2WxE6ppyuhYSKJ5 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kD66ehmuOElIBFoEfWjYssrRSYlyvO+Lx+D/2kXwP4/wnHNgfoiHlcD4wDO4lVUzaXqEiYFAzsi2qZPe5j+n8blY769O9jVarxVmm78Uo3lWk6iN0x/fPTE6wHLB+DeH4OjRhUfUGSStZ+6qEofsog== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3fe2e810-de89-4abb-7910-08d9770d9632 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 23:24:08.9608 (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: AM6PR03MB4216 Subject: [FFmpeg-devel] [PATCH v2 05/14] avfilter/af_aresample: Use preinit instead of init_dict 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: fPFrx4lut1kD By using preinit, the SwrContext already exists directly after allocating the filter, so that the filter's AVClass's child_next becomes usable for setting options with the AV_OPT_SEARCH_CHILDREN search flag. This means that it is no longer necessary to use the init_dict callback for this filter. Furthermore, the earlier code did not abide by the documentation of the init_dict callback at all: Instead of only returning the options that have not been recognized it always returned all options on any av_opt_set() error and errored out in this case; yet if the error was just caused by an unrecognized option, it should not error out at all and instead return said option. This behaviour has been inherited by avfilter_init_dict(), contradicting its documentation. This is also fixed by this commit. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_aresample.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c index e46369b98d..8e0eaee17b 100644 --- a/libavfilter/af_aresample.c +++ b/libavfilter/af_aresample.c @@ -43,31 +43,16 @@ typedef struct AResampleContext { int more_data; } AResampleContext; -static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts) +static av_cold int preinit(AVFilterContext *ctx) { AResampleContext *aresample = ctx->priv; - int ret = 0; aresample->next_pts = AV_NOPTS_VALUE; aresample->swr = swr_alloc(); - if (!aresample->swr) { - ret = AVERROR(ENOMEM); - goto end; - } - - if (opts) { - AVDictionaryEntry *e = NULL; + if (!aresample->swr) + return AVERROR(ENOMEM); - while ((e = av_dict_get(*opts, "", e, AV_DICT_IGNORE_SUFFIX))) { - if ((ret = av_opt_set(aresample->swr, e->key, e->value, 0)) < 0) - goto end; - } - av_dict_free(opts); - } - if (aresample->sample_rate_arg > 0) - av_opt_set_int(aresample->swr, "osr", aresample->sample_rate_arg, 0); -end: - return ret; + return 0; } static av_cold void uninit(AVFilterContext *ctx) @@ -90,6 +75,8 @@ static int query_formats(AVFilterContext *ctx) AVFilterChannelLayouts *in_layouts, *out_layouts; int ret; + if (aresample->sample_rate_arg > 0) + av_opt_set_int(aresample->swr, "osr", aresample->sample_rate_arg, 0); av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format); av_opt_get_int(aresample->swr, "osr", 0, &out_rate); av_opt_get_int(aresample->swr, "ocl", 0, &out_layout); @@ -343,7 +330,7 @@ static const AVFilterPad aresample_outputs[] = { const AVFilter ff_af_aresample = { .name = "aresample", .description = NULL_IF_CONFIG_SMALL("Resample audio data."), - .init_dict = init_dict, + .preinit = preinit, .uninit = uninit, .query_formats = query_formats, .priv_size = sizeof(AResampleContext),