By comparing versions of dictionaries, it's possible to detect if metadata
has changed.
---
 libavutil/dict.c |  8 ++++++++
 libavutil/dict.h | 10 ++++++++++
 2 files changed, 18 insertions(+)

diff --git a/libavutil/dict.c b/libavutil/dict.c
index 7b4dbf2..113afe4 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -27,6 +27,7 @@
 
 struct AVDictionary {
     int count;
+    uint64_t version;
     AVDictionaryEntry *elems;
 };
 
@@ -75,6 +76,8 @@ int av_dict_set(AVDictionary **pm, const char *key, const 
char *value,
     if (!m)
         m = *pm = av_mallocz(sizeof(*m));
 
+    m->version++;
+
     if (tag) {
         if (flags & AV_DICT_DONT_OVERWRITE)
             return 0;
@@ -117,6 +120,11 @@ int av_dict_set(AVDictionary **pm, const char *key, const 
char *value,
     return 0;
 }
 
+uint64_t av_dict_version(const AVDictionary *m)
+{
+    return m ? m->version : 0;
+}
+
 static int parse_key_value_pair(AVDictionary **pm, const char **buf,
                                 const char *key_val_sep, const char *pairs_sep,
                                 int flags)
diff --git a/libavutil/dict.h b/libavutil/dict.h
index e4aee27..1679119 100644
--- a/libavutil/dict.h
+++ b/libavutil/dict.h
@@ -25,6 +25,8 @@
 #ifndef AVUTIL_DICT_H
 #define AVUTIL_DICT_H
 
+#include <stdint.h>
+
 /**
  * @addtogroup lavu_dict AVDictionary
  * @ingroup lavu_data
@@ -107,6 +109,14 @@ int av_dict_count(const AVDictionary *m);
 int av_dict_set(AVDictionary **pm, const char *key, const char *value, int 
flags);
 
 /**
+ * Get the version of number for the current state of the dictionary. Whenever
+ * an item is changed, this number is incremented.
+ *
+ * @return >= 0 for any changes, 0 for an empty dictionary
+ */
+uint64_t av_dict_version(const AVDictionary *m);
+
+/**
  * Parse the key/value pairs list and add to a dictionary.
  *
  * @param key_val_sep  a 0-terminated list of characters used to separate
-- 
2.0.0.rc2

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to