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

Commit d7ee2c6c authored by Kevin Rocard's avatar Kevin Rocard Committed by android-build-merger
Browse files

Merge "Workaround: Do not send command to a disconnected usb subsystem" into oc-dr1-dev

am: 2cfb8392

Change-Id: I4b52cb6721e487f25587805e4b9f3eb1155bbe76
parents 56689452 2cfb8392
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ int audio_extn_hfp_set_mic_mute(struct audio_device *adev, bool state);
#define audio_extn_usb_get_max_channels(dir)                           (0)
#define audio_extn_usb_get_max_bit_width(dir)                          (0)
#define audio_extn_usb_sup_sample_rates(t, s, l)                       (0)
#define audio_extn_usb_alive(adev)                                     (false)
#else
void audio_extn_usb_init(void *adev);
void audio_extn_usb_deinit();
@@ -98,6 +99,7 @@ bool audio_extn_usb_is_capture_supported();
int audio_extn_usb_get_max_channels(bool is_playback);
int audio_extn_usb_get_max_bit_width(bool is_playback);
int audio_extn_usb_sup_sample_rates(bool is_playback, uint32_t *sr, uint32_t l);
bool audio_extn_usb_alive(int card);
#endif


+8 −0
Original line number Diff line number Diff line
@@ -306,6 +306,7 @@ static int usb_get_capability(int type,
        goto done;
    }

    // TODO: figure up if this wait is needed any more
    while (tries--) {
        if (access(path, F_OK) < 0) {
            ALOGW("stream %s doesn't exist retrying\n", path);
@@ -1102,6 +1103,13 @@ exit:
    return;
}

bool audio_extn_usb_alive(int card) {
    char path[PATH_MAX] = {0};
    // snprintf should never fail
    (void) snprintf(path, sizeof(path), "/proc/asound/card%u/stream0", card);
    return access(path, F_OK) == 0;
}

void audio_extn_usb_init(void *adev)
{
    if (usbmod == NULL) {
+33 −10
Original line number Diff line number Diff line
@@ -2207,6 +2207,19 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
            val = AUDIO_DEVICE_OUT_SPEAKER;
        }

        audio_devices_t new_dev = val;

        // Workaround: If routing to an non existing usb device, fail gracefully
        // The routing request will otherwise block during 10 second
        if (audio_is_usb_out_device(new_dev) && !audio_extn_usb_alive(adev->snd_card)) {
            ALOGW("out_set_parameters() ignoring rerouting to non existing USB card %d",
                  adev->snd_card);
            pthread_mutex_unlock(&adev->lock);
            pthread_mutex_unlock(&out->lock);
            status = -ENOSYS;
            goto routing_fail;
        }

        /*
         * select_devices() call below switches all the usecases on the same
         * backend to the new device. Refer to check_and_route_playback_usecases() in
@@ -2225,7 +2238,6 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
         *       Because select_devices() must be called to switch back the music
         *       playback to headset.
         */
        audio_devices_t new_dev = val;
        if (new_dev != AUDIO_DEVICE_NONE) {
            bool same_dev = out->devices == new_dev;
            out->devices = new_dev;
@@ -2269,6 +2281,7 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
        /*handles device and call state changes*/
        audio_extn_extspk_update(adev->extspk);
    }
    routing_fail:

    if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD) {
        parse_compress_metadata(out, parms);
@@ -3124,6 +3137,15 @@ static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
    if (ret >= 0) {
        val = atoi(value);
        if (((int)in->device != val) && (val != 0) && audio_is_input_device(val) ) {

            // Workaround: If routing to an non existing usb device, fail gracefully
            // The routing request will otherwise block during 10 second
            if (audio_is_usb_in_device(val) && !audio_extn_usb_alive(adev->snd_card)) {
                ALOGW("in_set_parameters() ignoring rerouting to non existing USB card %d",
                      adev->snd_card);
                status = -ENOSYS;
            } else {

                in->device = val;
                /* If recording is in progress, change the tx device to new device */
                if (!in->standby) {
@@ -3137,6 +3159,7 @@ static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
                }
            }
        }
    }

    pthread_mutex_unlock(&adev->lock);
    pthread_mutex_unlock(&in->lock);