]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Change numid properly with external ctl plugins
authorTakashi Iwai <tiwai@suse.de>
Tue, 17 Feb 2009 15:58:12 +0000 (16:58 +0100)
committerTakashi Iwai <tiwai@suse.de>
Tue, 17 Feb 2009 15:58:12 +0000 (16:58 +0100)
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>
src/control/control_ext.c

index a8675c13dc9db52608b1ff4e642cc8a8eb4c0fdc..d1fe8eaadec55671d9fcdfcc456d9d13e97a0d84 100644 (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);