From 639819a0e5610ec3b31d65d626ec871ed1d5f287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Mei=C3=9Fner?= Date: Wed, 29 Oct 2014 15:06:22 +0100 Subject: [PATCH] Choose tracks based on language, if possible --- .../pfMoviePlayer/plMoviePlayer.cpp | 24 ++++++++++++------- .../FeatureLib/pfMoviePlayer/plMoviePlayer.h | 1 + .../PubUtilLib/plResMgr/plLocalization.cpp | 11 +++++++++ .../PubUtilLib/plResMgr/plLocalization.h | 3 +++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.cpp b/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.cpp index be33308b..95ee77e2 100644 --- a/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.cpp +++ b/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.cpp @@ -53,15 +53,16 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com # define WEBM_CODECID_OPUS "A_OPUS" #endif +#include "hsResMgr.h" +#include "hsTimer.h" +#include "plAudio/plWin32VideoSound.h" #include "plGImage/plMipmap.h" #include "pnKeyedObject/plUoid.h" #include "plPipeline/hsGDeviceRef.h" #include "plPipeline/plPlates.h" -#include "plPlanarImage.h" -#include "hsResMgr.h" -#include "hsTimer.h" -#include "plAudio/plWin32VideoSound.h" +#include "plResMgr/plLocalization.h" +#include "plPlanarImage.h" #include "webm/mkvreader.hpp" #include "webm/mkvparser.hpp" @@ -224,8 +225,7 @@ bool plMoviePlayer::IOpenMovie() SAFE_OP(seg->Load(), "load segment from webm"); fSegment.reset(seg); - // TODO: Figure out video and audio based on current language - // For now... just take the first one. + // Use first tracks unless another one matches the current game language const mkvparser::Tracks* tracks = fSegment->GetTracks(); for (uint32_t i = 0; i < tracks->GetTracksCount(); ++i) { @@ -237,13 +237,13 @@ bool plMoviePlayer::IOpenMovie() { case mkvparser::Track::kAudio: { - if (!fAudioTrack) + if (!fAudioTrack || ICheckLanguage(track)) fAudioTrack.reset(new TrackMgr(track)); break; } case mkvparser::Track::kVideo: { - if (!fVideoTrack) + if (!fVideoTrack || ICheckLanguage(track)) fVideoTrack.reset(new TrackMgr(track)); break; } @@ -255,6 +255,14 @@ bool plMoviePlayer::IOpenMovie() #endif } +bool plMoviePlayer::ICheckLanguage(const mkvparser::Track* track) +{ + auto codes = plLocalization::GetLanguageCodes(plLocalization::GetLanguage()); + if (codes.find(track->GetLanguage()) != codes.end()) + return true; + return false; +} + void plMoviePlayer::IProcessVideoFrame(const std::vector& frames) { #ifdef VIDEO_AVAILABLE diff --git a/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.h b/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.h index 59c11e26..62a48494 100644 --- a/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.h +++ b/Sources/Plasma/FeatureLib/pfMoviePlayer/plMoviePlayer.h @@ -87,6 +87,7 @@ protected: bool fPaused; bool IOpenMovie(); + bool ICheckLanguage(const mkvparser::Track* track); void IProcessVideoFrame(const std::vector& frames); void IProcessAudioFrame(const std::vector& frames); diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.cpp index cc6c17da..fcf58329 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.cpp @@ -56,6 +56,17 @@ const char* plLocalization::fLangTags[] = }; const int kLangTagLen = 4; +// ISO 639, e.g. used in video tracks +std::set plLocalization::fLangCodes[] = +{ + {"eng", "en"}, + {"fre", "fra", "fr"}, + {"ger", "deu", "de"}, + {"spa", "es"}, + {"ita", "it"}, + {"jpn", "ja"} +}; + const char* plLocalization::fLangNames[] = { "English", // kEnglish diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.h b/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.h index c474562b..980b32e3 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.h +++ b/Sources/Plasma/PubUtilLib/plResMgr/plLocalization.h @@ -44,6 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include +#include #include "plFileSystem.h" class plLocalization @@ -78,6 +79,7 @@ public: protected: static Language fLanguage; static const char* fLangTags[kNumLanguages]; + static std::set fLangCodes[kNumLanguages]; static const char* fLangNames[kNumLanguages]; static bool fUsesUnicode[kNumLanguages]; static encodingTypes fUnicodeEncoding[kNumLanguages]; @@ -89,6 +91,7 @@ public: static Language GetLanguage() { return fLanguage; } static const char* GetLanguageName(Language lang) { return fLangNames[lang]; } + static std::set GetLanguageCodes(Language lang) { return fLangCodes[lang]; } static bool UsingUnicode() { return fUsesUnicode[fLanguage]; } static encodingTypes UnicodeEncoding() { return fUnicodeEncoding[fLanguage]; }