Skip to content

Commit

Permalink
Merge pull request #15774 from HiassofT/alsa-enumeration
Browse files Browse the repository at this point in the history
AESinkALSA: fix enumeration of cards without front devices
  • Loading branch information
fritsch committed Mar 28, 2019
2 parents c5fb63b + 6480ee3 commit c5a5942
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,10 +1153,14 @@ void CAESinkALSA::EnumerateDevicesEx(AEDeviceInfoList &list, bool force)

/* Do not enumerate "default", it is already enumerated above. */

/* Do not enumerate the sysdefault or surroundXX devices, those are
* always accompanied with a "front" device and it is handled above
* as "@". The below devices will be automatically used if available
* for a "@" device. */
/* Do not enumerate the surroundXX devices, those are always accompanied
* with a "front" device and it is handled above as "@". The below
* devices plus sysdefault will be automatically used if available
* for a "@" device.
* sysdefault devices are enumerated as not all cards have front/surround
* devices. For cards with front/surround devices the sysdefault
* entry will be removed in a second pass after enumeration.
*/

/* Ubuntu has patched their alsa-lib so that "defaults.namehint.extended"
* defaults to "on" instead of upstream "off", causing lots of unwanted
Expand All @@ -1165,7 +1169,6 @@ void CAESinkALSA::EnumerateDevicesEx(AEDeviceInfoList &list, bool force)
* "plughw", "dsnoop"). */

else if (baseName != "default"
&& baseName != "sysdefault"
&& baseName != "surround40"
&& baseName != "surround41"
&& baseName != "surround50"
Expand Down Expand Up @@ -1200,6 +1203,32 @@ void CAESinkALSA::EnumerateDevicesEx(AEDeviceInfoList &list, bool force)
list[0].m_displayName = "Default";
}

/* cards with surround entries where sysdefault should be removed */
std::set<std::string> cardsWithSurround;

for (AEDeviceInfoList::iterator it1 = list.begin(); it1 != list.end(); ++it1)
{
std::string baseName = it1->m_deviceName.substr(0, it1->m_deviceName.find(':'));
std::string card = GetParamFromName(it1->m_deviceName, "CARD");
if (baseName == "@" && !card.empty())
cardsWithSurround.insert(card);
}

if (!cardsWithSurround.empty())
{
/* remove sysdefault entries where we already have a surround entry */
AEDeviceInfoList::iterator iter = list.begin();
while (iter != list.end())
{
std::string baseName = iter->m_deviceName.substr(0, iter->m_deviceName.find(':'));
std::string card = GetParamFromName(iter->m_deviceName, "CARD");
if (baseName == "sysdefault" && cardsWithSurround.find(card) != cardsWithSurround.end())
iter = list.erase(iter);
else
iter++;
}
}

/* lets check uniqueness, we may need to append DEV or CARD to DisplayName */
/* If even a single device of card/dev X clashes with Y, add suffixes to
* all devices of both them, for clarity. */
Expand Down

0 comments on commit c5a5942

Please sign in to comment.