summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2013-05-18 20:42:01 +0200
committerPaul Kocialkowski <contact@paulk.fr>2013-05-18 20:42:01 +0200
commit5c05a42d8a008439285fec9b3b082ed30006f951 (patch)
tree046bd91bfb67d2da3ac54edc002f8358a46bfd35
parent3660b5ae8d6bcd134072aae742b5682f40a96573 (diff)
downloadhardware_tinyalsa-audio-5c05a42d8a008439285fec9b3b082ed30006f951.zip
hardware_tinyalsa-audio-5c05a42d8a008439285fec9b3b082ed30006f951.tar.gz
hardware_tinyalsa-audio-5c05a42d8a008439285fec9b3b082ed30006f951.tar.bz2
Mixer: Handle write element
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rw-r--r--mixer.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/mixer.c b/mixer.c
index d0685e8..9608083 100644
--- a/mixer.c
+++ b/mixer.c
@@ -20,6 +20,7 @@
#define LOG_TAG "TinyALSA-Audio Mixer"
+#include <fcntl.h>
#include <errno.h>
#include <pthread.h>
#include <stdint.h>
@@ -501,6 +502,43 @@ void tinyalsa_mixer_config_start(void *data, const XML_Char *elem,
tinyalsa_mixer_data_free(mixer_data);
list_head_free(list);
}
+ } else if(strcmp(elem, "write") == 0) {
+ if(config_data->device != NULL && config_data->list_start != NULL) {
+ list = list_head_alloc();
+ mixer_data = tinyalsa_mixer_data_alloc();
+
+ mixer_data->type = MIXER_DATA_TYPE_WRITE;
+ list->data = (void *) mixer_data;
+ } else {
+ LOGE("Missing device/path for elem: %s", elem);
+ return;
+ }
+
+ for(i=0 ; attr[i] != NULL && attr[i+1] != NULL ; i++) {
+ if(strcmp(attr[i], "name") == 0) {
+ i++;
+ mixer_data->name = strdup((char *) attr[i]);
+ } else if(strcmp(attr[i], "value") == 0) {
+ i++;
+ mixer_data->value = strdup((char *) attr[i]);
+ } else {
+ LOGE("Unknown write attr: %s", attr[i]);
+ }
+ }
+
+ if(mixer_data->name != NULL && mixer_data->value != NULL) {
+ if(*config_data->list_start == NULL) {
+ *config_data->list_start = list;
+ } else {
+ config_data->list->next = list;
+ list->prev = config_data->list;
+ }
+
+ config_data->list = list;
+ } else {
+ tinyalsa_mixer_data_free(mixer_data);
+ list_head_free(list);
+ }
}
}
@@ -696,6 +734,36 @@ int tinyalsa_mixer_set_route_ctrl(struct tinyalsa_mixer *mixer,
return 0;
}
+int tinyalsa_mixer_set_route_write(struct tinyalsa_mixer *mixer,
+ struct tinyalsa_mixer_data *mixer_data)
+{
+ char *buffer = NULL;
+ int fd;
+
+ if(mixer_data->type != MIXER_DATA_TYPE_WRITE)
+ return -1;
+
+ LOGD("Writing %s to %s", mixer_data->value, mixer_data->name);
+
+ asprintf(&buffer, "%s\n", mixer_data->value);
+ if(buffer == NULL)
+ return -1;
+
+ fd = open(mixer_data->name, O_WRONLY);
+ if(fd < 0) {
+ free(buffer);
+ return -1;
+ }
+
+ write(fd, buffer, strlen(buffer) + 1);
+
+ free(buffer);
+
+ close(fd);
+
+ return 0;
+}
+
int tinyalsa_mixer_set_route_list(struct tinyalsa_mixer *mixer, struct list_head *list)
{
struct tinyalsa_mixer_data *mixer_data = NULL;
@@ -718,6 +786,12 @@ int tinyalsa_mixer_set_route_list(struct tinyalsa_mixer *mixer, struct list_head
return -1;
}
}
+ } else if(mixer_data->type == MIXER_DATA_TYPE_WRITE) {
+ rc = tinyalsa_mixer_set_route_write(mixer, mixer_data);
+ if(rc < 0) {
+ LOGE("Unable to write!");
+ return -1;
+ }
}
if(list->next != NULL)