comparison riff.c @ 1677:2a85c82b8538 libavformat

add codec_id <-> codec_tag tables to AVIn/OutputFormat
author michael
date Sun, 21 Jan 2007 01:39:17 +0000
parents 6f13826a5037
children ba58d49d4685
comparison
equal deleted inserted replaced
1676:507177b7444c 1677:2a85c82b8538
20 */ 20 */
21 21
22 #include "avformat.h" 22 #include "avformat.h"
23 #include "avcodec.h" 23 #include "avcodec.h"
24 #include "riff.h" 24 #include "riff.h"
25 #include "allformats.h" // for asf_muxer
25 26
26 /* Note: when encoding, the first matching tag is used, so order is 27 /* Note: when encoding, the first matching tag is used, so order is
27 important if multiple tags possible for a given codec. */ 28 important if multiple tags possible for a given codec. */
28 const CodecTag codec_bmp_tags[] = { 29 const AVCodecTag codec_bmp_tags[] = {
29 { CODEC_ID_H264, MKTAG('H', '2', '6', '4') }, 30 { CODEC_ID_H264, MKTAG('H', '2', '6', '4') },
30 { CODEC_ID_H264, MKTAG('h', '2', '6', '4') }, 31 { CODEC_ID_H264, MKTAG('h', '2', '6', '4') },
31 { CODEC_ID_H264, MKTAG('X', '2', '6', '4') }, 32 { CODEC_ID_H264, MKTAG('X', '2', '6', '4') },
32 { CODEC_ID_H264, MKTAG('x', '2', '6', '4') }, 33 { CODEC_ID_H264, MKTAG('x', '2', '6', '4') },
33 { CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') }, 34 { CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') },
40 41
41 /* added based on MPlayer */ 42 /* added based on MPlayer */
42 { CODEC_ID_H263P, MKTAG('U', '2', '6', '3') }, 43 { CODEC_ID_H263P, MKTAG('U', '2', '6', '3') },
43 { CODEC_ID_H263P, MKTAG('v', 'i', 'v', '1') }, 44 { CODEC_ID_H263P, MKTAG('v', 'i', 'v', '1') },
44 45
45 { CODEC_ID_MPEG4, MKTAG('F', 'M', 'P', '4')}, 46 { CODEC_ID_MPEG4, MKTAG('F', 'M', 'P', '4') },
46 { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X'), .invalid_asf = 1 }, 47 { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') },
47 { CODEC_ID_MPEG4, MKTAG('D', 'X', '5', '0'), .invalid_asf = 1 }, 48 { CODEC_ID_MPEG4, MKTAG('D', 'X', '5', '0') },
48 { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D'), .invalid_asf = 1 }, 49 { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D') },
49 { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') }, 50 { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
50 { CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') }, 51 { CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
51 { CODEC_ID_MPEG4, MKTAG(0x04, 0, 0, 0) }, /* some broken avi use this */ 52 { CODEC_ID_MPEG4, MKTAG(0x04, 0, 0, 0) }, /* some broken avi use this */
52 53
53 /* added based on MPlayer */ 54 /* added based on MPlayer */
58 { CODEC_ID_MPEG4, MKTAG('W', 'V', '1', 'F') }, 59 { CODEC_ID_MPEG4, MKTAG('W', 'V', '1', 'F') },
59 { CODEC_ID_MPEG4, MKTAG('S', 'E', 'D', 'G') }, 60 { CODEC_ID_MPEG4, MKTAG('S', 'E', 'D', 'G') },
60 61
61 { CODEC_ID_MPEG4, MKTAG('R', 'M', 'P', '4') }, 62 { CODEC_ID_MPEG4, MKTAG('R', 'M', 'P', '4') },
62 63
63 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3'), .invalid_asf = 1 }, /* default signature when using MSMPEG4 */ 64 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3') }, /* default signature when using MSMPEG4 */
64 { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') }, 65 { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
65 66
66 /* added based on MPlayer */ 67 /* added based on MPlayer */
67 { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', 'G', '3') }, 68 { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', 'G', '3') },
68 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '5') }, 69 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '5') },
166 { CODEC_ID_JPEG2000, MKTAG('M', 'J', '2', 'C') }, 167 { CODEC_ID_JPEG2000, MKTAG('M', 'J', '2', 'C') },
167 { CODEC_ID_VMNC, MKTAG('V', 'M', 'n', 'c') }, 168 { CODEC_ID_VMNC, MKTAG('V', 'M', 'n', 'c') },
168 { CODEC_ID_NONE, 0 }, 169 { CODEC_ID_NONE, 0 },
169 }; 170 };
170 171
171 const CodecTag codec_wav_tags[] = { 172 const AVCodecTag codec_wav_tags[] = {
172 { CODEC_ID_MP2, 0x50 }, 173 { CODEC_ID_MP2, 0x50 },
173 { CODEC_ID_MP3, 0x55 }, 174 { CODEC_ID_MP3, 0x55 },
174 { CODEC_ID_AC3, 0x2000 }, 175 { CODEC_ID_AC3, 0x2000 },
175 { CODEC_ID_DTS, 0x2001 }, 176 { CODEC_ID_DTS, 0x2001 },
176 { CODEC_ID_PCM_S16LE, 0x01 }, 177 { CODEC_ID_PCM_S16LE, 0x01 },
204 { CODEC_ID_MP3, MKTAG('L', 'A', 'M', 'E') }, 205 { CODEC_ID_MP3, MKTAG('L', 'A', 'M', 'E') },
205 { CODEC_ID_MP3, MKTAG('M', 'P', '3', ' ') }, 206 { CODEC_ID_MP3, MKTAG('M', 'P', '3', ' ') },
206 { 0, 0 }, 207 { 0, 0 },
207 }; 208 };
208 209
209 unsigned int codec_get_tag(const CodecTag *tags, int id) 210 unsigned int codec_get_tag(const AVCodecTag *tags, int id)
210 { 211 {
211 while (tags->id != CODEC_ID_NONE) { 212 while (tags->id != CODEC_ID_NONE) {
212 if (tags->id == id) 213 if (tags->id == id)
213 return tags->tag; 214 return tags->tag;
214 tags++; 215 tags++;
215 } 216 }
216 return 0; 217 return 0;
217 } 218 }
218 219
219 unsigned int codec_get_asf_tag(const CodecTag *tags, unsigned int id) 220 enum CodecID codec_get_id(const AVCodecTag *tags, unsigned int tag)
220 {
221 while (tags->id != CODEC_ID_NONE) {
222 if (!tags->invalid_asf && tags->id == id)
223 return tags->tag;
224 tags++;
225 }
226 return 0;
227 }
228
229 enum CodecID codec_get_id(const CodecTag *tags, unsigned int tag)
230 { 221 {
231 while (tags->id != CODEC_ID_NONE) { 222 while (tags->id != CODEC_ID_NONE) {
232 if( toupper((tag >> 0)&0xFF) == toupper((tags->tag >> 0)&0xFF) 223 if( toupper((tag >> 0)&0xFF) == toupper((tags->tag >> 0)&0xFF)
233 && toupper((tag >> 8)&0xFF) == toupper((tags->tag >> 8)&0xFF) 224 && toupper((tag >> 8)&0xFF) == toupper((tags->tag >> 8)&0xFF)
234 && toupper((tag >>16)&0xFF) == toupper((tags->tag >>16)&0xFF) 225 && toupper((tag >>16)&0xFF) == toupper((tags->tag >>16)&0xFF)
235 && toupper((tag >>24)&0xFF) == toupper((tags->tag >>24)&0xFF)) 226 && toupper((tag >>24)&0xFF) == toupper((tags->tag >>24)&0xFF))
236 return tags->id; 227 return tags->id;
237 tags++; 228 tags++;
229 }
230 return CODEC_ID_NONE;
231 }
232
233 unsigned int av_codec_get_tag(const AVCodecTag *tags[4], enum CodecID id)
234 {
235 int i;
236 for(i=0; i<4 && tags[i]; i++){
237 int tag= codec_get_tag(tags[i], id);
238 if(tag) return tag;
239 }
240 return 0;
241 }
242
243 enum CodecID av_codec_get_id(const AVCodecTag *tags[4], unsigned int tag)
244 {
245 int i;
246 for(i=0; i<4 && tags[i]; i++){
247 enum CodecID id= codec_get_id(tags[i], tag);
248 if(id!=CODEC_ID_NONE) return id;
238 } 249 }
239 return CODEC_ID_NONE; 250 return CODEC_ID_NONE;
240 } 251 }
241 252
242 unsigned int codec_get_bmp_tag(int id) 253 unsigned int codec_get_bmp_tag(int id)
365 376
366 return hdrsize; 377 return hdrsize;
367 } 378 }
368 379
369 /* BITMAPINFOHEADER header */ 380 /* BITMAPINFOHEADER header */
370 void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const CodecTag *tags, int for_asf) 381 void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf)
371 { 382 {
372 put_le32(pb, 40 + enc->extradata_size); /* size */ 383 put_le32(pb, 40 + enc->extradata_size); /* size */
373 put_le32(pb, enc->width); 384 put_le32(pb, enc->width);
374 put_le32(pb, enc->height); 385 put_le32(pb, enc->height);
375 put_le16(pb, 1); /* planes */ 386 put_le16(pb, 1); /* planes */
376 387
377 put_le16(pb, enc->bits_per_sample ? enc->bits_per_sample : 24); /* depth */ 388 put_le16(pb, enc->bits_per_sample ? enc->bits_per_sample : 24); /* depth */
378 /* compression type */ 389 /* compression type */
379 put_le32(pb, for_asf ? (enc->codec_tag ? enc->codec_tag : codec_get_asf_tag(tags, enc->codec_id)) : enc->codec_tag); // 390 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); //
380 put_le32(pb, enc->width * enc->height * 3); 391 put_le32(pb, enc->width * enc->height * 3);
381 put_le32(pb, 0); 392 put_le32(pb, 0);
382 put_le32(pb, 0); 393 put_le32(pb, 0);
383 put_le32(pb, 0); 394 put_le32(pb, 0);
384 put_le32(pb, 0); 395 put_le32(pb, 0);