diff options
author | Takashi Iwai <tiwai@suse.de> | 2012-01-25 18:31:50 +0100 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2012-01-25 18:31:50 +0100 |
commit | abfb6e73b9360442b58d262148204fe9f437abd3 (patch) | |
tree | 1d4a15afc22bfb17fb43d3c3585b16d6bd318ab4 | |
parent | eb06ee5f29ad5fd7f032dff92702a2d0e12d2973 (diff) | |
download | salsa-lib-abfb6e73b9360442b58d262148204fe9f437abd3.tar.gz |
Add the support of snd_ctl_elem_add_enumerated()
-rw-r--r-- | src/asound.h | 4 | ||||
-rw-r--r-- | src/control.c | 36 | ||||
-rw-r--r-- | src/ctl_func.h | 3 |
3 files changed, 42 insertions, 1 deletions
diff --git a/src/asound.h b/src/asound.h index 6ddf860..aa691ec 100644 --- a/src/asound.h +++ b/src/asound.h @@ -656,7 +656,7 @@ typedef struct _snd_timer_tread { /* control interface */ -#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 6) +#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 7) typedef struct snd_ctl_card_info { int card; @@ -749,6 +749,8 @@ typedef struct snd_ctl_elem_info { unsigned int items; unsigned int item; char name[64]; + unsigned long long names_ptr; + unsigned int names_length; } enumerated; unsigned char reserved[128]; } value; diff --git a/src/control.c b/src/control.c index 0bddd8a..c373876 100644 --- a/src/control.c +++ b/src/control.c @@ -189,6 +189,42 @@ int snd_ctl_elem_add_iec958(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id) return snd_ctl_elem_add(ctl, &info); } +int snd_ctl_elem_add_enumerated(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, + unsigned int count, unsigned int items, + const char *const names[]) +{ + snd_ctl_elem_info_t info; + unsigned int i, len; + char *buf, *p; + int err; + + if (ctl->protocol < SNDRV_PROTOCOL_VERSION(2, 0, 7)) + return -ENXIO; + if (!items) + return -EINVAL; + + len = 0; + for (i = 0; i < items; ++i) + len += strlen(names[i]) + 1; + buf = malloc(len); + if (!buf) + return -ENOMEM; + p = buf; + for (i = 0; i < items; ++i) + p = stpcpy(p, names[i]) + 1; + + memzero_valgrind(&info, sizeof(info)); + info.id = *id; + info.type = SND_CTL_ELEM_TYPE_ENUMERATED; + info.count = count; + info.value.enumerated.items = items; + info.value.enumerated.names_ptr = (uintptr_t)buf; + info.value.enumerated.names_length = len; + + err = snd_ctl_elem_add(ctl, &info); + free(buf); + return err; +} #if SALSA_HAS_TLV_SUPPORT /* diff --git a/src/ctl_func.h b/src/ctl_func.h index 32de1c6..9cbe131 100644 --- a/src/ctl_func.h +++ b/src/ctl_func.h @@ -59,6 +59,9 @@ int snd_ctl_elem_add_integer64(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, int snd_ctl_elem_add_boolean(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count); int snd_ctl_elem_add_iec958(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id); +int snd_ctl_elem_add_enumerated(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, + unsigned int count, unsigned int items, + const char *const names[]); #if SALSA_HAS_TLV_SUPPORT int snd_tlv_parse_dB_info(unsigned int *tlv, |