Send audio data to the dedicated audio processing app if exists 08/230708/2
authorJi-hoon Lee <dalton.lee@samsung.com>
Mon, 13 Apr 2020 12:25:04 +0000 (21:25 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Mon, 13 Apr 2020 12:29:48 +0000 (21:29 +0900)
Change-Id: Id361946ae510d939acdfc1c5dbb82394be4fab6e

inc/application_manager.h
inc/application_manager_aul.h
inc/service_ipc_dbus.h
inc/service_main.h
src/application_manager_aul.cpp
src/service_ipc_dbus.cpp
src/service_main.cpp
src/service_plugin.cpp
tests/utc/client-manager/test_client_manager.cpp
tests/utc/service-main/test_service_main.cpp

index 1effd84..05bdcca 100644 (file)
@@ -32,6 +32,7 @@ public:
        virtual bool bring_app_to_foreground(const std::string& appid) = 0;
        virtual bool launch_app_async(const std::string& appid, bool background) = 0;
        virtual boost::optional<std::string> get_appid_by_pid(pid_t pid) = 0;
+       virtual boost::optional<pid_t> get_pid_by_appid(const std::string& appid) = 0;
 };
 
 #ifdef __cplusplus
index 4b46f59..9e3bedb 100644 (file)
@@ -34,6 +34,7 @@ public:
        virtual bool bring_app_to_foreground(const std::string& appid) override;
        virtual bool launch_app_async(const std::string& appid, bool background) override;
        virtual boost::optional<std::string> get_appid_by_pid(pid_t pid) override;
+       boost::optional<pid_t> get_pid_by_appid(const std::string& appid) override;
 };
 
 #ifdef __cplusplus
index 9c5e40b..b462aec 100644 (file)
@@ -59,6 +59,9 @@ public:
        void set_client_manager(CClientManager* manager) {
                mClientManager = manager;
        }
+       void set_application_manager(IApplicationManager* manager) {
+               mApplicationManager = manager;
+       }
        void set_service_ipc_observer(IServiceIpcObserver* observer) {
                mDispatcher.set_ipc_observer(observer);
        }
@@ -79,6 +82,7 @@ private:
        int mStreamingDataSerial{0};
 
        CClientManager* mClientManager{nullptr};
+       IApplicationManager* mApplicationManager{nullptr};
 };
 
 #ifdef __cplusplus
index a6e0c00..6aed620 100644 (file)
@@ -101,6 +101,7 @@ public:
        int mas_ui_client_change_assistant(const char* appid);
        int mas_get_current_client_pid();
        int mas_get_current_preprocessing_client_pid();
+       pid_t mas_get_current_audio_processing_pid();
        int mas_get_client_pid_by_wakeup_word(const char *wakeup_word);
        int mas_get_client_pid_by_appid(const char *appid);
        std::string mas_get_client_appid_by_pid(int pid);
@@ -177,6 +178,8 @@ private:
 
                ma_preprocessing_allow_mode_e preprocessing_allow_mode;
                char preprocessing_allow_appid[MAX_APPID_LEN];
+
+               boost::optional<std::string> audio_processing_appid;
        } ma_client_info;
 
        ma_client_info mClientInfo[MAX_MACLIENT_INFO_NUM];
index 41ae5f2..6b2ca7a 100644 (file)
@@ -110,3 +110,15 @@ boost::optional<std::string> CApplicationManagerAul::get_appid_by_pid(pid_t pid)
 
        return ret;
 }
+
+boost::optional<pid_t> CApplicationManagerAul::get_pid_by_appid(const std::string& appid)
+{
+       boost::optional<pid_t> ret;
+
+       int pid = aul_app_get_pid(appid.c_str());
+       if (pid >= 0) {
+               ret = pid;
+       }
+
+       return ret;
+}
\ No newline at end of file
index f6fba74..1d176c6 100644 (file)
@@ -244,10 +244,14 @@ int CServiceIpcDbus::send_streaming_audio_data(int pid, int event, void* data, u
                bundle *b = bundle_create();
                if (b) {
                        bundle_add_byte(b, "content", pending_buffer, pending_buffer_size);
-                       int ret = message_port_send_message(
-                               mClientManager->find_client_appid_by_pid(pid).c_str(), message_port, b);
-                       if (MESSAGE_PORT_ERROR_NONE != ret)
-                               masc_message_port_error(ret);
+                       boost::optional<std::string> appid = mApplicationManager->get_appid_by_pid(pid);
+                       if (appid) {
+                               int ret = message_port_send_message((*appid).c_str(), message_port, b);
+                               if (MESSAGE_PORT_ERROR_NONE != ret)
+                                       masc_message_port_error(ret);
+                       } else {
+                               MAS_LOGE("AppID for PID %d not found!!!", pid);
+                       }
 
                        pending_buffer_size = 0;
                        bundle_free(b);
@@ -265,10 +269,14 @@ int CServiceIpcDbus::send_streaming_audio_data(int pid, int event, void* data, u
                bundle *b = bundle_create();
                if (b) {
                        bundle_add_byte(b, "content", buffer, total_size);
-                       int ret = message_port_send_message(
-                               mClientManager->find_client_appid_by_pid(pid).c_str(), message_port, b);
-                       if (MESSAGE_PORT_ERROR_NONE != ret)
-                               masc_message_port_error(ret);
+                       boost::optional<std::string> appid = mApplicationManager->get_appid_by_pid(pid);
+                       if (appid) {
+                               int ret = message_port_send_message((*appid).c_str(), message_port, b);
+                               if (MESSAGE_PORT_ERROR_NONE != ret)
+                                       masc_message_port_error(ret);
+                       } else {
+                               MAS_LOGE("AppID for PID %d not found!!!", pid);
+                       }
 
                        bundle_free(b);
                } else {
index 85cee29..ac58436 100644 (file)
@@ -700,6 +700,23 @@ int CServiceMain::mas_get_current_preprocessing_client_pid()
        return ret;
 }
 
+pid_t CServiceMain::mas_get_current_audio_processing_pid()
+{
+       pid_t ret = -1;
+       if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) {
+               boost::optional<std::string> audio_processing_appid =
+                       mClientInfo[mCurrentClientInfo].audio_processing_appid;
+               if (audio_processing_appid) {
+                       boost::optional<pid_t> optional_pid_t;
+                       optional_pid_t = mApplicationManager.get_pid_by_appid((*audio_processing_appid).c_str());
+                       if (optional_pid_t) {
+                               ret = *optional_pid_t;
+                       }
+               }
+       }
+       return ret;
+}
+
 int CServiceMain::mas_get_client_pid_by_appid(const char *appid)
 {
        int ret = -1;
@@ -1299,6 +1316,7 @@ bool CServiceMain::app_create(void *data)
        mClientManager.set_application_manager(&mApplicationManager);
 
        mServiceIpc.set_client_manager(&mClientManager);
+       mServiceIpc.set_application_manager(&mApplicationManager);
        mServiceIpc.set_service_ipc_observer(this);
 
        mServicePlugin.set_service_ipc(&mServiceIpc);
index f12323e..64dd796 100644 (file)
@@ -352,7 +352,11 @@ static void __audio_streaming_cb(mas_speech_streaming_event_e event, void* buffe
        }
 
        if (service_ipc && service_main) {
-               int pid = service_main->mas_get_current_client_pid();
+               /* First check if we have dedicated audio processing app for current client */
+               pid_t pid = service_main->mas_get_current_audio_processing_pid();
+               /* If not, send audio data to the main client */
+               if (-1 == pid) pid = service_main->mas_get_current_client_pid();
+
                int preprocessing_pid = service_main->mas_get_current_preprocessing_client_pid();
                if (pid == -1) {
                        MAS_LOGE("[ERROR] Fail to retrieve pid of current MA client");
index 7db0af8..73f9cbe 100644 (file)
@@ -31,6 +31,7 @@ public:
        bool bring_app_to_foreground(const std::string& appid) override { return true; }
        bool launch_app_async(const std::string& appid, bool background) override { return true; }
        boost::optional<std::string> get_appid_by_pid(pid_t pid) override { return boost::optional<std::string>{}; }
+       boost::optional<pid_t> get_pid_by_appid(const std::string& appid) override { return boost::optional<pid_t>{-1}; };
 };
 
 class StorageWithNoClient : public testing::Test
index b14cf72..6d8f175 100644 (file)
@@ -42,6 +42,7 @@ public:
                return true;
        }
        boost::optional<std::string> get_appid_by_pid(pid_t pid) override { return boost::optional<std::string>{}; }
+       boost::optional<pid_t> get_pid_by_appid(const std::string& appid) override { return boost::optional<pid_t>{-1}; };
 public:
        boost::optional<std::string> launched_appid;
        boost::optional<bool> launched_option_background;