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();
384 __set_policy_for_playing(40);
387 while (APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) {
388 if ((unsigned int)idx >= sound_data->data_size)
391 if ((unsigned int)idx + SOUND_BUFFER_LENGTH > sound_data->data_size) {
392 len = sound_data->data_size - idx;
394 len = SOUND_BUFFER_LENGTH;
397 if (AUDIO_STATE_READY == g_audio_state) {
398 /* Request prepare */
399 ret = audio_out_prepare(g_audio_h);
400 if (AUDIO_IO_ERROR_NONE != ret) {
401 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to prepare audio : %d", ret);
402 g_playing_info = NULL;
403 /* unset volume policy, volume will be 100% */
404 __unset_policy_for_playing();
407 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Prepare audio");
408 g_audio_state = AUDIO_STATE_PLAY;
411 char* temp_data = sound_data->data;
412 ret = audio_out_write(g_audio_h, &temp_data[idx], len);
414 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to audio write - %d", ret);
419 if (NULL == g_playing_info && APP_STATE_PAUSED != player->state) {
420 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current player is NULL");
421 g_audio_state = AUDIO_STATE_READY;
422 ret = audio_out_unprepare(g_audio_h);
423 if (AUDIO_IO_ERROR_NONE != ret) {
424 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
426 /* unset volume policy, volume will be 100% */
427 __unset_policy_for_playing();
429 if (NULL != sound_data) {
430 if (NULL != sound_data->data) {
431 free(sound_data->data);
432 sound_data->data = NULL;
442 if (APP_STATE_PAUSED == player->state) {
444 player->paused_data = sound_data;
446 player->is_paused_data = true;
449 g_audio_state = AUDIO_STATE_READY;
450 SLOG(LOG_DEBUG, tts_tag(), "[Player] Stop player thread by pause");
452 /* Request prepare */
453 ret = audio_out_unprepare(g_audio_h);
454 if (AUDIO_IO_ERROR_NONE != ret) {
455 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
457 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
459 /* unset volume policy, volume will be 100% */
460 __unset_policy_for_playing();
465 if (NULL == g_playing_info && APP_STATE_READY == player->state) {
467 g_audio_state = AUDIO_STATE_READY;
468 SLOG(LOG_DEBUG, tts_tag(), "[Player] Stop player thread");
470 /* Request prepare */
471 ret = audio_out_unprepare(g_audio_h);
472 if (AUDIO_IO_ERROR_NONE != ret) {
473 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
475 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Unprepare audio");
478 if (NULL != sound_data) {
479 if (NULL != sound_data->data) {
480 free(sound_data->data);
481 sound_data->data = NULL;
487 /* unset volume policy, volume will be 100% */
488 __unset_policy_for_playing();
492 if ((APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) &&
493 (TTSE_RESULT_EVENT_FINISH == sound_data->event)) {
494 /* send utterence finish signal */
495 int pid = ttsd_data_get_pid(player->uid);
498 SLOG(LOG_WARN, tts_tag(), "[Send WARNIING] Current player is not valid");
499 /* unset volume policy, volume will be 100% */
500 __unset_policy_for_playing();
504 if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
505 SLOG(LOG_ERROR, tts_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)",
506 pid, player->uid, sound_data->utt_id);
507 /* unset volume policy, volume will be 100% */
508 __unset_policy_for_playing();
512 SLOG(LOG_DEBUG, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
515 if (NULL != sound_data) {
516 if (NULL != sound_data->data) {
517 free(sound_data->data);
518 sound_data->data = NULL;
525 if (NULL == g_playing_info) {
526 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Current player is NULL");
527 g_audio_state = AUDIO_STATE_READY;
528 ret = audio_out_unprepare(g_audio_h);
529 if (AUDIO_IO_ERROR_NONE != ret) {
530 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
532 /* unset volume policy, volume will be 100% */
533 __unset_policy_for_playing();
543 int ttsd_player_init()
545 g_playing_info = NULL;
546 g_audio_state = AUDIO_STATE_NONE;
551 ecore_thread_max_set(1);
553 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_INFORMATION, __player_focus_state_cb, NULL, &g_stream_info_h);
554 if (SOUND_MANAGER_ERROR_NONE != ret) {
555 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create stream info");
558 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Create stream info");
561 ecore_thread_max_set(1);
563 ret = __create_audio_out(TTSE_AUDIO_TYPE_RAW_S16, 16000);
567 g_player_init = true;
572 int ttsd_player_release(void)
574 if (false == g_player_init) {
575 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
576 return TTSD_ERROR_OPERATION_FAILED;
581 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] ==========================");
582 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
583 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] ==========================");
585 /* The thread should be released */
586 int thread_count = ecore_thread_active_get();
588 while (0 < thread_count) {
593 SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
597 thread_count = ecore_thread_active_get();
600 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Thread is released");
602 ret = __destroy_audio_out();
606 ret = sound_manager_destroy_stream_information(g_stream_info_h);
607 if (SOUND_MANAGER_ERROR_NONE != ret) {
608 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to destroy stream info");
610 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Destroy stream info");
613 /* clear g_player_list */
614 g_playing_info = NULL;
615 g_player_init = false;
620 int ttsd_player_create_instance(int uid)
622 if (false == g_player_init) {
623 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
627 /* Check uid is duplicated */
628 if (NULL != __player_get_item(uid)) {
629 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is already registered", uid);
633 player_s* new_client = (player_s*)calloc(1, sizeof(player_s));
634 if (NULL == new_client) {
635 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to allocate memory");
636 return TTSE_ERROR_OUT_OF_MEMORY;
639 new_client->uid = uid;
640 new_client->event = TTSE_RESULT_EVENT_FINISH;
641 new_client->state = APP_STATE_READY;
642 new_client->is_paused_data = false;
644 new_client->paused_data = NULL;
646 SECURE_SLOG(LOG_DEBUG, tts_tag(), "[Player] Create player : uid(%d)", uid);
648 g_player_list = g_list_append(g_player_list, new_client);
653 int ttsd_player_destroy_instance(int uid)
655 if (false == g_player_init) {
656 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
661 current = __player_get_item(uid);
662 if (NULL == current) {
663 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
667 if (NULL != g_playing_info) {
668 if (uid == g_playing_info->uid) {
669 g_playing_info = NULL;
674 player_s *data = NULL;
676 if (0 < g_list_length(g_player_list)) {
677 /* Get a first item */
678 iter = g_list_first(g_player_list);
680 while (NULL != iter) {
681 /* Get handle data from list */
682 data = (player_s*)iter->data;
686 if (uid == data->uid) {
687 g_player_list = g_list_remove_link(g_player_list, iter);
695 iter = g_list_next(iter);
699 SLOG(LOG_DEBUG, tts_tag(), "[PLAYER Success] Destroy instance");
704 int ttsd_player_play(int uid)
706 if (false == g_player_init) {
707 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
711 if (NULL != g_playing_info) {
712 if (uid == g_playing_info->uid) {
713 SLOG(LOG_DEBUG, tts_tag(), "[Player] uid(%d) has already played", g_playing_info->uid);
716 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] stop old player (%d)", g_playing_info->uid);
717 ttsd_player_stop(g_playing_info->uid);
721 SLOG(LOG_DEBUG, tts_tag(), "[Player] start play : uid(%d)", uid);
723 /* Check sound queue size */
724 if (0 == ttsd_data_get_sound_data_size(uid)) {
725 SLOG(LOG_WARN, tts_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid);
731 current = __player_get_item(uid);
732 if (NULL == current) {
733 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
737 current->state = APP_STATE_PLAYING;
739 g_playing_info = current;
741 SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
743 if (0 < ttsd_data_get_sound_data_size(current->uid)) {
744 SLOG(LOG_DEBUG, tts_tag(), "[Player] Run thread");
745 ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
751 int ttsd_player_stop(int uid)
753 if (false == g_player_init) {
754 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
760 current = __player_get_item(uid);
761 if (NULL == current) {
762 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
766 /* check whether uid is current playing or not */
767 if (NULL != g_playing_info) {
768 if (uid == g_playing_info->uid) {
769 /* release current playing info */
770 g_playing_info = NULL;
773 SLOG(LOG_DEBUG, tts_tag(), "[Player] No current playing");
776 if (true == current->is_paused_data) {
777 if (NULL != current->paused_data) {
778 if (NULL != current->paused_data->data) {
779 free(current->paused_data->data);
780 current->paused_data->data = NULL;
783 free(current->paused_data);
784 current->paused_data = NULL;
788 current->event = TTSE_RESULT_EVENT_FINISH;
789 current->state = APP_STATE_READY;
790 current->is_paused_data = false;
793 if (NULL == g_playing_info) {
794 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
795 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
796 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
798 /* The thread should be released */
799 int thread_count = ecore_thread_active_get();
801 while (0 < thread_count) {
806 SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
810 thread_count = ecore_thread_active_get();
813 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
814 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
815 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
818 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Stop player : uid(%d)", uid);
823 int ttsd_player_clear(int uid)
825 if (false == g_player_init) {
826 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
832 current = __player_get_item(uid);
833 if (NULL == current) {
834 SECURE_SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
838 if (true == current->is_paused_data) {
839 if (NULL != current->paused_data) {
840 if (NULL != current->paused_data->data) {
841 free(current->paused_data->data);
842 current->paused_data->data = NULL;
845 free(current->paused_data);
846 current->paused_data = NULL;
850 current->event = TTSE_RESULT_EVENT_FINISH;
851 current->state = APP_STATE_READY;
852 current->is_paused_data = false;
855 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Clear player : uid(%d)", uid);
860 int ttsd_player_pause(int uid)
862 SLOG(LOG_DEBUG, tts_tag(), "[Player] pause player : uid(%d)", uid);
864 if (false == g_player_init) {
865 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
871 current = __player_get_item(uid);
872 if (NULL == current) {
873 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] ttsd_player_pause() : uid(%d) is not valid", uid);
877 /* check whether uid is current playing or not */
878 if (NULL != g_playing_info) {
879 if (uid == g_playing_info->uid) {
880 /* release current playing info */
881 g_playing_info = NULL;
887 current->state = APP_STATE_PAUSED;
889 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
890 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
891 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
893 /* The thread should be released */
894 int thread_count = ecore_thread_active_get();
896 while (0 < thread_count) {
901 SLOG(LOG_WARN, tts_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
905 thread_count = ecore_thread_active_get();
908 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
909 SLOG(LOG_ERROR, tts_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
910 SLOG(LOG_DEBUG, tts_tag(), "[Player] ==========================");
912 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Pause player : uid(%d)", uid);
917 int ttsd_player_resume(int uid)
919 SLOG(LOG_DEBUG, tts_tag(), "[Player] Resume player : uid(%d)", uid);
921 if (false == g_player_init) {
922 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
928 current = __player_get_item(uid);
929 if (NULL == current) {
930 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] uid(%d) is not valid", uid);
934 /* check current player */
935 if (NULL != g_playing_info)
936 g_playing_info = NULL;
938 current->state = APP_STATE_PLAYING;
939 g_playing_info = current;
941 SLOG(LOG_DEBUG, tts_tag(), "[Player] Run thread");
942 ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
947 int ttsd_player_all_stop()
949 if (false == g_player_init) {
950 SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Not Initialized");
954 g_playing_info = NULL;
957 player_s *data = NULL;
959 if (0 < g_list_length(g_player_list)) {
960 /* Get a first item */
961 iter = g_list_first(g_player_list);
963 while (NULL != iter) {
964 /* Get handle data from list */
965 data = (player_s*)iter->data;
968 if (0 > ttsd_data_get_client_state(data->uid, &state)) {
969 SLOG(LOG_ERROR, tts_tag(), "[player ERROR] uid(%d) is not valid", data->uid);
970 ttsd_player_destroy_instance(data->uid);
971 iter = g_list_next(iter);
975 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
976 data->event = TTSE_RESULT_EVENT_FINISH;
977 data->state = APP_STATE_READY;
979 if (true == data->is_paused_data) {
980 if (NULL != data->paused_data) {
981 if (NULL != data->paused_data->data) {
982 free(data->paused_data->data);
983 data->paused_data->data = NULL;
986 free(data->paused_data);
987 data->paused_data = NULL;
991 data->is_paused_data = false;
996 iter = g_list_next(iter);
1000 SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] player all stop!!");