Skip to content

Commit

Permalink
audio: Extend platform parser to allow device name aliasing
Browse files Browse the repository at this point in the history
* Supported sections now include device names
* This allows for aliasing device names to a custom name

Change-Id: I880e90a7e887f020517d89ba276199c700c0eeae
  • Loading branch information
intervigilium committed Sep 5, 2014
1 parent 83d5015 commit f9e14e8
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 3 deletions.
6 changes: 6 additions & 0 deletions hal/msm8960/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
17 changes: 16 additions & 1 deletion hal/msm8974/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions hal/platform_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
49 changes: 47 additions & 2 deletions hal/platform_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,23 @@ typedef enum {
ACDB,
PCM_ID,
BACKEND_NAME,
DEVICE_NAME,
} section_t;

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[] = {
[ROOT] = process_root,
[ACDB] = process_acdb_id,
[PCM_ID] = process_pcm_id,
[BACKEND_NAME] = process_backend_name,
[DEVICE_NAME] = process_device_name,
};

static section_t section;
Expand All @@ -81,6 +84,11 @@ static section_t section;
* ...
* ...
* </pcm_ids>
* <device_names>
* <device name="???" alias="???"/>
* ...
* ...
* </device_names>
* </audio_platform_info>
*/

Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
}

Expand Down
6 changes: 6 additions & 0 deletions hal_mpq/mpq8092/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit f9e14e8

Please sign in to comment.