From patchwork Fri Jan 20 19:31:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 40083 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp1432444pzj; Fri, 20 Jan 2023 11:33:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXtBuCZavxlP0otMS0508tyzdytm7u9506YPX1YZ2EbEKK6pQdFzm2chtYeqQVc7kXy1/92b X-Received: by 2002:a17:906:cd1f:b0:84d:4a2b:73b9 with SMTP id oz31-20020a170906cd1f00b0084d4a2b73b9mr17425151ejb.59.1674243187503; Fri, 20 Jan 2023 11:33:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674243187; cv=none; d=google.com; s=arc-20160816; b=bWqWUrhnl/Gwn/STe0DYI2S06bpvEJq28WNQm7mh2vQ3q2hoHbpgTcFrcKmXiCyPbw aUjvP9rNiTz219VMLe1mxIsGxbXo+H1qnF+xBVKV9SctRKUTE2sERkgjVf4WczkANXx+ bdgiQFziztu6Y6vf5WkBW0x1H2KNpjjt0SXOmzPRzIiGSArYRAnxjYy1QZw6PeeNWoaR z2su5iorAwAIjJPG5/sgNjGgSi8GFYtU6ultxKM/O/1SuWcCCqrS+9VrxC1305Lufg3+ slVMguWfKtgZKCvaJhUd1/kFrUbG7iIydZvGdiKwMqs5tmHDfsRSvBBYQ9VjjKfa1knn SXXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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:message-id:date:to:from :delivered-to; bh=hXx17WtzWTwc7jyO3KNR7Wkx6//uBcrsc4dbY1YpYWQ=; b=GJoSkt8S/CamB4jIb9lm9Dq0VqhP594lZakE/M3JYa+mhVob/10zDiv9Qqke73OfYF qfYmr34Ztk1hZjX3qx2RnzZ4XOWAFDBjMsqOwC3EZWrtRZlNzUJbuRu5+3s/BYNDaOcz S6UFPYAbVaolajANVXrFV56wgd5YC4FZRVa9dbHw2cjM2bvheQFlE3oOiS+YRHHYC0vC zFW2C9zombuZYixJmt5zxCLRCwiKhfNbMPX3yRvv4PAjpK8jLpcWQVpxaoIVtdEimifD Px2vsyaL2rWsfUdgrydRfPxuzCCbOMK4qASEWEYaXeL/iUR92MrCcREDcCXv5nhKCnFU uWvQ== ARC-Authentication-Results: i=1; mx.google.com; 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 t3-20020a170906948300b0087787ae09f5si3809898ejx.412.2023.01.20.11.32.51; Fri, 20 Jan 2023 11:33:07 -0800 (PST) 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; 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 DDE2568BD40; Fri, 20 Jan 2023 21:32:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0ECC968BCDC for ; Fri, 20 Jan 2023 21:32:00 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id C57322404F5 for ; Fri, 20 Jan 2023 20:31:59 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id tljhF59iUipt for ; Fri, 20 Jan 2023 20:31:59 +0100 (CET) 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 mail0.khirnov.net (Postfix) with ESMTPS id AD4F6240178 for ; Fri, 20 Jan 2023 20:31:56 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A404F3A0101 for ; Fri, 20 Jan 2023 20:31:48 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Jan 2023 20:31:28 +0100 Message-Id: <20230120193132.21597-1-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] lavfi/avfilter: export process_options() 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: NHEMfvN2TKU9 Also, replace an AVFilterContext argument with a logging context+private class, as those are the only things needed in this function. Will be useful in future commits. --- libavfilter/avfilter.c | 20 ++++++++++---------- libavfilter/internal.h | 13 +++++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index c2ecdffa6f..86b275dc4f 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -797,8 +797,8 @@ int ff_filter_get_nb_threads(AVFilterContext *ctx) return ctx->graph->nb_threads; } -static int process_options(AVFilterContext *ctx, AVDictionary **options, - const char *args) +int ff_filter_opt_parse(void *logctx, const AVClass *priv_class, + AVDictionary **options, const char *args) { const AVOption *o = NULL; int ret; @@ -812,8 +812,8 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options, while (*args) { const char *shorthand = NULL; - if (ctx->filter->priv_class) - o = av_opt_next(ctx->priv, o); + if (priv_class) + o = av_opt_next(&priv_class, o); if (o) { if (o->type == AV_OPT_TYPE_CONST || o->offset == offset) continue; @@ -826,9 +826,9 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options, &parsed_key, &value); if (ret < 0) { if (ret == AVERROR(EINVAL)) - av_log(ctx, AV_LOG_ERROR, "No option name near '%s'\n", args); + av_log(logctx, AV_LOG_ERROR, "No option name near '%s'\n", args); else - av_log(ctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", args, + av_log(logctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", args, av_err2str(ret)); return ret; } @@ -838,13 +838,13 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options, key = parsed_key; /* discard all remaining shorthand */ - if (ctx->filter->priv_class) - while ((o = av_opt_next(ctx->priv, o))); + if (priv_class) + while ((o = av_opt_next(&priv_class, o))); } else { key = shorthand; } - av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value); + av_log(logctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value); av_dict_set(options, key, value, AV_DICT_MULTIKEY); @@ -908,7 +908,7 @@ int avfilter_init_str(AVFilterContext *filter, const char *args) int ret = 0; if (args && *args) { - ret = process_options(filter, &options, args); + ret = ff_filter_opt_parse(filter, filter->filter->priv_class, &options, args); if (ret < 0) goto fail; } diff --git a/libavfilter/internal.h b/libavfilter/internal.h index aaf2c6c584..2ec41917f7 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -405,4 +405,17 @@ int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link, int default_pool_size); +/** + * Parse filter options into a dictionary. + * + * @param logctx context for logging + * @param priv_class a filter's private class for shorthand options or NULL + * @param options dictionary to store parsed options in + * @param args options string to parse + * + * @return a non-negative number on success, a negative error code on failure + */ +int ff_filter_opt_parse(void *logctx, const AVClass *priv_class, + AVDictionary **options, const char *args); + #endif /* AVFILTER_INTERNAL_H */