check return value from vconf
[platform/core/uifw/tts.git] / server / ttsd_player.c
index a2d2e26..20a9eb4 100644 (file)
@@ -428,17 +428,6 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                        if (0 != ret || NULL == sound_data) {
                                /* empty queue */
                                SLOG(LOG_DEBUG, tts_tag(), "[Player] No sound data. Waiting mode");
-                               /* release audio & recover session */
-                               ret = audio_out_unprepare(g_audio_h);
-                               if (AUDIO_IO_ERROR_NONE != ret) {
-                                       SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
-                               } else {
-                                       SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
-                               }
-                               g_audio_state = AUDIO_STATE_READY;
-
-                               /* unset volume policy, volume will be 100% */
-                               __unset_policy_for_playing();
 
                                /* wait for new audio data come */
                                while (1) {
@@ -446,18 +435,49 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                        if (NULL == g_playing_info) {
                                                /* current playing uid is replaced */
                                                SLOG(LOG_INFO, tts_tag(), "[Player] Finish thread");
+                                               if (AUDIO_STATE_PLAY == g_audio_state) {
+                                                       /* release audio & recover session */
+                                                       ret = audio_out_unprepare(g_audio_h);
+                                                       if (AUDIO_IO_ERROR_NONE != ret) {
+                                                               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
+                                                       } else {
+                                                               SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
+                                                       }
+                                                       g_audio_state = AUDIO_STATE_READY;
+                                               }
+                                               /* unset volume policy, volume will be 100% */
+                                               __unset_policy_for_playing();
                                                return;
                                        } else if (0 < ttsd_data_get_sound_data_size(player->uid)) {
                                                /* new audio data come */
                                                SLOG(LOG_INFO, tts_tag(), "[Player] Resume thread");
                                                break;
                                        }
+
+                                       /* If engine is not on processing */
+                                       if (TTSD_SYNTHESIS_CONTROL_DOING != ttsd_get_synth_control()) {
+                                               if (AUDIO_STATE_PLAY == g_audio_state) {
+                                                       /* release audio & recover session */
+                                                       ret = audio_out_unprepare(g_audio_h);
+                                                       if (AUDIO_IO_ERROR_NONE != ret) {
+                                                               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
+                                                       } else {
+                                                               SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
+                                                       }
+                                                       g_audio_state = AUDIO_STATE_READY;
+
+                                                       /* unset volume policy, volume will be 100% */
+                                                       __unset_policy_for_playing();
+                                               }
+                                       }
                                }
 
                                SLOG(LOG_INFO, tts_tag(), "[Player] Finish to wait for new audio data come");
 
-                               /* set volume policy as 40%, when resume play thread*/
-                               __set_policy_for_playing(40);
+                               if (AUDIO_STATE_READY == g_audio_state) {
+                                       /* set volume policy as 40%, when resume play thread*/
+                                       __set_policy_for_playing(40);
+                               }
 
                                /* resume play thread */
                                player->state = APP_STATE_PLAYING;
@@ -478,7 +498,6 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                        /* unset volume policy, volume will be 100% */
                                        __unset_policy_for_playing();
 
-                                       ttsd_data_clear_sound_data(&sound_data);
                                        return;
                                }
 
@@ -503,7 +522,6 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                                SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
                                                /* unset volume policy, volume will be 100% */
                                                __unset_policy_for_playing();
-                                               ttsd_data_clear_sound_data(&sound_data);
                                                return;
                                        }
                                        if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
@@ -512,7 +530,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                        }
                                }
                                SLOG(LOG_INFO, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
-                               ttsd_data_clear_sound_data(&sound_data);
+                               ttsd_data_clear_sound_data(player->uid, &sound_data);
                                continue;
                        }
                }
@@ -528,7 +546,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                /* unset volume policy, volume will be 100% */
                                __unset_policy_for_playing();
 
-                               ttsd_data_clear_sound_data(&sound_data);
+                               ttsd_data_clear_sound_data(player->uid, &sound_data);
 
                                return;
                        }
@@ -555,7 +573,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                        /* unset volume policy, volume will be 100% */
                                        __unset_policy_for_playing();
 
-                                       ttsd_data_clear_sound_data(&sound_data);
+                                       ttsd_data_clear_sound_data(player->uid, &sound_data);
 
                                        return;
                                }
@@ -564,11 +582,14 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                        }
 
                        char* temp_data = sound_data->data;
+                       SLOG(LOG_INFO, tts_tag(), "[Player INFO] Before audio_out_write. data(%p), data[%d](%p), uid(%d), utt_id(%d), len(%d)",
+                                       temp_data, idx, &temp_data[idx], player->uid, sound_data->utt_id, len);
                        ret = audio_out_write(g_audio_h, &temp_data[idx], len);
                        if (0 > ret) {
                                SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to audio write - %d", ret);
                        } else {
                                idx += len;
+                               SLOG(LOG_INFO, tts_tag(), "[Player INFO] After audio_out_write");
                        }
 
                        if (NULL == g_playing_info && APP_STATE_PAUSED != player->state) {
@@ -581,7 +602,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                /* unset volume policy, volume will be 100% */
                                __unset_policy_for_playing();
 
-                               ttsd_data_clear_sound_data(&sound_data);
+                               ttsd_data_clear_sound_data(player->uid, &sound_data);
 
                                return;
                        }
@@ -622,7 +643,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
                        }
 
-                       ttsd_data_clear_sound_data(&sound_data);
+                       ttsd_data_clear_sound_data(player->uid, &sound_data);
                        /* unset volume policy, volume will be 100% */
                        __unset_policy_for_playing();
                        return;
@@ -638,7 +659,6 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                /* unset volume policy, volume will be 100% */
                                __unset_policy_for_playing();
 
-                               ttsd_data_clear_sound_data(&sound_data);
                                return;
                        }
 
@@ -648,14 +668,14 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                /* unset volume policy, volume will be 100% */
                                __unset_policy_for_playing();
 
-                               ttsd_data_clear_sound_data(&sound_data);
+                               ttsd_data_clear_sound_data(player->uid, &sound_data);
                                return;
                        }
 
                        SLOG(LOG_INFO, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
                }
 
-               ttsd_data_clear_sound_data(&sound_data);
+               ttsd_data_clear_sound_data(player->uid, &sound_data);
 
                if (NULL == g_playing_info) {
                        SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current player is NULL");