[FFmpeg-devel] [PATCH 3/3] Export metadata in the generic format.

Anton Khirnov anton
Tue Oct 5 19:57:06 CEST 2010


deprecate old conversion API.
---
 libavformat/asfdec.c         |    3 +++
 libavformat/asfenc.c         |    6 ++++++
 libavformat/avformat.h       |   28 +++++++++++++++-------------
 libavformat/avidec.c         |    4 ++++
 libavformat/avienc.c         |   10 ++++------
 libavformat/flacdec.c        |    2 ++
 libavformat/id3v2.c          |    2 ++
 libavformat/matroskadec.c    |    3 +++
 libavformat/matroskaenc.c    |   10 ++++++++++
 libavformat/metadata.c       |   11 +++--------
 libavformat/mp3.c            |    7 +++++++
 libavformat/nutdec.c         |    3 +++
 libavformat/nutenc.c         |    3 +++
 libavformat/oggdec.c         |    2 ++
 libavformat/oggparsevorbis.c |    3 +++
 libavformat/oma.c            |    2 ++
 libavformat/vorbiscomment.c  |    1 +
 17 files changed, 73 insertions(+), 27 deletions(-)

diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
index 6741f8c..76cdfc6 100644
--- a/libavformat/asfdec.c
+++ b/libavformat/asfdec.c
@@ -478,6 +478,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
                     } else
                         get_tag(s, name, value_type, value_len);
             }
+            metadata_conv(&s->metadata, NULL, ff_asf_metadata_conv);
         } else if (!guidcmp(&g, &ff_asf_metadata_header)) {
             int n, stream_num, name_len, value_len, value_type, value_num;
             n = get_le16(pb);
@@ -1235,5 +1236,7 @@ AVInputFormat asf_demuxer = {
     asf_read_close,
     asf_read_seek,
     asf_read_pts,
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_asf_metadata_conv,
+#endif
 };
diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c
index 9f8d69a..78cf9a4 100644
--- a/libavformat/asfenc.c
+++ b/libavformat/asfenc.c
@@ -279,6 +279,8 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data
     int bit_rate;
     int64_t duration;
 
+    metadata_conv(&s->metadata, ff_asf_metadata_conv, NULL);
+
     tags[0] = av_metadata_get(s->metadata, "title"    , NULL, 0);
     tags[1] = av_metadata_get(s->metadata, "author"   , NULL, 0);
     tags[2] = av_metadata_get(s->metadata, "copyright", NULL, 0);
@@ -870,7 +872,9 @@ AVOutputFormat asf_muxer = {
     asf_write_trailer,
     .flags = AVFMT_GLOBALHEADER,
     .codec_tag= (const AVCodecTag* const []){codec_asf_bmp_tags, ff_codec_bmp_tags, ff_codec_wav_tags, 0},
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_asf_metadata_conv,
+#endif
 };
 #endif
 
@@ -892,6 +896,8 @@ AVOutputFormat asf_stream_muxer = {
     asf_write_trailer,
     .flags = AVFMT_GLOBALHEADER,
     .codec_tag= (const AVCodecTag* const []){codec_asf_bmp_tags, ff_codec_bmp_tags, ff_codec_wav_tags, 0},
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_asf_metadata_conv,
+#endif
 };
 #endif //CONFIG_ASF_STREAM_MUXER
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 362a056..57afa53 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -22,7 +22,7 @@
 #define AVFORMAT_AVFORMAT_H
 
 #define LIBAVFORMAT_VERSION_MAJOR 52
-#define LIBAVFORMAT_VERSION_MINOR 79
+#define LIBAVFORMAT_VERSION_MINOR 80
 #define LIBAVFORMAT_VERSION_MICRO  0
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
@@ -107,10 +107,9 @@ struct AVFormatContext;
  *       sorting will have '-sort' appended. E.g. artist="The Beatles",
  *       artist-sort="Beatles, The".
  *
- * 4. Tag names are normally exported exactly as stored in the container to
- *    allow lossless remuxing to the same format. For container-independent
- *    handling of metadata, av_metadata_conv() can convert it to ffmpeg generic
- *    format. Follows a list of generic tag names:
+ * 4. Demuxers attempt to export metadata in a generic format, however tags
+ *    with no generic equivalents are left as they are stored in the format.
+ *    Follows a list of generic tag names:
  *
  * album        -- name of the set this work belongs to
  * album_artist -- main creator of the set/album, if different from artist.
@@ -147,7 +146,9 @@ typedef struct {
 }AVMetadataTag;
 
 typedef struct AVMetadata AVMetadata;
+#if FF_API_OLD_METADATA
 typedef struct AVMetadataConv AVMetadataConv;
+#endif
 
 /**
  * Get a metadata element with matching key.
@@ -186,16 +187,13 @@ attribute_deprecated int av_metadata_set(AVMetadata **pm, const char *key, const
  */
 int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags);
 
+#if FF_API_OLD_METADATA
 /**
- * Convert all the metadata sets from ctx according to the source and
- * destination conversion tables. If one of the tables is NULL, then
- * tags are converted to/from ffmpeg generic tag names.
- *
- * @param d_conv destination tags format conversion table
- * @param s_conv source tags format conversion table
+ * This function is provided for compatibility reason and currently does nothing.
  */
-void av_metadata_conv(struct AVFormatContext *ctx, const AVMetadataConv *d_conv,
-                                                   const AVMetadataConv *s_conv);
+attribute_deprecated void av_metadata_conv(struct AVFormatContext *ctx, const AVMetadataConv *d_conv,
+                                                                        const AVMetadataConv *s_conv);
+#endif
 
 /**
  * Free all the memory allocated for an AVMetadata struct.
@@ -319,7 +317,9 @@ typedef struct AVOutputFormat {
 
     enum CodecID subtitle_codec; /**< default subtitle codec */
 
+#if FF_API_OLD_METADATA
     const AVMetadataConv *metadata_conv;
+#endif
 
     /* private fields */
     struct AVOutputFormat *next;
@@ -434,7 +434,9 @@ typedef struct AVInputFormat {
      */
     int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
 
+#if FF_API_OLD_METADATA
     const AVMetadataConv *metadata_conv;
+#endif
 
     /* private fields */
     struct AVInputFormat *next;
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 84ccaec..8aeff6b 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -280,6 +280,7 @@ static void avi_read_info(AVFormatContext *s, uint64_t end)
         uint32_t size = get_le32(s->pb);
         avi_read_tag(s, NULL, tag, size);
     }
+    metadata_conv(&s->metadata, NULL, ff_avi_metadata_conv);
 }
 
 static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
@@ -651,6 +652,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
         case MKTAG('s', 't', 'r', 'n'):
             if(s->nb_streams){
                 avi_read_tag(s, s->streams[s->nb_streams-1], tag, size);
+                metadata_conv(&s->streams[s->nb_streams - 1]->metadata, NULL, ff_avi_metadata_conv);
                 break;
             }
         default:
@@ -1332,5 +1334,7 @@ AVInputFormat avi_demuxer = {
     avi_read_packet,
     avi_read_close,
     avi_read_seek,
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_avi_metadata_conv,
+#endif
 };
diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index 161fb1b..cb4617a 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -290,12 +290,7 @@ static int avi_write_header(AVFormatContext *s)
             return -1;
         }
         ff_end_tag(pb, strf);
-        if ((t = av_metadata_get(s->streams[i]->metadata, "strn", NULL, 0))) {
-            avi_write_info_tag(s->pb, t->key, t->value);
-            t = NULL;
-        }
-        //FIXME a limitation of metadata conversion system
-        else if ((t = av_metadata_get(s->streams[i]->metadata, "INAM", NULL, 0))) {
+        if ((t = av_metadata_get(s->streams[i]->metadata, "title", NULL, 0))) {
             avi_write_info_tag(s->pb, "strn", t->value);
             t = NULL;
         }
@@ -375,6 +370,7 @@ static int avi_write_header(AVFormatContext *s)
 
     list2 = ff_start_tag(pb, "LIST");
     put_tag(pb, "INFO");
+    metadata_conv(&s->metadata, ff_avi_metadata_conv, NULL);
     for (i = 0; *ff_avi_tags[i]; i++) {
         if ((t = av_metadata_get(s->metadata, ff_avi_tags[i], NULL, AV_METADATA_MATCH_CASE)))
             avi_write_info_tag(s->pb, t->key, t->value);
@@ -647,5 +643,7 @@ AVOutputFormat avi_muxer = {
     avi_write_trailer,
     .codec_tag= (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0},
     .flags= AVFMT_VARIABLE_FPS,
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_avi_metadata_conv,
+#endif
 };
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index e54fb39..63761ee 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -147,5 +147,7 @@ AVInputFormat flac_demuxer = {
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "flac",
     .value = CODEC_ID_FLAC,
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_vorbiscomment_metadata_conv,
+#endif
 };
diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 364720f..fbcb8f8 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -23,6 +23,7 @@
 #include "id3v1.h"
 #include "libavutil/avstring.h"
 #include "libavutil/intreadwrite.h"
+#include "metadata.h"
 
 int ff_id3v2_match(const uint8_t *buf, const char * magic)
 {
@@ -249,6 +250,7 @@ void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)
         /* Skip to end of tag */
         url_fseek(s->pb, next, SEEK_SET);
     }
+    metadata_conv(&s->metadata, NULL, ff_id3v2_metadata_conv);
 
     if (len > 0) {
         /* Skip padding */
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 0d0285e..7457e58 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1048,6 +1048,7 @@ static void matroska_convert_tag(AVFormatContext *s, EbmlList *list,
                 matroska_convert_tag(s, &tags[i].sub, metadata, key);
         }
     }
+    metadata_conv(metadata, NULL, ff_mkv_metadata_conv);
 }
 
 static void matroska_convert_tags(AVFormatContext *s)
@@ -1923,5 +1924,7 @@ AVInputFormat matroska_demuxer = {
     matroska_read_packet,
     matroska_read_close,
     matroska_read_seek,
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_mkv_metadata_conv,
+#endif
 };
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 29fddce..c66a701 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -752,6 +752,8 @@ static int mkv_write_tags(AVFormatContext *s)
     ebml_master tags = {0};
     int i, ret;
 
+    metadata_conv(&s->metadata, ff_mkv_metadata_conv, NULL);
+
     if (av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) {
         ret = mkv_write_tag(s, s->metadata, 0, 0, &tags);
         if (ret < 0) return ret;
@@ -760,6 +762,8 @@ static int mkv_write_tags(AVFormatContext *s)
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
 
+        metadata_conv(&st->metadata, ff_mkv_metadata_conv, NULL);
+
         if (!av_metadata_get(st->metadata, "", 0, AV_METADATA_IGNORE_SUFFIX))
             continue;
 
@@ -770,6 +774,8 @@ static int mkv_write_tags(AVFormatContext *s)
     for (i = 0; i < s->nb_chapters; i++) {
         AVChapter *ch = s->chapters[i];
 
+        metadata_conv(&ch->metadata, ff_mkv_metadata_conv, NULL);
+
         if (!av_metadata_get(ch->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX))
             continue;
 
@@ -1186,7 +1192,9 @@ AVOutputFormat matroska_muxer = {
     .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
     .codec_tag = (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0},
     .subtitle_codec = CODEC_ID_TEXT,
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_mkv_metadata_conv,
+#endif
 };
 #endif
 
@@ -1220,6 +1228,8 @@ AVOutputFormat matroska_audio_muxer = {
     mkv_write_trailer,
     .flags = AVFMT_GLOBALHEADER,
     .codec_tag = (const AVCodecTag* const []){ff_codec_wav_tags, 0},
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_mkv_metadata_conv,
+#endif
 };
 #endif
diff --git a/libavformat/metadata.c b/libavformat/metadata.c
index 8fc1771..1940598 100644
--- a/libavformat/metadata.c
+++ b/libavformat/metadata.c
@@ -140,15 +140,10 @@ void metadata_conv(AVMetadata **pm, const AVMetadataConv *d_conv,
     *pm = dst;
 }
 
+#if FF_API_OLD_METADATA
 void av_metadata_conv(AVFormatContext *ctx, const AVMetadataConv *d_conv,
                                             const AVMetadataConv *s_conv)
 {
-    int i;
-    metadata_conv(&ctx->metadata, d_conv, s_conv);
-    for (i=0; i<ctx->nb_streams ; i++)
-        metadata_conv(&ctx->streams [i]->metadata, d_conv, s_conv);
-    for (i=0; i<ctx->nb_chapters; i++)
-        metadata_conv(&ctx->chapters[i]->metadata, d_conv, s_conv);
-    for (i=0; i<ctx->nb_programs; i++)
-        metadata_conv(&ctx->programs[i]->metadata, d_conv, s_conv);
+    return;
 }
+#endif
diff --git a/libavformat/mp3.c b/libavformat/mp3.c
index c1622a3..1527e98 100644
--- a/libavformat/mp3.c
+++ b/libavformat/mp3.c
@@ -199,7 +199,9 @@ AVInputFormat mp3_demuxer = {
     mp3_read_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "mp2,mp3,m2a", /* XXX: use probe */
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_id3v2_metadata_conv,
+#endif
 };
 #endif
 
@@ -298,7 +300,9 @@ AVOutputFormat mp2_muxer = {
     NULL,
     mp3_write_packet,
     mp3_write_trailer,
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_id3v2_metadata_conv,
+#endif
 };
 #endif
 
@@ -321,6 +325,7 @@ static int mp3_write_header(struct AVFormatContext *s)
     size_pos = url_ftell(s->pb);
     put_be32(s->pb, 0);
 
+    metadata_conv(&s->metadata, ff_id3v2_metadata_conv, NULL);
     while ((t = av_metadata_get(s->metadata, "", t, AV_METADATA_IGNORE_SUFFIX))) {
         uint32_t tag = 0;
 
@@ -370,6 +375,8 @@ AVOutputFormat mp3_muxer = {
     mp3_write_packet,
     mp3_write_trailer,
     AVFMT_NOTIMESTAMPS,
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_id3v2_metadata_conv,
+#endif
 };
 #endif
diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index 7db06fa..7c25cc9 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -467,6 +467,7 @@ static int decode_info_header(NUTContext *nut){
                 av_metadata_set2(metadata, name, str_value, 0);
         }
     }
+    metadata_conv(metadata, NULL, ff_nut_metadata_conv);
 
     if(skip_reserved(bc, end) || get_checksum(bc)){
         av_log(s, AV_LOG_ERROR, "info header checksum mismatch\n");
@@ -934,7 +935,9 @@ AVInputFormat nut_demuxer = {
     nut_read_close,
     read_seek,
     .extensions = "nut",
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_nut_metadata_conv,
+#endif
     .codec_tag = (const AVCodecTag * const []) { ff_codec_bmp_tags, ff_nut_video_tags, ff_codec_wav_tags, ff_nut_subtitle_tags, 0 },
 };
 #endif
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 8cbc7d4..3b079fc 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -439,6 +439,7 @@ static int write_globalinfo(NUTContext *nut, ByteIOContext *bc){
     if(ret < 0)
         return ret;
 
+    metadata_conv(&s->metadata, ff_nut_metadata_conv, NULL);
     while ((t = av_metadata_get(s->metadata, "", t, AV_METADATA_IGNORE_SUFFIX)))
         count += add_info(dyn_bc, t->key, t->value);
 
@@ -810,5 +811,7 @@ AVOutputFormat nut_muxer = {
     write_trailer,
     .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
     .codec_tag = (const AVCodecTag * const []){ ff_codec_bmp_tags, ff_nut_video_tags, ff_codec_wav_tags, ff_nut_subtitle_tags, 0 },
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_nut_metadata_conv,
+#endif
 };
diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index 4c9a43a..b20fe8d 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -641,6 +641,8 @@ AVInputFormat ogg_demuxer = {
     ogg_read_seek,
     ogg_read_timestamp,
     .extensions = "ogg",
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_vorbiscomment_metadata_conv,
+#endif
     .flags = AVFMT_GENERIC_INDEX,
 };
diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index c7f8149..9f87393 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -29,6 +29,7 @@
 #include "libavcodec/bytestream.h"
 #include "avformat.h"
 #include "oggdec.h"
+#include "vorbiscomment.c"
 
 static int ogm_chapter(AVFormatContext *as, uint8_t *key, uint8_t *val)
 {
@@ -137,6 +138,8 @@ ff_vorbis_comment(AVFormatContext * as, AVMetadata **m, const uint8_t *buf, int
         av_log(as, AV_LOG_INFO,
                "truncated comment header, %i comments not found\n", n);
 
+    metadata_conv(m, NULL, ff_vorbiscomment_metadata_conv);
+
     return 0;
 }
 
diff --git a/libavformat/oma.c b/libavformat/oma.c
index cdf1106..51f3410 100644
--- a/libavformat/oma.c
+++ b/libavformat/oma.c
@@ -201,6 +201,8 @@ AVInputFormat oma_demuxer = {
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "oma,aa3",
     .codec_tag= (const AVCodecTag* const []){codec_oma_tags, 0},
+#if FF_API_OLD_METADATA
     .metadata_conv = ff_id3v2_metadata_conv,
+#endif
 };
 
diff --git a/libavformat/vorbiscomment.c b/libavformat/vorbiscomment.c
index 733ddd1..17bd2f2 100644
--- a/libavformat/vorbiscomment.c
+++ b/libavformat/vorbiscomment.c
@@ -54,6 +54,7 @@ int ff_vorbiscomment_length(AVMetadata *m, const char *vendor_string,
 int ff_vorbiscomment_write(uint8_t **p, AVMetadata **m,
                            const char *vendor_string, const unsigned count)
 {
+    metadata_conv(m, ff_vorbiscomment_metadata_conv, NULL);
     bytestream_put_le32(p, strlen(vendor_string));
     bytestream_put_buffer(p, vendor_string, strlen(vendor_string));
     if (*m) {
-- 
1.7.1




More information about the ffmpeg-devel mailing list