2 * Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
16 #include <sound_manager.h>
17 #include <sound_manager_internal.h>
19 #include "ttsd_main.h"
20 #include "ttsd_player.h"
21 #include "ttsd_data.h"
22 #include "ttsd_dbus.h"
24 #include "tts_internal.h"
25 #include "ttsd_server.h"
28 * Internal data structure
38 int uid; /** client id */
39 app_tts_state_e state; /** client state */
41 /* Current utterance information */
42 ttse_result_event_e event; /** event of last utterance */
46 sound_data_s* paused_data;
49 #define SOUND_BUFFER_LENGTH 2048
50 #define FOCUS_SERVER_READY "/tmp/.sound_server_ready"
52 /* Sound buf save for test */
57 static char g_temp_file_name[128] = {'\0',};
61 static int g_count = 1;
64 /** player init info */
65 static bool g_player_init = false;
68 static GList *g_player_list;
70 /** current player information */
71 static player_s* g_playing_info;
74 static audio_state_e g_audio_state;
76 static ttse_audio_type_e g_audio_type;
78 static int g_sampling_rate;
80 static audio_out_h g_audio_h;
82 static sound_stream_info_h g_stream_info_h;
84 static sound_stream_ducking_h g_media_stream_ducking;
85 static sound_stream_ducking_h g_system_stream_ducking;
86 static sound_stream_ducking_h g_notification_stream_ducking;
87 static sound_stream_ducking_h g_alarm_stream_ducking;
89 // static bool ducking_flag;
91 #define SND_MGR_DUCKING_DURATION 500
93 static int g_focus_watch_id;
95 static double g_bg_volume_ratio;
101 player_s* __player_get_item(int uid)
104 player_s *data = NULL;
106 if (0 < g_list_length(g_player_list)) {
107 /* Get a first item */
108 iter = g_list_first(g_player_list);
110 while (NULL != iter) {
111 /* Get handle data from list */
112 data = (player_s*)iter->data;
115 if (uid == data->uid)
119 iter = g_list_next(iter);
126 void __player_focus_state_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state,
127 sound_stream_focus_change_reason_e reason_for_change, int sound_behavior, const char *extra_info, void *user_data)
129 SLOG(LOG_DEBUG, tts_tag(), "@@@ Focus state changed cb");
131 if (stream_info != g_stream_info_h) {
132 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Invalid stream info handle");
135 SLOG(LOG_WARN, tts_tag(), "[Player] focus state changed to (%d) with reason(%d) and extra info(%s)", (int)focus_state, (int)reason_for_change, extra_info);
137 if (AUDIO_STATE_PLAY == g_audio_state && focus_mask == SOUND_STREAM_FOCUS_FOR_PLAYBACK && SOUND_STREAM_FOCUS_STATE_RELEASED == focus_state) {
138 if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
139 g_audio_state = AUDIO_STATE_READY;
141 if (NULL == g_playing_info) {
142 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
146 if (APP_STATE_PLAYING == g_playing_info->state) {
147 int uid = g_playing_info->uid;
149 if (0 != ttsd_player_pause(uid)) {
150 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to pause the player");
154 ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
155 int pid = ttsd_data_get_pid(uid);
156 /* send message to client about changing state */
157 ttsdc_send_set_state_message(pid, uid, APP_STATE_PAUSED);
160 SLOG(LOG_DEBUG, tts_tag(), "[Player] Ignore focus state cb - mode(%d)", ttsd_get_mode());
164 /* if (AUDIO_STATE_READY == g_audio_state && focus_mask == SOUND_STREAM_FOCUS_FOR_PLAYBACK && SOUND_STREAM_FOCUS_STATE_ACQUIRED == focus_state) {
165 if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
166 g_audio_state = AUDIO_STATE_PLAY;
168 if (NULL == g_playing_info) {
169 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
173 if (APP_STATE_PAUSED == g_playing_info->state) {
174 int uid = g_playing_info->uid;
176 g_audio_state = AUDIO_STATE_PLAY;
177 if (0 != ttsd_player_resume(uid)) {
178 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to resume the player");
179 g_audio_state = AUDIO_STATE_READY;
183 ttsd_data_set_client_state(uid, APP_STATE_PLAYING);
184 int pid = ttsd_data_get_pid(uid);
185 ttsdc_send_set_state_message(pid, uid, APP_STATE_PLAYING);
189 SLOG(LOG_DEBUG, tts_tag(), "[Player] Ignore focus state cb - mode(%d)", ttsd_get_mode());
193 SLOG(LOG_DEBUG, tts_tag(), "@@@");
198 void __player_focus_state_watch_cb(int id, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state, sound_stream_focus_change_reason_e reason,
199 const char *extra_info, void *user_data)
201 SLOG(LOG_DEBUG, tts_tag(), "@@@ Focus state watch cb");
203 ttsd_mode_e mode = ttsd_get_mode();
205 if (TTSD_MODE_SCREEN_READER != mode && TTSD_MODE_NOTIFICATION != mode) {
206 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] This is not screen-reader mode and notification mode.");
210 if (AUDIO_STATE_PLAY == g_audio_state && SOUND_STREAM_FOCUS_CHANGED_BY_VOICE_INFORMATION == reason &&
211 NULL != extra_info && 0 == strncmp(extra_info, "TTSD_MODE_INTERRUPT", strlen(extra_info))) {
212 /* If the focus is changed by "Interrupt" mode and current players of "SR" and "Noti" modes are on going, please stop the current players. */
213 g_audio_state = AUDIO_STATE_READY;
215 if (NULL == g_playing_info) {
216 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
220 if (APP_STATE_PLAYING == g_playing_info->state) {
221 int uid = g_playing_info->uid;
223 if (0 != ttsd_server_stop(uid)) {
224 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to stop TTS server");
227 if (0 != ttsd_player_stop(uid)) {
228 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to stop the player");
232 ttsd_data_set_client_state(uid, APP_STATE_READY);
233 int pid = ttsd_data_get_pid(uid);
234 /* send message to client about changing state */
235 ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
237 SLOG(LOG_DEBUG, tts_tag(), "[Player] Not playing state");
240 SLOG(LOG_DEBUG, tts_tag(), "[Player] This is not Interrupt mode or not playing state.");
246 void __sound_stream_ducking_state_changed_cb(sound_stream_ducking_h stream_ducking, bool is_ducked, void *user_data)
248 SLOG(LOG_DEBUG, tts_tag(), "@@@ ducking state changed cb");
249 SLOG(LOG_DEBUG, tts_tag(), "[Player] is ducked : %d", is_ducked);
250 // ducking_flag = true;
254 static char* __get_ducking_stream(sound_stream_type_e stream_type)
256 if (SOUND_STREAM_TYPE_MEDIA == stream_type)
257 return "Media stream";
258 else if (SOUND_STREAM_TYPE_SYSTEM == stream_type)
259 return "System stream";
260 else if (SOUND_STREAM_TYPE_NOTIFICATION == stream_type)
261 return "Notification stream";
262 else if (SOUND_STREAM_TYPE_ALARM == stream_type)
263 return "Alarm stream";
264 return "Non matched stream";
267 static int __activate_ducking_sound_stream(sound_stream_type_e stream_type, sound_stream_ducking_h stream_ducking_h)
269 bool is_ducked = false;
270 int ret = sound_manager_is_ducked(stream_ducking_h, &is_ducked);
272 SLOG(LOG_DEBUG, tts_tag(), "[Player] The %s is already ducked", __get_ducking_stream(stream_type));
274 ret = sound_manager_activate_ducking(stream_ducking_h, SND_MGR_DUCKING_DURATION, g_bg_volume_ratio);
275 if (SOUND_MANAGER_ERROR_NONE != ret) {
276 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to activate ducking for %s", __get_ducking_stream(stream_type));
278 SLOG(LOG_INFO, tts_tag(), "[Player SUCCESS] Activate ducking for %s", __get_ducking_stream(stream_type));
284 static void __change_background_volume()
286 __activate_ducking_sound_stream(SOUND_STREAM_TYPE_MEDIA, g_media_stream_ducking);
287 __activate_ducking_sound_stream(SOUND_STREAM_TYPE_SYSTEM, g_system_stream_ducking);
288 __activate_ducking_sound_stream(SOUND_STREAM_TYPE_NOTIFICATION, g_notification_stream_ducking);
289 __activate_ducking_sound_stream(SOUND_STREAM_TYPE_ALARM, g_alarm_stream_ducking);
292 static int __deactivate_ducking_sound_stream(sound_stream_type_e stream_type, sound_stream_ducking_h stream_ducking_h)
294 bool is_ducked = false;
295 int ret = sound_manager_is_ducked(stream_ducking_h, &is_ducked);
297 SLOG(LOG_DEBUG, tts_tag(), "[Player] The %s is already recovered from ducking", __get_ducking_stream(stream_type));
299 ret = sound_manager_deactivate_ducking(stream_ducking_h);
300 if (SOUND_MANAGER_ERROR_NONE != ret) {
301 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to deactivate ducking for %s", __get_ducking_stream(stream_type));
303 SLOG(LOG_INFO, tts_tag(), "[Player SUCCESS] Deactivate ducking for %s", __get_ducking_stream(stream_type));
309 static void __recover_background_volume()
311 __deactivate_ducking_sound_stream(SOUND_STREAM_TYPE_MEDIA, g_media_stream_ducking);
312 __deactivate_ducking_sound_stream(SOUND_STREAM_TYPE_SYSTEM, g_system_stream_ducking);
313 __deactivate_ducking_sound_stream(SOUND_STREAM_TYPE_NOTIFICATION, g_notification_stream_ducking);
314 __deactivate_ducking_sound_stream(SOUND_STREAM_TYPE_ALARM, g_alarm_stream_ducking);
317 static int __create_audio_out(ttse_audio_type_e type, int rate)
320 audio_sample_type_e sample_type;
322 if (TTSE_AUDIO_TYPE_RAW_S16 == type) {
323 sample_type = AUDIO_SAMPLE_TYPE_S16_LE;
325 sample_type = AUDIO_SAMPLE_TYPE_U8;
328 ret = audio_out_create_new(rate, AUDIO_CHANNEL_MONO, sample_type, &g_audio_h);
329 if (AUDIO_IO_ERROR_NONE != ret) {
330 g_audio_state = AUDIO_STATE_NONE;
332 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create audio");
335 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Create audio");
339 g_sampling_rate = rate;
341 g_audio_state = AUDIO_STATE_READY;
346 static int __destroy_audio_out()
348 if (NULL == g_audio_h) {
349 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current handle is not valid");
354 ret = audio_out_destroy(g_audio_h);
355 if (AUDIO_IO_ERROR_NONE != ret) {
356 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to destroy audio");
359 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Destroy audio");
365 g_audio_state = AUDIO_STATE_NONE;
371 static void __end_play_thread(void *data, Ecore_Thread *thread)
373 SLOG(LOG_ERROR, tts_tag(), "@@@ End thread");
380 static void __set_policy_for_playing(int volume)
383 __change_background_volume();
385 /* Set stream info */
387 ttsd_mode_e mode = ttsd_get_mode();
388 if (TTSD_MODE_DEFAULT == mode) {
389 ret = sound_manager_acquire_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL);
390 if (SOUND_MANAGER_ERROR_NONE != ret) {
391 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to acquire focus");
393 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Success to acquire focus (default mode)");
395 } else if (TTSD_MODE_INTERRUPT == mode) {
396 ret = sound_manager_acquire_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, "TTSD_MODE_INTERRUPT");
397 if (SOUND_MANAGER_ERROR_NONE != ret) {
398 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to acquire focus");
400 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Success to acquire focus (interrupt mode)");
404 ret = audio_out_set_sound_stream_info(g_audio_h, g_stream_info_h);
405 if (AUDIO_IO_ERROR_NONE != ret) {
406 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to set stream info");
409 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] set policy for playing");
414 static void __unset_policy_for_playing()
417 ttsd_mode_e mode = ttsd_get_mode();
418 /* Unset stream info */
419 if (TTSD_MODE_DEFAULT == mode || TTSD_MODE_INTERRUPT == mode) {
420 sound_stream_focus_state_e state_for_playing = SOUND_STREAM_FOCUS_STATE_ACQUIRED;
421 ret = sound_manager_get_focus_state(g_stream_info_h, &state_for_playing, NULL);
422 if (SOUND_MANAGER_ERROR_NONE != ret) {
423 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to get focus state: %d", ret);
426 if (SOUND_STREAM_FOCUS_STATE_ACQUIRED == state_for_playing) {
427 if (TTSD_MODE_DEFAULT == mode || TTSD_MODE_INTERRUPT == mode) {
428 ret = sound_manager_release_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL);
429 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] release focus (mode: %d)", mode);
432 if (SOUND_MANAGER_ERROR_NONE != ret) {
433 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to release focus");
438 __recover_background_volume();
440 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] unset policy for playing");
445 int ttsd_player_check_current_playback_focus(bool *is_current_interrupt)
448 ttsd_mode_e mode = ttsd_get_mode();
450 if (TTSD_MODE_INTERRUPT != mode) {
451 /* check the current playback focus */
452 sound_stream_focus_change_reason_e reason;
453 int sound_behavior = 0;
454 char *extra_info = NULL;
456 ret = sound_manager_get_current_playback_focus(&reason, &sound_behavior, &extra_info);
458 SLOG(LOG_DEBUG, tts_tag(), "[Player] current playback focus: extra_info(%s), reason(%d), sound_behavior(%d)", extra_info, reason, sound_behavior);
460 if (SOUND_MANAGER_ERROR_NONE == ret && NULL != extra_info && 0 < strlen(extra_info)) {
461 if (SOUND_STREAM_FOCUS_CHANGED_BY_VOICE_INFORMATION == reason && 0 == strncmp(extra_info, "TTSD_MODE_INTERRUPT", strlen(extra_info))) {
462 SLOG(LOG_DEBUG, tts_tag(), "[Player] The current focus in Interrupt. Cannot play the requested sound data");
463 *is_current_interrupt = true;
468 return TTSD_ERROR_NONE;
472 if (NULL != extra_info) {
478 *is_current_interrupt = false;
480 return TTSD_ERROR_NONE;
483 static void __play_thread(void *data, Ecore_Thread *thread)
485 SLOG(LOG_DEBUG, tts_tag(), "@@@ Start thread");
491 snprintf(g_temp_file_name, sizeof(g_temp_file_name), "/tmp/tts_temp_%d_%d", getpid(), g_count);
492 int ret = access(g_temp_file_name, 0);
495 SLOG(LOG_ERROR, tts_tag(), "[Recorder ERROR] File is already exist");
496 if (0 == remove(g_temp_file_name)) {
497 SLOG(LOG_DEBUG, tts_tag(), "[Recorder] Remove file");
507 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[Recorder] Temp file name=[%s]", g_temp_file_name);
510 g_pFile = fopen(g_temp_file_name, "wb+x");
512 SLOG(LOG_ERROR, tts_tag(), "[Recorder ERROR] File not found!");
517 if (NULL == g_playing_info) {
518 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] No current player");
522 player_s* player = g_playing_info;
523 sound_data_s* sound_data = NULL;
526 int len = SOUND_BUFFER_LENGTH;
529 /* set volume policy as 40% */
530 __set_policy_for_playing(40);
532 if (true == player->is_paused_data) {
534 sound_data = player->paused_data;
535 player->paused_data = NULL;
539 player->is_paused_data = false;
542 if (NULL == sound_data) {
543 /* Request unprepare */
544 ret = audio_out_unprepare(g_audio_h);
545 if (AUDIO_IO_ERROR_NONE != ret) {
546 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
548 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
551 g_audio_state = AUDIO_STATE_READY;
553 /* unset volume policy, volume will be 100% */
554 __unset_policy_for_playing();
557 SLOG(LOG_INFO, tts_tag(), "[Player] Sound info : id(%d) data(%p) size(%d) audiotype(%d) rate(%d) event(%d)",
558 sound_data->utt_id, sound_data->data, sound_data->data_size, sound_data->audio_type, sound_data->rate, sound_data->event);
561 ret = ttsd_data_get_sound_data(player->uid, &sound_data);
562 if (0 != ret || NULL == sound_data) {
564 SLOG(LOG_DEBUG, tts_tag(), "[Player] No sound data. Waiting mode");
566 /* wait for new audio data come */
569 if (NULL == g_playing_info) {
570 /* current playing uid is replaced */
571 SLOG(LOG_INFO, tts_tag(), "[Player] Finish thread");
572 if (AUDIO_STATE_PLAY == g_audio_state) {
573 /* release audio & recover session */
574 ret = audio_out_unprepare(g_audio_h);
575 if (AUDIO_IO_ERROR_NONE != ret) {
576 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
578 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
580 g_audio_state = AUDIO_STATE_READY;
582 /* unset volume policy, volume will be 100% */
583 __unset_policy_for_playing();
585 } else if (0 < ttsd_data_get_sound_data_size(player->uid)) {
586 /* new audio data come */
587 SLOG(LOG_INFO, tts_tag(), "[Player] Resume thread");
591 /* If engine is not on processing */
592 if (TTSD_SYNTHESIS_CONTROL_DOING != ttsd_get_synth_control()) {
593 if (AUDIO_STATE_PLAY == g_audio_state) {
594 /* release audio & recover session */
595 ret = audio_out_unprepare(g_audio_h);
596 if (AUDIO_IO_ERROR_NONE != ret) {
597 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
599 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
601 g_audio_state = AUDIO_STATE_READY;
603 /* unset volume policy, volume will be 100% */
604 __unset_policy_for_playing();
609 SLOG(LOG_INFO, tts_tag(), "[Player] Finish to wait for new audio data come");
611 if (AUDIO_STATE_READY == g_audio_state) {
612 /* set volume policy as 40%, when resume play thread*/
613 __set_policy_for_playing(40);
616 /* resume play thread */
617 player->state = APP_STATE_PLAYING;
621 /* If wdata's event is 'start', current wdata is first data of engine for synthesis.
622 * If wdata's event is 'finish', player should check previous event to know whether this wdata is first or not.
623 * When previous wdata's event is 'finish' and current wdata's event is 'finish',
624 * the player should send utt started event.
626 if (TTSE_RESULT_EVENT_START == sound_data->event ||
627 (TTSE_RESULT_EVENT_FINISH == player->event && TTSE_RESULT_EVENT_FINISH == sound_data->event)) {
628 int pid = ttsd_data_get_pid(player->uid);
631 SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
632 /* unset volume policy, volume will be 100% */
633 __unset_policy_for_playing();
638 if (0 != ttsdc_send_utt_start_message(pid, player->uid, sound_data->utt_id)) {
639 SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Start Signal : pid(%d), uid(%d), uttid(%d)",
640 pid, player->uid, sound_data->utt_id);
642 SLOG(LOG_INFO, tts_tag(), "[Player] Start utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
645 /* Save last event to check utterance start */
646 player->event = sound_data->event;
649 if (NULL == sound_data->data || 0 >= sound_data->data_size) {
650 if (TTSE_RESULT_EVENT_FINISH == sound_data->event) {
651 SLOG(LOG_DEBUG, tts_tag(), "No sound data");
652 /* send utterence finish signal */
653 int pid = ttsd_data_get_pid(player->uid);
656 SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
657 /* unset volume policy, volume will be 100% */
658 __unset_policy_for_playing();
662 __unset_policy_for_playing();
664 if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
665 SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)",
666 pid, player->uid, sound_data->utt_id);
668 SLOG(LOG_INFO, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
671 SLOG(LOG_INFO, tts_tag(), "[Player] Event(%d) utterance : uid(%d), uttid(%d)", sound_data->event, player->uid, sound_data->utt_id);
672 ttsd_data_clear_sound_data(player->uid, &sound_data);
677 if (g_sampling_rate != sound_data->rate || g_audio_type != sound_data->audio_type) {
678 SLOG(LOG_INFO, tts_tag(), "[Player] Change audio handle : org type(%d) org rate(%d)", g_audio_type, g_sampling_rate);
679 if (NULL != g_audio_h) {
680 __destroy_audio_out();
683 if (0 > __create_audio_out(sound_data->audio_type, sound_data->rate)) {
684 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create audio out");
685 /* unset volume policy, volume will be 100% */
686 __unset_policy_for_playing();
688 ttsd_data_clear_sound_data(player->uid, &sound_data);
693 SLOG(LOG_INFO, tts_tag(), "[Player INFO] Success to destroy and recreate audio out");
694 __set_policy_for_playing(40);
697 while (APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) {
698 if ((unsigned int)idx >= sound_data->data_size)
701 if ((unsigned int)idx + SOUND_BUFFER_LENGTH > sound_data->data_size) {
702 len = sound_data->data_size - idx;
704 len = SOUND_BUFFER_LENGTH;
707 if (AUDIO_STATE_READY == g_audio_state) {
708 /* Request prepare */
709 ret = audio_out_prepare(g_audio_h);
710 if (AUDIO_IO_ERROR_NONE != ret) {
711 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to prepare audio : %d", ret);
712 g_playing_info = NULL;
713 /* unset volume policy, volume will be 100% */
714 __unset_policy_for_playing();
716 ttsd_data_clear_sound_data(player->uid, &sound_data);
720 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Prepare audio");
721 g_audio_state = AUDIO_STATE_PLAY;
724 char* temp_data = sound_data->data;
725 SLOG(LOG_INFO, tts_tag(), "[Player INFO] Before audio_out_write. data(%p), data[%d](%p), uid(%d), utt_id(%d), len(%d)",
726 temp_data, idx, &temp_data[idx], player->uid, sound_data->utt_id, len);
728 /* write pcm buffer */
729 fwrite(&temp_data[idx], 1, len, g_pFile);
731 ret = audio_out_write(g_audio_h, &temp_data[idx], len);
733 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to audio write - %d", ret);
736 SLOG(LOG_INFO, tts_tag(), "[Player INFO] After audio_out_write");
739 if (NULL == g_playing_info && APP_STATE_PAUSED != player->state) {
740 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current player is NULL");
741 g_audio_state = AUDIO_STATE_READY;
742 ret = audio_out_unprepare(g_audio_h);
743 if (AUDIO_IO_ERROR_NONE != ret) {
744 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
746 /* unset volume policy, volume will be 100% */
747 __unset_policy_for_playing();
749 ttsd_data_clear_sound_data(player->uid, &sound_data);
754 if (APP_STATE_PAUSED == player->state) {
756 SLOG(LOG_DEBUG, tts_tag(), "[Player] player(%p)", player);
757 player->paused_data = sound_data;
759 player->is_paused_data = true;
762 g_audio_state = AUDIO_STATE_READY;
764 SLOG(LOG_INFO, tts_tag(), "[Player] Stop player thread by pause");
766 /* Request prepare */
767 ret = audio_out_unprepare(g_audio_h);
768 if (AUDIO_IO_ERROR_NONE != ret) {
769 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
771 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
773 /* unset volume policy, volume will be 100% */
774 __unset_policy_for_playing();
779 if (NULL == g_playing_info && APP_STATE_READY == player->state) {
781 g_audio_state = AUDIO_STATE_READY;
782 SLOG(LOG_DEBUG, tts_tag(), "[Player] Stop player thread");
784 /* Request prepare */
785 ret = audio_out_unprepare(g_audio_h);
786 if (AUDIO_IO_ERROR_NONE != ret) {
787 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
789 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
792 ttsd_data_clear_sound_data(player->uid, &sound_data);
793 /* unset volume policy, volume will be 100% */
794 __unset_policy_for_playing();
798 if ((APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) &&
799 (TTSE_RESULT_EVENT_FINISH == sound_data->event)) {
800 /* send utterence finish signal */
801 int pid = ttsd_data_get_pid(player->uid);
804 SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
805 /* unset volume policy, volume will be 100% */
806 __unset_policy_for_playing();
811 if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
812 SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)",
813 pid, player->uid, sound_data->utt_id);
814 /* unset volume policy, volume will be 100% */
815 __unset_policy_for_playing();
817 ttsd_data_clear_sound_data(player->uid, &sound_data);
821 SLOG(LOG_INFO, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
824 ttsd_data_clear_sound_data(player->uid, &sound_data);
826 if (NULL == g_playing_info) {
827 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current player is NULL");
828 g_audio_state = AUDIO_STATE_READY;
829 ret = audio_out_unprepare(g_audio_h);
830 if (AUDIO_IO_ERROR_NONE != ret) {
831 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
833 /* unset volume policy, volume will be 100% */
834 __unset_policy_for_playing();
841 int __create_ducking_handle(void)
844 if (NULL == g_media_stream_ducking) {
845 ret = sound_manager_create_stream_ducking(SOUND_STREAM_TYPE_MEDIA, __sound_stream_ducking_state_changed_cb, NULL, &g_media_stream_ducking);
846 if (SOUND_MANAGER_ERROR_NONE != ret)
847 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to create stream ducking for type media, ret(%d)", ret);
849 SLOG(LOG_INFO, tts_tag(), "[Player INFO] Ducking handle for media stream is already created");
851 if (NULL == g_system_stream_ducking) {
852 ret = sound_manager_create_stream_ducking(SOUND_TYPE_SYSTEM, __sound_stream_ducking_state_changed_cb, NULL, &g_system_stream_ducking);
853 if (SOUND_MANAGER_ERROR_NONE != ret)
854 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to create stream ducking for system type, ret(%d)", ret);
856 SLOG(LOG_INFO, tts_tag(), "[Player INFO] Ducking handle for system stream is already created");
859 if (NULL == g_notification_stream_ducking) {
860 ret = sound_manager_create_stream_ducking(SOUND_TYPE_NOTIFICATION, __sound_stream_ducking_state_changed_cb, NULL, &g_notification_stream_ducking);
861 if (SOUND_MANAGER_ERROR_NONE != ret)
862 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to create stream ducking for notification type, ret(%d)", ret);
864 SLOG(LOG_INFO, tts_tag(), "[Player INFO] Ducking handle for notification stream is already created");
867 if (NULL == g_alarm_stream_ducking) {
868 ret = sound_manager_create_stream_ducking(SOUND_TYPE_ALARM, __sound_stream_ducking_state_changed_cb, NULL, &g_alarm_stream_ducking);
869 if (SOUND_MANAGER_ERROR_NONE != ret)
870 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to create stream ducking for alarm type, ret(%d)", ret);
872 SLOG(LOG_INFO, tts_tag(), "[Player INFO] Ducking handle for alarm stream is already created");
881 int ttsd_player_init()
883 g_playing_info = NULL;
884 g_audio_state = AUDIO_STATE_NONE;
889 ecore_thread_max_set(1);
893 if (0 == access(FOCUS_SERVER_READY, F_OK)) {
894 SLOG(LOG_ERROR, tts_tag(), "[Player SUCCESS] focus server is available");
898 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] focus server is not available");
903 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_INFORMATION, __player_focus_state_cb, NULL, &g_stream_info_h);
904 if (SOUND_MANAGER_ERROR_NONE != ret) {
905 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create stream info");
908 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Create stream info");
911 /* add sound focus state watch callback */
912 ret = sound_manager_add_focus_state_watch_cb(SOUND_STREAM_FOCUS_FOR_PLAYBACK, __player_focus_state_watch_cb, NULL, &g_focus_watch_id);
913 if (SOUND_MANAGER_ERROR_NONE != ret) {
914 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to add sound focus watch callback");
915 sound_manager_destroy_stream_information(g_stream_info_h);
918 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Add sound focus watch callback");
921 ret = __create_ducking_handle();
922 if (SOUND_MANAGER_ERROR_NONE != ret) {
923 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to create ducking handle, ret(%d)", ret);
925 SLOG(LOG_INFO, tts_tag(), "[Player SUCCESS] Create ducking handle");
928 ecore_thread_max_set(1);
930 ret = __create_audio_out(TTSE_AUDIO_TYPE_RAW_S16, 16000);
932 sound_manager_destroy_stream_information(g_stream_info_h);
933 sound_manager_remove_focus_state_watch_cb(g_focus_watch_id);
937 g_player_init = true;
942 int __destroy_ducking_handle(void)
945 if (g_media_stream_ducking) {
946 ret = sound_manager_destroy_stream_ducking(g_media_stream_ducking);
947 if (SOUND_MANAGER_ERROR_NONE != ret)
948 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to destroy media stream ducking, ret(%d)", ret);
949 g_media_stream_ducking = NULL;
951 SLOG(LOG_INFO, tts_tag(), "[Player INFO] Ducking handle for media stream is already created");
954 if (g_system_stream_ducking) {
955 ret = sound_manager_destroy_stream_ducking(g_system_stream_ducking);
956 if (SOUND_MANAGER_ERROR_NONE != ret)
957 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to destroy system stream ducking, ret(%d)", ret);
958 g_system_stream_ducking = NULL;
960 SLOG(LOG_INFO, tts_tag(), "[Player INFO] Ducking handle for system stream is already created");
963 if (g_notification_stream_ducking) {
964 ret = sound_manager_destroy_stream_ducking(g_notification_stream_ducking);
965 if (SOUND_MANAGER_ERROR_NONE != ret)
966 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to destroy notification stream ducking, ret(%d)", ret);
967 g_notification_stream_ducking = NULL;
969 SLOG(LOG_INFO, tts_tag(), "[Player INFO] Ducking handle for notification stream is already created");
972 if (g_alarm_stream_ducking) {
973 ret = sound_manager_destroy_stream_ducking(g_alarm_stream_ducking);
974 if (SOUND_MANAGER_ERROR_NONE != ret)
975 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to destroy alarm stream ducking, ret(%d)", ret);
976 g_alarm_stream_ducking = NULL;
978 SLOG(LOG_INFO, tts_tag(), "[Player INFO] Ducking handle for alarm stream is already created");
983 int ttsd_player_release(void)
985 if (false == g_player_init) {
986 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
987 return TTSD_ERROR_OPERATION_FAILED;
992 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] @@@@@");
993 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
994 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] @@@@@");
996 /* The thread should be released */
997 int thread_count = ecore_thread_active_get();
999 while (0 < thread_count) {
1004 SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
1008 thread_count = ecore_thread_active_get();
1011 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Thread is released");
1013 ret = __destroy_audio_out();
1017 ret = sound_manager_destroy_stream_information(g_stream_info_h);
1018 if (SOUND_MANAGER_ERROR_NONE != ret) {
1019 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to destroy stream info");
1021 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Destroy stream info");
1024 /* remove focus state watch callback */
1025 ret = sound_manager_remove_focus_state_watch_cb(g_focus_watch_id);
1026 if (SOUND_MANAGER_ERROR_NONE != ret) {
1027 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to remove the focus state watch cb");
1029 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Remove the focus state watch cb");
1032 ret = __destroy_ducking_handle();
1033 if (SOUND_MANAGER_ERROR_NONE != ret)
1034 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to destroy stream ducking, ret(%d)", ret);
1036 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Destroy stream ducking");
1038 /* clear g_player_list */
1039 g_playing_info = NULL;
1040 g_player_init = false;
1045 int ttsd_player_create_instance(int uid)
1047 if (false == g_player_init) {
1048 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
1052 /* Check uid is duplicated */
1053 if (NULL != __player_get_item(uid)) {
1054 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is already registered", uid);
1058 player_s* new_client = (player_s*)calloc(1, sizeof(player_s));
1059 if (NULL == new_client) {
1060 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to allocate memory");
1061 return TTSE_ERROR_OUT_OF_MEMORY;
1064 new_client->uid = uid;
1065 new_client->event = TTSE_RESULT_EVENT_FINISH;
1066 new_client->state = APP_STATE_READY;
1067 new_client->is_paused_data = false;
1068 new_client->idx = 0;
1069 new_client->paused_data = NULL;
1071 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[Player] Create player : uid(%d)", uid);
1073 g_player_list = g_list_append(g_player_list, new_client);
1078 int ttsd_player_destroy_instance(int uid)
1080 if (false == g_player_init) {
1081 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
1086 current = __player_get_item(uid);
1087 if (NULL == current) {
1088 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
1092 if (NULL != g_playing_info) {
1093 if (uid == g_playing_info->uid) {
1094 g_playing_info = NULL;
1099 player_s *data = NULL;
1101 if (0 < g_list_length(g_player_list)) {
1102 /* Get a first item */
1103 iter = g_list_first(g_player_list);
1105 while (NULL != iter) {
1106 /* Get handle data from list */
1107 data = (player_s*)iter->data;
1111 if (uid == data->uid) {
1112 g_player_list = g_list_remove_link(g_player_list, iter);
1120 iter = g_list_next(iter);
1124 SLOG(LOG_DEBUG, tts_tag(), "[PLAYER Success] Destroy instance");
1129 int ttsd_player_play(int uid)
1131 if (false == g_player_init) {
1132 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
1136 if (NULL != g_playing_info) {
1137 if (uid == g_playing_info->uid) {
1138 SLOG(LOG_DEBUG, tts_tag(), "[Player] uid(%d) has already played", g_playing_info->uid);
1141 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] stop old player (%d)", g_playing_info->uid);
1142 ttsd_player_stop(g_playing_info->uid);
1146 SLOG(LOG_DEBUG, tts_tag(), "[Player] start play : uid(%d)", uid);
1148 /* Check sound queue size */
1149 if (0 == ttsd_data_get_sound_data_size(uid)) {
1150 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid);
1156 current = __player_get_item(uid);
1157 if (NULL == current) {
1158 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
1162 current->state = APP_STATE_PLAYING;
1164 g_playing_info = current;
1166 SLOG(LOG_INFO, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
1168 if (0 < ttsd_data_get_sound_data_size(current->uid)) {
1169 SLOG(LOG_INFO, tts_tag(), "[Player] Run thread");
1170 ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
1176 int ttsd_player_stop(int uid)
1178 if (false == g_player_init) {
1179 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
1185 current = __player_get_item(uid);
1186 if (NULL == current) {
1187 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
1191 /* check whether uid is current playing or not */
1192 if (NULL != g_playing_info) {
1193 if (uid == g_playing_info->uid) {
1194 /* release current playing info */
1195 g_playing_info = NULL;
1198 SLOG(LOG_DEBUG, tts_tag(), "[Player] No current playing");
1201 if (true == current->is_paused_data) {
1202 if (NULL != current->paused_data) {
1203 if (NULL != current->paused_data->data) {
1204 free(current->paused_data->data);
1205 current->paused_data->data = NULL;
1208 free(current->paused_data);
1209 current->paused_data = NULL;
1213 current->event = TTSE_RESULT_EVENT_FINISH;
1214 current->state = APP_STATE_READY;
1215 current->is_paused_data = false;
1218 if (NULL == g_playing_info) {
1219 SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
1220 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
1221 SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
1223 /* The thread should be released */
1224 int thread_count = ecore_thread_active_get();
1226 while (0 < thread_count) {
1231 SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
1235 thread_count = ecore_thread_active_get();
1238 SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
1239 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
1240 SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
1243 SLOG(LOG_INFO, tts_tag(), "[Player SUCCESS] Stop player : uid(%d)", uid);
1248 int ttsd_player_clear(int uid)
1250 if (false == g_player_init) {
1251 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
1257 current = __player_get_item(uid);
1258 if (NULL == current) {
1259 SECURE_SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
1263 if (true == current->is_paused_data) {
1264 if (NULL != current->paused_data) {
1265 if (NULL != current->paused_data->data) {
1266 free(current->paused_data->data);
1267 current->paused_data->data = NULL;
1270 free(current->paused_data);
1271 current->paused_data = NULL;
1275 current->event = TTSE_RESULT_EVENT_FINISH;
1276 current->state = APP_STATE_READY;
1277 current->is_paused_data = false;
1280 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Clear player : uid(%d)", uid);
1285 int ttsd_player_pause(int uid)
1287 SLOG(LOG_DEBUG, tts_tag(), "[Player] pause player : uid(%d)", uid);
1289 if (false == g_player_init) {
1290 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
1296 current = __player_get_item(uid);
1297 if (NULL == current) {
1298 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] ttsd_player_pause() : uid(%d) is not valid", uid);
1302 /* check whether uid is current playing or not */
1303 if (NULL != g_playing_info) {
1304 if (uid == g_playing_info->uid) {
1305 /* release current playing info */
1306 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] release current playing info (%d)", uid);
1307 g_playing_info = NULL;
1313 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] current player (%p), g_playing_info(%p)", current, g_playing_info);
1315 current->state = APP_STATE_PAUSED;
1317 if (NULL == g_playing_info) {
1318 SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
1319 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
1320 SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
1322 /* The thread should be released */
1323 int thread_count = ecore_thread_active_get();
1325 while (0 < thread_count) {
1329 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] current(%p), state(%d)", current, current->state);
1332 SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue. current(%p) current state(%d)", current, current->state);
1336 thread_count = ecore_thread_active_get();
1339 SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
1340 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
1341 SLOG(LOG_DEBUG, tts_tag(), "[Player] @@@@@");
1345 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Pause player : uid(%d)", uid);
1350 int ttsd_player_resume(int uid)
1352 SLOG(LOG_DEBUG, tts_tag(), "[Player] Resume player : uid(%d)", uid);
1354 if (false == g_player_init) {
1355 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
1361 current = __player_get_item(uid);
1362 if (NULL == current) {
1363 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
1367 /* check current player */
1368 if (NULL != g_playing_info)
1369 g_playing_info = NULL;
1371 current->state = APP_STATE_PLAYING;
1372 g_playing_info = current;
1374 SLOG(LOG_INFO, tts_tag(), "[Player] Resume to run thread");
1375 ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
1380 int ttsd_player_all_stop()
1382 if (false == g_player_init) {
1383 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
1387 g_playing_info = NULL;
1390 player_s *data = NULL;
1392 if (0 < g_list_length(g_player_list)) {
1393 /* Get a first item */
1394 iter = g_list_first(g_player_list);
1396 while (NULL != iter) {
1397 /* Get handle data from list */
1398 data = (player_s*)iter->data;
1400 app_tts_state_e state;
1401 if (0 > ttsd_data_get_client_state(data->uid, &state)) {
1402 SLOG(LOG_ERROR, tts_tag(), "[player ERROR] uid(%d) is not valid", data->uid);
1403 ttsd_player_destroy_instance(data->uid);
1404 iter = g_list_next(iter);
1408 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
1409 data->event = TTSE_RESULT_EVENT_FINISH;
1410 data->state = APP_STATE_READY;
1412 if (true == data->is_paused_data) {
1413 if (NULL != data->paused_data) {
1414 if (NULL != data->paused_data->data) {
1415 free(data->paused_data->data);
1416 data->paused_data->data = NULL;
1419 free(data->paused_data);
1420 data->paused_data = NULL;
1424 data->is_paused_data = false;
1429 iter = g_list_next(iter);
1433 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] player all stop!!");
1438 int ttsd_player_play_pcm(int uid)
1440 if (false == g_player_init) {
1441 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
1445 if (NULL != g_playing_info) {
1446 if (uid == g_playing_info->uid) {
1447 SLOG(LOG_DEBUG, tts_tag(), "[Player] uid(%d) has already played", g_playing_info->uid);
1450 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] stop old player (%d)", g_playing_info->uid);
1451 ttsd_player_stop(g_playing_info->uid);
1455 SLOG(LOG_DEBUG, tts_tag(), "[Player] start play : uid(%d)", uid);
1457 /* Check sound queue size */
1458 if (0 == ttsd_data_get_sound_data_size(uid)) {
1459 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid);
1464 current = __player_get_item(uid);
1465 if (NULL == current) {
1466 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
1470 current->state = APP_STATE_PLAYING;
1472 g_playing_info = current;
1474 SLOG(LOG_INFO, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
1476 if (0 <= ttsd_data_get_sound_data_size(current->uid)) {
1477 SLOG(LOG_INFO, tts_tag(), "[Player] Run thread");
1478 ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
1484 int ttsd_player_get_background_volume_ratio(double* ratio)
1489 *ratio = g_bg_volume_ratio;
1491 return TTSD_ERROR_NONE;
1494 int ttsd_player_set_background_volume_ratio(double ratio)
1496 SLOG(LOG_INFO, tts_tag(), "[Player DEBUG] ttsd_player_set_background_volume_ratio : %lf", ratio);
1498 g_bg_volume_ratio = ratio;
1499 return TTSD_ERROR_NONE;