Fix player bug 45/17845/1
authorKwangyoun Kim <ky85.kim@samsung.com>
Fri, 21 Jun 2013 06:02:51 +0000 (15:02 +0900)
committerLee Dongyeol <dy3.lee@samsung.com>
Tue, 11 Mar 2014 10:56:23 +0000 (19:56 +0900)
Change-Id: Iefd81ba8a54a18d84a29bb6fe7c10f8ea3723492

server/ttsd_player.c
server/ttsd_player.h

index c1a2768..d3552cf 100644 (file)
@@ -52,6 +52,7 @@ typedef struct {
        MMHandleType    player_handle;  /** mm player handle */
        int             utt_id;         /** utt_id of next file */
        ttsp_result_event_e event;      /** event of callback */
+       bool            pause_after_complete;   /** For resume when the 'Paused' state of player after end callback */
 } player_s;
 
 typedef struct {
@@ -85,14 +86,9 @@ static player_result_callback_func g_result_callback;
 /** numbering for temp file */
 static unsigned int g_index;              
 
-/** For resume when the 'Paused' state of player after end of play */
-static bool g_pause_info;
-static int g_paused_uid;
-
 /*
 * Internal Interfaces 
 */
-
 player_s* __player_get_item(int uid);
 
 int __save_file(int uid, int index, sound_data_s data, char** filename);
@@ -156,7 +152,7 @@ int ttsd_player_create_instance(int uid)
        
        /* Check uid is duplicated */
        if (NULL != __player_get_item(uid)) {
-               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is already registered", uid); 
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is already registered", uid); 
                return -1;
        }
 
@@ -175,8 +171,9 @@ int ttsd_player_create_instance(int uid)
        new_client->player_handle = player_handle;
        new_client->utt_id = -1;
        new_client->event = TTSP_RESULT_EVENT_FINISH;
+       new_client->pause_after_complete = false;
        
-       SLOG(LOG_DEBUG, get_tag(), "[Player] Create player : uid(%d), handle(%d)", uid, player_handle );
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Player] Create player : uid(%d), handle(%d)", uid, player_handle );
 
        g_player_list = g_list_append(g_player_list, new_client);
 
@@ -193,7 +190,7 @@ int ttsd_player_destroy_instance(int uid)
        player_s* current;
        current = __player_get_item(uid);
        if (NULL == current) {
-               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); 
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); 
                return -1;
        }
 
@@ -263,7 +260,7 @@ int ttsd_player_destroy_instance(int uid)
 
 int ttsd_player_play(int uid)
 {
-       SLOG(LOG_DEBUG, get_tag(), "[Player] start play : uid(%d)", uid );
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Player] start play : uid(%d)", uid );
 
        if (false == g_player_init) {
                SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized" );
@@ -272,14 +269,14 @@ int ttsd_player_play(int uid)
 
        if (NULL != g_playing_info) {
                if (uid == g_playing_info->uid) {
-                       SLOG(LOG_WARN, get_tag(), "[Player WARNING] uid(%d) has already played", g_playing_info->uid); 
+                       SECURE_SLOG(LOG_WARN, get_tag(), "[Player WARNING] uid(%d) has already played", g_playing_info->uid); 
                        return 0;
                }
        }
 
        /* Check sound queue size */
        if (0 == ttsd_data_get_sound_data_size(uid)) {
-               SLOG(LOG_WARN, get_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid); 
+               SECURE_SLOG(LOG_WARN, get_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid); 
                return -1;
        }
 
@@ -287,7 +284,7 @@ int ttsd_player_play(int uid)
        player_s* current;
        current = __player_get_item(uid);
        if (NULL == current) {
-               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); 
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); 
                return -1;
        }
 
@@ -326,12 +323,12 @@ int ttsd_player_play(int uid)
                SLOG(LOG_ERROR, get_tag(), "[Player ERROR] fail to set or start mm_player");
        }
 
-       SLOG(LOG_DEBUG, get_tag(), "[Player] Started play and wait for played callback : uid(%d)", uid);
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Player] Started play and wait for played callback : uid(%d)", uid);
 
        return 0;
 }
 
-int ttsd_player_next_play(int uid)
+int __ttsd_player_next_play(int uid)
 {
        if (false == g_player_init) {
                SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized" );
@@ -342,14 +339,14 @@ int ttsd_player_next_play(int uid)
        player_s* current;
        current = __player_get_item(uid);
        if (NULL == current) {
-               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); 
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); 
                g_playing_info = NULL;
                return -1;
        }
 
        if (NULL != g_playing_info) {
                if (uid != g_playing_info->uid) {
-                       SLOG(LOG_WARN, get_tag(), "[Player WARNING] Current player(%d) is NOT uid(%d)", g_playing_info->uid, uid); 
+                       SECURE_SLOG(LOG_WARN, get_tag(), "[Player WARNING] Current player(%d) is NOT uid(%d)", g_playing_info->uid, uid); 
                        return 0;
                }
        } else {
@@ -384,7 +381,7 @@ int ttsd_player_next_play(int uid)
 
        /* Check sound queue size */
        if (0 == ttsd_data_get_sound_data_size(uid)) {
-               SLOG(LOG_WARN, get_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid); 
+               SECURE_SLOG(LOG_WARN, get_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid); 
                g_playing_info = NULL;
                return -1;
        }
@@ -394,7 +391,7 @@ int ttsd_player_next_play(int uid)
                SLOG(LOG_ERROR, get_tag(), "[Player ERROR] fail to set or start mm_player");
        }
 
-       SLOG(LOG_DEBUG, get_tag(), "[Player] Started play and wait for played callback : uid(%d)", uid);
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Player] Started play and wait for played callback : uid(%d)", uid);
 
        return 0;
 }
@@ -402,7 +399,7 @@ int ttsd_player_next_play(int uid)
 
 int ttsd_player_stop(int uid)
 {
-       SLOG(LOG_DEBUG, get_tag(), "[Player] stop player : uid(%d)", uid );
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Player] stop player : uid(%d)", uid );
 
        if (false == g_player_init) {
                SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized" );
@@ -413,7 +410,7 @@ int ttsd_player_stop(int uid)
        player_s* current;
        current = __player_get_item(uid);
        if (NULL == current) {
-               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); 
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); 
                return -1;
        }
 
@@ -428,6 +425,7 @@ int ttsd_player_stop(int uid)
        }
 
        current->utt_id = -1;
+       current->pause_after_complete = false;
 
        MMPlayerStateType player_state;
        mm_player_get_state(current->player_handle, &player_state);
@@ -453,14 +451,14 @@ int ttsd_player_stop(int uid)
                        break;
        }
 
-       SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Stop player : uid(%d)", uid);
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Stop player : uid(%d)", uid);
 
        return 0;
 }
 
 int ttsd_player_pause(int uid)
 {
-       SLOG(LOG_DEBUG, get_tag(), "[Player] pause player : uid(%d)", uid );
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Player] pause player : uid(%d)", uid );
 
        if (false == g_player_init) {
                SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized" );
@@ -471,7 +469,7 @@ int ttsd_player_pause(int uid)
        player_s* current;
        current = __player_get_item(uid);
        if (NULL == current) {
-               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] ttsd_player_pause() : uid(%d) is not valid", uid); 
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] ttsd_player_pause() : uid(%d) is not valid", uid); 
                return -1;
        }
 
@@ -506,7 +504,7 @@ int ttsd_player_pause(int uid)
 
 int ttsd_player_resume(int uid)
 {
-       SLOG(LOG_DEBUG, get_tag(), "[Player] Resume player : uid(%d)", uid );
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Player] Resume player : uid(%d)", uid );
 
        if (false == g_player_init) {
                SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized" );
@@ -517,12 +515,12 @@ int ttsd_player_resume(int uid)
        player_s* current;
        current = __player_get_item(uid);
        if (NULL == current) {
-               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); 
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); 
                return -1;
        }
 
        /* check current player */
-       if (NULL != g_playing_info) 
+       if (NULL != g_playing_info)
                g_playing_info = NULL;
 
        
@@ -534,14 +532,13 @@ int ttsd_player_resume(int uid)
        int ret = -1;
        if (MM_PLAYER_STATE_PAUSED == player_state) {
                /* When the 'Paused' state of player after end of play */
-               if (g_pause_info == true && g_paused_uid == uid) {
+               if (true == current->pause_after_complete) {
                        g_playing_info = current;
 
-                       g_pause_info = false;
-                       g_paused_uid = -1;
+                       current->pause_after_complete = false;
                        
                        /* Current state need load and play */
-                       ret = ttsd_player_next_play(uid);
+                       ret = __ttsd_player_next_play(uid);
                        if (0 != ret) {
                                SLOG(LOG_ERROR, get_tag(), "[player] Fail to next play in resume function");
                        }
@@ -573,7 +570,7 @@ int ttsd_player_get_state(int uid, ttsd_player_state_e* state)
        player_s* current;
        current = __player_get_item(uid);
        if (NULL == current) {
-               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); 
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); 
                return -1;
        }
 
@@ -597,7 +594,7 @@ int ttsd_player_get_state(int uid, ttsd_player_state_e* state)
 
                case MM_PLAYER_STATE_READY:
                default:
-                       SLOG(LOG_ERROR, get_tag(), "[Player ERROR] player state of uid(%d) is not valid", uid); 
+                       SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] player state of uid(%d) is not valid", uid); 
                        return -1;
                        break;
        }
@@ -622,7 +619,7 @@ int ttsd_player_get_current_client()
 
 int ttsd_player_get_current_utterance_id(int uid)
 {
-       SLOG(LOG_DEBUG, get_tag(), "[Player] get current utt id : uid(%d)", uid );
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Player] get current utt id : uid(%d)", uid );
 
        if (false == g_player_init) {
                SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized" );
@@ -633,7 +630,7 @@ int ttsd_player_get_current_utterance_id(int uid)
        player_s* current;
        current = __player_get_item(uid);
        if (NULL == current) {
-               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); 
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid); 
                return -1;
        }
 
@@ -703,9 +700,9 @@ static Eina_Bool __player_next_play(void *data)
                return EINA_FALSE;
        }
 
-       SLOG(LOG_DEBUG, get_tag(), "[PLAYER] uid = %d", *uid);
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "[PLAYER] uid = %d", *uid);
        
-       if (0 != ttsd_player_next_play(*uid)) {
+       if (0 != __ttsd_player_next_play(*uid)) {
                SLOG(LOG_WARN, get_tag(), "[PLAYER WARNING] Fail to play next");
        }
 
@@ -737,7 +734,7 @@ static int msg_callback(int message, void *data, void *user_param)
        case MM_MESSAGE_ERROR:
                {
                        SLOG(LOG_DEBUG, get_tag(), "===== PLAYER ERROR CALLBACK");
-                       SLOG(LOG_ERROR, get_tag(), "[PLAYER ERROR] Info : uid(%d), utt id(%d), error file(%s)", uid, utt_id, user_data->filename);
+                       SECURE_SLOG(LOG_ERROR, get_tag(), "[PLAYER ERROR] Info : uid(%d), utt id(%d), error file(%s)", uid, utt_id, user_data->filename);
 
                        /* send error info */
                        g_result_callback(PLAYER_ERROR, uid, utt_id);
@@ -745,7 +742,7 @@ static int msg_callback(int message, void *data, void *user_param)
                        player_s* current;
                        current = __player_get_item(uid);
                        if (NULL == current) {
-                               SLOG(LOG_ERROR, get_tag(), "[PLAYER ERROR] uid(%d) is NOT valid ", uid); 
+                               SECURE_SLOG(LOG_ERROR, get_tag(), "[PLAYER ERROR] uid(%d) is NOT valid ", uid); 
                        } else {
                                current->event = TTSP_RESULT_EVENT_FINISH;
                        }
@@ -757,7 +754,7 @@ static int msg_callback(int message, void *data, void *user_param)
                        if (NULL != g_playing_info) {
                                if (uid == g_playing_info->uid) {
                                        g_playing_info = NULL;
-                                       SLOG(LOG_WARN, get_tag(), "[PLAYER] Current Player is NOT uid(%d)", uid);
+                                       SECURE_SLOG(LOG_WARN, get_tag(), "[PLAYER] Current Player is NOT uid(%d)", uid);
                                }
                        }
 
@@ -775,18 +772,18 @@ static int msg_callback(int message, void *data, void *user_param)
                        SLOG(LOG_DEBUG, get_tag(), "===== END OF STREAM CALLBACK");
 
                        if (-1 == remove(user_data->filename)) {
-                               SLOG(LOG_WARN, get_tag(), "[PLAYER WARNING] Fail to remove temp file", user_data->filename); 
+                               SECURE_SLOG(LOG_WARN, get_tag(), "[PLAYER WARNING] Fail to remove temp file", user_data->filename); 
                        }
 
                        /* Check uid */
                        player_s* current;
                        current = __player_get_item(uid);
                        if (NULL == current) {
-                               SLOG(LOG_ERROR, get_tag(), "[PLAYER ERROR] uid(%d) is NOT valid", uid); 
+                               SECURE_SLOG(LOG_ERROR, get_tag(), "[PLAYER ERROR] uid(%d) is NOT valid", uid); 
                                if (NULL != g_playing_info) {
                                        if (uid == g_playing_info->uid) {
                                                g_playing_info = NULL;
-                                               SLOG(LOG_WARN, get_tag(), "[PLAYER] Current Player is NOT uid(%d)", uid);
+                                               SECURE_SLOG(LOG_WARN, get_tag(), "[PLAYER] Current Player is NOT uid(%d)", uid);
                                        }
                                }
                                SLOG(LOG_DEBUG, get_tag(), "=====");
@@ -801,9 +798,9 @@ static int msg_callback(int message, void *data, void *user_param)
                        /* send utterence finish signal */
                        if (TTSP_RESULT_EVENT_FINISH == current->event) {
                                if (0 == ttsdc_send_utt_finish_message(pid, uid, utt_id))
-                                       SLOG(LOG_DEBUG, get_tag(), "[Send SUCCESS] Send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)", pid, uid, utt_id);
+                                       SECURE_SLOG(LOG_DEBUG, get_tag(), "[Send SUCCESS] Send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)", pid, uid, utt_id);
                                else 
-                                       SLOG(LOG_ERROR, get_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)", pid, uid, utt_id);
+                                       SECURE_SLOG(LOG_ERROR, get_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)", pid, uid, utt_id);
                        }
 
                        /* for sync problem */
@@ -811,14 +808,14 @@ static int msg_callback(int message, void *data, void *user_param)
                        mm_player_get_state(current->player_handle, &player_state);
                        
                        if (MM_PLAYER_STATE_PAUSED == player_state) {
-                               g_pause_info = true;    /* The current state of player is 'Paused' */
-                               g_paused_uid = uid;     /* The current uid when the current state player is 'Paused' */
+                               /* The current state of player is 'Paused' */
+                               current->pause_after_complete = true;
                        } else {
                                /* play state */
                                int* uid_data = (int*) g_malloc0(sizeof(int));
                                *uid_data = uid;
 
-                               SLOG(LOG_DEBUG, get_tag(), "[PLAYER] uid = %d", *uid_data);
+                               SECURE_SLOG(LOG_DEBUG, get_tag(), "[PLAYER] uid = %d", *uid_data);
 
                                ecore_timer_add(0, __player_next_play, (void*)uid_data);
                        }
@@ -896,7 +893,7 @@ int __save_file(int uid, int index, sound_data_s data, char** filename)
                strcpy(postfix, "amr");
                break;
        default:
-               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Audio type(%d) is NOT valid", data.audio_type); 
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Audio type(%d) is NOT valid", data.audio_type); 
                return -1;
        }
 
@@ -960,8 +957,8 @@ int __save_file(int uid, int index, sound_data_s data, char** filename)
        *filename = temp;
        
        SLOG(LOG_DEBUG, get_tag(), " ");
-       SLOG(LOG_DEBUG, get_tag(), "Filepath : %s ", *filename);
-       SLOG(LOG_DEBUG, get_tag(), "Header : Data size(%d), Sample rate(%d), Channel(%d) ", data.data_size, data.rate, data.channels);
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "Filepath : %s ", *filename);
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "Header : Data size(%d), Sample rate(%d), Channel(%d) ", data.data_size, data.rate, data.channels);
 
        return 0;
 }
@@ -970,10 +967,10 @@ int __init_wave_header (WavHeader* hdr, size_t nsamples, size_t sampling_rate, i
 {
        if (hdr == NULL || sampling_rate <= 0 || channel <= 0) {
                SLOG(LOG_ERROR, get_tag(), "[Player ERROR] __init_wave_header : input parameter invalid");
-               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] hdr : %p", hdr);
-               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] nsample : %d", nsamples);
-               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] sampling_rate : %", sampling_rate);
-               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] channel : %", channel);
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] hdr : %p", hdr);
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] nsample : %d", nsamples);
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] sampling_rate : %", sampling_rate);
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] channel : %", channel);
                return TTSD_ERROR_INVALID_PARAMETER;
        }
 
@@ -1006,7 +1003,7 @@ int __set_and_start(player_s* player)
        /* get sound data */
        sound_data_s wdata;
        if (0 != ttsd_data_get_sound_data(player->uid, &wdata)) {
-               SLOG(LOG_WARN, get_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", player->uid); 
+               SECURE_SLOG(LOG_WARN, get_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", player->uid); 
                return -1;
        }
 
@@ -1032,7 +1029,7 @@ int __set_and_start(player_s* player)
        memset(user_data->filename, 0, TEMP_FILE_MAX); 
        strncpy( user_data->filename, sound_file, strlen(sound_file) );
 
-       SLOG(LOG_DEBUG, get_tag(), "Info : uid(%d), utt(%d), filename(%s) , event(%d)", 
+       SECURE_SLOG(LOG_DEBUG, get_tag(), "Info : uid(%d), utt(%d), filename(%s) , event(%d)", 
                user_data->uid, user_data->utt_id, user_data->filename, user_data->event);
        SLOG(LOG_DEBUG, get_tag(), " ");
 
@@ -1048,7 +1045,7 @@ int __set_and_start(player_s* player)
        char* err_attr_name = NULL;
 
        if (0 != access(sound_file, R_OK)) {
-               SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to read sound file (%s)", sound_file);
+               SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to read sound file (%s)", sound_file);
                return -1;
        }
        
@@ -1099,7 +1096,7 @@ int __set_and_start(player_s* player)
 
                /* send utterance start message */
                if (0 != ttsdc_send_utt_start_message(pid, player->uid, wdata.utt_id)) {
-                       SLOG(LOG_ERROR, get_tag(), "[Send ERROR] Fail to send Utterance Start Signal : pid(%d), uid(%d), uttid(%d)", pid, player->uid, wdata.utt_id);
+                       SECURE_SLOG(LOG_ERROR, get_tag(), "[Send ERROR] Fail to send Utterance Start Signal : pid(%d), uid(%d), uttid(%d)", pid, player->uid, wdata.utt_id);
                }
        } else {
                SLOG(LOG_DEBUG, get_tag(), "[PLAYER] Don't need to send Utterance Start Signal");
index cc8d2f1..fb73bb5 100644 (file)
@@ -47,8 +47,6 @@ int ttsd_player_destroy_instance(int uid);
 
 int ttsd_player_play(int uid);
 
-int ttsd_player_next_play(int uid);
-
 int ttsd_player_stop(int uid);
 
 int ttsd_player_pause(int uid);