#include <Ecore.h>
#include <sound_manager.h>
#include <sound_manager_internal.h>
+#include <pthread.h>
#include "ttsd_main.h"
#include "ttsd_player.h"
static double g_bg_volume_ratio;
+static pthread_mutex_t g_play_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
+
/*
* Internal Interfaces
*/
/* set volume policy as 40% */
__set_policy_for_playing(40);
while (1) { // 1st while(1)
+ pthread_mutex_lock(&g_play_thread_mutex);
/* check g_playing_info one more time */
if (false == __is_player_valid(player)) {
SLOG(LOG_INFO, tts_tag(), "[Player INFO] Player is not valid");
SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
}
__unset_policy_for_playing();
+ pthread_mutex_unlock(&g_play_thread_mutex);
return;
}
/* unset volume policy, volume will be 100% */
__unset_policy_for_playing();
+ pthread_mutex_unlock(&g_play_thread_mutex);
return;
}
SLOG(LOG_INFO, tts_tag(), "[Player] Sound info : id(%d) data(%p) size(%d) audiotype(%d) rate(%d) event(%d)",
}
/* unset volume policy, volume will be 100% */
__unset_policy_for_playing();
+ pthread_mutex_unlock(&g_play_thread_mutex);
return;
} else if (0 < ttsd_data_get_sound_data_size(player->uid)) {
/* new audio data come */
/* resume play thread */
player->state = APP_STATE_PLAYING;
+ pthread_mutex_unlock(&g_play_thread_mutex);
continue;
} // NULL == sound_data
/* unset volume policy, volume will be 100% */
__unset_policy_for_playing();
ttsd_data_clear_sound_data(&sound_data);
+ pthread_mutex_unlock(&g_play_thread_mutex);
return;
}
/* unset volume policy, volume will be 100% */
__unset_policy_for_playing();
ttsd_data_clear_sound_data(&sound_data);
+ pthread_mutex_unlock(&g_play_thread_mutex);
return;
}
} // TTSE_RESULT_EVENT_FINISH == sound_data->event
SLOG(LOG_INFO, tts_tag(), "[Player] Event(%d) utterance : uid(%d), uttid(%d)", sound_data->event, player->uid, sound_data->utt_id);
ttsd_data_clear_sound_data(&sound_data);
+ pthread_mutex_unlock(&g_play_thread_mutex);
continue;
} // (NULL == sound_data->data || 0 >= sound_data->data_size)
} // NO player->is_paused_data
ttsd_data_clear_sound_data(&sound_data);
+ pthread_mutex_unlock(&g_play_thread_mutex);
return;
}
ttsd_data_clear_sound_data(&sound_data);
+ pthread_mutex_unlock(&g_play_thread_mutex);
return;
}
SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Prepare audio");
ttsd_data_clear_sound_data(&sound_data);
+ pthread_mutex_unlock(&g_play_thread_mutex);
return;
} // (NULL == g_playing_info && APP_STATE_PAUSED != player->state)
}
/* unset volume policy, volume will be 100% */
__unset_policy_for_playing();
+ pthread_mutex_unlock(&g_play_thread_mutex);
return;
} // (APP_STATE_PAUSED == player->state)
} // while (APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state)
/* unset volume policy, volume will be 100% */
__unset_policy_for_playing();
ttsd_data_clear_sound_data(&sound_data);
+ pthread_mutex_unlock(&g_play_thread_mutex);
return;
} // (NULL == g_playing_info && APP_STATE_READY == player->state)
/* unset volume policy, volume will be 100% */
__unset_policy_for_playing();
ttsd_data_clear_sound_data(&sound_data);
+ pthread_mutex_unlock(&g_play_thread_mutex);
return;
}
/* unset volume policy, volume will be 100% */
__unset_policy_for_playing();
ttsd_data_clear_sound_data(&sound_data);
+ pthread_mutex_unlock(&g_play_thread_mutex);
return;
}
/* unset volume policy, volume will be 100% */
__unset_policy_for_playing();
ttsd_data_clear_sound_data(&sound_data);
+ pthread_mutex_unlock(&g_play_thread_mutex);
return;
}
+
+ pthread_mutex_unlock(&g_play_thread_mutex);
} // end of 1st while(1)
}
SLOG(LOG_DEBUG, tts_tag(), "[Player] No current playing");
}
+ pthread_mutex_lock(&g_play_thread_mutex);
if (NULL == g_playing_info) {
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;
- }
+ // int thread_count = ecore_thread_active_get();
+ // int count = 0;
+ // while (0 < thread_count) {
+ // usleep(20000);
- thread_count = ecore_thread_active_get();
- }
+ // 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);
current->state = APP_STATE_PAUSED;
+ pthread_mutex_lock(&g_play_thread_mutex);
if (NULL == g_playing_info) {
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);
+ // 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);
+ // 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;
- }
+ // 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();
- }
+ // 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);