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"
25 * Internal data structure
35 int uid; /** client id */
36 app_state_e state; /** client state */
38 /* Current utterance information */
39 ttse_result_event_e event; /** event of last utterance */
43 sound_data_s* paused_data;
46 #define SOUND_BUFFER_LENGTH 2048
47 #define FOCUS_SERVER_READY "/tmp/.sound_server_ready"
49 /** player init info */
50 static bool g_player_init = false;
53 static GList *g_player_list;
55 /** current player information */
56 static player_s* g_playing_info;
59 static audio_state_e g_audio_state;
61 static ttse_audio_type_e g_audio_type;
63 static int g_sampling_rate;
65 static audio_out_h g_audio_h;
67 static sound_stream_info_h g_stream_info_h;
73 player_s* __player_get_item(int uid)
76 player_s *data = NULL;
78 if (0 < g_list_length(g_player_list)) {
79 /* Get a first item */
80 iter = g_list_first(g_player_list);
82 while (NULL != iter) {
83 /* Get handle data from list */
84 data = (player_s*)iter->data;
91 iter = g_list_next(iter);
98 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,
99 sound_stream_focus_change_reason_e reason_for_change, int sound_behavior, const char *extra_info, void *user_data)
101 SLOG(LOG_DEBUG, tts_tag(), "===== Focus state changed cb");
103 if (stream_info != g_stream_info_h) {
104 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Invalid stream info handle");
107 SLOG(LOG_WARN, tts_tag(), "[Player] focus state changed to (%d) with reason(%d)", (int)focus_state, (int)reason_for_change);
109 if (AUDIO_STATE_PLAY == g_audio_state && focus_mask == SOUND_STREAM_FOCUS_FOR_PLAYBACK && SOUND_STREAM_FOCUS_STATE_RELEASED == focus_state) {
110 if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
111 g_audio_state = AUDIO_STATE_READY;
113 if (NULL == g_playing_info) {
114 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
118 if (APP_STATE_PLAYING == g_playing_info->state) {
119 int uid = g_playing_info->uid;
121 if (0 != ttsd_player_pause(uid)) {
122 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to pause the player");
126 g_playing_info->state = APP_STATE_PAUSED;
127 ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
128 int pid = ttsd_data_get_pid(uid);
129 /* send message to client about changing state */
130 ttsdc_send_set_state_message(pid, uid, APP_STATE_PAUSED);
133 SLOG(LOG_DEBUG, tts_tag(), "[Player] Ignore focus state cb - mode(%d)", ttsd_get_mode());
137 SLOG(LOG_DEBUG, tts_tag(), "=====");
138 SLOG(LOG_DEBUG, tts_tag(), "");
143 static int __create_audio_out(ttse_audio_type_e type, int rate)
146 audio_sample_type_e sample_type;
148 if (TTSE_AUDIO_TYPE_RAW_S16 == type) {
149 sample_type = AUDIO_SAMPLE_TYPE_S16_LE;
151 sample_type = AUDIO_SAMPLE_TYPE_U8;
154 ret = audio_out_create_new(rate, AUDIO_CHANNEL_MONO, sample_type, &g_audio_h);
155 if (AUDIO_IO_ERROR_NONE != ret) {
156 g_audio_state = AUDIO_STATE_NONE;
158 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create audio");
161 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Create audio");
165 g_sampling_rate = rate;
167 g_audio_state = AUDIO_STATE_READY;
172 static int __destroy_audio_out()
174 if (NULL == g_audio_h) {
175 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current handle is not valid");
180 ret = audio_out_destroy(g_audio_h);
181 if (AUDIO_IO_ERROR_NONE != ret) {
182 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to destroy audio");
185 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Destroy audio");
191 g_audio_state = AUDIO_STATE_NONE;
197 static void __end_play_thread(void *data, Ecore_Thread *thread)
199 SLOG(LOG_ERROR, tts_tag(), "===== End thread");
202 static void __set_policy_for_playing(int volume)
204 /* Set stream info */
206 if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
207 ret = sound_manager_acquire_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL);
208 if (SOUND_MANAGER_ERROR_NONE != ret) {
209 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to acquire focus");
212 ret = audio_out_set_sound_stream_info(g_audio_h, g_stream_info_h);
213 if (AUDIO_IO_ERROR_NONE != ret) {
214 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to set stream info");
220 static void __unset_policy_for_playing()
223 /* Unset stream info */
224 if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
225 sound_stream_focus_state_e state_for_playing = SOUND_STREAM_FOCUS_STATE_ACQUIRED;
226 ret = sound_manager_get_focus_state(g_stream_info_h, &state_for_playing, NULL);
227 if (SOUND_MANAGER_ERROR_NONE != ret) {
228 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to get focus state: %d", ret);
231 if (SOUND_STREAM_FOCUS_STATE_ACQUIRED == state_for_playing) {
232 ret = sound_manager_release_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL);
233 if (SOUND_MANAGER_ERROR_NONE != ret) {
234 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to release focus");
242 static void __play_thread(void *data, Ecore_Thread *thread)
244 SLOG(LOG_DEBUG, tts_tag(), "===== Start thread");
246 if (NULL == g_playing_info) {
247 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] No current player");
251 player_s* player = g_playing_info;
252 sound_data_s* sound_data = NULL;
255 int len = SOUND_BUFFER_LENGTH;
258 /* set volume policy as 40% */
259 __set_policy_for_playing(40);
261 if (true == player->is_paused_data) {
263 sound_data = player->paused_data;
264 player->paused_data = NULL;
268 player->is_paused_data = false;
271 if (NULL == sound_data) {
272 /* Request unprepare */
273 ret = audio_out_unprepare(g_audio_h);
274 if (AUDIO_IO_ERROR_NONE != ret) {
275 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
277 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
280 g_audio_state = AUDIO_STATE_READY;
282 /* unset volume policy, volume will be 100% */
283 __unset_policy_for_playing();
286 SLOG(LOG_INFO, tts_tag(), "[Player] Sound info : id(%d) data(%p) size(%d) audiotype(%d) rate(%d) event(%d)",
287 sound_data->utt_id, sound_data->data, sound_data->data_size, sound_data->audio_type, sound_data->rate, sound_data->event);
290 ret = ttsd_data_get_sound_data(player->uid, &sound_data);
291 if (0 != ret || NULL == sound_data) {
293 SLOG(LOG_DEBUG, tts_tag(), "[Player] No sound data. Waiting mode");
294 /* release audio & recover session */
295 ret = audio_out_unprepare(g_audio_h);
296 if (AUDIO_IO_ERROR_NONE != ret) {
297 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
299 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
301 g_audio_state = AUDIO_STATE_READY;
303 /* unset volume policy, volume will be 100% */
304 __unset_policy_for_playing();
306 /* wait for new audio data come */
309 if (NULL == g_playing_info) {
310 /* current playing uid is replaced */
311 SLOG(LOG_INFO, tts_tag(), "[Player] Finish thread");
313 } else if (0 < ttsd_data_get_sound_data_size(player->uid)) {
314 /* new audio data come */
315 SLOG(LOG_INFO, tts_tag(), "[Player] Resume thread");
320 SLOG(LOG_INFO, tts_tag(), "[Player] Finish to wait for new audio data come");
322 /* set volume policy as 40%, when resume play thread*/
323 __set_policy_for_playing(40);
325 /* resume play thread */
326 player->state = APP_STATE_PLAYING;
330 /* If wdata's event is 'start', current wdata is first data of engine for synthesis.
331 * If wdata's event is 'finish', player should check previous event to know whether this wdata is first or not.
332 * When previous wdata's event is 'finish' and current wdata's event is 'finish',
333 * the player should send utt started event.
335 if (TTSE_RESULT_EVENT_START == sound_data->event ||
336 (TTSE_RESULT_EVENT_FINISH == player->event && TTSE_RESULT_EVENT_FINISH == sound_data->event)) {
337 int pid = ttsd_data_get_pid(player->uid);
340 SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
341 /* unset volume policy, volume will be 100% */
342 __unset_policy_for_playing();
344 if (NULL != sound_data->data) {
345 free(sound_data->data);
346 sound_data->data = NULL;
353 if (0 != ttsdc_send_utt_start_message(pid, player->uid, sound_data->utt_id)) {
354 SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Start Signal : pid(%d), uid(%d), uttid(%d)",
355 pid, player->uid, sound_data->utt_id);
357 SLOG(LOG_INFO, tts_tag(), "[Player] Start utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
360 /* Save last event to check utterance start */
361 player->event = sound_data->event;
364 if (NULL == sound_data->data || 0 >= sound_data->data_size) {
365 if (TTSE_RESULT_EVENT_FINISH == sound_data->event) {
366 SLOG(LOG_DEBUG, tts_tag(), "No sound data");
367 /* send utterence finish signal */
368 int pid = ttsd_data_get_pid(player->uid);
371 SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
372 /* unset volume policy, volume will be 100% */
373 __unset_policy_for_playing();
374 if (NULL != sound_data->data) {
375 free(sound_data->data);
376 sound_data->data = NULL;
382 if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
383 SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)",
384 pid, player->uid, sound_data->utt_id);
387 SLOG(LOG_INFO, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
392 if (g_sampling_rate != sound_data->rate || g_audio_type != sound_data->audio_type) {
393 SLOG(LOG_DEBUG, tts_tag(), "[Player] Change audio handle : org type(%d) org rate(%d)", g_audio_type, g_sampling_rate);
394 if (NULL != g_audio_h) {
395 __destroy_audio_out();
398 if (0 > __create_audio_out(sound_data->audio_type, sound_data->rate)) {
399 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create audio out");
400 /* unset volume policy, volume will be 100% */
401 __unset_policy_for_playing();
403 if (NULL != sound_data->data) {
404 free(sound_data->data);
405 sound_data->data = NULL;
412 __set_policy_for_playing(40);
415 while (APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) {
416 if ((unsigned int)idx >= sound_data->data_size)
419 if ((unsigned int)idx + SOUND_BUFFER_LENGTH > sound_data->data_size) {
420 len = sound_data->data_size - idx;
422 len = SOUND_BUFFER_LENGTH;
425 if (AUDIO_STATE_READY == g_audio_state) {
426 /* Request prepare */
427 ret = audio_out_prepare(g_audio_h);
428 if (AUDIO_IO_ERROR_NONE != ret) {
429 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to prepare audio : %d", ret);
430 g_playing_info = NULL;
431 /* unset volume policy, volume will be 100% */
432 __unset_policy_for_playing();
434 if (NULL != sound_data->data) {
435 free(sound_data->data);
436 sound_data->data = NULL;
444 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Prepare audio");
445 g_audio_state = AUDIO_STATE_PLAY;
448 char* temp_data = sound_data->data;
449 ret = audio_out_write(g_audio_h, &temp_data[idx], len);
451 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to audio write - %d", ret);
456 if (NULL == g_playing_info && APP_STATE_PAUSED != player->state) {
457 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current player is NULL");
458 g_audio_state = AUDIO_STATE_READY;
459 ret = audio_out_unprepare(g_audio_h);
460 if (AUDIO_IO_ERROR_NONE != ret) {
461 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
463 /* unset volume policy, volume will be 100% */
464 __unset_policy_for_playing();
466 if (NULL != sound_data) {
467 if (NULL != sound_data->data) {
468 free(sound_data->data);
469 sound_data->data = NULL;
479 if (APP_STATE_PAUSED == player->state) {
481 player->paused_data = sound_data;
483 player->is_paused_data = true;
486 g_audio_state = AUDIO_STATE_READY;
487 SLOG(LOG_INFO, tts_tag(), "[Player] Stop player thread by pause");
489 /* Request prepare */
490 ret = audio_out_unprepare(g_audio_h);
491 if (AUDIO_IO_ERROR_NONE != ret) {
492 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
494 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
496 /* unset volume policy, volume will be 100% */
497 __unset_policy_for_playing();
502 if (NULL == g_playing_info && APP_STATE_READY == player->state) {
504 g_audio_state = AUDIO_STATE_READY;
505 SLOG(LOG_DEBUG, tts_tag(), "[Player] Stop player thread");
507 /* Request prepare */
508 ret = audio_out_unprepare(g_audio_h);
509 if (AUDIO_IO_ERROR_NONE != ret) {
510 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
512 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
515 if (NULL != sound_data) {
516 if (NULL != sound_data->data) {
517 free(sound_data->data);
518 sound_data->data = NULL;
524 /* unset volume policy, volume will be 100% */
525 __unset_policy_for_playing();
529 if ((APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) &&
530 (TTSE_RESULT_EVENT_FINISH == sound_data->event)) {
531 /* send utterence finish signal */
532 int pid = ttsd_data_get_pid(player->uid);
535 SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
536 /* unset volume policy, volume will be 100% */
537 __unset_policy_for_playing();
538 if (NULL != sound_data->data) {
539 free(sound_data->data);
540 sound_data->data = NULL;
548 if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
549 SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)",
550 pid, player->uid, sound_data->utt_id);
551 /* unset volume policy, volume will be 100% */
552 __unset_policy_for_playing();
553 if (NULL != sound_data->data) {
554 free(sound_data->data);
555 sound_data->data = NULL;
563 SLOG(LOG_INFO, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
566 if (NULL != sound_data) {
567 if (NULL != sound_data->data) {
568 free(sound_data->data);
569 sound_data->data = NULL;
576 if (NULL == g_playing_info) {
577 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current player is NULL");
578 g_audio_state = AUDIO_STATE_READY;
579 ret = audio_out_unprepare(g_audio_h);
580 if (AUDIO_IO_ERROR_NONE != ret) {
581 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
583 /* unset volume policy, volume will be 100% */
584 __unset_policy_for_playing();
594 int ttsd_player_init()
596 g_playing_info = NULL;
597 g_audio_state = AUDIO_STATE_NONE;
602 ecore_thread_max_set(1);
606 if (0 == access(FOCUS_SERVER_READY, F_OK)) {
607 SLOG(LOG_ERROR, tts_tag(), "[Player SUCCESS] focus server is available");
611 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] focus server is not available");
616 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_INFORMATION, __player_focus_state_cb, NULL, &g_stream_info_h);
617 if (SOUND_MANAGER_ERROR_NONE != ret) {
618 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create stream info");
621 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Create stream info");
624 ecore_thread_max_set(1);
626 ret = __create_audio_out(TTSE_AUDIO_TYPE_RAW_S16, 16000);
630 g_player_init = true;
635 int ttsd_player_release(void)
637 if (false == g_player_init) {
638 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
639 return TTSD_ERROR_OPERATION_FAILED;
644 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] ==========================");
645 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
646 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] ==========================");
648 /* The thread should be released */
649 int thread_count = ecore_thread_active_get();
651 while (0 < thread_count) {
656 SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
660 thread_count = ecore_thread_active_get();
663 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Thread is released");
665 ret = __destroy_audio_out();
669 ret = sound_manager_destroy_stream_information(g_stream_info_h);
670 if (SOUND_MANAGER_ERROR_NONE != ret) {
671 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to destroy stream info");
673 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Destroy stream info");
676 /* clear g_player_list */
677 g_playing_info = NULL;
678 g_player_init = false;
683 int ttsd_player_create_instance(int uid)
685 if (false == g_player_init) {
686 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
690 /* Check uid is duplicated */
691 if (NULL != __player_get_item(uid)) {
692 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is already registered", uid);
696 player_s* new_client = (player_s*)calloc(1, sizeof(player_s));
697 if (NULL == new_client) {
698 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to allocate memory");
699 return TTSE_ERROR_OUT_OF_MEMORY;
702 new_client->uid = uid;
703 new_client->event = TTSE_RESULT_EVENT_FINISH;
704 new_client->state = APP_STATE_READY;
705 new_client->is_paused_data = false;
707 new_client->paused_data = NULL;
709 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[Player] Create player : uid(%d)", uid);
711 g_player_list = g_list_append(g_player_list, new_client);
716 int ttsd_player_destroy_instance(int uid)
718 if (false == g_player_init) {
719 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
724 current = __player_get_item(uid);
725 if (NULL == current) {
726 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
730 if (NULL != g_playing_info) {
731 if (uid == g_playing_info->uid) {
732 g_playing_info = NULL;
737 player_s *data = NULL;
739 if (0 < g_list_length(g_player_list)) {
740 /* Get a first item */
741 iter = g_list_first(g_player_list);
743 while (NULL != iter) {
744 /* Get handle data from list */
745 data = (player_s*)iter->data;
749 if (uid == data->uid) {
750 g_player_list = g_list_remove_link(g_player_list, iter);
758 iter = g_list_next(iter);
762 SLOG(LOG_DEBUG, tts_tag(), "[PLAYER Success] Destroy instance");
767 int ttsd_player_play(int uid)
769 if (false == g_player_init) {
770 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
774 if (NULL != g_playing_info) {
775 if (uid == g_playing_info->uid) {
776 SLOG(LOG_DEBUG, tts_tag(), "[Player] uid(%d) has already played", g_playing_info->uid);
779 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] stop old player (%d)", g_playing_info->uid);
780 ttsd_player_stop(g_playing_info->uid);
784 SLOG(LOG_DEBUG, tts_tag(), "[Player] start play : uid(%d)", uid);
786 /* Check sound queue size */
787 if (0 == ttsd_data_get_sound_data_size(uid)) {
788 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid);
794 current = __player_get_item(uid);
795 if (NULL == current) {
796 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
800 current->state = APP_STATE_PLAYING;
802 g_playing_info = current;
804 SLOG(LOG_INFO, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
806 if (0 < ttsd_data_get_sound_data_size(current->uid)) {
807 SLOG(LOG_INFO, tts_tag(), "[Player] Run thread");
808 ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
814 int ttsd_player_stop(int uid)
816 if (false == g_player_init) {
817 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
823 current = __player_get_item(uid);
824 if (NULL == current) {
825 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
829 /* check whether uid is current playing or not */
830 if (NULL != g_playing_info) {
831 if (uid == g_playing_info->uid) {
832 /* release current playing info */
833 g_playing_info = NULL;
836 SLOG(LOG_DEBUG, tts_tag(), "[Player] No current playing");
839 if (true == current->is_paused_data) {
840 if (NULL != current->paused_data) {
841 if (NULL != current->paused_data->data) {
842 free(current->paused_data->data);
843 current->paused_data->data = NULL;
846 free(current->paused_data);
847 current->paused_data = NULL;
851 current->event = TTSE_RESULT_EVENT_FINISH;
852 current->state = APP_STATE_READY;
853 current->is_paused_data = false;
856 if (NULL == g_playing_info) {
857 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
858 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
859 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
861 /* The thread should be released */
862 int thread_count = ecore_thread_active_get();
864 while (0 < thread_count) {
869 SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
873 thread_count = ecore_thread_active_get();
876 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
877 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
878 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
881 SLOG(LOG_INFO, tts_tag(), "[Player SUCCESS] Stop player : uid(%d)", uid);
886 int ttsd_player_clear(int uid)
888 if (false == g_player_init) {
889 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
895 current = __player_get_item(uid);
896 if (NULL == current) {
897 SECURE_SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
901 if (true == current->is_paused_data) {
902 if (NULL != current->paused_data) {
903 if (NULL != current->paused_data->data) {
904 free(current->paused_data->data);
905 current->paused_data->data = NULL;
908 free(current->paused_data);
909 current->paused_data = NULL;
913 current->event = TTSE_RESULT_EVENT_FINISH;
914 current->state = APP_STATE_READY;
915 current->is_paused_data = false;
918 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Clear player : uid(%d)", uid);
923 int ttsd_player_pause(int uid)
925 SLOG(LOG_DEBUG, tts_tag(), "[Player] pause player : uid(%d)", uid);
927 if (false == g_player_init) {
928 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
934 current = __player_get_item(uid);
935 if (NULL == current) {
936 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] ttsd_player_pause() : uid(%d) is not valid", uid);
940 /* check whether uid is current playing or not */
941 if (NULL != g_playing_info) {
942 if (uid == g_playing_info->uid) {
943 /* release current playing info */
944 g_playing_info = NULL;
950 current->state = APP_STATE_PAUSED;
952 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
953 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
954 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
956 /* The thread should be released */
957 int thread_count = ecore_thread_active_get();
959 while (0 < thread_count) {
964 SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
968 thread_count = ecore_thread_active_get();
971 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
972 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
973 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
975 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Pause player : uid(%d)", uid);
980 int ttsd_player_resume(int uid)
982 SLOG(LOG_DEBUG, tts_tag(), "[Player] Resume player : uid(%d)", uid);
984 if (false == g_player_init) {
985 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
991 current = __player_get_item(uid);
992 if (NULL == current) {
993 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
997 /* check current player */
998 if (NULL != g_playing_info)
999 g_playing_info = NULL;
1001 current->state = APP_STATE_PLAYING;
1002 g_playing_info = current;
1004 SLOG(LOG_INFO, tts_tag(), "[Player] Resume to run thread");
1005 ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
1010 int ttsd_player_all_stop()
1012 if (false == g_player_init) {
1013 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
1017 g_playing_info = NULL;
1020 player_s *data = NULL;
1022 if (0 < g_list_length(g_player_list)) {
1023 /* Get a first item */
1024 iter = g_list_first(g_player_list);
1026 while (NULL != iter) {
1027 /* Get handle data from list */
1028 data = (player_s*)iter->data;
1031 if (0 > ttsd_data_get_client_state(data->uid, &state)) {
1032 SLOG(LOG_ERROR, tts_tag(), "[player ERROR] uid(%d) is not valid", data->uid);
1033 ttsd_player_destroy_instance(data->uid);
1034 iter = g_list_next(iter);
1038 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
1039 data->event = TTSE_RESULT_EVENT_FINISH;
1040 data->state = APP_STATE_READY;
1042 if (true == data->is_paused_data) {
1043 if (NULL != data->paused_data) {
1044 if (NULL != data->paused_data->data) {
1045 free(data->paused_data->data);
1046 data->paused_data->data = NULL;
1049 free(data->paused_data);
1050 data->paused_data = NULL;
1054 data->is_paused_data = false;
1059 iter = g_list_next(iter);
1063 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] player all stop!!");