[vlc-devel] [PATCH 1/2] demux: mkv: parse language codes with embedded country codes

Shaleen Jain shaleen.jain95 at gmail.com
Wed Apr 12 11:14:08 CEST 2017


fixes bug: https://trac.videolan.org/vlc/ticket/11813
---
 modules/demux/mkv/matroska_segment_parse.cpp | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/modules/demux/mkv/matroska_segment_parse.cpp b/modules/demux/mkv/matroska_segment_parse.cpp
index f4d73613c9..94f54838f8 100644
--- a/modules/demux/mkv/matroska_segment_parse.cpp
+++ b/modules/demux/mkv/matroska_segment_parse.cpp
@@ -80,6 +80,17 @@ static inline char * ToUTF8( const UTFstring &u )
     return strdup( u.GetUTF8().c_str() );
 }
 
+// https://www.matroska.org/technical/specs/index.html#languages
+static inline char * parseLanguage(const char * lang)
+{
+    char* psz_lang = strdup(lang);
+	if( strchr(psz_lang, '-' ) != NULL ) {
+		return strtok(psz_lang, "-");
+	} else {
+		return psz_lang;
+	}
+}
+
 /*****************************************************************************
  * ParseSeekHead:
  *****************************************************************************/
@@ -380,7 +391,7 @@ void matroska_segment_c::ParseTrackEntry( KaxTrackEntry *m )
         E_CASE( KaxTrackLanguage, lang )
         {
             free( vars.tk->fmt.psz_language );
-            vars.tk->fmt.psz_language = strdup( std::string( lang ).c_str() );
+            vars.tk->fmt.psz_language = parseLanguage(std::string( lang ).c_str());
             debug( vars, "Track Language=`%s'", vars.tk->fmt.psz_language );
         }
         E_CASE( KaxCodecID, codecid )
-- 
2.12.2



More information about the vlc-devel mailing list