Change numid properly with external ctl plugins

So far, external ctl plugins don't change numid.  Some apps expect the
non-zero numids with list, and the plugin doesn't work for them.

This patch adds a fake numid to each control based on the offset
number.  The lookup with non-zero numid is supported but is pretty
inefficient.  Eventually the plugin side may be optimized to look
at the numid, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2009-02-17 16:58:12 +01:00
parent e38f921625
commit 81241ffb81

View file

@ -107,6 +107,7 @@ static int snd_ctl_ext_elem_list(snd_ctl_t *handle, snd_ctl_elem_list_t *list)
ret = ext->callback->elem_list(ext, offset, ids);
if (ret < 0)
return ret;
ids->numid = offset + 1; /* fake number */
list->used++;
offset++;
ids++;
@ -114,13 +115,24 @@ static int snd_ctl_ext_elem_list(snd_ctl_t *handle, snd_ctl_elem_list_t *list)
return 0;
}
static snd_ctl_ext_key_t get_elem(snd_ctl_ext_t *ext, snd_ctl_elem_id_t *id)
{
int numid = id->numid;
if (numid > 0) {
ext->callback->elem_list(ext, numid - 1, id);
id->numid = numid;
} else
id->numid = 0;
return ext->callback->find_elem(ext, id);
}
static int snd_ctl_ext_elem_info(snd_ctl_t *handle, snd_ctl_elem_info_t *info)
{
snd_ctl_ext_t *ext = handle->private_data;
snd_ctl_ext_key_t key;
int type, ret;
key = ext->callback->find_elem(ext, &info->id);
key = get_elem(ext, &info->id);
if (key == SND_CTL_EXT_KEY_NOT_FOUND)
return -ENOENT;
ret = ext->callback->get_attribute(ext, key, &type, &info->access, &info->count);
@ -200,7 +212,7 @@ static int snd_ctl_ext_elem_read(snd_ctl_t *handle, snd_ctl_elem_value_t *contro
int type, ret;
unsigned int access, count;
key = ext->callback->find_elem(ext, &control->id);
key = get_elem(ext, &control->id);
if (key == SND_CTL_EXT_KEY_NOT_FOUND)
return -ENOENT;
ret = ext->callback->get_attribute(ext, key, &type, &access, &count);
@ -254,7 +266,7 @@ static int snd_ctl_ext_elem_write(snd_ctl_t *handle, snd_ctl_elem_value_t *contr
int type, ret;
unsigned int access, count;
key = ext->callback->find_elem(ext, &control->id);
key = get_elem(ext, &control->id);
if (key == SND_CTL_EXT_KEY_NOT_FOUND)
return -ENOENT;
ret = ext->callback->get_attribute(ext, key, &type, &access, &count);