aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Wilson <simonwilson@google.com>2012-10-23 15:05:23 -0700
committerSimon Wilson <simonwilson@google.com>2013-05-07 10:15:20 -0700
commit38f87f3be4f397d796a558555ee3218e18cd793b (patch)
tree34050c4015adf9cf2335ba931f4d96ad6b84f958
parent50895678c5006e5538ec465f03ed0d6048d70074 (diff)
mixer: add get/set_array API
This replaces (and extends) the existing get/set_bytes API, which is no longer required.
-rw-r--r--include/tinyalsa/asoundlib.h4
-rw-r--r--mixer.c50
2 files changed, 44 insertions, 10 deletions
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h
index a4ebec8..ddd7a01 100644
--- a/include/tinyalsa/asoundlib.h
+++ b/include/tinyalsa/asoundlib.h
@@ -220,9 +220,9 @@ int mixer_ctl_get_percent(struct mixer_ctl *ctl, unsigned int id);
int mixer_ctl_set_percent(struct mixer_ctl *ctl, unsigned int id, int percent);
int mixer_ctl_get_value(struct mixer_ctl *ctl, unsigned int id);
-int mixer_ctl_get_bytes(struct mixer_ctl *ctl, void *data, size_t len);
+int mixer_ctl_get_array(struct mixer_ctl *ctl, void *array, size_t count);
int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value);
-int mixer_ctl_set_bytes(struct mixer_ctl *ctl, const void *data, size_t len);
+int mixer_ctl_set_array(struct mixer_ctl *ctl, const void *array, size_t count);
int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string);
/* Determe range of integer mixer controls */
diff --git a/mixer.c b/mixer.c
index f52bca9..7419d3f 100644
--- a/mixer.c
+++ b/mixer.c
@@ -317,13 +317,14 @@ int mixer_ctl_get_value(struct mixer_ctl *ctl, unsigned int id)
return 0;
}
-int mixer_ctl_get_bytes(struct mixer_ctl *ctl, void *data, size_t len)
+int mixer_ctl_get_array(struct mixer_ctl *ctl, void *array, size_t count)
{
struct snd_ctl_elem_value ev;
int ret;
+ size_t size;
+ void *source;
- if (!ctl || (len > ctl->info->count) || !len || !data ||
- (ctl->info->type != SNDRV_CTL_ELEM_TYPE_BYTES))
+ if (!ctl || (count > ctl->info->count) || !count || !array)
return -EINVAL;
memset(&ev, 0, sizeof(ev));
@@ -333,7 +334,23 @@ int mixer_ctl_get_bytes(struct mixer_ctl *ctl, void *data, size_t len)
if (ret < 0)
return ret;
- memcpy(data, ev.value.bytes.data, len);
+ switch (ctl->info->type) {
+ case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
+ case SNDRV_CTL_ELEM_TYPE_INTEGER:
+ size = sizeof(ev.value.integer.value[0]);
+ source = ev.value.integer.value;
+ break;
+
+ case SNDRV_CTL_ELEM_TYPE_BYTES:
+ size = sizeof(ev.value.bytes.data[0]);
+ source = ev.value.bytes.data;
+ break;
+
+ default:
+ return -EINVAL;
+ }
+
+ memcpy(array, source, size * count);
return 0;
}
@@ -372,18 +389,35 @@ int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value)
return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev);
}
-int mixer_ctl_set_bytes(struct mixer_ctl *ctl, const void *data, size_t len)
+int mixer_ctl_set_array(struct mixer_ctl *ctl, const void *array, size_t count)
{
struct snd_ctl_elem_value ev;
+ size_t size;
+ void *dest;
- if (!ctl || (len > ctl->info->count) || !len || !data ||
- (ctl->info->type != SNDRV_CTL_ELEM_TYPE_BYTES))
+ if (!ctl || (count > ctl->info->count) || !count || !array)
return -EINVAL;
memset(&ev, 0, sizeof(ev));
ev.id.numid = ctl->info->id.numid;
- memcpy(ev.value.bytes.data, data, len);
+ switch (ctl->info->type) {
+ case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
+ case SNDRV_CTL_ELEM_TYPE_INTEGER:
+ size = sizeof(ev.value.integer.value[0]);
+ dest = ev.value.integer.value;
+ break;
+
+ case SNDRV_CTL_ELEM_TYPE_BYTES:
+ size = sizeof(ev.value.bytes.data[0]);
+ dest = ev.value.bytes.data;
+ break;
+
+ default:
+ return -EINVAL;
+ }
+
+ memcpy(dest, array, size * count);
return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev);
}