Add sound buf save for test 99/206999/1
authorsungrae jo <seongrae.jo@samsung.com>
Thu, 30 May 2019 01:41:20 +0000 (10:41 +0900)
committersungrae jo <seongrae.jo@samsung.com>
Thu, 30 May 2019 01:41:20 +0000 (10:41 +0900)
Change-Id: I20355dea35f02f351d103f308a64e30e9e95bd3a
Signed-off-by: sungrae jo <seongrae.jo@samsung.com>
server/ttsd_player.c

index aa2fbcc..3ca665b 100644 (file)
@@ -49,6 +49,18 @@ typedef struct {
 #define SOUND_BUFFER_LENGTH    2048
 #define FOCUS_SERVER_READY "/tmp/.sound_server_ready"
 
+/* Sound buf save for test */
+/*
+#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;
+#endif
+
 /** player init info */
 static bool g_player_init = false;
 
@@ -278,6 +290,10 @@ static int __destroy_audio_out()
 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 __set_policy_for_playing(int volume)
@@ -382,6 +398,36 @@ static void __play_thread(void *data, Ecore_Thread *thread)
 {
        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;
@@ -592,6 +638,10 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                        char* temp_data = sound_data->data;
                        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);
+#endif
                        ret = audio_out_write(g_audio_h, &temp_data[idx], len);
                        if (0 > ret) {
                                SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to audio write - %d", ret);