CClientManager* mClientManager{nullptr};
IApplicationManager* mApplicationManager{nullptr};
+
+ int mLocalMessagePortID{-1};
+ const std::string mLocalMessagePortName{"audio-processor"};
};
#endif /* __SERVICE_IPC_DBUS_H__ */
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 {
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};
};
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();
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};
void CWakeupManager::set_last_wakeup_event_info(mas_wakeup_event_info wakeup_info)
{
mLastWakeupEventInfo = wakeup_info;
+ mLastWakeupEventID++;
}
vector<ISettingValueObserver*> CWakeupManager::get_setting_observers()
{
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();
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) {
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);
{
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;
+}