annotate isom.c @ 1370:49421e5b5335 libavformat

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