comparison isom.c @ 1216:fec0a3d5408f libavformat

move common code from mov.c and movenc.c to isom.c
author bcoudurier
date Tue, 01 Aug 2006 14:58:15 +0000
parents
children 874dcd428a17
comparison
equal deleted inserted replaced
1215:eee822269f39 1216:fec0a3d5408f
1 /*
2 * ISO Media common code
3 * Copyright (c) 2001 Fabrice Bellard.
4 * Copyright (c) 2002 Francois Revol <revol@free.fr>
5 * Copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "avformat.h"
23 #include "riff.h"
24 #include "isom.h"
25
26 /* http://gpac.sourceforge.net/tutorial/mediatypes.htm */
27 const CodecTag ff_mov_obj_type[] = {
28 { CODEC_ID_MPEG4 , 32 },
29 { CODEC_ID_H264 , 33 },
30 { CODEC_ID_AAC , 64 },
31 { CODEC_ID_MPEG2VIDEO, 96 }, /* MPEG2 Simple */
32 { CODEC_ID_MPEG2VIDEO, 97 }, /* MPEG2 Main */
33 { CODEC_ID_MPEG2VIDEO, 98 }, /* MPEG2 SNR */
34 { CODEC_ID_MPEG2VIDEO, 99 }, /* MPEG2 Spatial */
35 { CODEC_ID_MPEG2VIDEO, 100 }, /* MPEG2 High */
36 { CODEC_ID_MPEG2VIDEO, 101 }, /* MPEG2 422 */
37 { CODEC_ID_AAC , 102 }, /* MPEG2 AAC Main */
38 { CODEC_ID_AAC , 103 }, /* MPEG2 AAC Low */
39 { CODEC_ID_AAC , 104 }, /* MPEG2 AAC SSR */
40 { CODEC_ID_MP3 , 105 },
41 { CODEC_ID_MPEG1VIDEO, 106 },
42 { CODEC_ID_MP2 , 107 },
43 { CODEC_ID_MJPEG , 108 },
44 { CODEC_ID_PCM_S16LE , 224 },
45 { CODEC_ID_VORBIS , 221 },
46 { CODEC_ID_AC3 , 226 },
47 { CODEC_ID_PCM_ALAW , 227 },
48 { CODEC_ID_PCM_MULAW , 228 },
49 { CODEC_ID_PCM_S16BE , 230 },
50 { CODEC_ID_H263 , 242 },
51 { CODEC_ID_H261 , 243 },
52 { 0, 0 },
53 };
54
55 /* map numeric codes from mdhd atom to ISO 639 */
56 /* cf. QTFileFormat.pdf p253, qtff.pdf p205 */
57 /* http://developer.apple.com/documentation/mac/Text/Text-368.html */
58 /* deprecated by putting the code as 3*5bit ascii */
59 static const char *mov_mdhd_language_map[] = {
60 /* 0-9 */
61 "eng", "fra", "ger", "ita", "dut", "sve", "spa", "dan", "por", "nor",
62 "heb", "jpn", "ara", "fin", "gre", "ice", "mlt", "tur", "hr "/*scr*/, "chi"/*ace?*/,
63 "urd", "hin", "tha", "kor", "lit", "pol", "hun", "est", "lav", NULL,
64 "fo ", NULL, "rus", "chi", NULL, "iri", "alb", "ron", "ces", "slk",
65 "slv", "yid", "sr ", "mac", "bul", "ukr", "bel", "uzb", "kaz", "aze",
66 /*?*/
67 "aze", "arm", "geo", "mol", "kir", "tgk", "tuk", "mon", NULL, "pus",
68 "kur", "kas", "snd", "tib", "nep", "san", "mar", "ben", "asm", "guj",
69 "pa ", "ori", "mal", "kan", "tam", "tel", NULL, "bur", "khm", "lao",
70 /* roman? arabic? */
71 "vie", "ind", "tgl", "may", "may", "amh", "tir", "orm", "som", "swa",
72 /*==rundi?*/
73 NULL, "run", NULL, "mlg", "epo", NULL, NULL, NULL, NULL, NULL,
74 /* 100 */
75 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
76 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
77 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "wel", "baq",
78 "cat", "lat", "que", "grn", "aym", "tat", "uig", "dzo", "jav"
79 };
80
81 int ff_mov_iso639_to_lang(const char *lang, int mp4)
82 {
83 int i, code = 0;
84
85 /* old way, only for QT? */
86 for (i = 0; !mp4 && (i < (sizeof(mov_mdhd_language_map)/sizeof(char *))); i++) {
87 if (mov_mdhd_language_map[i] && !strcmp(lang, mov_mdhd_language_map[i]))
88 return i;
89 }
90 /* XXX:can we do that in mov too? */
91 if (!mp4)
92 return 0;
93 /* handle undefined as such */
94 if (lang[0] == '\0')
95 lang = "und";
96 /* 5bit ascii */
97 for (i = 0; i < 3; i++) {
98 unsigned char c = (unsigned char)lang[i];
99 if (c < 0x60)
100 return 0;
101 if (c > 0x60 + 0x1f)
102 return 0;
103 code <<= 5;
104 code |= (c - 0x60);
105 }
106 return code;
107 }
108
109 int ff_mov_lang_to_iso639(int code, char *to)
110 {
111 int i;
112 /* is it the mangled iso code? */
113 /* see http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt */
114 if (code > 138) {
115 for (i = 2; i >= 0; i--) {
116 to[i] = 0x60 + (code & 0x1f);
117 code >>= 5;
118 }
119 return 1;
120 }
121 /* old fashion apple lang code */
122 if (code >= (sizeof(mov_mdhd_language_map)/sizeof(char *)))
123 return 0;
124 if (!mov_mdhd_language_map[code])
125 return 0;
126 strncpy(to, mov_mdhd_language_map[code], 4);
127 return 1;
128 }