Permalink
Browse files

AESinkALSA: Factor guessing AEDeviceType to a separate function

  • Loading branch information...
1 parent 7ad9c1b commit 139b521b5c8c63800d2d43a5aac49407062438f2 @anssih anssih committed Jul 21, 2012
Showing with 18 additions and 15 deletions.
  1. +17 −14 xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp
  2. +1 −1 xbmc/cores/AudioEngine/Sinks/AESinkALSA.h
@@ -151,10 +151,12 @@ bool CAESinkALSA::Initialize(AEAudioFormat &format, std::string &device)
format.m_channelLayout = m_channelLayout;
+ AEDeviceType devType = AEDeviceTypeFromName(device);
+
std::string AESParams;
/* digital interfaces should have AESx set, though in practice most
* receivers don't care */
- if (m_passthrough || device.substr(0, 6) == "iec958" || device.substr(0, 4) == "hdmi")
+ if (m_passthrough || devType == AE_DEVTYPE_HDMI || devType == AE_DEVTYPE_IEC958)
GetAESParams(format, AESParams);
CLog::Log(LOGINFO, "CAESinkALSA::Initialize - Attempting to open device \"%s\"", device.c_str());
@@ -826,6 +828,16 @@ void CAESinkALSA::EnumerateDevicesEx(AEDeviceInfoList &list)
}
}
+AEDeviceType CAESinkALSA::AEDeviceTypeFromName(const std::string &name)
+{
+ if (name.substr(0, 4) == "hdmi")
+ return AE_DEVTYPE_HDMI;
+ else if (name.substr(0, 6) == "iec958")
+ return AE_DEVTYPE_IEC958;
+
+ return AE_DEVTYPE_PCM;
+}
+
std::string CAESinkALSA::GetParamFromName(const std::string &name, const std::string &param)
{
/* name = "hdmi:CARD=x,DEV=y" param = "CARD" => return "x" */
@@ -860,16 +872,7 @@ void CAESinkALSA::EnumerateDevice(AEDeviceInfoList &list, const std::string &dev
CAEDeviceInfo info;
info.m_deviceName = device;
-
- bool isHDMI = (device.substr(0, 4) == "hdmi");
- bool isSPDIF = (device.substr(0, 6) == "iec958");
-
- if (isHDMI)
- info.m_deviceType = AE_DEVTYPE_HDMI;
- else if (isSPDIF)
- info.m_deviceType = AE_DEVTYPE_IEC958;
- else
- info.m_deviceType = AE_DEVTYPE_PCM;
+ info.m_deviceType = AEDeviceTypeFromName(device);
if (cardNr >= 0)
{
@@ -878,7 +881,7 @@ void CAESinkALSA::EnumerateDevice(AEDeviceInfoList &list, const std::string &dev
if (snd_card_get_name(cardNr, &cardName) == 0)
info.m_displayName = cardName;
- if (isHDMI && info.m_displayName.size() > 5 &&
+ if (info.m_deviceType == AE_DEVTYPE_HDMI && info.m_displayName.size() > 5 &&
info.m_displayName.substr(info.m_displayName.size()-5) == " HDMI")
{
/* We already know this is HDMI, strip it */
@@ -895,7 +898,7 @@ void CAESinkALSA::EnumerateDevice(AEDeviceInfoList &list, const std::string &dev
if (pcminfoName != "USB Audio")
info.m_displayNameExtra = pcminfoName;
- if (isHDMI)
+ if (info.m_deviceType == AE_DEVTYPE_HDMI)
{
/* replace, this was likely "HDMI 0" */
info.m_displayNameExtra = "HDMI";
@@ -950,7 +953,7 @@ void CAESinkALSA::EnumerateDevice(AEDeviceInfoList &list, const std::string &dev
}
}
}
- else if (isSPDIF)
+ else if (info.m_deviceType == AE_DEVTYPE_IEC958)
{
/* append instead of replace, pcminfoName is useful for S/PDIF */
if (!info.m_displayNameExtra.empty())
@@ -79,7 +79,7 @@ class CAESinkALSA : public IAESink
static bool OpenPCMDevice(const std::string &name, const std::string &params, int channels, snd_pcm_t **pcmp, snd_config_t *lconf, bool preferDmixStereo = false);
static AEDeviceType AEDeviceTypeFromName(const std::string &name);
- static void GetParamFromName(const std::string &name, const std::string &param, std::string &value);
+ static std::string GetParamFromName(const std::string &name, const std::string &param);
static void EnumerateDevice(AEDeviceInfoList &list, const std::string &device, const std::string &description, snd_config_t *config);
static bool SoundDeviceExists(const std::string& device);
static bool GetELD(snd_hctl_t *hctl, int device, CAEDeviceInfo& info, bool& badHDMI);

0 comments on commit 139b521

Please sign in to comment.