Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 69e8b576 authored by Ethan Chen's avatar Ethan Chen
Browse files

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
parent 3190dc6a
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -941,3 +941,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;
}
+16 −1
Original line number Diff line number Diff line
@@ -172,7 +172,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",
@@ -2050,3 +2050,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 −0
Original line number Diff line number Diff line
@@ -63,6 +63,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);
+47 −2
Original line number Diff line number Diff line
@@ -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;
 * ...
 * ...
 * </pcm_ids>
 * <device_names>
 * <device name="???" alias="???"/>
 * ...
 * ...
 * </device_names>
 * </audio_platform_info>
 */

@@ -203,6 +211,38 @@ done:
    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;
    }
}

+6 −0
Original line number Diff line number Diff line
@@ -1334,3 +1334,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;
}