[vlc-devel] [PATCH] Language support acording to MKV-Spec

Maximilian Madlung maxi.madlung at gmx.de
Tue Jul 29 01:07:28 CEST 2014


Fixed bugs

Reduced redundancy

and coding conventions
---
 src/input/es_out.c |   49 +++++++++++++++++++++++++++++++++++++------------
 1 file changed, 37 insertions(+), 12 deletions(-)

diff --git a/src/input/es_out.c b/src/input/es_out.c
index d5ac33b..b1ca128 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -192,6 +192,7 @@ static void EsOutDecodersStopBuffering( es_out_t *out, bool b_forced );
 
 static char *LanguageGetName( const char *psz_code );
 static char *LanguageGetCode( const char *psz_lang );
+static iso639_lang_t* getIso639( char *input );
 static char **LanguageSplit( const char *psz_langs, bool b_default_any );
 static int LanguageArrayIndex( char **ppsz_langs, const char *psz_lang );
 
@@ -2727,24 +2728,24 @@ static char *LanguageGetName( const char *psz_code )
         return strdup( "" );
     }
 
-    if( strlen( psz_code ) == 2 )
+    /* Check if the language code consists a "-[...]" and only take the front
+       part as language */
+    if( strchr( psz_code, '-' ) != NULL )
     {
-        pl = GetLang_1( psz_code );
-    }
-    else if( strlen( psz_code ) == 3 )
-    {
-        pl = GetLang_2B( psz_code );
-        if( !strcmp( pl->psz_iso639_1, "??" ) )
-        {
-            pl = GetLang_2T( psz_code );
-        }
+        char* buf;
+        char* psz_code_temp = strdup( psz_code );
+        char* psz_lang = strtok_r ( psz_code_temp, "-", &buf );
+
+        pl = getIso639( psz_lang );
+
     }
     else
     {
-        return strdup( psz_code );
+        pl = getIso639( psz_code );
+
     }
 
-    if( !strcmp( pl->psz_iso639_1, "??" ) )
+    if( pl == 0 ||  !strcmp( pl->psz_iso639_1, "??" ) )
     {
        return strdup( psz_code );
     }
@@ -2754,6 +2755,30 @@ static char *LanguageGetName( const char *psz_code )
     }
 }
 
+static iso639_lang_t* getIso639( char *input )
+{
+    const iso639_lang_t *pl;
+
+    if( strlen( input ) == 2 )
+    {
+        pl = GetLang_1( input );
+    }
+    else if( strlen( input ) == 3 )
+    {
+        pl = GetLang_2B( input );
+        if( !strcmp( pl->psz_iso639_1, "??" ) )
+        {
+            pl = GetLang_2T( input );
+        }
+    }
+    else
+    {
+        return 0;
+    }
+
+    return pl;
+}
+
 /* Get a 2 char code */
 static char *LanguageGetCode( const char *psz_lang )
 {
-- 
1.7.9.5




More information about the vlc-devel mailing list