From patchwork Sun Aug 18 11:26:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51066 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:b6ca:0:b0:48e:c0f8:d0de with SMTP id s10csp1374389vqj; Sun, 18 Aug 2024 04:27:42 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVQrOhHNQVH0DJrsJPp3L80ORTzHinzXIcbJfHufcGjUlm4Z+Ka5FRL4x6hnDosvYoFtLfSB28y32IaBqKEOiDoxQDB4nsXVq5GmQ== X-Google-Smtp-Source: AGHT+IEjHIxya6RQUvwit33Zi8MUTyukgVXMBtOe4o1jrZkzzURTgE/B9FAEDDxUTphPHSMvBJ5x X-Received: by 2002:a2e:be07:0:b0:2ee:5ed4:792f with SMTP id 38308e7fff4ca-2f3be571fecmr67545251fa.2.1723980462128; Sun, 18 Aug 2024 04:27:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723980462; cv=none; d=google.com; s=arc-20160816; b=uC45OUNTp+R3pLQZyLZpQziKA2VJdkxPV5zo4df4YqqmbKi9cPjvCZVtUI3MgpsN7f s/V5j2EPPRgyyNKu2C1EJkUxsGqhzsPvX6D1egyS7tIUkoED1LIaBjxC1kQ9fJ4OEhWi opQ8YPzxuV5xOomeAbnGGyxsfdosO9ZCWLD4q4aTLptl/pnCUpcwfBS1XnVdG0t4FR9I I9tYdqeaZ9/C0Gnu10ei2v+uUMffT3WazSeB9FBdCWxI16unzjTCYiXQCgUOdkcp+738 Mc3w4xqa9Vz7BmUTCEMIcIgpr5NweMnO/9z4kFAu2ECVpXYQU3tQIsKNHOecUOFll+r7 zMTQ== 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 :dkim-signature:delivered-to; bh=c336vOZ1WTL15llXOSEdAvFzN/GXolgFSL9M5ZTgmfE=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=KgxIqAl8y2zN01yq0zPNY/14qY9kcPZsS0HNBbTJMMdWED86/6H2PInJb1FQ0UT1Zw /LyY8AeuHf4vuLxZIzwZF49MWl+kbyNIVQzkCgZLTX72zShOjHKDjpHhVq5e7QdOa+uR kbKAYDPVnfJCwSjKZr/2cor1ZuUGKPfA/WmKQ9bfDuTx1I9Y0cgJqa5cqHeBOowV6Hnc ObEBJPyeDttngspa4wGFOL8oF/JhmWgkw2BUo1MNWlVCEq75vK2iEdUU0utod3gWLqfq S+Zsa+W14pX4ZbsjgD7cyNCBXgSC0RkdsROY4tUISSrb6rz5l3hEAZCUwWOr88wBnbp6 sbcQ==; 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=gg0wB9qL; 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 38308e7fff4ca-2f3b745e438si20045431fa.46.2024.08.18.04.27.41; Sun, 18 Aug 2024 04:27:42 -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=@khirnov.net header.s=mail header.b=gg0wB9qL; 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 548DE68DDB9; Sun, 18 Aug 2024 14:27:27 +0300 (EEST) 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 BE06968DD45 for ; Sun, 18 Aug 2024 14:27:18 +0300 (EEST) 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=gg0wB9qL; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 1EB82EFE for ; Sun, 18 Aug 2024 13:27:18 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id t8LEdBB46-se for ; Sun, 18 Aug 2024 13:27:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1723980436; bh=Ekc2FANT4V72NA28kDsTD5iv985YE2Hllvh53MQ4NBs=; h=From:To:Subject:Date:From; b=gg0wB9qL0EgTAYW0dQPj2ib7fVUwD2YqfUPEBDNRiSpfM7uwyEb+Ad6+aADnmbxtR 3fE9KDF9u8rUMzHAGBRaEB+BOhC38qa5sgJFkBJ5lqwk1iBQeUWv0rZQc7yjZ6OfkU 5rv7QmDDcqtatc5eOJl5bnJKzV70+eZks3C931ei/oi70efi2zJEey3YZOmfQTxdZY u8lK4WM12MYDnf3bbiVRqhoIrg5fCcn4JJ2fTyqqufMR6O8wMpWDZ4CAzk8iwR7hAb oOdgPRbxIW9suIf+KOBmqmzx1TRRgNVUmYqd7JMiImikLswUA/Pu6CUXKFRFjP4GfY K/AA0k6JkYW1w== 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 8C2F84DEE for ; Sun, 18 Aug 2024 13:27:16 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 457A83A02CA for ; Sun, 18 Aug 2024 13:27:10 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Aug 2024 13:26:53 +0200 Message-ID: <20240818112655.18270-1-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] lavu/opt: document underlying C types for enum AVOptionType 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: MNBpeN9Y30HY --- libavutil/opt.h | 78 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/libavutil/opt.h b/libavutil/opt.h index 07e27a9208..23bc495158 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -240,26 +240,98 @@ * before the file is actually opened. */ +/** + * An option type determines: + * - for native access, the underlying C type of the field that an AVOption + * refers to; + * - for foreign access, the semantics of accessing the option through this API, + * e.g. which av_opt_get_*() and av_opt_set_*() functions can be called, or + * what format will av_opt_get()/av_opt_set() expect/produce. + */ enum AVOptionType{ + /** + * Underlying C type is unsigned int. + */ AV_OPT_TYPE_FLAGS = 1, + /** + * Underlying C type is int. + */ AV_OPT_TYPE_INT, + /** + * Underlying C type is int64_t. + */ AV_OPT_TYPE_INT64, + /** + * Underlying C type is double. + */ AV_OPT_TYPE_DOUBLE, + /** + * Underlying C type is float. + */ AV_OPT_TYPE_FLOAT, + /** + * Underlying C type is a uint8_t* that is either NULL or points to a C + * string allocated with the av_malloc() family of functions. + */ AV_OPT_TYPE_STRING, + /** + * Underlying C type is AVRational. + */ AV_OPT_TYPE_RATIONAL, - AV_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length + /** + * Underlying C type is a uint8_t* that is either NULL or points to an array + * allocated with the av_malloc() family of functions. The pointer is + * immediately followed by an int containing the array length in bytes. + */ + AV_OPT_TYPE_BINARY, + /** + * Underlying C type is AVDictionary*. + */ AV_OPT_TYPE_DICT, + /** + * Underlying C type is uint64_t. + */ AV_OPT_TYPE_UINT64, + /** + * Special option type for declaring named constants. Does not correspond to + * an actual field in the object, offset must be 0. + */ AV_OPT_TYPE_CONST, - AV_OPT_TYPE_IMAGE_SIZE, ///< offset must point to two consecutive ints + /** + * Underlying C type is two consecutive integers. + */ + AV_OPT_TYPE_IMAGE_SIZE, + /** + * Underlying C type is enum AVPixelFormat. + */ AV_OPT_TYPE_PIXEL_FMT, + /** + * Underlying C type is enum AVSampleFormat. + */ AV_OPT_TYPE_SAMPLE_FMT, - AV_OPT_TYPE_VIDEO_RATE, ///< offset must point to AVRational + /** + * Underlying C type is AVRational. + */ + AV_OPT_TYPE_VIDEO_RATE, + /** + * Underlying C type is int64_t. + */ AV_OPT_TYPE_DURATION, + /** + * Underlying C type is uint8_t[4]. + */ AV_OPT_TYPE_COLOR, + /** + * Underlying C type is int. + */ AV_OPT_TYPE_BOOL, + /** + * Underlying C type is AVChannelLayout. + */ AV_OPT_TYPE_CHLAYOUT, + /** + * Underlying C type is unsigned int. + */ AV_OPT_TYPE_UINT, /** From patchwork Sun Aug 18 11:26:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51069 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:b6ca:0:b0:48e:c0f8:d0de with SMTP id s10csp1394355vqj; Sun, 18 Aug 2024 05:21:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW9bFOO9Tw7TvL7q3bCH3OOK0U58tG5CTVHMo403hcsuI84x2TMXeoq+9TsFQRsbJ7yAbKmsqwA3jT7KsOxxQb0@gmail.com X-Google-Smtp-Source: AGHT+IH2xzGhYDbn/4DPSj00782TxCquFQMdGc7bJRenKey6oXHs7TrVjn2Ej8zqelfQNpBf9BlL X-Received: by 2002:a05:6512:ba5:b0:52f:c438:883c with SMTP id 2adb3069b0e04-5331c695a36mr3189484e87.1.1723983676925; Sun, 18 Aug 2024 05:21:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723983676; cv=none; d=google.com; s=arc-20160816; b=F/MCI0XHnkLLs1QIqCrJOekw34sHoMXopmnHyxpuFupXxu5qIGayO6KCGAzvIVIKUX 66wamHFnWaYu+CprA2pzDmlUddNVfQHywEdKTaXiUtBSC7FgICfL2IP001a+TMqUpMkQ tz0tieYTi8sc9cs5bUWNCuhK2HzGndWmliVNLgQ/Ru7ZhRl7+ptYWlN6QVOw0UCAtmXt OxierCxBiEgNMPOys1q3TioyMEXb5jn9QWx19gacAPcnFmh6Y67Ky4Mk2C+Je2Ow8RCd POwbe6gXJR1e1PmodQsUPPOIF+rYGMkxQvWbWTn3TI/hWfnewWrnrUENQ27SwDshS52u upsw== 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=P3Lu5ZbkZa3m+wQDEQIf12jfP275o1HnuQI1qUZz2ls=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=r4AJfMih8HiAWl9THFSc9xiORkHRWMinEH1jkmm2O52LTUB/ezJQsS4SLbMNXb5H6p tpEuzq3HHRVTDkIb67StjZvNnsGTcFquAqXNH/s47TnllICxYbmToh5tJxpCpjcCz0gI vWl7s2nvlR4XJH26AkRUwW/tTKrBdeOpSM7pwC5PwOEhL1RgTZaE1ntOpr1klxlByU6t msrWLEBWnNt4mYmKCOcpv6hj0ZN7OfIZHo4UK8uB9ZRUMJpsWtmwCaEVNjwO2iC6x3ZP hJjiYFthDhdbzAZZW9tiuvbIXUIwMVa0cxBNisi87w/v/mBFeeEJ+QCrHf6EZozDA7LR Wusw==; 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=ovbgCAoE; 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 2adb3069b0e04-5330d41df4asi2222661e87.441.2024.08.18.05.21.16; Sun, 18 Aug 2024 05:21:16 -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=@khirnov.net header.s=mail header.b=ovbgCAoE; 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 28B5C68DCBD; Sun, 18 Aug 2024 14:27:26 +0300 (EEST) 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 BBCF668DCBD for ; Sun, 18 Aug 2024 14:27:18 +0300 (EEST) 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=ovbgCAoE; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id AB8D74DF6 for ; Sun, 18 Aug 2024 13:27:17 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id HnMFP_UR9sGV for ; Sun, 18 Aug 2024 13:27:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1723980436; bh=yhtowpxZ66xhUEHvcA4s0RypkGOgTiSCsetJx+93u/w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ovbgCAoEFP4vym8uodgiWg9jlzZxnMrOi4tOG+YgHEnvhfZXHeoWQdJO62vQyWh4G JJAeDCSzHIk8+0iSBizDyIGkQFN0BiUZDlVDozId7FfIfX+6Tbj2JXX8OpBAi5+5PX C18NlOITMxfxERcEI/dHHMX4Ru/LLZDPYirMYTsss2J6hlvWVLk18zA8Fm+bYS3IkB wV5tor9GS2gg45/v2Dpkjex8/6G11hJt27GvLp7Iu6bIJ3aRxWYrJra4AoVXdONewK Lt/xiFHyq5CRY0AmR43toeototV3hymjXWK8GDeQVA9xQmPQudlw4x30L8u4iChGIK xRpMGl9O4zEtA== 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 8AF04EFE for ; Sun, 18 Aug 2024 13:27:16 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 50BCF3A1676 for ; Sun, 18 Aug 2024 13:27:10 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Aug 2024 13:26:54 +0200 Message-ID: <20240818112655.18270-2-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240818112655.18270-1-anton@khirnov.net> References: <20240818112655.18270-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] lavu/opt: forward av_opt_get_video_rate() to av_opt_get_q() 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: omUkwSQ+X0TS The two functions are exactly the same. --- libavutil/opt.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/libavutil/opt.c b/libavutil/opt.c index 32a9e059e3..2cfc2d9c5a 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -1277,18 +1277,7 @@ int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_ int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val) { - int64_t intnum = 1; - double num = 1; - int ret, den = 1; - - if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0) - return ret; - - if (num == 1.0 && (int)intnum == intnum) - *out_val = (AVRational) { intnum, den }; - else - *out_val = av_d2q(num * intnum / den, 1 << 24); - return 0; + return av_opt_get_q(obj, name, search_flags, out_val); } static int get_format(void *obj, const char *name, int search_flags, int *out_fmt, From patchwork Sun Aug 18 11:26:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51067 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:b6ca:0:b0:48e:c0f8:d0de with SMTP id s10csp1374430vqj; Sun, 18 Aug 2024 04:27:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVVhPEdEVxzlq6kLFFA3dUozfVZH2xNWKE1SrVkrwJ7QVlnDAUNGXn0xP8CYAUXfQtpRSKJf7wpxd3gVBYUB8wt/ylGmtPmWCWFrw== X-Google-Smtp-Source: AGHT+IGOPizM/kEU7nydfOGMlyN3Ab7wVVPPWeJihNJMSwpprw+/BDb40uklzpkEaPLJcxO4ZHkz X-Received: by 2002:a5d:6d0d:0:b0:367:9614:fdf7 with SMTP id ffacd0b85a97d-371942a2dabmr3229182f8f.0.1723980472142; Sun, 18 Aug 2024 04:27:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723980472; cv=none; d=google.com; s=arc-20160816; b=rggEUHGkFWkSskQ6Agsvkxbx6dDru6gvpM4gpekraQ/ea/xpzQs0lGB/aQ7hUGTh94 +vGBSvAQQlvERi+xQX1WadzLFvcNYm7x2evvEIh+eWweT3fE66q1XtFXMnLgtrdxUh6m rglBUS46S/Ry2rz+DNBbCW8SgNIRGvxneQkESecEZVckNn2d9mVzJkBN+jq5Dojp45rB 3y5iosCrTVK1THvt0uyVY+czBZlLQ2xoEFkdxFoHgpOe9kfiGa9HJLc0ZhOKcHsqLb11 YrxehDC6Q/e3pNzeRRVjlSUhgAAfjqdOUd1HCx1ByKAh2QJR3taXI7J5v4kiekxssxlb SKkw== 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=4mC6Aj6o8uVj34z8v+HH2qJKA13Lg6qAQBAIHX/qSqg=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=TmzmHiWjJdZjV7fIgGm0SNjDF3G3kUv2ARXFrSeQMO3qiouN3zrAinddIKkMLuMKVS I8OAKv+IiczFgmfJSBKA3YpRexls2ORHb9pSyWwFCANDkl1HfuYIqYDNXs89RDGKqejp Pg5J1U21sz/JOkeprxupxPvOIqxFma1L9U5qmcE4hIY1kccs+XLRB9xf1VVfNLzVYtQn dnUmJ9Q3fo5lZkKNulat0+l4ZbKNYbu8Cn6DduTwnS5Horb4finITgk0ZozpN5g+h3m1 tjiG81YeenfAPGbeso85Y2Sm05PmrtMoDO5IXNHPB/J/QP1q4g/xIrryzuOAvzFWCRI/ E9VQ==; 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=Vpu7VBtJ; 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 a640c23a62f3a-a838393bb54si429632266b.485.2024.08.18.04.27.51; Sun, 18 Aug 2024 04:27:52 -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=@khirnov.net header.s=mail header.b=Vpu7VBtJ; 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 42D7C68DDBF; Sun, 18 Aug 2024 14:27:28 +0300 (EEST) 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 2EDCB68DCBD for ; Sun, 18 Aug 2024 14:27:19 +0300 (EEST) 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=Vpu7VBtJ; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id C1A9A4DEE for ; Sun, 18 Aug 2024 13:27:18 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id Qbm5CiCbEJJ0 for ; Sun, 18 Aug 2024 13:27:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1723980436; bh=YJ9JKIZoh6jt53JZGQCnc4GVuIZJ1HMHVEddckeEzAk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Vpu7VBtJmV1H0k9O5YYB4ThQo9ZTP/xbTxtzAQ3D2K4tSCsnmcWqw0t7QCxG3NTN4 cy1mDlB1Tp22gmugqeYsPhx5RRX0Aq8CUn7ZMMmTHmDVj4jCrk+jr3J/ex4RRyt4Kv Gyo7s3Gr2WjXke+BjLA52n97LlRoR7UKNbW5P7/r3osxwRtbIysUdhxR/ucTQ9hjzG C/SgzbaKZSebmcpR/kcwLU1HTxQkgtj1Fkn3qUHHamoiBPEppx2EZQGp6CDRuPy38c 9u1lNY2jkyiz3Zuu2xhHqy9yN1GTFwAaQL632npCll6HNSB0cHRwfOv8tCbOkGvLHv /Viyv2KxH4Q5Q== 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 8E19E4DF1 for ; Sun, 18 Aug 2024 13:27:16 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 5C4C83A170F for ; Sun, 18 Aug 2024 13:27:10 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Aug 2024 13:26:55 +0200 Message-ID: <20240818112655.18270-3-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240818112655.18270-1-anton@khirnov.net> References: <20240818112655.18270-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] lavu/opt: add API for retrieving array-type option values 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: WtH4pAQ1eRAR Previously one could only convert the entire array to a string, not access individual elements. --- doc/APIchanges | 3 ++ libavutil/opt.c | 119 +++++++++++++++++++++++++++++++++++++++--- libavutil/opt.h | 40 ++++++++++++++ libavutil/tests/opt.c | 63 ++++++++++++++++++++++ libavutil/version.h | 2 +- tests/ref/fate/opt | 6 +++ 6 files changed, 226 insertions(+), 7 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 173f317ea1..e78aa6031d 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07 API changes, most recent first: +2024-08-xx - xxxxxxxxx - lavu 59.35.100 - opt.h + Add av_opt_get_array_size() and av_opt_get_array(). + 2024-08-10 - xxxxxxxxx - lavu 59.34.100 - hwcontext_vulkan.h Add qf and nb_qf to AVVulkanDeviceContext. Deprecate queue_family_index, nb_graphics_queues, diff --git a/libavutil/opt.c b/libavutil/opt.c index 2cfc2d9c5a..d515e20e97 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -121,9 +121,9 @@ static unsigned *opt_array_pcount(const void *parray) return (unsigned *)((const void * const *)parray + 1); } -static void opt_free_elem(const AVOption *o, void *ptr) +static void opt_free_elem(enum AVOptionType type, void *ptr) { - switch (TYPE_BASE(o->type)) { + switch (TYPE_BASE(type)) { case AV_OPT_TYPE_STRING: case AV_OPT_TYPE_BINARY: av_freep(ptr); @@ -145,7 +145,7 @@ static void opt_free_elem(const AVOption *o, void *ptr) static void opt_free_array(const AVOption *o, void *parray, unsigned *count) { for (unsigned i = 0; i < *count; i++) - opt_free_elem(o, opt_array_pelem(o, *(void **)parray, i)); + opt_free_elem(o->type, opt_array_pelem(o, *(void **)parray, i)); av_freep(parray); *count = 0; @@ -153,7 +153,7 @@ static void opt_free_array(const AVOption *o, void *parray, unsigned *count) static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum) { - switch (o->type) { + switch (TYPE_BASE(o->type)) { case AV_OPT_TYPE_FLAGS: *intnum = *(unsigned int*)dst; return 0; @@ -992,7 +992,7 @@ static void format_duration(char *buf, size_t size, int64_t d) } static int opt_get_elem(const AVOption *o, uint8_t **pbuf, size_t buf_len, - void *dst, int search_flags) + const void *dst, int search_flags) { int ret; @@ -1920,7 +1920,7 @@ void av_opt_free(void *obj) if (o->type & AV_OPT_TYPE_FLAG_ARRAY) opt_free_array(o, pitem, opt_array_pcount(pitem)); else - opt_free_elem(o, pitem); + opt_free_elem(o->type, pitem); } } @@ -2137,6 +2137,113 @@ int av_opt_copy(void *dst, const void *src) return ret; } +int av_opt_get_array_size(void *obj, const char *name, int search_flags, + unsigned int *out_val) +{ + void *target_obj, *parray; + const AVOption *o; + + o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); + if (!o || !target_obj) + return AVERROR_OPTION_NOT_FOUND; + if (!(o->type & AV_OPT_TYPE_FLAG_ARRAY)) + return AVERROR(EINVAL); + + parray = (uint8_t *)target_obj + o->offset; + *out_val = *opt_array_pcount(parray); + + return 0; +} + +int av_opt_get_array(void *obj, const char *name, int search_flags, + unsigned int start_elem, unsigned int nb_elems, + enum AVOptionType out_type, void *out_val) +{ + const size_t elem_size_out = opt_elem_size[TYPE_BASE(out_type)]; + + const AVOption *o; + void *target_obj; + + const void *parray; + unsigned array_size; + + int ret; + + o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); + if (!o || !target_obj) + return AVERROR_OPTION_NOT_FOUND; + if (!(o->type & AV_OPT_TYPE_FLAG_ARRAY) || + (out_type & AV_OPT_TYPE_FLAG_ARRAY)) + return AVERROR(EINVAL); + + parray = (uint8_t *)target_obj + o->offset; + array_size = *opt_array_pcount(parray); + + if (start_elem >= array_size || + array_size - start_elem < nb_elems) + return AVERROR(EINVAL); + + for (unsigned i = 0; i < nb_elems; i++) { + const void *src = opt_array_pelem(o, *(void**)parray, start_elem + i); + void *dst = (uint8_t*)out_val + i * elem_size_out; + + if (out_type == TYPE_BASE(o->type)) { + ret = opt_copy_elem(obj, out_type, dst, src); + if (ret < 0) + goto fail; + } else if (out_type == AV_OPT_TYPE_STRING) { + uint8_t buf[128], *out = buf; + + ret = opt_get_elem(o, &out, sizeof(buf), src, search_flags); + if (ret < 0) + goto fail; + + if (out == buf) { + out = av_strdup(buf); + if (!out) { + ret = AVERROR(ENOMEM); + goto fail; + } + } + + *(uint8_t**)dst = out; + } else if (out_type == AV_OPT_TYPE_INT64 || + out_type == AV_OPT_TYPE_DOUBLE || + out_type == AV_OPT_TYPE_RATIONAL) { + double num = 1.0; + int den = 1; + int64_t intnum = 1; + int ret; + + ret = read_number(o, src, &num, &den, &intnum); + if (ret < 0) + goto fail; + + switch (out_type) { + case AV_OPT_TYPE_INT64: + *(int64_t*)dst = (num == den) ? intnum : num * intnum / den; + break; + case AV_OPT_TYPE_DOUBLE: + *(double*)dst = num * intnum / den; + break; + case AV_OPT_TYPE_RATIONAL: + *(AVRational*)dst = (num == 1.0 && (int)intnum == intnum) ? + (AVRational){ intnum, den } : + av_d2q(num * intnum / den, 1<<24); + break; + default: av_assert0(0); + } + } else + return AVERROR(ENOSYS); + } + + return 0; +fail: + for (unsigned i = 0; i < nb_elems; i++) + opt_free_elem(out_type, (uint8_t*)out_val + i * elem_size_out); + return ret; +} + int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags) { int ret; diff --git a/libavutil/opt.h b/libavutil/opt.h index 23bc495158..cf9ebb9b12 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -944,6 +944,46 @@ int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannel * be freed with av_dict_free() by the caller */ int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val); + +/** + * For an array-type option, get the number of elements in the array. + */ +int av_opt_get_array_size(void *obj, const char *name, int search_flags, + unsigned int *out_val); + +/** + * For an array-type option, retrieve the values of one or more array elements. + * + * @param start_elem index of the first array element to retrieve + * @param nb_elems number of array elements to retrieve; start_elem+nb_elems + * must not be larger than array size as returned by + * av_opt_get_array_size() + * + * @param out_type Option type corresponding to the desired output. + * + * The array elements produced by this function will + * will be as if av_opt_getX() was called for each element, + * where X is specified by out_type. E.g. AV_OPT_TYPE_STRING + * corresponds to av_opt_get(). + * + * Typically this should be the same as the scalarized type of + * the AVOption being retrieved, but certain conversions are + * also possible - the same as those done by the corresponding + * av_opt_get*() function. E.g. any option type can be retrieved + * as a string, numeric types can be retrieved as int64, double, + * or rational, etc. + * + * @param out_val Array with nb_elems members into which the output will be + * written. The array type must match the underlying C type as + * documented for out_type, and be zeroed on entry to this + * function. + * + * For dynamically allocated types (strings, binary, dicts, + * etc.), the result is owned and freed by the caller. + */ +int av_opt_get_array(void *obj, const char *name, int search_flags, + unsigned int start_elem, unsigned int nb_elems, + enum AVOptionType out_type, void *out_val); /** * @} */ diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c index 02b3ed6e90..bfe351b4b3 100644 --- a/libavutil/tests/opt.c +++ b/libavutil/tests/opt.c @@ -300,6 +300,69 @@ int main(void) av_opt_free(&test2_ctx); } + printf("\nTesting av_opt_get_array()\n"); + { + static const int int_array[] = { 5, 0, 42, 137, INT_MAX }; + + TestContext test_ctx = { 0 }; + + int out_int [FF_ARRAY_ELEMS(int_array)] = { 0 }; + double out_double[FF_ARRAY_ELEMS(int_array)] = { 0. }; + char *out_str [FF_ARRAY_ELEMS(int_array)] = { NULL }; + AVDictionary *out_dict[2] = { NULL }; + + int ret; + + test_ctx.class = &test_class; + + av_log_set_level(AV_LOG_QUIET); + + av_opt_set_defaults(&test_ctx); + + test_ctx.array_int = av_memdup(int_array, sizeof(int_array)); + test_ctx.nb_array_int = FF_ARRAY_ELEMS(int_array); + + // retrieve as int + ret = av_opt_get_array(&test_ctx, "array_int", 0, + 1, 3, AV_OPT_TYPE_INT, out_int); + printf("av_opt_get_array(\"array_int\", 1, 3, INT)=%d -> [ %d, %d, %d ]\n", + ret, out_int[0], out_int[1], out_int[2]); + + // retrieve as double + ret = av_opt_get_array(&test_ctx, "array_int", 0, + 3, 2, AV_OPT_TYPE_DOUBLE, out_double); + printf("av_opt_get_array(\"array_int\", 3, 2, DOUBLE)=%d -> [ %.2f, %.2f ]\n", + ret, out_double[0], out_double[1]); + + // retrieve as str + ret = av_opt_get_array(&test_ctx, "array_int", 0, + 0, 5, AV_OPT_TYPE_STRING, out_str); + printf("av_opt_get_array(\"array_int\", 0, 5, STRING)=%d -> " + "[ %s, %s, %s, %s, %s ]\n", ret, + out_str[0], out_str[1], out_str[2], out_str[3], out_str[4]); + + for (int i = 0; i < FF_ARRAY_ELEMS(out_str); i++) + av_freep(&out_str[i]); + + ret = av_opt_get_array(&test_ctx, "array_dict", 0, 0, 2, + AV_OPT_TYPE_DICT, out_dict); + printf("av_opt_get_array(\"array_dict\", 0, 2, DICT)=%d\n", ret); + + for (int i = 0; i < test_ctx.nb_array_dict; i++) { + const AVDictionaryEntry *e = NULL; + while ((e = av_dict_iterate(test_ctx.array_dict[i], e))) { + const AVDictionaryEntry *e1 = av_dict_get(out_dict[i], e->key, NULL, 0); + if (!e1 || strcmp(e->value, e1->value)) { + printf("mismatching dict entry %s: %s/%s\n", + e->key, e->value, e1 ? e1->value : ""); + } + } + av_dict_free(&out_dict[i]); + } + + av_opt_free(&test_ctx); + } + printf("\nTest av_opt_serialize()\n"); { TestContext test_ctx = { 0 }; diff --git a/libavutil/version.h b/libavutil/version.h index 84eb3a388a..5ac9cc59dc 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 59 -#define LIBAVUTIL_VERSION_MINOR 34 +#define LIBAVUTIL_VERSION_MINOR 35 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt index 578350bc33..b8812e3eff 100644 --- a/tests/ref/fate/opt +++ b/tests/ref/fate/opt @@ -154,6 +154,12 @@ av_opt_set("array_dict", NULL) -> 0 array_dict=NULL; nb_array_dict=0 av_opt_get("array_dict") -> NULL +Testing av_opt_get_array() +av_opt_get_array("array_int", 1, 3, INT)=0 -> [ 0, 42, 137 ] +av_opt_get_array("array_int", 3, 2, DOUBLE)=0 -> [ 137.00, 2147483647.00 ] +av_opt_get_array("array_int", 0, 5, STRING)=0 -> [ 5, 0, 42, 137, 2147483647 ] +av_opt_get_array("array_dict", 0, 2, DICT)=0 + Test av_opt_serialize() num=0,unum=2147483648,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=hexagonal,bin=62696E00,bin1=,bin2=,num64=4294967296,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-),array_int=,array_str=str0|str\\|1|str\\\\2,array_dict=k00\=v\\\\\\\\00:k01\=v\\\,01\,k10\=v\\\\\=1\\\\:0 Setting entry with key 'num' to value '0'