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

Commit b51ceb1e authored by Haynes Mathew George's avatar Haynes Mathew George Committed by Mingming Yin
Browse files

hal: miscellaneous fixes

Fixes for the following issues reported by KW

21725, 21726, 21727, 21737, 21738, 21739, 21740, 21750,
21751, 21752, 25317, 30602, 32620, 36778, 41817, 41819,
50942, 54468, 54470, 54479, 55569, 54481, 55570, 55571,
58485, 85112, 85122, 85123

Change-Id: I9abef07db7ccdc19789a201eb268a97e1b360cad
parent 26f78bc7
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -148,6 +148,10 @@ static int32_t fm_start(struct audio_device *adev)
    ALOGD("%s: enter", __func__);
    ALOGD("%s: enter", __func__);


    uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
    uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));

    if (!uc_info)
        return -ENOMEM;

    uc_info->id = USECASE_AUDIO_PLAYBACK_FM;
    uc_info->id = USECASE_AUDIO_PLAYBACK_FM;
    uc_info->type = PCM_PLAYBACK;
    uc_info->type = PCM_PLAYBACK;
    uc_info->stream.out = adev->primary_output;
    uc_info->stream.out = adev->primary_output;
+4 −0
Original line number Original line Diff line number Diff line
@@ -136,6 +136,10 @@ static int32_t start_hfp(struct audio_device *adev,
    ALOGD("%s: enter", __func__);
    ALOGD("%s: enter", __func__);


    uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));
    uc_info = (struct audio_usecase *)calloc(1, sizeof(struct audio_usecase));

    if (!uc_info)
        return -ENOMEM;

    uc_info->id = hfpmod.ucid;
    uc_info->id = hfpmod.ucid;
    uc_info->type = PCM_HFP_CALL;
    uc_info->type = PCM_HFP_CALL;
    uc_info->stream.out = adev->primary_output;
    uc_info->stream.out = adev->primary_output;
+5 −0
Original line number Original line Diff line number Diff line
@@ -200,6 +200,11 @@ int audio_extn_listen_init(struct audio_device *adev, unsigned int snd_card)
        listen_dev = (struct listen_audio_device*)
        listen_dev = (struct listen_audio_device*)
            calloc(1, sizeof(struct listen_audio_device));
            calloc(1, sizeof(struct listen_audio_device));


        if (!listen_dev) {
            ALOGE("failed to allocate listen_dev mem");
            return -ENOMEM;
        }

        listen_dev->lib_handle = lib_handle;
        listen_dev->lib_handle = lib_handle;
        listen_dev->adev = adev;
        listen_dev->adev = adev;


+1 −1
Original line number Original line Diff line number Diff line
@@ -294,8 +294,8 @@ static int32_t ssr_init_surround_sound_lib(unsigned long buffersize)
    if ( ret > 0 ) {
    if ( ret > 0 ) {
        ALOGV("%s: Allocating surroundObj size is %d", __func__, ret);
        ALOGV("%s: Allocating surroundObj size is %d", __func__, ret);
        ssrmod.surround_obj = (void *)malloc(ret);
        ssrmod.surround_obj = (void *)malloc(ret);
        memset(ssrmod.surround_obj,0,ret);
        if (NULL != ssrmod.surround_obj) {
        if (NULL != ssrmod.surround_obj) {
            memset(ssrmod.surround_obj,0,ret);
            /* initialize after allocating the memory for surround_obj */
            /* initialize after allocating the memory for surround_obj */
            ret = ssrmod.surround_filters_init(ssrmod.surround_obj,
            ret = ssrmod.surround_filters_init(ssrmod.surround_obj,
                        6,
                        6,
+57 −52
Original line number Original line Diff line number Diff line
@@ -159,12 +159,16 @@ static int usb_get_capability(char *type, int32_t *channels,
    char *buffer;
    char *buffer;
    int32_t err = 1;
    int32_t err = 1;
    int32_t size = 0;
    int32_t size = 0;
    int32_t fd, i, channels_playback;
    int32_t fd=-1, i, channels_playback;
    char *read_buf, *str_start, *channel_start, *rates_str, *rates_str_for_val,
    char *str_start, *channel_start, *rates_str_start, *next_sr_str,
    *rates_str_start, *next_sr_str, *test, *next_sr_string, *temp_ptr;
         *next_sr_string, *temp_ptr;
    struct stat st;
    struct stat st;
    int *rates_supported;
    char *read_buf = NULL;
    char *rates_str = NULL;
    char *rates_str_for_val = NULL;
    int  *rates_supported = NULL;
    char path[128];
    char path[128];
    int ret = 0;


    memset(&st, 0x0, sizeof(struct stat));
    memset(&st, 0x0, sizeof(struct stat));
    *sample_rate = 0;
    *sample_rate = 0;
@@ -175,45 +179,49 @@ static int usb_get_capability(char *type, int32_t *channels,
    if (fd <0) {
    if (fd <0) {
        ALOGE("%s: error failed to open config file %s error: %d\n",
        ALOGE("%s: error failed to open config file %s error: %d\n",
              __func__, path, errno);
              __func__, path, errno);
        close(fd);
        ret = -EINVAL;
        return -EINVAL;
        goto done;
    }
    }


    if (fstat(fd, &st) < 0) {
    if (fstat(fd, &st) < 0) {
        ALOGE("%s: error failed to stat %s error %d\n",
        ALOGE("%s: error failed to stat %s error %d\n",
             __func__, path, errno);
             __func__, path, errno);
        close(fd);
        ret = -EINVAL;
        return -EINVAL;
        goto done;
    }
    }


    file_size = st.st_size;
    file_size = st.st_size;


    read_buf = (char *)calloc(1, USB_BUFF_SIZE + 1);
    read_buf = (char *)calloc(1, USB_BUFF_SIZE + 1);

    if (!read_buf) {
        ALOGE("Failed to create read_buf");
        ret = -ENOMEM;
        goto done;
    }

    err = read(fd, read_buf, USB_BUFF_SIZE);
    err = read(fd, read_buf, USB_BUFF_SIZE);
    str_start = strstr(read_buf, type);
    str_start = strstr(read_buf, type);
    if (str_start == NULL) {
    if (str_start == NULL) {
        ALOGE("%s: error %s section not found in usb config file",
        ALOGE("%s: error %s section not found in usb config file",
               __func__, type);
               __func__, type);
        close(fd);
        ret = -EINVAL;
        free(read_buf);
        goto done;
        return -EINVAL;
    }
    }


    channel_start = strstr(str_start, "Channels:");
    channel_start = strstr(str_start, "Channels:");
    if (channel_start == NULL) {
    if (channel_start == NULL) {
        ALOGE("%s: error could not find Channels information", __func__);
        ALOGE("%s: error could not find Channels information", __func__);
        close(fd);
        ret = -EINVAL;
        free(read_buf);
        goto done;
        return -EINVAL;
    }
    }


    channel_start = strstr(channel_start, " ");
    channel_start = strstr(channel_start, " ");
    if (channel_start == NULL) {
    if (channel_start == NULL) {
        ALOGE("%s: error channel section not found in usb config file",
        ALOGE("%s: error channel section not found in usb config file",
               __func__);
               __func__);
        close(fd);
        ret = -EINVAL;
        free(read_buf);
        goto done;
        return -EINVAL;
    }
    }


    channels_playback = atoi(channel_start);
    channels_playback = atoi(channel_start);
@@ -227,44 +235,38 @@ static int usb_get_capability(char *type, int32_t *channels,
    rates_str_start = strstr(str_start, "Rates:");
    rates_str_start = strstr(str_start, "Rates:");
    if (rates_str_start == NULL) {
    if (rates_str_start == NULL) {
        ALOGE("%s: error cant find rates information", __func__);
        ALOGE("%s: error cant find rates information", __func__);
        close(fd);
        ret = -EINVAL;
        free(read_buf);
        goto done;
        return -EINVAL;
    }
    }


    rates_str_start = strstr(rates_str_start, " ");
    rates_str_start = strstr(rates_str_start, " ");
    if (rates_str_start == NULL) {
    if (rates_str_start == NULL) {
        ALOGE("%s: error channel section not found in usb config file",
        ALOGE("%s: error channel section not found in usb config file",
               __func__);
               __func__);
        close(fd);
        ret = -EINVAL;
        free(read_buf);
        goto done;
        return -EINVAL;
    }
    }


    char *target = strchr(rates_str_start, '\n');
    char *target = strchr(rates_str_start, '\n');
    if (target == NULL) {
    if (target == NULL) {
        ALOGE("%s: error end of line not found", __func__);
        ALOGE("%s: error end of line not found", __func__);
        close(fd);
        ret = -EINVAL;
        free(read_buf);
        goto done;
        return -EINVAL;
    }
    }


    size = target - rates_str_start;
    size = target - rates_str_start;
    if ((rates_str = (char *)malloc(size + 1)) == NULL) {
    if ((rates_str = (char *)malloc(size + 1)) == NULL) {
        ALOGE("%s: error unable to allocate memory to hold sample rate strings",
        ALOGE("%s: error unable to allocate memory to hold sample rate strings",
              __func__);
              __func__);
        close(fd);
        ret = -EINVAL;
        free(read_buf);
        goto done;
        return -ENOMEM;
    }
    }


    if ((rates_str_for_val = (char *)malloc(size + 1)) == NULL) {
    if ((rates_str_for_val = (char *)malloc(size + 1)) == NULL) {
        ALOGE("%s: error unable to allocate memory to hold sample rate string",
        ALOGE("%s: error unable to allocate memory to hold sample rate string",
               __func__);
               __func__);
        close(fd);
        ret = -EINVAL;
        free(rates_str);
        goto done;
        free(read_buf);
        return -ENOMEM;
    }
    }


    memcpy(rates_str, rates_str_start, size);
    memcpy(rates_str, rates_str_start, size);
@@ -275,23 +277,23 @@ static int usb_get_capability(char *type, int32_t *channels,
    size = usb_get_numof_rates(rates_str);
    size = usb_get_numof_rates(rates_str);
    if (!size) {
    if (!size) {
        ALOGE("%s: error could not get rate size, returning", __func__);
        ALOGE("%s: error could not get rate size, returning", __func__);
        close(fd);
        ret = -EINVAL;
        free(rates_str_for_val);
        goto done;
        free(rates_str);
        free(read_buf);
        return -EINVAL;
    }
    }


    rates_supported = (int *)malloc(sizeof(int) * size);
    rates_supported = (int *)malloc(sizeof(int) * size);

    if (!rates_supported) {
        ALOGE("couldn't allocate mem for rates_supported");
        ret = -EINVAL;
        goto done;
    }

    next_sr_string = strtok_r(rates_str_for_val, " ,", &temp_ptr);
    next_sr_string = strtok_r(rates_str_for_val, " ,", &temp_ptr);
    if (next_sr_string == NULL) {
    if (next_sr_string == NULL) {
        ALOGE("%s: error could not get first rate val", __func__);
        ALOGE("%s: error could not get first rate val", __func__);
        close(fd);
        ret = -EINVAL;
        free(rates_str_for_val);
        goto done;
        free(rates_str);
        free(rates_supported);
        free(read_buf);
        return -EINVAL;
    }
    }


    rates_supported[0] = atoi(next_sr_string);
    rates_supported[0] = atoi(next_sr_string);
@@ -299,6 +301,10 @@ static int usb_get_capability(char *type, int32_t *channels,
           __func__, rates_supported[0]);
           __func__, rates_supported[0]);
    for (i = 1; i<size; i++) {
    for (i = 1; i<size; i++) {
        next_sr_string = strtok_r(NULL, " ,.-", &temp_ptr);
        next_sr_string = strtok_r(NULL, " ,.-", &temp_ptr);
        if (next_sr_string == NULL) {
            rates_supported[i] = -1; // fill in an invalid sr for the rest
            continue;
        }
        rates_supported[i] = atoi(next_sr_string);
        rates_supported[i] = atoi(next_sr_string);
        ALOGD("rates_supported[%d] for playback: %d",i, rates_supported[i]);
        ALOGD("rates_supported[%d] for playback: %d",i, rates_supported[i]);
    }
    }
@@ -317,12 +323,13 @@ static int usb_get_capability(char *type, int32_t *channels,
    }
    }
    ALOGD("%s: sample_rate: %d", __func__, *sample_rate);
    ALOGD("%s: sample_rate: %d", __func__, *sample_rate);


    close(fd);
done:
    free(rates_str_for_val);
    if (fd >= 0) close(fd);
    free(rates_str);
    if (rates_str_for_val) free(rates_str_for_val);
    free(rates_supported);
    if (rates_str) free(rates_str);
    free(read_buf);
    if (rates_supported) free(rates_supported);
    return 0;
    if (read_buf) free(read_buf);
    return ret;
}
}


static int32_t usb_playback_entry(void *adev)
static int32_t usb_playback_entry(void *adev)
@@ -387,7 +394,6 @@ static int32_t usb_playback_entry(void *adev)
        if(usbmod->proxy_pcm_playback_handle
        if(usbmod->proxy_pcm_playback_handle
            && !pcm_is_ready(usbmod->proxy_pcm_playback_handle)){
            && !pcm_is_ready(usbmod->proxy_pcm_playback_handle)){
                     pcm_close(usbmod->proxy_pcm_playback_handle);
                     pcm_close(usbmod->proxy_pcm_playback_handle);
                     usbmod->proxy_pcm_playback_handle = NULL;
                     proxy_open_retry_count--;
                     proxy_open_retry_count--;
                     usleep(USB_PROXY_OPEN_WAIT_TIME * 1000);
                     usleep(USB_PROXY_OPEN_WAIT_TIME * 1000);
                     ALOGE("%s: pcm_open for proxy failed retrying = %d",
                     ALOGE("%s: pcm_open for proxy failed retrying = %d",
@@ -507,7 +513,6 @@ static int32_t usb_record_entry(void *adev)
        if(usbmod->proxy_pcm_record_handle
        if(usbmod->proxy_pcm_record_handle
            && !pcm_is_ready(usbmod->proxy_pcm_record_handle)){
            && !pcm_is_ready(usbmod->proxy_pcm_record_handle)){
                     pcm_close(usbmod->proxy_pcm_record_handle);
                     pcm_close(usbmod->proxy_pcm_record_handle);
                     usbmod->proxy_pcm_record_handle = NULL;
                     proxy_open_retry_count--;
                     proxy_open_retry_count--;
                     usleep(USB_PROXY_OPEN_WAIT_TIME * 1000);
                     usleep(USB_PROXY_OPEN_WAIT_TIME * 1000);
                     ALOGE("%s: pcm_open for proxy(recording) failed retrying = %d",
                     ALOGE("%s: pcm_open for proxy(recording) failed retrying = %d",
Loading