By comparing versions of dictionaries, it's possible to detect if metadata
has changed.
---
 doc/APIchanges      |  3 +++
 libavutil/dict.c    |  8 ++++++++
 libavutil/dict.h    | 10 ++++++++++
 libavutil/version.h |  2 +-
 4 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 952ee51..8f5fce1 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:     2013-12-xx
 
 API changes, most recent first:
 
+2014-06-xx - xxxxxxx - lavu 53.17.0 - dict.h
+  Add av_dict_version to allow for checking if a dictionary changes
+
 2014-04-xx - xxxxxxx - lavc 55.54.0 - avcodec.h
   Add AVCodecContext.side_data_only_packets to allow encoders to output packets
   with only side data. This option may become mandatory in the future, so all
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..9d03ab8 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 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
diff --git a/libavutil/version.h b/libavutil/version.h
index 427409f..a4384b3 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -54,7 +54,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 53
-#define LIBAVUTIL_VERSION_MINOR 16
+#define LIBAVUTIL_VERSION_MINOR 17
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
2.0.0.rc2

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to