Coverage Report

Created: 2026-02-26 08:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/demux/mp4/languages.h
Line
Count
Source
1
/*****************************************************************************
2
 * languages.h: Quicktime language codes and ISO-639-2/T conversion
3
 *****************************************************************************
4
 * Copyright (C) 2014 VLC authors and VideoLAN
5
 *
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.
10
 *
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.
15
 *
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_
22
23
static bool decodeQtLanguageCode( uint16_t i_language_code, char *psz_iso,
24
                                  bool *b_mactables )
25
5.22k
{
26
5.22k
    static const char * psz_qt_to_iso639_2T_lower =
27
5.22k
            "eng"    "fra"    "deu"    "ita"    "nld"
28
5.22k
            "swe"    "spa"    "dan"    "por"    "nor" /* 5-9 */
29
5.22k
            "heb"    "jpn"    "ara"    "fin"    "gre"
30
5.22k
            "isl"    "mlt"    "tur"    "hrv"    "zho" /* 15-19 */
31
5.22k
            "urd"    "hin"    "tha"    "kor"    "lit"
32
5.22k
            "pol"    "hun"    "est"    "lav"    "sme" /* 25-29 */
33
5.22k
            "fao"    "fas"    "rus"    "zho"    "nld" /* nld==flemish */
34
5.22k
            "gle"    "sqi"    "ron"    "ces"    "slk" /* 35-39 */
35
5.22k
            "slv"    "yid"    "srp"    "mkd"    "bul"
36
5.22k
            "ukr"    "bel"    "uzb"    "kaz"    "aze" /* 45-49 */
37
5.22k
            "aze"    "hye"    "kat"    "mol"    "kir"
38
5.22k
            "tgk"    "tuk"    "mon"    "mon"    "pus" /* 55-59 */
39
5.22k
            "kur"    "kas"    "snd"    "bod"    "nep"
40
5.22k
            "san"    "mar"    "ben"    "asm"    "guj" /* 65-69 */
41
5.22k
            "pan"    "ori"    "mal"    "kan"    "tam"
42
5.22k
            "tel"    "sin"    "mya"    "khm"    "lao" /* 75-79 */
43
5.22k
            "vie"    "ind"    "tgl"    "msa"    "msa"
44
5.22k
            "amh"    "tir"    "orm"    "som"    "swa" /* 85-89 */
45
5.22k
            "kin"    "run"    "nya"    "mlg"    "epo" /* 90-94 */
46
5.22k
            ;
47
48
5.22k
    static const char * psz_qt_to_iso639_2T_upper =
49
5.22k
            "cym"    "eus"    "cat"    "lat"    "que" /* 128-132 */
50
5.22k
            "grn"    "aym"    "tat"    "uig"    "dzo"
51
5.22k
            "jaw"    "sun"    "glg"    "afr"    "bre" /* 138-142 */
52
5.22k
            "iku"    "gla"    "glv"    "gle"    "ton"
53
5.22k
            "gre"                                     /* 148 */
54
5.22k
            ;
55
56
5.22k
    if ( i_language_code < 0x400 || i_language_code == 0x7FFF )
57
3.06k
    {
58
3.06k
        const void *p_data;
59
3.06k
        *b_mactables = true;
60
3.06k
        if ( i_language_code <= 94 )
61
2.11k
        {
62
2.11k
            p_data = psz_qt_to_iso639_2T_lower + i_language_code * 3;
63
2.11k
        }
64
952
        else if ( i_language_code >= 128 && i_language_code <= 148 )
65
0
        {
66
0
            i_language_code -= 128;
67
0
            p_data = psz_qt_to_iso639_2T_upper + i_language_code * 3;
68
0
        }
69
952
        else
70
952
            return false;
71
2.11k
        memcpy( psz_iso, p_data, 3 );
72
2.11k
    }
73
2.15k
    else
74
2.15k
    {
75
2.15k
        *b_mactables = false;
76
        /*
77
         * to build code: ( ( 'f' - 0x60 ) << 10 ) | ( ('r' - 0x60) << 5 ) | ('a' - 0x60)
78
         */
79
2.15k
        if( i_language_code == 0x55C4 ) /* "und" */
80
1.77k
        {
81
1.77k
            memset( psz_iso, 0, 3 );
82
1.77k
            return false;
83
1.77k
        }
84
85
1.50k
        for( unsigned i = 0; i < 3; i++ )
86
1.13k
            psz_iso[i] = ( ( i_language_code >> ( (2-i)*5 ) )&0x1f ) + 0x60;
87
377
    }
88
2.49k
    return true;
89
5.22k
}
meta.c:decodeQtLanguageCode
Line
Count
Source
25
939
{
26
939
    static const char * psz_qt_to_iso639_2T_lower =
27
939
            "eng"    "fra"    "deu"    "ita"    "nld"
28
939
            "swe"    "spa"    "dan"    "por"    "nor" /* 5-9 */
29
939
            "heb"    "jpn"    "ara"    "fin"    "gre"
30
939
            "isl"    "mlt"    "tur"    "hrv"    "zho" /* 15-19 */
31
939
            "urd"    "hin"    "tha"    "kor"    "lit"
32
939
            "pol"    "hun"    "est"    "lav"    "sme" /* 25-29 */
33
939
            "fao"    "fas"    "rus"    "zho"    "nld" /* nld==flemish */
34
939
            "gle"    "sqi"    "ron"    "ces"    "slk" /* 35-39 */
35
939
            "slv"    "yid"    "srp"    "mkd"    "bul"
36
939
            "ukr"    "bel"    "uzb"    "kaz"    "aze" /* 45-49 */
37
939
            "aze"    "hye"    "kat"    "mol"    "kir"
38
939
            "tgk"    "tuk"    "mon"    "mon"    "pus" /* 55-59 */
39
939
            "kur"    "kas"    "snd"    "bod"    "nep"
40
939
            "san"    "mar"    "ben"    "asm"    "guj" /* 65-69 */
41
939
            "pan"    "ori"    "mal"    "kan"    "tam"
42
939
            "tel"    "sin"    "mya"    "khm"    "lao" /* 75-79 */
43
939
            "vie"    "ind"    "tgl"    "msa"    "msa"
44
939
            "amh"    "tir"    "orm"    "som"    "swa" /* 85-89 */
45
939
            "kin"    "run"    "nya"    "mlg"    "epo" /* 90-94 */
46
939
            ;
47
48
939
    static const char * psz_qt_to_iso639_2T_upper =
49
939
            "cym"    "eus"    "cat"    "lat"    "que" /* 128-132 */
50
939
            "grn"    "aym"    "tat"    "uig"    "dzo"
51
939
            "jaw"    "sun"    "glg"    "afr"    "bre" /* 138-142 */
52
939
            "iku"    "gla"    "glv"    "gle"    "ton"
53
939
            "gre"                                     /* 148 */
54
939
            ;
55
56
939
    if ( i_language_code < 0x400 || i_language_code == 0x7FFF )
57
0
    {
58
0
        const void *p_data;
59
0
        *b_mactables = true;
60
0
        if ( i_language_code <= 94 )
61
0
        {
62
0
            p_data = psz_qt_to_iso639_2T_lower + i_language_code * 3;
63
0
        }
64
0
        else if ( i_language_code >= 128 && i_language_code <= 148 )
65
0
        {
66
0
            i_language_code -= 128;
67
0
            p_data = psz_qt_to_iso639_2T_upper + i_language_code * 3;
68
0
        }
69
0
        else
70
0
            return false;
71
0
        memcpy( psz_iso, p_data, 3 );
72
0
    }
73
939
    else
74
939
    {
75
939
        *b_mactables = false;
76
        /*
77
         * to build code: ( ( 'f' - 0x60 ) << 10 ) | ( ('r' - 0x60) << 5 ) | ('a' - 0x60)
78
         */
79
939
        if( i_language_code == 0x55C4 ) /* "und" */
80
933
        {
81
933
            memset( psz_iso, 0, 3 );
82
933
            return false;
83
933
        }
84
85
24
        for( unsigned i = 0; i < 3; i++ )
86
18
            psz_iso[i] = ( ( i_language_code >> ( (2-i)*5 ) )&0x1f ) + 0x60;
87
6
    }
88
6
    return true;
89
939
}
libmp4.c:decodeQtLanguageCode
Line
Count
Source
25
4.28k
{
26
4.28k
    static const char * psz_qt_to_iso639_2T_lower =
27
4.28k
            "eng"    "fra"    "deu"    "ita"    "nld"
28
4.28k
            "swe"    "spa"    "dan"    "por"    "nor" /* 5-9 */
29
4.28k
            "heb"    "jpn"    "ara"    "fin"    "gre"
30
4.28k
            "isl"    "mlt"    "tur"    "hrv"    "zho" /* 15-19 */
31
4.28k
            "urd"    "hin"    "tha"    "kor"    "lit"
32
4.28k
            "pol"    "hun"    "est"    "lav"    "sme" /* 25-29 */
33
4.28k
            "fao"    "fas"    "rus"    "zho"    "nld" /* nld==flemish */
34
4.28k
            "gle"    "sqi"    "ron"    "ces"    "slk" /* 35-39 */
35
4.28k
            "slv"    "yid"    "srp"    "mkd"    "bul"
36
4.28k
            "ukr"    "bel"    "uzb"    "kaz"    "aze" /* 45-49 */
37
4.28k
            "aze"    "hye"    "kat"    "mol"    "kir"
38
4.28k
            "tgk"    "tuk"    "mon"    "mon"    "pus" /* 55-59 */
39
4.28k
            "kur"    "kas"    "snd"    "bod"    "nep"
40
4.28k
            "san"    "mar"    "ben"    "asm"    "guj" /* 65-69 */
41
4.28k
            "pan"    "ori"    "mal"    "kan"    "tam"
42
4.28k
            "tel"    "sin"    "mya"    "khm"    "lao" /* 75-79 */
43
4.28k
            "vie"    "ind"    "tgl"    "msa"    "msa"
44
4.28k
            "amh"    "tir"    "orm"    "som"    "swa" /* 85-89 */
45
4.28k
            "kin"    "run"    "nya"    "mlg"    "epo" /* 90-94 */
46
4.28k
            ;
47
48
4.28k
    static const char * psz_qt_to_iso639_2T_upper =
49
4.28k
            "cym"    "eus"    "cat"    "lat"    "que" /* 128-132 */
50
4.28k
            "grn"    "aym"    "tat"    "uig"    "dzo"
51
4.28k
            "jaw"    "sun"    "glg"    "afr"    "bre" /* 138-142 */
52
4.28k
            "iku"    "gla"    "glv"    "gle"    "ton"
53
4.28k
            "gre"                                     /* 148 */
54
4.28k
            ;
55
56
4.28k
    if ( i_language_code < 0x400 || i_language_code == 0x7FFF )
57
3.06k
    {
58
3.06k
        const void *p_data;
59
3.06k
        *b_mactables = true;
60
3.06k
        if ( i_language_code <= 94 )
61
2.11k
        {
62
2.11k
            p_data = psz_qt_to_iso639_2T_lower + i_language_code * 3;
63
2.11k
        }
64
952
        else if ( i_language_code >= 128 && i_language_code <= 148 )
65
0
        {
66
0
            i_language_code -= 128;
67
0
            p_data = psz_qt_to_iso639_2T_upper + i_language_code * 3;
68
0
        }
69
952
        else
70
952
            return false;
71
2.11k
        memcpy( psz_iso, p_data, 3 );
72
2.11k
    }
73
1.21k
    else
74
1.21k
    {
75
1.21k
        *b_mactables = false;
76
        /*
77
         * to build code: ( ( 'f' - 0x60 ) << 10 ) | ( ('r' - 0x60) << 5 ) | ('a' - 0x60)
78
         */
79
1.21k
        if( i_language_code == 0x55C4 ) /* "und" */
80
844
        {
81
844
            memset( psz_iso, 0, 3 );
82
844
            return false;
83
844
        }
84
85
1.48k
        for( unsigned i = 0; i < 3; i++ )
86
1.11k
            psz_iso[i] = ( ( i_language_code >> ( (2-i)*5 ) )&0x1f ) + 0x60;
87
371
    }
88
2.48k
    return true;
89
4.28k
}
90
91
#endif