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 ttsp_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 ttsp_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, get_tag(), "===== Focus state changed cb");
101 if (stream_info != g_stream_info_h) {
102 SLOG(LOG_ERROR, get_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, get_tag(), "[Player ERROR] Fail to get focus state");
114 SLOG(LOG_WARN, get_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, get_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, get_tag(), "[Player] Ignore focus state cb - mode(%d)", ttsd_get_mode());
140 SLOG(LOG_DEBUG, get_tag(), "=====");
141 SLOG(LOG_DEBUG, get_tag(), "");
146 static int __create_audio_out(ttsp_audio_type_e type, int rate)
149 audio_sample_type_e sample_type;
151 if (TTSP_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, get_tag(), "[Player ERROR] Fail to create audio");
164 SLOG(LOG_DEBUG, get_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, get_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, get_tag(), "[Player ERROR] Fail to destroy audio");
188 SLOG(LOG_DEBUG, get_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, get_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, get_tag(), "[Player WARNING] Fail to acquire focus");
214 ret = audio_out_set_stream_info(g_audio_h, g_stream_info_h);
215 if (AUDIO_IO_ERROR_NONE != ret) {
216 SLOG(LOG_WARN, get_tag(), "[Player WARNING] Fail to set stream info");
220 /* Set volume policy */
222 SLOG(LOG_WARN, get_tag(), "[Player WARNING] set volume policy");
223 ret = sound_manager_set_volume_voice_policy(volume);
224 if (SOUND_MANAGER_ERROR_NONE != ret) {
225 SLOG(LOG_WARN, get_tag(), "[Player WARNING] Fail to set volume policy");
231 static void __unset_policy_for_playing()
234 /* Unset volume policy */
236 SLOG(LOG_WARN, get_tag(), "[Player WARNING] unset volume policy");
237 ret = sound_manager_unset_volume_voice_policy();
238 if (SOUND_MANAGER_ERROR_NONE != ret) {
239 SLOG(LOG_WARN, get_tag(), "[Player WARNING] Fail to unset volume policy");
242 /* Unset stream info */
243 if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
244 ret = sound_manager_release_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_PLAYBACK, NULL);
245 if (SOUND_MANAGER_ERROR_NONE != ret) {
246 SLOG(LOG_WARN, get_tag(), "[Player WARNING] Fail to release focus");
253 static void __play_thread(void *data, Ecore_Thread *thread)
255 SLOG(LOG_DEBUG, get_tag(), "===== Start thread");
257 if (NULL == g_playing_info) {
258 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] No current player");
262 player_s* player = g_playing_info;
263 sound_data_s* sound_data = NULL;
266 int len = SOUND_BUFFER_LENGTH;
269 /* set volume policy as 40% */
270 __set_policy_for_playing(40);
272 if (true == player->is_paused_data) {
274 sound_data = player->paused_data;
275 player->paused_data = NULL;
279 player->is_paused_data = false;
282 if (NULL == sound_data) {
283 /* Request unprepare */
284 ret = audio_out_unprepare(g_audio_h);
285 if (AUDIO_IO_ERROR_NONE != ret) {
286 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
288 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Unprepare audio");
291 g_audio_state = AUDIO_STATE_READY;
293 /* unset volume policy, volume will be 100% */
294 __unset_policy_for_playing();
297 SLOG(LOG_INFO, get_tag(), "[Player] Sound info : id(%d) data(%p) size(%d) audiotype(%d) rate(%d) event(%d)",
298 sound_data->utt_id, sound_data->data, sound_data->data_size, sound_data->audio_type, sound_data->rate, sound_data->event);
301 ret = ttsd_data_get_sound_data(player->uid, &sound_data);
302 if (0 != ret || NULL == sound_data) {
304 SLOG(LOG_DEBUG, get_tag(), "[Player] No sound data. Waiting mode");
305 /* release audio & recover session */
306 ret = audio_out_unprepare(g_audio_h);
307 if (AUDIO_IO_ERROR_NONE != ret) {
308 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
310 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Unprepare audio");
312 g_audio_state = AUDIO_STATE_READY;
314 /* unset volume policy, volume will be 100% */
315 __unset_policy_for_playing();
317 /* wait for new audio data come */
320 if (NULL == g_playing_info) {
321 /* current playing uid is replaced */
322 SLOG(LOG_DEBUG, get_tag(), "[Player] Finish thread");
324 } else if (0 < ttsd_data_get_sound_data_size(player->uid)) {
325 /* new audio data come */
326 SLOG(LOG_DEBUG, get_tag(), "[Player] Resume thread");
331 /* set volume policy as 40%, when resume play thread*/
332 __set_policy_for_playing(40);
334 /* resume play thread */
335 player->state = APP_STATE_PLAYING;
339 /* If wdata's event is 'start', current wdata is first data of engine for synthesis.
340 * If wdata's event is 'finish', player should check previous event to know whether this wdata is first or not.
341 * When previous wdata's event is 'finish' and current wdata's event is 'finish',
342 * the player should send utt started event.
344 if (TTSP_RESULT_EVENT_START == sound_data->event ||
345 (TTSP_RESULT_EVENT_FINISH == player->event && TTSP_RESULT_EVENT_FINISH == sound_data->event)) {
346 int pid = ttsd_data_get_pid(player->uid);
349 SLOG(LOG_WARN, get_tag(), "[Send WARNIING] Current player is not valid");
350 /* unset volume policy, volume will be 100% */
351 __unset_policy_for_playing();
355 if (0 != ttsdc_send_utt_start_message(pid, player->uid, sound_data->utt_id)) {
356 SLOG(LOG_ERROR, get_tag(), "[Send ERROR] Fail to send Utterance Start Signal : pid(%d), uid(%d), uttid(%d)",
357 pid, player->uid, sound_data->utt_id);
359 SLOG(LOG_DEBUG, get_tag(), "[Player] Start utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
362 /* Save last event to check utterance start */
363 player->event = sound_data->event;
366 if (NULL == sound_data->data || 0 >= sound_data->data_size) {
367 if (TTSP_RESULT_EVENT_FINISH == sound_data->event) {
368 SLOG(LOG_DEBUG, get_tag(), "No sound data");
369 /* send utterence finish signal */
370 int pid = ttsd_data_get_pid(player->uid);
373 SLOG(LOG_WARN, get_tag(), "[Send WARNIING] Current player is not valid");
374 /* unset volume policy, volume will be 100% */
375 __unset_policy_for_playing();
378 if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
379 SLOG(LOG_ERROR, get_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)",
380 pid, player->uid, sound_data->utt_id);
383 SLOG(LOG_DEBUG, get_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
388 if (g_sampling_rate != sound_data->rate || g_audio_type != sound_data->audio_type) {
389 SLOG(LOG_DEBUG, get_tag(), "[Player] Change audio handle : org type(%d) org rate(%d)", g_audio_type, g_sampling_rate);
390 if (NULL != g_audio_h) {
391 __destroy_audio_out();
394 if (0 > __create_audio_out(sound_data->audio_type, sound_data->rate)) {
395 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to create audio out");
396 /* unset volume policy, volume will be 100% */
397 __unset_policy_for_playing();
402 while (APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) {
403 if ((unsigned int)idx >= sound_data->data_size)
406 if ((unsigned int)idx + SOUND_BUFFER_LENGTH > sound_data->data_size) {
407 len = sound_data->data_size - idx;
409 len = SOUND_BUFFER_LENGTH;
412 if (AUDIO_STATE_READY == g_audio_state) {
413 /* Request prepare */
414 ret = audio_out_prepare(g_audio_h);
415 if (AUDIO_IO_ERROR_NONE != ret) {
416 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to prepare audio : %d", ret);
417 g_playing_info = NULL;
418 /* unset volume policy, volume will be 100% */
419 __unset_policy_for_playing();
422 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Prepare audio");
423 g_audio_state = AUDIO_STATE_PLAY;
426 char* temp_data = sound_data->data;
427 ret = audio_out_write(g_audio_h, &temp_data[idx], len);
429 SLOG(LOG_WARN, get_tag(), "[Player WARNING] Fail to audio write - %d", ret);
434 if (NULL == g_playing_info && APP_STATE_PAUSED != player->state) {
435 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Current player is NULL");
436 g_audio_state = AUDIO_STATE_READY;
437 ret = audio_out_unprepare(g_audio_h);
438 if (AUDIO_IO_ERROR_NONE != ret) {
439 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
441 /* unset volume policy, volume will be 100% */
442 __unset_policy_for_playing();
444 if (NULL != sound_data) {
445 if (NULL != sound_data->data) {
446 free(sound_data->data);
447 sound_data->data = NULL;
457 if (APP_STATE_PAUSED == player->state) {
459 player->paused_data = sound_data;
461 player->is_paused_data = true;
464 g_audio_state = AUDIO_STATE_READY;
465 SLOG(LOG_DEBUG, get_tag(), "[Player] Stop player thread by pause");
467 /* Request prepare */
468 ret = audio_out_unprepare(g_audio_h);
469 if (AUDIO_IO_ERROR_NONE != ret) {
470 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
472 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Unprepare audio");
474 /* unset volume policy, volume will be 100% */
475 __unset_policy_for_playing();
480 if (NULL == g_playing_info && APP_STATE_READY == player->state) {
482 g_audio_state = AUDIO_STATE_READY;
483 SLOG(LOG_DEBUG, get_tag(), "[Player] Stop player thread");
485 /* Request prepare */
486 ret = audio_out_unprepare(g_audio_h);
487 if (AUDIO_IO_ERROR_NONE != ret) {
488 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
490 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Unprepare audio");
493 if (NULL != sound_data) {
494 if (NULL != sound_data->data) {
495 free(sound_data->data);
496 sound_data->data = NULL;
502 /* unset volume policy, volume will be 100% */
503 __unset_policy_for_playing();
507 if ((APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) &&
508 (TTSP_RESULT_EVENT_FINISH == sound_data->event)) {
509 /* send utterence finish signal */
510 int pid = ttsd_data_get_pid(player->uid);
513 SLOG(LOG_WARN, get_tag(), "[Send WARNIING] Current player is not valid");
514 /* unset volume policy, volume will be 100% */
515 __unset_policy_for_playing();
519 if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
520 SLOG(LOG_ERROR, get_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)",
521 pid, player->uid, sound_data->utt_id);
522 /* unset volume policy, volume will be 100% */
523 __unset_policy_for_playing();
527 SLOG(LOG_DEBUG, get_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
530 if (NULL != sound_data) {
531 if (NULL != sound_data->data) {
532 free(sound_data->data);
533 sound_data->data = NULL;
540 if (NULL == g_playing_info) {
541 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Current player is NULL");
542 g_audio_state = AUDIO_STATE_READY;
543 ret = audio_out_unprepare(g_audio_h);
544 if (AUDIO_IO_ERROR_NONE != ret) {
545 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
547 /* unset volume policy, volume will be 100% */
548 __unset_policy_for_playing();
558 int ttsd_player_init()
560 g_playing_info = NULL;
561 g_audio_state = AUDIO_STATE_NONE;
566 ecore_thread_max_set(1);
568 ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_INFORMATION, __player_focus_state_cb, NULL, &g_stream_info_h);
569 if (SOUND_MANAGER_ERROR_NONE != ret) {
570 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to create stream info");
573 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Create stream info");
576 ret = __create_audio_out(TTSP_AUDIO_TYPE_RAW_S16, 16000);
580 g_player_init = true;
585 int ttsd_player_release(void)
587 if (false == g_player_init) {
588 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
589 return TTSD_ERROR_OPERATION_FAILED;
594 SLOG(LOG_DEBUG, get_tag(), "[Player DEBUG] ==========================");
595 SLOG(LOG_DEBUG, get_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
596 SLOG(LOG_DEBUG, get_tag(), "[Player DEBUG] ==========================");
598 /* The thread should be released */
599 int thread_count = ecore_thread_active_get();
601 while (0 < thread_count) {
606 SLOG(LOG_WARN, get_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
610 thread_count = ecore_thread_active_get();
613 SLOG(LOG_DEBUG, get_tag(), "[Player DEBUG] Thread is released");
615 ret = __destroy_audio_out();
619 ret = sound_manager_destroy_stream_information(g_stream_info_h);
620 if (SOUND_MANAGER_ERROR_NONE != ret) {
621 SLOG(LOG_WARN, get_tag(), "[Player WARNING] Fail to destroy stream info");
623 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Destroy stream info");
626 /* clear g_player_list */
627 g_playing_info = NULL;
628 g_player_init = false;
633 int ttsd_player_create_instance(int uid)
635 if (false == g_player_init) {
636 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
640 /* Check uid is duplicated */
641 if (NULL != __player_get_item(uid)) {
642 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is already registered", uid);
646 player_s* new_client = (player_s*)calloc(1, sizeof(player_s));
647 if (NULL == new_client) {
648 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to allocate memory");
649 return TTSP_ERROR_OUT_OF_MEMORY;
652 new_client->uid = uid;
653 new_client->event = TTSP_RESULT_EVENT_FINISH;
654 new_client->state = APP_STATE_READY;
655 new_client->is_paused_data = false;
657 new_client->paused_data = NULL;
659 SECURE_SLOG(LOG_DEBUG, get_tag(), "[Player] Create player : uid(%d)", uid);
661 g_player_list = g_list_append(g_player_list, new_client);
666 int ttsd_player_destroy_instance(int uid)
668 if (false == g_player_init) {
669 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
674 current = __player_get_item(uid);
675 if (NULL == current) {
676 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid);
680 if (NULL != g_playing_info) {
681 if (uid == g_playing_info->uid) {
682 g_playing_info = NULL;
687 player_s *data = NULL;
689 if (0 < g_list_length(g_player_list)) {
690 /* Get a first item */
691 iter = g_list_first(g_player_list);
693 while (NULL != iter) {
694 /* Get handle data from list */
695 data = (player_s*)iter->data;
699 if (uid == data->uid) {
700 g_player_list = g_list_remove_link(g_player_list, iter);
708 iter = g_list_next(iter);
712 SLOG(LOG_DEBUG, get_tag(), "[PLAYER Success] Destroy instance");
717 int ttsd_player_play(int uid)
719 if (false == g_player_init) {
720 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
724 if (NULL != g_playing_info) {
725 if (uid == g_playing_info->uid) {
726 SLOG(LOG_DEBUG, get_tag(), "[Player] uid(%d) has already played", g_playing_info->uid);
729 SLOG(LOG_WARN, get_tag(), "[Player WARNING] stop old player (%d)", g_playing_info->uid);
730 ttsd_player_stop(g_playing_info->uid);
734 SLOG(LOG_DEBUG, get_tag(), "[Player] start play : uid(%d)", uid);
736 /* Check sound queue size */
737 if (0 == ttsd_data_get_sound_data_size(uid)) {
738 SLOG(LOG_WARN, get_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid);
744 current = __player_get_item(uid);
745 if (NULL == current) {
746 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid);
750 current->state = APP_STATE_PLAYING;
752 g_playing_info = current;
754 SLOG(LOG_DEBUG, get_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
756 if (0 < ttsd_data_get_sound_data_size(current->uid)) {
757 SLOG(LOG_DEBUG, get_tag(), "[Player] Run thread");
758 ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
764 int ttsd_player_stop(int uid)
766 if (false == g_player_init) {
767 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
773 current = __player_get_item(uid);
774 if (NULL == current) {
775 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid);
779 /* check whether uid is current playing or not */
780 if (NULL != g_playing_info) {
781 if (uid == g_playing_info->uid) {
782 /* release current playing info */
783 g_playing_info = NULL;
786 SLOG(LOG_DEBUG, get_tag(), "[Player] No current playing");
789 if (true == current->is_paused_data) {
790 if (NULL != current->paused_data) {
791 if (NULL != current->paused_data->data) {
792 free(current->paused_data->data);
793 current->paused_data->data = NULL;
796 free(current->paused_data);
797 current->paused_data = NULL;
801 current->event = TTSP_RESULT_EVENT_FINISH;
802 current->state = APP_STATE_READY;
803 current->is_paused_data = false;
806 if (NULL == g_playing_info) {
807 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
808 SLOG(LOG_ERROR, get_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
809 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
811 /* The thread should be released */
812 int thread_count = ecore_thread_active_get();
814 while (0 < thread_count) {
819 SLOG(LOG_WARN, get_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
823 thread_count = ecore_thread_active_get();
826 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
827 SLOG(LOG_ERROR, get_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
828 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
831 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Stop player : uid(%d)", uid);
836 int ttsd_player_clear(int uid)
838 if (false == g_player_init) {
839 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
845 current = __player_get_item(uid);
846 if (NULL == current) {
847 SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid);
851 if (true == current->is_paused_data) {
852 if (NULL != current->paused_data) {
853 if (NULL != current->paused_data->data) {
854 free(current->paused_data->data);
855 current->paused_data->data = NULL;
858 free(current->paused_data);
859 current->paused_data = NULL;
863 current->event = TTSP_RESULT_EVENT_FINISH;
864 current->state = APP_STATE_READY;
865 current->is_paused_data = false;
868 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Clear player : uid(%d)", uid);
873 int ttsd_player_pause(int uid)
875 SLOG(LOG_DEBUG, get_tag(), "[Player] pause player : uid(%d)", uid);
877 if (false == g_player_init) {
878 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
884 current = __player_get_item(uid);
885 if (NULL == current) {
886 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] ttsd_player_pause() : uid(%d) is not valid", uid);
890 /* check whether uid is current playing or not */
891 if (NULL != g_playing_info) {
892 if (uid == g_playing_info->uid) {
893 /* release current playing info */
894 g_playing_info = NULL;
900 current->state = APP_STATE_PAUSED;
902 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
903 SLOG(LOG_ERROR, get_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
904 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
906 /* The thread should be released */
907 int thread_count = ecore_thread_active_get();
909 while (0 < thread_count) {
914 SLOG(LOG_WARN, get_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
918 thread_count = ecore_thread_active_get();
921 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
922 SLOG(LOG_ERROR, get_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
923 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
925 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Pause player : uid(%d)", uid);
930 int ttsd_player_resume(int uid)
932 SLOG(LOG_DEBUG, get_tag(), "[Player] Resume player : uid(%d)", uid);
934 if (false == g_player_init) {
935 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
941 current = __player_get_item(uid);
942 if (NULL == current) {
943 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid);
947 /* check current player */
948 if (NULL != g_playing_info)
949 g_playing_info = NULL;
951 current->state = APP_STATE_PLAYING;
952 g_playing_info = current;
954 SLOG(LOG_DEBUG, get_tag(), "[Player] Run thread");
955 ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
960 int ttsd_player_all_stop()
962 if (false == g_player_init) {
963 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
967 g_playing_info = NULL;
970 player_s *data = NULL;
972 if (0 < g_list_length(g_player_list)) {
973 /* Get a first item */
974 iter = g_list_first(g_player_list);
976 while (NULL != iter) {
977 /* Get handle data from list */
978 data = (player_s*)iter->data;
981 if (0 > ttsd_data_get_client_state(data->uid, &state)) {
982 SLOG(LOG_ERROR, get_tag(), "[player ERROR] uid(%d) is not valid", data->uid);
983 ttsd_player_destroy_instance(data->uid);
984 iter = g_list_next(iter);
988 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
989 data->event = TTSP_RESULT_EVENT_FINISH;
990 data->state = APP_STATE_READY;
992 if (true == data->is_paused_data) {
993 if (NULL != data->paused_data) {
994 if (NULL != data->paused_data->data) {
995 free(data->paused_data->data);
996 data->paused_data->data = NULL;
999 free(data->paused_data);
1000 data->paused_data = NULL;
1004 data->is_paused_data = false;
1009 iter = g_list_next(iter);
1013 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] player all stop!!");