static double g_bg_volume_ratio;
static pthread_mutex_t g_play_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t g_player_control_mutex = PTHREAD_MUTEX_INITIALIZER;
/*
* Internal Interfaces
int ttsd_player_play(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 -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);
+ pthread_mutex_unlock(&g_player_control_mutex);
return 0;
} else {
SLOG(LOG_WARN, tts_tag(), "[Player WARNING] stop old player (%d)", g_playing_info->uid);
+ pthread_mutex_unlock(&g_player_control_mutex);
ttsd_player_stop(g_playing_info->uid);
+ pthread_mutex_lock(&g_player_control_mutex);
}
}
/* 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);
+ pthread_mutex_unlock(&g_player_control_mutex);
return -1;
}
current = __player_get_item(uid);
if (NULL == current) {
SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
+ pthread_mutex_unlock(&g_player_control_mutex);
return -1;
}
ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
}
+ pthread_mutex_unlock(&g_player_control_mutex);
return 0;
}
int ttsd_player_stop(int uid)
{
+ pthread_mutex_lock(&g_player_control_mutex);
int ret = ttsd_player_clear(uid);
if (0 != ret) {
SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to stop player, ret(%d)", ret);
+ pthread_mutex_unlock(&g_player_control_mutex);
return ret;
}
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] @@@@@");
-
- /* The thread should be released */
- // int thread_count = ecore_thread_active_get();
- // int count = 0;
- // while (0 < thread_count) {
- // usleep(20000);
-
- // count++;
- // if (50 == count) {
- // SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
- // break;
- // }
-
- // thread_count = ecore_thread_active_get();
- // }
-
- 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] @@@@@");
}
pthread_mutex_unlock(&g_play_thread_mutex);
SLOG(LOG_INFO, tts_tag(), "[Player SUCCESS] Stop player : uid(%d)", uid);
+ pthread_mutex_unlock(&g_player_control_mutex);
return 0;
}
int ttsd_player_pause(int uid)
{
+ pthread_mutex_lock(&g_player_control_mutex);
SLOG(LOG_DEBUG, tts_tag(), "[Player] pause player : uid(%d)", uid);
if (false == g_player_init) {
SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
+ pthread_mutex_unlock(&g_player_control_mutex);
return -1;
}
current = __player_get_item(uid);
if (NULL == current) {
SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] ttsd_player_pause() : uid(%d) is not valid", uid);
+ pthread_mutex_unlock(&g_player_control_mutex);
return -1;
}
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] @@@@@");
-
- /* The thread should be released */
- // int thread_count = ecore_thread_active_get();
- // int count = 0;
- // while (0 < thread_count) {
- // usleep(10000);
-
- // count++;
- // SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] current(%p), state(%d)", current, current->state);
-
- // if (30 == count) {
- // SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue. current(%p) current state(%d)", current, current->state);
- // break;
- // }
-
- // thread_count = ecore_thread_active_get();
- // }
-
- 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] @@@@@");
}
pthread_mutex_unlock(&g_play_thread_mutex);
SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Pause player : uid(%d)", uid);
+ pthread_mutex_unlock(&g_player_control_mutex);
return 0;
}
int ttsd_player_resume(int uid)
{
+ pthread_mutex_lock(&g_player_control_mutex);
SLOG(LOG_DEBUG, tts_tag(), "[Player] Resume player : uid(%d)", uid);
if (false == g_player_init) {
SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
+ pthread_mutex_unlock(&g_player_control_mutex);
return -1;
}
current = __player_get_item(uid);
if (NULL == current) {
SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
+ pthread_mutex_unlock(&g_player_control_mutex);
return -1;
}
SLOG(LOG_INFO, tts_tag(), "[Player] Resume to run thread");
ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
+ pthread_mutex_unlock(&g_player_control_mutex);
return 0;
}
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 -1;
}
SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] player all stop!!");
+ pthread_mutex_unlock(&g_player_control_mutex);
return 0;
}
int ttsd_player_play_pcm(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 -1;
}
return 0;
} else {
SLOG(LOG_WARN, tts_tag(), "[Player WARNING] stop old player (%d)", g_playing_info->uid);
+ pthread_mutex_unlock(&g_player_control_mutex);
ttsd_player_stop(g_playing_info->uid);
+ pthread_mutex_lock(&g_player_control_mutex);
}
}
current = __player_get_item(uid);
if (NULL == current) {
SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
+ pthread_mutex_unlock(&g_player_control_mutex);
return -1;
}
ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
}
+ pthread_mutex_unlock(&g_player_control_mutex);
return 0;
}