using namespace std;
-typedef struct
+typedef struct
{
char* lang;
int vctype;
}used_voice_s;
-typedef struct
+typedef struct
{
int pid;
int uid;
static vector<app_data_s> g_app_list;
+static pthread_mutex_t g_speak_data_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t g_sound_data_mutex = PTHREAD_MUTEX_INITIALIZER;
/*
int __data_show_sound_list(int index)
{
SLOG(LOG_DEBUG, tts_tag(), "----- Sound list -----");
-
+
unsigned int i = 0;
std::list<sound_data_s*>::iterator iter;
- for (iter = g_app_list[index].m_wav_data.begin(); iter != g_app_list[index].m_wav_data.end(); iter++) {
- SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] data(%p) data size(%ld), uttid(%d), type(%d)",
+ for (iter = g_app_list[index].m_wav_data.begin(); iter != g_app_list[index].m_wav_data.end(); ++iter) {
+ SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] data(%p) data size(%d), uttid(%d), type(%d)",
i, *iter, (*iter)->data, (*iter)->data_size, (*iter)->utt_id, (*iter)->audio_type);
i++;
}
unsigned int i = 0;
std::list<speak_data_s*>::iterator iter;
- for (iter = g_app_list[index].m_speak_data.begin(); iter != g_app_list[index].m_speak_data.end(); iter++) {
+ for (iter = g_app_list[index].m_speak_data.begin(); iter != g_app_list[index].m_speak_data.end(); ++iter) {
SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] lang(%s), vctype(%d), speed(%d), uttid(%d), text(%s)",
i + 1, *iter, (*iter)->lang, (*iter)->vctype, (*iter)->speed, (*iter)->utt_id, (*iter)->text);
i++;
unsigned int i = 0;
std::list<used_voice_s>::iterator iter;
- for (iter = g_app_list[index].m_used_voice.begin(); iter != g_app_list[index].m_used_voice.end(); iter++) {
+ for (iter = g_app_list[index].m_used_voice.begin(); iter != g_app_list[index].m_used_voice.end(); ++iter) {
SLOG(LOG_DEBUG, tts_tag(), "[%dth] lang(%s), vctype(%d)", i + 1, iter->lang, iter->vctype);
i++;
}
#ifdef DATA_DEBUG
__data_show_list();
-#endif
+#endif
return TTSD_ERROR_NONE;
}
int index = 0;
index = ttsd_data_is_client(uid);
-
+
if (index < 0) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
return -1;
#ifdef DATA_DEBUG
__data_show_list();
-#endif
+#endif
return TTSD_ERROR_NONE;
}
for (int i = 0; i < vsize; i++) {
if(g_app_list[i].uid == uid) {
- return i;
+ return i;
}
}
int index;
index = ttsd_data_is_client(uid);
-
+
if (index < 0) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
return TTSD_ERROR_INVALID_PARAMETER;
{
int index = 0;
index = ttsd_data_is_client(uid);
-
+
if (index < 0) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
return TTSD_ERROR_INVALID_PARAMETER;
}
+ /* mutex is locked */
+ pthread_mutex_lock(&g_speak_data_mutex);
int size = g_app_list[index].m_speak_data.size();
+
+ /* mutex is unlocked */
+ pthread_mutex_unlock(&g_speak_data_mutex);
+
return size;
}
/* Find voice */
std::list<used_voice_s>::iterator iter;
- for (iter = g_app_list[index].m_used_voice.begin();iter != g_app_list[index].m_used_voice.end();iter++) {
+ for (iter = g_app_list[index].m_used_voice.begin(); iter != g_app_list[index].m_used_voice.end();++iter) {
if (0 == strcmp(lang, iter->lang) && type == iter->vctype) {
SLOG(LOG_DEBUG, tts_tag(), "[DATA] The voice is already registered (%s)(%d)", lang, type);
return 0;
used_voice.lang = strdup(lang);
used_voice.vctype = type;
- g_app_list[index].m_used_voice.insert(g_app_list[index].m_used_voice.end(), used_voice);
+ try {
+ iter = g_app_list[index].m_used_voice.insert(g_app_list[index].m_used_voice.end(), used_voice);
+ } catch (const std::bad_alloc&) {
+ SLOG(LOG_ERROR, tts_tag(), "[DATA][ERROR] Fail to insert m_used_voice (bad_alloc)");
+ return -1;
+ }
+ SLOG(LOG_ERROR, tts_tag(), "[DATA] lang(%s), vctype(%d)", iter->lang, iter->vctype);
#ifdef DATA_DEBUG
__data_show_used_voice_list(index);
/* Find voice */
std::list<used_voice_s>::iterator iter;
- for (iter = g_app_list[index].m_used_voice.begin(); iter != g_app_list[index].m_used_voice.end(); iter++) {
+ for (iter = g_app_list[index].m_used_voice.begin(); iter != g_app_list[index].m_used_voice.end(); ++iter) {
if (NULL != callback) {
callback(iter->lang, iter->vctype);
}
if (NULL != iter->lang) {
free(iter->lang);
+ iter->lang = NULL;
}
- }
+ }
g_app_list[index].m_used_voice.clear();
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
return TTSD_ERROR_INVALID_PARAMETER;
}
-
- g_app_list[index].m_speak_data.insert(g_app_list[index].m_speak_data.end(), data);
+
+ /* mutex is locked */
+ pthread_mutex_lock(&g_speak_data_mutex);
+
+ std::list<speak_data_s*>::iterator iter;
+
+ try {
+ iter = g_app_list[index].m_speak_data.insert(g_app_list[index].m_speak_data.end(), data);
+ } catch (const std::bad_alloc&) {
+ SLOG(LOG_ERROR, tts_tag(), "[DATA][ERROR] Fail to insert m_speak_data (bad_alloc)");
+ pthread_mutex_unlock(&g_speak_data_mutex);
+
+ return TTSD_ERROR_OUT_OF_MEMORY;
+ }
+ SLOG(LOG_ERROR, tts_tag(), "[DATA][%p] utt_id(%d), text(%s), lang(%s), vctype(%d), speed(%d)",
+ *iter, (*iter)->utt_id, (*iter)->text, (*iter)->lang, (*iter)->vctype, (*iter)->speed);
if (1 == data->utt_id)
g_app_list[index].utt_id_stopped = 0;
#ifdef DATA_DEBUG
__data_show_text_list(index);
-#endif
+#endif
+ pthread_mutex_unlock(&g_speak_data_mutex);
+
return TTSD_ERROR_NONE;
}
return TTSD_ERROR_INVALID_PARAMETER;
}
+ /* mutex is locked */
+ pthread_mutex_lock(&g_speak_data_mutex);
+
if (0 == g_app_list[index].m_speak_data.size()) {
#ifdef DATA_DEBUG
- SLOG(LOG_WARN, tts_tag(), "[DATA WARNING] There is no speak data");
-#endif
+ SLOG(LOG_WARN, tts_tag(), "[DATA WARNING] There is no speak data");
+#endif
+ pthread_mutex_unlock(&g_speak_data_mutex);
return -1;
}
std::list<speak_data_s*>::iterator iter = g_app_list[index].m_speak_data.begin();
*data = *iter;
- g_app_list[index].m_speak_data.pop_front();
+ if (!g_app_list[index].m_speak_data.empty())
+ g_app_list[index].m_speak_data.pop_front();
#ifdef DATA_DEBUG
__data_show_text_list(index);
-#endif
+#endif
+ pthread_mutex_unlock(&g_speak_data_mutex);
+
return TTSD_ERROR_NONE;
}
/* mutex is locked */
pthread_mutex_lock(&g_sound_data_mutex);
- g_app_list[index].m_wav_data.insert(g_app_list[index].m_wav_data.end(), data);
+ std::list<sound_data_s*>::iterator iter;
+
+ try {
+ iter = g_app_list[index].m_wav_data.insert(g_app_list[index].m_wav_data.end(), data);
+ } catch (const std::bad_alloc&) {
+ SLOG(LOG_ERROR, tts_tag(), "[DATA][ERROR] Fail to insert m_sound_data (bad_alloc)");
+ pthread_mutex_unlock(&g_sound_data_mutex);
+
+ return TTSD_ERROR_OUT_OF_MEMORY;
+ }
+ SLOG(LOG_ERROR, tts_tag(), "[DATA][%p] utt_id(%d), data(%p)", *iter, (*iter)->utt_id, (*iter)->data);
#ifdef DATA_DEBUG
__data_show_sound_list(index);
-#endif
+#endif
/* mutex is unlocked */
pthread_mutex_unlock(&g_sound_data_mutex);
std::list<sound_data_s*>::iterator iter = g_app_list[index].m_wav_data.begin();
*data = *iter;
- g_app_list[index].m_wav_data.pop_front();
+ if (!g_app_list[index].m_wav_data.empty())
+ g_app_list[index].m_wav_data.pop_front();
#ifdef DATA_DEBUG
__data_show_sound_list(index);
-#endif
+#endif
/* mutex is unlocked */
pthread_mutex_unlock(&g_sound_data_mutex);
}
}
+ pthread_mutex_lock(&g_speak_data_mutex);
g_app_list[index].m_speak_data.clear();
+ pthread_mutex_unlock(&g_speak_data_mutex);
+
+ pthread_mutex_lock(&g_sound_data_mutex);
g_app_list[index].m_wav_data.clear();
+ pthread_mutex_unlock(&g_sound_data_mutex);
return TTSD_ERROR_NONE;
}
#ifdef DATA_DEBUG
__data_show_list();
-#endif
-
+#endif
+
/* Copy app info */
vector<app_data_s> temp_app_list;
int vsize = g_app_list.size();
for (i = 0;i < vsize;i++) {
temp_app_list.erase(temp_app_list.begin());
}
-
+
return 0;
}
index = ttsd_data_is_client(uid);
if (index < 0) {
SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
- return TTSD_ERROR_INVALID_PARAMETER;
+ return false;
}
if (uttid < g_app_list[index].utt_id_stopped)
for (int i = 0; i < vsize; i++) {
if(g_app_list[i].state == APP_STATE_PLAYING) {
- return g_app_list[i].uid;
+ return g_app_list[i].uid;
}
}
for (int i = 0;i < vsize;i++) {
if(g_app_list[i].pid == pid) {
- number++;
+ number++;
}
}
i = 0;
std::list<sound_data_s*>::iterator iter;
- for (iter = g_app_list[index].m_wav_data.begin(); iter != g_app_list[index].m_wav_data.end(); iter++) {
- SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] data(%p) data size(%ld), uttid(%d), type(%d)",
+ for (iter = g_app_list[index].m_wav_data.begin(); iter != g_app_list[index].m_wav_data.end(); ++iter) {
+ SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] data(%p) data size(%d), uttid(%d), type(%d)",
i, *iter, (*iter)->data, (*iter)->data_size, (*iter)->utt_id, (*iter)->audio_type);
i++;
}
fprintf(fp, "----------------------");
-
+
/* get speck data */
fprintf(fp, "----- Text list -----");
i = 0;
std::list<speak_data_s*>::iterator iter_speak;
- for (iter_speak = g_app_list[index].m_speak_data.begin(); iter_speak != g_app_list[index].m_speak_data.end(); iter_speak++) {
+ for (iter_speak = g_app_list[index].m_speak_data.begin(); iter_speak != g_app_list[index].m_speak_data.end(); ++iter_speak) {
SLOG(LOG_DEBUG, tts_tag(), "[%dth][%p] lang(%s), vctype(%d), speed(%d), uttid(%d), text(%s)",
i, *iter_speak, (*iter_speak)->lang, (*iter_speak)->vctype, (*iter_speak)->speed, (*iter_speak)->utt_id, (*iter_speak)->text);
i++;
}
fprintf(fp, "---------------------");
-
+
return 0;
}