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