changeset 1677:2a85c82b8538 libavformat

add codec_id <-> codec_tag tables to AVIn/OutputFormat
author michael
date Sun, 21 Jan 2007 01:39:17 +0000
parents 507177b7444c
children 71078c1009c4
files aiff.c asf-enc.c au.c avformat.h avienc.c flvenc.c gxfenc.c isom.c isom.h libnut.c mov.c movenc.c nsvdec.c riff.c riff.h swf.c voc.c voc.h wav.c
diffstat 19 files changed, 95 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/aiff.c	Sat Jan 20 23:09:27 2007 +0000
+++ b/aiff.c	Sun Jan 21 01:39:17 2007 +0000
@@ -23,7 +23,7 @@
 #include "riff.h"
 #include "intfloat_readwrite.h"
 
-static const CodecTag codec_aiff_tags[] = {
+static const AVCodecTag codec_aiff_tags[] = {
     { CODEC_ID_PCM_S16BE, MKTAG('N','O','N','E') },
     { CODEC_ID_PCM_S8, MKTAG('N','O','N','E') },
     { CODEC_ID_PCM_S24BE, MKTAG('N','O','N','E') },
--- a/asf-enc.c	Sat Jan 20 23:09:27 2007 +0000
+++ b/asf-enc.c	Sun Jan 21 01:39:17 2007 +0000
@@ -187,6 +187,13 @@
                 2*PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS \
                 )
 
+static const AVCodecTag codec_asf_bmp_tags[] = {
+    { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
+    { CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
+    { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
+    { CODEC_ID_NONE, 0 },
+};
+
 static int preroll_time = 2000;
 
 static const uint8_t error_spread_ADPCM_G726[] = { 0x01, 0x90, 0x01, 0x90, 0x01, 0x01, 0x00, 0x00 };
@@ -842,6 +849,7 @@
     asf_write_packet,
     asf_write_trailer,
     .flags = AVFMT_GLOBALHEADER,
+    .codec_tag= {codec_asf_bmp_tags, codec_bmp_tags, codec_wav_tags},
 };
 #endif
 
@@ -862,5 +870,6 @@
     asf_write_packet,
     asf_write_trailer,
     .flags = AVFMT_GLOBALHEADER,
+    .codec_tag= {codec_asf_bmp_tags, codec_bmp_tags, codec_wav_tags},
 };
 #endif //CONFIG_ASF_STREAM_MUXER
--- a/au.c	Sat Jan 20 23:09:27 2007 +0000
+++ b/au.c	Sun Jan 21 01:39:17 2007 +0000
@@ -35,7 +35,7 @@
 #define AU_UNKOWN_SIZE ((uint32_t)(~0))
 
 /* The ffmpeg codecs we support, and the IDs they have in the file */
-static const CodecTag codec_au_tags[] = {
+static const AVCodecTag codec_au_tags[] = {
     { CODEC_ID_PCM_MULAW, 1 },
     { CODEC_ID_PCM_S16BE, 3 },
     { CODEC_ID_PCM_ALAW, 27 },
--- a/avformat.h	Sat Jan 20 23:09:27 2007 +0000
+++ b/avformat.h	Sun Jan 21 01:39:17 2007 +0000
@@ -25,8 +25,8 @@
 extern "C" {
 #endif
 
-#define LIBAVFORMAT_VERSION_INT ((51<<16)+(7<<8)+0)
-#define LIBAVFORMAT_VERSION     51.7.0
+#define LIBAVFORMAT_VERSION_INT ((51<<16)+(8<<8)+0)
+#define LIBAVFORMAT_VERSION     51.8.0
 #define LIBAVFORMAT_BUILD       LIBAVFORMAT_VERSION_INT
 
 #define LIBAVFORMAT_IDENT       "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
@@ -96,6 +96,8 @@
 /*************************************************/
 /* input/output formats */
 
+struct AVCodecTag;
+
 struct AVFormatContext;
 
 /* this structure contains the data a format has to probe a file */
@@ -155,6 +157,13 @@
     /* currently only used to set pixel format if not YUV420P */
     int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
     int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, AVPacket *in, int flush);
+
+    /**
+     * list of supported codec_id-codec_tag pairs, ordered by "better choice first"
+     * the arrays are all CODEC_ID_NONE terminated
+     */
+    const struct AVCodecTag *codec_tag[4];
+
     /* private fields */
     struct AVOutputFormat *next;
 } AVOutputFormat;
@@ -210,6 +219,8 @@
        (RTSP) */
     int (*read_pause)(struct AVFormatContext *);
 
+    const struct AVCodecTag *codec_tag[4];
+
     /* private fields */
     struct AVInputFormat *next;
 } AVInputFormat;
@@ -396,6 +407,10 @@
 
 void av_register_all(void);
 
+/* codec tag <-> codec id */
+enum CodecID av_codec_get_id(const struct AVCodecTag *tags[4], unsigned int tag);
+unsigned int av_codec_get_tag(const struct AVCodecTag *tags[4], enum CodecID id);
+
 /* media file input */
 AVInputFormat *av_find_input_format(const char *short_name);
 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
--- a/avienc.c	Sat Jan 20 23:09:27 2007 +0000
+++ b/avienc.c	Sun Jan 21 01:39:17 2007 +0000
@@ -575,5 +575,6 @@
     avi_write_header,
     avi_write_packet,
     avi_write_trailer,
+    .codec_tag= {codec_bmp_tags, codec_wav_tags},
 };
 #endif //CONFIG_AVI_MUXER
--- a/flvenc.c	Sat Jan 20 23:09:27 2007 +0000
+++ b/flvenc.c	Sun Jan 21 01:39:17 2007 +0000
@@ -25,7 +25,7 @@
 #undef NDEBUG
 #include <assert.h>
 
-static const CodecTag flv_video_codec_ids[] = {
+static const AVCodecTag flv_video_codec_ids[] = {
     {CODEC_ID_FLV1,    FLV_CODECID_H263  },
     {CODEC_ID_FLASHSV, FLV_CODECID_SCREEN},
     {CODEC_ID_VP6F,    FLV_CODECID_VP6   },
@@ -33,7 +33,7 @@
     {CODEC_ID_NONE,    0}
 };
 
-static const CodecTag flv_audio_codec_ids[] = {
+static const AVCodecTag flv_audio_codec_ids[] = {
     {CODEC_ID_MP3,       FLV_CODECID_MP3    >> FLV_AUDIO_CODECID_OFFSET},
     {CODEC_ID_PCM_S8,    FLV_CODECID_PCM_BE >> FLV_AUDIO_CODECID_OFFSET},
     {CODEC_ID_PCM_S16BE, FLV_CODECID_PCM_BE >> FLV_AUDIO_CODECID_OFFSET},
--- a/gxfenc.c	Sat Jan 20 23:09:27 2007 +0000
+++ b/gxfenc.c	Sun Jan 21 01:39:17 2007 +0000
@@ -85,7 +85,7 @@
     { 720,  6 },
 };
 
-static const CodecTag gxf_media_types[] = {
+static const AVCodecTag gxf_media_types[] = {
     { CODEC_ID_MJPEG     ,   3 }, /* NTSC */
     { CODEC_ID_MJPEG     ,   4 }, /* PAL */
     { CODEC_ID_PCM_S24LE ,   9 },
--- a/isom.c	Sat Jan 20 23:09:27 2007 +0000
+++ b/isom.c	Sun Jan 21 01:39:17 2007 +0000
@@ -26,7 +26,7 @@
 #include "isom.h"
 
 /* http://gpac.sourceforge.net/tutorial/mediatypes.htm */
-const CodecTag ff_mov_obj_type[] = {
+const AVCodecTag ff_mov_obj_type[] = {
     { CODEC_ID_MPEG4     ,  32 },
     { CODEC_ID_H264      ,  33 },
     { CODEC_ID_AAC       ,  64 },
--- a/isom.h	Sat Jan 20 23:09:27 2007 +0000
+++ b/isom.h	Sun Jan 21 01:39:17 2007 +0000
@@ -25,7 +25,7 @@
 #define FFMPEG_ISOM_H
 
 /* isom.c */
-extern const CodecTag ff_mov_obj_type[];
+extern const AVCodecTag ff_mov_obj_type[];
 
 int ff_mov_iso639_to_lang(const char *lang, int mp4);
 int ff_mov_lang_to_iso639(int code, char *to);
--- a/libnut.c	Sat Jan 20 23:09:27 2007 +0000
+++ b/libnut.c	Sun Jan 21 01:39:17 2007 +0000
@@ -10,7 +10,7 @@
     nut_stream_header_t * s;
 } NUTContext;
 
-static const CodecTag nut_tags[] = {
+static const AVCodecTag nut_tags[] = {
     { CODEC_ID_MPEG4,  MKTAG('m', 'p', '4', 'v') },
     { CODEC_ID_MP3,    MKTAG('m', 'p', '3', ' ') },
     { CODEC_ID_VORBIS, MKTAG('v', 'r', 'b', 's') },
--- a/mov.c	Sat Jan 20 23:09:27 2007 +0000
+++ b/mov.c	Sun Jan 21 01:39:17 2007 +0000
@@ -66,7 +66,7 @@
 #undef NDEBUG
 #include <assert.h>
 
-static const CodecTag mov_video_tags[] = {
+static const AVCodecTag mov_video_tags[] = {
 /*  { CODEC_ID_, MKTAG('c', 'v', 'i', 'd') }, *//* Cinepak */
 /*  { CODEC_ID_H263, MKTAG('r', 'a', 'w', ' ') }, *//* Uncompressed RGB */
 /*  { CODEC_ID_H263, MKTAG('Y', 'u', 'v', '2') }, *//* Uncompressed YUV422 */
@@ -127,7 +127,7 @@
     { CODEC_ID_NONE, 0 },
 };
 
-static const CodecTag mov_audio_tags[] = {
+static const AVCodecTag mov_audio_tags[] = {
     { CODEC_ID_PCM_S32BE, MKTAG('i', 'n', '3', '2') },
     { CODEC_ID_PCM_S24BE, MKTAG('i', 'n', '2', '4') },
     { CODEC_ID_PCM_S16BE, MKTAG('N', 'O', 'N', 'E') }, /* uncompressed */
--- a/movenc.c	Sat Jan 20 23:09:27 2007 +0000
+++ b/movenc.c	Sun Jan 21 01:39:17 2007 +0000
@@ -322,7 +322,7 @@
     return updateSize (pb, pos);
 }
 
-static const CodecTag codec_movaudio_tags[] = {
+static const AVCodecTag codec_movaudio_tags[] = {
     { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') },
     { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') },
     { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') },
@@ -526,7 +526,7 @@
     return updateSize(pb, pos);
 }
 
-static const CodecTag codec_movvideo_tags[] = {
+static const AVCodecTag codec_movvideo_tags[] = {
     { CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') },
     { CODEC_ID_SVQ3, MKTAG('S', 'V', 'Q', '3') },
     { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
--- a/nsvdec.c	Sat Jan 20 23:09:27 2007 +0000
+++ b/nsvdec.c	Sun Jan 21 01:39:17 2007 +0000
@@ -183,7 +183,7 @@
     //DVDemuxContext* dv_demux;
 } NSVContext;
 
-static const CodecTag nsv_codec_video_tags[] = {
+static const AVCodecTag nsv_codec_video_tags[] = {
     { CODEC_ID_VP3, MKTAG('V', 'P', '3', ' ') },
     { CODEC_ID_VP3, MKTAG('V', 'P', '3', '0') },
     { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') },
@@ -202,7 +202,7 @@
     { 0, 0 },
 };
 
-static const CodecTag nsv_codec_audio_tags[] = {
+static const AVCodecTag nsv_codec_audio_tags[] = {
     { CODEC_ID_MP3, MKTAG('M', 'P', '3', ' ') },
     { CODEC_ID_AAC, MKTAG('A', 'A', 'C', ' ') },
     { CODEC_ID_AAC, MKTAG('A', 'A', 'C', 'P') }, /* _CUTTED__MUXED_2 Heads - Out Of The City.nsv */
--- a/riff.c	Sat Jan 20 23:09:27 2007 +0000
+++ b/riff.c	Sun Jan 21 01:39:17 2007 +0000
@@ -22,10 +22,11 @@
 #include "avformat.h"
 #include "avcodec.h"
 #include "riff.h"
+#include "allformats.h" // for asf_muxer
 
 /* Note: when encoding, the first matching tag is used, so order is
    important if multiple tags possible for a given codec. */
-const CodecTag codec_bmp_tags[] = {
+const AVCodecTag codec_bmp_tags[] = {
     { CODEC_ID_H264, MKTAG('H', '2', '6', '4') },
     { CODEC_ID_H264, MKTAG('h', '2', '6', '4') },
     { CODEC_ID_H264, MKTAG('X', '2', '6', '4') },
@@ -42,10 +43,10 @@
     { CODEC_ID_H263P, MKTAG('U', '2', '6', '3') },
     { CODEC_ID_H263P, MKTAG('v', 'i', 'v', '1') },
 
-    { CODEC_ID_MPEG4, MKTAG('F', 'M', 'P', '4')},
-    { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X'), .invalid_asf = 1 },
-    { CODEC_ID_MPEG4, MKTAG('D', 'X', '5', '0'), .invalid_asf = 1 },
-    { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D'), .invalid_asf = 1 },
+    { CODEC_ID_MPEG4, MKTAG('F', 'M', 'P', '4') },
+    { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') },
+    { CODEC_ID_MPEG4, MKTAG('D', 'X', '5', '0') },
+    { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D') },
     { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
     { CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
     { CODEC_ID_MPEG4, MKTAG(0x04, 0, 0, 0) }, /* some broken avi use this */
@@ -60,7 +61,7 @@
 
     { CODEC_ID_MPEG4, MKTAG('R', 'M', 'P', '4') },
 
-    { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3'), .invalid_asf = 1 }, /* default signature when using MSMPEG4 */
+    { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3') }, /* default signature when using MSMPEG4 */
     { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
 
     /* added based on MPlayer */
@@ -168,7 +169,7 @@
     { CODEC_ID_NONE, 0 },
 };
 
-const CodecTag codec_wav_tags[] = {
+const AVCodecTag codec_wav_tags[] = {
     { CODEC_ID_MP2, 0x50 },
     { CODEC_ID_MP3, 0x55 },
     { CODEC_ID_AC3, 0x2000 },
@@ -206,7 +207,7 @@
     { 0, 0 },
 };
 
-unsigned int codec_get_tag(const CodecTag *tags, int id)
+unsigned int codec_get_tag(const AVCodecTag *tags, int id)
 {
     while (tags->id != CODEC_ID_NONE) {
         if (tags->id == id)
@@ -216,17 +217,7 @@
     return 0;
 }
 
-unsigned int codec_get_asf_tag(const CodecTag *tags, unsigned int id)
-{
-    while (tags->id != CODEC_ID_NONE) {
-        if (!tags->invalid_asf && tags->id == id)
-            return tags->tag;
-        tags++;
-    }
-    return 0;
-}
-
-enum CodecID codec_get_id(const CodecTag *tags, unsigned int tag)
+enum CodecID codec_get_id(const AVCodecTag *tags, unsigned int tag)
 {
     while (tags->id != CODEC_ID_NONE) {
         if(   toupper((tag >> 0)&0xFF) == toupper((tags->tag >> 0)&0xFF)
@@ -239,6 +230,26 @@
     return CODEC_ID_NONE;
 }
 
+unsigned int av_codec_get_tag(const AVCodecTag *tags[4], enum CodecID id)
+{
+    int i;
+    for(i=0; i<4 && tags[i]; i++){
+        int tag= codec_get_tag(tags[i], id);
+        if(tag) return tag;
+    }
+    return 0;
+}
+
+enum CodecID av_codec_get_id(const AVCodecTag *tags[4], unsigned int tag)
+{
+    int i;
+    for(i=0; i<4 && tags[i]; i++){
+        enum CodecID id= codec_get_id(tags[i], tag);
+        if(id!=CODEC_ID_NONE) return id;
+    }
+    return CODEC_ID_NONE;
+}
+
 unsigned int codec_get_bmp_tag(int id)
 {
     return codec_get_tag(codec_bmp_tags, id);
@@ -367,7 +378,7 @@
 }
 
 /* BITMAPINFOHEADER header */
-void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const CodecTag *tags, int for_asf)
+void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf)
 {
     put_le32(pb, 40 + enc->extradata_size); /* size */
     put_le32(pb, enc->width);
@@ -376,7 +387,7 @@
 
     put_le16(pb, enc->bits_per_sample ? enc->bits_per_sample : 24); /* depth */
     /* compression type */
-    put_le32(pb, for_asf ? (enc->codec_tag ? enc->codec_tag : codec_get_asf_tag(tags, enc->codec_id)) : enc->codec_tag); //
+    put_le32(pb, for_asf ? (enc->codec_tag ? enc->codec_tag : av_codec_get_tag(asf_muxer.codec_tag, enc->codec_id)) : enc->codec_tag); //
     put_le32(pb, enc->width * enc->height * 3);
     put_le32(pb, 0);
     put_le32(pb, 0);
--- a/riff.h	Sat Jan 20 23:09:27 2007 +0000
+++ b/riff.h	Sun Jan 21 01:39:17 2007 +0000
@@ -19,33 +19,37 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+/**
+ * @file riff.h
+ * internal header for RIFF based (de)muxers
+ * do NOT include this in end user applications
+ */
+
 #ifndef FF_RIFF_H
 #define FF_RIFF_H
 
 offset_t start_tag(ByteIOContext *pb, const char *tag);
 void end_tag(ByteIOContext *pb, offset_t start);
 
-typedef struct CodecTag {
+typedef struct AVCodecTag {
     int id;
     unsigned int tag;
-    unsigned int invalid_asf : 1;
-} CodecTag;
+} AVCodecTag;
 
-void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const CodecTag *tags, int for_asf);
+void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf);
 int put_wav_header(ByteIOContext *pb, AVCodecContext *enc);
 int wav_codec_get_id(unsigned int tag, int bps);
 void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size);
 
-extern const CodecTag codec_bmp_tags[];
-extern const CodecTag codec_wav_tags[];
+extern const AVCodecTag codec_bmp_tags[];
+extern const AVCodecTag codec_wav_tags[];
 
-unsigned int codec_get_tag(const CodecTag *tags, int id);
-enum CodecID codec_get_id(const CodecTag *tags, unsigned int tag);
-unsigned int codec_get_bmp_tag(int id);
-unsigned int codec_get_wav_tag(int id);
-enum CodecID codec_get_bmp_id(unsigned int tag);
-enum CodecID codec_get_wav_id(unsigned int tag);
-unsigned int codec_get_asf_tag(const CodecTag *tags, unsigned int id);
+unsigned int codec_get_tag(const AVCodecTag *tags, int id);
+enum CodecID codec_get_id(const AVCodecTag *tags, unsigned int tag);
+unsigned int codec_get_bmp_tag(int id) attribute_deprecated; //use av_codec_get_tag
+unsigned int codec_get_wav_tag(int id) attribute_deprecated; //use av_codec_get_tag
+enum CodecID codec_get_bmp_id(unsigned int tag) attribute_deprecated; //use av_codec_get_id
+enum CodecID codec_get_wav_id(unsigned int tag) attribute_deprecated; //use av_codec_get_id
 void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale);
 
 #endif
--- a/swf.c	Sat Jan 20 23:09:27 2007 +0000
+++ b/swf.c	Sun Jan 21 01:39:17 2007 +0000
@@ -80,7 +80,7 @@
     int audio_type;
 } SWFContext;
 
-static const CodecTag swf_codec_tags[] = {
+static const AVCodecTag swf_codec_tags[] = {
     {CODEC_ID_FLV1, 0x02},
     {CODEC_ID_VP6F, 0x04},
     {0, 0},
--- a/voc.c	Sat Jan 20 23:09:27 2007 +0000
+++ b/voc.c	Sun Jan 21 01:39:17 2007 +0000
@@ -23,7 +23,7 @@
 
 const unsigned char voc_magic[21] = "Creative Voice File\x1A";
 
-const CodecTag voc_codec_tags[] = {
+const AVCodecTag voc_codec_tags[] = {
     {CODEC_ID_PCM_U8,        0x00},
     {CODEC_ID_ADPCM_SBPRO_4, 0x01},
     {CODEC_ID_ADPCM_SBPRO_3, 0x02},
--- a/voc.h	Sat Jan 20 23:09:27 2007 +0000
+++ b/voc.h	Sun Jan 21 01:39:17 2007 +0000
@@ -43,7 +43,7 @@
 } voc_type_t;
 
 extern const unsigned char voc_magic[21];
-extern const CodecTag voc_codec_tags[];
+extern const AVCodecTag voc_codec_tags[];
 
 int voc_get_packet(AVFormatContext *s, AVPacket *pkt,
                    AVStream *st, int max_size);
--- a/wav.c	Sat Jan 20 23:09:27 2007 +0000
+++ b/wav.c	Sun Jan 21 01:39:17 2007 +0000
@@ -235,6 +235,7 @@
     wav_read_packet,
     wav_read_close,
     wav_read_seek,
+    .codec_tag= {codec_wav_tags},
 };
 #endif
 #ifdef CONFIG_WAV_MUXER
@@ -249,5 +250,6 @@
     wav_write_header,
     wav_write_packet,
     wav_write_trailer,
+    .codec_tag= {codec_wav_tags},
 };
 #endif