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

Commit 99dab497 authored by Eric Laurent's avatar Eric Laurent
Browse files

audio hal: add support for USB_HEADSET device

Add support for USB_HEADSET device in device selection logic where
only USB_DEVICE was supported so far.

Bug: 36220140
Test: check music/video playback, voice/VoIP calls, OK google and
Camcorder with and without USB headset

Change-Id: Ia1a241b9a9cdec6c48c0596a057fabac30b1b16f
parent c7a9341c
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -1266,7 +1266,7 @@ int select_devices(struct audio_device *adev,
    /* Enable new sound devices */
    if (out_snd_device != SND_DEVICE_NONE) {
        if ((usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) ||
            (usecase->devices & AUDIO_DEVICE_OUT_USB_DEVICE))
            (usecase->devices & (AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_USB_HEADSET)))
            check_and_route_playback_usecases(adev, usecase, out_snd_device);
        enable_snd_device(adev, out_snd_device);
    }
@@ -3885,17 +3885,17 @@ 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) {
        audio_devices_t device = (audio_devices_t)strtoul(value, NULL, 10);
        if (device == AUDIO_DEVICE_OUT_USB_DEVICE) {
        if (audio_is_usb_out_device(device)) {
            ret = str_parms_get_str(parms, "card", value, sizeof(value));
            if (ret >= 0) {
                const int card = atoi(value);
                audio_extn_usb_add_device(AUDIO_DEVICE_OUT_USB_DEVICE, card);
                audio_extn_usb_add_device(device, card);
            }
        } else if (device == AUDIO_DEVICE_IN_USB_DEVICE) {
        } else if (audio_is_usb_in_device(device)) {
            ret = str_parms_get_str(parms, "card", value, sizeof(value));
            if (ret >= 0) {
                const int card = atoi(value);
                audio_extn_usb_add_device(AUDIO_DEVICE_IN_USB_DEVICE, card);
                audio_extn_usb_add_device(device, card);
            }
        }
    }
@@ -3903,18 +3903,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) {
        audio_devices_t device = (audio_devices_t)strtoul(value, NULL, 10);
        if (device == AUDIO_DEVICE_OUT_USB_DEVICE) {
        if (audio_is_usb_out_device(device)) {
            ret = str_parms_get_str(parms, "card", value, sizeof(value));
            if (ret >= 0) {
                const int card = atoi(value);

                audio_extn_usb_remove_device(AUDIO_DEVICE_OUT_USB_DEVICE, card);
                audio_extn_usb_remove_device(device, card);
            }
        } else if (device == AUDIO_DEVICE_IN_USB_DEVICE) {
        } else if (audio_is_usb_in_device(device)) {
            ret = str_parms_get_str(parms, "card", value, sizeof(value));
            if (ret >= 0) {
                const int card = atoi(value);
                audio_extn_usb_remove_device(AUDIO_DEVICE_IN_USB_DEVICE, card);
                audio_extn_usb_remove_device(device, card);
            }
        }
    }
+14 −12
Original line number Diff line number Diff line
@@ -2282,8 +2282,10 @@ snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devi
            snd_device = adev->bt_wb_speech_enabled ?
                    SND_DEVICE_OUT_SPEAKER_AND_BT_SCO_WB :
                    SND_DEVICE_OUT_SPEAKER_AND_BT_SCO;
        } 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_USB_DEVICE |
                               AUDIO_DEVICE_OUT_SPEAKER_SAFE)) {
@@ -2321,7 +2323,7 @@ snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devi
                else
                    snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES;
                }
        } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
        } else if (audio_is_usb_out_device(devices)) {
            if (voice_is_in_call(adev)) {
                switch (adev->voice.tty_mode) {
                    case TTY_MODE_FULL:
@@ -2393,7 +2395,7 @@ snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devi
        }
    } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
        snd_device = SND_DEVICE_OUT_HDMI ;
    } else if (devices & AUDIO_DEVICE_OUT_USB_DEVICE) {
    } else if (audio_is_usb_out_device(devices)) {
        if (audio_extn_usb_is_capture_supported())
            snd_device = SND_DEVICE_OUT_USB_HEADSET;
        else
@@ -2450,7 +2452,7 @@ 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;
@@ -2514,7 +2516,7 @@ 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;
          }
@@ -2574,7 +2576,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_VOICE_REC_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_VOICE_RECOG_USB_HEADSET_MIC;
        }
    } else if (source == AUDIO_SOURCE_UNPROCESSED) {
@@ -2594,7 +2596,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 ||
@@ -2621,7 +2623,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_HEADSET_MIC_AEC;
                } 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);
@@ -2643,7 +2645,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_HEADSET_MIC_AEC;
               } 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);
@@ -2726,7 +2728,7 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
            }
        } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) {
            snd_device = SND_DEVICE_IN_HDMI_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_USB_HEADSET_MIC;
        } else {
            ALOGE("%s: Unknown input device(s) %#x", __func__, in_device);
@@ -2768,7 +2770,7 @@ snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_d
            }
        } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
            snd_device = SND_DEVICE_IN_HDMI_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