hal: update platform info parser to read key value pairs

Add support to parse platform specific configuration as
key value pairs from audio_platform_info.xml file.

Change-Id: Id1199f6f5cb3a060476f713a69b5de05f48815ce
This commit is contained in:
Ravi Kumar Alamanda 2015-06-28 21:04:09 -07:00 committed by Vidyakumar Athota
parent 7285d6ff83
commit 14b0f2d79b
4 changed files with 60 additions and 10 deletions

View File

@ -1434,8 +1434,7 @@ void *platform_init(struct audio_device *adev)
dir = opendir(CodecPeek);
if (dir != NULL) {
while (NULL != (dirent = readdir(dir))) {
if (strstr (dirent->d_name,file_name))
{
if (strstr (dirent->d_name,file_name)) {
my_data->is_wsa_speaker = true;
break;
}
@ -1449,9 +1448,9 @@ acdb_init_fail:
/* Initialize ACDB and PCM ID's */
if (is_external_codec)
platform_info_init(PLATFORM_INFO_XML_PATH_EXTCODEC);
platform_info_init(PLATFORM_INFO_XML_PATH_EXTCODEC, my_data);
else
platform_info_init(PLATFORM_INFO_XML_PATH);
platform_info_init(PLATFORM_INFO_XML_PATH, my_data);
/* init usb */
audio_extn_usb_init(adev);

View File

@ -1393,9 +1393,9 @@ acdb_init_fail:
/* Initialize ACDB ID's */
if (my_data->is_i2s_ext_modem)
platform_info_init(PLATFORM_INFO_XML_PATH_I2S);
platform_info_init(PLATFORM_INFO_XML_PATH_I2S, my_data);
else
platform_info_init(PLATFORM_INFO_XML_PATH);
platform_info_init(PLATFORM_INFO_XML_PATH, my_data);
/* If platform is apq8084 and baseband is MDM, load CSD Client specific
* symbols. Voice call is handled by MDM and apps processor talks to

View File

@ -87,8 +87,8 @@ bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id);
int platform_set_snd_device_backend(snd_device_t snd_device, const char * backend);
/* From platform_info_parser.c */
int platform_info_init(const char *filename);
/* From platform_info.c */
int platform_info_init(const char *filename, void *);
void platform_snd_card_update(void *platform, int snd_scard_state);

View File

@ -34,6 +34,7 @@
#include <stdio.h>
#include <expat.h>
#include <cutils/log.h>
#include <cutils/str_parms.h>
#include <audio_hw.h>
#include "platform_api.h"
#include <platform.h>
@ -49,6 +50,7 @@ typedef enum {
BACKEND_NAME,
INTERFACE_NAME,
TZ_NAME,
CONFIG_PARAMS,
} section_t;
typedef void (* section_process_fn)(const XML_Char **attr);
@ -60,6 +62,7 @@ static void process_pcm_id(const XML_Char **attr);
static void process_backend_name(const XML_Char **attr);
static void process_interface_name(const XML_Char **attr);
static void process_tz_name(const XML_Char **attr);
static void process_config_params(const XML_Char **attr);
static void process_root(const XML_Char **attr);
static section_process_fn section_table[] = {
@ -71,10 +74,18 @@ static section_process_fn section_table[] = {
[BACKEND_NAME] = process_backend_name,
[INTERFACE_NAME] = process_interface_name,
[TZ_NAME] = process_tz_name,
[CONFIG_PARAMS] = process_config_params,
};
static section_t section;
struct platform_info {
void *platform;
struct str_parms *kvpairs;
};
static struct platform_info my_data;
/*
* <audio_platform_info>
* <acdb_ids>
@ -102,6 +113,12 @@ static section_t section;
* ...
* ...
* </tz_names>
* <config_params>
* <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
* ...
* ...
* </config_params>
*
* </audio_platform_info>
*/
@ -115,7 +132,7 @@ static void process_pcm_id(const XML_Char **attr)
int index;
if (strcmp(attr[0], "name") != 0) {
ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
goto done;
}
@ -352,6 +369,24 @@ done:
return;
}
static void process_config_params(const XML_Char **attr)
{
if (strcmp(attr[0], "key") != 0) {
ALOGE("%s: 'key' not found", __func__);
goto done;
}
if (strcmp(attr[2], "value") != 0) {
ALOGE("%s: 'value' not found", __func__);
goto done;
}
str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
done:
return;
}
static void start_tag(void *userdata __unused, const XML_Char *tag_name,
const XML_Char **attr)
{
@ -367,6 +402,8 @@ 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, "config_params") == 0) {
section = CONFIG_PARAMS;
} else if (strcmp(tag_name, "interface_names") == 0) {
section = INTERFACE_NAME;
} else if (strcmp(tag_name, "native_configs") == 0) {
@ -399,6 +436,14 @@ static void start_tag(void *userdata __unused, const XML_Char *tag_name,
section_process_fn fn = section_table[NATIVESUPPORT];
fn(attr);
} else if (strcmp(tag_name, "param") == 0) {
if (section != CONFIG_PARAMS) {
ALOGE("param tag only supported with CONFIG_PARAMS section");
return;
}
section_process_fn fn = section_table[section];
fn(attr);
}
return;
@ -414,6 +459,9 @@ 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, "config_params") == 0) {
section = ROOT;
platform_set_parameters(my_data.platform, my_data.kvpairs);
} else if (strcmp(tag_name, "interface_names") == 0) {
section = ROOT;
} else if (strcmp(tag_name, "native_configs") == 0) {
@ -421,7 +469,7 @@ static void end_tag(void *userdata __unused, const XML_Char *tag_name)
}
}
int platform_info_init(const char *filename)
int platform_info_init(const char *filename, void *platform)
{
XML_Parser parser;
FILE *file;
@ -446,6 +494,9 @@ int platform_info_init(const char *filename)
goto err_close_file;
}
my_data.platform = platform;
my_data.kvpairs = str_parms_create();
XML_SetElementHandler(parser, start_tag, end_tag);
while (1) {