Allow audio processor applications to send start streaming request 75/285475/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Tue, 13 Dec 2022 09:40:48 +0000 (18:40 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Tue, 13 Dec 2022 09:40:48 +0000 (18:40 +0900)
Change-Id: I36707c55cfc4e64331d2228c30ed051950c15bdf

inc/service_ipc_dbus.h
inc/service_ipc_dbus_dispatcher.h
inc/service_main.h
plugins/wakeup-manager/inc/wakeup_manager.h
plugins/wakeup-manager/src/wakeup_manager.cpp
src/service_ipc_dbus.cpp
src/service_main.cpp

index 3be24d1..900e792 100644 (file)
@@ -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__ */
index c7f3104..8b6bae8 100644 (file)
@@ -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};
 };
index 0a92610..9b70246 100644 (file)
@@ -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();
index 77e8437..994dab3 100644 (file)
@@ -261,6 +261,9 @@ private:
 
        mas_wakeup_event_info mLastWakeupEventInfo;
 
+       unsigned int mLastWakeupEventID{0};
+       unsigned int mCurrentStreamingSessionID{0};
+
        boost::optional<ma_voice_key_status_e> mPendingVoiceKeyStatus;
        atomic_bool mStreamingCompleted{false};
        Ecore_Timer *mVoiceKeyStatusUpdateTimer{nullptr};
index 79bd057..5b6271e 100644 (file)
@@ -770,6 +770,7 @@ vector<IWakeupEventObserver*> CWakeupManager::get_wakeup_observers()
 void CWakeupManager::set_last_wakeup_event_info(mas_wakeup_event_info wakeup_info)
 {
        mLastWakeupEventInfo = wakeup_info;
+       mLastWakeupEventID++;
 }
 
 vector<ISettingValueObserver*> 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();
 
index 4c00aa3..3114dc5 100644 (file)
@@ -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<CServiceIpcDbus *>(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);
 
index 65b9ac1..0c5eedf 100644 (file)
@@ -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;
+}