From patchwork Wed Sep 15 17:22:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 30259 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp484837iov; Wed, 15 Sep 2021 10:23:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVq10Z2PMyQvrVfq4Ztrueq8VzZj+kzap+E08QMlm/mCM5fpMfOQsItDWRMOeae4Tk01OR X-Received: by 2002:a50:8e06:: with SMTP id 6mr1148170edw.107.1631726627037; Wed, 15 Sep 2021 10:23:47 -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 hr13si534263ejc.66.2021.09.15.10.23.46; Wed, 15 Sep 2021 10:23:47 -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="UnY/WNvD"; 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 D820168AFF5; Wed, 15 Sep 2021 20:23:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05olkn2078.outbound.protection.outlook.com [40.92.90.78]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6BD1768AFBF for ; Wed, 15 Sep 2021 20:23:28 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gO36BQt+e+fUwvnONEhpmv47Vk8MWhojlWCpn46XeEENhqt46IBAR1je3AbrDEGhP0i0Eolc9ZD1B5zZ8Ji6gV5SiGVUZlzAwsD7+724j0bHSszhBfNTqoISgZfCy7yqeFxdu1bCSloXx50OtnhOechLuDcyfbD5PSYCdOgOPwGhJMqVtiE2neSphnJaPte93e1vnZPJ1CXAQ44/MB7Yl1RcuQ87SUERdInohVG66ksNkPwH7HGyzi7FdtDksA+ewcmnkUhCPSG3suShJ43pjAvu0P+hWST/trlbQet0anykigeT3U3JHXQOXJF+NawAdjo7VVG4IBABXK4YrFypVg== 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=l0OmzlbYlSF3Gd0JhYsIa4FSedoiRBZOrtYAB8696kk=; b=Gn0y9VcSifLg8tjvf96hDnS+k6SqtTEz9AxYfWivv61zyGGCbA0sCjoPhdjVBA8cNLqG4/cSKMqHYA4fH1qEJBg1xuECSrDu7syqjUoWrZB7uN+S+kiTo6wii8fBj6PjOySUDy+IVSWWqJ6+QWa3ropYfxXfmj/7ZbjQzpw2/kl6I7Vz6CGG7JlUWQoqn/2cq2zlms/rxTJ+conM3/E9f9hJGvTFNx2HnrP872mXmhrwM6coJvA6xkLQjY+I8N7BFFfUjD9QDma53oE6VotTd6PSFoD/HMVPsUUJ86pHziZEzLVHY2+uLp0dTtbGRe4FLLzwdyjWGd2gvpVlKow33w== 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=l0OmzlbYlSF3Gd0JhYsIa4FSedoiRBZOrtYAB8696kk=; b=UnY/WNvDBi4xk1bWAkj4AQd31eYdLWSc4K/ykDhmCSU1d1WavRGIzVO1FLTGyYUPO1erpyiFL5Hf1sTQ7xN8AKqKmGc4VvV0Lm3PHvH//+Jc44rvZBd0Z4oHxCXlZ4PXRkBqVCDoPCpUim4OyRaL2XRavvc/iSTzoyW/UGQIzwl2k5Wq6/WJbcObioUiO2DCAuvddgBYp/2YNXFzs5BDOTZ9oZ7QnegQAnCYeqga7NviiF99/CTlSWmSoLfzSXGmLmWMq0Bdk+8GbwopGGl4vIrSJfegQa/H4Ed8XL7LW7i45yW29qEqTDQOrwmg81GZSUdX0KF6JkX8kTd1T9/ljg== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB3957.eurprd03.prod.outlook.com (2603:10a6:20b:15::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.16; Wed, 15 Sep 2021 17:23:26 +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; Wed, 15 Sep 2021 17:23:26 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 15 Sep 2021 19:22:57 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [RRtsSqKEsqg56IqXTp1BdRVKfvWsCE2P] X-ClientProxiedBy: AM0PR02CA0153.eurprd02.prod.outlook.com (2603:10a6:20b:28d::20) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210915172257.4090685-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by AM0PR02CA0153.eurprd02.prod.outlook.com (2603:10a6:20b:28d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Wed, 15 Sep 2021 17:23:25 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ade00ab2-2adf-407b-8c09-08d9786d86ed X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiSH+vJHojH/XUp/uqv+O9nEaubDNUIz7HXax7EzlzuJKzmYQpCO+h0KT77+C/krkF1rc0vMw8JxZrzTYP3eAXlyWE0t0fcxZUpfR0HS2mxpveaiyZBw1btFyKAZvy8H36rj0iHPM6UEHUyHhbgU9hph9IRdKhyVFga8mMnaCKPU/JNFS4vw9qAqLO6nHy7CM4phEDHNuZfjTKjq4elK7EsUejZQzN14/RAObVEtZIgZqJFgjycRs+3H4Shg1q+KOb9l7ZX0FEGHAj/0hZFOzxw+uOhRTuZve0m76RX8PILC/EQHxNPb5A4OscWTRa2Nr29WPravY5exLRD/aPDh2/+z7O9+SjUurvPgcJRYTwI2z3izFniDWFGyBPFZ2h5dtFFXJiR+agw3iSiVxXdVK9zFat4v2CtSoXVQF5/idHL5TUKoLw6QCK2IS4oAFyOHZ2e3uDA0x0I3dVKAZhTn2ViOrT5ulpghV4wkXQJCQzXM0CY5f3p3iDJwhA21B1k0wUrbQtJCzwZNngruXXm3Vt6z8P2ACjc5n5SGF1jENtFzIt13D0tzSd1wL1vVvMJr+y1kjnTLqrTLmJMMaJJdo6xZOAAtE8tCMqCyfIOzfBg5zLqn4Qbc2YYYbvETTS/H261zPyq/iaIu0IxL0pGxPzP4LGGlCZUT8ibWvH8m7NV/Dggf3Kk9ltgNalwiY7tRmeELb2oljC646qhpBzgYFvanZ8DTuJHEjQEDKJpbP8gVPVEQMoq2hI+5w+ABKWSlNsE= X-MS-TrafficTypeDiagnostic: AM6PR03MB3957: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xQOsQs6ziALY9Soz34C5/oU9hdfFztrc2yaiIEXCrtT+7bO/30Ts/ctqZtBAAKMEMBHK0BdgAoD106yrkTxHq1cSmyps+zBH4CSCpeqy9zx3kaaSqcZYOUEhmEvv5qL1KB+b5qUwk1DVdkf/qJND+idiGP3zwNhdj1Rs5skWTHj8im66MkqxjAR5n2sqd/w/lHFu6q/MbM1mWKkEUoJ0Jchu6X+R0iackQS78L+YhIxn6VmCFfDfdyBDGdxQMiag4hkBVMVRX3wqjDi6XDztRbZYnLVwW8VAwhnBhnOKQXUTollr1EIp4d+bObYaIm02IWCwSGfHSmoJEURE81l7ciW7VNcrLP3O6m4k624kHXTrN5BKpGVlOOPhoIf0CshSOF8JqByg33cz5OsarvAGW+L/W1ZP/x6OuUP7wl+Z6fNY1+kcWwBhwXWxJEnv2ON6 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: H6BnBQnLlTUQjnLgKtfZVKqdmiOUylv3KFcHiUon56D5Z4hnFvpBX2ILJpwy8xkMAIW2GsO51Xdlnbpp+Dh4yXHgz9PnqQpM1aoYJFKP6JOUHbnLCgqU9nhRBlhj/thbT47fuX0WIS3fMFQ7tuRsWQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ade00ab2-2adf-407b-8c09-08d9786d86ed X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2021 17:23:26.2319 (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: AM6PR03MB3957 Subject: [FFmpeg-devel] [PATCH 5/5] avfilter/avfilter: Apply options in one av_opt_set_dict2() call 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: 7g0ljpQQRy8d Up until now, avfilter_init_dict() first applied the generic options via av_opt_set_dict(), then set the filter-specific options via av_opt_set_dict2() applied to the private context with the AV_OPT_SEARCH_CHILDREN flag set (this ensures that e.g. framesync options are set, too). For filters with the init_dict callback the remaining options were passed to it. This has the downside that all non-generic options are copied to a new dictionary in the first av_opt_set_dict() which involves allocations. This commit changes this by using av_opt_set_dict2() on the AVFilterContext to set all options (except those for init_dict) in one step. In order to ensure that the generic options are still applied first, the new AV_OPT_SEARCH_CHILDREN_AFTER_ME flag is used. This also reverses the search order between the private context and its children (if any), but this is actually more logical (the child contexts are more generic, hence the more special private context options should take precedence) as well as irrelevant (there is some option duplication*, but all duplicated options are entirely equivalent). Notice that there is also no option collision between the generic option and any child option (i.e. one could have used AV_OPT_SEARCH_CHILDREN) as well, but there might be some day: E.g. both the AVFilterContext class as well as the swresample class have an option named "threads". If the scale filters would expose this class in their preinit callback, there would be a problem when using AV_OPT_SEARCH_CHILDREN. Finally, in case an error happens in the second step (e.g. due to an option being out-of-range) the name and address of the AVFilterContext instead of the private context are used. This allows the user to more easily map this error to the actual filter. *: Several overlay filters duplicate framesync options (to preserve the ability to set them via the shorthand notation). Signed-off-by: Andreas Rheinhardt --- libavfilter/avfilter.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index ce63b9762f..87e28a8024 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -897,9 +897,9 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options) { int ret = 0; - ret = av_opt_set_dict(ctx, options); + ret = av_opt_set_dict2(ctx, options, AV_OPT_SEARCH_CHILDREN_AFTER_ME); if (ret < 0) { - av_log(ctx, AV_LOG_ERROR, "Error applying generic filter options.\n"); + av_log(ctx, AV_LOG_ERROR, "Error applying filter options.\n"); return ret; } @@ -912,14 +912,6 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options) ctx->thread_type = 0; } - if (ctx->filter->priv_class) { - ret = av_opt_set_dict2(ctx->priv, options, AV_OPT_SEARCH_CHILDREN); - if (ret < 0) { - av_log(ctx, AV_LOG_ERROR, "Error applying options to the filter.\n"); - return ret; - } - } - if (ctx->filter->init) ret = ctx->filter->init(ctx); else if (ctx->filter->init_dict)