[FFmpeg-devel] [PATCH 1/8] metadata: wrap conversion tables in a struct.

Anton Khirnov wyskas
Wed Jun 2 15:15:58 CEST 2010


It's need for adding callbacks to conversion.
---
 libavformat/asf.c           |    6 +++++-
 libavformat/asf.h           |    2 +-
 libavformat/asfdec.c        |    2 +-
 libavformat/asfenc.c        |    4 ++--
 libavformat/avi.c           |    6 +++++-
 libavformat/avi.h           |    2 +-
 libavformat/avidec.c        |    2 +-
 libavformat/avienc.c        |    2 +-
 libavformat/flacdec.c       |    2 +-
 libavformat/flacenc.c       |    2 +-
 libavformat/id3v2.c         |    6 +++++-
 libavformat/id3v2.h         |    2 +-
 libavformat/matroska.c      |    6 +++++-
 libavformat/matroska.h      |    2 +-
 libavformat/matroskadec.c   |    2 +-
 libavformat/metadata.c      |   10 +++++-----
 libavformat/metadata.h      |    6 +++++-
 libavformat/mp3.c           |    4 ++--
 libavformat/nut.c           |    6 +++++-
 libavformat/nut.h           |    2 +-
 libavformat/nutdec.c        |    2 +-
 libavformat/nutenc.c        |    2 +-
 libavformat/oggdec.c        |    2 +-
 libavformat/oggenc.c        |    2 +-
 libavformat/vorbiscomment.c |    6 +++++-
 libavformat/vorbiscomment.h |    2 +-
 26 files changed, 60 insertions(+), 32 deletions(-)

diff --git a/libavformat/asf.c b/libavformat/asf.c
index e25ac03..8f940f5 100644
--- a/libavformat/asf.c
+++ b/libavformat/asf.c
@@ -133,7 +133,7 @@ const ff_asf_guid ff_asf_digital_signature = {
 };
 
 /* List of official tags at http://msdn.microsoft.com/en-us/library/dd743066(VS.85).aspx */
-const AVMetadataConv ff_asf_metadata_conv[] = {
+static const AVMetadataConvTable asf_conv_table[] = {
     { "WM/AlbumArtist"     , "album_artist"},
     { "WM/AlbumTitle"      , "album"       },
     { "Author"             , "artist"      },
@@ -153,6 +153,10 @@ const AVMetadataConv ff_asf_metadata_conv[] = {
     { 0 }
 };
 
+const AVMetadataConv ff_asf_metadata_conv = {
+    asf_conv_table,
+};
+
 int ff_put_str16_nolen(ByteIOContext *s, const char *tag)
 {
     const uint8_t *q = tag;
diff --git a/libavformat/asf.h b/libavformat/asf.h
index 85e54cc..8469b99 100644
--- a/libavformat/asf.h
+++ b/libavformat/asf.h
@@ -165,7 +165,7 @@ extern const ff_asf_guid ff_asf_content_encryption;
 extern const ff_asf_guid ff_asf_ext_content_encryption;
 extern const ff_asf_guid ff_asf_digital_signature;
 
-extern const AVMetadataConv ff_asf_metadata_conv[];
+extern const AVMetadataConv ff_asf_metadata_conv;
 
 #define ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT 0x80 //1000 0000
 
diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
index b3533d1..071d6bc 100644
--- a/libavformat/asfdec.c
+++ b/libavformat/asfdec.c
@@ -1203,5 +1203,5 @@ AVInputFormat asf_demuxer = {
     asf_read_close,
     asf_read_seek,
     asf_read_pts,
-    .metadata_conv = ff_asf_metadata_conv,
+    .metadata_conv = &ff_asf_metadata_conv,
 };
diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c
index 9f8d69a..1194886 100644
--- a/libavformat/asfenc.c
+++ b/libavformat/asfenc.c
@@ -870,7 +870,7 @@ 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},
-    .metadata_conv = ff_asf_metadata_conv,
+    .metadata_conv = &ff_asf_metadata_conv,
 };
 #endif
 
@@ -892,6 +892,6 @@ 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},
-    .metadata_conv = ff_asf_metadata_conv,
+    .metadata_conv = &ff_asf_metadata_conv,
 };
 #endif //CONFIG_ASF_STREAM_MUXER
diff --git a/libavformat/avi.c b/libavformat/avi.c
index 705ad03..90eba73 100644
--- a/libavformat/avi.c
+++ b/libavformat/avi.c
@@ -21,7 +21,7 @@
 
 #include "avi.h"
 
-const AVMetadataConv ff_avi_metadata_conv[] = {
+static const AVMetadataConvTable avi_conv_table[] = {
     { "IART", "artist"    },
     { "ICMT", "comment"   },
     { "ICOP", "copyright" },
@@ -37,6 +37,10 @@ const AVMetadataConv ff_avi_metadata_conv[] = {
     { 0 },
 };
 
+const AVMetadataConv ff_avi_metadata_conv = {
+    avi_conv_table,
+};
+
 const char ff_avi_tags[][5] = {
     "IARL", "IART", "ICMS", "ICMT", "ICOP", "ICRD", "ICRP", "IDIM", "IDPI",
     "IENG", "IGNR", "IKEY", "ILGT", "ILNG", "IMED", "INAM", "IPLT", "IPRD",
diff --git a/libavformat/avi.h b/libavformat/avi.h
index f345c14..7867d5b 100644
--- a/libavformat/avi.h
+++ b/libavformat/avi.h
@@ -36,7 +36,7 @@
 /* index flags */
 #define AVIIF_INDEX             0x10
 
-extern const AVMetadataConv ff_avi_metadata_conv[];
+extern const AVMetadataConv ff_avi_metadata_conv;
 
 /**
  * A list of AVI info tags.
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 485c4eb..421b7b2 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -1194,5 +1194,5 @@ AVInputFormat avi_demuxer = {
     avi_read_packet,
     avi_read_close,
     avi_read_seek,
-    .metadata_conv = ff_avi_metadata_conv,
+    .metadata_conv = &ff_avi_metadata_conv,
 };
diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index b4a31ec..972332b 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -644,5 +644,5 @@ AVOutputFormat avi_muxer = {
     avi_write_trailer,
     .codec_tag= (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0},
     .flags= AVFMT_VARIABLE_FPS,
-    .metadata_conv = ff_avi_metadata_conv,
+    .metadata_conv = &ff_avi_metadata_conv,
 };
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 2ceef96..3601fb3 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -147,5 +147,5 @@ AVInputFormat flac_demuxer = {
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "flac",
     .value = CODEC_ID_FLAC,
-    .metadata_conv = ff_vorbiscomment_metadata_conv,
+    .metadata_conv = &ff_vorbiscomment_metadata_conv,
 };
diff --git a/libavformat/flacenc.c b/libavformat/flacenc.c
index 91a080f..630e0ee 100644
--- a/libavformat/flacenc.c
+++ b/libavformat/flacenc.c
@@ -128,5 +128,5 @@ AVOutputFormat flac_muxer = {
     flac_write_packet,
     flac_write_trailer,
     .flags= AVFMT_NOTIMESTAMPS,
-    .metadata_conv = ff_vorbiscomment_metadata_conv,
+    .metadata_conv = &ff_vorbiscomment_metadata_conv,
 };
diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 6fa11db..4831501 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -232,7 +232,7 @@ void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)
     url_fskip(s->pb, len);
 }
 
-const AVMetadataConv ff_id3v2_metadata_conv[] = {
+static const AVMetadataConvTable id3v2_conv_table[] = {
     { "TALB", "album"},
     { "TAL",  "album"},
     { "TCOM", "composer"},
@@ -263,6 +263,10 @@ const AVMetadataConv ff_id3v2_metadata_conv[] = {
     { 0 }
 };
 
+const AVMetadataConv ff_id3v2_metadata_conv = {
+    id3v2_conv_table,
+};
+
 const char ff_id3v2_tags[][4] = {
    "TALB", "TBPM", "TCOM", "TCON", "TCOP", "TDEN", "TDLY", "TDOR", "TDRC",
    "TDRL", "TDTG", "TENC", "TEXT", "TFLT", "TIPL", "TIT1", "TIT2", "TIT3",
diff --git a/libavformat/id3v2.h b/libavformat/id3v2.h
index 70030d2..96f8222 100644
--- a/libavformat/id3v2.h
+++ b/libavformat/id3v2.h
@@ -52,7 +52,7 @@ void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)
  */
 void ff_id3v2_read(AVFormatContext *s);
 
-extern const AVMetadataConv ff_id3v2_metadata_conv[];
+extern const AVMetadataConv ff_id3v2_metadata_conv;
 
 /**
  * A list of ID3v2.4 text information frames.
diff --git a/libavformat/matroska.c b/libavformat/matroska.c
index dac4735..4e7ed63 100644
--- a/libavformat/matroska.c
+++ b/libavformat/matroska.c
@@ -93,8 +93,12 @@ const CodecMime ff_mkv_mime_tags[] = {
     {""                           , CODEC_ID_NONE}
 };
 
-const AVMetadataConv ff_mkv_metadata_conv[] = {
+static const AVMetadataConvTable matroska_conv_table[] = {
     { "LEAD_PERFORMER", "performer" },
     { "PART_NUMBER"   , "track"  },
     { 0 }
 };
+
+const AVMetadataConv ff_mkv_metadata_conv = {
+    matroska_conv_table,
+};
diff --git a/libavformat/matroska.h b/libavformat/matroska.h
index 40ab3a7..9cd4cf5 100644
--- a/libavformat/matroska.h
+++ b/libavformat/matroska.h
@@ -236,6 +236,6 @@ typedef struct CodecMime{
 
 extern const CodecTags ff_mkv_codec_tags[];
 extern const CodecMime ff_mkv_mime_tags[];
-extern const AVMetadataConv ff_mkv_metadata_conv[];
+extern const AVMetadataConv ff_mkv_metadata_conv;
 
 #endif /* AVFORMAT_MATROSKA_H */
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 33e3d88..52b83ac 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1890,5 +1890,5 @@ AVInputFormat matroska_demuxer = {
     matroska_read_packet,
     matroska_read_close,
     matroska_read_seek,
-    .metadata_conv = ff_mkv_metadata_conv,
+    .metadata_conv = &ff_mkv_metadata_conv,
 };
diff --git a/libavformat/metadata.c b/libavformat/metadata.c
index ff7ffe9..30d1657 100644
--- a/libavformat/metadata.c
+++ b/libavformat/metadata.c
@@ -112,7 +112,7 @@ void metadata_conv(AVMetadata **pm, const AVMetadataConv *d_conv,
 {
     /* TODO: use binary search to look up the two conversion tables
        if the tables are getting big enough that it would matter speed wise */
-    const AVMetadataConv *sc, *dc;
+    const AVMetadataConvTable *sc, *dc;
     AVMetadataTag *mtag = NULL;
     AVMetadata *dst = NULL;
     const char *key;
@@ -120,14 +120,14 @@ void metadata_conv(AVMetadata **pm, const AVMetadataConv *d_conv,
     while((mtag=av_metadata_get(*pm, "", mtag, AV_METADATA_IGNORE_SUFFIX))) {
         key = mtag->key;
         if (s_conv != d_conv) {
-            if (s_conv)
-                for (sc=s_conv; sc->native; sc++)
+            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)
-                for (dc=d_conv; dc->native; dc++)
+            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;
diff --git a/libavformat/metadata.h b/libavformat/metadata.h
index fe7130e..309147d 100644
--- a/libavformat/metadata.h
+++ b/libavformat/metadata.h
@@ -35,9 +35,13 @@ struct AVMetadata{
     AVMetadataTag *elems;
 };
 
-struct AVMetadataConv{
+typedef struct AVMetadataConvTable {
     const char *native;
     const char *generic;
+} AVMetadataConvTable;
+
+struct AVMetadataConv {
+    const AVMetadataConvTable *conv_table;
 };
 
 #if LIBAVFORMAT_VERSION_MAJOR < 53
diff --git a/libavformat/mp3.c b/libavformat/mp3.c
index dcb59e8..023e1ad 100644
--- a/libavformat/mp3.c
+++ b/libavformat/mp3.c
@@ -191,7 +191,7 @@ AVInputFormat mp3_demuxer = {
     mp3_read_packet,
     .flags= AVFMT_GENERIC_INDEX,
     .extensions = "mp2,mp3,m2a", /* XXX: use probe */
-    .metadata_conv = ff_id3v2_metadata_conv,
+    .metadata_conv = &ff_id3v2_metadata_conv,
 };
 #endif
 
@@ -361,6 +361,6 @@ AVOutputFormat mp3_muxer = {
     mp3_write_packet,
     mp3_write_trailer,
     AVFMT_NOTIMESTAMPS,
-    .metadata_conv = ff_id3v2_metadata_conv,
+    .metadata_conv = &ff_id3v2_metadata_conv,
 };
 #endif
diff --git a/libavformat/nut.c b/libavformat/nut.c
index 7a85961..9291cfd 100644
--- a/libavformat/nut.c
+++ b/libavformat/nut.c
@@ -135,7 +135,7 @@ const Dispositions ff_nut_dispositions[] = {
     {""            , 0}
 };
 
-const AVMetadataConv ff_nut_metadata_conv[] = {
+static const AVMetadataConvTable nut_conv_table[] = {
     { "Author",         "artist"      },
     { "X-CreationTime", "date"        },
     { "CreationTime",   "date"        },
@@ -148,3 +148,7 @@ const AVMetadataConv ff_nut_metadata_conv[] = {
     { "X-UsesFont",     "usesfont"    },
     { 0 },
 };
+
+const AVMetadataConv ff_nut_metadata_conv = {
+    nut_conv_table,
+};
diff --git a/libavformat/nut.h b/libavformat/nut.h
index 7013fb1..d474ccc 100644
--- a/libavformat/nut.h
+++ b/libavformat/nut.h
@@ -115,6 +115,6 @@ void ff_nut_free_sp(NUTContext *nut);
 
 extern const Dispositions ff_nut_dispositions[];
 
-extern const AVMetadataConv ff_nut_metadata_conv[];
+extern const AVMetadataConv ff_nut_metadata_conv;
 
 #endif /* AVFORMAT_NUT_H */
diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index eed644c..190c687 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -925,7 +925,7 @@ AVInputFormat nut_demuxer = {
     nut_read_close,
     read_seek,
     .extensions = "nut",
-    .metadata_conv = ff_nut_metadata_conv,
+    .metadata_conv = &ff_nut_metadata_conv,
     .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 469672b..99def44 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -825,5 +825,5 @@ 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 },
-    .metadata_conv = ff_nut_metadata_conv,
+    .metadata_conv = &ff_nut_metadata_conv,
 };
diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c
index 3161e68..9a8b1e1 100644
--- a/libavformat/oggdec.c
+++ b/libavformat/oggdec.c
@@ -641,6 +641,6 @@ AVInputFormat ogg_demuxer = {
     ogg_read_seek,
     ogg_read_timestamp,
     .extensions = "ogg",
-    .metadata_conv = ff_vorbiscomment_metadata_conv,
+    .metadata_conv = &ff_vorbiscomment_metadata_conv,
     .flags = AVFMT_GENERIC_INDEX,
 };
diff --git a/libavformat/oggenc.c b/libavformat/oggenc.c
index c35b497..7194c66 100644
--- a/libavformat/oggenc.c
+++ b/libavformat/oggenc.c
@@ -462,5 +462,5 @@ AVOutputFormat ogg_muxer = {
     ogg_write_header,
     ogg_write_packet,
     ogg_write_trailer,
-    .metadata_conv = ff_vorbiscomment_metadata_conv,
+    .metadata_conv = &ff_vorbiscomment_metadata_conv,
 };
diff --git a/libavformat/vorbiscomment.c b/libavformat/vorbiscomment.c
index d23c66d..836f006 100644
--- a/libavformat/vorbiscomment.c
+++ b/libavformat/vorbiscomment.c
@@ -29,12 +29,16 @@
  * from Ogg Vorbis I format specification: comment field and header specification
  * http://xiph.org/vorbis/doc/v-comment.html
  */
-const AVMetadataConv ff_vorbiscomment_metadata_conv[] = {
+static const AVMetadataConvTable vorbiscomment_conv_table[] = {
     { "ALBUMARTIST", "album_artist"},
     { "TRACKNUMBER", "track"  },
     { 0 }
 };
 
+const AVMetadataConv ff_vorbiscomment_metadata_conv = {
+    vorbiscomment_conv_table,
+};
+
 int ff_vorbiscomment_length(AVMetadata *m, const char *vendor_string,
                             unsigned *count)
 {
diff --git a/libavformat/vorbiscomment.h b/libavformat/vorbiscomment.h
index 714f1f2..bf822be 100644
--- a/libavformat/vorbiscomment.h
+++ b/libavformat/vorbiscomment.h
@@ -52,6 +52,6 @@ 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);
 
-extern const AVMetadataConv ff_vorbiscomment_metadata_conv[];
+extern const AVMetadataConv ff_vorbiscomment_metadata_conv;
 
 #endif /* AVFORMAT_VORBISCOMMENT_H */
-- 
1.7.1




More information about the ffmpeg-devel mailing list