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

Commit 5a7c5d6d authored by Mingming Yin's avatar Mingming Yin
Browse files

hal: update playback channel mapping for USB headset

- Set proper USB headset channel mapping before
  starting playback.
- Update audio_extn_set_afe_proxy_channel_mixer
  to handle channel mapping based on channel count.

CRs-Fixed: 620828

Change-Id: I9660e3088bc747c30891b0aa7ec8d22096dd0fa2
parent 3075fcc2
Loading
Loading
Loading
Loading
+21 −9
Original line number Original line Diff line number Diff line
@@ -211,6 +211,10 @@ static int32_t afe_proxy_set_channel_mapping(struct audio_device *adev,
    ALOGV("%s channel_count:%d",__func__, channel_count);
    ALOGV("%s channel_count:%d",__func__, channel_count);


    switch (channel_count) {
    switch (channel_count) {
    case 2:
        set_values[0] = PCM_CHANNEL_FL;
        set_values[1] = PCM_CHANNEL_FR;
        break;
    case 6:
    case 6:
        set_values[0] = PCM_CHANNEL_FL;
        set_values[0] = PCM_CHANNEL_FL;
        set_values[1] = PCM_CHANNEL_FR;
        set_values[1] = PCM_CHANNEL_FR;
@@ -248,7 +252,8 @@ static int32_t afe_proxy_set_channel_mapping(struct audio_device *adev,
    return ret;
    return ret;
}
}


int32_t audio_extn_set_afe_proxy_channel_mixer(struct audio_device *adev)
int32_t audio_extn_set_afe_proxy_channel_mixer(struct audio_device *adev,
                                    int channel_count)
{
{
    int32_t ret = 0;
    int32_t ret = 0;
    const char *channel_cnt_str = NULL;
    const char *channel_cnt_str = NULL;
@@ -259,9 +264,8 @@ int32_t audio_extn_set_afe_proxy_channel_mixer(struct audio_device *adev)
    /* use the existing channel count set by hardware params to
    /* use the existing channel count set by hardware params to
    configure the back end for stereo as usb/a2dp would be
    configure the back end for stereo as usb/a2dp would be
    stereo by default */
    stereo by default */
    ALOGD("%s: channels = %d", __func__,
    ALOGD("%s: channels = %d", __func__, channel_count);
           aextnmod.proxy_channel_num);
    switch (channel_count) {
    switch (aextnmod.proxy_channel_num) {
    case 8: channel_cnt_str = "Eight"; break;
    case 8: channel_cnt_str = "Eight"; break;
    case 7: channel_cnt_str = "Seven"; break;
    case 7: channel_cnt_str = "Seven"; break;
    case 6: channel_cnt_str = "Six"; break;
    case 6: channel_cnt_str = "Six"; break;
@@ -271,7 +275,7 @@ int32_t audio_extn_set_afe_proxy_channel_mixer(struct audio_device *adev)
    default: channel_cnt_str = "Two"; break;
    default: channel_cnt_str = "Two"; break;
    }
    }


    if(aextnmod.proxy_channel_num >= 2 && aextnmod.proxy_channel_num < 8) {
    if(channel_count >= 2 && channel_count <= 8) {
       ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
       ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
       if (!ctl) {
       if (!ctl) {
            ALOGE("%s: could not get ctl for mixer cmd - %s",
            ALOGE("%s: could not get ctl for mixer cmd - %s",
@@ -281,10 +285,12 @@ int32_t audio_extn_set_afe_proxy_channel_mixer(struct audio_device *adev)
    }
    }
    mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);
    mixer_ctl_set_enum_by_string(ctl, channel_cnt_str);


    if (aextnmod.proxy_channel_num == 6 ||
    if (channel_count == 6 || channel_count == 8 || channel_count == 2) {
          aextnmod.proxy_channel_num == 8)
        ret = afe_proxy_set_channel_mapping(adev, channel_count);
        ret = afe_proxy_set_channel_mapping(adev,
    } else {
                             aextnmod.proxy_channel_num);
        ALOGE("%s: set unsupported channel count(%d)",  __func__, channel_count);
        ret = -EINVAL;
    }


    ALOGD("%s: exit", __func__);
    ALOGD("%s: exit", __func__);
    return ret;
    return ret;
@@ -354,6 +360,12 @@ int32_t audio_extn_read_afe_proxy_channel_masks(struct stream_out *out)
    }
    }
    return ret;
    return ret;
}
}

int32_t audio_extn_get_afe_proxy_channel_count()
{
    return aextnmod.proxy_channel_num;
}

#endif /* AFE_PROXY_ENABLED */
#endif /* AFE_PROXY_ENABLED */


void audio_extn_set_parameters(struct audio_device *adev,
void audio_extn_set_parameters(struct audio_device *adev,
+7 −3
Original line number Original line Diff line number Diff line
@@ -40,11 +40,15 @@ bool audio_extn_should_use_handset_anc(int in_channels);
#endif
#endif


#ifndef AFE_PROXY_ENABLED
#ifndef AFE_PROXY_ENABLED
#define audio_extn_set_afe_proxy_channel_mixer(adev)     (0)
#define audio_extn_set_afe_proxy_channel_mixer(adev,channel_count)     (0)
#define audio_extn_read_afe_proxy_channel_masks(out)                   (0)
#define audio_extn_read_afe_proxy_channel_masks(out)                   (0)
#define audio_extn_get_afe_proxy_channel_count()                       (0)
#else
#else
int32_t audio_extn_set_afe_proxy_channel_mixer(struct audio_device *adev);
int32_t audio_extn_set_afe_proxy_channel_mixer(struct audio_device *adev,
                                                    int channel_count);
int32_t audio_extn_read_afe_proxy_channel_masks(struct stream_out *out);
int32_t audio_extn_read_afe_proxy_channel_masks(struct stream_out *out);
int32_t audio_extn_get_afe_proxy_channel_count();

#endif
#endif


#ifndef USB_HEADSET_ENABLED
#ifndef USB_HEADSET_ENABLED
+5 −2
Original line number Original line Diff line number Diff line
@@ -1141,14 +1141,17 @@ snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devi
        snd_device = SND_DEVICE_OUT_HDMI ;
        snd_device = SND_DEVICE_OUT_HDMI ;
    } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
    } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
               devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
               devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
        ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
        audio_extn_set_afe_proxy_channel_mixer(adev, 2);
        snd_device = SND_DEVICE_OUT_USB_HEADSET;
        snd_device = SND_DEVICE_OUT_USB_HEADSET;
    } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
    } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
        snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
        snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
    } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
    } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
        snd_device = SND_DEVICE_OUT_HANDSET;
        snd_device = SND_DEVICE_OUT_HANDSET;
    } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
    } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
        ALOGD("%s: setting sink capability for Proxy", __func__);
        channel_count = audio_extn_get_afe_proxy_channel_count();
        audio_extn_set_afe_proxy_channel_mixer(adev);
        ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
        audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
        snd_device = SND_DEVICE_OUT_AFE_PROXY;
        snd_device = SND_DEVICE_OUT_AFE_PROXY;
    } else {
    } else {
        ALOGE("%s: Unknown device(s) %#x", __func__, devices);
        ALOGE("%s: Unknown device(s) %#x", __func__, devices);
+5 −2
Original line number Original line Diff line number Diff line
@@ -1216,14 +1216,17 @@ snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devi
        snd_device = SND_DEVICE_OUT_HDMI ;
        snd_device = SND_DEVICE_OUT_HDMI ;
    } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
    } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
               devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
               devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
        ALOGD("%s: setting USB hadset channel capability(2) for Proxy", __func__);
        audio_extn_set_afe_proxy_channel_mixer(adev, 2);
        snd_device = SND_DEVICE_OUT_USB_HEADSET;
        snd_device = SND_DEVICE_OUT_USB_HEADSET;
    } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
    } else if (devices & AUDIO_DEVICE_OUT_FM_TX) {
        snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
        snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
    } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
    } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
        snd_device = SND_DEVICE_OUT_HANDSET;
        snd_device = SND_DEVICE_OUT_HANDSET;
    } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
    } else if (devices & AUDIO_DEVICE_OUT_PROXY) {
        ALOGD("%s: setting sink capability for Proxy", __func__);
        channel_count = audio_extn_get_afe_proxy_channel_count();
        audio_extn_set_afe_proxy_channel_mixer(adev);
        ALOGD("%s: setting sink capability(%d) for Proxy", __func__, channel_count);
        audio_extn_set_afe_proxy_channel_mixer(adev, channel_count);
        snd_device = SND_DEVICE_OUT_AFE_PROXY;
        snd_device = SND_DEVICE_OUT_AFE_PROXY;
    } else {
    } else {
        ALOGE("%s: Unknown device(s) %#x", __func__, devices);
        ALOGE("%s: Unknown device(s) %#x", __func__, devices);