From f7e29206f63faebdd6be448773dc9de2af8ad57e Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 25 Jul 2022 14:29:28 +0900 Subject: [PATCH 01/16] Fix issue detected by static analysis tool Change-Id: I573bfa8478cad77c9f38f4eaa00304ea2d854bfa --- plugins/wakeup-manager/src/wakeup_settings.cpp | 4 ++++ src/service_plugin.cpp | 21 ++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/plugins/wakeup-manager/src/wakeup_settings.cpp b/plugins/wakeup-manager/src/wakeup_settings.cpp index be28afe..e501e31 100644 --- a/plugins/wakeup-manager/src/wakeup_settings.cpp +++ b/plugins/wakeup-manager/src/wakeup_settings.cpp @@ -341,6 +341,10 @@ string CWakeupSettings::get_default_assistant_appid() void CWakeupSettings::set_default_assistant_appid(std::string appid) { + if (appid.empty()) { + MWR_LOGE("appid is NULL"); + return; + } if (appid.compare(get_default_assistant_appid()) == 0) { MWR_LOGE("Default assistant appid not changed, ignoring..."); return; diff --git a/src/service_plugin.cpp b/src/service_plugin.cpp index 780390a..706652d 100644 --- a/src/service_plugin.cpp +++ b/src/service_plugin.cpp @@ -39,12 +39,12 @@ static int g_last_wakeup_event_id = 0; typedef struct { int id; - char* wakeup_word; - char* wakeup_appid; - unsigned char* extra_data; - size_t extra_data_length; - char* extra_data_desc; - CServicePlugin* plugin; + char* wakeup_word{nullptr}; + char* wakeup_appid{nullptr}; + unsigned char* extra_data{nullptr}; + size_t extra_data_length{0}; + char* extra_data_desc{nullptr}; + CServicePlugin* plugin{nullptr}; } AsyncParam; bool CServicePlugin::is_ui_panel_enabled() @@ -209,7 +209,11 @@ static void process_wakeup_event_by_word_timer(void* data) param->id = id; param->wakeup_word = strdup(wakeup_word.c_str()); param->wakeup_appid = strdup(appid); - param->extra_data = extra_data; + if (extra_data && extra_data_length > 0) { + param->extra_data = (unsigned char*)malloc(extra_data_length); + if (param->extra_data) + memcpy(param->extra_data, extra_data, extra_data_length); + } param->extra_data_length = extra_data_length; param->extra_data_desc = strdup(extra_data_desc.c_str()); param->plugin = plugin; @@ -217,6 +221,9 @@ static void process_wakeup_event_by_word_timer(void* data) } } + free(extra_data); + extra_data = nullptr; + MAS_LOGI("END"); return; } -- 2.7.4 From 161fa2eedf17fdf3493ff39cc09e666445ebd9ea Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 25 Jul 2022 15:27:30 +0900 Subject: [PATCH 02/16] Bump version to 0.3.36 Change-Id: Id0a6a7523197ff665329ab7e5e988c91d6bb1dd7 --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index 7663e19..aa846c3 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 45657db..9b71477 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.3.35 +Version: 0.3.36 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4 From 9fed45c084cb559463492ea716fb8b7a4fba544f Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 8 Aug 2022 13:54:32 +0900 Subject: [PATCH 03/16] Fix issue detected by static analysis tool Change-Id: I3d296586e161a2a024b301c1ef21e2f406799109 --- src/service_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/service_main.cpp b/src/service_main.cpp index c670fdd..ceee5c6 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -937,7 +937,7 @@ const char* CServiceMain::get_client_appid_by_wakeup_word(const char *wakeup_wor 0 < strlen(items[loop].appid)) { for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) { if (0 < strlen(items[loop].wakeup_word[inner_loop])) { - char comparand[MAX_WAKEUP_WORD_LEN]; + char comparand[MAX_WAKEUP_WORD_LEN] = {0, }; int comparand_index = 0; for (int index = 0; index < MAX_WAKEUP_WORD_LEN; index++) { if (' ' != items[loop].wakeup_word[inner_loop][index]) { @@ -986,7 +986,7 @@ int CServiceMain::set_current_client_by_wakeup_word(const char *wakeup_word) 0 < strlen(items[loop].appid)) { for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) { if (0 < strlen(items[loop].wakeup_word[inner_loop])) { - char comparand[MAX_WAKEUP_WORD_LEN]; + char comparand[MAX_WAKEUP_WORD_LEN] = {0, }; int comparand_index = 0; for (int index = 0; index < MAX_WAKEUP_WORD_LEN; index++) { if (' ' != items[loop].wakeup_word[inner_loop][index]) { -- 2.7.4 From 31bfb36ae46873cd7e4bd4e21166a531a96b7673 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 22 Sep 2022 16:40:19 +0900 Subject: [PATCH 04/16] Change log level for debugging Change-Id: I3050e5e4e9febd52d2adf131566cb3e90a9438af --- plugins/wakeup-manager/src/wakeup_manager.cpp | 8 ++++++++ src/service_main.cpp | 1 + src/service_plugin.cpp | 1 + 3 files changed, 10 insertions(+) diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index 60073e3..ddbb8a2 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -1285,6 +1285,7 @@ bool CWakeupManager::CSettingsEventObserver::on_voice_input_language_changed( bool CWakeupManager::CSettingsEventObserver::on_assistant_enabled_info_changed( const char* appid, bool enabled) { + MWR_LOGE("[ENTER]"); if (nullptr == mWakeupManager || nullptr == appid) return false; mWakeupManager->set_assistant_enabled(std::string(appid), enabled); vector observers = mWakeupManager->get_setting_observers(); @@ -1294,12 +1295,14 @@ bool CWakeupManager::CSettingsEventObserver::on_assistant_enabled_info_changed( else observer->on_value_changed(); } + MWR_LOGE("[END]"); return true; } bool CWakeupManager::CSettingsEventObserver::on_default_assistant_appid_changed( const char* appid) { + MWR_LOGE("[ENTER]"); if (nullptr == mWakeupManager || nullptr == appid) return false; /* Passing 'expected' as false since the change was occurred outside of MAS */ mWakeupManager->process_default_assistant_changed(std::string(appid), false); @@ -1310,26 +1313,31 @@ bool CWakeupManager::CSettingsEventObserver::on_default_assistant_appid_changed( else observer->on_loaded_wakeup_engine_changed(); } + MWR_LOGE("[END]"); return true; } bool CWakeupManager::CSettingsEventObserver::on_multiple_mode_changed() { + MWR_LOGE("[ENTER]"); if (nullptr == mWakeupManager) return false; vector observers = mWakeupManager->get_setting_observers(); for (const auto& observer : observers) { observer->on_loaded_wakeup_engine_changed(); } + MWR_LOGE("[END]"); return true; } bool CWakeupManager::CSettingsEventObserver::on_wake_word_detection_enabled_info_changed() { + MWR_LOGE("[ENTER]"); if (nullptr == mWakeupManager) return false; vector observers = mWakeupManager->get_setting_observers(); for (const auto& observer : observers) { observer->on_loaded_wakeup_engine_changed(); } + MWR_LOGE("[END]"); return true; } diff --git a/src/service_main.cpp b/src/service_main.cpp index ceee5c6..48eb142 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -55,6 +55,7 @@ void CPackageUpdateEventObserver::OnUpdateFinished() void CPackageUpdateEventObserver::OnRestartRequired() { + MAS_LOGE("Restarting service"); service_app_exit(); } diff --git a/src/service_plugin.cpp b/src/service_plugin.cpp index 706652d..67b6779 100644 --- a/src/service_plugin.cpp +++ b/src/service_plugin.cpp @@ -604,6 +604,7 @@ static void __loaded_engine_changed_cb(void* user_data) CServiceMain* service_main = plugin->get_service_main(); if (service_main) { + MAS_LOGE("[SUCCESS] Restarting service"); service_main->app_restart(); } } -- 2.7.4 From baa2ba2b89004da8b64db912c5d729bb33d4f44c Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 29 Sep 2022 09:59:16 +0900 Subject: [PATCH 05/16] Modified not to restart the daemon repeatedly Change-Id: I4fd0822ac19d5cd010a39afe79410e13f4162805 --- plugins/wakeup-manager/src/wakeup_settings.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/wakeup-manager/src/wakeup_settings.cpp b/plugins/wakeup-manager/src/wakeup_settings.cpp index e501e31..d88d81b 100644 --- a/plugins/wakeup-manager/src/wakeup_settings.cpp +++ b/plugins/wakeup-manager/src/wakeup_settings.cpp @@ -17,6 +17,8 @@ static auto contains(const C& v, const T& x) -> decltype(end(v), true) return end(v) != find(begin(v), end(v), x); } +static string prev_wake_word_enabled; + CWakeupSettings::CWakeupSettings() { } @@ -147,6 +149,16 @@ static void wakeup_setting_enabled_wake_word_detection_changed_cb(keynode_t* nod { MWR_LOGD("[ENTER]"); + char *vconf_str = vconf_keynode_get_str(node); + if (!vconf_str) return; + + MWR_LOGI("vconf value : %s", vconf_str); + if (0 == prev_wake_word_enabled.compare(string(vconf_str))) { + return; + } + + prev_wake_word_enabled = string(vconf_str); + CWakeupSettings* settings = static_cast(data); if (nullptr == settings) return; -- 2.7.4 From 1ca407474f6f4dfe7f6a3663ce520d5bfd77584c Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 29 Sep 2022 12:12:24 +0900 Subject: [PATCH 06/16] Bump version to 0.3.37 Change-Id: I5660de15f66039d338edee05bafbd9d05fe3ec01 --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index aa846c3..dda7e64 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 9b71477..ea0576e 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.3.36 +Version: 0.3.37 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4 From 7d3cff07f22746654f0f7e080190ae89150ced33 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 29 Sep 2022 20:33:06 +0900 Subject: [PATCH 07/16] Register package manager event handler before loading wakeup engines If the wakeup engine app gets installed while multi-assistant-service is being launched and also is trying to load wakeup engines, the newly installed wakeup engine will not be loaded since at the time of launching the installation was not completed, and the installation completion event would not be received also, since the package manager event handler might not be registered yet. So if we register package manager event handler first and then load wakeup engines, even if the wakeup engine currently being installed fails to be loaded, the installation completion event is guaranteed to be received by the package manager event handler, making sure that the multi-assistant-service would restart for re-loading. Change-Id: I1e8f57d6a08c9290a0ae11422d1404188c97c3df --- src/package_update_monitor.cpp | 20 ++++++++++++++------ src/service_main.cpp | 4 ++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/package_update_monitor.cpp b/src/package_update_monitor.cpp index 112fff8..c2c74ff 100644 --- a/src/package_update_monitor.cpp +++ b/src/package_update_monitor.cpp @@ -42,7 +42,7 @@ void CPackageUpdateMonitor::initialize() ret = package_manager_set_event_cb(mHandle, CPackageUpdateMonitor::package_manager_event_cb, this); if (ret == PACKAGE_MANAGER_ERROR_NONE) { - LOGD("package_manager_set_event_cb succeeded."); + LOGE("package_manager_set_event_cb succeeded : %p", mHandle); } else { LOGE("package_manager_set_event_cb failed(%d)", ret); } @@ -74,7 +74,7 @@ static bool is_wakeup_engine(const pkgmgrinfo_appinfo_h handle, CPackageUpdateMo for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM;loop++) { if (clientInfo.getItems()[loop].used) { for (int inner_loop = 0;inner_loop < MAX_WAKEUP_ENGINES_NUM;inner_loop++) { - LOGD("comparing appid : %s %s", clientInfo.getItems()[loop].wakeup_engine[inner_loop], appid); + LOGI("comparing appid : %s %s", clientInfo.getItems()[loop].wakeup_engine[inner_loop], appid); if (0 == strncmp(clientInfo.getItems()[loop].wakeup_engine[inner_loop], appid, MAX_APPID_LEN)) { is_wakeup_engine = true; } @@ -85,6 +85,7 @@ static bool is_wakeup_engine(const pkgmgrinfo_appinfo_h handle, CPackageUpdateMo LOGE("pkgmgrinfo_appinfo_get_appid failed! error code=%d", ret); } + LOGI("Returning : %d", is_wakeup_engine); return is_wakeup_engine; } @@ -99,6 +100,7 @@ static bool is_voice_assistant(const pkgmgrinfo_appinfo_h handle, CPackageUpdate } else { LOGE("pkgmgrinfo_appinfo_get_metadata_value failed! error code=%d", ret); } + LOGI("Returning : %d", is_voice_assistant); return is_voice_assistant; } @@ -152,21 +154,26 @@ void CPackageUpdateMonitor::package_manager_event_cb(const char *type, const cha bool should_exit = false; bool pkginfo_found = true; - if (!package || !type) + if (!package || !type){ + LOGE("Package name or type info is NULL"); return; + } if (PACKAGE_MANAGER_EVENT_TYPE_UPDATE != event_type && PACKAGE_MANAGER_EVENT_TYPE_INSTALL != event_type && - PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL != event_type) + PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL != event_type) { + LOGE("Unexpected event type : %d", event_type); return; + } if (PACKAGE_MANAGER_EVENT_STATE_STARTED != event_state && PACKAGE_MANAGER_EVENT_STATE_COMPLETED != event_state && - PACKAGE_MANAGER_EVENT_STATE_FAILED != event_state) + PACKAGE_MANAGER_EVENT_STATE_FAILED != event_state) { return; + } bool user = false; - LOGD("type=%s package=%s event_type=%d event_state=%d progress=%d error=%d", + LOGI("type=%s package=%s event_type=%d event_state=%d progress=%d error=%d", type, package, event_type, event_state, progress, error); ret = pkgmgrinfo_pkginfo_get_pkginfo(package, &handle); if (ret != PMINFO_R_OK || NULL == handle) { @@ -199,6 +206,7 @@ void CPackageUpdateMonitor::package_manager_event_cb(const char *type, const cha LOGW("Failed to get pkg list from pkginfo, returned %d", ret); } } + LOGI("filter_result : %d", filter_result); } else { /* Even if we failed acquiring the pkginfo, proceed if we're uninstalling since at the time of uninstall completion, pkginfo would not exist */ diff --git a/src/service_main.cpp b/src/service_main.cpp index 48eb142..14cb54b 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -1384,6 +1384,8 @@ bool CServiceMain::app_create(void *data) return false; } + mPackageUpdateMonitor.initialize(); + initialize_service_plugin(); process_activated_setting(); @@ -1400,8 +1402,6 @@ bool CServiceMain::app_create(void *data) nullptr, 0, nullptr, CLIENT_LAUNCH_MODE_PRELAUNCH); } - mPackageUpdateMonitor.initialize(); - MAS_LOGE("[END] Service app create"); return true; } -- 2.7.4 From 65571ab8e74036f3470137582d574e48620fc6e5 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 24 Oct 2022 11:31:38 +0900 Subject: [PATCH 08/16] Skip application running check when acquiring PID or AppID Since the application running check is already performed when wakeup event gets processed, there is no need to check the running status every time PID or AppID is acquired. Change-Id: If93f64f67cfde458123fca6c16f18713fd5118e8 --- src/application_manager_aul.cpp | 23 ++++++++++++++++++++++- src/client_manager.cpp | 16 ++-------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/application_manager_aul.cpp b/src/application_manager_aul.cpp index 782448b..e2e293e 100644 --- a/src/application_manager_aul.cpp +++ b/src/application_manager_aul.cpp @@ -17,6 +17,8 @@ #include "application_manager_aul.h" #include "service_common.h" +#include + #include #include @@ -28,19 +30,38 @@ CApplicationManagerAul::~CApplicationManagerAul() { } +static void print_duration(std::string func, std::chrono::time_point started) +{ + const std::chrono::milliseconds threshold(100); + auto finished = std::chrono::steady_clock::now(); + auto interval = finished - started; + if (interval > threshold) { + long long int count = static_cast( + std::chrono::duration_cast(interval).count()); + MAS_LOGE("%s %lld", func.c_str(), count); + } +} + bool CApplicationManagerAul::is_application_running(pid_t pid) { + auto started = std::chrono::steady_clock::now(); + int status = aul_app_get_status_bypid(pid); if (0 > status) { MAS_LOGE("The process %d does not exist : %d", pid, status); + print_duration(__func__, started); return false; } + print_duration(__func__, started); return true; } bool CApplicationManagerAul::is_application_running(const std::string& appid) { - return (!!aul_app_is_running(appid.c_str())); + auto started = std::chrono::steady_clock::now(); + bool ret = (!!aul_app_is_running(appid.c_str())); + print_duration(__func__, started); + return ret; } bool CApplicationManagerAul::bring_app_to_foreground(const std::string& appid) diff --git a/src/client_manager.cpp b/src/client_manager.cpp index 458c384..9bd575b 100644 --- a/src/client_manager.cpp +++ b/src/client_manager.cpp @@ -149,13 +149,7 @@ pid_t CClientManager::find_client_pid_by_appid(std::string appid) ma_client_s* client = find_client_by_appid(appid); if (client) { - bool running = mApplicationManager->is_application_running(client->pid); - if (false == running) { - MAS_LOGE("The PID for %s was %d, but it seems to be terminated", - appid.c_str(), client->pid); - } else { - pid = client->pid; - } + pid = client->pid; } if (-1 == pid) { MAS_LOGE("PID lookup failed for : %s", appid.c_str()); @@ -174,13 +168,7 @@ std::string CClientManager::find_client_appid_by_pid(pid_t pid) ma_client_s* client = find_client_by_pid(pid); if (client) { - bool running = mApplicationManager->is_application_running(pid); - if (false == running) { - MAS_LOGE("The appid for %d was %s, but it seems to be terminated", - pid, client->appid.c_str()); - } else { - appid = client->appid; - } + appid = client->appid; } return appid; } -- 2.7.4 From 28fe4a4d91258f8a4f1f1a7db87a657f947e1be2 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 30 Nov 2022 15:46:51 +0900 Subject: [PATCH 09/16] Prevent restarting service when conversation session exists Change-Id: I79771d40e67e2bda2efdd6a50474ef500fd5230c --- src/service_plugin.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/service_plugin.cpp b/src/service_plugin.cpp index 67b6779..0df29ed 100644 --- a/src/service_plugin.cpp +++ b/src/service_plugin.cpp @@ -604,8 +604,15 @@ static void __loaded_engine_changed_cb(void* user_data) CServiceMain* service_main = plugin->get_service_main(); if (service_main) { - MAS_LOGE("[SUCCESS] Restarting service"); - service_main->app_restart(); + /* Make sure the app doesn't restart within a conversation session */ + ma_service_state_e service_state = service_main->get_current_service_state(); + if (service_state == MA_SERVICE_STATE_INACTIVE || + service_state == MA_SERVICE_STATE_LISTENING) { + MAS_LOGE("[SUCCESS] Restarting service"); + service_main->app_restart(); + } else { + MAS_LOGE("Cannot restart service when service_state is %d", service_state); + } } } -- 2.7.4 From b024d6c4d2e9742a3bb2dbe31833dffa1cc7efe3 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 30 Nov 2022 18:05:43 +0900 Subject: [PATCH 10/16] Reduce blocking time when streaming audio data When the CPU is busy handling many tasks, there are times that the streaming thread gets blocked while calling some undelying platform API functions. To avoid this problem, applied several methods for reducing the blocking time and added log messages for displaying time information. List of methods used for reducing the blocking time: 1. Cache appid / pid information that is acquired by calling AUL API functions, since they sometimes do not return immediately and take a while to complete. 2. Instead of passing a pointer to the shared audio data into the message transmission module while holding the lock to protect the shared audio data, make a copy of audio data and release the lock immediately so that the copy of audio data can be used without the risk of race condition. This is because sometimes the message transmission also takes a bit of time to complete, and the other threads waiting for the lock cannot proceed in such cases. Change-Id: I6c6959fadddbc557dbb77849fa25ce4949155f4b --- inc/service_common.h | 3 + .../wakeup-manager/src/wakeup_audio_manager.cpp | 77 ++++++++++++++++++++-- src/application_manager_aul.cpp | 56 +++++++++++++--- src/service_ipc_dbus.cpp | 71 ++++++++++++++++++++ src/service_plugin.cpp | 45 +++++++++++++ 5 files changed, 237 insertions(+), 15 deletions(-) diff --git a/inc/service_common.h b/inc/service_common.h index 2a3ff4f..58bbf7c 100644 --- a/inc/service_common.h +++ b/inc/service_common.h @@ -6,6 +6,9 @@ #include #include +// Enable this macro for profiling with detailed timeinfo +// #define PRINT_DETAILED_TIMEINFO + #ifdef LOG_TAG #undef LOG_TAG #endif diff --git a/plugins/wakeup-manager/src/wakeup_audio_manager.cpp b/plugins/wakeup-manager/src/wakeup_audio_manager.cpp index b05fcc8..8bab1d6 100644 --- a/plugins/wakeup-manager/src/wakeup_audio_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_audio_manager.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -23,6 +24,11 @@ namespace wakeup /* Need to check whether this value needs to be configurable */ static int g_speech_pcm_wait_count = 800; +#ifdef PRINT_DETAILED_TIMEINFO +static atomic_int g_mutex_wait_index{0}; +static map g_mutex_wait_time; +#endif + static long long get_current_milliseconds_after_epoch() { auto now = chrono::steady_clock::now(); @@ -33,6 +39,17 @@ static long long get_current_milliseconds_after_epoch() return value.count(); } +#ifdef PRINT_DETAILED_TIMEINFO +static std::string get_current_milliseconds_after_epoch(chrono::time_point point) +{ + auto now_ms = chrono::time_point_cast(point); + /* number of milliseconds since the epoch of system_clock */ + auto value = now_ms.time_since_epoch(); + + return std::to_string(value.count()); +} +#endif + CAudioManager::CAudioManager() { } @@ -253,6 +270,9 @@ void CAudioManager::streaming_audio_data_thread_func(long long start_time) lock.unlock(); while (!(mStopStreamingThread.load())) { + const size_t SEND_BUFFER_SIZE = 4096; + unsigned char send_buffer[SEND_BUFFER_SIZE]; + int ret = -1; int cnt = 0; @@ -318,14 +338,37 @@ void CAudioManager::streaming_audio_data_thread_func(long long start_time) if (lead != end) { iter = lead; - mas_speech_data& speech_data = iter->data; + + mas_speech_data speech_data = iter->data; + size_t len = speech_data.len; + if (len > SEND_BUFFER_SIZE) { + LOGE("ERROR : SPEECH DATA contains data bigger than the buffer size : %d, truncating", len); + len = SEND_BUFFER_SIZE; + } + memcpy(send_buffer, speech_data.buffer, len); + speech_data.buffer = send_buffer; + speech_data.len = len; + lock.unlock(); + for (const auto& observer : observers) { if (observer) { validate_audio_data_event_field(speech_data); + +#ifdef PRINT_DETAILED_TIMEINFO + auto started = std::chrono::steady_clock::now(); +#endif if (!observer->on_streaming_audio_data( speech_data.event, speech_data.buffer, speech_data.len)) { LOGE("[Recorder WARNING] One of the observer returned false"); } +#ifdef PRINT_DETAILED_TIMEINFO + auto finished = std::chrono::steady_clock::now(); + auto interval = finished - started; + long long int count = static_cast( + chrono::duration_cast(interval).count()); + int index = g_mutex_wait_index; + g_mutex_wait_time[index] += count; +#endif } } @@ -336,8 +379,9 @@ void CAudioManager::streaming_audio_data_thread_func(long long start_time) } advance(lead, 1); + } else { + lock.unlock(); } - lock.unlock(); } if (true != finish_event_sent) { @@ -359,8 +403,29 @@ void CAudioManager::streaming_audio_data_thread_func(long long start_time) MWR_LOGE("[EXIT]"); } +#ifdef PRINT_DETAILED_TIMEINFO +static void print_duration(std::chrono::time_point started) +{ + const std::chrono::milliseconds threshold(100); + auto finished = std::chrono::steady_clock::now(); + auto interval = finished - started; + if (interval > threshold) { + long long int count = static_cast( + std::chrono::duration_cast(interval).count()); + int index = g_mutex_wait_index; + MAS_LOGE("Mutex wait time : %d %lld %lld, [%s~]", index, count, + g_mutex_wait_time[index], + get_current_milliseconds_after_epoch(started).c_str()); + } +} +#endif + void CAudioManager::add_audio_data(mas_speech_data& data, long long time) { +#ifdef PRINT_DETAILED_TIMEINFO + ++g_mutex_wait_index; +#endif + long long delta = mAudioRecordingDurationMilliseconds; bool print_log = false; @@ -416,6 +481,10 @@ void CAudioManager::add_audio_data(mas_speech_data& data, long long time) lock_guard lock(mMutex); +#ifdef PRINT_DETAILED_TIMEINFO + print_duration(now); +#endif + /* Pop items only when the streaming is not activated */ if (!mStreamingThreadActive.load()) { while(false == mAudioData.empty() && mAudioData.front().time < time - delta) { @@ -483,9 +552,7 @@ void CAudioManager::notify_audio_data_recording(long time, void* data, int len) lock.unlock(); for (const auto& observer : observers) { if (observer) { - if (!observer->on_recording_audio_data(time, data, len)) { - LOGE("[Recorder WARNING] One of the observer returned false"); - } + observer->on_recording_audio_data(time, data, len); } } } diff --git a/src/application_manager_aul.cpp b/src/application_manager_aul.cpp index e2e293e..ea0d759 100644 --- a/src/application_manager_aul.cpp +++ b/src/application_manager_aul.cpp @@ -18,6 +18,7 @@ #include "service_common.h" #include +#include #include #include @@ -128,14 +129,32 @@ boost::optional CApplicationManagerAul::get_appid_by_pid(pid_t pid) int retry_num = 0; char appid[MAX_APPID_LEN] = {'\0', }; - do { - if (AUL_R_OK == aul_app_get_appid_bypid(pid, appid, sizeof(appid))) { - appid[MAX_APPID_LEN - 1] = '\0'; - ret = std::string{appid}; - succeeded = true; + typedef struct { + std::string appid; + std::chrono::time_point updated; + } AppInfo; + + static std::map appids; + if (appids.find(pid) != appids.end()) { + auto info = appids[pid]; + auto now = std::chrono::steady_clock::now(); + if (now - info.updated < std::chrono::seconds(60)) { + ret = info.appid; } - retry_num++; - } while (!succeeded && retry_num < max_retry_num); + } + + if (!ret) { + do { + if (AUL_R_OK == aul_app_get_appid_bypid(pid, appid, sizeof(appid))) { + appid[MAX_APPID_LEN - 1] = '\0'; + ret = std::string{appid}; + succeeded = true; + + appids[pid] = AppInfo{*ret, std::chrono::steady_clock::now()}; + } + retry_num++; + } while (!succeeded && retry_num < max_retry_num); + } return ret; } @@ -144,9 +163,26 @@ boost::optional CApplicationManagerAul::get_pid_by_appid(const std::strin { boost::optional ret; - pid_t pid = aul_app_get_pid(appid.c_str()); - if (pid >= 0) { - ret = pid; + typedef struct { + pid_t pid; + std::chrono::time_point updated; + } AppInfo; + + static std::map pids; + if (pids.find(appid) != pids.end()) { + auto info = pids[appid]; + auto now = std::chrono::steady_clock::now(); + if (now - info.updated < std::chrono::seconds(10)) { + ret = info.pid; + } + } + + if (!ret) { + pid_t pid = aul_app_get_pid(appid.c_str()); + if (pid >= 0) { + ret = pid; + pids[appid] = AppInfo{pid, std::chrono::steady_clock::now()}; + } } return ret; diff --git a/src/service_ipc_dbus.cpp b/src/service_ipc_dbus.cpp index 915b1ed..d8101ad 100644 --- a/src/service_ipc_dbus.cpp +++ b/src/service_ipc_dbus.cpp @@ -26,6 +26,16 @@ #include "service_main.h" #include "service_ipc_dbus.h" +#ifdef PRINT_DETAILED_TIMEINFO +static long long int get_time_interval_count( + std::chrono::time_point time_point_1, + std::chrono::time_point time_point_2) { + auto interval = time_point_2 - time_point_1; + return static_cast( + std::chrono::duration_cast(interval).count()); +} +#endif + std::atomic_size_t gAudioDataMileage{0}; int CServiceIpcDbus::reconnect() @@ -228,6 +238,11 @@ int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data, return -1; } +#ifdef PRINT_DETAILED_TIMEINFO + bool flushed = false; + auto started = std::chrono::steady_clock::now(); +#endif + static unsigned char pending_buffer[STREAMING_BUFFER_SIZE]; static size_t pending_buffer_size = 0; @@ -244,6 +259,10 @@ int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data, size_t total_size = 0; size_t new_size = 0; +#ifdef PRINT_DETAILED_TIMEINFO + auto checkpoint_1 = std::chrono::steady_clock::now(); +#endif + new_size = sizeof(header); if (new_size + total_size <= STREAMING_BUFFER_SIZE) { memcpy(buffer, &header, new_size); @@ -282,20 +301,47 @@ int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data, MAS_LOGE("queueing streaming data, serial : %d %d %zu", last_serial_waiting_for_flush, event, gAudioDataMileage.load()); } + +#ifdef PRINT_DETAILED_TIMEINFO + auto checkpoint_2 = std::chrono::steady_clock::now(); + auto checkpoint_2_1 = checkpoint_2; + auto checkpoint_2_2 = checkpoint_2; + auto checkpoint_2_3 = checkpoint_2; + auto checkpoint_2_4 = checkpoint_2; +#endif + if (pending_buffer_size + total_size > STREAMING_BUFFER_SIZE || MAS_SPEECH_STREAMING_EVENT_FINISH == event || current_time - last_flush_time > minimum_flush_interval) { + +#ifdef PRINT_DETAILED_TIMEINFO + flushed = true; +#endif + last_flush_time = current_time; bundle *b = bundle_create(); if (b) { bundle_add_byte(b, "content", pending_buffer, pending_buffer_size); +#ifdef PRINT_DETAILED_TIMEINFO + checkpoint_2_1 = std::chrono::steady_clock::now(); +#endif boost::optional appid = mApplicationManager->get_appid_by_pid(pid); +#ifdef PRINT_DETAILED_TIMEINFO + checkpoint_2_2 = std::chrono::steady_clock::now(); +#endif + if (appid) { +#ifdef PRINT_DETAILED_TIMEINFO + checkpoint_2_3 = std::chrono::steady_clock::now(); +#endif #if USE_TRUSTED_MESSAGE_PORT int ret = message_port_send_trusted_message((*appid).c_str(), message_port, b); #else int ret = message_port_send_message((*appid).c_str(), message_port, b); #endif +#ifdef PRINT_DETAILED_TIMEINFO + checkpoint_2_4 = std::chrono::steady_clock::now(); +#endif if (MESSAGE_PORT_ERROR_NONE != ret) masc_message_port_error(ret); } else { @@ -315,6 +361,9 @@ int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data, } } +#ifdef PRINT_DETAILED_TIMEINFO + auto checkpoint_3 = std::chrono::steady_clock::now(); +#endif if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) { MAS_LOGE("Sending FINISH event : %zu", gAudioDataMileage.load()); bundle *b = bundle_create(); @@ -345,6 +394,28 @@ int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data, MAS_LOGE("Buffer overflow : %zu %zu", pending_buffer_size, total_size); } } + +#ifdef PRINT_DETAILED_TIMEINFO + auto finished = std::chrono::steady_clock::now(); + long long int count = get_time_interval_count(started, finished); + + if (count > 30) { + long long int count1 = get_time_interval_count(started, checkpoint_1); + long long int count2 = get_time_interval_count(checkpoint_1, checkpoint_2); + long long int count3 = get_time_interval_count(checkpoint_2, checkpoint_3); + long long int count4 = get_time_interval_count(checkpoint_3, finished); + + long long int count2_1 = get_time_interval_count(checkpoint_2, checkpoint_2_1); + long long int count2_2 = get_time_interval_count(checkpoint_2_1, checkpoint_2_2); + long long int count2_3 = get_time_interval_count(checkpoint_2_2, checkpoint_2_3); + long long int count2_4 = get_time_interval_count(checkpoint_2_3, checkpoint_2_4); + long long int count2_5 = get_time_interval_count(checkpoint_2_4, checkpoint_3); + + MAS_LOGE("Spent %lld for sending a single message %d [%lld %lld %lld %lld] (%lld %lld %lld %lld %lld)", + count, flushed, count1, count2, count3, count4, count2_1, count2_2, count2_3, count2_4, count2_5); + } +#endif + return 0; } diff --git a/src/service_plugin.cpp b/src/service_plugin.cpp index 0df29ed..0c99bd0 100644 --- a/src/service_plugin.cpp +++ b/src/service_plugin.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include "service_main.h" #include "service_plugin.h" #include "service_ipc_dbus.h" @@ -35,6 +37,16 @@ #define BUF_SAVE_MODE #endif +#ifdef PRINT_DETAILED_TIMEINFO +static long long int get_time_interval_count( + std::chrono::time_point time_point_1, + std::chrono::time_point time_point_2) { + auto interval = time_point_2 - time_point_1; + return static_cast( + std::chrono::duration_cast(interval).count()); +} +#endif + static int g_last_wakeup_event_id = 0; typedef struct { @@ -420,6 +432,13 @@ void handle_speech_streaming_event_failure(void* data) static void __audio_streaming_cb(mas_speech_streaming_event_e event, void* buffer, int len, void *user_data) { +#ifdef PRINT_DETAILED_TIMEINFO + auto started = std::chrono::steady_clock::now(); + auto checkpoint_1 = started; + auto checkpoint_2 = started; + auto checkpoint_3 = started; +#endif + CServicePlugin* plugin = static_cast(user_data); if (event == MAS_SPEECH_STREAMING_EVENT_FAIL) { @@ -450,6 +469,10 @@ static void __audio_streaming_cb(mas_speech_streaming_event_e event, void* buffe service_main = plugin->get_service_main(); } +#ifdef PRINT_DETAILED_TIMEINFO + checkpoint_1 = std::chrono::steady_clock::now(); +#endif + if (service_ipc && service_main) { /* First check if we have dedicated audio processing app for current client */ pid_t pid = service_main->get_current_audio_processing_pid(); @@ -461,6 +484,10 @@ static void __audio_streaming_cb(mas_speech_streaming_event_e event, void* buffe MAS_LOGE("[ERROR] Fail to retrieve pid of current MA client"); } else { if (__validate_streaming_event_order(pid, &event)) { +#ifdef PRINT_DETAILED_TIMEINFO + checkpoint_2 = std::chrono::steady_clock::now(); +#endif + int ret = service_ipc->send_streaming_audio_data(pid, event, buffer, len); if (0 != ret) { @@ -473,6 +500,9 @@ static void __audio_streaming_cb(mas_speech_streaming_event_e event, void* buffe MAS_LOGE("[ERROR] Fail to send speech data to preprocessing client, ret(%d)", ret); } } +#ifdef PRINT_DETAILED_TIMEINFO + checkpoint_3 = std::chrono::steady_clock::now(); +#endif } } } @@ -490,6 +520,21 @@ static void __audio_streaming_cb(mas_speech_streaming_event_e event, void* buffe } } #endif + +#ifdef PRINT_DETAILED_TIMEINFO + auto finished = std::chrono::steady_clock::now(); + long long int total_count = get_time_interval_count(started, finished); + + if(total_count > 30) { + long long int count1 = get_time_interval_count(started, checkpoint_1); + long long int count2 = get_time_interval_count(checkpoint_1, checkpoint_2); + long long int count3 = get_time_interval_count(checkpoint_2, checkpoint_3); + long long int count4 = get_time_interval_count(checkpoint_3, finished); + + MAS_LOGE("Spent audio streaming callback time : %lld ms [%lld %lld %lld %lld]", + total_count, count1, count2, count3, count4); + } +#endif } static void __speech_status_cb(mas_speech_status_e status, void *user_data) -- 2.7.4 From 13140c9e1c91f973a75608eac14886e598998459 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 5 Dec 2022 19:39:51 +0900 Subject: [PATCH 11/16] Remove unnecessary pid<->appid conversion logic Change-Id: If0439c8fae6c8ba65d8249eef9dbe4a9ac7d13d7 --- inc/service_ipc_dbus.h | 4 +++- inc/service_main.h | 21 ++++++++++++++---- src/service_ipc_dbus.cpp | 47 +++++++++++----------------------------- src/service_main.cpp | 56 +++++++++++++++++++++++++++++++++++------------- src/service_plugin.cpp | 39 +++++++++++++++++---------------- 5 files changed, 95 insertions(+), 72 deletions(-) diff --git a/inc/service_ipc_dbus.h b/inc/service_ipc_dbus.h index d9102e5..3be24d1 100644 --- a/inc/service_ipc_dbus.h +++ b/inc/service_ipc_dbus.h @@ -17,6 +17,8 @@ #ifndef __SERVICE_IPC_DBUS_H__ #define __SERVICE_IPC_DBUS_H__ +#include + #include #include @@ -33,7 +35,7 @@ public: int close_connection(); int send_hello(pid_t pid); int send_error_message(int reason, const char* err_msg); - int send_streaming_audio_data(pid_t pid, int event, void* data, unsigned int data_size); + int send_streaming_audio_data(std::string appid, int event, void* data, unsigned int data_size); int change_active_state(pid_t pid, int state, const char* wakeup_word, const unsigned char* wakeup_extra_data, size_t wakeup_extra_data_length, const char* wakeup_extra_data_desc); diff --git a/inc/service_main.h b/inc/service_main.h index ea87dad..0a92610 100644 --- a/inc/service_main.h +++ b/inc/service_main.h @@ -102,30 +102,43 @@ public: int client_set_assistant_language(pid_t pid, const char* language); int client_add_wake_word(pid_t pid, const char* wake_word, const char* language); int client_remove_wake_word(pid_t pid, const char* wake_word, const char* language); + int ui_client_initialize(pid_t pid); int ui_client_deinitialize(pid_t pid); int ui_client_change_assistant(const char* appid); + pid_t get_current_client_pid(); pid_t get_current_preprocessing_client_pid(); pid_t get_current_audio_processing_pid(); + + boost::optional get_current_client_appid(); + boost::optional get_current_preprocessing_client_appid(); + boost::optional get_current_audio_processing_appid(); + int get_client_pid_by_wakeup_word(const char *wakeup_word); + const char* get_client_appid_by_wakeup_word(const char *wakeup_word); + int get_client_pid_by_appid(const char *appid); std::string get_client_appid_by_pid(pid_t pid); + bool get_client_custom_ui_option_by_appid(const char *appid); - const char* get_client_appid_by_wakeup_word(const char *wakeup_word); + int set_current_client_by_wakeup_word(const char *wakeup_word); int set_current_client_by_appid(const char *appid); + int launch_client_by_wakeup_word(const char *wakeup_word, const unsigned char* extra_data, size_t extra_data_length, const char *extra_data_desc); + int launch_client_by_appid(const char *appid, const char *word, + const unsigned char *extra_data, size_t extra_data_length, const char *extra_data_desc, + CLIENT_LAUNCH_MODE launch_mode); + int prelaunch_default_assistant(); int set_current_service_state(ma_service_state_e state); int bring_client_to_foreground(const char* appid); ma_service_state_e get_current_service_state(); - int launch_client_by_appid(const char *appid, const char *word, - const unsigned char *extra_data, size_t extra_data_length, const char *extra_data_desc, - CLIENT_LAUNCH_MODE launch_mode); int process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event); int update_voice_key_support_mode(); + int get_current_wakeup_word(char** wakeup_word); int set_current_wakeup_word(const char *wakeup_word); diff --git a/src/service_ipc_dbus.cpp b/src/service_ipc_dbus.cpp index d8101ad..4c00aa3 100644 --- a/src/service_ipc_dbus.cpp +++ b/src/service_ipc_dbus.cpp @@ -231,7 +231,7 @@ static long long get_current_milliseconds_after_epoch() return value.count(); } -int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data, unsigned int data_size) +int CServiceIpcDbus::send_streaming_audio_data(std::string appid, int event, void* data, unsigned int data_size) { if (nullptr == mClientManager) { MAS_LOGE("mClientManager variable is NULL"); @@ -306,8 +306,6 @@ int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data, auto checkpoint_2 = std::chrono::steady_clock::now(); auto checkpoint_2_1 = checkpoint_2; auto checkpoint_2_2 = checkpoint_2; - auto checkpoint_2_3 = checkpoint_2; - auto checkpoint_2_4 = checkpoint_2; #endif if (pending_buffer_size + total_size > STREAMING_BUFFER_SIZE || @@ -325,28 +323,16 @@ int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data, #ifdef PRINT_DETAILED_TIMEINFO checkpoint_2_1 = std::chrono::steady_clock::now(); #endif - boost::optional appid = mApplicationManager->get_appid_by_pid(pid); -#ifdef PRINT_DETAILED_TIMEINFO - checkpoint_2_2 = std::chrono::steady_clock::now(); -#endif - - if (appid) { -#ifdef PRINT_DETAILED_TIMEINFO - checkpoint_2_3 = std::chrono::steady_clock::now(); -#endif #if USE_TRUSTED_MESSAGE_PORT - int ret = message_port_send_trusted_message((*appid).c_str(), message_port, b); + int ret = message_port_send_trusted_message(appid.c_str(), message_port, b); #else - int ret = message_port_send_message((*appid).c_str(), message_port, b); + int ret = message_port_send_message(appid.c_str(), message_port, b); #endif #ifdef PRINT_DETAILED_TIMEINFO - checkpoint_2_4 = std::chrono::steady_clock::now(); + checkpoint_2_2 = std::chrono::steady_clock::now(); #endif - if (MESSAGE_PORT_ERROR_NONE != ret) - masc_message_port_error(ret); - } else { - MAS_LOGE("AppID for PID %d not found!!!", pid); - } + if (MESSAGE_PORT_ERROR_NONE != ret) + masc_message_port_error(ret); pending_buffer_size = 0; bundle_free(b); @@ -369,18 +355,13 @@ int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data, bundle *b = bundle_create(); if (b) { bundle_add_byte(b, "content", buffer, total_size); - boost::optional appid = mApplicationManager->get_appid_by_pid(pid); - if (appid) { #if USE_TRUSTED_MESSAGE_PORT - int ret = message_port_send_trusted_message((*appid).c_str(), message_port, b); + int ret = message_port_send_trusted_message(appid.c_str(), message_port, b); #else - int ret = message_port_send_message((*appid).c_str(), message_port, b); + int ret = message_port_send_message(appid.c_str(), message_port, b); #endif - if (MESSAGE_PORT_ERROR_NONE != ret) - masc_message_port_error(ret); - } else { - MAS_LOGE("AppID for PID %d not found!!!", pid); - } + if (MESSAGE_PORT_ERROR_NONE != ret) + masc_message_port_error(ret); bundle_free(b); } else { @@ -407,12 +388,10 @@ int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data, long long int count2_1 = get_time_interval_count(checkpoint_2, checkpoint_2_1); long long int count2_2 = get_time_interval_count(checkpoint_2_1, checkpoint_2_2); - long long int count2_3 = get_time_interval_count(checkpoint_2_2, checkpoint_2_3); - long long int count2_4 = get_time_interval_count(checkpoint_2_3, checkpoint_2_4); - long long int count2_5 = get_time_interval_count(checkpoint_2_4, checkpoint_3); + long long int count2_3 = get_time_interval_count(checkpoint_2_2, checkpoint_3); - MAS_LOGE("Spent %lld for sending a single message %d [%lld %lld %lld %lld] (%lld %lld %lld %lld %lld)", - count, flushed, count1, count2, count3, count4, count2_1, count2_2, count2_3, count2_4, count2_5); + MAS_LOGE("Spent %lld for sending a single message %d [%lld %lld %lld %lld] (%lld %lld %lld)", + count, flushed, count1, count2, count3, count4, count2_1, count2_2, count2_3); } #endif diff --git a/src/service_main.cpp b/src/service_main.cpp index 14cb54b..65b9ac1 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -829,43 +829,69 @@ int CServiceMain::process_activated_setting() int CServiceMain::get_current_client_pid() { int ret = -1; + boost::optional appid = get_current_client_appid(); + if (appid) { + ret = mClientManager.find_client_pid_by_appid(*appid); + } + return ret; +} + +pid_t CServiceMain::get_current_preprocessing_client_pid() +{ + pid_t ret = -1; + boost::optional preprocessing_appid = get_current_preprocessing_client_appid(); + if (preprocessing_appid) { + ret = mClientManager.find_client_pid_by_appid(*preprocessing_appid); + } + return ret; +} + +pid_t CServiceMain::get_current_audio_processing_pid() +{ + pid_t ret = -1; + boost::optional audio_processing_appid = get_current_audio_processing_appid(); + if (audio_processing_appid) { + boost::optional audio_processing_pid = + mApplicationManager.get_pid_by_appid(*audio_processing_appid); + if (audio_processing_pid) { + ret = *audio_processing_pid; + } + } + return ret; +} + +boost::optional CServiceMain::get_current_client_appid() +{ + boost::optional ret; if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) { ClientInfoItems *items = mClientInfo.getItems(); const char *appid = items[mCurrentClientInfo].appid; if (appid) { - ret = mClientManager.find_client_pid_by_appid(std::string{appid}); + ret = std::string{appid}; } } return ret; } -pid_t CServiceMain::get_current_preprocessing_client_pid() +boost::optional CServiceMain::get_current_preprocessing_client_appid() { - pid_t ret = -1; + boost::optional ret; if (mCurrentPreprocessingClientInfo >= 0 && mCurrentPreprocessingClientInfo < MAX_MACLIENT_INFO_NUM) { ClientInfoItems *items = mClientInfo.getItems(); const char *appid = items[mCurrentPreprocessingClientInfo].appid; if (appid) { - ret = mClientManager.find_client_pid_by_appid(std::string{appid}); + ret = std::string{appid}; } } return ret; } -pid_t CServiceMain::get_current_audio_processing_pid() +boost::optional CServiceMain::get_current_audio_processing_appid() { - pid_t ret = -1; + boost::optional ret; if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) { ClientInfoItems *items = mClientInfo.getItems(); - boost::optional audio_processing_appid = - items[mCurrentClientInfo].audio_processing_appid; - if (audio_processing_appid) { - boost::optional audio_processing_pid; - audio_processing_pid = mApplicationManager.get_pid_by_appid((*audio_processing_appid).c_str()); - if (audio_processing_pid) { - ret = *audio_processing_pid; - } - } + ret = items[mCurrentClientInfo].audio_processing_appid; } return ret; } diff --git a/src/service_plugin.cpp b/src/service_plugin.cpp index 0c99bd0..3f3ba2a 100644 --- a/src/service_plugin.cpp +++ b/src/service_plugin.cpp @@ -361,11 +361,11 @@ static void __wakeup_event_cb(mas_wakeup_event_info wakeup_info, void* user_data } } -static bool __validate_streaming_event_order(pid_t pid, mas_speech_streaming_event_e *event) +static bool __validate_streaming_event_order(std::string appid, mas_speech_streaming_event_e *event) { bool ret = false; - static int previous_pid = -1; + static std::string previous_appid; static mas_speech_streaming_event_e previous_event = MAS_SPEECH_STREAMING_EVENT_FINISH; if (NULL == event) return false; @@ -380,7 +380,7 @@ static bool __validate_streaming_event_order(pid_t pid, mas_speech_streaming_eve {MAS_SPEECH_STREAMING_EVENT_FINISH, MAS_SPEECH_STREAMING_EVENT_FINISH}, }; - if (pid != previous_pid) { + if (appid != previous_appid) { /* When sending streaming event to a new client, it always sends START message first */ previous_event = MAS_SPEECH_STREAMING_EVENT_FINISH; } @@ -398,17 +398,17 @@ static bool __validate_streaming_event_order(pid_t pid, mas_speech_streaming_eve *event = MAS_SPEECH_STREAMING_EVENT_START; ret = true; - MAS_LOGD("[WARNING] forcibly changed CONTINUE to START : %d -> %d (PID %d -> %d)", - previous_event, *event, previous_pid, pid); + MAS_LOGD("[WARNING] forcibly changed CONTINUE to START : %d -> %d (PID %s -> %s)", + previous_event, *event, previous_appid.c_str(), appid.c_str()); } } if (ret) { - previous_pid = pid; + previous_appid = appid; previous_event = *event; } else { - MAS_LOGE("[ERROR] State sequence validation failed : %d -> %d (PID %d -> %d)", - previous_event, *event, previous_pid, pid); + MAS_LOGE("[ERROR] State sequence validation failed : %d -> %d (APPID %s -> %s)", + previous_event, *event, previous_appid.c_str(), appid.c_str()); } return ret; } @@ -475,26 +475,29 @@ static void __audio_streaming_cb(mas_speech_streaming_event_e event, void* buffe if (service_ipc && service_main) { /* First check if we have dedicated audio processing app for current client */ - pid_t pid = service_main->get_current_audio_processing_pid(); + boost::optional appid = + service_main->get_current_audio_processing_appid(); + /* If not, send audio data to the main client */ - if (-1 == pid) pid = service_main->get_current_client_pid(); + if (!appid) appid = service_main->get_current_client_appid(); + + boost::optional preprocessing_appid = + service_main->get_current_preprocessing_client_appid(); - int preprocessing_pid = service_main->get_current_preprocessing_client_pid(); - if (pid == -1) { - MAS_LOGE("[ERROR] Fail to retrieve pid of current MA client"); + if (!appid) { + MAS_LOGE("[ERROR] Fail to retrieve target appid of current MA client"); } else { - if (__validate_streaming_event_order(pid, &event)) { + if (__validate_streaming_event_order(*appid, &event)) { #ifdef PRINT_DETAILED_TIMEINFO checkpoint_2 = std::chrono::steady_clock::now(); #endif - - int ret = service_ipc->send_streaming_audio_data(pid, + int ret = service_ipc->send_streaming_audio_data(*appid, 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 = service_ipc->send_streaming_audio_data(preprocessing_pid, + if (preprocessing_appid && (*appid).compare(*preprocessing_appid) != 0) { + int ret = service_ipc->send_streaming_audio_data(*preprocessing_appid, event, buffer, len); if (0 != ret) { MAS_LOGE("[ERROR] Fail to send speech data to preprocessing client, ret(%d)", ret); -- 2.7.4 From d78a627d20f146bae2ebddeb81501c1fc4aca55c Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 9 Dec 2022 12:02:07 +0900 Subject: [PATCH 12/16] Postpone voice key release event emission until streaming completes Change-Id: I5931b2502c06fc645188a20c71a6ea1776ce7e63 --- plugins/wakeup-manager/inc/wakeup_manager.h | 10 +++ plugins/wakeup-manager/src/dependency_resolver.cpp | 2 +- plugins/wakeup-manager/src/wakeup_manager.cpp | 80 +++++++++++++++++++++- 3 files changed, 88 insertions(+), 4 deletions(-) diff --git a/plugins/wakeup-manager/inc/wakeup_manager.h b/plugins/wakeup-manager/inc/wakeup_manager.h index fda6b2a..77e8437 100644 --- a/plugins/wakeup-manager/inc/wakeup_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_manager.h @@ -155,6 +155,11 @@ public: void start_periodic_monitor_timer(); void stop_periodic_monitor_timer(); + void update_voice_key_status(ma_voice_key_status_e status); + void update_pending_voice_key_status(); + + void start_voice_key_status_update_timer(); + void set_streaming_completed(bool completed); private: class CEngineEventObserver : public IEngineEventObserver { @@ -256,6 +261,11 @@ private: mas_wakeup_event_info mLastWakeupEventInfo; + boost::optional mPendingVoiceKeyStatus; + atomic_bool mStreamingCompleted{false}; + Ecore_Timer *mVoiceKeyStatusUpdateTimer{nullptr}; + mutex mVoiceKeyStatusUpdateMutex; + mutex mMutex; }; diff --git a/plugins/wakeup-manager/src/dependency_resolver.cpp b/plugins/wakeup-manager/src/dependency_resolver.cpp index c8892cc..abacd59 100644 --- a/plugins/wakeup-manager/src/dependency_resolver.cpp +++ b/plugins/wakeup-manager/src/dependency_resolver.cpp @@ -488,4 +488,4 @@ int dependency_resolver_get_custom_vconf_key(const char* default_key, char** cus } return ret; -} \ No newline at end of file +} diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index ddbb8a2..79bd057 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -681,15 +681,87 @@ bool CWakeupManager::process_plugin_event(mas_plugin_event_e event, void* data, } if (next_voice_key_status) { - for (const auto& observer : mWakeupObservers) { - observer->on_voice_key_status_changed(*next_voice_key_status); - } + update_voice_key_status(*next_voice_key_status); } MWR_LOGD("[END]"); return true; } +void CWakeupManager::set_streaming_completed(bool completed) +{ + MWR_LOGI("[ENTER] : %d", completed); + mStreamingCompleted.store(completed); + + /* When Streaming completes, update pending voice key status */ + update_pending_voice_key_status(); +} + +void CWakeupManager::start_voice_key_status_update_timer() +{ + const float VOICE_KEY_STATUS_UPDATE_INTERVAL = 5.0f; + + if (mVoiceKeyStatusUpdateTimer) { + ecore_timer_del(mVoiceKeyStatusUpdateTimer); + } + + mVoiceKeyStatusUpdateTimer = ecore_timer_add(VOICE_KEY_STATUS_UPDATE_INTERVAL, + [](void *data) { + MAS_LOGE("voice_key_status_update_timer expired"); + auto manager = static_cast(data); + manager->update_pending_voice_key_status(); + return ECORE_CALLBACK_CANCEL; + }, static_cast(this)); +} + +void CWakeupManager::update_pending_voice_key_status() +{ + MAS_LOGI("[ENTER]"); + if (mVoiceKeyStatusUpdateTimer) { + ecore_timer_del(mVoiceKeyStatusUpdateTimer); + mVoiceKeyStatusUpdateTimer = nullptr; + } + if (mPendingVoiceKeyStatus) { + for (const auto& observer : mWakeupObservers) { + observer->on_voice_key_status_changed(*mPendingVoiceKeyStatus); + } + mPendingVoiceKeyStatus = boost::none; + } +} + +void CWakeupManager::update_voice_key_status(ma_voice_key_status_e status) +{ + MWR_LOGI("status : %d", status); + if (mPendingVoiceKeyStatus) { + for (const auto& observer : mWakeupObservers) { + observer->on_voice_key_status_changed(*mPendingVoiceKeyStatus); + } + mPendingVoiceKeyStatus = boost::none; + } + + /* If streaming has not been completed yet after pressed event, + * postpone the status update until streaming is completed */ + bool postpone = false; + if (status == MA_VOICE_KEY_STATUS_RELEASED_AFTER_PUSH) { + if (!mStreamingCompleted.load()) { + postpone = true; + } + } + + if (postpone) { + mPendingVoiceKeyStatus = status; + start_voice_key_status_update_timer(); + } else { + for (const auto& observer : mWakeupObservers) { + observer->on_voice_key_status_changed(status); + } + } + + if (status == MA_VOICE_KEY_STATUS_PRESSED) { + mStreamingCompleted.store(false); + } +} + vector CWakeupManager::get_wakeup_observers() { return mWakeupObservers; @@ -1265,6 +1337,8 @@ bool CWakeupManager::CAudioEventObserver::on_streaming_audio_data( if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) { mWakeupManager->set_streaming_mode(STREAMING_MODE::NONE); mWakeupManager->stop_streaming_duration_timer(); + + mWakeupManager->set_streaming_completed(true); } return true; -- 2.7.4 From e55ec1a524fe9242bc71a0f7a375c938d3e0ecab Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Tue, 13 Dec 2022 18:40:48 +0900 Subject: [PATCH 13/16] Allow audio processor applications to send start streaming request Change-Id: I36707c55cfc4e64331d2228c30ed051950c15bdf --- inc/service_ipc_dbus.h | 3 ++ inc/service_ipc_dbus_dispatcher.h | 3 ++ inc/service_main.h | 2 + plugins/wakeup-manager/inc/wakeup_manager.h | 3 ++ plugins/wakeup-manager/src/wakeup_manager.cpp | 10 +++++ src/service_ipc_dbus.cpp | 54 +++++++++++++++++++++++++++ src/service_main.cpp | 21 +++++++++++ 7 files changed, 96 insertions(+) diff --git a/inc/service_ipc_dbus.h b/inc/service_ipc_dbus.h index 3be24d1..900e792 100644 --- a/inc/service_ipc_dbus.h +++ b/inc/service_ipc_dbus.h @@ -83,6 +83,9 @@ private: CClientManager* mClientManager{nullptr}; IApplicationManager* mApplicationManager{nullptr}; + + int mLocalMessagePortID{-1}; + const std::string mLocalMessagePortName{"audio-processor"}; }; #endif /* __SERVICE_IPC_DBUS_H__ */ diff --git a/inc/service_ipc_dbus_dispatcher.h b/inc/service_ipc_dbus_dispatcher.h index c7f3104..8b6bae8 100644 --- a/inc/service_ipc_dbus_dispatcher.h +++ b/inc/service_ipc_dbus_dispatcher.h @@ -48,6 +48,8 @@ public: virtual int on_ui_initialize(pid_t pid) = 0; virtual int on_ui_deinitialize(pid_t pid) = 0; virtual int on_ui_change_assistant(std::string app_id) = 0; + + virtual int on_ap_start_streaming_audio_data(std::string appid, int type) = 0; }; class CServiceIpcDbusDispatcher { @@ -79,6 +81,7 @@ public: int on_ui_change_assistant(DBusConnection* conn, DBusMessage* msg); void set_ipc_observer(IServiceIpcObserver* observer) { mIpcObserver = observer; } + IServiceIpcObserver* get_ipc_observer() { return mIpcObserver; } private: IServiceIpcObserver *mIpcObserver{nullptr}; }; diff --git a/inc/service_main.h b/inc/service_main.h index 0a92610..9b70246 100644 --- a/inc/service_main.h +++ b/inc/service_main.h @@ -166,6 +166,8 @@ public: int on_ui_deinitialize(pid_t pid) override; int on_ui_change_assistant(std::string app_id) override; + int on_ap_start_streaming_audio_data(std::string appid, int type) override; + bool app_create(void *data); void app_terminate(void *data); void app_restart(); diff --git a/plugins/wakeup-manager/inc/wakeup_manager.h b/plugins/wakeup-manager/inc/wakeup_manager.h index 77e8437..994dab3 100644 --- a/plugins/wakeup-manager/inc/wakeup_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_manager.h @@ -261,6 +261,9 @@ private: mas_wakeup_event_info mLastWakeupEventInfo; + unsigned int mLastWakeupEventID{0}; + unsigned int mCurrentStreamingSessionID{0}; + boost::optional mPendingVoiceKeyStatus; atomic_bool mStreamingCompleted{false}; Ecore_Timer *mVoiceKeyStatusUpdateTimer{nullptr}; diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index 79bd057..5b6271e 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -770,6 +770,7 @@ vector CWakeupManager::get_wakeup_observers() void CWakeupManager::set_last_wakeup_event_info(mas_wakeup_event_info wakeup_info) { mLastWakeupEventInfo = wakeup_info; + mLastWakeupEventID++; } vector CWakeupManager::get_setting_observers() @@ -827,6 +828,15 @@ bool CWakeupManager::start_streaming_utterance_data() { MWR_LOGI("[ENTER]"); + if (mStreamingMode == STREAMING_MODE::UTTERANCE) { + if (mCurrentStreamingSessionID == mLastWakeupEventID) { + MWR_LOGW("Streaming already started for this session"); + return false; + } + } + + mCurrentStreamingSessionID = mLastWakeupEventID; + mAudioManager.stop_streaming_current_utterance_data(); mWakeupEngineManager.stop_streaming_current_utterance_data(); diff --git a/src/service_ipc_dbus.cpp b/src/service_ipc_dbus.cpp index 4c00aa3..3114dc5 100644 --- a/src/service_ipc_dbus.cpp +++ b/src/service_ipc_dbus.cpp @@ -38,6 +38,40 @@ static long long int get_time_interval_count( std::atomic_size_t gAudioDataMileage{0}; +static void message_port_cb(int local_port_id, + const char *remote_app_id, const char *remote_port, + bool trusted_remote_port, bundle *message, void *user_data) +{ + CServiceIpcDbus *service_ipc = static_cast(user_data); + if (!service_ipc) { + MAS_LOGE("Invalid user_data"); + return; + } + + CServiceIpcDbusDispatcher* dispatcher = service_ipc->get_dispatcher(); + if (!dispatcher) { + MAS_LOGE("Dispatcher not found"); + return; + } + + IServiceIpcObserver *observer = dispatcher->get_ipc_observer(); + if (!observer) { + MAS_LOGE("Observer not found"); + return; + } + + char *request = nullptr; + bundle_get_str(message, "request", &request); + if (request) { + const char *szStartStreamingRequest = "start_streaming_current_utterance"; + if (strncmp(request, szStartStreamingRequest, strlen(szStartStreamingRequest)) == 0) { + MAS_LOGE("start_streaming request"); + observer->on_ap_start_streaming_audio_data(std::string{remote_app_id}, + MA_AUDIO_STREAMING_DATA_TYPE_CURRENT_UTTERANCE); + } + } +} + int CServiceIpcDbus::reconnect() { if (!mConnectionSender || !mConnectionListener) { @@ -1401,11 +1435,31 @@ int CServiceIpcDbus::open_connection() return -1; } +#if USE_TRUSTED_MESSAGE_PORT + int port_id = message_port_register_trusted_local_port(mLocalMessagePortName.c_str(), message_port_cb, this); +#else + int port_id = message_port_register_local_port(mLocalMessagePortName.c_str(), message_port_cb, this); +#endif + + if (port_id < 0) { + MAS_LOGE("Port register error: %d", port_id); + } else { + MAS_LOGI("port_id: %d", port_id); + mLocalMessagePortID = port_id; + } + return 0; } int CServiceIpcDbus::close_connection() { +#if USE_TRUSTED_MESSAGE_PORT + if (-1 != mLocalMessagePortID) message_port_unregister_trusted_local_port(mLocalMessagePortID); +#else + if (-1 != mLocalMessagePortID) message_port_unregister_local_port(mLocalMessagePortID); +#endif + mLocalMessagePortID = -1; + DBusError err; dbus_error_init(&err); diff --git a/src/service_main.cpp b/src/service_main.cpp index 65b9ac1..0c5eedf 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -1673,3 +1673,24 @@ int CServiceMain::on_ui_change_assistant(std::string app_id) { return ui_client_change_assistant(app_id.c_str()); } + +int CServiceMain::on_ap_start_streaming_audio_data(std::string ap_appid, int type) +{ + LOGE("AP requested to start streaming audio data : %s %d", + ap_appid.c_str(), type); + + if (mCurrentClientInfo < 0 || mCurrentClientInfo >= MAX_MACLIENT_INFO_NUM) { + MAS_LOGE("Invalid client info index"); + return -1; + } + + ClientInfoItems *items = mClientInfo.getItems(); + if (items[mCurrentClientInfo].audio_processing_appid) { + if (ap_appid.compare(*(items[mCurrentClientInfo].audio_processing_appid)) == 0) { + std::string appid = items[mCurrentClientInfo].appid; + pid_t pid_by_appid = mClientManager.find_client_pid_by_appid(appid); + return client_start_streaming_audio_data(pid_by_appid, type); + } + } + return -1; +} -- 2.7.4 From 8d584cf23b345054eeafd4caeac798324747f1ae Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 15 Dec 2022 12:59:39 +0900 Subject: [PATCH 14/16] Postpone restart operation when streaming audio data Change-Id: I0189262b57d89885c4463a8443939cbc5f67660b --- inc/service_plugin.h | 11 ++++++++--- src/service_plugin.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/inc/service_plugin.h b/inc/service_plugin.h index 69d081c..6a4691d 100644 --- a/inc/service_plugin.h +++ b/inc/service_plugin.h @@ -81,8 +81,11 @@ public: void set_service_ipc(CServiceIpcDbus* ipc) { mServiceIpc = ipc; } CServiceIpcDbus* get_service_ipc() { return mServiceIpc; } - void set_service_main(CServiceMain* main) { mServiceMain = main; } - CServiceMain* get_service_main() { return mServiceMain; } + void set_service_main(CServiceMain* main) { mServiceMain = main; } + CServiceMain* get_service_main() { return mServiceMain; } + + void start_app_restart_timer(); + void stop_app_restart_timer(); private: #ifdef BUF_SAVE_MODE char mDumpFilename[128]{'\0', }; @@ -96,7 +99,9 @@ private: ma_plugin_settings* mPluginSettings{NULL}; CServiceIpcDbus* mServiceIpc{nullptr}; - CServiceMain* mServiceMain{nullptr}; + CServiceMain* mServiceMain{nullptr}; + + Ecore_Timer *mAppRestartTimer{nullptr}; }; #endif /* __SERVICE_PLUGIN_H__ */ diff --git a/src/service_plugin.cpp b/src/service_plugin.cpp index 3f3ba2a..2b8e8da 100644 --- a/src/service_plugin.cpp +++ b/src/service_plugin.cpp @@ -643,6 +643,37 @@ static void __wakeup_service_voice_key_status_changed_cb(ma_voice_key_status_e s } } +static Eina_Bool app_restart_timer_func(void *user_data) +{ + CServicePlugin *plugin = static_cast(user_data); + if (plugin) { + CServiceMain* service_main = plugin->get_service_main(); + if (service_main) { + ma_service_state_e service_state = service_main->get_current_service_state(); + if (service_state != MA_SERVICE_STATE_UTTERANCE) { + MAS_LOGE("[SUCCESS] Restarting service"); + service_main->app_restart(); + } + } + } + + return ECORE_CALLBACK_RENEW; +} + +void CServicePlugin::stop_app_restart_timer() +{ + if (mAppRestartTimer) { + ecore_timer_del(mAppRestartTimer); + mAppRestartTimer = nullptr; + } +} + +void CServicePlugin::start_app_restart_timer() +{ + stop_app_restart_timer(); + mAppRestartTimer = ecore_timer_add(1.0f, app_restart_timer_func, this); +} + static void __loaded_engine_changed_cb(void* user_data) { MAS_LOGD("[SUCCESS] __loaded_engine_changed_cb is called"); @@ -654,12 +685,12 @@ static void __loaded_engine_changed_cb(void* user_data) if (service_main) { /* Make sure the app doesn't restart within a conversation session */ ma_service_state_e service_state = service_main->get_current_service_state(); - if (service_state == MA_SERVICE_STATE_INACTIVE || - service_state == MA_SERVICE_STATE_LISTENING) { + if (service_state != MA_SERVICE_STATE_UTTERANCE) { MAS_LOGE("[SUCCESS] Restarting service"); service_main->app_restart(); } else { MAS_LOGE("Cannot restart service when service_state is %d", service_state); + plugin->start_app_restart_timer(); } } } @@ -855,6 +886,11 @@ int CServicePlugin::deinitialize(void) } #endif + if (mAppRestartTimer) { + ecore_timer_del(mAppRestartTimer); + mAppRestartTimer = nullptr; + } + int ret = -1; if (NULL != mPluginHandle) { wakeup_manager_deinitialize func = mWakeupManagerInterface.deinitialize; -- 2.7.4 From 548048b13d46192ceb2bf1c146e129b8d2c37897 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Tue, 10 Jan 2023 17:58:51 +0900 Subject: [PATCH 15/16] Prevent duplicated requests from canceling active streaming session Change-Id: Ie0444f1b7bfa86bec4a415bc393e29ccee5839d0 --- plugins/wakeup-manager/src/wakeup_manager.cpp | 8 +++----- src/service_ipc_dbus.cpp | 12 ++++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index 5b6271e..516669f 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -828,11 +828,9 @@ bool CWakeupManager::start_streaming_utterance_data() { MWR_LOGI("[ENTER]"); - if (mStreamingMode == STREAMING_MODE::UTTERANCE) { - if (mCurrentStreamingSessionID == mLastWakeupEventID) { - MWR_LOGW("Streaming already started for this session"); - return false; - } + if (mCurrentStreamingSessionID == mLastWakeupEventID) { + MWR_LOGW("Streaming already started for this session"); + return false; } mCurrentStreamingSessionID = mLastWakeupEventID; diff --git a/src/service_ipc_dbus.cpp b/src/service_ipc_dbus.cpp index 3114dc5..365c3b8 100644 --- a/src/service_ipc_dbus.cpp +++ b/src/service_ipc_dbus.cpp @@ -60,12 +60,12 @@ static void message_port_cb(int local_port_id, return; } - char *request = nullptr; - bundle_get_str(message, "request", &request); - if (request) { - const char *szStartStreamingRequest = "start_streaming_current_utterance"; - if (strncmp(request, szStartStreamingRequest, strlen(szStartStreamingRequest)) == 0) { - MAS_LOGE("start_streaming request"); + char *command = nullptr; + bundle_get_str(message, "command", &command); + if (command) { + const char *szStartStreamingCommand = "start_streaming_current_utterance"; + if (strncmp(command, szStartStreamingCommand, strlen(szStartStreamingCommand)) == 0) { + MAS_LOGE("AP sent start streaming request"); observer->on_ap_start_streaming_audio_data(std::string{remote_app_id}, MA_AUDIO_STREAMING_DATA_TYPE_CURRENT_UTTERANCE); } -- 2.7.4 From b7d1b7541e2c4ef9e2b5076bbba641714ce97c43 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Tue, 10 Jan 2023 17:59:11 +0900 Subject: [PATCH 16/16] Bump version to 0.3.38 Change-Id: Ibfc511e8953a4d9df1bc86803806f6f7a0f5a283 --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index dda7e64..d3d4f57 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index ea0576e..42d6a1b 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.3.37 +Version: 0.3.38 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4