changeset 4158:ea1e24175669 libavformat

Add a metadata compatibility layer, so that when a user application set metadata using old API, it is automatically converted to new API before muxing.
author aurel
date Tue, 06 Jan 2009 00:09:23 +0000
parents 017e68062073
children 6b5c3c5460be
files metadata.c metadata.h utils.c
diffstat 3 files changed, 45 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/metadata.c	Mon Jan 05 23:56:27 2009 +0000
+++ b/metadata.c	Tue Jan 06 00:09:23 2009 +0000
@@ -73,3 +73,40 @@
 
     return 0;
 }
+
+#if LIBAVFORMAT_VERSION_MAJOR < 53
+#define FILL_METADATA(s, key, value) {                                        \
+    if (value && *value &&                                                    \
+        !av_metadata_get(s->metadata, #key, NULL, AV_METADATA_IGNORE_CASE))   \
+        av_metadata_set(&s->metadata, (const AVMetadataTag){#key, value});    \
+    }
+#define FILL_METADATA_STR(s, key)  FILL_METADATA(s, key, s->key)
+#define FILL_METADATA_INT(s, key) {                                           \
+    char number[10];                                                          \
+    snprintf(number, sizeof(number), "%d", s->key);                           \
+    FILL_METADATA(s, key, number) }
+
+void ff_metadata_sync_compat(AVFormatContext *ctx)
+{
+    int i;
+
+    FILL_METADATA_STR(ctx, title);
+    FILL_METADATA_STR(ctx, author);
+    FILL_METADATA_STR(ctx, copyright);
+    FILL_METADATA_STR(ctx, comment);
+    FILL_METADATA_STR(ctx, album);
+    FILL_METADATA_INT(ctx, year);
+    FILL_METADATA_INT(ctx, track);
+    FILL_METADATA_STR(ctx, genre);
+    for (i=0; i<ctx->nb_chapters; i++)
+        FILL_METADATA_STR(ctx->chapters[i], title);
+    for (i=0; i<ctx->nb_programs; i++) {
+        FILL_METADATA_STR(ctx->programs[i], name);
+        FILL_METADATA_STR(ctx->programs[i], provider_name);
+    }
+    for (i=0; i<ctx->nb_streams; i++) {
+        FILL_METADATA_STR(ctx->streams[i], language);
+        FILL_METADATA_STR(ctx->streams[i], filename);
+    }
+}
+#endif
--- a/metadata.h	Mon Jan 05 23:56:27 2009 +0000
+++ b/metadata.h	Tue Jan 06 00:09:23 2009 +0000
@@ -35,4 +35,8 @@
     AVMetadataTag *elems;
 };
 
+#if LIBAVFORMAT_VERSION_MAJOR < 53
+void ff_metadata_sync_compat(AVFormatContext *s);
+#endif
+
 #endif /* AVFORMAT_METADATA_H */
--- a/utils.c	Mon Jan 05 23:56:27 2009 +0000
+++ b/utils.c	Tue Jan 06 00:09:23 2009 +0000
@@ -2501,6 +2501,10 @@
             return AVERROR(ENOMEM);
     }
 
+#if LIBAVFORMAT_VERSION_MAJOR < 53
+    ff_metadata_sync_compat(s);
+#endif
+
     if(s->oformat->write_header){
         ret = s->oformat->write_header(s);
         if (ret < 0)