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

Commit 1d519c60 authored by Lakshman Chaluvaraju's avatar Lakshman Chaluvaraju Committed by Garmond Leung
Browse files

audio-hal: hal_play_test: Add changes to unload qap libs in session close

Change-Id: I8e5b24caff1ff246ebf3a75ad5c941084b99bbb8
parent e75e9f64
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -2337,7 +2337,6 @@ int main(int argc, char* argv[]) {

    if (is_qap_session_active(argc, argv, kvp_string)) {
        char *file_name = NULL;
        char *file_name_tmp = NULL;
        char *cmd_kvp_str[100] = {NULL};
        char *play_list_kvp_str[100] = {NULL};
        int i = 0, j = 0;
+46 −33
Original line number Diff line number Diff line
@@ -114,7 +114,8 @@ double data_input_st_arr[TIMESTAMP_ARRAY_SIZE];
double data_callback_st_arr[TIMESTAMP_ARRAY_SIZE];
bool has_system_input = false;
char session_kv_pairs[256];
bool stream_close = false;
bool primary_stream_close = false;
uint8_t stream_cnt = 0;
uint32_t dsp_latency = 0;

static int get_qap_out_config_index_for_id(int32_t out_id)
@@ -320,8 +321,7 @@ char* check_for_playlist(char *kvp_string) {
    if (tmp_str != NULL) {
        file_str = strstr(kvp_string, ".txt");
        len = file_str - tmp_str;
        play_list = (char*) malloc(sizeof(char) * (len+4));
        memset(play_list, '\0', len+4);
        play_list = (char*) calloc(1, sizeof(char) * (len+4));
        strncpy(play_list, tmp_str+2, len+2);
    }
    return play_list;
@@ -392,13 +392,13 @@ int start_playback_through_qap_playlist(char *cmd_kvp_str[], int num_of_streams,
            }
        }
        i++;
        while (!stream_close) {
        while (!primary_stream_close) {
            usleep(50000);
            fprintf(stderr, "QAP Stream not closed\n");
        }
        fprintf(stderr, "QAP Stream closed\n");
    } while (i <num_of_streams);
    if (broad_cast && qap_wrapper_session_active) {
    if (qap_wrapper_session_active) {
        qap_wrapper_session_close();
        qap_wrapper_session_active = false;
    }
@@ -427,8 +427,7 @@ char *qap_wrapper_get_single_kvp(const char *key, const char *kv_pairs, int *sta
        if (temp_kvp != NULL) {
            temp_key = strtok_r(temp_kvp, "=", &context2);
            if (!strncmp(key, temp_key, strlen(key))) {
                kvp = malloc((strlen(token) + 1) * sizeof(char));
                memset(kvp, 0, strlen(token) + 1);
                kvp = calloc(1, (strlen(token) + 1) * sizeof(char));
                strncat(kvp, token, strlen(token));
                return kvp;
            }
@@ -441,8 +440,7 @@ char *qap_wrapper_get_single_kvp(const char *key, const char *kv_pairs, int *sta
                if (temp_kvp != NULL) {
                    temp_key = strtok_r(temp_kvp, "=", &context2);
                    if (!strncmp(key, temp_key, strlen(key))) {
                        kvp = malloc((strlen(token) + 1) * sizeof(char));
                        memset(kvp, 0, strlen(token) + 1);
                        kvp = calloc(1, (strlen(token) + 1) * sizeof(char));
                        strncat(kvp, token, strlen(token));
                        return kvp;
                    }
@@ -488,7 +486,7 @@ int *qap_wrapper_get_int_value_array(const char *kvp, int *count, int *status __
            for (i=0; s[i]; s[i]==',' ? i++ : *s++);

            temp = i;
            val = malloc((i + 1)*sizeof(int));
            val = calloc(1, (i + 1)*sizeof(int));
            i = 0;
            val[i++] = strtol(tempstr2, &endstr, 0);

@@ -690,7 +688,7 @@ static void close_output_streams()
            fprintf(stderr, "%s::%d: could not close output stream, error - %d\n", __func__, __LINE__, ret);
        qap_out_hdmi_handle = NULL;
    }
    stream_close = true;
    primary_stream_close = true;
}

void qap_wrapper_session_callback(qap_session_handle_t session_handle __unused, void* priv_data __unused, qap_callback_event_t event_id, int size __unused, void *data)
@@ -707,12 +705,13 @@ void qap_wrapper_session_callback(qap_session_handle_t session_handle __unused,
    switch (event_id) {
        case QAP_CALLBACK_EVENT_EOS:
            ALOGV("%s %d Received Main Input EOS", __func__, __LINE__);
            stream_cnt --;
            pthread_mutex_lock(&main_eos_lock);
            pthread_cond_signal(&main_eos_cond);
            pthread_mutex_unlock(&main_eos_lock);

            ALOGE("%s %d Received Main Input EOS ", __func__, __LINE__);
            if (!stream_close)
            if (!stream_cnt)
                close_output_streams();
            if (play_list_cnt && input_streams_count) {
                play_list_cnt--;
@@ -721,12 +720,15 @@ void qap_wrapper_session_callback(qap_session_handle_t session_handle __unused,
            break;
        case QAP_CALLBACK_EVENT_EOS_ASSOC:
        case QAP_CALLBACK_EVENT_MAIN_2_EOS:
            stream_cnt --;
            if (!has_system_input){
                ALOGV("%s %d Received Secondary Input EOS", __func__, __LINE__);
                pthread_mutex_lock(&sec_eos_lock);
                pthread_cond_signal(&sec_eos_cond);
                pthread_mutex_unlock(&sec_eos_lock);
            }
            if (!stream_cnt)
                close_output_streams();
            break;
        case QAP_CALLBACK_EVENT_ERROR:
            break;
@@ -1162,7 +1164,7 @@ int qap_wrapper_session_open(char *kv_pairs, void* stream_data, int num_of_strea
        }
    }

    if (stream->filetype == FILE_DTS) {
    if (stream->filetype == FILE_DTS && (NULL == m8_lib_handle)) {
        m8_lib_handle = (qap_session_handle_t) qap_load_library(QAC_LIB_M8);
        if (m8_lib_handle == NULL) {
            fprintf(stdout, "Failed to load M8 library\n");
@@ -1176,7 +1178,7 @@ int qap_wrapper_session_open(char *kv_pairs, void* stream_data, int num_of_strea
                (stream->filetype == FILE_WAV) ||
                (stream->filetype == FILE_AAC) ||
                (stream->filetype == FILE_AAC_ADTS) ||
                (stream->filetype == FILE_AAC_LATM)) {
                (stream->filetype == FILE_AAC_LATM) && (NULL == ms12_lib_handle)) {
        ms12_lib_handle = (qap_session_handle_t) qap_load_library(QAC_LIB_MS12);
        if (ms12_lib_handle == NULL) {
            fprintf(stderr, "Failed to load MS12 library\n");
@@ -1307,6 +1309,16 @@ int qap_wrapper_session_close ()
    session_output_configured = false;
    qap_session_close(qap_session_handle);
    qap_session_handle = NULL;
    if (stream_cnt == 0) {
        if (NULL != m8_lib_handle) {
            qap_unload_library(m8_lib_handle);
            m8_lib_handle = NULL;
        }
        if (NULL != ms12_lib_handle) {
            qap_unload_library(ms12_lib_handle);
            ms12_lib_handle = NULL;
        }
    }
}

void *qap_wrapper_start_stream (void* stream_data)
@@ -1572,7 +1584,8 @@ qap_module_handle_t qap_wrapper_stream_open(void* stream_data)
        return NULL;
    }

    stream_close = false;
    primary_stream_close = false;
    stream_cnt ++;
    return qap_module_handle;

}
@@ -1580,33 +1593,27 @@ void get_play_list(FILE *fp, stream_config (*stream_param)[], int *num_of_stream
{
    char *token = NULL;
    char *strings[100] = {NULL};
    char cmd_str[500] = {0};
    char cmd_str[1024] = {0};
    char *tmp_str = NULL;
    int i = 0;

    do {
        int j = 0, cnt = 1, status = 0;
        int j = 0, cnt = 0, status = 0;

        if (fgets(cmd_str, sizeof(cmd_str), fp) != NULL)
            tmp_str = strdup(cmd_str);
        else
            break;
        fprintf(stdout, "%s %d\n", __FUNCTION__, __LINE__);
        fprintf(stdout, "%s %d tmp_str is %s", __FUNCTION__, __LINE__, tmp_str);
        token = strtok(tmp_str, " ");
        if (NULL != token) {
            strings[cnt] = (char*)calloc(1, (strlen(token) +1));
            memset(strings[cnt], '\0', strlen(token) +1);
            strncpy(strings[cnt], token, strlen(token));
            cnt++;
            strings[cnt++] = strdup("playlist");
            strings[cnt++] = strdup(token);
            while (NULL != (token = strtok(NULL, " "))) {
                strings[cnt] = (char*)calloc(1, (strlen(token) +1));
                memset(strings[cnt], '\0', strlen(token) +1);
                strncpy(strings[cnt], token, strlen(token));
                strings[cnt] = strdup(token);
                ALOGV("%s %d strings[%d] is %s", __FUNCTION__, __LINE__, cnt, strings[cnt]);
                cnt++;
            }
            strings[0] = calloc(1, 4);
            memset(strings[0], '\0', 4);
            strncpy(strings[0], "play_list", 3);
            for (j = 0;j< cnt;j++) {
                if (!strncmp(strings[j], "-f", 2)) {
                   (*stream_param)[i].filename = strdup(strings[j+1]);
@@ -1626,15 +1633,21 @@ void get_play_list(FILE *fp, stream_config (*stream_param)[], int *num_of_stream
                    (*stream_param)[i].aac_fmt_type = atoi(strings[j+1]);
                }
            }
            free(tmp_str);
            tmp_str = NULL;
        }
        if(NULL != (*stream_param)[i].filename) {
            *num_of_streams = i+1;
            play_list = true;
            kvp_str[i] = (char *)qap_wrapper_get_cmd_string_from_arg_array(cnt, (char**)strings, &status);
            kvp_str[i] = (char *)qap_wrapper_get_cmd_string_from_arg_array(cnt, strings, &status);
            ALOGV("%s %d kvp_str[%d] is %s", __FUNCTION__, __LINE__, i, kvp_str[i]);
        }
        free(tmp_str);
        for (j=0; j < cnt; j++)
        for (j=0; j < cnt; j++) {
           if (NULL != strings[j]){
               free(strings[j]);
               strings[j] = NULL;
           }
        }
        i++;
    }while(NULL != cmd_str);