[alsa-devel] [PATCH] control, hw, rawmidi: accept control device node as card identifier when opening

Jaroslav Kysela perex at perex.cz
Tue May 12 16:40:24 CEST 2009

On Tue, 12 May 2009, Lennart Poettering wrote:

> On Tue, 12.05.09 14:42, Jaroslav Kysela (perex at perex.cz) wrote:
>> On Tue, 12 May 2009, Lennart Poettering wrote:
>>> With my original patch there are no superfluous opens.
>> If application uses more *open() calls from alsa-lib for one card (for
>> example to open ctl handle and pcm handle), it's better to obtain card
>> index at first, because each conversion requires one or more (card id)
>> open/close sequence for control device to get card_info. Providing direct
>> card index eliminates this conversion. It's just suggested optimization.
> I think if apps want to open ctl and hw at the same time the most
> elegant way would be this:
> <snip>
> snd_pcm_open(&pcm, "hw:/dev/snd/by-path/yaddayadda", ...);
> snd_pcm_info(pcm, &info);
> snd_ctl_open(&ctl, snprint("hw:%i", snd_pcm_info_get_card(info)));
> </snip>
> With my patch that costs exactly two open() calls. It's also more
> flexible since it will handle arbitrary device strings, doesn't need
> to hardcode "hw:".

The mentioned code will work with my patch as well. There is no 
difference, because extended snd_card_get_index() is called from _*open() 
callbacks when card argument is a string.

> You seem to suggest this:
> <snip>
> i = snd_card_index("hw:/dev/snd/by-path/yaddayadda");

It should be: i = snd_card_index("/dev/snd/by-path/yaddayadda");

> snd_hw_open(&hw, snprint("hw:%i", i));

You mean probably snd_pcm_open() here.

> snd_ctl_open(&ctl, snprint("hw:%i", i));
> </snip>
> Which your patch that costs three open()s.

It's similar to your patch. Two open calls. snd_pcm_open() does not use 
ctl device if a direct card index is specified.

> And hardcodes "hw".

It's not relevant. Your code also hardcodes "hw" (and application should 
decide if hw: is a proper interface not alsa-lib - any defined device 
which accepts the card argument will work).

> I really would like to know why my patch was so bad?

I do not think that an addition of extra argument to open() calls is good 
in this case. The card identification for open() calls is string anyway, 
because you may use syntax like 'hw:FirstHDACard' - see 'cat 
/proc/asound/cards' for string identification. All other extensions 
should be in the configuration area (in .conf files or configuration 
parsing code).


Jaroslav Kysela <perex at perex.cz>
Linux Kernel Sound Maintainer
ALSA Project, Red Hat, Inc.

More information about the Alsa-devel mailing list