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

Commit 410c530a authored by Ravi Kumar Alamanda's avatar Ravi Kumar Alamanda Committed by Pavan Chikkala
Browse files

hal: update error handling for pcm_prepare failures

Return any errors from pcm_prepare in start input
or output streams and ensure the pcm device is closed.

CRs-Fixed: 914347

Change-Id: I168cad151ed3fa0d0d3281ec7aceb99ef58bc753
parent ee8068c5
Loading
Loading
Loading
Loading
+30 −8
Original line number Diff line number Diff line
@@ -393,7 +393,7 @@ int enable_audio_route(struct audio_device *adev,
    audio_extn_utils_send_app_type_cfg(usecase);
    strcpy(mixer_path, use_case_table[usecase->id]);
    platform_add_backend_name(mixer_path, snd_device);
    ALOGV("%s: apply mixer and update path: %s", __func__, mixer_path);
    ALOGD("%s: apply mixer and update path: %s", __func__, mixer_path);
    audio_route_apply_and_update_path(adev->audio_route, mixer_path);
    ALOGV("%s: exit", __func__);
    return 0;
@@ -415,7 +415,7 @@ int disable_audio_route(struct audio_device *adev,
        snd_device = usecase->out_snd_device;
    strcpy(mixer_path, use_case_table[usecase->id]);
    platform_add_backend_name(mixer_path, snd_device);
    ALOGV("%s: reset and update mixer path: %s", __func__, mixer_path);
    ALOGD("%s: reset and update mixer path: %s", __func__, mixer_path);
    audio_route_reset_and_update_path(adev->audio_route, mixer_path);
    audio_extn_sound_trigger_update_stream_status(usecase, ST_EVENT_STREAM_FREE);
    audio_extn_listen_update_stream_status(usecase, LISTEN_EVENT_STREAM_FREE);
@@ -469,8 +469,7 @@ int enable_snd_device(struct audio_device *adev,
            return -EINVAL;
        }
    } else {
        ALOGV("%s: snd_device(%d: %s)", __func__,
        snd_device, device_name);
        ALOGD("%s: snd_device(%d: %s)", __func__, snd_device, device_name);
        /* due to the possibility of calibration overwrite between listen
            and audio, notify listen hal before audio calibration is sent */
        audio_extn_sound_trigger_update_device_status(snd_device,
@@ -514,8 +513,7 @@ int disable_snd_device(struct audio_device *adev,
    }

    if (adev->snd_dev_ref_cnt[snd_device] == 0) {
        ALOGV("%s: snd_device(%d: %s)", __func__,
              snd_device, device_name);
        ALOGD("%s: snd_device(%d: %s)", __func__, snd_device, device_name);
        /* exit usb play back thread */
        if(SND_DEVICE_OUT_USB_HEADSET == snd_device ||
           SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET == snd_device)
@@ -1054,9 +1052,20 @@ int start_input_stream(struct stream_in *in)
        }
        break;
    }

    ALOGV("%s: pcm_prepare", __func__);
    ret = pcm_prepare(in->pcm);
    if (ret < 0) {
        ALOGE("%s: pcm_prepare returned %d", __func__, ret);
        pcm_close(in->pcm);
        in->pcm = NULL;
        goto error_open;
    }

    audio_extn_perf_lock_release();

    ALOGV("%s: exit", __func__);
    ALOGD("%s: exit", __func__);

    return ret;

error_open:
@@ -1492,6 +1501,17 @@ int start_output_stream(struct stream_out *out)
            }
            break;
        }

        ALOGV("%s: pcm_prepare", __func__);
        if (pcm_is_ready(out->pcm)) {
            ret = pcm_prepare(out->pcm);
            if (ret < 0) {
                ALOGE("%s: pcm_prepare returned %d", __func__, ret);
                pcm_close(out->pcm);
                out->pcm = NULL;
                goto error_open;
            }
        }
    } else {
        out->pcm = NULL;
        out->compr = compress_open(adev->snd_card,
@@ -1517,7 +1537,9 @@ int start_output_stream(struct stream_out *out)
        if (adev->offload_effects_start_output != NULL)
            adev->offload_effects_start_output(out->handle, out->pcm_device_id);
    }
    ALOGV("%s: exit", __func__);

    ALOGD("%s: exit", __func__);

    return 0;
error_open:
    stop_output_stream(out);