From patchwork Thu Sep 22 02:02:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marvin Scholz X-Patchwork-Id: 38138 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1e65:b0:96:9b22:e02b with SMTP id cy37csp3228204pzb; Wed, 21 Sep 2022 19:02:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Q8e6zTQCAkzaybgPudr8VNwHHDjLC3WQkOH26aYFwfi5osrzQ0GmAr5miyy84w+c+8M02 X-Received: by 2002:a17:906:770d:b0:73c:a08f:593c with SMTP id q13-20020a170906770d00b0073ca08f593cmr937170ejm.182.1663812176754; Wed, 21 Sep 2022 19:02:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663812176; cv=none; d=google.com; s=arc-20160816; b=Jh/ziB/WPrBfvpaIDjedGAEE631y1YbyCgMPXOSjUFfIHi4jUgDon56SxvlMdMq8su 0Kb4TMSafzgu6/aPuhoT2jt5Mk0nHvkG6kV0sIec+Ool7G5UNLuk1HtTKnS0U6Go9w9Y aZqfNd5wharAPAGbXCaNPVm7VSJ7h019wkae/UIjhVHiMuX26Rex0SCpzj4iQOl4vcs0 QZqXjAzVpulmz0Ejg75OBHhQ38CPpyWhJsTougvu+Lh4+/+MRi/g4JW89MV/ViTyBDHR hEKJMUKVLsiUpVaO5a1LNOXWfMuTaOlYYlEzLFIOhJlaqzGbtBQ7d/OSr6jUvkVG8F0l whew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=kTmsOPYHJPd80e9QnT142UEdShF65W1MsR4XzKqb50E=; b=nUnkB7PTbMBcf0VTieOj/la60B7vc93hhku7SIWKngWEm4z3J5KpCeACGfcH/TqjuG WJAvEojDW98Tka7VzuBP8VK1XYz393iC+i8E3vJ02EXcdZ8xsgJs9WIdkHS1qkMZCfIg 8JPhcFt4CWjB3MhBbJEk38+VAYnhuYEsN16Q+OzWyjW+bnIwJiEkI2k4wBmCyZxuG8Mv YPjgkXSTmFV/JjwgkikOBU6lQs9mORn2bNpxyvLbPrCVA0H6P06L1QRJhJSvlaCAgvMl 0rTHDjvstrswGg1+nxkgiqUghDeQ1jJU2WtPb0vZ+FuFmV1CqkZNziuRkh10PkcyQOa7 MW6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=kUhdiZNE; 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=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id oq12-20020a170906cc8c00b0077547abf08fsi3381374ejb.169.2022.09.21.19.02.32; Wed, 21 Sep 2022 19:02:56 -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=@gmail.com header.s=20210112 header.b=kUhdiZNE; 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=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B2C3F68BB19; Thu, 22 Sep 2022 05:02:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D091968B64C for ; Thu, 22 Sep 2022 05:02:22 +0300 (EEST) Received: by mail-ej1-f45.google.com with SMTP id bj12so17779440ejb.13 for ; Wed, 21 Sep 2022 19:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=iw3GnKUXOMqxpFtm09k+F6RSLHvwCpkNTZhJYpkISu8=; b=kUhdiZNE9fKfVTh/adGnYKfHvdhOWTn5Hg3B3UDhQXSWSwHI/Zt6Q0Gk5mQtj05aT8 mX1XO6iN++joL7CL0w+fWKcseIXdkwDxe7HZAXzd+H10kV2rZBZAHM4arSMeALPHj+4H FYcrCgMshstPPZtcLmHuiJUxh8/Wn4XXstSttGz6k0kCpUHoEjaCMUSfncuQKQqo3eog ejp+JZA7W+VG5CH+sZGhNjVQAt+fe1c4FOZa7ma5ksOTL3E1UMWB6P6SN8gx+75IErsb f9pRGNYMW6Ai0LfnH0iyYOm3KrDJL8Kjkn//NVzsNFfFrFmazks1l6CsDkECTBSyQUy+ SA6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=iw3GnKUXOMqxpFtm09k+F6RSLHvwCpkNTZhJYpkISu8=; b=5NRaQTr3ckdEym29uQJ9LknW7mjJNZoOq6V53xSTb7mKbWcCphaaSHMBVBMBRCQsTj Dt9M80edkvQfvH+2gO/tTR3s2U0Vat0bzJ1LsqmFS5GNfHquaY3uJ63mM/P2l9uwHmvK mwEDslmrykKIo+178K7pZ8wUhrz9YO8phvjlgP1qsna9jPGmYeY9/Nu3e8bwUR9SZ94z ObyMR8xWKwqMGzCOCBy3pMKraOnwFsOIzptJdVxBtl60t9r5gRayHsOqRKMGai3NGEBy tmEK9fbUezmNBSBG1rEAmgWaTsppVcdozcqbqjI4VA+xeTZNyeAnkTef0IcjrCA8xUT1 06TQ== X-Gm-Message-State: ACrzQf3qR08dy5VAfboBIDqy6tR73gngP5C1ZdU/FUsT7aYAznj4CtyF o6uko1wq3iDnjcdHm/Ype8J57im61D4= X-Received: by 2002:a17:907:1ded:b0:76f:af8f:942e with SMTP id og45-20020a1709071ded00b0076faf8f942emr896036ejc.120.1663812142119; Wed, 21 Sep 2022 19:02:22 -0700 (PDT) Received: from MBP-von-Marvin.citadel.scalie.me (84-112-104-25.cable.dynamic.surfer.at. [84.112.104.25]) by smtp.gmail.com with ESMTPSA id e4-20020aa7d7c4000000b0044ec76521a1sm2792794eds.55.2022.09.21.19.02.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 19:02:21 -0700 (PDT) From: Marvin Scholz To: ffmpeg-devel@ffmpeg.org Date: Thu, 22 Sep 2022 04:02:15 +0200 Message-Id: <20220922020216.46589-1-epirat07@gmail.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avutil/dict: Add av_dict_iterate 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: Marvin Scholz Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: IUNhTmCAZ0YR This is a more explicit iteration API rather than using the "magic" av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX) which is not really trivial to grasp what it does when casually reading through code. --- libavutil/dict.c | 19 +++++++++++++++++++ libavutil/dict.h | 27 +++++++++++++++++++++++++++ libavutil/version.h | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/libavutil/dict.c b/libavutil/dict.c index 14ad780a79..2f690a5b8e 100644 --- a/libavutil/dict.c +++ b/libavutil/dict.c @@ -20,6 +20,7 @@ #include +#include "avassert.h" #include "avstring.h" #include "dict.h" #include "dict_internal.h" @@ -38,6 +39,24 @@ int av_dict_count(const AVDictionary *m) return m ? m->count : 0; } +AVDictionaryEntry *av_dict_iterate(const AVDictionary *m, + const AVDictionaryEntry *prev) +{ + int i = 0; + + if (!m) + return NULL; + + if (prev) + i = prev - m->elems + 1; + + av_assert2(i >= 0); + if (i >= m->count) + return NULL; + + return &m->elems[i]; +} + AVDictionaryEntry *av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags) { diff --git a/libavutil/dict.h b/libavutil/dict.h index 0d1afc6c64..b42b3f07fd 100644 --- a/libavutil/dict.h +++ b/libavutil/dict.h @@ -32,6 +32,8 @@ #include +#include "attributes.h" + /** * @addtogroup lavu_dict AVDictionary * @ingroup lavu_data @@ -101,6 +103,31 @@ typedef struct AVDictionary AVDictionary; AVDictionaryEntry *av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags); +/** + * Iterate over a dictionary + * + * Iterates through all entries in the dictionary. + * + * @warning The returned AVDictionaryEntry key/value must not be changed. + * + * @param m The dictionary to iterate over + * @param prev Pointer to the previous AVDictionaryEntry, NULL initially + * + * @retval AVDictionaryEntry* The next element in the dictionary + * @retval NULL No more elements in the dictionary + * + * Typical usage: + * @code + * AVDictionaryEntry *e = NULL; + * while (e = av_dict_iterate(m, e)) { + * // ... + * } + * @endcode + */ +av_warn_unused_result +AVDictionaryEntry *av_dict_iterate(const AVDictionary *m, + const AVDictionaryEntry *prev); + /** * Get number of entries in dictionary. * diff --git a/libavutil/version.h b/libavutil/version.h index 0585fa7b80..6fd07ed2a4 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -80,7 +80,7 @@ #define LIBAVUTIL_VERSION_MAJOR 57 #define LIBAVUTIL_VERSION_MINOR 36 -#define LIBAVUTIL_VERSION_MICRO 102 +#define LIBAVUTIL_VERSION_MICRO 103 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ LIBAVUTIL_VERSION_MINOR, \