Re: alsa-lib's new API issue (snd_ctl_elem_id_compare)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Mar 08, 2021 at 03:33:46PM +0100, Jaroslav Kysela wrote:
> Dne 08. 03. 21 v 13:58 Takashi Sakamoto napsal(a):
> > My concerns are:
> > 
> > 1. evaluation of numid field is not covered.
> > 
> > This is not preferable since ALSA control core implementation covers two
> > types of comparison; numid only, and the combination iface, device,
> > subdevice, name, and index fields. If the API is produced for general use
> > cases, it should correctly handle the numid-only case, in my opinion.
> 
> My motivation was to allow to use this function for qsort() for example. The
> numid and full-field comparisons are two very different things.
 
Yep. I easily associated sort implementation in hcontrol API or simple
mixer API from your implementation

However, the new API is a part of control API and it just achieves things without
any supplemental information given from userspace implementation.

> > 2. tri-state return value is semantically inconsistent
> 
> It's correct for the sorting (strcmp like).
> 
> > The ID structure includes three types of values; integer, enumeration, and
> > string. In my opinion, tri-state return value from them has different meaning
> > each other.
> True, the signess is the key, the value should be ignored.
 
Semantically, comparability is different from equality. Even if we can find
ordered pair for integer values, we can not find any ordered pair for
enumeration and strings without programmer's arbitrariness. In short, we
can not see order in SNDRV_CTL_ELEM_IFACE_CARD and
SNDRV_CTL_ELEM_IFACE_HWDEP even if in C language enumeration is an alias
to integer value.

As long as ID structure for control element is compound structure with
several types of values, it's not worse to find comparability to it for
sorting purpose.

I wish you to follow specification described in ALSA control core and
UAPI to keep consistency against semantics of IDs for control element
in this subsystem when producing low-level control API.

> > The reason I post this message instead of posting any fix is that the fix
> > to the API affects to alsa-utils, in which the API is used by a patch you
> > applied a few days ago[2]. The patch also includes change to 'AM_PATH_ALSA'
> > declaration in configure.ac with bumped-up version to '1.2.5', and it
> > disables to rebuild alsa-utils on the latest toolchain. (alsa-lib 1.2.5 is
> > not released yet.)
> 
> The latest alsa-lib in the git repo is already set to 1.2.5pre1, so if you
> upgrade alsa-lib, everything should be fine. I was a bit lazy to write a
> configure test and add a wrapper to alsactl to support the older alsa-lib.

The laziness is preferable in the most cases in our work, however in the case 
it's worse. Everything is not fine, breaking things carelessly.

At a quick glance, you've introduced below APIs since v1.2.4 release.

 * int snd_config_get_card()
 * int snd_ctl_elem_id_compare()
 * void snd_ctl_elem_info_set_read_write()
 * void snd_ctl_elem_info_set_tlv_read_write()
 * void snd_ctl_elem_info_set_inactive()

One of the above, 'snd_ctl_elem_id_compare()' is just used by
alsa-utils, and the rest is not used fortunately. I'll post patch to
alsa-utils to get back alsa-lib compatibility to v1.0.27, or better
version number.

For the above comparison API, as I described, it's not appropriate. ID
structure for control element is not comparable, thus it should be dropped
or replaced with equality function such as 'snd_ctl_elem_id_equal()'.

When you need any sorting algorithms, it should be implemented in
application side or alsa-lib API in the other layer such as hcontrol and
simple mixer since control API should follow to specification of ALSA
control written in kernel land.


Thanks

Takashi Sakamoto



[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux