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
48 /** player init info */
49 static bool g_player_init = false;
52 static GList *g_player_list;
54 /** current player information */
55 static player_s* g_playing_info;
58 static audio_state_e g_audio_state;
60 static ttse_audio_type_e g_audio_type;
62 static int g_sampling_rate;
64 static audio_out_h g_audio_h;
66 static sound_stream_info_h g_stream_info_h;
72 player_s* __player_get_item(int uid)
75 player_s *data = NULL;
77 if (0 < g_list_length(g_player_list)) {
78 /* Get a first item */
79 iter = g_list_first(g_player_list);
81 while (NULL != iter) {
82 /* Get handle data from list */
83 data = (player_s*)iter->data;
90 iter = g_list_next(iter);
97 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,
98 sound_stream_focus_change_reason_e reason_for_change, int sound_behavior, const char *extra_info, void *user_data)
100 SLOG(LOG_DEBUG, tts_tag(), "===== Focus state changed cb");
102 if (stream_info != g_stream_info_h) {
103 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Invalid stream info handle");
106 SLOG(LOG_WARN, tts_tag(), "[Player] focus state changed to (%d) with reason(%d)", (int)focus_state, (int)reason_for_change);
108 if (AUDIO_STATE_PLAY == g_audio_state && focus_mask == SOUND_STREAM_FOCUS_FOR_PLAYBACK && SOUND_STREAM_FOCUS_STATE_RELEASED == focus_state) {
109 if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
110 g_audio_state = AUDIO_STATE_READY;
112 if (NULL == g_playing_info) {
113 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
117 if (APP_STATE_PLAYING == g_playing_info->state) {
118 g_playing_info->state = APP_STATE_PAUSED;
120 ttsd_data_set_client_state(g_playing_info->uid, APP_STATE_PAUSED);
122 int pid = ttsd_data_get_pid(g_playing_info->uid);
124 /* send message to client about changing state */
125 ttsdc_send_set_state_message(pid, g_playing_info->uid, APP_STATE_PAUSED);
128 SLOG(LOG_DEBUG, tts_tag(), "[Player] Ignore focus state cb - mode(%d)", ttsd_get_mode());
132 SLOG(LOG_DEBUG, tts_tag(), "=====");
133 SLOG(LOG_DEBUG, tts_tag(), "");
138 static int __create_audio_out(ttse_audio_type_e type, int rate)
141 audio_sample_type_e sample_type;
143 if (TTSE_AUDIO_TYPE_RAW_S16 == type) {
144 sample_type = AUDIO_SAMPLE_TYPE_S16_LE;
146 sample_type = AUDIO_SAMPLE_TYPE_U8;
149 ret = audio_out_create_new(rate, AUDIO_CHANNEL_MONO, sample_type, &g_audio_h);
150 if (AUDIO_IO_ERROR_NONE != ret) {
151 g_audio_state = AUDIO_STATE_NONE;
153 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create audio");
156 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Create audio");
160 g_sampling_rate = rate;
162 g_audio_state = AUDIO_STATE_READY;
167 static int __destroy_audio_out()
169 if (NULL == g_audio_h) {
170 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current handle is not valid");
175 ret = audio_out_destroy(g_audio_h);
176 if (AUDIO_IO_ERROR_NONE != ret) {
177 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to destroy audio");
180 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Destroy audio");
186 g_audio_state = AUDIO_STATE_NONE;
192 static void __end_play_thread(void *data, Ecore_Thread *thread)
194 SLOG(LOG_ERROR, tts_tag(), "===== End thread");
197 static void __set_policy_for_playing(int volume)
199 /* Set stream info */
201 if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
202 ret = sound_manager_acquire_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL);
203 if (SOUND_MANAGER_ERROR_NONE != ret) {
204 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to acquire focus");
207 ret = audio_out_set_stream_info(g_audio_h, g_stream_info_h);
208 if (AUDIO_IO_ERROR_NONE != ret) {
209 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to set stream info");
215 static void __unset_policy_for_playing()
218 /* Unset stream info */
219 if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
220 ret = sound_manager_release_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, SOUND_BEHAVIOR_NONE, NULL);
221 if (SOUND_MANAGER_ERROR_NONE != ret) {
222 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to release focus");
229 static void __play_thread(void *data, Ecore_Thread *thread)
231 SLOG(LOG_DEBUG, tts_tag(), "===== Start thread");
233 if (NULL == g_playing_info) {
234 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] No current player");
238 player_s* player = g_playing_info;
239 sound_data_s* sound_data = NULL;
242 int len = SOUND_BUFFER_LENGTH;
245 /* set volume policy as 40% */
246 __set_policy_for_playing(40);
248 if (true == player->is_paused_data) {
250 sound_data = player->paused_data;
251 player->paused_data = NULL;
255 player->is_paused_data = false;
258 if (NULL == sound_data) {
259 /* Request unprepare */
260 ret = audio_out_unprepare(g_audio_h);
261 if (AUDIO_IO_ERROR_NONE != ret) {
262 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
264 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
267 g_audio_state = AUDIO_STATE_READY;
269 /* unset volume policy, volume will be 100% */
270 __unset_policy_for_playing();
273 SLOG(LOG_INFO, tts_tag(), "[Player] Sound info : id(%d) data(%p) size(%d) audiotype(%d) rate(%d) event(%d)",
274 sound_data->utt_id, sound_data->data, sound_data->data_size, sound_data->audio_type, sound_data->rate, sound_data->event);
277 ret = ttsd_data_get_sound_data(player->uid, &sound_data);
278 if (0 != ret || NULL == sound_data) {
280 SLOG(LOG_DEBUG, tts_tag(), "[Player] No sound data. Waiting mode");
281 /* release audio & recover session */
282 ret = audio_out_unprepare(g_audio_h);
283 if (AUDIO_IO_ERROR_NONE != ret) {
284 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
286 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
288 g_audio_state = AUDIO_STATE_READY;
290 /* unset volume policy, volume will be 100% */
291 __unset_policy_for_playing();
293 /* wait for new audio data come */
296 if (NULL == g_playing_info) {
297 /* current playing uid is replaced */
298 SLOG(LOG_DEBUG, tts_tag(), "[Player] Finish thread");
300 } else if (0 < ttsd_data_get_sound_data_size(player->uid)) {
301 /* new audio data come */
302 SLOG(LOG_DEBUG, tts_tag(), "[Player] Resume thread");
307 /* set volume policy as 40%, when resume play thread*/
308 __set_policy_for_playing(40);
310 /* resume play thread */
311 player->state = APP_STATE_PLAYING;
315 /* If wdata's event is 'start', current wdata is first data of engine for synthesis.
316 * If wdata's event is 'finish', player should check previous event to know whether this wdata is first or not.
317 * When previous wdata's event is 'finish' and current wdata's event is 'finish',
318 * the player should send utt started event.
320 if (TTSE_RESULT_EVENT_START == sound_data->event ||
321 (TTSE_RESULT_EVENT_FINISH == player->event && TTSE_RESULT_EVENT_FINISH == sound_data->event)) {
322 int pid = ttsd_data_get_pid(player->uid);
325 SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
326 /* unset volume policy, volume will be 100% */
327 __unset_policy_for_playing();
331 if (0 != ttsdc_send_utt_start_message(pid, player->uid, sound_data->utt_id)) {
332 SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Start Signal : pid(%d), uid(%d), uttid(%d)",
333 pid, player->uid, sound_data->utt_id);
335 SLOG(LOG_DEBUG, tts_tag(), "[Player] Start utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
338 /* Save last event to check utterance start */
339 player->event = sound_data->event;
342 if (NULL == sound_data->data || 0 >= sound_data->data_size) {
343 if (TTSE_RESULT_EVENT_FINISH == sound_data->event) {
344 SLOG(LOG_DEBUG, tts_tag(), "No sound data");
345 /* send utterence finish signal */
346 int pid = ttsd_data_get_pid(player->uid);
349 SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
350 /* unset volume policy, volume will be 100% */
351 __unset_policy_for_playing();
354 if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
355 SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)",
356 pid, player->uid, sound_data->utt_id);
359 SLOG(LOG_DEBUG, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
364 if (g_sampling_rate != sound_data->rate || g_audio_type != sound_data->audio_type) {
365 SLOG(LOG_DEBUG, tts_tag(), "[Player] Change audio handle : org type(%d) org rate(%d)", g_audio_type, g_sampling_rate);
366 if (NULL != g_audio_h) {
367 __destroy_audio_out();
370 if (0 > __create_audio_out(sound_data->audio_type, sound_data->rate)) {
371 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create audio out");
372 /* unset volume policy, volume will be 100% */
373 __unset_policy_for_playing();
376 __set_policy_for_playing(40);
379 while (APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) {
380 if ((unsigned int)idx >= sound_data->data_size)
383 if ((unsigned int)idx + SOUND_BUFFER_LENGTH > sound_data->data_size) {
384 len = sound_data->data_size - idx;
386 len = SOUND_BUFFER_LENGTH;
389 if (AUDIO_STATE_READY == g_audio_state) {
390 /* Request prepare */
391 ret = audio_out_prepare(g_audio_h);
392 if (AUDIO_IO_ERROR_NONE != ret) {
393 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to prepare audio : %d", ret);
394 g_playing_info = NULL;
395 /* unset volume policy, volume will be 100% */
396 __unset_policy_for_playing();
399 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Prepare audio");
400 g_audio_state = AUDIO_STATE_PLAY;
403 char* temp_data = sound_data->data;
404 ret = audio_out_write(g_audio_h, &temp_data[idx], len);
406 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to audio write - %d", ret);
411 if (NULL == g_playing_info && APP_STATE_PAUSED != player->state) {
412 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current player is NULL");
413 g_audio_state = AUDIO_STATE_READY;
414 ret = audio_out_unprepare(g_audio_h);
415 if (AUDIO_IO_ERROR_NONE != ret) {
416 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
418 /* unset volume policy, volume will be 100% */
419 __unset_policy_for_playing();
421 if (NULL != sound_data) {
422 if (NULL != sound_data->data) {
423 free(sound_data->data);
424 sound_data->data = NULL;
434 if (APP_STATE_PAUSED == player->state) {
436 player->paused_data = sound_data;
438 player->is_paused_data = true;
441 g_audio_state = AUDIO_STATE_READY;
442 SLOG(LOG_DEBUG, tts_tag(), "[Player] Stop player thread by pause");
444 /* Request prepare */
445 ret = audio_out_unprepare(g_audio_h);
446 if (AUDIO_IO_ERROR_NONE != ret) {
447 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
449 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
451 /* unset volume policy, volume will be 100% */
452 __unset_policy_for_playing();
457 if (NULL == g_playing_info && APP_STATE_READY == player->state) {
459 g_audio_state = AUDIO_STATE_READY;
460 SLOG(LOG_DEBUG, tts_tag(), "[Player] Stop player thread");
462 /* Request prepare */
463 ret = audio_out_unprepare(g_audio_h);
464 if (AUDIO_IO_ERROR_NONE != ret) {
465 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
467 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
470 if (NULL != sound_data) {
471 if (NULL != sound_data->data) {
472 free(sound_data->data);
473 sound_data->data = NULL;
479 /* unset volume policy, volume will be 100% */
480 __unset_policy_for_playing();
484 if ((APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) &&
485 (TTSE_RESULT_EVENT_FINISH == sound_data->event)) {
486 /* send utterence finish signal */
487 int pid = ttsd_data_get_pid(player->uid);
490 SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
491 /* unset volume policy, volume will be 100% */
492 __unset_policy_for_playing();
496 if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
497 SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)",
498 pid, player->uid, sound_data->utt_id);
499 /* unset volume policy, volume will be 100% */
500 __unset_policy_for_playing();
504 SLOG(LOG_DEBUG, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
507 if (NULL != sound_data) {
508 if (NULL != sound_data->data) {
509 free(sound_data->data);
510 sound_data->data = NULL;
517 if (NULL == g_playing_info) {
518 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current player is NULL");
519 g_audio_state = AUDIO_STATE_READY;
520 ret = audio_out_unprepare(g_audio_h);
521 if (AUDIO_IO_ERROR_NONE != ret) {
522 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
524 /* unset volume policy, volume will be 100% */
525 __unset_policy_for_playing();
535 int ttsd_player_init()
537 g_playing_info = NULL;
538 g_audio_state = AUDIO_STATE_NONE;
543 ecore_thread_max_set(1);
545 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_INFORMATION, __player_focus_state_cb, NULL, &g_stream_info_h);
546 if (SOUND_MANAGER_ERROR_NONE != ret) {
547 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create stream info");
550 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Create stream info");
553 ecore_thread_max_set(1);
555 ret = __create_audio_out(TTSE_AUDIO_TYPE_RAW_S16, 16000);
559 g_player_init = true;
564 int ttsd_player_release(void)
566 if (false == g_player_init) {
567 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
568 return TTSD_ERROR_OPERATION_FAILED;
573 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] ==========================");
574 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
575 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] ==========================");
577 /* The thread should be released */
578 int thread_count = ecore_thread_active_get();
580 while (0 < thread_count) {
585 SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
589 thread_count = ecore_thread_active_get();
592 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Thread is released");
594 ret = __destroy_audio_out();
598 ret = sound_manager_destroy_stream_information(g_stream_info_h);
599 if (SOUND_MANAGER_ERROR_NONE != ret) {
600 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to destroy stream info");
602 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Destroy stream info");
605 /* clear g_player_list */
606 g_playing_info = NULL;
607 g_player_init = false;
612 int ttsd_player_create_instance(int uid)
614 if (false == g_player_init) {
615 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
619 /* Check uid is duplicated */
620 if (NULL != __player_get_item(uid)) {
621 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is already registered", uid);
625 player_s* new_client = (player_s*)calloc(1, sizeof(player_s));
626 if (NULL == new_client) {
627 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to allocate memory");
628 return TTSE_ERROR_OUT_OF_MEMORY;
631 new_client->uid = uid;
632 new_client->event = TTSE_RESULT_EVENT_FINISH;
633 new_client->state = APP_STATE_READY;
634 new_client->is_paused_data = false;
636 new_client->paused_data = NULL;
638 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[Player] Create player : uid(%d)", uid);
640 g_player_list = g_list_append(g_player_list, new_client);
645 int ttsd_player_destroy_instance(int uid)
647 if (false == g_player_init) {
648 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
653 current = __player_get_item(uid);
654 if (NULL == current) {
655 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
659 if (NULL != g_playing_info) {
660 if (uid == g_playing_info->uid) {
661 g_playing_info = NULL;
666 player_s *data = NULL;
668 if (0 < g_list_length(g_player_list)) {
669 /* Get a first item */
670 iter = g_list_first(g_player_list);
672 while (NULL != iter) {
673 /* Get handle data from list */
674 data = (player_s*)iter->data;
678 if (uid == data->uid) {
679 g_player_list = g_list_remove_link(g_player_list, iter);
687 iter = g_list_next(iter);
691 SLOG(LOG_DEBUG, tts_tag(), "[PLAYER Success] Destroy instance");
696 int ttsd_player_play(int uid)
698 if (false == g_player_init) {
699 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
703 if (NULL != g_playing_info) {
704 if (uid == g_playing_info->uid) {
705 SLOG(LOG_DEBUG, tts_tag(), "[Player] uid(%d) has already played", g_playing_info->uid);
708 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] stop old player (%d)", g_playing_info->uid);
709 ttsd_player_stop(g_playing_info->uid);
713 SLOG(LOG_DEBUG, tts_tag(), "[Player] start play : uid(%d)", uid);
715 /* Check sound queue size */
716 if (0 == ttsd_data_get_sound_data_size(uid)) {
717 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid);
723 current = __player_get_item(uid);
724 if (NULL == current) {
725 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
729 current->state = APP_STATE_PLAYING;
731 g_playing_info = current;
733 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
735 if (0 < ttsd_data_get_sound_data_size(current->uid)) {
736 SLOG(LOG_DEBUG, tts_tag(), "[Player] Run thread");
737 ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
743 int ttsd_player_stop(int uid)
745 if (false == g_player_init) {
746 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
752 current = __player_get_item(uid);
753 if (NULL == current) {
754 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
758 /* check whether uid is current playing or not */
759 if (NULL != g_playing_info) {
760 if (uid == g_playing_info->uid) {
761 /* release current playing info */
762 g_playing_info = NULL;
765 SLOG(LOG_DEBUG, tts_tag(), "[Player] No current playing");
768 if (true == current->is_paused_data) {
769 if (NULL != current->paused_data) {
770 if (NULL != current->paused_data->data) {
771 free(current->paused_data->data);
772 current->paused_data->data = NULL;
775 free(current->paused_data);
776 current->paused_data = NULL;
780 current->event = TTSE_RESULT_EVENT_FINISH;
781 current->state = APP_STATE_READY;
782 current->is_paused_data = false;
785 if (NULL == g_playing_info) {
786 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
787 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
788 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
790 /* The thread should be released */
791 int thread_count = ecore_thread_active_get();
793 while (0 < thread_count) {
798 SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
802 thread_count = ecore_thread_active_get();
805 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
806 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
807 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
810 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Stop player : uid(%d)", uid);
815 int ttsd_player_clear(int uid)
817 if (false == g_player_init) {
818 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
824 current = __player_get_item(uid);
825 if (NULL == current) {
826 SECURE_SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
830 if (true == current->is_paused_data) {
831 if (NULL != current->paused_data) {
832 if (NULL != current->paused_data->data) {
833 free(current->paused_data->data);
834 current->paused_data->data = NULL;
837 free(current->paused_data);
838 current->paused_data = NULL;
842 current->event = TTSE_RESULT_EVENT_FINISH;
843 current->state = APP_STATE_READY;
844 current->is_paused_data = false;
847 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Clear player : uid(%d)", uid);
852 int ttsd_player_pause(int uid)
854 SLOG(LOG_DEBUG, tts_tag(), "[Player] pause player : uid(%d)", uid);
856 if (false == g_player_init) {
857 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
863 current = __player_get_item(uid);
864 if (NULL == current) {
865 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] ttsd_player_pause() : uid(%d) is not valid", uid);
869 /* check whether uid is current playing or not */
870 if (NULL != g_playing_info) {
871 if (uid == g_playing_info->uid) {
872 /* release current playing info */
873 g_playing_info = NULL;
879 current->state = APP_STATE_PAUSED;
881 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
882 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
883 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
885 /* The thread should be released */
886 int thread_count = ecore_thread_active_get();
888 while (0 < thread_count) {
893 SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
897 thread_count = ecore_thread_active_get();
900 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
901 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
902 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
904 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Pause player : uid(%d)", uid);
909 int ttsd_player_resume(int uid)
911 SLOG(LOG_DEBUG, tts_tag(), "[Player] Resume player : uid(%d)", uid);
913 if (false == g_player_init) {
914 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
920 current = __player_get_item(uid);
921 if (NULL == current) {
922 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
926 /* check current player */
927 if (NULL != g_playing_info)
928 g_playing_info = NULL;
930 current->state = APP_STATE_PLAYING;
931 g_playing_info = current;
933 SLOG(LOG_DEBUG, tts_tag(), "[Player] Run thread");
934 ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
939 int ttsd_player_all_stop()
941 if (false == g_player_init) {
942 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
946 g_playing_info = NULL;
949 player_s *data = NULL;
951 if (0 < g_list_length(g_player_list)) {
952 /* Get a first item */
953 iter = g_list_first(g_player_list);
955 while (NULL != iter) {
956 /* Get handle data from list */
957 data = (player_s*)iter->data;
960 if (0 > ttsd_data_get_client_state(data->uid, &state)) {
961 SLOG(LOG_ERROR, tts_tag(), "[player ERROR] uid(%d) is not valid", data->uid);
962 ttsd_player_destroy_instance(data->uid);
963 iter = g_list_next(iter);
967 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
968 data->event = TTSE_RESULT_EVENT_FINISH;
969 data->state = APP_STATE_READY;
971 if (true == data->is_paused_data) {
972 if (NULL != data->paused_data) {
973 if (NULL != data->paused_data->data) {
974 free(data->paused_data->data);
975 data->paused_data->data = NULL;
978 free(data->paused_data);
979 data->paused_data = NULL;
983 data->is_paused_data = false;
988 iter = g_list_next(iter);
992 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] player all stop!!");