#include "ActivatedModes.h"
+
ActivatedModes::ActivatedModes()
{
- for (int i = 0; i < __numOfModes; i++) {
- __modeCounts[i] = 0;
+ for (int i = 0; i < mNumOfModes; i++) {
+ mModeCounts[i] = 0;
}
- __modeFlags[0] = TTSE_MODE_MASK_DEFAULT;
- __modeFlags[1] = TTSE_MODE_MASK_NOTIFICATION;
- __modeFlags[2] = TTSE_MODE_MASK_SCREEN_READER;
- __modeFlags[3] = TTSE_MODE_MASK_INTERRUPT;
+ mModeFlags[0] = TTSE_MODE_MASK_DEFAULT;
+ mModeFlags[1] = TTSE_MODE_MASK_NOTIFICATION;
+ mModeFlags[2] = TTSE_MODE_MASK_SCREEN_READER;
+ mModeFlags[3] = TTSE_MODE_MASK_INTERRUPT;
}
ActivatedModes::~ActivatedModes()
void ActivatedModes::addMode(ttsd_mode_e mode)
{
int index = getIndex(mode);
- __modeCounts[index]++;
+ mModeCounts[index]++;
}
void ActivatedModes::removeMode(ttsd_mode_e mode)
{
int index = getIndex(mode);
- __modeCounts[index]--;
+ mModeCounts[index]--;
}
int ActivatedModes::getModes()
{
int result = 0;
- for (int i = 0; i < __numOfModes; i++) {
- if (__modeCounts[i] > 0) {
- result |= __modeFlags[i];
+ for (int i = 0; i < mNumOfModes; i++) {
+ if (mModeCounts[i] > 0) {
+ result |= mModeFlags[i];
}
}
int getIndex(ttsd_mode_e mode);
private:
- static const int __numOfModes = 4;
- ttse_mode_mask_e __modeFlags[__numOfModes];
+ static const int mNumOfModes = 4;
+ ttse_mode_mask_e mModeFlags[mNumOfModes];
- int __modeCounts[__numOfModes];
+ int mModeCounts[mNumOfModes];
};
AudioStream::AudioStream():
- __audioHandle(nullptr),
- __audioType(TTSE_AUDIO_TYPE_RAW_S16),
- __audioRate(16000),
- __prepared(false),
- __streamInfo(nullptr),
- __focusAquired(false),
- __state(AUDIO_STATE_NONE)
+ mAudioHandle(nullptr),
+ mAudioType(TTSE_AUDIO_TYPE_RAW_S16),
+ mAudioRate(16000),
+ mPrepared(false),
+ mStreamInfo(nullptr),
+ mFocusAquired(false),
+ mState(AUDIO_STATE_NONE)
{
createSoundStreamInfo();
- createAudioHandle(__audioType, __audioRate);
+ createAudioHandle(mAudioType, mAudioRate);
}
AudioStream::~AudioStream()
{
- __focusAquired = false;
+ mFocusAquired = false;
unprepareAudioOut();
destroyAudioHandle();
void AudioStream::destroySoundStreamInfo()
{
- int ret = sound_manager_destroy_stream_information(__streamInfo);
+ int ret = sound_manager_destroy_stream_information(mStreamInfo);
if (SOUND_MANAGER_ERROR_NONE != ret) {
SLOG(LOG_WARN, tts_tag(), "[AudioStream] Fail to destroy stream info");
}
- __streamInfo = nullptr;
- __focusAquired = false;
+ mStreamInfo = nullptr;
+ mFocusAquired = false;
}
int AudioStream::setAudioFormat(ttse_audio_type_e type, int rate)
{
- if (__audioType == type && __audioRate == rate) {
+ if (mAudioType == type && mAudioRate == rate) {
return TTSD_ERROR_NONE;
}
SLOG(LOG_INFO, tts_tag(), "[AudioStream] Audio info is different. type:(%d)/(%d), rate:(%d)/(%d)",
- __audioType, type, __audioRate, rate);
+ mAudioType, type, mAudioRate, rate);
destroyAudioHandle();
if (TTSD_ERROR_NONE != createAudioHandle(type, rate)) {
return TTSD_ERROR_OPERATION_FAILED;
}
- if (__focusAquired) {
+ if (mFocusAquired) {
acquireSoundFocus();
}
- __state = AUDIO_STATE_READY;
+ mState = AUDIO_STATE_READY;
return TTSD_ERROR_NONE;
}
int AudioStream::acquireSoundFocus()
{
if (isAudioHandleValid() == false) {
- int ret = createAudioHandle(__audioType, __audioRate);
+ int ret = createAudioHandle(mAudioType, mAudioRate);
if (TTSD_ERROR_NONE != ret) {
SLOG(LOG_ERROR, tts_tag(), "[AudioStream] Fail to create the audio handle. ret(%s)", get_error_message(ret));
return TTSD_ERROR_OPERATION_FAILED;
}
}
- int ret = sound_manager_acquire_focus(__streamInfo, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, nullptr);
+ int ret = sound_manager_acquire_focus(mStreamInfo, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, nullptr);
if (SOUND_MANAGER_ERROR_NONE != ret) {
SLOG(LOG_WARN, tts_tag(), "[AudioStream] Fail to acquire focus. ret(%s)", get_error_message(ret));
} else {
SLOG(LOG_DEBUG, tts_tag(), "[AudioStream] Success to acquire focus");
}
- ret = audio_out_set_sound_stream_info(__audioHandle, __streamInfo);
+ ret = audio_out_set_sound_stream_info(mAudioHandle, mStreamInfo);
if (AUDIO_IO_ERROR_NONE != ret) {
SLOG(LOG_WARN, tts_tag(), "[AudioStream] Fail to set stream info. ret(%s)", get_error_message(ret));
return TTSD_ERROR_OPERATION_FAILED;
}
- __focusAquired = true;
+ mFocusAquired = true;
return TTSD_ERROR_NONE;
}
}
sound_stream_focus_state_e focusState = SOUND_STREAM_FOCUS_STATE_RELEASED;
- int ret = sound_manager_get_focus_state(__streamInfo, &focusState, nullptr);
+ int ret = sound_manager_get_focus_state(mStreamInfo, &focusState, nullptr);
if (SOUND_MANAGER_ERROR_NONE != ret) {
SLOG(LOG_WARN, tts_tag(), "[AudioStream] Fail to get focus state: %d", ret);
}
return TTSD_ERROR_NONE;
}
- ret = sound_manager_release_focus(__streamInfo, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, nullptr);
+ ret = sound_manager_release_focus(mStreamInfo, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, nullptr);
if (SOUND_MANAGER_ERROR_NONE != ret) {
SLOG(LOG_WARN, tts_tag(), "[AudioStream] Fail to release focus");
return TTSD_ERROR_OPERATION_FAILED;
}
- __focusAquired = false;
+ mFocusAquired = false;
return TTSD_ERROR_NONE;
}
int AudioStream::prepareAudioOut()
{
- if (__prepared) {
+ if (mPrepared) {
SLOG(LOG_DEBUG, tts_tag(), "[AudioStream] Audio is already prepared");
return TTSD_ERROR_NONE;
}
if (isAudioHandleValid() == false) {
- int ret = createAudioHandle(__audioType, __audioRate);
+ int ret = createAudioHandle(mAudioType, mAudioRate);
if (TTSD_ERROR_NONE != ret) {
SLOG(LOG_ERROR, tts_tag(), "[AudioStream] Fail to create the audio handle. ret(%s)", get_error_message(ret));
return TTSD_ERROR_OPERATION_FAILED;
}
}
- int ret = audio_out_prepare(__audioHandle);
+ int ret = audio_out_prepare(mAudioHandle);
if (AUDIO_IO_ERROR_NONE != ret) {
SLOG(LOG_ERROR, tts_tag(), "[AudioStream] Fail to prepare audio : %d", ret);
return TTSD_ERROR_OPERATION_FAILED;
}
- __prepared = true;
- __state = AUDIO_STATE_PLAY;
+ mPrepared = true;
+ mState = AUDIO_STATE_PLAY;
return TTSD_ERROR_NONE;
}
int AudioStream::playAudioData(char* buffer, unsigned int length)
{
- if (false == __prepared) {
+ if (false == mPrepared) {
SLOG(LOG_ERROR, tts_tag(), "[AudioStream] Audio is not prepared");
return TTSD_ERROR_OPERATION_FAILED;
}
return TTSD_ERROR_OPERATION_FAILED;
}
- int ret = audio_out_write(__audioHandle, static_cast<void*>(buffer), length);
+ int ret = audio_out_write(mAudioHandle, static_cast<void*>(buffer), length);
if (0 > ret) {
SLOG(LOG_ERROR, tts_tag(), "[AudioStream] Fail to audio write - %d", ret);
return TTSD_ERROR_OPERATION_FAILED;
int AudioStream::unprepareAudioOut()
{
- if (false == __prepared) {
+ if (false == mPrepared) {
SLOG(LOG_DEBUG, tts_tag(), "[AudioStream] Audio is not prepared");
return TTSD_ERROR_NONE;
}
return TTSD_ERROR_NONE;
}
- int ret = audio_out_unprepare(__audioHandle);
+ int ret = audio_out_unprepare(mAudioHandle);
if (AUDIO_IO_ERROR_NONE != ret) {
SLOG(LOG_ERROR, tts_tag(), "[AudioStream] Fail to prepare audio : %d", ret);
return TTSD_ERROR_OPERATION_FAILED;
}
- __prepared = false;
- __state = AUDIO_STATE_READY;
+ mPrepared = false;
+ mState = AUDIO_STATE_READY;
return TTSD_ERROR_NONE;
}
bool AudioStream::isAudioHandleValid()
{
- if (__audioHandle == nullptr) {
+ if (mAudioHandle == nullptr) {
return false;
}
bool AudioStream::isStreamInfoValid()
{
- if (__streamInfo == nullptr) {
+ if (mStreamInfo == nullptr) {
return false;
}
void AudioStream::waitForPlay()
{
- __state = AUDIO_STATE_WAIT_FOR_PLAYING;
+ mState = AUDIO_STATE_WAIT_FOR_PLAYING;
}
AudioStream::AudioState AudioStream::getState()
{
- return __state;
+ return mState;
}
int AudioStream::createAudioHandle(ttse_audio_type_e type, int rate)
sample_type = AUDIO_SAMPLE_TYPE_U8;
}
- int ret = audio_out_create_new(rate, AUDIO_CHANNEL_MONO, sample_type, &__audioHandle);
+ int ret = audio_out_create_new(rate, AUDIO_CHANNEL_MONO, sample_type, &mAudioHandle);
if (AUDIO_IO_ERROR_NONE != ret) {
SLOG(LOG_ERROR, tts_tag(), "[AudioStream] Fail to create audio out handle. ret(%s)", get_error_message(ret));
return TTSD_ERROR_OPERATION_FAILED;
}
- __audioType = type;
- __audioRate = rate;
- __state = AUDIO_STATE_READY;
+ mAudioType = type;
+ mAudioRate = rate;
+ mState = AUDIO_STATE_READY;
SLOG(LOG_INFO, tts_tag(), "[AudioStream] Create audio");
return TTSD_ERROR_NONE;
void AudioStream::destroyAudioHandle()
{
- if (nullptr == __audioHandle) {
+ if (nullptr == mAudioHandle) {
SLOG(LOG_INFO, tts_tag(), "[AudioStream] Audio handle is not exist");
return;
}
- int ret = audio_out_destroy(__audioHandle);
+ int ret = audio_out_destroy(mAudioHandle);
if (AUDIO_IO_ERROR_NONE != ret) {
SLOG(LOG_ERROR, tts_tag(), "[AudioStream] Fail to destroy audio out handle. ret(%s)", get_error_message(ret));
} else {
SLOG(LOG_INFO, tts_tag(), "[AudioStream] Destroy audio");
}
- __state = AUDIO_STATE_NONE;
+ mState = AUDIO_STATE_NONE;
}
int AudioStream::createSoundStreamInfo()
}
}
- int ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_INFORMATION, __focusStateChangedCallback, this, &__streamInfo);
- if (SOUND_MANAGER_ERROR_NONE != ret || __streamInfo == nullptr) {
+ int ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_INFORMATION, focusStateChangedCallback, this, &mStreamInfo);
+ if (SOUND_MANAGER_ERROR_NONE != ret || mStreamInfo == nullptr) {
SLOG(LOG_ERROR, tts_tag(), "[AudioStream] Fail to create stream info(%d/%s)", ret, get_error_message(ret));
- __streamInfo = nullptr;
+ mStreamInfo = nullptr;
return TTSD_ERROR_OPERATION_FAILED;
}
- __focusAquired = false;
+ mFocusAquired = false;
SLOG(LOG_DEBUG, tts_tag(), "[AudioStream] Create stream info");
return TTSD_ERROR_NONE;
}
-void AudioStream::__focusStateChangedCallback(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask,
+void AudioStream::focusStateChangedCallback(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask,
sound_stream_focus_state_e focus_state, sound_stream_focus_change_reason_e reason_for_change,
int sound_behavior, const char *extra_info, void *user_data)
{
int playAudioData(char* buffer, unsigned int length);
private:
- static void __focusStateChangedCallback(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask,
+ static void focusStateChangedCallback(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask,
sound_stream_focus_state_e focus_state, sound_stream_focus_change_reason_e reason_for_change, int sound_behavior, const char *extra_info,
void *user_data);
void destroySoundStreamInfo();
private:
- audio_out_h __audioHandle;
- ttse_audio_type_e __audioType;
- int __audioRate;
- bool __prepared;
+ audio_out_h mAudioHandle;
+ ttse_audio_type_e mAudioType;
+ int mAudioRate;
+ bool mPrepared;
- sound_stream_info_h __streamInfo;
- bool __focusAquired;
+ sound_stream_info_h mStreamInfo;
+ bool mFocusAquired;
- AudioState __state;
+ AudioState mState;
};
using namespace std;
-static const char* __get_ducking_stream(sound_stream_type_e stream_type)
+
+static const char* get_ducking_stream(sound_stream_type_e stream_type)
{
switch (stream_type)
{
return "Non matched stream";
}
-static void __sound_stream_ducking_state_changed_cb(sound_stream_ducking_h stream_ducking, bool is_ducked, void *user_data)
+static void ducking_state_changed_cb(sound_stream_ducking_h stream_ducking, bool is_ducked, void *user_data)
{
SLOG(LOG_DEBUG, tts_tag(), "[BackgroundVolume] is ducked : %d", is_ducked);
return;
}
BackgroundVolume::BackgroundVolume(long long int duckingDuration):
- __duckingDuration(duckingDuration),
- __mediaStream(nullptr),
- __notificationStream(nullptr),
- __alarmStream(nullptr),
- __volumeRatio(0.0),
- __isVolumeDucked(false),
- __changeVolumeTime(chrono::steady_clock::now()),
- __postponedRecoverTimer(nullptr),
- __postponedModifyTimer(nullptr)
+ mDuckingDuration(duckingDuration),
+ mMediaStream(nullptr),
+ mNotificationStream(nullptr),
+ mAlarmStream(nullptr),
+ mVolumeRatio(0.0),
+ mVolumeDucked(false),
+ mChangeVolumeTime(chrono::steady_clock::now()),
+ mPostponedRecoverTimer(nullptr),
+ mPostponedModifyTimer(nullptr)
{
int ret = createHandles();
if (TTSD_ERROR_NONE != ret) {
BackgroundVolume::~BackgroundVolume()
{
long long int diff = getDurationAfterDucking();
- if (diff < __duckingDuration) {
- usleep(__duckingDuration * 1000);
+ if (diff < mDuckingDuration) {
+ usleep(mDuckingDuration * 1000);
}
deactivateDuckingAll();
- if (nullptr != __postponedModifyTimer) {
- void* result = ecore_timer_del(__postponedModifyTimer);
- __postponedModifyTimer = nullptr;
+ if (nullptr != mPostponedModifyTimer) {
+ void* result = ecore_timer_del(mPostponedModifyTimer);
+ mPostponedModifyTimer = nullptr;
SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Remove modification timer. result(%p)", result);
}
- if (nullptr != __postponedRecoverTimer) {
- void* result = ecore_timer_del(__postponedRecoverTimer);
- __postponedRecoverTimer = nullptr;
+ if (nullptr != mPostponedRecoverTimer) {
+ void* result = ecore_timer_del(mPostponedRecoverTimer);
+ mPostponedRecoverTimer = nullptr;
SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Remove recover timer. result(%p)", result);
}
- if (__mediaStream) {
- int ret = sound_manager_destroy_stream_ducking(__mediaStream);
+ if (mMediaStream) {
+ int ret = sound_manager_destroy_stream_ducking(mMediaStream);
if (SOUND_MANAGER_ERROR_NONE != ret)
SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Fail to destroy media stream ducking, ret(%d)", ret);
- __mediaStream = nullptr;
+ mMediaStream = nullptr;
} else {
SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Ducking handle for media stream is already destroyed");
}
- if (__notificationStream) {
- int ret = sound_manager_destroy_stream_ducking(__notificationStream);
+ if (mNotificationStream) {
+ int ret = sound_manager_destroy_stream_ducking(mNotificationStream);
if (SOUND_MANAGER_ERROR_NONE != ret)
SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Fail to destroy notification stream ducking, ret(%d)", ret);
- __notificationStream = nullptr;
+ mNotificationStream = nullptr;
} else {
SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Ducking handle for notification stream is already destroyed");
}
- if (__alarmStream) {
- int ret = sound_manager_destroy_stream_ducking(__alarmStream);
+ if (mAlarmStream) {
+ int ret = sound_manager_destroy_stream_ducking(mAlarmStream);
if (SOUND_MANAGER_ERROR_NONE != ret)
SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Fail to destroy alarm stream ducking, ret(%d)", ret);
- __alarmStream = nullptr;
+ mAlarmStream = nullptr;
} else {
SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Ducking handle for alarm stream is already destroyed");
}
void BackgroundVolume::setVolumeRatio(double ratio)
{
- SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Volume is changed from (%lf) to (%lf).", __volumeRatio.load(), ratio);
- __volumeRatio = ratio;
+ SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Volume is changed from (%lf) to (%lf).", mVolumeRatio.load(), ratio);
+ mVolumeRatio = ratio;
ecore_main_loop_thread_safe_call_async(modifyVolumeOnMainThread, static_cast<void*>(this));
}
}
BackgroundVolume* backgroundVolume = static_cast<BackgroundVolume*>(data);
- if (!backgroundVolume->__isVolumeDucked.load()) {
+ if (!backgroundVolume->mVolumeDucked.load()) {
SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Volume is not changed yet.");
return;
}
- if (backgroundVolume->__postponedModifyTimer != nullptr) {
- SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Reserved volume modification exist. (%p)", backgroundVolume->__postponedModifyTimer);
+ if (backgroundVolume->mPostponedModifyTimer != nullptr) {
+ SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Reserved volume modification exist. (%p)", backgroundVolume->mPostponedModifyTimer);
return;
}
long long int diff = backgroundVolume->getDurationAfterDucking();
- if (diff >= backgroundVolume->__duckingDuration) {
- double ratio = backgroundVolume->__volumeRatio.load();
+ if (diff >= backgroundVolume->mDuckingDuration) {
+ double ratio = backgroundVolume->mVolumeRatio.load();
SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Modify volume ratio(%lf) directly", ratio);
backgroundVolume->deactivateDuckingAll();
backgroundVolume->activateDuckingAll(0, ratio);
} else {
- double delay = static_cast<double>(backgroundVolume->__duckingDuration - diff) / 1000.0;
- backgroundVolume->__postponedModifyTimer = ecore_timer_add(delay, postponedModifyTimerCb, data);
- SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Delay volume modification (%p), delay(%lf)", backgroundVolume->__postponedModifyTimer, delay);
+ double delay = static_cast<double>(backgroundVolume->mDuckingDuration - diff) / 1000.0;
+ backgroundVolume->mPostponedModifyTimer = ecore_timer_add(delay, postponedModifyTimerCb, data);
+ SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Delay volume modification (%p), delay(%lf)", backgroundVolume->mPostponedModifyTimer, delay);
}
}
}
BackgroundVolume* backgroundVolume = static_cast<BackgroundVolume*>(data);
- double ratio = backgroundVolume->__volumeRatio.load();
+ double ratio = backgroundVolume->mVolumeRatio.load();
backgroundVolume->deactivateDuckingAll();
backgroundVolume->activateDuckingAll(0, ratio);
SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Delayed volume modification success. ratio(%lf)", ratio);
- backgroundVolume->__postponedModifyTimer = nullptr;
+ backgroundVolume->mPostponedModifyTimer = nullptr;
return EINA_FALSE;
}
double BackgroundVolume::getVolumeRatio()
{
- return __volumeRatio.load();
+ return mVolumeRatio.load();
}
void BackgroundVolume::applyVolumeRatio()
{
- __isVolumeDucked = true;
+ mVolumeDucked = true;
ecore_main_loop_thread_safe_call_async(changeVolumeOnMainThread, static_cast<void*>(this));
}
}
BackgroundVolume* backgroundVolume = static_cast<BackgroundVolume*>(data);
- if (nullptr != backgroundVolume->__postponedRecoverTimer) {
- void* result = ecore_timer_del(backgroundVolume->__postponedRecoverTimer);
- backgroundVolume->__postponedRecoverTimer = nullptr;
+ if (nullptr != backgroundVolume->mPostponedRecoverTimer) {
+ void* result = ecore_timer_del(backgroundVolume->mPostponedRecoverTimer);
+ backgroundVolume->mPostponedRecoverTimer = nullptr;
SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Remove recover timer. result(%p)", result);
}
- double ratio = backgroundVolume->__volumeRatio.load();
+ double ratio = backgroundVolume->mVolumeRatio.load();
SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Volume ratio(%lf)", ratio);
if (0.0 > ratio || 1.0 < ratio) {
SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Invalid ratio(%lf)", ratio);
return;
}
- backgroundVolume->activateDuckingAll(backgroundVolume->__duckingDuration, ratio);
+ backgroundVolume->activateDuckingAll(backgroundVolume->mDuckingDuration, ratio);
}
void BackgroundVolume::activateDuckingAll(unsigned int duration, double ratio)
activateDucking(SOUND_STREAM_TYPE_NOTIFICATION, duration, ratio);
activateDucking(SOUND_STREAM_TYPE_ALARM, duration, ratio);
- __changeVolumeTime = chrono::steady_clock::now();
+ mChangeVolumeTime = chrono::steady_clock::now();
}
bool BackgroundVolume::activateDucking(sound_stream_type_e type, unsigned int duration, double ratio)
sound_stream_ducking_h handle = getStreamDuckingHandle(type);
sound_manager_is_ducked(handle, &isDucked);
if (isDucked) {
- SLOG(LOG_DEBUG, tts_tag(), "[BackgroundVolume] The %s is already ducked", __get_ducking_stream(type));
+ SLOG(LOG_DEBUG, tts_tag(), "[BackgroundVolume] The %s is already ducked", get_ducking_stream(type));
return false;
}
if (SOUND_MANAGER_ERROR_NONE != sound_manager_activate_ducking(handle, duration, ratio)) {
- SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Fail to activate ducking for %s", __get_ducking_stream(type));
+ SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Fail to activate ducking for %s", get_ducking_stream(type));
return false;
}
- SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Activate ducking for %s", __get_ducking_stream(type));
+ SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Activate ducking for %s", get_ducking_stream(type));
return true;
}
void BackgroundVolume::recoverVolumeRatio()
{
- __isVolumeDucked = false;
+ mVolumeDucked = false;
ecore_main_loop_thread_safe_call_async(recoverVolumeOnMainThread, static_cast<void*>(this));
}
}
BackgroundVolume* backgroundVolume = static_cast<BackgroundVolume*>(data);
- if (nullptr != backgroundVolume->__postponedRecoverTimer) {
- SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Reserved volume recover exist. (%p)", backgroundVolume->__postponedRecoverTimer);
+ if (nullptr != backgroundVolume->mPostponedRecoverTimer) {
+ SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Reserved volume recover exist. (%p)", backgroundVolume->mPostponedRecoverTimer);
return;
}
- if (nullptr != backgroundVolume->__postponedModifyTimer) {
- void* result = ecore_timer_del(backgroundVolume->__postponedModifyTimer);
- backgroundVolume->__postponedModifyTimer = nullptr;
+ if (nullptr != backgroundVolume->mPostponedModifyTimer) {
+ void* result = ecore_timer_del(backgroundVolume->mPostponedModifyTimer);
+ backgroundVolume->mPostponedModifyTimer = nullptr;
SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Remove modification timer. result(%p)", result);
}
long long int diff = backgroundVolume->getDurationAfterDucking();
- if (diff >= backgroundVolume->__duckingDuration) {
+ if (diff >= backgroundVolume->mDuckingDuration) {
SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Direct deactivate ducking");
backgroundVolume->deactivateDuckingAll();
} else {
- double delay = static_cast<double>(backgroundVolume->__duckingDuration - diff) / 1000.0;
- backgroundVolume->__postponedRecoverTimer = ecore_timer_add(delay, postponedRecoverTimerCb, data);
- SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Delay deactivate ducking (%p), delay(%f)", backgroundVolume->__postponedRecoverTimer, delay);
+ double delay = static_cast<double>(backgroundVolume->mDuckingDuration - diff) / 1000.0;
+ backgroundVolume->mPostponedRecoverTimer = ecore_timer_add(delay, postponedRecoverTimerCb, data);
+ SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Delay deactivate ducking (%p), delay(%f)", backgroundVolume->mPostponedRecoverTimer, delay);
}
}
long long int BackgroundVolume::getDurationAfterDucking()
{
auto currentTime = chrono::steady_clock::now();
- chrono::milliseconds diff = chrono::duration_cast<chrono::milliseconds>(currentTime - __changeVolumeTime);
+ chrono::milliseconds diff = chrono::duration_cast<chrono::milliseconds>(currentTime - mChangeVolumeTime);
return diff.count();
}
BackgroundVolume* backgroundVolume = static_cast<BackgroundVolume*>(data);
backgroundVolume->deactivateDuckingAll();
- backgroundVolume->__postponedRecoverTimer = nullptr;
+ backgroundVolume->mPostponedRecoverTimer = nullptr;
SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Delayed unset policy success");
return EINA_FALSE;
sound_stream_ducking_h handle = getStreamDuckingHandle(type);
sound_manager_is_ducked(handle, &isDucked);
if (!isDucked) {
- SLOG(LOG_DEBUG, tts_tag(), "[BackgroundVolume] The %s is already recovered from ducking", __get_ducking_stream(type));
+ SLOG(LOG_DEBUG, tts_tag(), "[BackgroundVolume] The %s is already recovered from ducking", get_ducking_stream(type));
return;
}
if (SOUND_MANAGER_ERROR_NONE != sound_manager_deactivate_ducking(handle)) {
- SLOG(LOG_WARN, tts_tag(), "[BackgroundVolume] Fail to deactivate ducking for %s", __get_ducking_stream(type));
+ SLOG(LOG_WARN, tts_tag(), "[BackgroundVolume] Fail to deactivate ducking for %s", get_ducking_stream(type));
} else {
- SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Deactivate ducking for %s", __get_ducking_stream(type));
+ SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Deactivate ducking for %s", get_ducking_stream(type));
}
}
{
SLOG(LOG_INFO, tts_tag(), "[BackgroundVolume] Create ducking handles");
- if (nullptr == __mediaStream) {
- int ret = sound_manager_create_stream_ducking(SOUND_STREAM_TYPE_MEDIA, __sound_stream_ducking_state_changed_cb, nullptr, &__mediaStream);
+ if (nullptr == mMediaStream) {
+ int ret = sound_manager_create_stream_ducking(SOUND_STREAM_TYPE_MEDIA,
+ ducking_state_changed_cb, nullptr, &mMediaStream);
if (SOUND_MANAGER_ERROR_NONE != ret) {
SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Fail to create stream ducking for type media, ret(%d/%s)", ret, get_error_message(ret));
- __mediaStream = nullptr;
+ mMediaStream = nullptr;
return TTSD_ERROR_OPERATION_FAILED;
}
}
- if (nullptr == __notificationStream) {
- int ret = sound_manager_create_stream_ducking(SOUND_STREAM_TYPE_NOTIFICATION, __sound_stream_ducking_state_changed_cb, nullptr, &__notificationStream);
+ if (nullptr == mNotificationStream) {
+ int ret = sound_manager_create_stream_ducking(SOUND_STREAM_TYPE_NOTIFICATION,
+ ducking_state_changed_cb, nullptr, &mNotificationStream);
if (SOUND_MANAGER_ERROR_NONE != ret) {
SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Fail to create stream ducking for notification type, ret(%d/%s)", ret, get_error_message(ret));
- __notificationStream = nullptr;
+ mNotificationStream = nullptr;
return TTSD_ERROR_OPERATION_FAILED;
}
}
- if (nullptr == __alarmStream) {
- int ret = sound_manager_create_stream_ducking(SOUND_STREAM_TYPE_ALARM, __sound_stream_ducking_state_changed_cb, nullptr, &__alarmStream);
+ if (nullptr == mAlarmStream) {
+ int ret = sound_manager_create_stream_ducking(SOUND_STREAM_TYPE_ALARM,
+ ducking_state_changed_cb, nullptr, &mAlarmStream);
if (SOUND_MANAGER_ERROR_NONE != ret) {
SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Fail to create stream ducking for alarm type, ret(%d/%s)", ret, get_error_message(ret));
- __alarmStream = nullptr;
+ mAlarmStream = nullptr;
return TTSD_ERROR_OPERATION_FAILED;
}
}
bool BackgroundVolume::isDuckingHandleValid()
{
- if (__mediaStream == nullptr || __notificationStream == nullptr || __alarmStream == nullptr) {
+ if (mMediaStream == nullptr || mNotificationStream == nullptr || mAlarmStream == nullptr) {
return false;
}
switch (type)
{
case SOUND_STREAM_TYPE_MEDIA:
- return __mediaStream;
+ return mMediaStream;
case SOUND_STREAM_TYPE_NOTIFICATION:
- return __notificationStream;
+ return mNotificationStream;
case SOUND_STREAM_TYPE_ALARM:
- return __alarmStream;
+ return mAlarmStream;
default:
SLOG(LOG_ERROR, tts_tag(), "[BackgroundVolume] Invalid stream type (%d)", type);
void deactivateDucking(sound_stream_type_e type);
private:
- const long long int __duckingDuration;
- sound_stream_ducking_h __mediaStream;
- sound_stream_ducking_h __notificationStream;
- sound_stream_ducking_h __alarmStream;
- std::atomic<double> __volumeRatio;
- std::atomic<bool> __isVolumeDucked;
+ const long long int mDuckingDuration;
+ sound_stream_ducking_h mMediaStream;
+ sound_stream_ducking_h mNotificationStream;
+ sound_stream_ducking_h mAlarmStream;
+ std::atomic<double> mVolumeRatio;
+ std::atomic<bool> mVolumeDucked;
- std::chrono::time_point<std::chrono::steady_clock> __changeVolumeTime;
- Ecore_Timer* __postponedRecoverTimer;
- Ecore_Timer* __postponedModifyTimer;
+ std::chrono::time_point<std::chrono::steady_clock> mChangeVolumeTime;
+ Ecore_Timer* mPostponedRecoverTimer;
+ Ecore_Timer* mPostponedModifyTimer;
};
using namespace std;
+
void PlayerThread::runThread(PlayerThread* player)
{
SLOG(LOG_INFO, tts_tag(), "[Player] Run player thread");
PlayerThread::PlayerThread(PlayUtteranceCallback threadFucntion)
{
SLOG(LOG_INFO, tts_tag(), "[PlayerThread] Constructor");
- __currentUid = TTS_INVALID_UID;
- __playerAvailable = true;
- __playUtterance = threadFucntion;
+ mCurrentUid = TTS_INVALID_UID;
+ mPlayerAvailable = true;
+ mPlayUtterance = threadFucntion;
SLOG(LOG_INFO, tts_tag(), "[PlayerThread] Start thread");
- __playerThread = thread(runThread, this);
+ mPlayerThread = thread(runThread, this);
}
PlayerThread::~PlayerThread()
{
SLOG(LOG_INFO, tts_tag(), "[PlayerThread] Destructor");
- unique_lock<mutex> controlLock(__controlMutex);
- __playerAvailable = false;
- __playUtterance = nullptr;
+ unique_lock<mutex> controlLock(mControlMutex);
+ mPlayerAvailable = false;
+ mPlayUtterance = nullptr;
tryToStopPlayer();
SLOG(LOG_INFO, tts_tag(), "[PlayerThread] Thread is stopped or waiting");
- __threadCond.notify_all();
- __playerThread.join();
+ mThreadCond.notify_all();
+ mPlayerThread.join();
SLOG(LOG_INFO, tts_tag(), "[PlayerThread] Finish thread");
}
void PlayerThread::tryToStopPlayer()
{
- __currentUid = TTS_INVALID_UID;
+ mCurrentUid = TTS_INVALID_UID;
- unique_lock<mutex> stopCheckLock(__stopCheckMutex);
- cv_status ret = __stopCheckCond.wait_for(stopCheckLock, chrono::milliseconds(500));
+ unique_lock<mutex> stopCheckLock(mStopCheckMutex);
+ cv_status ret = mStopCheckCond.wait_for(stopCheckLock, chrono::milliseconds(500));
if (ret == cv_status::timeout) {
SLOG(LOG_WARN, tts_tag(), "[PlayerThread] Timeout stop request");
}
bool PlayerThread::isPlayerAvailable()
{
- return __playerAvailable.load();
+ return mPlayerAvailable.load();
}
unsigned int PlayerThread::getCurrentUid()
{
- return __currentUid.load();
+ return mCurrentUid.load();
}
bool PlayerThread::isCurrentUid(unsigned int uid)
return false;
}
- if (uid != __currentUid.load()) {
+ if (uid != mCurrentUid.load()) {
return false;
}
void PlayerThread::requestPlay(unsigned int uid)
{
- lock_guard<mutex> lock(__controlMutex);
+ lock_guard<mutex> lock(mControlMutex);
if (false == isPlayerAvailable()) {
SLOG(LOG_ERROR, tts_tag(), "[PlayerThread] Player is already finished.");
return;
}
SLOG(LOG_INFO, tts_tag(), "[PlayerThread] Play request. uid(%u)", uid);
- __currentUid = uid;
- __threadCond.notify_all();
+ mCurrentUid = uid;
+ mThreadCond.notify_all();
}
void PlayerThread::requestStop()
{
- lock_guard<mutex> lock(__controlMutex);
+ lock_guard<mutex> lock(mControlMutex);
if (false == isPlayerAvailable()) {
SLOG(LOG_ERROR, tts_tag(), "[PlayerThread] Player is already finished.");
return;
}
- unsigned int uid = __currentUid.load();
+ unsigned int uid = mCurrentUid.load();
if (uid == TTS_INVALID_UID) {
SLOG(LOG_INFO, tts_tag(), "[PlayerThread] Thread is already stopped");
return;
void PlayerThread::runPlayer()
{
- unique_lock<mutex> lock(__threadMutex);
- if (nullptr == __playUtterance) {
+ unique_lock<mutex> lock(mThreadMutex);
+ if (nullptr == mPlayUtterance) {
SLOG(LOG_ERROR, tts_tag(), "[PlayerThread] Play utterance callback is not set");
return;
}
while (isPlayerAvailable()) {
SLOG(LOG_INFO, tts_tag(), "[PlayerThread] Wait playing");
if (isThreadStopped()) {
- __threadCond.wait(lock);
+ mThreadCond.wait(lock);
}
while (false == isThreadStopped()) {
unsigned int uid = getCurrentUid();
SLOG(LOG_INFO, tts_tag(), "[Player] Current player uid(%u)", uid);
- __playUtterance(this, uid);
+ mPlayUtterance(this, uid);
}
- __stopCheckCond.notify_all();
+ mStopCheckCond.notify_all();
}
}
bool PlayerThread::isThreadStopped()
{
- bool isStopped = (TTS_INVALID_UID == __currentUid.load()) || (false == isPlayerAvailable());
+ bool isStopped = (TTS_INVALID_UID == mCurrentUid.load()) || (false == isPlayerAvailable());
return isStopped;
}
bool isThreadStopped();
private:
- std::atomic<unsigned int> __currentUid;
- std::atomic<bool> __playerAvailable;
+ std::atomic<unsigned int> mCurrentUid;
+ std::atomic<bool> mPlayerAvailable;
- std::thread __playerThread;
- std::mutex __threadMutex;
- std::mutex __controlMutex;
- std::mutex __stopCheckMutex;
- std::condition_variable __threadCond;
- std::condition_variable __stopCheckCond;
+ std::thread mPlayerThread;
+ std::mutex mThreadMutex;
+ std::mutex mControlMutex;
+ std::mutex mStopCheckMutex;
+ std::condition_variable mThreadCond;
+ std::condition_variable mStopCheckCond;
- PlayUtteranceCallback __playUtterance;
+ PlayUtteranceCallback mPlayUtterance;
};
static void notifyStateChangeOnMainThread(void* data);
private:
- ttsd_state_e __beforeState;
- ttsd_state_e __currentState;
- std::mutex __stateMutex;
+ ttsd_state_e mBeforeState;
+ ttsd_state_e mCurrentState;
+ std::mutex mStateMutex;
- ttsd_state_changed_cb __callback;
+ ttsd_state_changed_cb mCallback;
};
#endif /* __TTSD_STATE_MANAGER_H_ */
using namespace std;
+
typedef struct
{
char* lang;
static ActivatedModes g_activated_modes;
#ifdef DATA_DEBUG
-static void __data_show_list()
+static void show_client_list()
{
SLOG(LOG_DEBUG, tts_tag(), "----- client list -----");
SLOG(LOG_DEBUG, tts_tag(), "-----------------------");
}
-static void __data_show_sound_list(app_data_s& app_data)
+static void show_sound_list(app_data_s& app_data)
{
SLOG(LOG_DEBUG, tts_tag(), "----- Sound list -----");
SLOG(LOG_DEBUG, tts_tag(), "----------------------");
}
-static void __data_show_text_list(app_data_s& app_data)
+static void show_text_list(app_data_s& app_data)
{
SLOG(LOG_DEBUG, tts_tag(), "----- Text list -----");
SLOG(LOG_DEBUG, tts_tag(), "---------------------");
}
-static void __data_show_used_voice_list(app_data_s& app_data)
+static void show_used_voice_list(app_data_s& app_data)
{
SLOG(LOG_DEBUG, tts_tag(), "----- Used voice list -----");
return g_synth_control.load();
}
-static app_data_s* __get_client_app_data(unsigned int uid)
+static app_data_s* get_client_app_data(unsigned int uid)
{
for (auto& app_data : g_app_list) {
if (app_data.uid == uid) {
int ttsd_data_new_client(int pid, unsigned int uid, ttsd_mode_e mode, int registered_event_mask, tts_ipc_method_e method)
{
lock_guard<mutex> lock(g_app_data_mutex);
- if(nullptr != __get_client_app_data(uid) ) {
+ if(nullptr != get_client_app_data(uid) ) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is already registered (%u)", uid);
return TTSD_ERROR_INVALID_PARAMETER;
}
g_activated_modes.addMode(mode);
#ifdef DATA_DEBUG
- __data_show_list();
+ show_client_list();
#endif
SLOG(LOG_INFO, tts_tag(), "[DATA INFO] New client. pid(%d), uid(%u)", app.pid, app.uid);
return TTSD_ERROR_NONE;
}
-static inline void __destroy_speak_data(speak_data_s* speak_data)
+static inline void destroy_speak_data(speak_data_s* speak_data)
{
SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] utt(%d), text(%s), lang(%s), vctype(%d) speed(%d)",
speak_data->utt_id, speak_data->text, speak_data->lang, speak_data->vctype, speak_data->speed);
delete speak_data;
}
-static inline void __destroy_sound_data(sound_data_s* sound_data)
+static inline void destroy_sound_data(sound_data_s* sound_data)
{
SLOG(LOG_ERROR, tts_tag(), "[DEBUG][%p] event(%d) data(%p) size(%d) rate(%d) utt(%d)",
sound_data, sound_data->event, sound_data->data, sound_data->data_size, sound_data->rate, sound_data->utt_id);
delete sound_data;
}
-static void __clean_data(app_data_s& app_data)
+static void clean_data(app_data_s& app_data)
{
SLOG(LOG_ERROR, tts_tag(), "[INFO] Clean data. uid(%u)", app_data.uid);
removed_last_uttid = speak_data->utt_id;
- __destroy_speak_data(speak_data);
+ destroy_speak_data(speak_data);
speak_data = nullptr;
}
continue;
}
- __destroy_sound_data(sound_data);
+ destroy_sound_data(sound_data);
sound_data = nullptr;
}
return TTSD_ERROR_INVALID_PARAMETER;
}
- __clean_data(g_app_list[index]);
+ clean_data(g_app_list[index]);
ttsd_mode_e mode = g_app_list[index].mode;
g_app_list.erase(g_app_list.begin() + index);
g_activated_modes.removeMode(mode);
#ifdef DATA_DEBUG
- __data_show_list();
+ show_client_list();
#endif
SLOG(LOG_INFO, tts_tag(), "[DATA INFO] Client is deleted. uid(%u), index(%d)", uid, index);
int ttsd_data_get_pid(unsigned int uid)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return -1;
tts_ipc_method_e ttsd_data_get_ipc_method(unsigned int uid)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTS_IPC_METHOD_UNDEFINED;
ttsd_mode_e ttsd_data_get_mode(unsigned int uid)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTSD_MODE_DEFAULT;
int ttsd_data_set_credential(unsigned int uid, const char* credential)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTSD_ERROR_INVALID_PARAMETER;
char* ttsd_data_get_credential(unsigned int uid)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return nullptr;
int ttsd_data_get_speak_data_size(unsigned int uid)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTSD_ERROR_INVALID_PARAMETER;
int ttsd_data_set_used_voice(unsigned int uid, const char* lang, int type)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTSD_ERROR_INVALID_PARAMETER;
SLOG(LOG_ERROR, tts_tag(), "[DATA] lang(%s), vctype(%d)", used_voice.lang, used_voice.vctype);
#ifdef DATA_DEBUG
- __data_show_used_voice_list(*app_data);
+ show_used_voice_list(*app_data);
#endif
return -1; /* Need to load voice*/
int ttsd_data_reset_used_voice(unsigned int uid, ttsd_used_voice_cb callback)
{
unique_lock<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTSD_ERROR_INVALID_PARAMETER;
usedVoices.clear();
#ifdef DATA_DEBUG
- __data_show_used_voice_list(*app_data);
+ show_used_voice_list(*app_data);
#endif
return TTSD_ERROR_NONE;
SECURE_SLOG(LOG_ERROR, tts_tag(), "[ERROR] data is nullptr");
return;
}
- __destroy_speak_data(speak_data);
+ destroy_speak_data(speak_data);
}
int ttsd_data_add_speak_data(unsigned int uid, speak_data_s* data)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTSD_ERROR_INVALID_PARAMETER;
app_data->utt_id_stopped = 0;
#ifdef DATA_DEBUG
- __data_show_text_list(*app_data);
+ show_text_list(*app_data);
#endif
return TTSD_ERROR_NONE;
}
-static speak_data_s* __get_speak_data(app_data_s* app_data)
+static speak_data_s* get_speak_data(app_data_s* app_data)
{
if (app_data->m_speak_data.empty()) {
#ifdef DATA_DEBUG
}
#ifdef DATA_DEBUG
- __data_show_text_list(*app_data);
+ show_text_list(*app_data);
#endif
return app_data->m_speak_data.front();
int ttsd_data_get_speak_data(unsigned int uid, speak_data_s** data)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTSD_ERROR_INVALID_PARAMETER;
}
- speak_data_s* speakData = __get_speak_data(app_data);
+ speak_data_s* speakData = get_speak_data(app_data);
if (nullptr == speakData) {
SLOG(LOG_WARN, tts_tag(), "[DATA WARNING] There is no speak data");
return TTSD_ERROR_OPERATION_FAILED;
return;
}
- __destroy_sound_data(sound_data);
+ destroy_sound_data(sound_data);
}
int ttsd_data_add_sound_data(unsigned int uid, sound_data_s* data)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTSD_ERROR_INVALID_PARAMETER;
data, data->utt_id, data->data, data->data_size, data->audio_type);
#ifdef DATA_DEBUG
- __data_show_sound_list(*app_data);
+ show_sound_list(*app_data);
#endif
return TTSD_ERROR_NONE;
}
#ifdef DATA_DEBUG
- __data_show_sound_list(*app_data);
+ show_sound_list(*app_data);
#endif
return app_data->m_wav_data.front();
sound_data_s* ttsd_data_get_first_sound_data(unsigned int uid)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return nullptr;
int ttsd_data_get_sound_data_size(unsigned int uid)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return -1;
int ttsd_data_set_last_sound_result_event(unsigned int uid, ttse_result_event_e event)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTSE_ERROR_INVALID_PARAMETER;
ttse_result_event_e ttsd_data_get_last_sound_result_event(unsigned int uid)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTSE_RESULT_EVENT_FAIL;
int ttsd_data_clear_data(unsigned int uid)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTSD_ERROR_INVALID_PARAMETER;
}
- __clean_data(*app_data);
+ clean_data(*app_data);
return TTSD_ERROR_NONE;
}
app_tts_state_e ttsd_data_get_client_state(unsigned int uid)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return APP_STATE_NONE;
int ttsd_data_set_client_state(unsigned int uid, app_tts_state_e state)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTSD_ERROR_INVALID_PARAMETER;
tts_app_play_type_e ttsd_data_get_play_type(unsigned int uid)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTS_APP_PLAY_TYPE_SYNTH;
int ttsd_data_set_play_type(unsigned int uid, tts_app_play_type_e type)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTSD_ERROR_INVALID_PARAMETER;
int ttsd_data_set_paused_data(unsigned int uid, sound_data_s* sound_data)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return TTSD_ERROR_INVALID_PARAMETER;
bool ttsd_data_is_paused_data_existing(unsigned int uid)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return false;
bool ttsd_data_is_service_state_changed_cb_set(unsigned int uid)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return false;
}
#ifdef DATA_DEBUG
- __data_show_list();
+ show_client_list();
#endif
/* Copy app info */
bool ttsd_data_is_uttid_valid(unsigned int uid, int uttid)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%u)", uid);
return false;
int ttsd_data_save_error_log(unsigned int uid, FILE* fp)
{
lock_guard<mutex> lock(g_app_data_mutex);
- app_data_s* app_data = __get_client_app_data(uid);
+ app_data_s* app_data = get_client_app_data(uid);
if (nullptr == app_data) {
SLOG(LOG_ERROR, tts_tag(), "[ERROR] Invalid client");
return -1;
#define SOUND_BUFFER_LENGTH 2048
/* CAUTION!
-If you change this constant value. Please check the function '__set_timer_for_delay_recover()'.
+If you change this constant value. Please check the function 'set_timer_for_delay_recover()'.
If you choose too big value, it may cause integer overflow issue.
*/
static const int SND_MGR_DUCKING_DURATION = 500;
/*
* Internal Interfaces
*/
-static void __set_playing_status(bool is_playing)
+static void set_playing_status(bool is_playing)
{
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);
}
#ifdef BUF_SAVE_MODE
-static void __open_buffer_dump_file()
+static void open_buffer_dump_file()
{
pthread_mutex_lock(&g_buf_save_mutex);
if (g_pFile) {
pthread_mutex_unlock(&g_buf_save_mutex);
}
-static void __close_buffer_dump_file()
+static void close_buffer_dump_file()
{
pthread_mutex_lock(&g_buf_save_mutex);
pthread_mutex_unlock(&g_buf_save_mutex);
}
-static void __write_buffer_dump_file(const void* buffer, size_t length)
+static void write_buffer_dump_file(const void* buffer, size_t length)
{
pthread_mutex_lock(&g_buf_save_mutex);
}
#endif
-static void __set_policy_for_playing(void)
+static void set_policy_for_playing(void)
{
g_audio_stream->acquireSoundFocus();
g_background_volume->applyVolumeRatio();
SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] set policy for playing");
}
-static void __unset_policy_for_playing()
+static void unset_policy_for_playing()
{
g_audio_stream->releaseSoundFocus();
g_background_volume->recoverVolumeRatio();
SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] unset policy for playing");
}
-static int __notify_utterance_started_event(unsigned int uid, int utt_id)
+static int notify_utterance_started_event(unsigned int uid, int utt_id)
{
int pid = ttsd_data_get_pid(uid);
if (pid <= 0) {
}
#ifdef BUF_SAVE_MODE
- __open_buffer_dump_file();
+ open_buffer_dump_file();
#endif
- __set_playing_status(true);
+ set_playing_status(true);
if (0 != ttsdc_ipc_send_utt_start_message(pid, uid, utt_id)) {
SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to send Utterance Started Signal : pid(%d), uid(%u), utt_id(%d)",
return TTSD_ERROR_NONE;
}
-static int __notify_utterance_completed_event(unsigned int uid, int utt_id)
+static int notify_utterance_completed_event(unsigned int uid, int utt_id)
{
int pid = ttsd_data_get_pid(uid);
if (pid <= 0) {
}
#ifdef BUF_SAVE_MODE
- __close_buffer_dump_file();
+ close_buffer_dump_file();
#endif
- __set_playing_status(false);
+ set_playing_status(false);
if (0 != ttsdc_ipc_send_utt_finish_message(pid, uid, utt_id)) {
SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%u), utt_id(%d)",
return TTSD_ERROR_NONE;
}
-static int __play_sound_data(PlayerThread* player, unsigned int uid, sound_data_s* sound_data)
+static int play_sound_data(PlayerThread* player, unsigned int uid, sound_data_s* sound_data)
{
if (TTSD_ERROR_NONE != g_audio_stream->setAudioFormat(sound_data->audio_type, sound_data->rate)) {
SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create audio out");
// Check whether set_policy is done or not
if (false == g_is_set_policy.load()) {
SLOG(LOG_INFO, tts_tag(), "[Player INFO] Set policy");
- __set_policy_for_playing();
+ set_policy_for_playing();
}
if (TTSD_ERROR_NONE != g_audio_stream->prepareAudioOut()) {
temp_data, idx, &temp_data[idx], uid, sound_data->utt_id, len);
#ifdef BUF_SAVE_MODE
- __write_buffer_dump_file(&temp_data[idx], len);
+ write_buffer_dump_file(&temp_data[idx], len);
#endif
if (TTSD_ERROR_NONE != g_audio_stream->playAudioData(&temp_data[idx], len)) {
return TTSD_ERROR_NONE;
}
-static void __wait_sound_data(PlayerThread* player, unsigned int uid)
+static void wait_sound_data(PlayerThread* player, unsigned int uid)
{
ttsd_synthesis_control_e prev_synth_control = TTSD_SYNTHESIS_CONTROL_EXPIRED;
while (0 >= ttsd_data_get_sound_data_size(uid)) {
if (TTSD_SYNTHESIS_CONTROL_DOING != synth_control) {
if (AudioStream::AUDIO_STATE_PLAY == g_audio_stream->getState()) {
g_audio_stream->unprepareAudioOut();
- __unset_policy_for_playing();
+ unset_policy_for_playing();
}
}
prev_synth_control = synth_control;
}
}
-static void __set_paused_data(unsigned int uid, sound_data_s* sound_data) {
+static void set_paused_data(unsigned int uid, sound_data_s* sound_data) {
int ret = ttsd_data_set_paused_data(uid, sound_data);
if (TTSD_ERROR_NONE != ret) {
ttsd_data_destroy_sound_data(sound_data);
}
}
-static void __play_utterance_cb(PlayerThread* player, unsigned int uid)
+static void play_utterance_cb(PlayerThread* player, unsigned int uid)
{
SLOG(LOG_DEBUG, tts_tag(), "[PLAYER] Start play utterance. uid(%u)", uid);
if (nullptr == sound_data) {
break;
}
- __set_playing_status(true);
+ set_playing_status(true);
SLOG(LOG_INFO, tts_tag(), "[Player] Sound info : id(%d) data(%p) size(%d) audiotype(%d) rate(%d) event(%d)",
sound_data->utt_id, sound_data->data, sound_data->data_size, sound_data->audio_type, sound_data->rate, sound_data->event);
if (nullptr == sound_data) {
SLOG(LOG_ERROR, tts_tag(), "[Player] No sound data. Waiting mode");
- __wait_sound_data(player, uid);
+ wait_sound_data(player, uid);
if (false == player->isCurrentUid(uid)) {
SLOG(LOG_INFO, tts_tag(), "[Player] Finish thread");
break;
*/
ttse_result_event_e last_event = ttsd_data_get_last_sound_result_event(uid);
if (TTSE_RESULT_EVENT_START == sound_data->event || (TTSE_RESULT_EVENT_FINISH == last_event && TTSE_RESULT_EVENT_FINISH == sound_data->event)) {
- int ret = __notify_utterance_started_event(uid, sound_data->utt_id);
+ int ret = notify_utterance_started_event(uid, sound_data->utt_id);
if (TTSD_ERROR_INVALID_PARAMETER == ret) {
break;
}
SLOG(LOG_INFO, tts_tag(), "[Player] No Sound data. Event(%d), uid(%u), uttid(%d)", event, uid, utt_id);
if (TTSE_RESULT_EVENT_FINISH == event) {
- __unset_policy_for_playing();
- if (TTSD_ERROR_INVALID_PARAMETER == __notify_utterance_completed_event(uid, utt_id)) {
+ unset_policy_for_playing();
+ if (TTSD_ERROR_INVALID_PARAMETER == notify_utterance_completed_event(uid, utt_id)) {
break;
}
}
}
}
- int ret = __play_sound_data(player, uid, sound_data);
+ int ret = play_sound_data(player, uid, sound_data);
if (TTSD_ERROR_INVALID_STATE == ret) {
SLOG(LOG_DEBUG, tts_tag(), "[Player] Uid(%u) is paused", uid);
- __set_paused_data(uid, sound_data);
+ set_paused_data(uid, sound_data);
break;
} else if (TTSD_ERROR_NONE != ret) {
SLOG(LOG_ERROR, tts_tag(), "[Player] Fail to play audio data. uid(%u)", uid);
sound_data = nullptr;
if (TTSE_RESULT_EVENT_FINISH == event) {
- __unset_policy_for_playing();
- if (TTSD_ERROR_NONE != __notify_utterance_completed_event(uid, utt_id)) {
+ unset_policy_for_playing();
+ if (TTSD_ERROR_NONE != notify_utterance_completed_event(uid, utt_id)) {
break;
}
}
}
g_audio_stream->unprepareAudioOut();
- __unset_policy_for_playing();
+ unset_policy_for_playing();
#ifdef BUF_SAVE_MODE
- __close_buffer_dump_file();
+ close_buffer_dump_file();
#endif
SLOG(LOG_DEBUG, tts_tag(), "[PLAYER] Finish play utterance. uid(%u)", uid);
{
g_background_volume = new BackgroundVolume(SND_MGR_DUCKING_DURATION);
g_audio_stream = new AudioStream();
- g_player_thread = new PlayerThread(__play_utterance_cb);
+ g_player_thread = new PlayerThread(play_utterance_cb);
g_is_set_policy = false;
g_player_init = true;
int ttsd_player_release(void)
{
#ifdef BUF_SAVE_MODE
- __close_buffer_dump_file();
+ close_buffer_dump_file();
#endif
- __set_playing_status(false);
+ set_playing_status(false);
if (false == g_player_init) {
SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
return TTSD_ERROR_OPERATION_FAILED;
}
#ifdef BUF_SAVE_MODE
- __close_buffer_dump_file();
+ close_buffer_dump_file();
#endif
- __set_playing_status(false);
+ set_playing_status(false);
ttsd_data_set_last_sound_result_event(uid, TTSE_RESULT_EVENT_FINISH);
ttsd_data_set_paused_data(uid, nullptr);
}
#ifdef BUF_SAVE_MODE
- __close_buffer_dump_file();
+ close_buffer_dump_file();
#endif
- __set_playing_status(false);
+ set_playing_status(false);
SLOG(LOG_INFO, tts_tag(), "[Player SUCCESS] Pause player : uid(%u)", uid);
return 0;
}
-bool __stop_all_client_callback(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
+static bool stop_all_client_callback(int pid, unsigned int uid, app_tts_state_e state, void* user_data)
{
if (0 > ttsd_data_is_client(uid)) {
SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%u) is not valid", uid);
}
g_player_thread->requestStop();
- ttsd_data_foreach_clients(__stop_all_client_callback, nullptr);
+ ttsd_data_foreach_clients(stop_all_client_callback, nullptr);
SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] player all stop!!");
return TTSD_ERROR_NONE;
static StateManager* g_stateManager = nullptr;
StateManager::StateManager(ttsd_state_changed_cb callback) :
- __beforeState(TTSD_STATE_READY), __currentState(TTSD_STATE_READY), __callback(callback)
+ mBeforeState(TTSD_STATE_READY),
+ mCurrentState(TTSD_STATE_READY),
+ mCallback(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;
+ mBeforeState = TTSD_STATE_READY;
+ mCurrentState = TTSD_STATE_READY;
+ mCallback = nullptr;
}
ttsd_state_e StateManager::getState()
{
- lock_guard<mutex> lock(__stateMutex);
- return __currentState;
+ lock_guard<mutex> lock(mStateMutex);
+ return mCurrentState;
}
void StateManager::setState(ttsd_state_e state)
{
- unique_lock<mutex> lock(__stateMutex);
- __beforeState = __currentState;
- __currentState = state;
+ unique_lock<mutex> lock(mStateMutex);
+ mBeforeState = mCurrentState;
+ mCurrentState = state;
- if (__beforeState == __currentState) {
+ if (mBeforeState == mCurrentState) {
return;
}
- SLOG(LOG_INFO, tts_tag(), "[StateManager] StateManager is changed. (%d) -> (%d)", __beforeState, __currentState);
+ SLOG(LOG_INFO, tts_tag(), "[StateManager] StateManager is changed. (%d) -> (%d)", mBeforeState, mCurrentState);
lock.unlock();
ecore_main_loop_thread_safe_call_async(notifyStateChangeOnMainThread, static_cast<void*>(this));
}
StateManager* stateManager = static_cast<StateManager*>(data);
- unique_lock<mutex> lock(stateManager->__stateMutex);
- ttsd_state_e before = stateManager->__beforeState;
- ttsd_state_e current = stateManager->__currentState;
+ unique_lock<mutex> lock(stateManager->mStateMutex);
+ ttsd_state_e before = stateManager->mBeforeState;
+ ttsd_state_e current = stateManager->mCurrentState;
lock.unlock();
- if (stateManager->__callback) {
- stateManager->__callback(before, current);
+ if (stateManager->mCallback) {
+ stateManager->mCallback(before, current);
}
}