Bug 327471 - ALSA multiple soundcard naming collision chaos
Summary: ALSA multiple soundcard naming collision chaos
Status: RESOLVED FIXED
Alias: None
Product: kmix
Classification: Applications
Component: general (show other bugs)
Version: 4.4
Platform: unspecified Linux
: VHI normal
Target Milestone: ---
Assignee: Christian Esken
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-11 22:06 UTC by howl
Modified: 2015-05-30 13:14 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 4.13


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description howl 2013-11-11 22:06:29 UTC
For some reason, my kernel shows me something like this in /proc/asound/cards

 0 [Generic        ]: HDA-Intel - HD-Audio Generic
                      HD-Audio Generic at 0xfe01c000 irq 50
 1 [Generic_1      ]: HDA-Intel - HD-Audio Generic
                      HD-Audio Generic at 0xfe020000 irq 16

The first one is HDMI on graphic card, the second one is normal soundcard.

As you might guess, when the Mixer_ALSA is asked about device name, it reports the same string "HD-Audio Generic" for both devices. Because the HDMI is first, it will be the only Mixer the kmix can ever interact with, because of key collision.

Trying to find out, if there could be some way to add that nasty "_1" suffix from alsa to one of the cards, I've stumbled upon a "snd_ctl_card_info_get_mixername" function. So my current hack to get a working kmix is this one:

diff --git a/backends/mixer_alsa9.cpp b/backends/mixer_alsa9.cpp
index 36a6dd6..b457b8c 100644
--- a/backends/mixer_alsa9.cpp
+++ b/backends/mixer_alsa9.cpp
@@ -314,7 +314,7 @@ int Mixer_ALSA::openAlsaDevice(const QString& devName)
         snd_ctl_close( ctl_handle );
         return Mixer::ERR_READ;
     }
-    const char* mixer_card_name =  snd_ctl_card_info_get_name( hw_info );
+    const char* mixer_card_name =  snd_ctl_card_info_get_mixername( hw_info );
     m_mixerName = mixer_card_name;
 
     snd_ctl_close( ctl_handle );

Side effect is that now the kmix is showing me more reasonable names: "ATI_ID_aa01" and "Realtek_ALC889". Thought i did find a way to change the soundcard ID, I could find a way to do it with name.

It might help to separate the name for key-creation from name that would be visible to users and use the "hw:%" (or just alsa id) to create a key. But I didn't check if that could be a plausible solution.

Reproducible: Always
Comment 1 Christian Esken 2013-12-18 13:22:22 UTC
Well, keys are based also on "card number", like seen in the kmixrc. Here you see the name "Creative_X-Fi" AND device number "1":

MasterMixer=ALSA::Creative_X-Fi:1

KMix builds the number "1" itself, to avoid issues on kernel soundcard reordering. "1" means, the first detected card with the name "Creative_X-Fi". So for your case there should be two cards:
ALSA::HDA-Intel - HD-Audio Generic:1
ALSA::HDA-Intel - HD-Audio Generic:2

If there is a key collision then it is a bug. I do not find one, though.
Are you able to debug, to find the root cause?
Comment 2 Christian Esken 2013-12-18 13:35:04 UTC
Probably related ticket is bug 315289.
Comment 3 Christian Esken 2013-12-18 17:21:22 UTC
Short summary of the current findings:
 - Key is properly built from ID: backend.getId()
 - cardNumber is taken from the card counter, and that one uses the NAME as a key (so we count per name)

So far so good. This is exactly as anticipated, and alone it does not explain the issue. Any more information would be helpful.

--- Internal work note follows: ------------------------------------------------------
 Mixer::recreateId() is not well done:
 - It is called twice: DBUSWrapper and possiblyAddMixer()
 - It is called after setting up the Timers. In a very(!) theoretical setup they could trigger before the _id is properly set.
 - Some time ago I annotated it with "The current solution works but is very hacky"
=> Possibly refactor ID creation now fully in the backends.
Comment 4 Christian Esken 2013-12-18 23:44:30 UTC
I found the cause. it is definitely 100% broken.

------------------------------------------
bool MixerToolBox::possiblyAddMixer(Mixer *mixer) 
{
	int newCardInstanceNum = 1 + s_mixerNums[mixer->getBaseName()];
        // OUCH ^^^^ mixer->getBaseName() is always empty here. As the name is set in openIfValid()
    if ( mixer->openIfValid(newCardInstanceNum) )
{
 // ...
        	s_mixerNums[mixer->getBaseName()] = newCardInstanceNum;
           // ^^^ Now mixer->getBaseName() is set
------------------------------------------

This means, every card gets an instanceNumber of 1. Only solution is to move teh full key generation in the backend (where it actually belogs).
Comment 5 Michal Humpula 2013-12-27 09:22:38 UTC
Hi Christian,

Thanks for looking into this. I changed email so I didn't get the info in time. If you haven't work on it yet, I think I would be able to post a suggested fix to reviewboard.
Comment 6 Christian Esken 2014-01-05 19:56:31 UTC
I am in the process of fixing it. Thanks for the feedback.
Comment 7 Christian Esken 2014-08-11 10:31:41 UTC
Fixed, at least for built-in cards that the kernel always detects in the same order. Hotplugged or reordered cards still have some problems, e.g. if one has two cards called "USB". But this is not the issue in this ticket, thus considering the bug fixed.
Should be fixed in KDE 4.13.
Comment 8 Richard Van Den Boom 2015-05-30 13:14:00 UTC
I don't really understand why this bug is marked as fixed in 4.13.
I'm running kmix 4.14.8 and can't still properly manage HD-Audio devices.
Juste as the inital poster, I have two devices reported with identical names by the kernel but different ID (A bit weird in my opinion but that's the way it is):

bash-4.3$ cat  /proc/asound/cards
 0 [Generic        ]: HDA-Intel - HD-Audio Generic
                      HD-Audio Generic at 0xfeb64000 irq 41
 1 [Generic_1      ]: HDA-Intel - HD-Audio Generic
                      HD-Audio Generic at 0xfeb60000 irq 16
 2 [CameraVenu     ]: USB-Audio - Vimicro USB 2.0 PC Camera (Venu
                      Vimicro Vimicro USB 2.0 PC Camera (Venu at usb-0000:00:12.2-5, high speed

Kmix still defaults to the first "HD-Audio Generic" device and never allows me to manage the second with "Generic_1" ID. The later does work with Alsa and I can make use of it with VLC or Skype, albeit with some manual configuration.