Revert "Make dbus message sending to be executed in main thread" 95/222495/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Wed, 15 Jan 2020 02:13:52 +0000 (11:13 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Wed, 15 Jan 2020 02:13:52 +0000 (11:13 +0900)
This reverts commit 5afd1db88433ef88f4e167f4adbd2c9d3375665b.

Change-Id: I8d99360d1e3274b95ddb7f9ecc326a8b7fd7053f

src/multi_assistant_service_plugin.c

index bd9de18..6eed1f5 100644 (file)
@@ -272,20 +272,15 @@ static void handle_speech_streaming_event_failure(void *data)
        mas_client_send_recognition_result(0, MA_RECOGNITION_RESULT_EVENT_ERROR);
 }
 
-static void handle_speech_streaming_event_success(void *data)
+static void __audio_streaming_cb(mas_speech_streaming_event_e event, unsigned char* buffer, int len, void *user_data)
 {
-       if (NULL == data) return;
-
-       mas_speech_data* speech_data = data;
-       if (NULL == speech_data->buffer) {
-               free(speech_data);
+       if (event == MAS_SPEECH_STREAMING_EVENT_FAIL) {
+               ecore_main_loop_thread_safe_call_async(handle_speech_streaming_event_failure, NULL);
                return;
        }
-
        static int count = 0;
-       if (speech_data->event != MAS_SPEECH_STREAMING_EVENT_CONTINUE || count % 100 == 0) {
-               MAS_LOGD( "[SUCCESS] __audio_streaming_cb is called, event(%d), buffer(%p), len(%d)",
-                       speech_data->event, speech_data->buffer, speech_data->len);
+       if (event != MAS_SPEECH_STREAMING_EVENT_CONTINUE || count % 100 == 0) {
+               MAS_LOGD( "[SUCCESS] __audio_streaming_cb is called, event(%d), buffer(%p), len(%d)", event, buffer, len);
        }
        ++count;
 
@@ -294,15 +289,13 @@ static void handle_speech_streaming_event_success(void *data)
        if (pid == -1) {
                MAS_LOGE("[ERROR] Fail to retrieve pid of current MA client");
        } else {
-               if (__validate_streaming_event_order(pid, &(speech_data->event))) {
-                       int ret = masc_dbus_send_streaming_audio_data(pid,
-                               speech_data->event, speech_data->buffer, speech_data->len);
+               if (__validate_streaming_event_order(pid, &event)) {
+                       int ret = masc_dbus_send_streaming_audio_data(pid, event, buffer, len);
                        if (0 != ret) {
                                MAS_LOGE("[ERROR] Fail to send speech data, ret(%d)", ret);
                        }
                        if (pid != preprocessing_pid && -1 != preprocessing_pid) {
-                               int ret = masc_dbus_send_streaming_audio_data(preprocessing_pid,
-                                       speech_data->event, speech_data->buffer, speech_data->len);
+                               int ret = masc_dbus_send_streaming_audio_data(preprocessing_pid, event, buffer, len);
                                if (0 != ret) {
                                        MAS_LOGE("[ERROR] Fail to send speech data to preprocessing client, ret(%d)", ret);
                                }
@@ -311,10 +304,11 @@ static void handle_speech_streaming_event_success(void *data)
        }
 
 #ifdef BUF_SAVE_MODE
+       /* write pcm buffer */
        if (g_pFile)
-               fwrite(speech_data->buffer, 1, speech_data->len, g_pFile);
+               fwrite(buffer, 1, len, g_pFile);
 
-       if (MAS_SPEECH_STREAMING_EVENT_FINISH == speech_data->event) {
+       if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) {
                if (g_pFile) {
                        MAS_LOGE("[Recorder SUCCESS] File Close");
                        fclose(g_pFile);
@@ -324,24 +318,6 @@ static void handle_speech_streaming_event_success(void *data)
                }
        }
 #endif
-       free(speech_data->buffer);
-       free(speech_data);
-}
-
-static void __audio_streaming_cb(mas_speech_streaming_event_e event, unsigned char* buffer, int len, void *user_data)
-{
-       if (event == MAS_SPEECH_STREAMING_EVENT_FAIL) {
-               ecore_main_loop_thread_safe_call_async(handle_speech_streaming_event_failure, NULL);
-       } else {
-               mas_speech_data* data = malloc(sizeof(mas_speech_data));
-               if (data) {
-                       data->event = event;
-                       data->buffer = malloc(len);
-                       if (data->buffer) memcpy(data->buffer, buffer, len);
-                       data->len = len;
-                       ecore_main_loop_thread_safe_call_async(handle_speech_streaming_event_success, data);
-               }
-       }
 }
 
 static void __speech_status_cb(mas_speech_status_e status, void *user_data)