X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=server%2Fttsd_player.c;h=54d1ef622fc26d4eca0de7081000388a9966525b;hb=f09e5290b213b4bb7f6f2bdf49188008e363aec6;hp=110da50c7d039fcb922efc0618e6520806c54017;hpb=d36b3a396be3e2cf3c0d63ba10df9c38e61b8071;p=platform%2Fcore%2Fuifw%2Ftts.git diff --git a/server/ttsd_player.c b/server/ttsd_player.c index 110da50..54d1ef6 100644 --- a/server/ttsd_player.c +++ b/server/ttsd_player.c @@ -21,6 +21,9 @@ #include "ttsd_data.h" #include "ttsd_dbus.h" +#include "tts_internal.h" +#include "ttsd_server.h" + /* * Internal data structure */ @@ -33,7 +36,7 @@ typedef enum { typedef struct { int uid; /** client id */ - app_state_e state; /** client state */ + app_tts_state_e state; /** client state */ /* Current utterance information */ ttse_result_event_e event; /** event of last utterance */ @@ -44,6 +47,7 @@ typedef struct { } player_s; #define SOUND_BUFFER_LENGTH 2048 +#define FOCUS_SERVER_READY "/tmp/.sound_server_ready" /** player init info */ static bool g_player_init = false; @@ -65,6 +69,7 @@ static audio_out_h g_audio_h; static sound_stream_info_h g_stream_info_h; +static int g_focus_watch_id; /* * Internal Interfaces */ @@ -97,13 +102,13 @@ player_s* __player_get_item(int uid) void __player_focus_state_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state, sound_stream_focus_change_reason_e reason_for_change, int sound_behavior, const char *extra_info, void *user_data) { - SLOG(LOG_DEBUG, tts_tag(), "===== Focus state changed cb"); + SLOG(LOG_DEBUG, tts_tag(), "@@@ Focus state changed cb"); if (stream_info != g_stream_info_h) { SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Invalid stream info handle"); return; } - SLOG(LOG_WARN, tts_tag(), "[Player] focus state changed to (%d) with reason(%d)", (int)focus_state, (int)reason_for_change); + SLOG(LOG_WARN, tts_tag(), "[Player] focus state changed to (%d) with reason(%d) and extra info(%s)", (int)focus_state, (int)reason_for_change, extra_info); if (AUDIO_STATE_PLAY == g_audio_state && focus_mask == SOUND_STREAM_FOCUS_FOR_PLAYBACK && SOUND_STREAM_FOCUS_STATE_RELEASED == focus_state) { if (TTSD_MODE_DEFAULT == ttsd_get_mode()) { @@ -122,7 +127,6 @@ void __player_focus_state_cb(sound_stream_info_h stream_info, sound_stream_focus return; } - g_playing_info->state = APP_STATE_PAUSED; ttsd_data_set_client_state(uid, APP_STATE_PAUSED); int pid = ttsd_data_get_pid(uid); /* send message to client about changing state */ @@ -133,8 +137,84 @@ void __player_focus_state_cb(sound_stream_info_h stream_info, sound_stream_focus } } - SLOG(LOG_DEBUG, tts_tag(), "====="); - SLOG(LOG_DEBUG, tts_tag(), ""); +/* if (AUDIO_STATE_READY == g_audio_state && focus_mask == SOUND_STREAM_FOCUS_FOR_PLAYBACK && SOUND_STREAM_FOCUS_STATE_ACQUIRED == focus_state) { + if (TTSD_MODE_DEFAULT == ttsd_get_mode()) { + g_audio_state = AUDIO_STATE_PLAY; + + if (NULL == g_playing_info) { + SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player"); + return; + } + + if (APP_STATE_PAUSED == g_playing_info->state) { + int uid = g_playing_info->uid; + + g_audio_state = AUDIO_STATE_PLAY; + if (0 != ttsd_player_resume(uid)) { + SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to resume the player"); + g_audio_state = AUDIO_STATE_READY; + return; + } + + ttsd_data_set_client_state(uid, APP_STATE_PLAYING); + int pid = ttsd_data_get_pid(uid); + ttsdc_send_set_state_message(pid, uid, APP_STATE_PLAYING); + } + + } else { + SLOG(LOG_DEBUG, tts_tag(), "[Player] Ignore focus state cb - mode(%d)", ttsd_get_mode()); + } + } +*/ + SLOG(LOG_DEBUG, tts_tag(), "@@@"); + + return; +} + +void __player_focus_state_watch_cb(int id, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state, sound_stream_focus_change_reason_e reason, + const char *extra_info, void *user_data) +{ + SLOG(LOG_DEBUG, tts_tag(), "@@@ Focus state watch cb"); + + ttsd_mode_e mode = ttsd_get_mode(); + + if (TTSD_MODE_SCREEN_READER != mode && TTSD_MODE_NOTIFICATION != mode) { + SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] This is not screen-reader mode and notification mode."); + return; + } + + if (AUDIO_STATE_PLAY == g_audio_state && SOUND_STREAM_FOCUS_CHANGED_BY_VOICE_INFORMATION == reason && + NULL != extra_info && 0 == strncmp(extra_info, "TTSD_MODE_INTERRUPT", strlen(extra_info))) { + /* If the focus is changed by "Interrupt" mode and current players of "SR" and "Noti" modes are on going, please stop the current players. */ + g_audio_state = AUDIO_STATE_READY; + + if (NULL == g_playing_info) { + SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player"); + return; + } + + if (APP_STATE_PLAYING == g_playing_info->state) { + int uid = g_playing_info->uid; + + if (0 != ttsd_server_stop(uid)) { + SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to stop TTS server"); + return; + } + if (0 != ttsd_player_stop(uid)) { + SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to stop the player"); + return; + } + + ttsd_data_set_client_state(uid, APP_STATE_READY); + int pid = ttsd_data_get_pid(uid); + /* send message to client about changing state */ + ttsdc_send_set_state_message(pid, uid, APP_STATE_READY); + } else { + SLOG(LOG_DEBUG, tts_tag(), "[Player] Not playing state"); + } + } else { + SLOG(LOG_DEBUG, tts_tag(), "[Player] This is not Interrupt mode or not playing state."); + } return; } @@ -195,32 +275,46 @@ static int __destroy_audio_out() static void __end_play_thread(void *data, Ecore_Thread *thread) { - SLOG(LOG_ERROR, tts_tag(), "===== End thread"); + SLOG(LOG_ERROR, tts_tag(), "@@@ End thread"); } static void __set_policy_for_playing(int volume) { /* Set stream info */ int ret; - if (TTSD_MODE_DEFAULT == ttsd_get_mode()) { + ttsd_mode_e mode = ttsd_get_mode(); + if (TTSD_MODE_DEFAULT == mode) { ret = sound_manager_acquire_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL); if (SOUND_MANAGER_ERROR_NONE != ret) { SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to acquire focus"); + } else { + SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Success to acquire focus (default mode)"); + } + } else if (TTSD_MODE_INTERRUPT == mode) { + ret = sound_manager_acquire_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, "TTSD_MODE_INTERRUPT"); + if (SOUND_MANAGER_ERROR_NONE != ret) { + SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to acquire focus"); + } else { + SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Success to acquire focus (interrupt mode)"); } } + ret = audio_out_set_sound_stream_info(g_audio_h, g_stream_info_h); if (AUDIO_IO_ERROR_NONE != ret) { SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to set stream info"); } + SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] set policy for playing"); + return; } static void __unset_policy_for_playing() { int ret; + ttsd_mode_e mode = ttsd_get_mode(); /* Unset stream info */ - if (TTSD_MODE_DEFAULT == ttsd_get_mode()) { + if (TTSD_MODE_DEFAULT == mode || TTSD_MODE_INTERRUPT == mode) { sound_stream_focus_state_e state_for_playing = SOUND_STREAM_FOCUS_STATE_ACQUIRED; ret = sound_manager_get_focus_state(g_stream_info_h, &state_for_playing, NULL); if (SOUND_MANAGER_ERROR_NONE != ret) { @@ -228,19 +322,61 @@ static void __unset_policy_for_playing() } if (SOUND_STREAM_FOCUS_STATE_ACQUIRED == state_for_playing) { - ret = sound_manager_release_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL); + if (TTSD_MODE_DEFAULT == mode || TTSD_MODE_INTERRUPT == mode) { + ret = sound_manager_release_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL); + SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] release focus (mode: %d)", mode); + } + if (SOUND_MANAGER_ERROR_NONE != ret) { SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to release focus"); } } } + SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] unset policy for playing"); + return; } +int ttsd_player_check_current_playback_focus(bool *is_current_interrupt) +{ + int ret; + ttsd_mode_e mode = ttsd_get_mode(); + + if (TTSD_MODE_INTERRUPT != mode) { + /* check the current playback focus */ + sound_stream_focus_change_reason_e reason; + int sound_behavior = 0; + char *extra_info = NULL; + + ret = sound_manager_get_current_playback_focus(&reason, &sound_behavior, &extra_info); + + if (SOUND_MANAGER_ERROR_NONE == ret && NULL != extra_info) { + if (SOUND_STREAM_FOCUS_CHANGED_BY_VOICE_INFORMATION == reason && 0 == strncmp(extra_info, "TTSD_MODE_INTERRUPT", strlen(extra_info))) { + SLOG(LOG_DEBUG, tts_tag(), "[Player] The current focus in Interrupt. Cannot play the requested sound data"); + *is_current_interrupt = true; + + free(extra_info); + extra_info = NULL; + + return TTSD_ERROR_NONE; + } + } + + if (NULL != extra_info) { + free(extra_info); + extra_info = NULL; + } + } + + *is_current_interrupt = false; + + return TTSD_ERROR_NONE; +} + static void __play_thread(void *data, Ecore_Thread *thread) { - SLOG(LOG_DEBUG, tts_tag(), "===== Start thread"); + SLOG(LOG_DEBUG, tts_tag(), "@@@ Start thread"); if (NULL == g_playing_info) { SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] No current player"); @@ -307,15 +443,17 @@ static void __play_thread(void *data, Ecore_Thread *thread) usleep(10000); if (NULL == g_playing_info) { /* current playing uid is replaced */ - SLOG(LOG_DEBUG, tts_tag(), "[Player] Finish thread"); + SLOG(LOG_INFO, tts_tag(), "[Player] Finish thread"); return; } else if (0 < ttsd_data_get_sound_data_size(player->uid)) { /* new audio data come */ - SLOG(LOG_DEBUG, tts_tag(), "[Player] Resume thread"); + SLOG(LOG_INFO, tts_tag(), "[Player] Resume thread"); break; } } + 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); @@ -337,6 +475,13 @@ 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(); + + if (NULL != sound_data->data) { + free(sound_data->data); + sound_data->data = NULL; + } + free(sound_data); + sound_data = NULL; return; } @@ -344,7 +489,7 @@ static void __play_thread(void *data, Ecore_Thread *thread) SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Start Signal : pid(%d), uid(%d), uttid(%d)", pid, player->uid, sound_data->utt_id); } - SLOG(LOG_DEBUG, tts_tag(), "[Player] Start utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id); + SLOG(LOG_INFO, tts_tag(), "[Player] Start utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id); } /* Save last event to check utterance start */ @@ -361,6 +506,12 @@ 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(); + if (NULL != sound_data->data) { + free(sound_data->data); + sound_data->data = NULL; + } + free(sound_data); + sound_data = NULL; return; } if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) { @@ -368,7 +519,13 @@ static void __play_thread(void *data, Ecore_Thread *thread) pid, player->uid, sound_data->utt_id); } } - SLOG(LOG_DEBUG, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id); + SLOG(LOG_INFO, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id); + if (NULL != sound_data->data) { + free(sound_data->data); + sound_data->data = NULL; + } + free(sound_data); + sound_data = NULL; continue; } } @@ -383,8 +540,17 @@ static void __play_thread(void *data, Ecore_Thread *thread) SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create audio out"); /* unset volume policy, volume will be 100% */ __unset_policy_for_playing(); + + if (NULL != sound_data->data) { + free(sound_data->data); + sound_data->data = NULL; + } + free(sound_data); + sound_data = NULL; + return; } + __set_policy_for_playing(40); } @@ -406,6 +572,15 @@ static void __play_thread(void *data, Ecore_Thread *thread) g_playing_info = NULL; /* unset volume policy, volume will be 100% */ __unset_policy_for_playing(); + + if (NULL != sound_data->data) { + free(sound_data->data); + sound_data->data = NULL; + } + + free(sound_data); + sound_data = NULL; + return; } SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Prepare audio"); @@ -451,7 +626,7 @@ static void __play_thread(void *data, Ecore_Thread *thread) player->idx = idx; g_audio_state = AUDIO_STATE_READY; - SLOG(LOG_DEBUG, tts_tag(), "[Player] Stop player thread by pause"); + SLOG(LOG_INFO, tts_tag(), "[Player] Stop player thread by pause"); /* Request prepare */ ret = audio_out_unprepare(g_audio_h); @@ -502,6 +677,13 @@ 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(); + if (NULL != sound_data->data) { + free(sound_data->data); + sound_data->data = NULL; + } + + free(sound_data); + sound_data = NULL; return; } @@ -510,10 +692,17 @@ static void __play_thread(void *data, Ecore_Thread *thread) pid, player->uid, sound_data->utt_id); /* unset volume policy, volume will be 100% */ __unset_policy_for_playing(); + if (NULL != sound_data->data) { + free(sound_data->data); + sound_data->data = NULL; + } + + free(sound_data); + sound_data = NULL; return; } - SLOG(LOG_DEBUG, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id); + SLOG(LOG_INFO, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id); } if (NULL != sound_data) { @@ -554,6 +743,18 @@ int ttsd_player_init() ecore_thread_max_set(1); + int cnt = 0; + while (1) { + if (0 == access(FOCUS_SERVER_READY, F_OK)) { + SLOG(LOG_ERROR, tts_tag(), "[Player SUCCESS] focus server is available"); + break; + } else { + if (0 == cnt++ % 10) + SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] focus server is not available"); + usleep(50000); + } + } + ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_INFORMATION, __player_focus_state_cb, NULL, &g_stream_info_h); if (SOUND_MANAGER_ERROR_NONE != ret) { SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create stream info"); @@ -562,6 +763,15 @@ int ttsd_player_init() SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Create stream info"); } + /* add sound focus state watch callback */ + ret = sound_manager_add_focus_state_watch_cb(SOUND_STREAM_FOCUS_FOR_PLAYBACK, __player_focus_state_watch_cb, NULL, &g_focus_watch_id); + if (SOUND_MANAGER_ERROR_NONE != ret) { + SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to add sound focus watch callback"); + return -1; + } else { + SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Add sound focus watch callback"); + } + ecore_thread_max_set(1); ret = __create_audio_out(TTSE_AUDIO_TYPE_RAW_S16, 16000); @@ -582,9 +792,9 @@ int ttsd_player_release(void) int ret; - SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] =========================="); + SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] @@@@@"); SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get()); - SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] =========================="); + SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] @@@@@"); /* The thread should be released */ int thread_count = ecore_thread_active_get(); @@ -614,6 +824,14 @@ int ttsd_player_release(void) SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Destroy stream info"); } + /* remove focus state watch callback */ + ret = sound_manager_remove_focus_state_watch_cb(g_focus_watch_id); + if (SOUND_MANAGER_ERROR_NONE != ret) { + SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to remove the focus state watch cb"); + } else { + SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Remove the focus state watch cb"); + } + /* clear g_player_list */ g_playing_info = NULL; g_player_init = false; @@ -742,10 +960,10 @@ int ttsd_player_play(int uid) g_playing_info = current; - SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get()); + SLOG(LOG_INFO, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get()); if (0 < ttsd_data_get_sound_data_size(current->uid)) { - SLOG(LOG_DEBUG, tts_tag(), "[Player] Run thread"); + SLOG(LOG_INFO, tts_tag(), "[Player] Run thread"); ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL); } @@ -795,9 +1013,9 @@ int ttsd_player_stop(int uid) current->idx = 0; if (NULL == g_playing_info) { - SLOG(LOG_DEBUG, tts_tag(), "[Player] =========================="); + SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@"); SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get()); - SLOG(LOG_DEBUG, tts_tag(), "[Player] =========================="); + SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@"); /* The thread should be released */ int thread_count = ecore_thread_active_get(); @@ -814,12 +1032,12 @@ int ttsd_player_stop(int uid) thread_count = ecore_thread_active_get(); } - SLOG(LOG_DEBUG, tts_tag(), "[Player] =========================="); + SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@"); SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get()); - SLOG(LOG_DEBUG, tts_tag(), "[Player] =========================="); + SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@"); } - SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Stop player : uid(%d)", uid); + SLOG(LOG_INFO, tts_tag(), "[Player SUCCESS] Stop player : uid(%d)", uid); return 0; } @@ -889,10 +1107,10 @@ int ttsd_player_pause(int uid) } current->state = APP_STATE_PAUSED; - - SLOG(LOG_DEBUG, tts_tag(), "[Player] =========================="); + + SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@"); SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get()); - SLOG(LOG_DEBUG, tts_tag(), "[Player] =========================="); + SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@"); /* The thread should be released */ int thread_count = ecore_thread_active_get(); @@ -909,9 +1127,9 @@ int ttsd_player_pause(int uid) thread_count = ecore_thread_active_get(); } - SLOG(LOG_DEBUG, tts_tag(), "[Player] =========================="); + SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@"); SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get()); - SLOG(LOG_DEBUG, tts_tag(), "[Player] =========================="); + SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@"); SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Pause player : uid(%d)", uid); @@ -942,7 +1160,7 @@ int ttsd_player_resume(int uid) current->state = APP_STATE_PLAYING; g_playing_info = current; - SLOG(LOG_DEBUG, tts_tag(), "[Player] Run thread"); + SLOG(LOG_INFO, tts_tag(), "[Player] Resume to run thread"); ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL); return 0; @@ -968,7 +1186,7 @@ int ttsd_player_all_stop() /* Get handle data from list */ data = (player_s*)iter->data; - app_state_e state; + app_tts_state_e state; if (0 > ttsd_data_get_client_state(data->uid, &state)) { SLOG(LOG_ERROR, tts_tag(), "[player ERROR] uid(%d) is not valid", data->uid); ttsd_player_destroy_instance(data->uid); @@ -1005,3 +1223,50 @@ int ttsd_player_all_stop() return 0; } + +int ttsd_player_play_pcm(int uid) +{ + if (false == g_player_init) { + SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized"); + return -1; + } + + if (NULL != g_playing_info) { + if (uid == g_playing_info->uid) { + SLOG(LOG_DEBUG, tts_tag(), "[Player] uid(%d) has already played", g_playing_info->uid); + return 0; + } else { + SLOG(LOG_WARN, tts_tag(), "[Player WARNING] stop old player (%d)", g_playing_info->uid); + ttsd_player_stop(g_playing_info->uid); + } + } + + SLOG(LOG_DEBUG, tts_tag(), "[Player] start play : uid(%d)", uid); + + /* Check sound queue size */ + if (0 == ttsd_data_get_sound_data_size(uid)) { + SLOG(LOG_WARN, tts_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid); + } + + /* Check uid */ + player_s* current; + current = __player_get_item(uid); + if (NULL == current) { + SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid); + return -1; + } + + current->state = APP_STATE_PLAYING; + + g_playing_info = current; + + SLOG(LOG_INFO, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get()); + + if (0 <= ttsd_data_get_sound_data_size(current->uid)) { + SLOG(LOG_INFO, tts_tag(), "[Player] Run thread"); + ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL); + } + + return 0; +} +