Skip to content

Commit

Permalink
Merge pull request #1828 from Montellese/audio_settings_update
Browse files Browse the repository at this point in the history
settings: improve migration of audio output settings from (pre-)Eden to Frodo
  • Loading branch information
Montellese committed Nov 22, 2012
2 parents 61f39b0 + 0a84744 commit 4709873
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 8 deletions.
26 changes: 26 additions & 0 deletions xbmc/cores/AudioEngine/AEFactory.cpp
Expand Up @@ -197,6 +197,32 @@ void CAEFactory::EnumerateOutputDevices(AEDeviceList &devices, bool passthrough)
AE->EnumerateOutputDevices(devices, passthrough); AE->EnumerateOutputDevices(devices, passthrough);
} }


void CAEFactory::VerifyOutputDevice(std::string &device, bool passthrough)
{
AEDeviceList devices;
EnumerateOutputDevices(devices, passthrough);
std::string firstDevice;

for (AEDeviceList::const_iterator deviceIt = devices.begin(); deviceIt != devices.end(); deviceIt++)
{
std::string currentDevice = deviceIt->second;
/* remember the first device so we can default to it if required */
if (firstDevice.empty())
firstDevice = deviceIt->second;

if (deviceIt->second == device)
return;
else if (deviceIt->first == device)
{
device = deviceIt->second;
return;
}
}

/* if the device wasnt found, set it to the first viable output */
device = firstDevice;
}

std::string CAEFactory::GetDefaultDevice(bool passthrough) std::string CAEFactory::GetDefaultDevice(bool passthrough)
{ {
if(AE) if(AE)
Expand Down
1 change: 1 addition & 0 deletions xbmc/cores/AudioEngine/AEFactory.h
Expand Up @@ -46,6 +46,7 @@ class CAEFactory
static void SetSoundMode(const int mode); static void SetSoundMode(const int mode);
static void OnSettingsChange(std::string setting); static void OnSettingsChange(std::string setting);
static void EnumerateOutputDevices(AEDeviceList &devices, bool passthrough); static void EnumerateOutputDevices(AEDeviceList &devices, bool passthrough);
static void VerifyOutputDevice(std::string &device, bool passthrough);
static std::string GetDefaultDevice(bool passthrough); static std::string GetDefaultDevice(bool passthrough);
static bool SupportsRaw(); static bool SupportsRaw();
static void SetMute(const bool enabled); static void SetMute(const bool enabled);
Expand Down
4 changes: 2 additions & 2 deletions xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAE.cpp
Expand Up @@ -142,7 +142,7 @@ bool CCoreAudioAE::OpenCoreAudio(unsigned int sampleRate, bool forceRaw,
// on iOS devices we set fixed to two channels. // on iOS devices we set fixed to two channels.
m_stdChLayout = AE_CH_LAYOUT_2_0; m_stdChLayout = AE_CH_LAYOUT_2_0;
#if defined(TARGET_DARWIN_OSX) #if defined(TARGET_DARWIN_OSX)
switch (g_guiSettings.GetInt("audiooutput.channellayout")) switch (g_guiSettings.GetInt("audiooutput.channels"))
{ {
default: default:
case 0: m_stdChLayout = AE_CH_LAYOUT_2_0; break; /* do not allow 1_0 output */ case 0: m_stdChLayout = AE_CH_LAYOUT_2_0; break; /* do not allow 1_0 output */
Expand Down Expand Up @@ -310,7 +310,7 @@ void CCoreAudioAE::OnSettingsChange(const std::string& setting)
setting == "audiooutput.mode" || setting == "audiooutput.mode" ||
setting == "audiooutput.ac3passthrough" || setting == "audiooutput.ac3passthrough" ||
setting == "audiooutput.dtspassthrough" || setting == "audiooutput.dtspassthrough" ||
setting == "audiooutput.channellayout" || setting == "audiooutput.channels" ||
setting == "audiooutput.multichannellpcm") setting == "audiooutput.multichannellpcm")
{ {
// only reinit the engine if we not // only reinit the engine if we not
Expand Down
Expand Up @@ -92,7 +92,7 @@ bool CCoreAudioAEHALOSX::InitializePCM(ICoreAudioSource *pSource, AEAudioFormat
if (!m_audioGraph) if (!m_audioGraph)
return false; return false;


AudioChannelLayoutTag layout = g_LayoutMap[ g_guiSettings.GetInt("audiooutput.channellayout") ]; AudioChannelLayoutTag layout = g_LayoutMap[ g_guiSettings.GetInt("audiooutput.channels") ];
// force optical/coax to 2.0 output channels // force optical/coax to 2.0 output channels
if (!m_Passthrough && g_guiSettings.GetInt("audiooutput.mode") == AUDIO_IEC958) if (!m_Passthrough && g_guiSettings.GetInt("audiooutput.mode") == AUDIO_IEC958)
layout = g_LayoutMap[1]; layout = g_LayoutMap[1];
Expand Down
4 changes: 2 additions & 2 deletions xbmc/cores/AudioEngine/Engines/SoftAE/SoftAE.cpp
Expand Up @@ -524,7 +524,7 @@ void CSoftAE::OnSettingsChange(const std::string& setting)
setting == "audiooutput.passthroughaac" || setting == "audiooutput.passthroughaac" ||
setting == "audiooutput.truehdpassthrough" || setting == "audiooutput.truehdpassthrough" ||
setting == "audiooutput.dtshdpassthrough" || setting == "audiooutput.dtshdpassthrough" ||
setting == "audiooutput.channellayout" || setting == "audiooutput.channels" ||
setting == "audiooutput.useexclusivemode" || setting == "audiooutput.useexclusivemode" ||
setting == "audiooutput.multichannellpcm" || setting == "audiooutput.multichannellpcm" ||
setting == "audiooutput.stereoupmix") setting == "audiooutput.stereoupmix")
Expand Down Expand Up @@ -553,7 +553,7 @@ void CSoftAE::LoadSettings()


/* load the configuration */ /* load the configuration */
m_stdChLayout = AE_CH_LAYOUT_2_0; m_stdChLayout = AE_CH_LAYOUT_2_0;
switch (g_guiSettings.GetInt("audiooutput.channellayout")) switch (g_guiSettings.GetInt("audiooutput.channels"))
{ {
default: default:
case 0: m_stdChLayout = AE_CH_LAYOUT_2_0; break; /* dont alow 1_0 output */ case 0: m_stdChLayout = AE_CH_LAYOUT_2_0; break; /* dont alow 1_0 output */
Expand Down
31 changes: 30 additions & 1 deletion xbmc/settings/GUISettings.cpp
Expand Up @@ -470,7 +470,7 @@ void CGUISettings::Initialize()
map<int,int> channelLayout; map<int,int> channelLayout;
for(int layout = AE_CH_LAYOUT_2_0; layout < AE_CH_LAYOUT_MAX; ++layout) for(int layout = AE_CH_LAYOUT_2_0; layout < AE_CH_LAYOUT_MAX; ++layout)
channelLayout.insert(make_pair(34100+layout, layout)); channelLayout.insert(make_pair(34100+layout, layout));
AddInt(ao, "audiooutput.channellayout", 34100, AE_CH_LAYOUT_2_0, channelLayout, SPIN_CONTROL_TEXT); AddInt(ao, "audiooutput.channels", 34100, AE_CH_LAYOUT_2_0, channelLayout, SPIN_CONTROL_TEXT);
AddBool(ao, "audiooutput.normalizelevels", 346, true); AddBool(ao, "audiooutput.normalizelevels", 346, true);
AddBool(ao, "audiooutput.stereoupmix", 252, false); AddBool(ao, "audiooutput.stereoupmix", 252, false);


Expand Down Expand Up @@ -1354,10 +1354,35 @@ void CGUISettings::GetSettingsGroup(CSettingsCategory* cat, vecSettings &setting


void CGUISettings::LoadXML(TiXmlElement *pRootElement, bool hideSettings /* = false */) void CGUISettings::LoadXML(TiXmlElement *pRootElement, bool hideSettings /* = false */)
{ // load our stuff... { // load our stuff...
bool updated = false;

for (mapIter it = settingsMap.begin(); it != settingsMap.end(); it++) for (mapIter it = settingsMap.begin(); it != settingsMap.end(); it++)
{ {
LoadFromXML(pRootElement, it, hideSettings); LoadFromXML(pRootElement, it, hideSettings);
} }

// check if we are updating to Frodo and need to update from
// audiooutput.channellayout to audiooutput.channels
TiXmlNode *channelNode = pRootElement->FirstChild("audiooutput");
if (channelNode != NULL)
{
channelNode = channelNode->FirstChild("channellayout");
CSettingInt* channels = (CSettingInt*)GetSetting("audiooutput.channels");
if (channelNode != NULL && channelNode->FirstChild() != NULL && channels != NULL)
{
channels->FromString(channelNode->FirstChild()->ValueStr());
if (channels->GetData() < AE_CH_LAYOUT_MAX - 1)
channels->SetData(channels->GetData() + 1);

// let's just reset the audiodevice settings as well
std::string audiodevice = GetString("audiooutput.audiodevice");
CAEFactory::VerifyOutputDevice(audiodevice, false);
SetString("audiooutput.audiodevice", audiodevice.c_str());

updated = true;
}
}

// Get hardware based stuff... // Get hardware based stuff...
CLog::Log(LOGNOTICE, "Getting hardware information now..."); CLog::Log(LOGNOTICE, "Getting hardware information now...");
// FIXME: Check if the hardware supports it (if possible ;) // FIXME: Check if the hardware supports it (if possible ;)
Expand Down Expand Up @@ -1401,6 +1426,7 @@ void CGUISettings::LoadXML(TiXmlElement *pRootElement, bool hideSettings /* = fa
{ {
timezone = g_timezone.GetOSConfiguredTimezone(); timezone = g_timezone.GetOSConfiguredTimezone();
SetString("locale.timezone", timezone); SetString("locale.timezone", timezone);
updated = true;
} }
g_timezone.SetTimezone(timezone); g_timezone.SetTimezone(timezone);
} }
Expand All @@ -1417,6 +1443,9 @@ void CGUISettings::LoadXML(TiXmlElement *pRootElement, bool hideSettings /* = fa
g_langInfo.SetSubtitleLanguage(streamLanguage); g_langInfo.SetSubtitleLanguage(streamLanguage);
else else
g_langInfo.SetSubtitleLanguage(""); g_langInfo.SetSubtitleLanguage("");

if (updated)
g_settings.Save();
} }


void CGUISettings::LoadFromXML(TiXmlElement *pRootElement, mapIter &it, bool advanced /* = false */) void CGUISettings::LoadFromXML(TiXmlElement *pRootElement, mapIter &it, bool advanced /* = false */)
Expand Down
7 changes: 5 additions & 2 deletions xbmc/settings/GUIWindowSettingsCategory.cpp
Expand Up @@ -2910,8 +2910,11 @@ void CGUIWindowSettingsCategory::FillInAudioDevices(CSetting* pSetting, bool Pas
if (selectedValue < 0) if (selectedValue < 0)
{ {
CLog::Log(LOGWARNING, "Failed to find previously selected audio sink"); CLog::Log(LOGWARNING, "Failed to find previously selected audio sink");
pControl->AddLabel(currentDevice, numberSinks); pControl->SetValue(0);
pControl->SetValue(numberSinks); if (!Passthrough)
((CSettingString*)pSetting)->SetData(m_AnalogAudioSinkMap[pControl->GetCurrentLabel()]);
else
((CSettingString*)pSetting)->SetData(m_DigitalAudioSinkMap[pControl->GetCurrentLabel()]);
} }
else else
pControl->SetValue(selectedValue); pControl->SetValue(selectedValue);
Expand Down

0 comments on commit 4709873

Please sign in to comment.