RFC: Expose soundcard busid to userspace
Hi,
I've got the problem, that the order of my soundcards is different after every reboot. I've tracked this problem down to udev and kernel hotplugging. Setting an index for every used driver seems to help.
The real problems are starting if I plug in some webcams with audio or USB headsets. Because my computer is in a testing lab, this happens very often. So the id's get mixed up nearly on every boot. I'd like the idea of an stable identifier for a soundcard. The soundcard name would work - but what happens if there are some soundcards with the same name? So I thought the bus_id would be a (nearly) perfect id. It is stable as long as you don't plug the soundcard in another pci or usb port.
The attached patches are a proof of concept. The problem I see are old kernels that don't support the busid field. The current ioctl does not zero the reserved space. So alsa-lib don't know if the data at busid is just garbage or a busid. Another possible implementation would be the introduction of another ioctl.
So what do you think of the introduction of a busid or stable id in alsa-lib. Perhaps some soundcards have an unique serial number?
Thanks,
Gregor
Index: core/control.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/core/control.c,v retrieving revision 1.69
control.c +2 -0
@@ -20,6 +20,7 @@*/ #include <sound/driver.h> +#include <linux/device.h> #include <linux/threads.h> #include <linux/interrupt.h> #include <linux/smp_lock.h>
@@ -538,6 +539,7 @@strlcpy (info->longname, card->longname,sizeof (info->longname));strlcpy (info->mixername, card->mixername,sizeof (info->mixername));strlcpy (info->components, card->components,sizeof (info->components)); +strlcpy (info->busid, card->dev->bus_id,sizeof (info->busid));up_read (&snd_ioctl_rwsem);if (copy_to_user (arg, info,sizeof (struct snd_ctl_card_info ))) {kfree (info);
? test/oldapi
Index: include/control.h
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/include/control.h,v retrieving revision 1.101
control.h +1 -0
@@ -290,6 +290,7 @@const char *snd_ctl_card_info_get_longname (const snd_ctl_card_info_t *obj);const char *snd_ctl_card_info_get_mixername (const snd_ctl_card_info_t *obj);const char *snd_ctl_card_info_get_components (const snd_ctl_card_info_t *obj); +const char *snd_ctl_card_info_get_busid (const snd_ctl_card_info_t *obj);size_t snd_ctl_event_sizeof (void );/** \hideinitializer
Index: include/sound/asound.h
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/include/sound/asound.h,v retrieving revision 1.22
sound/asound.h +2 -1
@@ -727,7 +727,8 @@unsigned char reserved_[16 ];/* reserved for future (was ID of mixer) */ unsigned char mixername[80 ];/* visual mixer identification */ unsigned char components[80 ];/* card components / fine identification, delimited with one space (AC97 etc..) */ -unsigned char reserved[48 ];/* reserved for future */ +unsigned char busid[20 ];/* physical bus id of soundcard */ +unsigned char reserved[28 ];/* reserved for future */ };enum sndrv_ctl_elem_type {
Index: src/control/control.c
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/src/control/control.c,v retrieving revision 1.108
control/control.c +11 -0
@@ -1365,6 +1365,17 @@ }/** +* \brief Get card bus id from a CTL card info +* \param obj CTL card info +* \return physical card bus id +*/ +const char *snd_ctl_card_info_get_busid (const snd_ctl_card_info_t *obj) +{ +assert (obj); +return (const char *)obj->busid; +} + +/** * \brief get size of #snd_ctl_event_t * \return size in bytes */
Index: test/control.c
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/test/control.c,v
retrieving revision 1.12
control.c +1 -0
@@ -40,6 +40,7 @@printf (" longname - '%s'\n" ,snd_ctl_card_info_get_longname (info));printf (" mixername - '%s'\n" ,snd_ctl_card_info_get_mixername (info));printf (" components - '%s'\n" ,snd_ctl_card_info_get_components (info)); +printf (" busid - '%s'\n" ,snd_ctl_card_info_get_busid (info)); dev =-1 ;while (1 ) {snd_pcm_sync_id_t sync;
At Wed, 4 Jan 2006 18:21:52 +0100,
Quoted 7 lines · Gregor Jasny
Hi,
I've got the problem, that the order of my soundcards is different after every reboot. I've tracked this problem down to udev and kernel hotplugging. Setting an index for every used driver seems to help.
Quoted 6 lines
The real problems are starting if I plug in some webcams with audio or USB headsets. Because my computer is in a testing lab, this happens very often. So the id's get mixed up nearly on every boot. I'd like the idea of an stable identifier for a soundcard. The soundcard name would work - but what happens if there are some soundcards with the same name?
It will be xxx_1.
Quoted 3 lines
So I thought the
bus_idwould be a (nearly) perfect id. It is stable as long as you don't plug the soundcard in another pci or usb port.
It's an interresting idea. Maybe we need to extend the id parser of alsa-lib to accept busid, too?
Quoted 5 lines
The attached patches are a proof of concept. The problem I see are old kernels that don't support the busid field. The current ioctl does not zero the reserved space. So alsa-lib don't know if the data at busid is just garbage or a busid. Another possible implementation would be the introduction of another ioctl.
We can check a protocol number to determine the capability.
Takashi
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click