From 8d584cf23b345054eeafd4caeac798324747f1ae Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 15 Dec 2022 12:59:39 +0900 Subject: [PATCH] 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