Skip to content
This repository
Browse code

Merge pull request #1828 from Montellese/audio_settings_update

settings: improve migration of audio output settings from (pre-)Eden to Frodo
  • Loading branch information...
commit 4709873071d9b79a34dbf9021230809dfffc69a3 2 parents 61f39b0 + 0a84744
Sascha Montellese authored November 22, 2012
26  xbmc/cores/AudioEngine/AEFactory.cpp
@@ -197,6 +197,32 @@ void CAEFactory::EnumerateOutputDevices(AEDeviceList &devices, bool passthrough)
197 197
     AE->EnumerateOutputDevices(devices, passthrough);
198 198
 }
199 199
 
  200
+void CAEFactory::VerifyOutputDevice(std::string &device, bool passthrough)
  201
+{
  202
+  AEDeviceList devices;
  203
+  EnumerateOutputDevices(devices, passthrough);
  204
+  std::string firstDevice;
  205
+
  206
+  for (AEDeviceList::const_iterator deviceIt = devices.begin(); deviceIt != devices.end(); deviceIt++)
  207
+  {
  208
+    std::string currentDevice = deviceIt->second;
  209
+    /* remember the first device so we can default to it if required */
  210
+    if (firstDevice.empty())
  211
+      firstDevice = deviceIt->second;
  212
+
  213
+    if (deviceIt->second == device)
  214
+      return;
  215
+    else if (deviceIt->first == device)
  216
+    {
  217
+      device = deviceIt->second;
  218
+      return;
  219
+    }
  220
+  }
  221
+
  222
+  /* if the device wasnt found, set it to the first viable output */
  223
+  device = firstDevice;
  224
+}
  225
+
200 226
 std::string CAEFactory::GetDefaultDevice(bool passthrough)
201 227
 {
202 228
   if(AE)
1  xbmc/cores/AudioEngine/AEFactory.h
@@ -46,6 +46,7 @@ class CAEFactory
46 46
   static void SetSoundMode(const int mode);
47 47
   static void OnSettingsChange(std::string setting);
48 48
   static void EnumerateOutputDevices(AEDeviceList &devices, bool passthrough);
  49
+  static void VerifyOutputDevice(std::string &device, bool passthrough);
49 50
   static std::string GetDefaultDevice(bool passthrough);
50 51
   static bool SupportsRaw();
51 52
   static void SetMute(const bool enabled);
4  xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAE.cpp
@@ -142,7 +142,7 @@ bool CCoreAudioAE::OpenCoreAudio(unsigned int sampleRate, bool forceRaw,
142 142
   // on iOS devices we set fixed to two channels.
143 143
   m_stdChLayout = AE_CH_LAYOUT_2_0;
144 144
 #if defined(TARGET_DARWIN_OSX)
145  
-  switch (g_guiSettings.GetInt("audiooutput.channellayout"))
  145
+  switch (g_guiSettings.GetInt("audiooutput.channels"))
146 146
   {
147 147
     default:
148 148
     case  0: m_stdChLayout = AE_CH_LAYOUT_2_0; break; /* do not allow 1_0 output */
@@ -310,7 +310,7 @@ void CCoreAudioAE::OnSettingsChange(const std::string& setting)
310 310
       setting == "audiooutput.mode"              ||
311 311
       setting == "audiooutput.ac3passthrough"    ||
312 312
       setting == "audiooutput.dtspassthrough"    ||
313  
-      setting == "audiooutput.channellayout"     ||
  313
+      setting == "audiooutput.channels"     ||
314 314
       setting == "audiooutput.multichannellpcm")
315 315
   {
316 316
     // only reinit the engine if we not
2  xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAEHALOSX.cpp
@@ -92,7 +92,7 @@ bool CCoreAudioAEHALOSX::InitializePCM(ICoreAudioSource *pSource, AEAudioFormat
92 92
   if (!m_audioGraph)
93 93
     return false;
94 94
 
95  
-  AudioChannelLayoutTag layout = g_LayoutMap[ g_guiSettings.GetInt("audiooutput.channellayout") ];
  95
+  AudioChannelLayoutTag layout = g_LayoutMap[ g_guiSettings.GetInt("audiooutput.channels") ];
96 96
   // force optical/coax to 2.0 output channels
97 97
   if (!m_Passthrough && g_guiSettings.GetInt("audiooutput.mode") == AUDIO_IEC958)
98 98
     layout = g_LayoutMap[1];
4  xbmc/cores/AudioEngine/Engines/SoftAE/SoftAE.cpp
@@ -524,7 +524,7 @@ void CSoftAE::OnSettingsChange(const std::string& setting)
524 524
       setting == "audiooutput.passthroughaac"    ||
525 525
       setting == "audiooutput.truehdpassthrough" ||
526 526
       setting == "audiooutput.dtshdpassthrough"  ||
527  
-      setting == "audiooutput.channellayout"     ||
  527
+      setting == "audiooutput.channels"     ||
528 528
       setting == "audiooutput.useexclusivemode"  ||
529 529
       setting == "audiooutput.multichannellpcm"  ||
530 530
       setting == "audiooutput.stereoupmix")
@@ -553,7 +553,7 @@ void CSoftAE::LoadSettings()
553 553
 
554 554
   /* load the configuration */
555 555
   m_stdChLayout = AE_CH_LAYOUT_2_0;
556  
-  switch (g_guiSettings.GetInt("audiooutput.channellayout"))
  556
+  switch (g_guiSettings.GetInt("audiooutput.channels"))
557 557
   {
558 558
     default:
559 559
     case  0: m_stdChLayout = AE_CH_LAYOUT_2_0; break; /* dont alow 1_0 output */
31  xbmc/settings/GUISettings.cpp
@@ -470,7 +470,7 @@ void CGUISettings::Initialize()
470 470
   map<int,int> channelLayout;
471 471
   for(int layout = AE_CH_LAYOUT_2_0; layout < AE_CH_LAYOUT_MAX; ++layout)
472 472
     channelLayout.insert(make_pair(34100+layout, layout));
473  
-  AddInt(ao, "audiooutput.channellayout", 34100, AE_CH_LAYOUT_2_0, channelLayout, SPIN_CONTROL_TEXT);
  473
+  AddInt(ao, "audiooutput.channels", 34100, AE_CH_LAYOUT_2_0, channelLayout, SPIN_CONTROL_TEXT);
474 474
   AddBool(ao, "audiooutput.normalizelevels", 346, true);
475 475
   AddBool(ao, "audiooutput.stereoupmix", 252, false);
476 476
 
@@ -1354,10 +1354,35 @@ void CGUISettings::GetSettingsGroup(CSettingsCategory* cat, vecSettings &setting
1354 1354
 
1355 1355
 void CGUISettings::LoadXML(TiXmlElement *pRootElement, bool hideSettings /* = false */)
1356 1356
 { // load our stuff...
  1357
+  bool updated = false;
  1358
+
1357 1359
   for (mapIter it = settingsMap.begin(); it != settingsMap.end(); it++)
1358 1360
   {
1359 1361
     LoadFromXML(pRootElement, it, hideSettings);
1360 1362
   }
  1363
+
  1364
+  // check if we are updating to Frodo and need to update from
  1365
+  // audiooutput.channellayout to audiooutput.channels
  1366
+  TiXmlNode *channelNode = pRootElement->FirstChild("audiooutput");
  1367
+  if (channelNode != NULL)
  1368
+  {
  1369
+    channelNode = channelNode->FirstChild("channellayout");
  1370
+    CSettingInt* channels = (CSettingInt*)GetSetting("audiooutput.channels");
  1371
+    if (channelNode != NULL && channelNode->FirstChild() != NULL && channels != NULL)
  1372
+    {
  1373
+      channels->FromString(channelNode->FirstChild()->ValueStr());
  1374
+      if (channels->GetData() < AE_CH_LAYOUT_MAX - 1)
  1375
+        channels->SetData(channels->GetData() + 1);
  1376
+
  1377
+      // let's just reset the audiodevice settings as well
  1378
+      std::string audiodevice = GetString("audiooutput.audiodevice");
  1379
+      CAEFactory::VerifyOutputDevice(audiodevice, false);
  1380
+      SetString("audiooutput.audiodevice", audiodevice.c_str());
  1381
+
  1382
+      updated = true;
  1383
+    }
  1384
+  }
  1385
+
1361 1386
   // Get hardware based stuff...
1362 1387
   CLog::Log(LOGNOTICE, "Getting hardware information now...");
1363 1388
   // FIXME: Check if the hardware supports it (if possible ;)
@@ -1401,6 +1426,7 @@ void CGUISettings::LoadXML(TiXmlElement *pRootElement, bool hideSettings /* = fa
1401 1426
     {
1402 1427
       timezone = g_timezone.GetOSConfiguredTimezone();
1403 1428
       SetString("locale.timezone", timezone);
  1429
+      updated = true;
1404 1430
     }
1405 1431
     g_timezone.SetTimezone(timezone);
1406 1432
   }
@@ -1417,6 +1443,9 @@ void CGUISettings::LoadXML(TiXmlElement *pRootElement, bool hideSettings /* = fa
1417 1443
     g_langInfo.SetSubtitleLanguage(streamLanguage);
1418 1444
   else
1419 1445
     g_langInfo.SetSubtitleLanguage("");
  1446
+
  1447
+  if (updated)
  1448
+    g_settings.Save();
1420 1449
 }
1421 1450
 
1422 1451
 void CGUISettings::LoadFromXML(TiXmlElement *pRootElement, mapIter &it, bool advanced /* = false */)
7  xbmc/settings/GUIWindowSettingsCategory.cpp
@@ -2910,8 +2910,11 @@ void CGUIWindowSettingsCategory::FillInAudioDevices(CSetting* pSetting, bool Pas
2910 2910
   if (selectedValue < 0)
2911 2911
   {
2912 2912
     CLog::Log(LOGWARNING, "Failed to find previously selected audio sink");
2913  
-    pControl->AddLabel(currentDevice, numberSinks);
2914  
-    pControl->SetValue(numberSinks);
  2913
+    pControl->SetValue(0);
  2914
+    if (!Passthrough)
  2915
+      ((CSettingString*)pSetting)->SetData(m_AnalogAudioSinkMap[pControl->GetCurrentLabel()]);
  2916
+    else
  2917
+      ((CSettingString*)pSetting)->SetData(m_DigitalAudioSinkMap[pControl->GetCurrentLabel()]);
2915 2918
   }
2916 2919
   else
2917 2920
     pControl->SetValue(selectedValue);

0 notes on commit 4709873

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