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

ALSA cards missing in Kodi's audio device list #15757

Closed
1 of 7 tasks
HiassofT opened this issue Mar 16, 2019 · 17 comments
Closed
1 of 7 tasks

ALSA cards missing in Kodi's audio device list #15757

HiassofT opened this issue Mar 16, 2019 · 17 comments

Comments

@HiassofT
Copy link
Contributor

Bug report

Describe the bug

The list of ALSA devices is missing cards, for example on a Raspberry Pi with enabled on-board ALSA audio and an audio card only the on-board ALSA device is listed.

This issue was recently reported on the forum https://forum.kodi.tv/showthread.php?tid=298461&pid=2834194#pid2834194 with LibreELEC Milhouse testbuilds, current LibreELEC 9 and older builds also show this behavior.

Expected Behavior

Kodi lists both on-board ALSA and the addon card.

Actual Behavior

Kodi only lists the on-board audio (bcm2835 ALSA), the addon card is missing in the audio device list.

To Reproduce

Enable both on-board audio and an audio card in config.txt, eg with these line (no actual hardware required)

dtparam=audio=on
dtoverlay=hifiberry-dac

Debuglog

aplay -L lists both cards:

le9:~ # aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device
sysdefault:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device
default:CARD=sndrpihifiberry
    snd_rpi_hifiberry_dac,
    Default Audio Device
sysdefault:CARD=sndrpihifiberry
    snd_rpi_hifiberry_dac,
    Default Audio Device

But Kodi only enumerates bcm2835 - debug log: http://ix.io/1DE9

Additional context or screenshots (if appropriate)

It looks like a key point to trigger the issue is that the addon ALSA card doesn't have (or need) an ALSA card conf which creates additional PCMs like front, surroundX etc. Only the default plughw PCM (plus it's sysdefault mirror) from alsa-lib are created, and that's fine for the card as it's a simple 2-channel only audio device.

From a quick glance at the code the "default" PCM enumeration handling looks a bit odd and doesn't seem to cover the case where multiple card-specific default PCMs are available on the system. Only the first default PCM (which on typical desktop Linux systems with Pulse audio is a global "pcm.!default" PCM) are picked up, other (sys)default PCMs are filtered out, hence the card isn't shown in the list.

Your Environment

Used Operating system: Linux / LibreELEC

  • Android

  • iOS

  • Linux

  • OSX

  • Raspberry-Pi

  • Windows

  • Windows UWP

  • Operating system version/name: LibreELEC 9.0.1, LibreELEC Milhouse RPi2 builds

  • Kodi version: 18.1 master

@fritsch
Copy link
Member

fritsch commented Mar 16, 2019

Startup - Dependency issue. A simple: systemctl restart kodi after some 20 seconds of uptime should fix it.

@HiassofT
Copy link
Contributor Author

no, kodi restart doesn't help: http://ix.io/1DGt

The missing "default" audio device on the second card is rather consistent. Here's an example with the Cirrus Logic Audio Card, which uses an alsa card conf to create an iec958 PCM (enabling output only on S/PDIF outputs and setting AES status bits) in addition to the default plughw PCM (which outputs both to analog and S/PDIF):

le9:~ # aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device
sysdefault:CARD=ALSA
    bcm2835 ALSA, bcm2835 ALSA
    Default Audio Device
default:CARD=RPiCirrus
    RPi-Cirrus,
    Default Audio Device
sysdefault:CARD=RPiCirrus
    RPi-Cirrus,
    Default Audio Device
iec958:CARD=RPiCirrus,DEV=0
    RPi-Cirrus,
    IEC958 (S/PDIF) Digital Audio Output

Kodi enumerates bcm2835 ALSA and RPi Cirrus iec958 PCM: http://ix.io/1DGp

When bcm2835 is disabled and RPi Cirrus is the only card both default and iec958 are enumerated

le9:~ # aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=RPiCirrus
    RPi-Cirrus,
    Default Audio Device
sysdefault:CARD=RPiCirrus
    RPi-Cirrus,
    Default Audio Device
iec958:CARD=RPiCirrus,DEV=0
    RPi-Cirrus,
    IEC958 (S/PDIF) Digital Audio Output

Kodi log: http://ix.io/1DGx

It looks to me like we need card specific "Analog"/"default" entries which then make it possible to select default:CARD=... (or hw:CARD=...) in addition to the current default entry (which will be useful for systems with Pulseaudio)

@fritsch
Copy link
Member

fritsch commented Mar 16, 2019

@fritsch
Copy link
Member

fritsch commented Mar 16, 2019

Your kodi.log does not match our enumeration: https://github.com/xbmc/xbmc/blob/master/xbmc/windowing/rpi/WinSystemRpi.cpp#L49

Custom patches in LE?

@HiassofT
Copy link
Contributor Author

LibreELEC contains a patch to register both AESinkALSA and AESinkPulse (the latter is only used for bluetooth audio, Pulse is installed without pulse.conf in alsa.conf.d and doesn't grab any ALSA devices):
https://github.com/LibreELEC/LibreELEC.tv/blob/master/packages/mediacenter/kodi/patches/kodi-100.14-use-alsa-and-pulse-together.patch
but AESinkALSA.cpp is unmodified
https://github.com/popcornmix/xbmc/commits/newclock5_18.1rc1-Leia/xbmc/cores/AudioEngine/Sinks/AESinkALSA.cpp

hias@lenny:~/private/libreelec/libreelec-git$ git grep AESinkALSA.cpp packages/mediacenter/kodi/patches/
hias@lenny:~/private/libreelec/libreelec-git$ 

@fritsch
Copy link
Member

fritsch commented Mar 17, 2019 via email

@HiassofT
Copy link
Contributor Author

I did a test on Raspbian, using plain kodi master (commit 84498a1) with this patch added HiassofT@7dc284c

This was with RPi on-board audio (dtparam=audio=on) and RPi-Cirrus card with alsa card conf to get iec958. Like Debian/Ubuntu Raspbian has "defaults.namehint.showall on" in alsa.conf so PCMs without hints (hw, dmix, ...) are enumerated, too.

Here's aplay -L output: http://ix.io/1DQs
And here's kodi log with verbose enumeration: http://ix.io/1DQt

default:CARD=xxx and sysdefault:CARD=xxx are skpped, RPi-Cirrus doesn't have front:... so only iec958 is enumerated.

I then did another quick test with sysdefault exclusion dropped HiassofT@705ac0a

kodi log http://ix.io/1DQz and audio device list now have additional entries "bcm2835 ALSA, bcm2835 ALSA" and "RPi-Cirrus, Analog".

I haven't tested yet on a device with usual front/surround/... PCMs but I guess with the quick hack test sysdefault:xxx and @:xxx would show up with the same display name in the list - so the display name would need to be adjusted so that @:xxx and sysdefault:xxx can be distinguished. Or remove sysdefault: from the list if @: is enumerated - could be a bit tricky though

@fritsch
Copy link
Member

fritsch commented Mar 18, 2019

Thanks for your testing.

@fritsch
Copy link
Member

fritsch commented Mar 18, 2019

I am currently away Snowboarding - choose whatever you think is best - I will review it :-)

@HiassofT
Copy link
Contributor Author

enjoy your time!

I have a first version running (with sysdefault removed if "@" is present), will PR it after some more testing

@fritsch
Copy link
Member

fritsch commented Mar 19, 2019

@anssih: what's your take on this? Original code was yours and works for many years now.

@anssih
Copy link
Member

anssih commented Mar 19, 2019

@fritsch thanks for the ping :)

@HiassofT Thanks for the analysis, you seem to be right. The assumption that all "sysdefault" devices are accompanied by "front" is not true.

One option is indeed to drop sysdefault exclusion and then drop sysdefault if also "@" exists for the CARD, like done in #15744.

Another, AFAICS simpler option would be to add "sysdefault" devices as "@" like "front" devices are. Maybe even instead of "front" to simplify the code, as "sysdefault" was added to ALSA already back in 2011.
I.e. just change "front" => "sysdefault" on lines 1145-1152 and "sysdefault" => "front" on line 1168.

@HiassofT Can you check if such a change would work, instead? And if so, what do you think?

@HiassofT
Copy link
Contributor Author

@anssih thanks a lot for your feedback!

I had thought about enumerating sysdefault instead of front as well but one problem is that front has a device assigned (and in theory cards could have multiple front/surround devices on different devs) whereas sysdefault is a "card-global" device without a dev.

From a quick glance through the limited sets of cards I have here (Intel HDA, MAudio 2496 with ICE1712 and a USB audio card) DEV of front/... is 0 on all of them and the Alsa card confs shipped with alsa-lib also seem to have DEV 0 for the front/... PCMs (I haven't checked all of the confs though).

So while "guessing" DEV=0 would probably work in most of the cases I wasn't quite satisfied with the approach as it could fail in some corner cases or with future cards. Therefore I went for the PRed approach of removing sysdefault if we also enumerate a front as it will work in those corner cases, too.

@anssih
Copy link
Member

anssih commented Mar 27, 2019

Sorry for the delay.

@HiassofT OK, makes sense.

@sunbladehub
Copy link

Can you please let me know if this observation is related to the changes above?

A fresh installation of LibreELEC 9.1.002 on a Pi 4B shows the following audio devices:

LibreELEC Master

Upon upgrading to the latest Milhouse build (via custom channel: http://milhouse.libreelec.tv/builds/master/RPi4) the audio devices change:

Milhouse Build

Is there a way to get the original device list on the Milhouse build?

@MilhouseVH
Copy link
Contributor

MilhouseVH commented Aug 21, 2019

@ailicic My "Milhouse" builds do not yet support RPi4 in any meaningful way - there's a lot that doesn't work (which is known, and on a list to be fixed). Any RPi4-based builds of mine that you've found are early pipe-cleaning trial builds and the RPi4 (with Kodi 19 and kernel 5.y) is still some way from where it needs to be for public testing, which is why I'm not yet publicising these builds, or taking bug reports.

For RPi4, the only supported releases are currently the official LibreELEC 9.2 alpha builds.

@sunbladehub
Copy link

Alright. Thanks for the info. Great work on the custom build!

@HiassofT HiassofT closed this as completed Dec 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants