Skip to content
This repository
Browse code

Merge pull request #2839 from ace20022/fix_lang_select

 [DVD/OMXPlayer] Fix auto-selection of audio and subtitle streams.
  • Loading branch information...
commit ba5e5e5a3dce01d66f7adffc62ae38b9d66ef2a2 2 parents 3b7bf8d + 44cf328
Martijn Kaijser authored September 10, 2013
27  xbmc/cores/dvdplayer/DVDPlayer.cpp
@@ -86,6 +86,7 @@
86 86
 #include "Util.h"
87 87
 #include "LangInfo.h"
88 88
 #include "URL.h"
  89
+#include "utils/LangCodeExpander.h"
89 90
 
90 91
 using namespace std;
91 92
 using namespace PVR;
@@ -145,8 +146,8 @@ static bool PredicateAudioPriority(const SelectionStream& lh, const SelectionStr
145 146
   if(!StringUtils::EqualsNoCase(CSettings::Get().GetString("locale.audiolanguage"), "original"))
146 147
   {
147 148
     CStdString audio_language = g_langInfo.GetAudioLanguage();
148  
-    PREDICATE_RETURN(audio_language.Equals(lh.language.c_str())
149  
-                   , audio_language.Equals(rh.language.c_str()));
  149
+    PREDICATE_RETURN(g_LangCodeExpander.CompareLangCodes(audio_language, lh.language)
  150
+                   , g_LangCodeExpander.CompareLangCodes(audio_language, rh.language));
150 151
   }
151 152
 
152 153
   PREDICATE_RETURN(lh.flags & CDemuxStream::FLAG_DEFAULT
@@ -174,8 +175,8 @@ static bool PredicateSubtitlePriority(const SelectionStream& lh, const Selection
174 175
   CStdString subtitle_language = g_langInfo.GetSubtitleLanguage();
175 176
   if(!StringUtils::EqualsNoCase(CSettings::Get().GetString("locale.subtitlelanguage"), "original"))
176 177
   {
177  
-    PREDICATE_RETURN((lh.source == STREAM_SOURCE_DEMUX_SUB || lh.source == STREAM_SOURCE_TEXT) && subtitle_language.Equals(lh.language.c_str())
178  
-                   , (rh.source == STREAM_SOURCE_DEMUX_SUB || rh.source == STREAM_SOURCE_TEXT) && subtitle_language.Equals(rh.language.c_str()));
  178
+    PREDICATE_RETURN((lh.source == STREAM_SOURCE_DEMUX_SUB || lh.source == STREAM_SOURCE_TEXT) && g_LangCodeExpander.CompareLangCodes(subtitle_language, lh.language)
  179
+                   , (rh.source == STREAM_SOURCE_DEMUX_SUB || rh.source == STREAM_SOURCE_TEXT) && g_LangCodeExpander.CompareLangCodes(subtitle_language, rh.language));
179 180
   }
180 181
 
181 182
   PREDICATE_RETURN(lh.source == STREAM_SOURCE_DEMUX_SUB
@@ -186,8 +187,8 @@ static bool PredicateSubtitlePriority(const SelectionStream& lh, const Selection
186 187
 
187 188
   if(!StringUtils::EqualsNoCase(CSettings::Get().GetString("locale.subtitlelanguage"), "original"))
188 189
   {
189  
-    PREDICATE_RETURN(subtitle_language.Equals(lh.language.c_str())
190  
-                   , subtitle_language.Equals(rh.language.c_str()));
  190
+    PREDICATE_RETURN(g_LangCodeExpander.CompareLangCodes(subtitle_language, lh.language)
  191
+                   , g_LangCodeExpander.CompareLangCodes(subtitle_language, rh.language));
191 192
   }
192 193
 
193 194
   PREDICATE_RETURN(lh.flags & CDemuxStream::FLAG_DEFAULT
@@ -325,7 +326,7 @@ void CSelectionStreams::Update(CDVDInputStream* input, CDVDDemux* demuxer)
325 326
       DVDNavStreamInfo info;
326 327
       nav->GetAudioStreamInfo(i, info);
327 328
       s.name     = info.name;
328  
-      s.language = info.language;
  329
+      s.language = g_LangCodeExpander.ConvertToISO6392T(info.language);
329 330
       s.channels = info.channels;
330 331
       Update(s);
331 332
     }
@@ -344,7 +345,7 @@ void CSelectionStreams::Update(CDVDInputStream* input, CDVDDemux* demuxer)
344 345
       DVDNavStreamInfo info;
345 346
       nav->GetSubtitleStreamInfo(i, info);
346 347
       s.name     = info.name;
347  
-      s.language = info.language;
  348
+      s.language = g_LangCodeExpander.ConvertToISO6392T(info.language);
348 349
       Update(s);
349 350
     }
350 351
   }
@@ -369,15 +370,7 @@ void CSelectionStreams::Update(CDVDInputStream* input, CDVDDemux* demuxer)
369 370
       s.source   = source;
370 371
       s.type     = stream->type;
371 372
       s.id       = stream->iId;
372  
-      s.language = stream->language;
373  
-
374  
-      if (s.language.length() == 2)
375  
-      {
376  
-        CStdString lang;
377  
-        g_LangCodeExpander.ConvertToThreeCharCode(lang, stream->language);
378  
-        s.language = lang;
379  
-      }
380  
-
  373
+      s.language = g_LangCodeExpander.ConvertToISO6392T(stream->language);
381 374
       s.flags    = stream->flags;
382 375
       s.filename = demuxer->GetFileName();
383 376
       stream->GetStreamName(s.name);
27  xbmc/cores/omxplayer/OMXPlayer.cpp
@@ -120,6 +120,7 @@
120 120
 #include "Util.h"
121 121
 #include "LangInfo.h"
122 122
 #include "URL.h"
  123
+#include "utils/LangCodeExpander.h"
123 124
 
124 125
 // video not playing from clock, but stepped
125 126
 #define TP(speed)  ((speed) < 0 || (speed) > 4*DVD_PLAYSPEED_NORMAL)
@@ -184,8 +185,8 @@ static bool PredicateAudioPriority(const OMXSelectionStream& lh, const OMXSelect
184 185
   if(!StringUtils::EqualsNoCase(CSettings::Get().GetString("locale.audiolanguage"), "original"))
185 186
   {
186 187
     CStdString audio_language = g_langInfo.GetAudioLanguage();
187  
-    PREDICATE_RETURN(audio_language.Equals(lh.language.c_str())
188  
-                   , audio_language.Equals(rh.language.c_str()));
  188
+    PREDICATE_RETURN(g_LangCodeExpander.CompareLangCodes(audio_language, lh.language)
  189
+                   , g_LangCodeExpander.CompareLangCodes(audio_language, rh.language));
189 190
   }
190 191
 
191 192
   PREDICATE_RETURN(lh.flags & CDemuxStream::FLAG_DEFAULT
@@ -213,8 +214,8 @@ static bool PredicateSubtitlePriority(const OMXSelectionStream& lh, const OMXSel
213 214
   CStdString subtitle_language = g_langInfo.GetSubtitleLanguage();
214 215
   if(!StringUtils::EqualsNoCase(CSettings::Get().GetString("locale.subtitlelanguage"), "original"))
215 216
   {
216  
-    PREDICATE_RETURN((lh.source == STREAM_SOURCE_DEMUX_SUB || lh.source == STREAM_SOURCE_TEXT) && subtitle_language.Equals(lh.language.c_str())
217  
-                   , (rh.source == STREAM_SOURCE_DEMUX_SUB || rh.source == STREAM_SOURCE_TEXT) && subtitle_language.Equals(rh.language.c_str()));
  217
+    PREDICATE_RETURN((lh.source == STREAM_SOURCE_DEMUX_SUB || lh.source == STREAM_SOURCE_TEXT) && g_LangCodeExpander.CompareLangCodes(subtitle_language, lh.language)
  218
+                   , (rh.source == STREAM_SOURCE_DEMUX_SUB || rh.source == STREAM_SOURCE_TEXT) && g_LangCodeExpander.CompareLangCodes(subtitle_language, rh.language));
218 219
   }
219 220
 
220 221
   PREDICATE_RETURN(lh.source == STREAM_SOURCE_DEMUX_SUB
@@ -225,8 +226,8 @@ static bool PredicateSubtitlePriority(const OMXSelectionStream& lh, const OMXSel
225 226
 
226 227
   if(!StringUtils::EqualsNoCase(CSettings::Get().GetString("locale.subtitlelanguage"), "original"))
227 228
   {
228  
-    PREDICATE_RETURN(subtitle_language.Equals(lh.language.c_str())
229  
-                   , subtitle_language.Equals(rh.language.c_str()));
  229
+    PREDICATE_RETURN(g_LangCodeExpander.CompareLangCodes(subtitle_language, lh.language)
  230
+                   , g_LangCodeExpander.CompareLangCodes(subtitle_language, rh.language));
230 231
   }
231 232
 
232 233
   PREDICATE_RETURN(lh.flags & CDemuxStream::FLAG_DEFAULT
@@ -364,7 +365,7 @@ void COMXSelectionStreams::Update(CDVDInputStream* input, CDVDDemux* demuxer)
364 365
       DVDNavStreamInfo info;
365 366
       nav->GetAudioStreamInfo(i, info);
366 367
       s.name     = info.name;
367  
-      s.language = info.language;
  368
+      s.language = g_LangCodeExpander.ConvertToISO6392T(info.language);
368 369
       s.channels = info.channels;
369 370
       Update(s);
370 371
     }
@@ -383,7 +384,7 @@ void COMXSelectionStreams::Update(CDVDInputStream* input, CDVDDemux* demuxer)
383 384
       DVDNavStreamInfo info;
384 385
       nav->GetSubtitleStreamInfo(i, info);
385 386
       s.name     = info.name;
386  
-      s.language = info.language;
  387
+      s.language = g_LangCodeExpander.ConvertToISO6392T(info.language);
387 388
       Update(s);
388 389
     }
389 390
   }
@@ -408,15 +409,7 @@ void COMXSelectionStreams::Update(CDVDInputStream* input, CDVDDemux* demuxer)
408 409
       s.source   = source;
409 410
       s.type     = stream->type;
410 411
       s.id       = stream->iId;
411  
-      s.language = stream->language;
412  
-
413  
-      if (s.language.length() == 2)
414  
-      {
415  
-        CStdString lang;
416  
-        g_LangCodeExpander.ConvertToThreeCharCode(lang, stream->language);
417  
-        s.language = lang;
418  
-      }
419  
-
  412
+      s.language = g_LangCodeExpander.ConvertToISO6392T(stream->language);
420 413
       s.flags    = stream->flags;
421 414
       s.filename = demuxer->GetFileName();
422 415
       stream->GetStreamName(s.name);
49  xbmc/utils/LangCodeExpander.cpp
@@ -420,6 +420,28 @@ void CLangCodeExpander::CodeToString(long code, CStdString& ret)
420 420
   }
421 421
 }
422 422
 
  423
+bool CLangCodeExpander::CompareFullLangNames(const CStdString& lang1, const CStdString& lang2)
  424
+{
  425
+  if (lang1.Equals(lang2))
  426
+    return true;
  427
+
  428
+  CStdString expandedLang1, expandedLang2, code1, code2;
  429
+
  430
+  if (!ReverseLookup(lang1, code1))
  431
+    return false;
  432
+  else
  433
+    code1 = lang1;
  434
+
  435
+  if (!ReverseLookup(lang2, code2))
  436
+    return false;
  437
+  else
  438
+    code2 = lang2;
  439
+
  440
+  Lookup(expandedLang1, code1);
  441
+  Lookup(expandedLang2, code2);
  442
+  return expandedLang1.Equals(expandedLang2);
  443
+}
  444
+
423 445
 std::vector<std::string> CLangCodeExpander::GetLanguageNames(LANGFORMATS format /* = CLangCodeExpander::ISO_639_1 */) const
424 446
 {
425 447
   std::vector<std::string> languages;
@@ -441,6 +463,33 @@ std::vector<std::string> CLangCodeExpander::GetLanguageNames(LANGFORMATS format
441 463
   return languages;
442 464
 }
443 465
 
  466
+bool CLangCodeExpander::CompareLangCodes(const CStdString& code1, const CStdString& code2)
  467
+{
  468
+  if (code1.Equals(code2))
  469
+    return true;
  470
+
  471
+  CStdString expandedLang1, expandedLang2;
  472
+
  473
+  if (!Lookup(expandedLang1, code1))
  474
+    return false;
  475
+
  476
+  if (!Lookup(expandedLang2, code2))
  477
+    return false;
  478
+
  479
+  return expandedLang1.Equals(expandedLang2);
  480
+}
  481
+
  482
+CStdString CLangCodeExpander::ConvertToISO6392T(const CStdString& lang)
  483
+{
  484
+  CStdString two, three;
  485
+  if (ConvertToTwoCharCode(two, lang))
  486
+  {
  487
+    if (ConvertToThreeCharCode(three, two))
  488
+      return three;
  489
+  }
  490
+  return lang;
  491
+}
  492
+
444 493
 extern const LCENTRY g_iso639_1[144] =
445 494
 {
446 495
   { MAKECODE('\0','\0','c','c'), "Closed Caption" },
24  xbmc/utils/LangCodeExpander.h
@@ -41,6 +41,22 @@ class CLangCodeExpander
41 41
   bool Lookup(CStdString& desc, const CStdString& code);
42 42
   bool Lookup(CStdString& desc, const int code);
43 43
 
  44
+  /** \brief Determines if two english language names represent the same language.
  45
+  *   \param[in] lang1 The first language string to compare given as english language name.
  46
+  *   \param[in] lang2 The second language string to compare given as english language name.
  47
+  *   \return true if the two language strings represent the same language, false otherwise.
  48
+  *   For example "Abkhaz" and "Abkhazian" represent the same language.
  49
+  */ 
  50
+  bool CompareFullLangNames(const CStdString& lang1, const CStdString& lang2);
  51
+
  52
+  /** \brief Determines if two languages given as ISO 639-1, ISO 639-2/T, or ISO 639-2/B codes represent the same language.
  53
+  *   \param[in] code1 The first language to compare given as ISO 639-1, ISO 639-2/T, or ISO 639-2/B code.
  54
+  *   \param[in] code2 The second language to compare given as ISO 639-1, ISO 639-2/T, or ISO 639-2/B code.
  55
+  *   \return true if the two language codes represent the same language, false otherwise.
  56
+  *   For example "ger", "deu" and "de" represent the same language.
  57
+  */ 
  58
+  bool CompareLangCodes(const CStdString& code1, const CStdString& code2);
  59
+
44 60
   /** \brief Converts a language given as 2-Char (ISO 639-1),
45 61
   *          3-Char (ISO 639-2/T or ISO 639-2/B),
46 62
   *          or full english name string to a 2-Char (ISO 639-1) code.  
@@ -49,6 +65,14 @@ class CLangCodeExpander
49 65
   *   \return true if the conversion succeeded, false otherwise. 
50 66
   */ 
51 67
   bool ConvertToTwoCharCode(CStdString& code, const CStdString& lang);
  68
+
  69
+  /** \brief Converts a language given as 2-Char (ISO 639-1),
  70
+  *          3-Char (ISO 639-2/T or ISO 639-2/B),
  71
+  *          or full english name string to a 3-Char ISO 639-2/T code.
  72
+  *   \param[in] lang The language that should be converted.
  73
+  *   \return The 3-Char ISO 639-2/T code of lang if that code exists, lang otherwise.
  74
+  */
  75
+  CStdString ConvertToISO6392T(const CStdString& lang);
52 76
 #ifdef TARGET_WINDOWS
53 77
   bool ConvertTwoToThreeCharCode(CStdString& strThreeCharCode, const CStdString& strTwoCharCode, bool localeHack = false);
54 78
   bool ConvertToThreeCharCode(CStdString& strThreeCharCode, const CStdString& strCharCode, bool localeHack = false);

0 notes on commit ba5e5e5

Please sign in to comment.
Something went wrong with that request. Please try again.