PlayerThread.cpp
ActivatedModes.cpp
ttsd_server.c
+ ttsd_state.cpp
../common/tts_config_mgr.c
../common/tts_config_parser.c
)
--- /dev/null
+/*
+* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+
+#ifndef __TTSD_STATE_MANAGER_H_
+#define __TTSD_STATE_MANAGER_H_
+
+
+#include <mutex>
+
+#include "ttsd_state.h"
+
+
+class StateManager {
+public:
+ StateManager(ttsd_state_changed_cb callback);
+ ~StateManager();
+
+ ttsd_state_e getState();
+ void setState(ttsd_state_e state);
+
+private:
+ static void notifyStateChangeOnMainThread(void* data);
+
+private:
+ ttsd_state_e __beforeState;
+ ttsd_state_e __currentState;
+ std::mutex __stateMutex;
+
+ ttsd_state_changed_cb __callback;
+};
+
+#endif /* __TTSD_STATE_MANAGER_H_ */
TTSD_INTERRUPTED_STOPPED /**< Current state change 'Ready' */
} ttsd_interrupted_code_e;
+typedef enum {
+ TTSD_STATE_INVALID = -1,
+ TTSD_STATE_READY = 0, /**< 'Idle' state */
+ TTSD_STATE_SYNTHESIZING = 1, /**< 'Synthesizing' state */
+ TTSD_STATE_PLAYING = 2 /**< 'Playing' state */
+} ttsd_state_e;
+
typedef struct {
char* engine_id;
char* engine_name;
#include "ttsd_data.h"
#include "ttsd_ipc.h"
#include "ttsd_player.h"
+#include "ttsd_state.h"
#include "BackgroundVolume.h"
#include "AudioStream.h"
{
int ret = vconf_set_bool(TTS_PLAYING_STATUS_KEY, is_playing ? 1 : 0);
SLOG(LOG_INFO, tts_tag(), "[Player] Set playing status (%s). ret(%d)", is_playing ? "True" : "False", ret);
+
+ if (is_playing) {
+ ttsd_state_set_state(TTSD_STATE_PLAYING);
+ } else {
+ if (ttsd_data_get_synth_control() == TTSD_SYNTHESIS_CONTROL_DOING) {
+ ttsd_state_set_state(TTSD_STATE_SYNTHESIZING);
+ } else {
+ ttsd_state_set_state(TTSD_STATE_READY);
+ }
+ }
}
#ifdef BUF_SAVE_MODE
#include "ttsd_engine_agent.h"
#include "ttsd_main.h"
#include "ttsd_player.h"
+#include "ttsd_state.h"
#include "ttsd_server.h"
g_wait_timer = ecore_timer_add(0.05, __wait_synthesis, (void*)credential);
}
+ if (ttsd_data_get_synth_control() == TTSD_SYNTHESIS_CONTROL_DOING && ttsd_state_get_state() == TTSD_STATE_READY) {
+ ttsd_state_set_state(TTSD_STATE_SYNTHESIZING);
+ }
+
free(credential);
credential = NULL;
ttsd_data_destroy_speak_data(speak_data);
SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize config.");
}
+ if (TTSD_ERROR_NONE != ttsd_state_initialize(NULL)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Server WARNING] Fail to initialize state.");
+ }
+
/* player init */
if (ttsd_player_init()) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to initialize player init.");
}
ttsd_config_finalize();
+ ttsd_state_finalize();
int ret = TTSD_ERROR_NONE;
ret = ttsd_player_release();
--- /dev/null
+/*
+* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+#include <Ecore.h>
+
+#include "StateManager.h"
+#include "ttsd_state.h"
+
+
+using namespace std;
+
+
+static StateManager* g_stateManager = nullptr;
+
+StateManager::StateManager(ttsd_state_changed_cb callback) :
+ __beforeState(TTSD_STATE_READY), __currentState(TTSD_STATE_READY), __callback(callback)
+{
+ SLOG(LOG_INFO, tts_tag(), "[StateManager] Constructor");
+}
+
+StateManager::~StateManager()
+{
+ SLOG(LOG_INFO, tts_tag(), "[StateManager] Destructor");
+ __beforeState = TTSD_STATE_READY;
+ __currentState = TTSD_STATE_READY;
+ __callback = nullptr;
+}
+
+ttsd_state_e StateManager::getState()
+{
+ lock_guard<mutex> lock(__stateMutex);
+ return __currentState;
+}
+
+void StateManager::setState(ttsd_state_e state)
+{
+ unique_lock<mutex> lock(__stateMutex);
+ __beforeState = __currentState;
+ __currentState = state;
+
+ if (__beforeState == __currentState) {
+ return;
+ }
+
+ SLOG(LOG_INFO, tts_tag(), "[StateManager] StateManager is changed. (%d) -> (%d)", __beforeState, __currentState);
+ lock.unlock();
+ ecore_main_loop_thread_safe_call_async(notifyStateChangeOnMainThread, static_cast<void*>(this));
+}
+
+void StateManager::notifyStateChangeOnMainThread(void* data)
+{
+ if (nullptr == data) {
+ SLOG(LOG_ERROR, tts_tag(), "[StateManager] Invalid data is passed");
+ return;
+ }
+
+ StateManager* stateManager = static_cast<StateManager*>(data);
+
+ unique_lock<mutex> lock(stateManager->__stateMutex);
+ ttsd_state_e before = stateManager->__beforeState;
+ ttsd_state_e current = stateManager->__currentState;
+ lock.unlock();
+
+ if (stateManager->__callback) {
+ stateManager->__callback(before, current);
+ }
+}
+
+
+int ttsd_state_initialize(ttsd_state_changed_cb callback)
+{
+ g_stateManager = new(nothrow) StateManager(callback);
+
+ if (nullptr == g_stateManager) {
+ SLOG(LOG_ERROR, tts_tag(), "[StateManager] Fail to initialize StateManager");
+ return TTSD_ERROR_OUT_OF_MEMORY;
+ }
+
+ return TTSD_ERROR_NONE;
+}
+
+int ttsd_state_finalize()
+{
+ if (nullptr == g_stateManager) {
+ SLOG(LOG_ERROR, tts_tag(), "[StateManager] StateManager is not initialized");
+ return TTSD_ERROR_INVALID_STATE;
+ }
+
+ delete g_stateManager;
+ g_stateManager = nullptr;
+
+ return TTSD_ERROR_NONE;
+}
+
+int ttsd_state_set_state(ttsd_state_e state)
+{
+ if (nullptr == g_stateManager) {
+ SLOG(LOG_ERROR, tts_tag(), "[StateManager] StateManager is not initialized");
+ return TTSD_ERROR_INVALID_STATE;
+ }
+
+ g_stateManager->setState(state);
+ return TTSD_ERROR_NONE;
+}
+
+ttsd_state_e ttsd_state_get_state()
+{
+ if (nullptr == g_stateManager) {
+ SLOG(LOG_ERROR, tts_tag(), "[StateManager] StateManager is not initialized");
+ return TTSD_STATE_INVALID;
+ }
+
+ return g_stateManager->getState();
+}
--- /dev/null
+/*
+* Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+#ifndef __TTSD_STATE_H__
+#define __TTSD_STATE_H__
+
+#include "ttsd_main.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef void (*ttsd_state_changed_cb)(ttsd_state_e before, ttsd_state_e current);
+
+
+int ttsd_state_initialize(ttsd_state_changed_cb callback);
+
+int ttsd_state_finalize();
+
+int ttsd_state_set_state(ttsd_state_e state);
+
+ttsd_state_e ttsd_state_get_state();
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TTSD_STATE_H__ */