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
{
mas_wakeup_event_info mLastWakeupEventInfo;
+ boost::optional<ma_voice_key_status_e> mPendingVoiceKeyStatus;
+ atomic_bool mStreamingCompleted{false};
+ Ecore_Timer *mVoiceKeyStatusUpdateTimer{nullptr};
+ mutex mVoiceKeyStatusUpdateMutex;
+
mutex mMutex;
};
}
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<CWakeupManager*>(data);
+ manager->update_pending_voice_key_status();
+ return ECORE_CALLBACK_CANCEL;
+ }, static_cast<void*>(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<IWakeupEventObserver*> CWakeupManager::get_wakeup_observers()
{
return mWakeupObservers;
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;