summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Hillenbrand <codeworkx@cyanogenmod.org>2013-05-25 15:56:24 -0700
committerGerrit Code Review <gerrit@cyanogenmod.org>2013-05-25 15:56:24 -0700
commit316262907d9cdd18363506163731fa15ccf4cae8 (patch)
tree8829139c1a43d0ee1875d86f2220116c05b4ec84
parent770ea9ca3dae18373ff45b8dd2f7849450e78b2f (diff)
parent3f21abe3096e0182f47fd7e8348a93005f44e010 (diff)
downloaddevice_samsung_galaxys2-common-316262907d9cdd18363506163731fa15ccf4cae8.zip
device_samsung_galaxys2-common-316262907d9cdd18363506163731fa15ccf4cae8.tar.gz
device_samsung_galaxys2-common-316262907d9cdd18363506163731fa15ccf4cae8.tar.bz2
Merge "Mixer: Handle write element" into cm-10.1
-rw-r--r--tinyalsa_audio/mixer.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/tinyalsa_audio/mixer.c b/tinyalsa_audio/mixer.c
index 0d4950d..e8742c6 100644
--- a/tinyalsa_audio/mixer.c
+++ b/tinyalsa_audio/mixer.c
@@ -20,6 +20,7 @@
#define LOG_TAG "TinyALSA-Audio Mixer"
+#include <fcntl.h>
#include <errno.h>
#include <pthread.h>
#include <stdint.h>
@@ -509,6 +510,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);
+ }
}
}
@@ -704,6 +742,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;
@@ -726,6 +794,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)