/*
#define BUF_SAVE_MODE
*/
+
#ifdef BUF_SAVE_MODE
static char g_temp_file_name[128] = {'\0',};
-
static FILE* g_pFile;
-
-static int g_count = 1;
+static int g_count = 0;
+static pthread_mutex_t g_buf_save_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
/** player init info */
* Internal Interfaces
*/
+#ifdef BUF_SAVE_MODE
+static void __open_buffer_dump_file()
+{
+ pthread_mutex_lock(&g_buf_save_mutex);
+ if (g_pFile) {
+ SLOG(LOG_ERROR, tts_tag(), "[Buffer Dump] File is already opened(%s)", g_temp_file_name);
+ pthread_mutex_unlock(&g_buf_save_mutex);
+ return;
+ }
+
+ g_count++;
+ while (1) {
+ snprintf(g_temp_file_name, sizeof(g_temp_file_name), "/tmp/tts_temp_%d_%d", getpid(), g_count);
+ int ret = access(g_temp_file_name, 0);
+
+ if (0 == ret) {
+ SLOG(LOG_ERROR, tts_tag(), "[Recorder ERROR] File is already exist");
+ if (0 == remove(g_temp_file_name)) {
+ SLOG(LOG_DEBUG, tts_tag(), "[Recorder] Remove file");
+ break;
+ } else {
+ g_count++;
+ }
+ } else {
+ break;
+ }
+ }
+
+ SECURE_SLOG(LOG_DEBUG, tts_tag(), "[Recorder] Temp file name=[%s]", g_temp_file_name);
+
+ /* open test file */
+ g_pFile = fopen(g_temp_file_name, "wb+x");
+ if (NULL == g_pFile) {
+ SLOG(LOG_ERROR, tts_tag(), "[Recorder ERROR] File not found!");
+ }
+
+ pthread_mutex_unlock(&g_buf_save_mutex);
+}
+
+static void __close_buffer_dump_file()
+{
+ pthread_mutex_lock(&g_buf_save_mutex);
+
+ if (g_pFile) {
+ fclose(g_pFile);
+ g_pFile = NULL;
+ }
+
+ pthread_mutex_unlock(&g_buf_save_mutex);
+}
+
+static void __write_buffer_dump_file(const void* buffer, size_t length)
+{
+ pthread_mutex_lock(&g_buf_save_mutex);
+
+ if (g_pFile) {
+ size_t ret = fwrite(buffer, 1, length, g_pFile);
+ SLOG(LOG_DEBUG, tts_tag(), "[Buffer Dump] Stored size(%zu / %zu)", ret, length);
+ } else {
+ SLOG(LOG_ERROR, tts_tag(), "[Buffer Dump] File is not opened. Please check the file open");
+ }
+
+ pthread_mutex_unlock(&g_buf_save_mutex);
+}
+#endif
+
static bool __is_player_valid(player_s* player)
{
if (NULL == player || NULL == g_playing_info) {
static void __end_play_thread(void *data, Ecore_Thread *thread)
{
SLOG(LOG_ERROR, tts_tag(), "@@@ End thread");
-
-#ifdef BUF_SAVE_MODE
- fclose(g_pFile);
-#endif
}
static void __del_timer_for_delayed_recover(void* data)
{
SLOG(LOG_DEBUG, tts_tag(), "@@@ Start thread");
-#ifdef BUF_SAVE_MODE
- g_count++;
-
- while (1) {
- snprintf(g_temp_file_name, sizeof(g_temp_file_name), "/tmp/tts_temp_%d_%d", getpid(), g_count);
- int ret = access(g_temp_file_name, 0);
-
- if (0 == ret) {
- SLOG(LOG_ERROR, tts_tag(), "[Recorder ERROR] File is already exist");
- if (0 == remove(g_temp_file_name)) {
- SLOG(LOG_DEBUG, tts_tag(), "[Recorder] Remove file");
- break;
- } else {
- g_count++;
- }
- } else {
- break;
- }
- }
-
- SECURE_SLOG(LOG_DEBUG, tts_tag(), "[Recorder] Temp file name=[%s]", g_temp_file_name);
-
- /* open test file */
- g_pFile = fopen(g_temp_file_name, "wb+x");
- if (!g_pFile) {
- SLOG(LOG_ERROR, tts_tag(), "[Recorder ERROR] File not found!");
- return;
- }
-#endif
-
if (NULL == g_playing_info) {
SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] No current player");
return;
return;
}
+#ifdef BUF_SAVE_MODE
+ __open_buffer_dump_file();
+#endif
+
if (0 != ttsdc_ipc_send_utt_start_message(pid, player->uid, sound_data->utt_id)) {
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);
__unset_policy_for_playing();
+#ifdef BUF_SAVE_MODE
+ __close_buffer_dump_file();
+#endif
+
if (0 != ttsdc_ipc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)",
pid, player->uid, sound_data->utt_id);
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);
#ifdef BUF_SAVE_MODE
- /* write pcm buffer */
- fwrite(&temp_data[idx], 1, len, g_pFile);
+ __write_buffer_dump_file(&temp_data[idx], len);
#endif
ret = audio_out_write(g_audio_h, &temp_data[idx], len);
if (0 > ret) {
return;
}
+#ifdef BUF_SAVE_MODE
+ __close_buffer_dump_file();
+#endif
if (0 != ttsdc_ipc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)",
pid, player->uid, sound_data->utt_id);
int ttsd_player_release(void)
{
+#ifdef BUF_SAVE_MODE
+ __close_buffer_dump_file();
+#endif
+
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_play_thread_mutex);
}
+#ifdef BUF_SAVE_MODE
+ __close_buffer_dump_file();
+#endif
+
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_play_thread_mutex);
}
+#ifdef BUF_SAVE_MODE
+ __close_buffer_dump_file();
+#endif
+
SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Pause player : uid(%d)", uid);
pthread_mutex_unlock(&g_player_control_mutex);