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

Commit ce227962 authored by Satya Krishna Pindiproli's avatar Satya Krishna Pindiproli
Browse files

hal: add support for USB_HEADSET in device selection

Currently, only USB devices of type USB_DEVICE are supported.

Add support for USB_HEADSET devices in HAL device selection
based on the device sent by audio policy.

CRs-Fixed: 2150144
Change-Id: I7a18ee024ef50d5e1da99d9bed20c81d424cf805
parent b09eb021
Loading
Loading
Loading
Loading
+11 −17
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
 * Copyright (c) 2013-2018, The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Copyright (C) 2013 The Android Open Source Project
@@ -6279,6 +6279,7 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
    ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_CONNECT, value, sizeof(value));
    if (ret >= 0) {
        val = atoi(value);
        audio_devices_t device = (audio_devices_t) val;
        if (audio_is_output_device(val) &&
            (val & AUDIO_DEVICE_OUT_AUX_DIGITAL)) {
            ALOGV("cache new ext disp type and edid");
@@ -6289,8 +6290,7 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
                goto done;
            }
            platform_cache_edid(adev->platform);
        } else if (((audio_devices_t)val == AUDIO_DEVICE_OUT_USB_DEVICE) ||
                   ((audio_devices_t)val == AUDIO_DEVICE_IN_USB_DEVICE)) {
        } else if (audio_is_usb_out_device(device) || audio_is_usb_in_device(device)) {
            /*
             * Do not allow AFE proxy port usage by WFD source when USB headset is connected.
             * Per AudioPolicyManager, USB device is higher priority than WFD.
@@ -6299,12 +6299,9 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
             * starting voice call on USB
             */
            ret = str_parms_get_str(parms, "card", value, sizeof(value));
            if (ret >= 0) {
                if (audio_is_output_device(val))
                    audio_extn_usb_add_device(AUDIO_DEVICE_OUT_USB_DEVICE, atoi(value));
                else
                    audio_extn_usb_add_device(AUDIO_DEVICE_IN_USB_DEVICE, atoi(value));
            }
            if (ret >= 0)
                audio_extn_usb_add_device(device, atoi(value));

            if (!audio_extn_usb_is_tunnel_supported()) {
                ALOGV("detected USB connect .. disable proxy");
                adev->allow_afe_proxy_usage = false;
@@ -6315,21 +6312,18 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
    ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_DISCONNECT, value, sizeof(value));
    if (ret >= 0) {
        val = atoi(value);
        audio_devices_t device = (audio_devices_t) val;
        /*
         * The HDMI / Displayport disconnect handling has been moved to
         * audio extension to ensure that its parameters are not
         * invalidated prior to updating sysfs of the disconnect event
         * Invalidate will be handled by audio_extn_ext_disp_set_parameters()
         */
        if (((audio_devices_t)val == AUDIO_DEVICE_OUT_USB_DEVICE) ||
            ((audio_devices_t)val == AUDIO_DEVICE_IN_USB_DEVICE)) {
        if (audio_is_usb_out_device(device) || audio_is_usb_in_device(device)) {
            ret = str_parms_get_str(parms, "card", value, sizeof(value));
            if (ret >= 0) {
                if (audio_is_output_device(val))
                    audio_extn_usb_remove_device(AUDIO_DEVICE_OUT_USB_DEVICE, atoi(value));
                else
                    audio_extn_usb_remove_device(AUDIO_DEVICE_IN_USB_DEVICE, atoi(value));
            }
            if (ret >= 0)
                audio_extn_usb_remove_device(device, atoi(value));

            if (!audio_extn_usb_is_tunnel_supported()) {
                ALOGV("detected USB disconnect .. enable proxy");
                adev->allow_afe_proxy_usage = true;
+24 −12
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
 * Copyright (c) 2013-2018, The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Copyright (C) 2013 The Android Open Source Project
@@ -940,6 +940,7 @@ static int msm_device_to_be_id_internal_codec [][NO_COLS] = {
       {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET              ,       9},
       {AUDIO_DEVICE_OUT_USB_ACCESSORY                  ,       -1},
       {AUDIO_DEVICE_OUT_USB_DEVICE                     ,       -1},
       {AUDIO_DEVICE_OUT_USB_HEADSET                    ,       -1},
       {AUDIO_DEVICE_OUT_REMOTE_SUBMIX                  ,       9},
       {AUDIO_DEVICE_OUT_PROXY                          ,       9},
       {AUDIO_DEVICE_OUT_FM                             ,       7},
@@ -965,6 +966,7 @@ static int msm_device_to_be_id_external_codec [][NO_COLS] = {
       {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET              ,       9},
       {AUDIO_DEVICE_OUT_USB_ACCESSORY                  ,       -1},
       {AUDIO_DEVICE_OUT_USB_DEVICE                     ,       -1},
       {AUDIO_DEVICE_OUT_USB_HEADSET                    ,       -1},
       {AUDIO_DEVICE_OUT_REMOTE_SUBMIX                  ,       9},
       {AUDIO_DEVICE_OUT_PROXY                          ,       9},
       {AUDIO_DEVICE_OUT_FM                             ,       7},
@@ -3904,8 +3906,10 @@ snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *o
        } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
                               AUDIO_DEVICE_OUT_SPEAKER)) {
            snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
        } else if (devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
                               AUDIO_DEVICE_OUT_SPEAKER)) {
        } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
                               AUDIO_DEVICE_OUT_SPEAKER)) ||
                    (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
                               AUDIO_DEVICE_OUT_SPEAKER))){
            snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
        } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
                   (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
@@ -3961,7 +3965,9 @@ snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *o
            } else {
                snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
            }
        } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
        } else if (devices &
                    (AUDIO_DEVICE_OUT_USB_DEVICE |
                     AUDIO_DEVICE_OUT_USB_HEADSET)) {
            if (snd_device == SND_DEVICE_NONE) {
                    snd_device = audio_extn_usb_is_capture_supported() ?
                             SND_DEVICE_OUT_VOICE_USB_HEADSET :
@@ -4096,7 +4102,9 @@ snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *o
        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;
    } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
    } else if (devices &
                (AUDIO_DEVICE_OUT_USB_DEVICE |
                 AUDIO_DEVICE_OUT_USB_HEADSET)) {
        if (audio_extn_usb_is_capture_supported())
           snd_device = SND_DEVICE_OUT_USB_HEADSET;
        else
@@ -4196,7 +4204,7 @@ static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
                snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
        } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
            snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
        } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
        } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
            snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
        }
        platform_set_echo_reference(adev, true, out_device);
@@ -4226,7 +4234,7 @@ static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
                snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
        } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
            snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
       } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
       } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
            snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
        }
        platform_set_echo_reference(adev, true, out_device);
@@ -4394,7 +4402,9 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
            }
        } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
            snd_device = SND_DEVICE_IN_VOICE_RX;
        } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
        } else if (out_device &
                    (AUDIO_DEVICE_OUT_USB_DEVICE |
                     AUDIO_DEVICE_OUT_USB_HEADSET)) {
            if (audio_extn_usb_is_capture_supported()) {
                snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
            }
@@ -4473,7 +4483,7 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
                else
                    snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
            }
        } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
        } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
            snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
        }
    } else if (source == AUDIO_SOURCE_UNPROCESSED) {
@@ -4493,7 +4503,7 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
            }
        } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
            snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
        } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
        } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
            snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
        }
    } else if ((source == AUDIO_SOURCE_VOICE_COMMUNICATION) ||
@@ -4572,7 +4582,7 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
            snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
        } else if (in_device & AUDIO_DEVICE_IN_FM_TUNER) {
            snd_device = SND_DEVICE_IN_CAPTURE_FM;
        } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE ) {
        } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
            snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
        } else {
            ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
@@ -4609,7 +4619,9 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
        } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
                   out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
            snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
        } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
        } else if (out_device &
                    (AUDIO_DEVICE_OUT_USB_DEVICE |
                     AUDIO_DEVICE_OUT_USB_HEADSET)) {
            if (audio_extn_usb_is_capture_supported())
                snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
            else
+29 −13
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
 * Copyright (c) 2013-2018, The Linux Foundation. All rights reserved.
 * Not a Contribution.
 *
 * Copyright (C) 2013 The Android Open Source Project
@@ -915,6 +915,7 @@ static int msm_device_to_be_id [][NO_COLS] = {
       {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET              ,       9},
       {AUDIO_DEVICE_OUT_USB_ACCESSORY                  ,       -1},
       {AUDIO_DEVICE_OUT_USB_DEVICE                     ,       -1},
       {AUDIO_DEVICE_OUT_USB_HEADSET                    ,       -1},
       {AUDIO_DEVICE_OUT_REMOTE_SUBMIX                  ,       9},
       {AUDIO_DEVICE_OUT_PROXY                          ,       9},
       {AUDIO_DEVICE_OUT_FM                             ,       7},
@@ -940,6 +941,7 @@ static int msm_device_to_be_id [][NO_COLS] = {
       {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET              ,       9},
       {AUDIO_DEVICE_OUT_USB_ACCESSORY                  ,       -1},
       {AUDIO_DEVICE_OUT_USB_DEVICE                     ,       -1},
       {AUDIO_DEVICE_OUT_USB_HEADSET                    ,       -1},
       {AUDIO_DEVICE_OUT_REMOTE_SUBMIX                  ,       9},
       {AUDIO_DEVICE_OUT_PROXY                          ,       9},
/* Add the correct be ids */
@@ -966,6 +968,7 @@ static int msm_device_to_be_id [][NO_COLS] = {
       {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET              ,       9},
       {AUDIO_DEVICE_OUT_USB_ACCESSORY                  ,       -1},
       {AUDIO_DEVICE_OUT_USB_DEVICE                     ,       -1},
       {AUDIO_DEVICE_OUT_USB_HEADSET                    ,       -1},
       {AUDIO_DEVICE_OUT_REMOTE_SUBMIX                  ,       9},
       {AUDIO_DEVICE_OUT_PROXY                          ,       9},
/* Add the correct be ids */
@@ -992,6 +995,7 @@ static int msm_device_to_be_id [][NO_COLS] = {
       {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET              ,       9},
       {AUDIO_DEVICE_OUT_USB_ACCESSORY                  ,       -1},
       {AUDIO_DEVICE_OUT_USB_DEVICE                     ,       -1},
       {AUDIO_DEVICE_OUT_USB_HEADSET                    ,       -1},
       {AUDIO_DEVICE_OUT_REMOTE_SUBMIX                  ,       9},
       {AUDIO_DEVICE_OUT_PROXY                          ,       9},
/* Add the correct be ids */
@@ -3711,8 +3715,10 @@ snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *o
        } else if (devices == (AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
                               AUDIO_DEVICE_OUT_SPEAKER)) {
            snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
        } else if (devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
                               AUDIO_DEVICE_OUT_SPEAKER)) {
        } else if ((devices == (AUDIO_DEVICE_OUT_USB_DEVICE |
                               AUDIO_DEVICE_OUT_SPEAKER)) ||
                   (devices == (AUDIO_DEVICE_OUT_USB_HEADSET |
                               AUDIO_DEVICE_OUT_SPEAKER))) {
            snd_device = SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET;
        } else if ((devices & AUDIO_DEVICE_OUT_SPEAKER) &&
                   (devices & AUDIO_DEVICE_OUT_ALL_A2DP)) {
@@ -3768,7 +3774,9 @@ snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *o
            } else {
                snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
            }
        } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
        } else if (devices &
                    (AUDIO_DEVICE_OUT_USB_DEVICE |
                     AUDIO_DEVICE_OUT_USB_HEADSET)) {
            if (voice_is_in_call(adev)) {
                switch (adev->voice.tty_mode) {
                    case TTY_MODE_FULL:
@@ -3904,7 +3912,9 @@ snd_device_t platform_get_output_snd_device(void *platform, struct stream_out *o
        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;
    } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
    } else if (devices &
                (AUDIO_DEVICE_OUT_USB_DEVICE |
                 AUDIO_DEVICE_OUT_USB_HEADSET)) {
        if (audio_extn_usb_is_capture_supported())
            snd_device = SND_DEVICE_OUT_USB_HEADSET;
        else
@@ -4007,7 +4017,7 @@ static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
                snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC_NS;
        } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
            snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
        } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
        } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
            snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
        }
        platform_set_echo_reference(adev, true, out_device);
@@ -4041,7 +4051,7 @@ static snd_device_t get_snd_device_for_voice_comm(struct platform_data *my_data,
                snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC;
        } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
            snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
       } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
       } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
            snd_device = SND_DEVICE_IN_USB_HEADSET_MIC_AEC;
        }
        platform_set_echo_reference(adev, true, out_device);
@@ -4145,7 +4155,9 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
                        ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->voice.tty_mode);
                }
                goto exit;
            } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
            } else if (out_device &
                        (AUDIO_DEVICE_OUT_USB_DEVICE |
                         AUDIO_DEVICE_OUT_USB_HEADSET)) {
                switch (adev->voice.tty_mode) {
                    case TTY_MODE_FULL:
                        snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_USB_MIC;
@@ -4242,7 +4254,9 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
            }
        } else if (out_device & AUDIO_DEVICE_OUT_TELEPHONY_TX) {
            snd_device = SND_DEVICE_IN_VOICE_RX;
        } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
        } else if (out_device &
                    (AUDIO_DEVICE_OUT_USB_DEVICE |
                     AUDIO_DEVICE_OUT_USB_HEADSET)) {
          if (audio_extn_usb_is_capture_supported()) {
            snd_device = SND_DEVICE_IN_VOICE_USB_HEADSET_MIC;
          }
@@ -4321,7 +4335,7 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
                else
                    snd_device = SND_DEVICE_IN_VOICE_REC_MIC;
            }
        } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
        } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
              snd_device = SND_DEVICE_IN_VOICE_RECOG_USB_HEADSET_MIC;
        }
    } else if (source == AUDIO_SOURCE_UNPROCESSED) {
@@ -4341,7 +4355,7 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
             }
         } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
                 snd_device = SND_DEVICE_IN_UNPROCESSED_HEADSET_MIC;
         } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE) {
         } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
                 snd_device = SND_DEVICE_IN_UNPROCESSED_USB_HEADSET_MIC;
         }
    } else if ((source == AUDIO_SOURCE_VOICE_COMMUNICATION) ||
@@ -4419,7 +4433,7 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
            snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
        } else if (in_device & AUDIO_DEVICE_IN_FM_TUNER) {
            snd_device = SND_DEVICE_IN_CAPTURE_FM;
        } else if (in_device & AUDIO_DEVICE_IN_USB_DEVICE ) {
        } else if (audio_is_usb_in_device(in_device | AUDIO_DEVICE_BIT_IN)) {
            snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
        } else {
            ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
@@ -4464,7 +4478,9 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
        } else if (out_device & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
                   out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
            snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
        } else if (out_device & AUDIO_DEVICE_OUT_USB_DEVICE) {
        } else if (out_device &
                    (AUDIO_DEVICE_OUT_USB_DEVICE |
                     AUDIO_DEVICE_OUT_USB_HEADSET)) {
            if (audio_extn_usb_is_capture_supported())
              snd_device = SND_DEVICE_IN_USB_HEADSET_MIC;
            else