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
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 8cef7b7..9e9bc61 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -413,7 +413,7 @@
};
/* Array to store sound devices */
-static const char * const device_table[SND_DEVICE_MAX] = {
+static const char * device_table[SND_DEVICE_MAX] = {
[SND_DEVICE_NONE] = "none",
/* Playback sound devices */
[SND_DEVICE_OUT_HANDSET] = "handset",
@@ -7860,6 +7860,21 @@
return snd_device;
}
+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;
+}
+
int platform_set_sidetone(struct audio_device *adev,
snd_device_t out_snd_device,
bool enable,
diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c
index a8c4630..c76b9ed 100644
--- a/hal/msm8960/platform.c
+++ b/hal/msm8960/platform.c
@@ -1252,6 +1252,12 @@
ALOGE("%s: Not implemented", __func__);
}
+int platform_set_snd_device_name(snd_device_t snd_device __unused,
+ const char * name __unused)
+{
+ return -ENOSYS;
+}
+
bool platform_can_enable_spkr_prot_on_device(snd_device_t snd_device __unused)
{
/* speaker protection not implemented for this platform*/
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index a0d19e3..fe40a16 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -406,7 +406,7 @@
};
/* Array to store sound devices */
-static const char * const device_table[SND_DEVICE_MAX] = {
+static const char * device_table[SND_DEVICE_MAX] = {
[SND_DEVICE_NONE] = "none",
/* Playback sound devices */
[SND_DEVICE_OUT_HANDSET] = "handset",
@@ -7966,6 +7966,21 @@
return snd_device;
}
+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;
+}
+
int platform_set_sidetone(struct audio_device *adev,
snd_device_t out_snd_device,
bool enable,
diff --git a/hal/platform_api.h b/hal/platform_api.h
index e54c496..7eb0a63 100644
--- a/hal/platform_api.h
+++ b/hal/platform_api.h
@@ -198,6 +198,7 @@
const char * hw_interface);
int platform_get_snd_device_backend_index(snd_device_t device);
const char * platform_get_snd_device_backend_interface(snd_device_t device);
+int platform_set_snd_device_name(snd_device_t snd_device, const char * name);
/* From platform_info.c */
int platform_info_init(const char *filename, void *, caller_t);
diff --git a/hal/platform_info.c b/hal/platform_info.c
index 956da09..b3dc273 100644
--- a/hal/platform_info.c
+++ b/hal/platform_info.c
@@ -70,6 +70,7 @@
MIC_INFO,
CUSTOM_MTMX_PARAMS,
CUSTOM_MTMX_PARAM_COEFFS,
+ DEVICE_NAME,
} section_t;
typedef void (* section_process_fn)(const XML_Char **attr);
@@ -91,6 +92,7 @@
static void process_mic_info(const XML_Char **attr);
static void process_custom_mtmx_params(const XML_Char **attr);
static void process_custom_mtmx_param_coeffs(const XML_Char **attr);
+static void process_device_name(const XML_Char **attr);
static section_process_fn section_table[] = {
[ROOT] = process_root,
@@ -109,6 +111,7 @@
[MIC_INFO] = process_mic_info,
[CUSTOM_MTMX_PARAMS] = process_custom_mtmx_params,
[CUSTOM_MTMX_PARAM_COEFFS] = process_custom_mtmx_param_coeffs,
+ [DEVICE_NAME] = process_device_name,
};
static section_t section;
@@ -248,6 +251,11 @@
* ...
* ...
* </config_params>
+ * <device_names>
+ * <device name="???" alias="???"/>
+ * ...
+ * ...
+ * </device_names>
* </audio_platform_info>
*/
@@ -955,7 +963,38 @@
}
mtmx_params_info.snd_device = platform_get_snd_device_index((char *)attr[attr_idx++]);
platform_add_custom_mtmx_params((void *)my_data.platform, &mtmx_params_info);
+}
+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 platform info xml not found, no alias set!",
+ __func__, attr[1]);
+ goto done;
+ }
+
+ if (strcmp(attr[2], "alias") != 0) {
+ ALOGE("%s: Device %s in platform info xml has no alias, no alias set!",
+ __func__, attr[1]);
+ 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,
@@ -996,11 +1035,13 @@
section = MICROPHONE_CHARACTERISTIC;
} else if (strcmp(tag_name, "snd_devices") == 0) {
section = SND_DEVICES;
+ } else if (strcmp(tag_name, "device_names") == 0) {
+ section = DEVICE_NAME;
} else if (strcmp(tag_name, "device") == 0) {
if ((section != ACDB) && (section != AEC) && (section != NS) &&
(section != BACKEND_NAME) && (section != BITWIDTH) &&
- (section != INTERFACE_NAME)) {
- ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
+ (section != INTERFACE_NAME) && (section != DEVICE_NAME)) {
+ ALOGE("device tag only supported for acdb/backend names/bitwidth/interface/device names");
return;
}
@@ -1142,6 +1183,8 @@
section = ROOT;
} else if (strcmp(tag_name, "custom_mtmx_param_coeffs") == 0) {
section = CUSTOM_MTMX_PARAMS;
+ } else if (strcmp(tag_name, "device_names") == 0) {
+ section = ROOT;
}
}