Make dbus message sending to be executed in main thread 14/220714/3
authorJi-hoon Lee <dalton.lee@samsung.com>
Fri, 20 Dec 2019 10:03:01 +0000 (19:03 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Fri, 20 Dec 2019 10:24:54 +0000 (19:24 +0900)
Change-Id: I04bdf186730cb31556f20ce7753888d7981b0d10

src/multi_assistant_dbus.c
src/multi_assistant_service_plugin.c

index 664a111..eab7619 100644 (file)
@@ -217,7 +217,11 @@ int masc_dbus_send_streaming_audio_data(int pid, int event, unsigned char* data,
                MAS_LOGE("[Dbus ERROR] Fail to Send");
                return -1; // MAS_ERROR_OPERATION_FAILED;
        } else {
-               MAS_LOGD("[Dbus DEBUG] Success to Send utterance stream");
+               static int last_event = -1;
+               if (event != last_event) {
+                       MAS_LOGI("[Dbus DEBUG] Success to Send utterance stream : event (%d)", event);
+               }
+               last_event = event;
                dbus_connection_flush(g_conn_sender);
        }
 
index 6eed1f5..bd9de18 100644 (file)
@@ -272,15 +272,20 @@ static void handle_speech_streaming_event_failure(void *data)
        mas_client_send_recognition_result(0, MA_RECOGNITION_RESULT_EVENT_ERROR);
 }
 
-static void __audio_streaming_cb(mas_speech_streaming_event_e event, unsigned char* buffer, int len, void *user_data)
+static void handle_speech_streaming_event_success(void *data)
 {
-       if (event == MAS_SPEECH_STREAMING_EVENT_FAIL) {
-               ecore_main_loop_thread_safe_call_async(handle_speech_streaming_event_failure, NULL);
+       if (NULL == data) return;
+
+       mas_speech_data* speech_data = data;
+       if (NULL == speech_data->buffer) {
+               free(speech_data);
                return;
        }
+
        static int count = 0;
-       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);
+       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);
        }
        ++count;
 
@@ -289,13 +294,15 @@ static void __audio_streaming_cb(mas_speech_streaming_event_e event, unsigned ch
        if (pid == -1) {
                MAS_LOGE("[ERROR] Fail to retrieve pid of current MA client");
        } else {
-               if (__validate_streaming_event_order(pid, &event)) {
-                       int ret = masc_dbus_send_streaming_audio_data(pid, event, buffer, len);
+               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 (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, event, buffer, len);
+                               int ret = masc_dbus_send_streaming_audio_data(preprocessing_pid,
+                                       speech_data->event, speech_data->buffer, speech_data->len);
                                if (0 != ret) {
                                        MAS_LOGE("[ERROR] Fail to send speech data to preprocessing client, ret(%d)", ret);
                                }
@@ -304,11 +311,10 @@ static void __audio_streaming_cb(mas_speech_streaming_event_e event, unsigned ch
        }
 
 #ifdef BUF_SAVE_MODE
-       /* write pcm buffer */
        if (g_pFile)
-               fwrite(buffer, 1, len, g_pFile);
+               fwrite(speech_data->buffer, 1, speech_data->len, g_pFile);
 
-       if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) {
+       if (MAS_SPEECH_STREAMING_EVENT_FINISH == speech_data->event) {
                if (g_pFile) {
                        MAS_LOGE("[Recorder SUCCESS] File Close");
                        fclose(g_pFile);
@@ -318,6 +324,24 @@ static void __audio_streaming_cb(mas_speech_streaming_event_e event, unsigned ch
                }
        }
 #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)