[FFmpeg-devel] [PATCH 4/8] metadata: add callbacks to conversion system.

Anton Khirnov wyskas
Wed Jun 2 15:16:01 CEST 2010


---
 libavformat/metadata.c |   54 ++++++++++++++++++++++++++++++++---------------
 libavformat/metadata.h |    4 +++
 2 files changed, 41 insertions(+), 17 deletions(-)

diff --git a/libavformat/metadata.c b/libavformat/metadata.c
index 2de4aa3..cf4baf4 100644
--- a/libavformat/metadata.c
+++ b/libavformat/metadata.c
@@ -114,29 +114,49 @@ void metadata_conv(AVMetadata **pm, const AVMetadataConv *d_conv,
        if the tables are getting big enough that it would matter speed wise */
     const AVMetadataConvTable *sc, *dc;
     AVMetadataTag *mtag = NULL;
-    AVMetadata *dst = NULL;
+    AVMetadata *dst = NULL, *src = *pm, *tmp = NULL;
     const char *key;
 
     if (d_conv == s_conv)
         return;
 
-    while((mtag=av_metadata_get(*pm, "", mtag, AV_METADATA_IGNORE_SUFFIX))) {
-        key = mtag->key;
-        if (s_conv && s_conv->conv_table)
-            for (sc=s_conv->conv_table; sc->native; sc++)
-                if (!strcasecmp(key, sc->native)) {
-                    key = sc->generic;
-                    break;
-                }
-        if (d_conv && d_conv->conv_table)
-            for (dc=d_conv->conv_table; dc->native; dc++)
-                if (!strcasecmp(key, dc->generic)) {
-                    key = dc->native;
-                    break;
-                }
-        av_metadata_set2(&dst, key, mtag->value, 0);
+    if (s_conv) {
+        if (s_conv->conv2generic)
+            s_conv->conv2generic(&src, &tmp);
+
+        if (s_conv->conv_table)
+            while((mtag = av_metadata_get(src, "", mtag, AV_METADATA_IGNORE_SUFFIX))) {
+                key = mtag->key;
+                for (sc=s_conv->conv_table; sc->native; sc++)
+                    if (!strcasecmp(key, sc->native)) {
+                        key = sc->generic;
+                        break;
+                    }
+                av_metadata_set2(&tmp, key, mtag->value, 0);
+            }
+        src  = tmp;
+        mtag = NULL;
+        av_metadata_free(pm);
     }
-    av_metadata_free(pm);
+
+    if (d_conv) {
+        if (d_conv->conv2native)
+            d_conv->conv2native(&src, &dst);
+
+        if (d_conv->conv_table)
+            while ((mtag = av_metadata_get(src, "", mtag, AV_METADATA_IGNORE_SUFFIX))) {
+                key = mtag->key;
+                for (dc=d_conv->conv_table; dc->native; dc++)
+                    if (!strcasecmp(key, dc->generic)) {
+                        key = dc->native;
+                        break;
+                    }
+                av_metadata_set2(&dst, key, mtag->value, 0);
+            }
+        av_metadata_free(&src);
+    } else
+        dst = src;
+
     *pm = dst;
 }
 
diff --git a/libavformat/metadata.h b/libavformat/metadata.h
index 309147d..24296c4 100644
--- a/libavformat/metadata.h
+++ b/libavformat/metadata.h
@@ -42,6 +42,10 @@ typedef struct AVMetadataConvTable {
 
 struct AVMetadataConv {
     const AVMetadataConvTable *conv_table;
+    /** Convert tags from src to generic/native format either a) in place, so they'll pass
+     *  through the table next or b) remove them from src and store results in dst. */
+    void (*conv2generic)(AVMetadata **src, AVMetadata **dst);
+    void (*conv2native)( AVMetadata **src, AVMetadata **dst);
 };
 
 #if LIBAVFORMAT_VERSION_MAJOR < 53
-- 
1.7.1




More information about the ffmpeg-devel mailing list