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

Commit 0fe80caa authored by Ethan Chen's avatar Ethan Chen Committed by Rashed Abdel-Tawab
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: I891704995a77d7a0a3ebea12dca883ee57eba501
parent 2eabaccd
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -1145,3 +1145,9 @@ int platform_set_device_params(struct stream_out *out __unused,
{
{
    return 0;
    return 0;
}
}

int platform_set_snd_device_name(snd_device_t snd_device __unused,
                                 const char * name __unused)
{
    return -ENOSYS;
}
+16 −1
Original line number Original line Diff line number Diff line
@@ -270,7 +270,7 @@ static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
};
};


/* Array to store sound devices */
/* 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",
    [SND_DEVICE_NONE] = "none",
    /* Playback sound devices */
    /* Playback sound devices */
    [SND_DEVICE_OUT_HANDSET] = "handset",
    [SND_DEVICE_OUT_HANDSET] = "handset",
@@ -3695,3 +3695,18 @@ int platform_set_device_params(struct stream_out *out, int param, int value)
end:
end:
    return ret;
    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 Original line Diff line number Diff line
@@ -82,6 +82,7 @@ bool platform_sound_trigger_device_needs_event(snd_device_t snd_device);
bool platform_sound_trigger_usecase_needs_event(audio_usecase_t uc_id);
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);
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 */
/* From platform_info_parser.c */
int platform_info_init(const char *filename);
int platform_info_init(const char *filename);
+47 −2
Original line number Original line Diff line number Diff line
@@ -46,6 +46,7 @@ typedef enum {
    BITWIDTH,
    BITWIDTH,
    PCM_ID,
    PCM_ID,
    BACKEND_NAME,
    BACKEND_NAME,
    DEVICE_NAME,
} section_t;
} section_t;


typedef void (* section_process_fn)(const XML_Char **attr);
typedef void (* section_process_fn)(const XML_Char **attr);
@@ -54,6 +55,7 @@ static void process_acdb_id(const XML_Char **attr);
static void process_bit_width(const XML_Char **attr);
static void process_bit_width(const XML_Char **attr);
static void process_pcm_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_backend_name(const XML_Char **attr);
static void process_device_name(const XML_Char **attr);
static void process_root(const XML_Char **attr);
static void process_root(const XML_Char **attr);


static section_process_fn section_table[] = {
static section_process_fn section_table[] = {
@@ -62,6 +64,7 @@ static section_process_fn section_table[] = {
    [BITWIDTH] = process_bit_width,
    [BITWIDTH] = process_bit_width,
    [PCM_ID] = process_pcm_id,
    [PCM_ID] = process_pcm_id,
    [BACKEND_NAME] = process_backend_name,
    [BACKEND_NAME] = process_backend_name,
    [DEVICE_NAME] = process_device_name,
};
};


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


@@ -237,6 +245,38 @@ done:
    return;
    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 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,
static void start_tag(void *userdata __unused, const XML_Char *tag_name,
                      const XML_Char **attr)
                      const XML_Char **attr)
{
{
@@ -252,9 +292,12 @@ static void start_tag(void *userdata __unused, const XML_Char *tag_name,
        section = PCM_ID;
        section = PCM_ID;
    } else if (strcmp(tag_name, "backend_names") == 0) {
    } else if (strcmp(tag_name, "backend_names") == 0) {
        section = BACKEND_NAME;
        section = BACKEND_NAME;
    } else if (strcmp(tag_name, "device_names") == 0) {
        section = DEVICE_NAME;
    } else if (strcmp(tag_name, "device") == 0) {
    } else if (strcmp(tag_name, "device") == 0) {
        if ((section != ACDB) && (section != BACKEND_NAME) && (section != BITWIDTH)) {
        if ((section != ACDB) && (section != BACKEND_NAME)
            ALOGE("device tag only supported for acdb/backend names");
                 && (section != BITWIDTH) && (section != DEVICE_NAME)) {
            ALOGE("device tag only supported for acdb/backend/device names");
            return;
            return;
        }
        }


@@ -284,6 +327,8 @@ static void end_tag(void *userdata __unused, const XML_Char *tag_name)
        section = ROOT;
        section = ROOT;
    } else if (strcmp(tag_name, "backend_names") == 0) {
    } else if (strcmp(tag_name, "backend_names") == 0) {
        section = ROOT;
        section = ROOT;
    } else if (strcmp(tag_name, "device_names") == 0) {
        section = ROOT;
    }
    }
}
}