Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

settings: improve migration of audio output settings from (pre-)Eden to Frodo #1828

Merged
merged 4 commits into from Nov 22, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}

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)
{
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 OnSettingsChange(std::string setting);
static void EnumerateOutputDevices(AEDeviceList &devices, bool passthrough);
static void VerifyOutputDevice(std::string &device, bool passthrough);
static std::string GetDefaultDevice(bool passthrough);
static bool SupportsRaw();
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.
m_stdChLayout = AE_CH_LAYOUT_2_0;
#if defined(TARGET_DARWIN_OSX)
switch (g_guiSettings.GetInt("audiooutput.channellayout"))
switch (g_guiSettings.GetInt("audiooutput.channels"))
{
default:
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.ac3passthrough" ||
setting == "audiooutput.dtspassthrough" ||
setting == "audiooutput.channellayout" ||
setting == "audiooutput.channels" ||
setting == "audiooutput.multichannellpcm")
{
// only reinit the engine if we not
Expand Down
Expand Up @@ -92,7 +92,7 @@ bool CCoreAudioAEHALOSX::InitializePCM(ICoreAudioSource *pSource, AEAudioFormat
if (!m_audioGraph)
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
if (!m_Passthrough && g_guiSettings.GetInt("audiooutput.mode") == AUDIO_IEC958)
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.truehdpassthrough" ||
setting == "audiooutput.dtshdpassthrough" ||
setting == "audiooutput.channellayout" ||
setting == "audiooutput.channels" ||
setting == "audiooutput.useexclusivemode" ||
setting == "audiooutput.multichannellpcm" ||
setting == "audiooutput.stereoupmix")
Expand Down Expand Up @@ -553,7 +553,7 @@ void CSoftAE::LoadSettings()

/* load the configuration */
m_stdChLayout = AE_CH_LAYOUT_2_0;
switch (g_guiSettings.GetInt("audiooutput.channellayout"))
switch (g_guiSettings.GetInt("audiooutput.channels"))
{
default:
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;
for(int layout = AE_CH_LAYOUT_2_0; layout < AE_CH_LAYOUT_MAX; ++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.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 */)
{ // load our stuff...
bool updated = false;

for (mapIter it = settingsMap.begin(); it != settingsMap.end(); it++)
{
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...
CLog::Log(LOGNOTICE, "Getting hardware information now...");
// 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();
SetString("locale.timezone", timezone);
updated = true;
}
g_timezone.SetTimezone(timezone);
}
Expand All @@ -1417,6 +1443,9 @@ void CGUISettings::LoadXML(TiXmlElement *pRootElement, bool hideSettings /* = fa
g_langInfo.SetSubtitleLanguage(streamLanguage);
else
g_langInfo.SetSubtitleLanguage("");

if (updated)
g_settings.Save();
}

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)
{
CLog::Log(LOGWARNING, "Failed to find previously selected audio sink");
pControl->AddLabel(currentDevice, numberSinks);
pControl->SetValue(numberSinks);
pControl->SetValue(0);
if (!Passthrough)
((CSettingString*)pSetting)->SetData(m_AnalogAudioSinkMap[pControl->GetCurrentLabel()]);
else
((CSettingString*)pSetting)->SetData(m_DigitalAudioSinkMap[pControl->GetCurrentLabel()]);
}
else
pControl->SetValue(selectedValue);
Expand Down