Add test code for dumping pcm data from ma-service 42/221642/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Mon, 6 Jan 2020 08:30:14 +0000 (17:30 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Mon, 6 Jan 2020 08:30:19 +0000 (17:30 +0900)
Change-Id: Ie72187b27c42b267064acd6482d2313ebc9a723f

client/ma.c

index 47f479ab24c6ac49eaafbaa07a7f83262703d48d..9dfd10fd3563cd95dfa855b9b3105655b1bab85c 100644 (file)
 #include "ma_defs.h"
 #include "ma_config_mgr.h"
 
+/* Sound buf save for test */
+#if 0
+#define BUF_SAVE_MODE
+#endif
+
 #define MAX_ASSISTANT_INFO_STR_LEN 128
 #define MAX_ASSISTANT_NUM 10
 #define ENABLED_ASSISTANTS_URL "db/multi-assistant/enabled_assistants"
@@ -597,6 +602,59 @@ int __ma_cb_audio_streaming(int event, char* buffer, int len)
        }
 #endif
 
+#ifdef BUF_SAVE_MODE
+       static char g_temp_file_name[128] = {'\0',};
+       static FILE* g_pFile = NULL;
+       static int g_count = 1;
+       if (MA_AUDIO_STREAMING_EVENT_START == event) {
+               if (g_pFile) {
+                       fclose(g_pFile);
+                       g_pFile = NULL;
+               } else {
+                       MA_LOGD("[Recorder Info] File not found!");
+               }
+
+               while (1) {
+                       snprintf(g_temp_file_name, sizeof(g_temp_file_name), "/tmp/ma_%d_%d", getpid(), g_count);
+                       int ret = access(g_temp_file_name, 0);
+
+                       if (0 == ret) {
+                               MA_LOGD("[Recorder ERROR] File is already exist");
+                               if (0 == remove(g_temp_file_name)) {
+                                       MA_LOGD("[Recorder] Remove file");
+                                       break;
+                               } else {
+                                       g_count++;
+                               }
+                       } else {
+                               break;
+                       }
+               }
+
+               MA_LOGD("[Recorder] Temp file name=[%s]", g_temp_file_name);
+
+               /* open test file */
+               g_pFile = fopen(g_temp_file_name, "wb+x");
+               if (!g_pFile) {
+                       MA_LOGD("[Recorder ERROR] File not found!");
+               }
+               g_count++;
+       }
+
+       if (g_pFile)
+               fwrite(buffer, 1, len, g_pFile);
+
+       if (MA_AUDIO_STREAMING_EVENT_FINISH == event) {
+               if (g_pFile) {
+                       MA_LOGE("[Recorder SUCCESS] File Close");
+                       fclose(g_pFile);
+                       g_pFile = NULL;
+               } else {
+                       MA_LOGE("[Recorder ERROR] File not found!");
+               }
+       }
+#endif
+
        ma_client_get_audio_streaming_cb(g_ma, &callback, &user_data);
 
        if (NULL != callback) {