From patchwork Fri Feb 23 13:58:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46482 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:26a3:b0:19e:cdac:8cce with SMTP id h35csp994313pze; Fri, 23 Feb 2024 06:35:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUnlMotKBjFiZzsY3QGV3DlD70dQyL16ikTwseWZVWntzf6zW5Hc8zKrAr0TgKoL7vy20oCpiHsbVIBtJxV6ZmdJ9mvymWC75jhNA== X-Google-Smtp-Source: AGHT+IEAwYf3tBPHWWnGZCNvk+aN6v0gfP7IqkIXAoaRoLZkp3ri31uwGwl0PxyqCNaon51oj56U X-Received: by 2002:a17:906:3685:b0:a3e:58df:fb08 with SMTP id a5-20020a170906368500b00a3e58dffb08mr1384656ejc.44.1708698922287; Fri, 23 Feb 2024 06:35:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708698922; cv=none; d=google.com; s=arc-20160816; b=0N0f/WJO6MadyYAFe6j1c/RnutF9ufazuhmAZGPhd1HgEC1KHMFWnK4/t4F0Ctm+vq afThes17P1A0m6eRSVzbEpHn+Gpn0iBt+hyD0UyZbQjOQFHKfhLbyRbvnu89u8OP+KZT hSnc3hUKS33uhgyBvvsJOsGRoeOli2v83PZDmfS7Q5mnsmv/NjG99qCB2jMRMT+y5NiL ca+o0RwTGUWCBsy7JNZeoJJP7igtel0nv+LrdPjCwytAWNGoAhVTx3jK+GeG0tpJ98go yOOsV6UgLEZZ/dRu0lmnnnrucd8DKphVI/NFdFsS4jvESd3JGHdyWpUOzuV5c7+ZOSg/ 0oMQ== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=l1opcVAwHPCcsw15FmBUfPfv851OxpmMsf2ZCC3eUu8=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Tc0dyvt2HF9koyM+AhU0TQ6OHSTY1uv9JKAXimEgLNf6F1WcobctEqlx0/CVArJzj0 QOBjOUDhm5yUhRpWxRCHyQfskP87sluC3zJFpNZvMHm/bEpJVPNIvjmABGPHMIqNCrPH NkJ6H4K1uX7hNuOHsP4ouSyOGbLlrLDm1mhaGlpB6UGH7xfcNfcpuhiO4ZNovvDjIE34 l4Mjszsqa0xCZAscYH3hfx+6k9Np3zdH2vw6ZoACmR1nrq0r730xDTMUvs5jXh98c0Jq +sGu5Li1cR8tzHIG3QkZzMtBmkEbTYRv60MBTPq585Zbp7lGCA/P9s0F/Btkh2acz7U4 wG+g==; 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=MA9hgbXM; 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 y15-20020a170906070f00b00a3f033ce7e8si3456966ejb.243.2024.02.23.06.35.21; Fri, 23 Feb 2024 06:35:22 -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; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=MA9hgbXM; 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 A9EFF68CB35; Fri, 23 Feb 2024 16:32:04 +0200 (EET) 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 2C98F68C6BD for ; Fri, 23 Feb 2024 16:31:36 +0200 (EET) 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=MA9hgbXM; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id E6A60448A for ; Fri, 23 Feb 2024 15:31:35 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 9DSZgaFcC-QV for ; Fri, 23 Feb 2024 15:31:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1708698688; bh=BpOlG4dUyzGJgRKs4xVXDH4FEVrAo3LBvIIBANgY8zU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MA9hgbXMONB6iaXOfnk3VwkEaszOKmYqiKxgDckXskp7d7JfXTQKamHs2fYZ0MZtv 70YxJE285YBuD2sTr87KQnVf1kg/pBrSM8Z/K6KnxIa051N0ikM4QmEHSxa4oPtg69 uqPw4utvoeFSWweWi6Bs+GYu1yQVrRLeUJfQifuoKXg2v3p4ul2/rrQQQBmxBIaPyx aeHvEGDAUCgNrvPRyra0KbH+m2FlW7KXTlf+neo9gra6Zoi97T1CYefUiarKA+mNiO deCqkoouVb2f/6KVZ09JN3uIFMnZX0kIbwDS2KBb67bMAaoG9Fe+LrcyxmkqwRvRHx yzESfUgdBPFdA== 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 8A0924D46 for ; Fri, 23 Feb 2024 15:31:27 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 75A633A1B33 for ; Fri, 23 Feb 2024 15:31:22 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 23 Feb 2024 14:58:36 +0100 Message-ID: <20240223143115.16521-15-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240223143115.16521-1-anton@khirnov.net> References: <20240223143115.16521-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/38] lavu/opt: factor per-type dispatch out of av_opt_set() 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: WdpLmLi4AXw3 Will be useful in following commits. --- libavutil/opt.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/libavutil/opt.c b/libavutil/opt.c index 0ca6d4d555..ebc8063dc6 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -484,13 +484,11 @@ static int set_string_channel_layout(void *obj, const AVOption *o, return av_channel_layout_from_string(channel_layout, val); } -int av_opt_set(void *obj, const char *name, const char *val, int search_flags) +static int opt_set_elem(void *obj, void *target_obj, const AVOption *o, + const char *val, void *dst) { - int ret = 0; - void *dst, *target_obj; - const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); - if (!o || !target_obj) - return AVERROR_OPTION_NOT_FOUND; + int ret; + FF_DISABLE_DEPRECATION_WARNINGS if (!val && (o->type != AV_OPT_TYPE_STRING && o->type != AV_OPT_TYPE_PIXEL_FMT && o->type != AV_OPT_TYPE_SAMPLE_FMT && @@ -503,13 +501,6 @@ FF_DISABLE_DEPRECATION_WARNINGS return AVERROR(EINVAL); FF_ENABLE_DEPRECATION_WARNINGS - if (o->flags & AV_OPT_FLAG_READONLY) - return AVERROR(EINVAL); - - if (o->flags & AV_OPT_FLAG_DEPRECATED) - av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help); - - dst = ((uint8_t *)target_obj) + o->offset; switch (o->type) { case AV_OPT_TYPE_BOOL: return set_string_bool(obj, o, val, dst); @@ -589,6 +580,24 @@ FF_ENABLE_DEPRECATION_WARNINGS return AVERROR(EINVAL); } +int av_opt_set(void *obj, const char *name, const char *val, int search_flags) +{ + void *dst, *target_obj; + const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); + if (!o || !target_obj) + return AVERROR_OPTION_NOT_FOUND; + + if (o->flags & AV_OPT_FLAG_READONLY) + return AVERROR(EINVAL); + + if (o->flags & AV_OPT_FLAG_DEPRECATED) + av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help); + + dst = ((uint8_t *)target_obj) + o->offset; + + return opt_set_elem(obj, target_obj, o, val, dst); +} + #define OPT_EVAL_NUMBER(name, opttype, vartype) \ int av_opt_eval_ ## name(void *obj, const AVOption *o, \ const char *val, vartype *name ## _out) \