Use message port for streaming audio data 40/221640/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Fri, 27 Dec 2019 04:55:56 +0000 (13:55 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Mon, 6 Jan 2020 11:57:49 +0000 (20:57 +0900)
Change-Id: I758966ad20b79f6c43243acd4dcee471dd207284

CMakeLists.txt
inc/multi_assistant_service_client.h
packaging/org.tizen.multi-assistant-service.spec
plugins/wakeup-manager/src/wakeup_audio_manager.cpp
src/multi_assistant_dbus.c
src/multi_assistant_service.c

index 1717bcf..6e4df5c 100644 (file)
@@ -23,6 +23,7 @@ pkg_check_modules(pkgs REQUIRED
        capi-network-connection
        dlog
        ecore
+       capi-message-port
        dbus-1
        glib-2.0
        libxml-2.0
index b6d7f42..bba7085 100644 (file)
@@ -71,6 +71,8 @@ int mas_get_client_pid_by_wakeup_word(const char *wakeup_word);
 
 int mas_get_client_pid_by_appid(const char *appid);
 
+const char* mas_get_client_appid_by_pid(int pid);
+
 bool mas_get_client_custom_ui_option_by_appid(const char *appid);
 
 const char* mas_get_client_appid_by_wakeup_word(const char *wakeup_word);
index 32ad561..714b073 100644 (file)
@@ -19,6 +19,7 @@ BuildRequires: pkgconfig(capi-media-audio-io)
 BuildRequires: pkgconfig(capi-network-connection)
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(ecore)
+BuildRequires: pkgconfig(capi-message-port)
 BuildRequires: pkgconfig(dbus-1)
 BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(libxml-2.0)
index efefeae..b7c9288 100644 (file)
@@ -385,7 +385,6 @@ void CAudioManager::notify_audio_data_recording(long time, void* data, int len)
                if (observer) {
                        if (!observer->on_recording_audio_data(time, data, len)) {
                                LOGE("[Recorder WARNING] One of the observer returned false");
-                               return;
                        }
                }
        }
index 34de016..72d3eda 100644 (file)
@@ -18,6 +18,7 @@
 #include <dirent.h>
 #include <dlfcn.h>
 #include <Ecore.h>
+#include <message_port.h>
 
 #include "multi_assistant_main.h"
 #include "multi_assistant_dbus_server.h"
@@ -28,6 +29,8 @@ static DBusConnection* g_conn_listener = NULL;
 
 static Ecore_Fd_Handler* g_dbus_fd_handler = NULL;
 
+static int g_streaming_data_serial = 0;
+
 int mas_dbus_reconnect()
 {
        if (!g_conn_sender || !g_conn_listener) {
@@ -173,59 +176,72 @@ int masc_dbus_send_error_message(int reason, const char* err_msg)
        return 0;
 }
 
-int masc_dbus_send_streaming_audio_data(int pid, int event, unsigned char* data, unsigned int data_size)
-{
-       if (0 != __dbus_check()) {
-               return -1; //MAS_ERROR_OPERATION_FAILED;
-       }
-
-       DBusMessage* msg;
-       DBusError err;
-       dbus_error_init(&err);
+const char *message_port = "ma_streaming_port";
 
-       char service_name[64];
-       memset(service_name, '\0', 64);
-       snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
+#define STREAMING_BUFFER_SIZE 4096
 
-       msg = dbus_message_new_method_call(
-                       service_name,
-                       MA_CLIENT_SERVICE_OBJECT_PATH,
-                       MA_CLIENT_SERVICE_INTERFACE,
-                       MAS_METHOD_STREAMING_AUDIO_DATA);
+typedef enum {
+       streaming_data_type_audio_data,
+       streaming_data_type_streaming_section
+} streaming_data_type_e;
 
-       static int count = 0;
-       if (NULL == msg) {
-               MAS_LOGE(">>>> Request mas send utterance stream : Fail to make message");
-               return -1; // MAS_ERROR_OPERATION_FAILED;
-       } else {
-               MAS_LOGD(">>>> Request mas send utterance stream : %s event(%d) %d", service_name, event, count++);
-       }
+typedef struct {
+       unsigned int streaming_data_size;
+       int streaming_data_type;
+       int streaming_data_serial;
+} streaming_data_header;
 
-       if (true != dbus_message_append_args(msg,
-               DBUS_TYPE_INT32, &event,
-               DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
-               &data, data_size,
-               DBUS_TYPE_INVALID)) {
-               dbus_message_unref(msg);
-               MAS_LOGE("[ERROR] Fail to append args");
-               return -1;
-       }
+typedef struct {
+       int event;
+       unsigned int data_size;
+} streaming_data_audio_data_header;
 
-       dbus_message_set_no_reply(msg, TRUE);
+typedef struct {
+       int section;
+} streaming_data_streaming_section_header;
 
-       if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
-               MAS_LOGE("[Dbus ERROR] Fail to Send");
-               return -1; // MAS_ERROR_OPERATION_FAILED;
-       } else {
-               static int last_event = -1;
-               if (event != last_event) {
-                       MAS_LOGI("[Dbus DEBUG] Success to Send utterance stream : %d event (%d)", pid, event);
-               }
-               last_event = event;
-               dbus_connection_flush(g_conn_sender);
-       }
+void masc_message_port_error(int error)
+{
+       MAS_LOGE("message_port error found : %s",
+               (MESSAGE_PORT_ERROR_NONE == error) ? "MESSAGE_PORT_ERROR_NONE" :
+               (MESSAGE_PORT_ERROR_IO_ERROR == error) ? "MESSAGE_PORT_ERROR_IO_ERROR" :
+               (MESSAGE_PORT_ERROR_OUT_OF_MEMORY == error) ? "MESSAGE_PORT_ERROR_OUT_OF_MEMORY" :
+               (MESSAGE_PORT_ERROR_INVALID_PARAMETER == error) ? "MESSAGE_PORT_ERROR_INVALID_PARAMETER" :
+               (MESSAGE_PORT_ERROR_PORT_NOT_FOUND == error) ? "MESSAGE_PORT_ERROR_PORT_NOT_FOUND" :
+               (MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH == error) ? "MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH" :
+               (MESSAGE_PORT_ERROR_MAX_EXCEEDED == error) ? "MESSAGE_PORT_ERROR_MAX_EXCEEDED" :
+               (MESSAGE_PORT_ERROR_RESOURCE_UNAVAILABLE == error) ? "MESSAGE_PORT_ERROR_RESOURCE_UNAVAILABLE" :
+               "MESSAGE_PORT_ERROR_UNKNOWN");
+}
 
-       dbus_message_unref(msg);
+int masc_dbus_send_streaming_audio_data(int pid, int event, unsigned char* data, unsigned int data_size)
+{
+       bundle *b = bundle_create();
+
+       streaming_data_header header;
+       header.streaming_data_type = 0;
+       header.streaming_data_size = sizeof(streaming_data_header) + sizeof(streaming_data_audio_data_header) + data_size;
+       header.streaming_data_serial = g_streaming_data_serial++;
+
+       streaming_data_audio_data_header audio_data_header;
+       audio_data_header.event = event;
+       audio_data_header.data_size = data_size;
+
+       unsigned char buffer[STREAMING_BUFFER_SIZE];
+       size_t total_size = 0;
+       memcpy(buffer, &header, sizeof(header));
+       total_size += sizeof(header);
+       memcpy(buffer + total_size, &audio_data_header, sizeof(audio_data_header));
+       total_size += sizeof(audio_data_header);
+       memcpy(buffer + total_size, data, data_size);
+       total_size += data_size;
+
+       bundle_add_byte(b, "content", buffer, total_size);
+       int ret = message_port_send_message(mas_get_client_appid_by_pid(pid), message_port, b);
+       if (MESSAGE_PORT_ERROR_NONE != ret)
+               masc_message_port_error(ret);
+
+       bundle_free(b);
        return 0;
 }
 
@@ -347,52 +363,30 @@ int masc_dbus_send_preprocessing_information(int pid, const char* app_id)
 
 int masc_dbus_send_streaming_section_changed(int pid, int section)
 {
-       if (0 != __dbus_check()) {
-               return -1; //MAS_ERROR_OPERATION_FAILED;
-       }
+       static int serial = 0;
+       bundle *b = bundle_create();
 
-       DBusMessage* msg;
+       streaming_data_header header;
+       header.streaming_data_type = 1;
+       header.streaming_data_size = sizeof(streaming_data_header) + sizeof(streaming_data_streaming_section_header);
+       header.streaming_data_serial = g_streaming_data_serial++;
 
-       DBusError err;
-       dbus_error_init(&err);
+       streaming_data_streaming_section_header streaming_section_header;
+       streaming_section_header.section = section;
 
-       char service_name[64];
-       memset(service_name, '\0', 64);
-       snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
+       unsigned char buffer[STREAMING_BUFFER_SIZE];
+       size_t total_size = 0;
+       memcpy(buffer, &header, sizeof(header));
+       total_size += sizeof(header);
+       memcpy(buffer + total_size, &streaming_section_header, sizeof(streaming_section_header));
+       total_size += sizeof(streaming_section_header);
 
-       msg = dbus_message_new_method_call(
-                       service_name,
-                       MA_CLIENT_SERVICE_OBJECT_PATH,
-                       MA_CLIENT_SERVICE_INTERFACE,
-                       MAS_METHOD_AUDIO_STREAMING_DATA_SECTION);
+       bundle_add_byte(b, "content", buffer, total_size);
+       int ret = message_port_send_message(mas_get_client_appid_by_pid(pid), message_port, b);
+       if (MESSAGE_PORT_ERROR_NONE != ret)
+               masc_message_port_error(ret);
 
-       static int count = 0;
-       if (NULL == msg) {
-               MAS_LOGE(">>>> Request mas send streaming section changed information : Fail to make message");
-               return -1; // MAS_ERROR_OPERATION_FAILED;
-       } else {
-               MAS_LOGD(">>>> Request mas send streaming section changed information : %s", service_name);
-       }
-
-       if (true != dbus_message_append_args(msg,
-               DBUS_TYPE_INT32, &section,
-               DBUS_TYPE_INVALID)) {
-               dbus_message_unref(msg);
-               MAS_LOGE("[ERROR] Fail to append args");
-               return -1;
-       }
-
-       dbus_message_set_no_reply(msg, TRUE);
-
-       if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
-               MAS_LOGE("[Dbus ERROR] Fail to Send");
-               return -1; // MAS_ERROR_OPERATION_FAILED;
-       } else {
-               MAS_LOGI("[Dbus DEBUG] Success to Send streaming section changed information : %d %d", pid, section);
-               dbus_connection_flush(g_conn_sender);
-       }
-
-       dbus_message_unref(msg);
+       bundle_free(b);
 
        return 0;
 }
@@ -1115,7 +1109,6 @@ int mas_dbus_open_connection()
                MAS_LOGD("Get fd from dbus : %d", fd);
        }
 
-
        g_dbus_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn_listener, NULL, NULL);
 
        if (NULL == g_dbus_fd_handler) {
index d07cf18..08f0435 100644 (file)
@@ -96,7 +96,6 @@ int ma_client_create(ma_client_s *info)
        }
 
        *data = *info;
-
        g_client_list = g_slist_append(g_client_list, data);
 
        return 0;
@@ -892,6 +891,27 @@ int mas_get_client_pid_by_appid(const char *appid)
        return ret;
 }
 
+const char* mas_get_client_appid_by_pid(int pid)
+{
+       const char* ret = NULL;
+
+       ma_client_s *client = NULL;
+       client = ma_client_find_by_pid(pid);
+       if (client) {
+               ret = client->appid;
+       }
+
+       int status = aul_app_get_status_bypid(pid);
+       if (-1 != ret && 0 > status) {
+               MAS_LOGE("The appid for %d was %s, but it seems to be terminated : %d",
+                       pid, (ret ? ret : "NULL"), status);
+               mas_client_deinitialize(pid);
+               ret = NULL;
+       }
+
+       return ret;
+}
+
 bool mas_get_client_custom_ui_option_by_appid(const char *appid)
 {
        bool ret = false;