demux: libmp4: fix regression in trun reading (fix #19170)
[vlc.git] / modules / demux / mp4 / languages.h
blob70be6883034f183c6a4ab1ed11dbbed3de85b2b6
1 /*****************************************************************************
2 * languages.h: Quicktime language codes and ISO-639-2/T conversion
3 *****************************************************************************
4 * Copyright (C) 2014 VLC authors and VideoLAN
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
20 #ifndef VLC_MP4_LANGUAGES_H_
21 #define VLC_MP4_LANGUAGES_H_
23 static bool decodeQtLanguageCode( uint16_t i_language_code, char *psz_iso,
24 bool *b_mactables )
26 static const char * psz_qt_to_iso639_2T_lower =
27 "eng" "fra" "deu" "ita" "nld"
28 "swe" "spa" "dan" "por" "nor" /* 5-9 */
29 "heb" "jpn" "ara" "fin" "gre"
30 "isl" "mlt" "tur" "hrv" "zho" /* 15-19 */
31 "urd" "hin" "tha" "kor" "lit"
32 "pol" "hun" "est" "lav" "sme" /* 25-29 */
33 "fao" "fas" "rus" "zho" "nld" /* nld==flemish */
34 "gle" "sqi" "ron" "ces" "slk" /* 35-39 */
35 "slv" "yid" "srp" "mkd" "bul"
36 "ukr" "bel" "uzb" "kaz" "aze" /* 45-49 */
37 "aze" "hye" "kat" "mol" "kir"
38 "tgk" "tuk" "mon" "mon" "pus" /* 55-59 */
39 "kur" "kas" "snd" "bod" "nep"
40 "san" "mar" "ben" "asm" "guj" /* 65-69 */
41 "pan" "ori" "mal" "kan" "tam"
42 "tel" "sin" "mya" "khm" "lao" /* 75-79 */
43 "vie" "ind" "tgl" "msa" "msa"
44 "amh" "tir" "orm" "som" "swa" /* 85-89 */
45 "kin" "run" "nya" "mlg" "epo" /* 90-94 */
48 static const char * psz_qt_to_iso639_2T_upper =
49 "cym" "eus" "cat" "lat" "que" /* 128-132 */
50 "grn" "aym" "tat" "uig" "dzo"
51 "jaw" "sun" "glg" "afr" "bre" /* 138-142 */
52 "iku" "gla" "glv" "gle" "ton"
53 "gre" /* 148 */
56 if ( i_language_code < 0x400 || i_language_code == 0x7FFF )
58 const void *p_data;
59 *b_mactables = true;
60 if ( i_language_code <= 94 )
62 p_data = psz_qt_to_iso639_2T_lower + i_language_code * 3;
64 else if ( i_language_code >= 128 && i_language_code <= 148 )
66 i_language_code -= 128;
67 p_data = psz_qt_to_iso639_2T_upper + i_language_code * 3;
69 else
70 return false;
71 memcpy( psz_iso, p_data, 3 );
73 else
75 *b_mactables = false;
77 * to build code: ( ( 'f' - 0x60 ) << 10 ) | ( ('r' - 0x60) << 5 ) | ('a' - 0x60)
79 if( i_language_code == 0x55C4 ) /* "und" */
81 memset( psz_iso, 0, 3 );
82 return false;
85 for( unsigned i = 0; i < 3; i++ )
86 psz_iso[i] = ( ( i_language_code >> ( (2-i)*5 ) )&0x1f ) + 0x60;
88 return true;
91 #endif