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

Unverified Commit 13d4b369 authored by Ethan Chen's avatar Ethan Chen Committed by Michael Bestas
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 0d9e7bd1
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -421,7 +421,7 @@ int pcm_device_table[AUDIO_USECASE_MAX][2] = {
};

/* 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",
@@ -8118,6 +8118,21 @@ int platform_get_ec_ref_loopback_snd_device(int channel_count)
    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,
+6 −0
Original line number Diff line number Diff line
@@ -1281,6 +1281,12 @@ void platform_set_gsm_mode(void *platform __unused, bool enable __unused)
    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*/
+16 −1
Original line number Diff line number Diff line
@@ -522,7 +522,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 const char * device_table[SND_DEVICE_MAX] = {
    [SND_DEVICE_NONE] = "none",
    /* Playback sound devices */
    [SND_DEVICE_OUT_HANDSET] = "handset",
@@ -11760,6 +11760,21 @@ 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;
}
int platform_set_sidetone(struct audio_device *adev,
                          snd_device_t out_snd_device,
                          bool enable,
+1 −0
Original line number Diff line number Diff line
@@ -304,6 +304,7 @@ int platform_set_hdmi_config(void *platform, uint32_t channel_count,
int platform_set_device_params(struct stream_out *out, int param, int value);
int platform_set_audio_device_interface(const char * device_name, const char *intf_name,
                                        const char * codec_type);
int platform_set_snd_device_name(snd_device_t snd_device, const char * name);
void platform_set_gsm_mode(void *platform, bool enable);
bool platform_can_enable_spkr_prot_on_device(snd_device_t snd_device);
int platform_get_spkr_prot_acdb_id(snd_device_t snd_device);
+45 −2
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ typedef enum {
    CUSTOM_MTMX_PARAM_IN_CH_INFO,
    MMSECNS,
    AUDIO_SOURCE_DELAY,
    DEVICE_NAME,
} section_t;

typedef void (* section_process_fn)(const XML_Char **attr);
@@ -119,6 +120,7 @@ static void process_custom_mtmx_in_params(const XML_Char **attr);
static void process_custom_mtmx_param_in_ch_info(const XML_Char **attr);
static void process_fluence_mmsecns(const XML_Char **attr);
static void process_audio_source_delay(const XML_Char **attr);
static void process_device_name(const XML_Char **attr);

static section_process_fn section_table[] = {
    [ROOT] = process_root,
@@ -144,6 +146,7 @@ static section_process_fn section_table[] = {
    [CUSTOM_MTMX_PARAM_IN_CH_INFO] = process_custom_mtmx_param_in_ch_info,
    [MMSECNS] = process_fluence_mmsecns,
    [AUDIO_SOURCE_DELAY] = process_audio_source_delay,
    [DEVICE_NAME] = process_device_name,
};

static section_t section;
@@ -294,6 +297,11 @@ static struct audio_custom_mtmx_in_params_info mtmx_in_params_info;
 *      ...
 * </operator_specific>
 *
 * <device_names>
 * <device name="???" alias="???"/>
 * ...
 * ...
 * </device_names>
 * </audio_platform_info>
 */

@@ -1301,7 +1309,38 @@ static void process_custom_mtmx_params(const XML_Char **attr)
    }

    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,
@@ -1346,11 +1385,13 @@ static void start_tag(void *userdata __unused, const XML_Char *tag_name,
            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 != MMSECNS) &&
                (section != BACKEND_NAME) && (section != BITWIDTH) &&
                (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC)) {
                ALOGE("device tag only supported for acdb/backend names/bitwitdh/interface names");
                (section != INTERFACE_NAME) && (section != OPERATOR_SPECIFIC) && (section != DEVICE_NAME)) {
                ALOGE("device tag only supported for acdb/backend names/bitwidth/interface/operator specific/device names");
                return;
            }

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