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

Commit d6a9e0c6 authored by kunleiz's avatar kunleiz
Browse files

hal: check for usb card state before setting in/out device

During record, audio record usecase still uses usb-headset-mic
as input device even if usb-headset is plugged out. It causes
record fail and mute issue happen.

Fix it by adding check for USB card state, and routing input
device to handset, output device to speaker when usb card is
not existed.

CRs-Fixed: 2264971
Change-Id: Ibfe43c4795a76bf386ab9008a632ef07aa1c7f28
parent 6ad12456
Loading
Loading
Loading
Loading
+14 −18
Original line number Diff line number Diff line
@@ -5719,6 +5719,13 @@ int adev_open_output_stream(struct audio_hw_device *dev,
                      (devices != AUDIO_DEVICE_OUT_USB_ACCESSORY);
    bool direct_dev = is_hdmi || is_usb_dev;

    if (is_usb_dev && (audio_extn_usb_connected(NULL))) {
        is_usb_dev = false;
        devices = AUDIO_DEVICE_OUT_SPEAKER;
        ALOGW("%s: ignore set device to non existing USB card, use output device(%#x)",
              __func__, devices);
    }

    *stream_out = NULL;

    out = (struct stream_out *)calloc(1, sizeof(struct stream_out));
@@ -5771,14 +5778,6 @@ int adev_open_output_stream(struct audio_hw_device *dev,
           ALOGV("AUDIO_DEVICE_OUT_AUX_DIGITAL and DIRECT|OFFLOAD, check hdmi caps");
           ret = read_hdmi_sink_caps(out);
       } else if (is_usb_dev) {
            /* Check against usb headset connection state */
            if (!audio_extn_usb_connected(NULL)) {
                ALOGD("%s: usb headset unplugged", __func__);
                ret = -EINVAL;
                pthread_mutex_unlock(&adev->lock);
                goto error_open;
            }

            ret = read_usb_sup_params_and_compare(true /*is_playback*/,
                                                  &config->format,
                                                  &out->supported_formats[0],
@@ -6850,6 +6849,13 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
                                                            flags,
                                                            source);

    if (is_usb_dev && (audio_extn_usb_connected(NULL))) {
        is_usb_dev = false;
        devices = AUDIO_DEVICE_IN_BUILTIN_MIC;
        ALOGW("%s: ignore set device to non existing USB card, use input device(%#x)",
              __func__, devices);
    }

    *stream_in = NULL;

    if (!(is_usb_dev && may_use_hifi_record)) {
@@ -6913,16 +6919,6 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
    }

    if (is_usb_dev && may_use_hifi_record) {
        /* Check against usb headset connection state */
        pthread_mutex_lock(&adev->lock);
        if (!audio_extn_usb_connected(NULL)) {
            ALOGD("%s: usb headset unplugged", __func__);
            ret = -EINVAL;
            pthread_mutex_unlock(&adev->lock);
            goto err_open;
        }
        pthread_mutex_unlock(&adev->lock);

        /* HiFi record selects an appropriate format, channel, rate combo
           depending on sink capabilities*/
        ret = read_usb_sup_params_and_compare(false /*is_playback*/,