From: Suyeon Hwang Date: Thu, 27 May 2021 11:52:08 +0000 (+0900) Subject: Remove functions and variables relative with player_s X-Git-Tag: submit/tizen/20220314.051039~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F82%2F271882%2F2;p=platform%2Fcore%2Fuifw%2Ftts.git Remove functions and variables relative with player_s Change-Id: I572a1b1420cafca0bfc9c3aab3e0f548b903f4c4 Signed-off-by: Suyeon Hwang --- diff --git a/server/ttsd_player.cpp b/server/ttsd_player.cpp index a4f0c5ec..975466ea 100644 --- a/server/ttsd_player.cpp +++ b/server/ttsd_player.cpp @@ -27,13 +27,6 @@ #include "tts_internal.h" #include "ttsd_server.h" -/* -* Internal data structure -*/ - -typedef struct { - unsigned int uid; /** client id */ -} player_s; #define SOUND_BUFFER_LENGTH 2048 @@ -55,12 +48,6 @@ static pthread_mutex_t g_buf_save_mutex = PTHREAD_MUTEX_INITIALIZER; /** player init info */ static bool g_player_init = false; -/** Client list */ -static GList *g_player_list; - -/** current player information */ -static player_s* g_playing_info; - static bool g_is_set_policy; /* CAUTION! @@ -70,8 +57,6 @@ If you choose too big value, it may cause integer overflow issue. #define SND_MGR_DUCKING_DURATION 500 static pthread_mutex_t g_play_thread_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t g_player_control_mutex = PTHREAD_MUTEX_INITIALIZER; - static pthread_cond_t g_play_thread_cond = PTHREAD_COND_INITIALIZER; static BackgroundVolume* g_background_volume = nullptr; @@ -153,31 +138,6 @@ static void __write_buffer_dump_file(const void* buffer, size_t length) } #endif -player_s* __player_get_item(unsigned int uid) -{ - GList *iter = NULL; - player_s *data = NULL; - - if (0 < g_list_length(g_player_list)) { - /* Get a first item */ - iter = g_list_first(g_player_list); - - while (NULL != iter) { - /* Get handle data from list */ - data = (player_s*)iter->data; - - /* compare uid */ - if (uid == data->uid) - return data; - - /* Get next item */ - iter = g_list_next(iter); - } - } - - return NULL; -} - static void __focus_release_callback() { unsigned int uid = g_player_thread->getCurrentUid(); @@ -574,9 +534,6 @@ static void __play_thread(void *data, Ecore_Thread *thread) */ int ttsd_player_init() { - pthread_mutex_lock(&g_player_control_mutex); - g_playing_info = NULL; - g_background_volume = new BackgroundVolume(SND_MGR_DUCKING_DURATION); g_audio_stream = new AudioStream(__focus_release_callback); g_player_thread = new PlayerThread(nullptr); @@ -586,8 +543,6 @@ int ttsd_player_init() g_is_set_policy = false; g_player_init = true; - pthread_mutex_unlock(&g_player_control_mutex); - return 0; } @@ -598,10 +553,8 @@ int ttsd_player_release(void) #endif __set_playing_status(false); - pthread_mutex_lock(&g_player_control_mutex); if (false == g_player_init) { SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized"); - pthread_mutex_unlock(&g_player_control_mutex); return TTSD_ERROR_OPERATION_FAILED; } @@ -624,13 +577,10 @@ int ttsd_player_release(void) thread_count = ecore_thread_active_get(); } - SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Thread is released"); - - /* clear g_player_list */ - g_playing_info = NULL; g_player_init = false; g_player_thread->requestStop(); pthread_cond_broadcast(&g_play_thread_cond); + SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Thread is released"); delete g_audio_stream; g_audio_stream = nullptr; @@ -641,109 +591,18 @@ int ttsd_player_release(void) delete g_player_thread; g_player_thread = nullptr; - pthread_mutex_unlock(&g_player_control_mutex); - - return 0; -} - -int ttsd_player_create_instance(unsigned int uid) -{ - if (false == g_player_init) { - SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized"); - return TTSD_ERROR_OPERATION_FAILED; - } - - /* Check uid is duplicated */ - if (NULL != __player_get_item(uid)) { - SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%u) is already registered", uid); - return -1; - } - - player_s* new_client = (player_s*)calloc(1, sizeof(player_s)); - if (NULL == new_client) { - SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to allocate memory"); - return TTSE_ERROR_OUT_OF_MEMORY; - } - - new_client->uid = uid; - ttsd_data_set_last_sound_result_event(uid, TTSE_RESULT_EVENT_FINISH); - ttsd_data_set_paused_data_existing(uid, false); - - SECURE_SLOG(LOG_DEBUG, tts_tag(), "[Player] Create player : uid(%u)", uid); - - g_player_list = g_list_append(g_player_list, new_client); - - return 0; -} - -int ttsd_player_destroy_instance(unsigned int uid) -{ - pthread_mutex_lock(&g_player_control_mutex); - if (false == g_player_init) { - SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized"); - pthread_mutex_unlock(&g_player_control_mutex); - return TTSD_ERROR_OPERATION_FAILED; - } - - player_s* current; - current = __player_get_item(uid); - if (NULL == current) { - SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%u) is not valid", uid); - pthread_mutex_unlock(&g_player_control_mutex); - return -1; - } - - if (NULL != g_playing_info) { - if (uid == g_playing_info->uid) { - g_playing_info = NULL; - } - } - - GList *iter = NULL; - player_s *data = NULL; - - if (0 < g_list_length(g_player_list)) { - /* Get a first item */ - iter = g_list_first(g_player_list); - - while (NULL != iter) { - /* Get handle data from list */ - data = (player_s*)iter->data; - - if (NULL != data) { - /* compare uid */ - if (uid == data->uid) { - g_player_list = g_list_remove_link(g_player_list, iter); - free(data); - data = NULL; - g_list_free(iter); - break; - } - } - - /* Get next item */ - iter = g_list_next(iter); - } - } - pthread_mutex_unlock(&g_player_control_mutex); - - SLOG(LOG_DEBUG, tts_tag(), "[PLAYER Success] Destroy instance"); - return 0; } int ttsd_player_play(unsigned int uid) { - pthread_mutex_lock(&g_player_control_mutex); if (false == g_player_init) { SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized"); - pthread_mutex_unlock(&g_player_control_mutex); return TTSD_ERROR_OPERATION_FAILED; } if (0 > ttsd_data_is_client(uid)) { SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%u) is not valid", uid); - pthread_mutex_unlock(&g_player_control_mutex); return -1; } @@ -751,13 +610,10 @@ int ttsd_player_play(unsigned int uid) if (0 < ttsd_data_is_client(currentUid)) { if (uid == currentUid) { SLOG(LOG_DEBUG, tts_tag(), "[Player] uid(%u) has already played", uid); - pthread_mutex_unlock(&g_player_control_mutex); return 0; } else { SLOG(LOG_WARN, tts_tag(), "[Player WARNING] stop old player (%u)", currentUid); - pthread_mutex_unlock(&g_player_control_mutex); ttsd_player_stop(currentUid); - pthread_mutex_lock(&g_player_control_mutex); } } @@ -765,16 +621,13 @@ int ttsd_player_play(unsigned int uid) g_player_thread->requestPlay(uid); pthread_cond_broadcast(&g_play_thread_cond); - pthread_mutex_unlock(&g_player_control_mutex); return 0; } int ttsd_player_stop(unsigned int uid) { - pthread_mutex_lock(&g_player_control_mutex); if (false == g_player_init) { SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized"); - pthread_mutex_unlock(&g_player_control_mutex); return TTSD_ERROR_OPERATION_FAILED; } @@ -799,47 +652,20 @@ int ttsd_player_stop(unsigned int uid) SLOG(LOG_INFO, tts_tag(), "[Player SUCCESS] Stop player : uid(%u)", uid); - pthread_mutex_unlock(&g_player_control_mutex); - return 0; -} - -int ttsd_player_clear(unsigned int uid) -{ - if (false == g_player_init) { - SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized"); - return TTSD_ERROR_OPERATION_FAILED; - } - - /* Check uid */ - player_s* current; - current = __player_get_item(uid); - if (NULL == current) { - SECURE_SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%u) is not valid", uid); - return -1; - } - - ttsd_data_set_last_sound_result_event(uid, TTSE_RESULT_EVENT_FINISH); - ttsd_data_set_paused_data_existing(uid, false); - - SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Clear player : uid(%u)", uid); - return 0; } int ttsd_player_pause(unsigned int uid) { - pthread_mutex_lock(&g_player_control_mutex); SLOG(LOG_DEBUG, tts_tag(), "[Player] pause player : uid(%u)", uid); if (false == g_player_init) { SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized"); - pthread_mutex_unlock(&g_player_control_mutex); return TTSD_ERROR_OPERATION_FAILED; } if (0 > ttsd_data_is_client(uid)) { SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] ttsd_player_pause() : uid(%u) is not valid", uid); - pthread_mutex_unlock(&g_player_control_mutex); return -1; } @@ -858,25 +684,20 @@ int ttsd_player_pause(unsigned int uid) __set_playing_status(false); SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Pause player : uid(%u)", uid); - - pthread_mutex_unlock(&g_player_control_mutex); return 0; } int ttsd_player_resume(unsigned int uid) { - pthread_mutex_lock(&g_player_control_mutex); SLOG(LOG_DEBUG, tts_tag(), "[Player] Resume player : uid(%u)", uid); if (false == g_player_init) { SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized"); - pthread_mutex_unlock(&g_player_control_mutex); return TTSD_ERROR_OPERATION_FAILED; } if (0 > ttsd_data_is_client(uid)) { SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%u) is not valid", uid); - pthread_mutex_unlock(&g_player_control_mutex); return -1; } @@ -884,7 +705,6 @@ int ttsd_player_resume(unsigned int uid) g_player_thread->requestPlay(uid); pthread_cond_broadcast(&g_play_thread_cond); - pthread_mutex_unlock(&g_player_control_mutex); return 0; } @@ -905,10 +725,8 @@ bool __stop_all_client_callback(int pid, unsigned int uid, app_tts_state_e state int ttsd_player_all_stop() { - pthread_mutex_lock(&g_player_control_mutex); if (false == g_player_init) { SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized"); - pthread_mutex_unlock(&g_player_control_mutex); return TTSD_ERROR_OPERATION_FAILED; } @@ -916,8 +734,6 @@ int ttsd_player_all_stop() g_player_thread->requestStop(); SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] player all stop!!"); - - pthread_mutex_unlock(&g_player_control_mutex); return 0; } diff --git a/server/ttsd_player.h b/server/ttsd_player.h index 552db2d1..ef850a09 100644 --- a/server/ttsd_player.h +++ b/server/ttsd_player.h @@ -39,16 +39,10 @@ int ttsd_player_init(); int ttsd_player_release(void); -int ttsd_player_create_instance(unsigned int uid); - -int ttsd_player_destroy_instance(unsigned int uid); - int ttsd_player_play(unsigned int uid); int ttsd_player_stop(unsigned int uid); -int ttsd_player_clear(unsigned int uid); - int ttsd_player_pause(unsigned int uid); int ttsd_player_resume(unsigned int uid); diff --git a/server/ttsd_server.c b/server/ttsd_server.c index 7e428904..68517ddb 100644 --- a/server/ttsd_server.c +++ b/server/ttsd_server.c @@ -173,9 +173,6 @@ int ttsd_send_error(ttse_error_e error, const char* msg) ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED); - if (0 != ttsd_player_clear(uid)) - SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_clear()"); - if (0 != ttsd_data_clear_data(uid)) SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_data_clear_data()"); @@ -652,17 +649,6 @@ int ttsd_server_initialize(int pid, unsigned int uid, tts_ipc_method_e method, b return TTSD_ERROR_OPERATION_FAILED; } - if (0 != ttsd_player_create_instance(uid)) { - SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to create player"); - return TTSD_ERROR_OPERATION_FAILED; - } - - g_file_num = 0; - g_min_latency = 10000.0; - g_max_latency = 0.0; - g_avg_latency = 0.0; - - return TTSD_ERROR_NONE; } @@ -789,9 +775,6 @@ int ttsd_server_finalize(unsigned int uid) } ttsd_server_stop(uid); - ttsd_player_clear(uid); - - ttsd_player_destroy_instance(uid); /* Need to unload voice when used voice is unregistered */ if (0 != ttsd_data_reset_used_voice(uid, __used_voice_cb)) {