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

Commit a56da22f authored by Aditya Bavanari's avatar Aditya Bavanari Committed by Shiv Maliyappanahalli
Browse files

hal: Fix failure in VtsHalAudioV2_0Target test due to spkr protection

1. Speaker protection cal file is not generated as
the path /data/misc/audio is not accessible. Change the
cal file path to /data/vendor/misc/audio to fix this.
2. VtsHalAudioV2_0Target fails to execute completely and results in
failure of target boot up after VTS execution as system server waits
indefinitely for audioserver to come up when speaker protection
is enabled.

This is due to improper clean up of speaker protection threads
and fd leaks.

Add spkr_prot_deinit function which joins the calibration thread
and cleans up the memory allocated for thread. Close the leaked
fds in the speaker calibration thread to ensure successful
execution of VTS.

CRs-Fixed: 2076733
Change-Id: I55a03dcafa3ed7bdf6f4d6d1bf72d84fbcc9c404
parent 6d65588e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -359,6 +359,7 @@ int32_t audio_extn_read_xml(struct audio_device *adev, uint32_t mixer_card,
#endif /* AUXPCM_BT_ENABLED */
#ifndef SPKR_PROT_ENABLED
#define audio_extn_spkr_prot_init(adev)       (0)
#define audio_extn_spkr_prot_deinit()         (0)
#define audio_extn_spkr_prot_start_processing(snd_device)    (-EINVAL)
#define audio_extn_spkr_prot_calib_cancel(adev) (0)
#define audio_extn_spkr_prot_stop_processing(snd_device)     (0)
@@ -368,6 +369,7 @@ int32_t audio_extn_read_xml(struct audio_device *adev, uint32_t mixer_card,
#define audio_extn_fbsp_get_parameters(query, reply)   (0)
#else
void audio_extn_spkr_prot_init(void *adev);
int audio_extn_spkr_prot_deinit();
int audio_extn_spkr_prot_start_processing(snd_device_t snd_device);
void audio_extn_spkr_prot_stop_processing(snd_device_t snd_device);
bool audio_extn_spkr_prot_is_enabled();
+62 −6
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@
#define MAX_RESISTANCE_SPKR_Q24 (40 * (1 << 24))

/*Path where the calibration file will be stored*/
#define CALIB_FILE "/data/misc/audio/audio.cal"
#define CALIB_FILE "/data/vendor/misc/audio/audio.cal"

/*Time between retries for calibartion or intial wait time
  after boot up*/
@@ -160,6 +160,8 @@ struct speaker_prot_session {
    bool trigger_cal;
    pthread_mutex_t cal_wait_cond_mutex;
    pthread_cond_t cal_wait_condition;
    bool init_check;
    volatile bool thread_exit;
};

static struct pcm_config pcm_config_skr_prot = {
@@ -756,11 +758,12 @@ static void* spkr_calibration_thread()
            pthread_exit(0);
            return NULL;
        }
        close(acdb_fd);
    }
    if (acdb_fd > 0)
        close(acdb_fd);

    ALOGV("%s: start calibration", __func__);
    while (1) {
    while (!handle.thread_exit) {
        if (handle.wsa_found) {
            spk_1_tzn = handle.spkr_1_tzn;
            spk_2_tzn = handle.spkr_2_tzn;
@@ -1268,6 +1271,7 @@ int audio_extn_fbsp_get_parameters(struct str_parms *query,
void audio_extn_spkr_prot_init(void *adev)
{
    char value[PROPERTY_VALUE_MAX];
    int result = 0;
    ALOGD("%s: Initialize speaker protection module", __func__);
    memset(&handle, 0, sizeof(handle));
    if (!adev) {
@@ -1276,6 +1280,8 @@ void audio_extn_spkr_prot_init(void *adev)
    }
    property_get("persist.vendor.audio.speaker.prot.enable", value, "");
    handle.spkr_prot_enable = false;
    handle.init_check = false;
    handle.thread_exit = false;
    if (!strncmp("true", value, 4))
       handle.spkr_prot_enable = true;
    if (!handle.spkr_prot_enable) {
@@ -1302,8 +1308,18 @@ void audio_extn_spkr_prot_init(void *adev)
        pthread_mutex_init(&handle.mutex_spkr_prot, NULL);
        pthread_mutex_init(&handle.spkr_calib_cancelack_mutex, NULL);
        ALOGD("%s:WSA Create calibration thread", __func__);
        (void)pthread_create(&handle.spkr_calibration_thread,
        result = pthread_create(&handle.spkr_calibration_thread,
        (const pthread_attr_t *) NULL, spkr_calibration_thread, &handle);
        if (result == 0) {
            handle.init_check = true;
        } else {
            ALOGE("%s: speaker calibration thread creation failed", __func__);
            pthread_mutex_destroy(&handle.mutex_spkr_prot);
            pthread_mutex_destroy(&handle.spkr_calib_cancelack_mutex);
            pthread_mutex_destroy(&handle.cal_wait_cond_mutex);
            pthread_cond_destroy(&handle.spkr_calib_cancel);
            pthread_cond_destroy(&handle.spkr_calibcancel_ack);
        }
    return;
    } else {
        ALOGD("%s: WSA spkr calibration thread is not created", __func__);
@@ -1344,8 +1360,20 @@ void audio_extn_spkr_prot_init(void *adev)
    }
    if (handle.thermal_client_request) {
        ALOGD("%s: Create calibration thread", __func__);
        (void)pthread_create(&handle.spkr_calibration_thread,
        result = pthread_create(&handle.spkr_calibration_thread,
        (const pthread_attr_t *) NULL, spkr_calibration_thread, &handle);
        if (result == 0) {
            handle.init_check = true;
        } else {
            ALOGE("%s: speaker calibration thread creation failed", __func__);
            pthread_mutex_destroy(&handle.mutex_spkr_prot);
            pthread_mutex_destroy(&handle.spkr_calib_cancelack_mutex);
            pthread_mutex_destroy(&handle.cal_wait_cond_mutex);
            pthread_cond_destroy(&handle.spkr_calib_cancel);
            pthread_cond_destroy(&handle.spkr_calibcancel_ack);
            pthread_mutex_destroy(&handle.spkr_prot_thermalsync_mutex);
            pthread_cond_destroy(&handle.spkr_prot_thermalsync);
        }
    } else {
        ALOGE("%s: thermal_client_request failed", __func__);
        if (handle.thermal_client_handle &&
@@ -1368,6 +1396,34 @@ void audio_extn_spkr_prot_init(void *adev)
    }
}

int audio_extn_spkr_prot_deinit()
{
    int result = 0;

    ALOGD("%s: Entering deinit init_check :%d", __func__, handle.init_check);
    if(!handle.init_check)
        return -1;

    handle.thread_exit = true;
    spkr_calibrate_signal();
    result = pthread_join(handle.spkr_calibration_thread, (void **) NULL);
    if (result < 0) {
        ALOGE("%s:Unable to join the calibration thread", __func__);
        return -1;
    }
    pthread_mutex_destroy(&handle.mutex_spkr_prot);
    pthread_mutex_destroy(&handle.spkr_calib_cancelack_mutex);
    pthread_mutex_destroy(&handle.cal_wait_cond_mutex);
    pthread_cond_destroy(&handle.spkr_calib_cancel);
    pthread_cond_destroy(&handle.spkr_calibcancel_ack);
    if(!handle.wsa_found) {
        pthread_mutex_destroy(&handle.spkr_prot_thermalsync_mutex);
        pthread_cond_destroy(&handle.spkr_prot_thermalsync);
    }
    memset(&handle, 0, sizeof(handle));
    return 0;
}

int audio_extn_select_spkr_prot_cal_data(snd_device_t snd_device)
{
    struct audio_cal_info_spk_prot_cfg protCfg;
+2 −0
Original line number Diff line number Diff line
@@ -2569,6 +2569,8 @@ void platform_deinit(void *platform)
    /* deinit usb */
    audio_extn_usb_deinit();
    audio_extn_dap_hal_deinit();
    if (audio_extn_spkr_prot_is_enabled())
        audio_extn_spkr_prot_deinit();
#ifdef DYNAMIC_LOG_ENABLED
    log_utils_deinit();
#endif
+2 −0
Original line number Diff line number Diff line
@@ -2351,6 +2351,8 @@ void platform_deinit(void *platform)
    /* deinit usb */
    audio_extn_usb_deinit();
    audio_extn_dap_hal_deinit();
    if (audio_extn_spkr_prot_is_enabled())
        audio_extn_spkr_prot_deinit();
#ifdef DYNAMIC_LOG_ENABLED
    log_utils_deinit();
#endif