From 702ab10c82b63ed4cf02def6690918ef1f864bfa Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 13 Apr 2020 21:25:04 +0900 Subject: [PATCH] Send audio data to the dedicated audio processing app if exists Change-Id: Id361946ae510d939acdfc1c5dbb82394be4fab6e --- inc/application_manager.h | 1 + inc/application_manager_aul.h | 1 + inc/service_ipc_dbus.h | 4 ++++ inc/service_main.h | 3 +++ src/application_manager_aul.cpp | 12 ++++++++++++ src/service_ipc_dbus.cpp | 24 ++++++++++++++++-------- src/service_main.cpp | 18 ++++++++++++++++++ src/service_plugin.cpp | 6 +++++- tests/utc/client-manager/test_client_manager.cpp | 1 + tests/utc/service-main/test_service_main.cpp | 1 + 10 files changed, 62 insertions(+), 9 deletions(-) diff --git a/inc/application_manager.h b/inc/application_manager.h index 1effd84..05bdcca 100644 --- a/inc/application_manager.h +++ b/inc/application_manager.h @@ -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 get_appid_by_pid(pid_t pid) = 0; + virtual boost::optional get_pid_by_appid(const std::string& appid) = 0; }; #ifdef __cplusplus diff --git a/inc/application_manager_aul.h b/inc/application_manager_aul.h index 4b46f59..9e3bedb 100644 --- a/inc/application_manager_aul.h +++ b/inc/application_manager_aul.h @@ -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 get_appid_by_pid(pid_t pid) override; + boost::optional get_pid_by_appid(const std::string& appid) override; }; #ifdef __cplusplus diff --git a/inc/service_ipc_dbus.h b/inc/service_ipc_dbus.h index 9c5e40b..b462aec 100644 --- a/inc/service_ipc_dbus.h +++ b/inc/service_ipc_dbus.h @@ -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 diff --git a/inc/service_main.h b/inc/service_main.h index a6e0c00..6aed620 100644 --- a/inc/service_main.h +++ b/inc/service_main.h @@ -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 audio_processing_appid; } ma_client_info; ma_client_info mClientInfo[MAX_MACLIENT_INFO_NUM]; diff --git a/src/application_manager_aul.cpp b/src/application_manager_aul.cpp index 41ae5f2..6b2ca7a 100644 --- a/src/application_manager_aul.cpp +++ b/src/application_manager_aul.cpp @@ -110,3 +110,15 @@ boost::optional CApplicationManagerAul::get_appid_by_pid(pid_t pid) return ret; } + +boost::optional CApplicationManagerAul::get_pid_by_appid(const std::string& appid) +{ + boost::optional ret; + + int pid = aul_app_get_pid(appid.c_str()); + if (pid >= 0) { + ret = pid; + } + + return ret; +} \ No newline at end of file diff --git a/src/service_ipc_dbus.cpp b/src/service_ipc_dbus.cpp index f6fba74..1d176c6 100644 --- a/src/service_ipc_dbus.cpp +++ b/src/service_ipc_dbus.cpp @@ -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 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 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 { diff --git a/src/service_main.cpp b/src/service_main.cpp index 85cee29..ac58436 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -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 audio_processing_appid = + mClientInfo[mCurrentClientInfo].audio_processing_appid; + if (audio_processing_appid) { + boost::optional 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); diff --git a/src/service_plugin.cpp b/src/service_plugin.cpp index f12323e..64dd796 100644 --- a/src/service_plugin.cpp +++ b/src/service_plugin.cpp @@ -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"); diff --git a/tests/utc/client-manager/test_client_manager.cpp b/tests/utc/client-manager/test_client_manager.cpp index 7db0af8..73f9cbe 100644 --- a/tests/utc/client-manager/test_client_manager.cpp +++ b/tests/utc/client-manager/test_client_manager.cpp @@ -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 get_appid_by_pid(pid_t pid) override { return boost::optional{}; } + boost::optional get_pid_by_appid(const std::string& appid) override { return boost::optional{-1}; }; }; class StorageWithNoClient : public testing::Test diff --git a/tests/utc/service-main/test_service_main.cpp b/tests/utc/service-main/test_service_main.cpp index b14cf72..6d8f175 100644 --- a/tests/utc/service-main/test_service_main.cpp +++ b/tests/utc/service-main/test_service_main.cpp @@ -42,6 +42,7 @@ public: return true; } boost::optional get_appid_by_pid(pid_t pid) override { return boost::optional{}; } + boost::optional get_pid_by_appid(const std::string& appid) override { return boost::optional{-1}; }; public: boost::optional launched_appid; boost::optional launched_option_background; -- 2.7.4