From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 7983E44729 for ; Thu, 22 Sep 2022 02:02:31 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 74B9C68BAFE; Thu, 22 Sep 2022 05:02:28 +0300 (EEST) 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-Google-Smtp-Source: AMsMyM6TH3POLWHUmDQM1oAztBbfnZo3rv1/DjGHtn2Jj7Gy0p/WLRYVyLjiWDw81eE9Mmo4W8B/RA== 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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, \ -- 2.37.0 (Apple Git-136) _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".