Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: rcombs <rcombs@rcombs.me>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 1/3] lavu/dict: add AV_DICT_DEDUP
Date: Wed, 24 Aug 2022 18:51:58 -0500
Message-ID: <20220824235200.22312-1-rcombs@rcombs.me> (raw)

This is useful when multiple metadata inputs may set the same value
(e.g. both a container-specific header and an ID3 tag).
---
 libavutil/dict.c | 11 +++++++++++
 libavutil/dict.h |  1 +
 2 files changed, 12 insertions(+)

diff --git a/libavutil/dict.c b/libavutil/dict.c
index 9d3d96c58b..d8b38cc71f 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -76,6 +76,17 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
 
     if (!(flags & AV_DICT_MULTIKEY)) {
         tag = av_dict_get(m, key, NULL, flags);
+    } else if (flags & AV_DICT_DEDUP) {
+        while ((tag = av_dict_get(m, key, NULL, flags))) {
+            if ((!value && !tag->value) ||
+                (value && tag->value && !strcmp(value, tag->value))) {
+                if (flags & AV_DICT_DONT_STRDUP_KEY)
+                    av_free(key);
+                if (flags & AV_DICT_DONT_STRDUP_VAL)
+                    av_free(value);
+                return 0;
+            }
+        }
     }
     if (flags & AV_DICT_DONT_STRDUP_KEY)
         copy_key = (void *)key;
diff --git a/libavutil/dict.h b/libavutil/dict.h
index 0d1afc6c64..a957b48bf3 100644
--- a/libavutil/dict.h
+++ b/libavutil/dict.h
@@ -75,6 +75,7 @@
 #define AV_DICT_APPEND         32   /**< If the entry already exists, append to it.  Note that no
                                       delimiter is added, the strings are simply concatenated. */
 #define AV_DICT_MULTIKEY       64   /**< Allow to store several equal keys in the dictionary */
+#define AV_DICT_DEDUP         128   /**< If inserting a value that already exists for a key, do nothing. Only relevant with AV_DICT_MULTIKEY. */
 
 typedef struct AVDictionaryEntry {
     char *key;
-- 
2.37.1

_______________________________________________
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".

             reply	other threads:[~2022-08-24 23:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-24 23:51 rcombs [this message]
2022-08-24 23:51 ` [FFmpeg-devel] [PATCH 2/3] lavf/metadata: support duplicate keys in ff_metadata_conv rcombs
2022-08-24 23:52 ` [FFmpeg-devel] [PATCH 3/3] lavf/id3v2dec: support multiple values and TIPL frames rcombs
2022-08-25  0:16   ` Soft Works
2022-08-25  0:23     ` Ridley Combs
2022-08-25  0:27 [FFmpeg-devel] [PATCH 1/3] lavu/dict: add AV_DICT_DEDUP rcombs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220824235200.22312-1-rcombs@rcombs.me \
    --to=rcombs@rcombs.me \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git