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_change_reason_e reason_for_change, const char *extra_info, void *user_data)
99 SLOG(LOG_DEBUG, tts_tag(), "===== Focus state changed cb");
101 if (stream_info != g_stream_info_h) {
102 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Invalid stream info handle");
107 sound_stream_focus_state_e state_for_playback ;
108 ret = sound_manager_get_focus_state(g_stream_info_h, &state_for_playback, NULL);
109 if (SOUND_MANAGER_ERROR_NONE != ret) {
110 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to get focus state");
114 SLOG(LOG_WARN, tts_tag(), "[Player] focus state changed to (%d) with reason(%d)", (int)state_for_playback, (int)reason_for_change);
116 if (AUDIO_STATE_PLAY == g_audio_state && SOUND_STREAM_FOCUS_STATE_RELEASED == state_for_playback) {
117 if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
118 g_audio_state = AUDIO_STATE_READY;
120 if (NULL == g_playing_info) {
121 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
125 if (APP_STATE_PLAYING == g_playing_info->state) {
126 g_playing_info->state = APP_STATE_PAUSED;
128 ttsd_data_set_client_state(g_playing_info->uid, APP_STATE_PAUSED);
130 int pid = ttsd_data_get_pid(g_playing_info->uid);
132 /* send message to client about changing state */
133 ttsdc_send_set_state_message(pid, g_playing_info->uid, APP_STATE_PAUSED);
136 SLOG(LOG_DEBUG, tts_tag(), "[Player] Ignore focus state cb - mode(%d)", ttsd_get_mode());
140 SLOG(LOG_DEBUG, tts_tag(), "=====");
141 SLOG(LOG_DEBUG, tts_tag(), "");
146 static int __create_audio_out(ttse_audio_type_e type, int rate)
149 audio_sample_type_e sample_type;
151 if (TTSE_AUDIO_TYPE_RAW_S16 == type) {
152 sample_type = AUDIO_SAMPLE_TYPE_S16_LE;
154 sample_type = AUDIO_SAMPLE_TYPE_U8;
157 ret = audio_out_create_new(rate, AUDIO_CHANNEL_MONO, sample_type, &g_audio_h);
158 if (AUDIO_IO_ERROR_NONE != ret) {
159 g_audio_state = AUDIO_STATE_NONE;
161 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create audio");
164 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Create audio");
168 g_sampling_rate = rate;
170 g_audio_state = AUDIO_STATE_READY;
175 static int __destroy_audio_out()
177 if (NULL == g_audio_h) {
178 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current handle is not valid");
183 ret = audio_out_destroy(g_audio_h);
184 if (AUDIO_IO_ERROR_NONE != ret) {
185 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to destroy audio");
188 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Destroy audio");
194 g_audio_state = AUDIO_STATE_NONE;
200 static void __end_play_thread(void *data, Ecore_Thread *thread)
202 SLOG(LOG_ERROR, tts_tag(), "===== End thread");
205 static void __set_policy_for_playing(int volume)
207 /* Set stream info */
209 if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
210 ret = sound_manager_acquire_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
211 if (SOUND_MANAGER_ERROR_NONE != ret) {
212 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to acquire focus");
215 ret = audio_out_set_stream_info(g_audio_h, g_stream_info_h);
216 if (AUDIO_IO_ERROR_NONE != ret) {
217 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to set stream info");
223 static void __unset_policy_for_playing()
226 /* Unset stream info */
227 if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
228 ret = sound_manager_release_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
229 if (SOUND_MANAGER_ERROR_NONE != ret) {
230 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to release focus");
237 static void __play_thread(void *data, Ecore_Thread *thread)
239 SLOG(LOG_DEBUG, tts_tag(), "===== Start thread");
241 if (NULL == g_playing_info) {
242 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] No current player");
246 player_s* player = g_playing_info;
247 sound_data_s* sound_data = NULL;
250 int len = SOUND_BUFFER_LENGTH;
253 /* set volume policy as 40% */
254 __set_policy_for_playing(40);
256 if (true == player->is_paused_data) {
258 sound_data = player->paused_data;
259 player->paused_data = NULL;
263 player->is_paused_data = false;
266 if (NULL == sound_data) {
267 /* Request unprepare */
268 ret = audio_out_unprepare(g_audio_h);
269 if (AUDIO_IO_ERROR_NONE != ret) {
270 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
272 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
275 g_audio_state = AUDIO_STATE_READY;
277 /* unset volume policy, volume will be 100% */
278 __unset_policy_for_playing();
281 SLOG(LOG_INFO, tts_tag(), "[Player] Sound info : id(%d) data(%p) size(%d) audiotype(%d) rate(%d) event(%d)",
282 sound_data->utt_id, sound_data->data, sound_data->data_size, sound_data->audio_type, sound_data->rate, sound_data->event);
285 ret = ttsd_data_get_sound_data(player->uid, &sound_data);
286 if (0 != ret || NULL == sound_data) {
288 SLOG(LOG_DEBUG, tts_tag(), "[Player] No sound data. Waiting mode");
289 /* release audio & recover session */
290 ret = audio_out_unprepare(g_audio_h);
291 if (AUDIO_IO_ERROR_NONE != ret) {
292 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
294 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
296 g_audio_state = AUDIO_STATE_READY;
298 /* unset volume policy, volume will be 100% */
299 __unset_policy_for_playing();
301 /* wait for new audio data come */
304 if (NULL == g_playing_info) {
305 /* current playing uid is replaced */
306 SLOG(LOG_DEBUG, tts_tag(), "[Player] Finish thread");
308 } else if (0 < ttsd_data_get_sound_data_size(player->uid)) {
309 /* new audio data come */
310 SLOG(LOG_DEBUG, tts_tag(), "[Player] Resume thread");
315 /* set volume policy as 40%, when resume play thread*/
316 __set_policy_for_playing(40);
318 /* resume play thread */
319 player->state = APP_STATE_PLAYING;
323 /* If wdata's event is 'start', current wdata is first data of engine for synthesis.
324 * If wdata's event is 'finish', player should check previous event to know whether this wdata is first or not.
325 * When previous wdata's event is 'finish' and current wdata's event is 'finish',
326 * the player should send utt started event.
328 if (TTSE_RESULT_EVENT_START == sound_data->event ||
329 (TTSE_RESULT_EVENT_FINISH == player->event && TTSE_RESULT_EVENT_FINISH == sound_data->event)) {
330 int pid = ttsd_data_get_pid(player->uid);
333 SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
334 /* unset volume policy, volume will be 100% */
335 __unset_policy_for_playing();
339 if (0 != ttsdc_send_utt_start_message(pid, player->uid, sound_data->utt_id)) {
340 SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Start Signal : pid(%d), uid(%d), uttid(%d)",
341 pid, player->uid, sound_data->utt_id);
343 SLOG(LOG_DEBUG, tts_tag(), "[Player] Start utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
346 /* Save last event to check utterance start */
347 player->event = sound_data->event;
350 if (NULL == sound_data->data || 0 >= sound_data->data_size) {
351 if (TTSE_RESULT_EVENT_FINISH == sound_data->event) {
352 SLOG(LOG_DEBUG, tts_tag(), "No sound data");
353 /* send utterence finish signal */
354 int pid = ttsd_data_get_pid(player->uid);
357 SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
358 /* unset volume policy, volume will be 100% */
359 __unset_policy_for_playing();
362 if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
363 SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)",
364 pid, player->uid, sound_data->utt_id);
367 SLOG(LOG_DEBUG, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
372 if (g_sampling_rate != sound_data->rate || g_audio_type != sound_data->audio_type) {
373 SLOG(LOG_DEBUG, tts_tag(), "[Player] Change audio handle : org type(%d) org rate(%d)", g_audio_type, g_sampling_rate);
374 if (NULL != g_audio_h) {
375 __destroy_audio_out();
378 if (0 > __create_audio_out(sound_data->audio_type, sound_data->rate)) {
379 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create audio out");
380 /* unset volume policy, volume will be 100% */
381 __unset_policy_for_playing();
386 while (APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) {
387 if ((unsigned int)idx >= sound_data->data_size)
390 if ((unsigned int)idx + SOUND_BUFFER_LENGTH > sound_data->data_size) {
391 len = sound_data->data_size - idx;
393 len = SOUND_BUFFER_LENGTH;
396 if (AUDIO_STATE_READY == g_audio_state) {
397 /* Request prepare */
398 ret = audio_out_prepare(g_audio_h);
399 if (AUDIO_IO_ERROR_NONE != ret) {
400 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to prepare audio : %d", ret);
401 g_playing_info = NULL;
402 /* unset volume policy, volume will be 100% */
403 __unset_policy_for_playing();
406 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Prepare audio");
407 g_audio_state = AUDIO_STATE_PLAY;
410 char* temp_data = sound_data->data;
411 ret = audio_out_write(g_audio_h, &temp_data[idx], len);
413 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to audio write - %d", ret);
418 if (NULL == g_playing_info && APP_STATE_PAUSED != player->state) {
419 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current player is NULL");
420 g_audio_state = AUDIO_STATE_READY;
421 ret = audio_out_unprepare(g_audio_h);
422 if (AUDIO_IO_ERROR_NONE != ret) {
423 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
425 /* unset volume policy, volume will be 100% */
426 __unset_policy_for_playing();
428 if (NULL != sound_data) {
429 if (NULL != sound_data->data) {
430 free(sound_data->data);
431 sound_data->data = NULL;
441 if (APP_STATE_PAUSED == player->state) {
443 player->paused_data = sound_data;
445 player->is_paused_data = true;
448 g_audio_state = AUDIO_STATE_READY;
449 SLOG(LOG_DEBUG, tts_tag(), "[Player] Stop player thread by pause");
451 /* Request prepare */
452 ret = audio_out_unprepare(g_audio_h);
453 if (AUDIO_IO_ERROR_NONE != ret) {
454 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
456 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
458 /* unset volume policy, volume will be 100% */
459 __unset_policy_for_playing();
464 if (NULL == g_playing_info && APP_STATE_READY == player->state) {
466 g_audio_state = AUDIO_STATE_READY;
467 SLOG(LOG_DEBUG, tts_tag(), "[Player] Stop player thread");
469 /* Request prepare */
470 ret = audio_out_unprepare(g_audio_h);
471 if (AUDIO_IO_ERROR_NONE != ret) {
472 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
474 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
477 if (NULL != sound_data) {
478 if (NULL != sound_data->data) {
479 free(sound_data->data);
480 sound_data->data = NULL;
486 /* unset volume policy, volume will be 100% */
487 __unset_policy_for_playing();
491 if ((APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) &&
492 (TTSE_RESULT_EVENT_FINISH == sound_data->event)) {
493 /* send utterence finish signal */
494 int pid = ttsd_data_get_pid(player->uid);
497 SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
498 /* unset volume policy, volume will be 100% */
499 __unset_policy_for_playing();
503 if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
504 SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)",
505 pid, player->uid, sound_data->utt_id);
506 /* unset volume policy, volume will be 100% */
507 __unset_policy_for_playing();
511 SLOG(LOG_DEBUG, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
514 if (NULL != sound_data) {
515 if (NULL != sound_data->data) {
516 free(sound_data->data);
517 sound_data->data = NULL;
524 if (NULL == g_playing_info) {
525 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current player is NULL");
526 g_audio_state = AUDIO_STATE_READY;
527 ret = audio_out_unprepare(g_audio_h);
528 if (AUDIO_IO_ERROR_NONE != ret) {
529 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
531 /* unset volume policy, volume will be 100% */
532 __unset_policy_for_playing();
542 int ttsd_player_init()
544 g_playing_info = NULL;
545 g_audio_state = AUDIO_STATE_NONE;
550 ecore_thread_max_set(1);
552 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_INFORMATION, __player_focus_state_cb, NULL, &g_stream_info_h);
553 if (SOUND_MANAGER_ERROR_NONE != ret) {
554 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create stream info");
557 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Create stream info");
560 ecore_thread_max_set(1);
562 ret = __create_audio_out(TTSE_AUDIO_TYPE_RAW_S16, 16000);
566 g_player_init = true;
571 int ttsd_player_release(void)
573 if (false == g_player_init) {
574 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
575 return TTSD_ERROR_OPERATION_FAILED;
580 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] ==========================");
581 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
582 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] ==========================");
584 /* The thread should be released */
585 int thread_count = ecore_thread_active_get();
587 while (0 < thread_count) {
592 SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
596 thread_count = ecore_thread_active_get();
599 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Thread is released");
601 ret = __destroy_audio_out();
605 ret = sound_manager_destroy_stream_information(g_stream_info_h);
606 if (SOUND_MANAGER_ERROR_NONE != ret) {
607 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to destroy stream info");
609 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Destroy stream info");
612 /* clear g_player_list */
613 g_playing_info = NULL;
614 g_player_init = false;
619 int ttsd_player_create_instance(int uid)
621 if (false == g_player_init) {
622 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
626 /* Check uid is duplicated */
627 if (NULL != __player_get_item(uid)) {
628 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is already registered", uid);
632 player_s* new_client = (player_s*)calloc(1, sizeof(player_s));
633 if (NULL == new_client) {
634 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to allocate memory");
635 return TTSE_ERROR_OUT_OF_MEMORY;
638 new_client->uid = uid;
639 new_client->event = TTSE_RESULT_EVENT_FINISH;
640 new_client->state = APP_STATE_READY;
641 new_client->is_paused_data = false;
643 new_client->paused_data = NULL;
645 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[Player] Create player : uid(%d)", uid);
647 g_player_list = g_list_append(g_player_list, new_client);
652 int ttsd_player_destroy_instance(int uid)
654 if (false == g_player_init) {
655 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
660 current = __player_get_item(uid);
661 if (NULL == current) {
662 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
666 if (NULL != g_playing_info) {
667 if (uid == g_playing_info->uid) {
668 g_playing_info = NULL;
673 player_s *data = NULL;
675 if (0 < g_list_length(g_player_list)) {
676 /* Get a first item */
677 iter = g_list_first(g_player_list);
679 while (NULL != iter) {
680 /* Get handle data from list */
681 data = (player_s*)iter->data;
685 if (uid == data->uid) {
686 g_player_list = g_list_remove_link(g_player_list, iter);
694 iter = g_list_next(iter);
698 SLOG(LOG_DEBUG, tts_tag(), "[PLAYER Success] Destroy instance");
703 int ttsd_player_play(int uid)
705 if (false == g_player_init) {
706 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
710 if (NULL != g_playing_info) {
711 if (uid == g_playing_info->uid) {
712 SLOG(LOG_DEBUG, tts_tag(), "[Player] uid(%d) has already played", g_playing_info->uid);
715 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] stop old player (%d)", g_playing_info->uid);
716 ttsd_player_stop(g_playing_info->uid);
720 SLOG(LOG_DEBUG, tts_tag(), "[Player] start play : uid(%d)", uid);
722 /* Check sound queue size */
723 if (0 == ttsd_data_get_sound_data_size(uid)) {
724 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid);
730 current = __player_get_item(uid);
731 if (NULL == current) {
732 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
736 current->state = APP_STATE_PLAYING;
738 g_playing_info = current;
740 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
742 if (0 < ttsd_data_get_sound_data_size(current->uid)) {
743 SLOG(LOG_DEBUG, tts_tag(), "[Player] Run thread");
744 ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
750 int ttsd_player_stop(int uid)
752 if (false == g_player_init) {
753 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
759 current = __player_get_item(uid);
760 if (NULL == current) {
761 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
765 /* check whether uid is current playing or not */
766 if (NULL != g_playing_info) {
767 if (uid == g_playing_info->uid) {
768 /* release current playing info */
769 g_playing_info = NULL;
772 SLOG(LOG_DEBUG, tts_tag(), "[Player] No current playing");
775 if (true == current->is_paused_data) {
776 if (NULL != current->paused_data) {
777 if (NULL != current->paused_data->data) {
778 free(current->paused_data->data);
779 current->paused_data->data = NULL;
782 free(current->paused_data);
783 current->paused_data = NULL;
787 current->event = TTSE_RESULT_EVENT_FINISH;
788 current->state = APP_STATE_READY;
789 current->is_paused_data = false;
792 if (NULL == g_playing_info) {
793 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
794 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
795 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
797 /* The thread should be released */
798 int thread_count = ecore_thread_active_get();
800 while (0 < thread_count) {
805 SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
809 thread_count = ecore_thread_active_get();
812 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
813 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
814 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
817 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Stop player : uid(%d)", uid);
822 int ttsd_player_clear(int uid)
824 if (false == g_player_init) {
825 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
831 current = __player_get_item(uid);
832 if (NULL == current) {
833 SECURE_SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
837 if (true == current->is_paused_data) {
838 if (NULL != current->paused_data) {
839 if (NULL != current->paused_data->data) {
840 free(current->paused_data->data);
841 current->paused_data->data = NULL;
844 free(current->paused_data);
845 current->paused_data = NULL;
849 current->event = TTSE_RESULT_EVENT_FINISH;
850 current->state = APP_STATE_READY;
851 current->is_paused_data = false;
854 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Clear player : uid(%d)", uid);
859 int ttsd_player_pause(int uid)
861 SLOG(LOG_DEBUG, tts_tag(), "[Player] pause player : uid(%d)", uid);
863 if (false == g_player_init) {
864 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
870 current = __player_get_item(uid);
871 if (NULL == current) {
872 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] ttsd_player_pause() : uid(%d) is not valid", uid);
876 /* check whether uid is current playing or not */
877 if (NULL != g_playing_info) {
878 if (uid == g_playing_info->uid) {
879 /* release current playing info */
880 g_playing_info = NULL;
886 current->state = APP_STATE_PAUSED;
888 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
889 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
890 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
892 /* The thread should be released */
893 int thread_count = ecore_thread_active_get();
895 while (0 < thread_count) {
900 SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
904 thread_count = ecore_thread_active_get();
907 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
908 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
909 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
911 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Pause player : uid(%d)", uid);
916 int ttsd_player_resume(int uid)
918 SLOG(LOG_DEBUG, tts_tag(), "[Player] Resume player : uid(%d)", uid);
920 if (false == g_player_init) {
921 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
927 current = __player_get_item(uid);
928 if (NULL == current) {
929 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
933 /* check current player */
934 if (NULL != g_playing_info)
935 g_playing_info = NULL;
937 current->state = APP_STATE_PLAYING;
938 g_playing_info = current;
940 SLOG(LOG_DEBUG, tts_tag(), "[Player] Run thread");
941 ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
946 int ttsd_player_all_stop()
948 if (false == g_player_init) {
949 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
953 g_playing_info = NULL;
956 player_s *data = NULL;
958 if (0 < g_list_length(g_player_list)) {
959 /* Get a first item */
960 iter = g_list_first(g_player_list);
962 while (NULL != iter) {
963 /* Get handle data from list */
964 data = (player_s*)iter->data;
967 if (0 > ttsd_data_get_client_state(data->uid, &state)) {
968 SLOG(LOG_ERROR, tts_tag(), "[player ERROR] uid(%d) is not valid", data->uid);
969 ttsd_player_destroy_instance(data->uid);
970 iter = g_list_next(iter);
974 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
975 data->event = TTSE_RESULT_EVENT_FINISH;
976 data->state = APP_STATE_READY;
978 if (true == data->is_paused_data) {
979 if (NULL != data->paused_data) {
980 if (NULL != data->paused_data->data) {
981 free(data->paused_data->data);
982 data->paused_data->data = NULL;
985 free(data->paused_data);
986 data->paused_data = NULL;
990 data->is_paused_data = false;
995 iter = g_list_next(iter);
999 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] player all stop!!");