From f9e14e80b2c457f46b504bb0e66c38dde48c894f Mon Sep 17 00:00:00 2001 From: Ethan Chen Date: Fri, 5 Sep 2014 13:01:26 -0700 Subject: [PATCH] audio: Extend platform parser to allow device name aliasing * Supported sections now include device names * This allows for aliasing device names to a custom name Change-Id: I880e90a7e887f020517d89ba276199c700c0eeae --- hal/msm8960/platform.c | 6 +++++ hal/msm8974/platform.c | 17 ++++++++++++- hal/platform_api.h | 1 + hal/platform_info.c | 49 ++++++++++++++++++++++++++++++++++++-- hal_mpq/mpq8092/platform.c | 6 +++++ 5 files changed, 76 insertions(+), 3 deletions(-) diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c index 12f4f2c..688d07a 100644 --- a/hal/msm8960/platform.c +++ b/hal/msm8960/platform.c @@ -1031,3 +1031,9 @@ int platform_set_snd_device_backend(snd_device_t snd_device __unused, { return -ENOSYS; } + +int platform_set_snd_device_name(snd_device_t snd_device __unused, + const char * name __unused) +{ + return -ENOSYS; +} diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c index 4cc0749..e4dd19f 100644 --- a/hal/msm8974/platform.c +++ b/hal/msm8974/platform.c @@ -188,7 +188,7 @@ static int pcm_device_table[AUDIO_USECASE_MAX][2] = { }; /* Array to store sound devices */ -static const char * const device_table[SND_DEVICE_MAX] = { +static char * device_table[SND_DEVICE_MAX] = { [SND_DEVICE_NONE] = "none", /* Playback sound devices */ [SND_DEVICE_OUT_HANDSET] = "handset", @@ -2213,3 +2213,18 @@ int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t p done: return ret; } + +int platform_set_snd_device_name(snd_device_t device, const char *name) +{ + int ret = 0; + + if ((device < SND_DEVICE_MIN) || (device >= SND_DEVICE_MAX)) { + ALOGE("%s:: Invalid snd_device = %d", __func__, device); + ret = -EINVAL; + goto done; + } + + device_table[device] = strdup(name); +done: + return ret; +} diff --git a/hal/platform_api.h b/hal/platform_api.h index 2c0534b..21e41cc 100644 --- a/hal/platform_api.h +++ b/hal/platform_api.h @@ -66,6 +66,7 @@ int platform_update_usecase_from_source(int source, audio_usecase_t usecase); bool platform_listen_update_status(snd_device_t snd_device); int platform_set_snd_device_backend(snd_device_t snd_device, const char * backend); +int platform_set_snd_device_name(snd_device_t snd_device, const char * name); /* From platform_info_parser.c */ int platform_info_init(void); diff --git a/hal/platform_info.c b/hal/platform_info.c index 787f45a..2a425e1 100644 --- a/hal/platform_info.c +++ b/hal/platform_info.c @@ -46,6 +46,7 @@ typedef enum { ACDB, PCM_ID, BACKEND_NAME, + DEVICE_NAME, } section_t; typedef void (* section_process_fn)(const XML_Char **attr); @@ -53,6 +54,7 @@ typedef void (* section_process_fn)(const XML_Char **attr); static void process_acdb_id(const XML_Char **attr); static void process_pcm_id(const XML_Char **attr); static void process_backend_name(const XML_Char **attr); +static void process_device_name(const XML_Char **attr); static void process_root(const XML_Char **attr); static section_process_fn section_table[] = { @@ -60,6 +62,7 @@ static section_process_fn section_table[] = { [ACDB] = process_acdb_id, [PCM_ID] = process_pcm_id, [BACKEND_NAME] = process_backend_name, + [DEVICE_NAME] = process_device_name, }; static section_t section; @@ -81,6 +84,11 @@ static section_t section; * ... * ... * + * + * + * ... + * ... + * * */ @@ -203,6 +211,38 @@ static void process_acdb_id(const XML_Char **attr) return; } +static void process_device_name(const XML_Char **attr) +{ + int index; + + if (strcmp(attr[0], "name") != 0) { + ALOGE("%s: 'name' not found, no alias set!", __func__); + goto done; + } + + index = platform_get_snd_device_index((char *)attr[1]); + if (index < 0) { + ALOGE("%s: Device %s in %s not found, no alias set!", + __func__, attr[1], PLATFORM_INFO_XML_PATH); + goto done; + } + + if (strcmp(attr[2], "alias") != 0) { + ALOGE("%s: Device %s in %s has no alias, no alias set!", + __func__, attr[1], PLATFORM_INFO_XML_PATH); + goto done; + } + + if (platform_set_snd_device_name(index, attr[3]) < 0) { + ALOGE("%s: Device %s, alias %s was not set!", + __func__, attr[1], attr[3]); + goto done; + } + +done: + return; +} + static void start_tag(void *userdata __unused, const XML_Char *tag_name, const XML_Char **attr) { @@ -216,9 +256,12 @@ static void start_tag(void *userdata __unused, const XML_Char *tag_name, section = PCM_ID; } else if (strcmp(tag_name, "backend_names") == 0) { section = BACKEND_NAME; + } else if (strcmp(tag_name, "device_names") == 0) { + section = DEVICE_NAME; } else if (strcmp(tag_name, "device") == 0) { - if ((section != ACDB) && (section != BACKEND_NAME)) { - ALOGE("device tag only supported for acdb/backend names"); + if ((section != ACDB) && (section != BACKEND_NAME) + && (section != DEVICE_NAME)) { + ALOGE("device tag only supported for acdb/backend/device names"); return; } @@ -246,6 +289,8 @@ static void end_tag(void *userdata __unused, const XML_Char *tag_name) section = ROOT; } else if (strcmp(tag_name, "backend_names") == 0) { section = ROOT; + } else if (strcmp(tag_name, "device_names") == 0) { + section = ROOT; } } diff --git a/hal_mpq/mpq8092/platform.c b/hal_mpq/mpq8092/platform.c index f329f16..7cd9cf4 100644 --- a/hal_mpq/mpq8092/platform.c +++ b/hal_mpq/mpq8092/platform.c @@ -1349,3 +1349,9 @@ int platform_set_snd_device_backend(snd_device_t snd_device __unused, return -ENOSYS; } +int platform_set_snd_device_name(snd_device_t snd_device __unused, + const char * name __unused) +{ + return -ENOSYS; +} +