2 * Copyright (c) 2011-2014 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;
70 player_s* __player_get_item(int uid)
73 player_s *data = NULL;
75 if (0 < g_list_length(g_player_list)) {
76 /* Get a first item */
77 iter = g_list_first(g_player_list);
79 while (NULL != iter) {
80 /* Get handle data from list */
81 data = (player_s*)iter->data;
88 iter = g_list_next(iter);
95 void __player_audio_io_interrupted_cb(audio_io_interrupted_code_e code, void *user_data)
97 SLOG(LOG_DEBUG, get_tag(), "===== INTERRUPTED CALLBACK");
99 SLOG(LOG_WARN, get_tag(), "[Player] code : %d", (int)code);
101 g_audio_state = AUDIO_STATE_READY;
103 if (NULL == g_playing_info) {
104 SLOG(LOG_WARN, get_tag(), "[Player WARNING] No current player");
108 if (APP_STATE_PLAYING == g_playing_info->state) {
109 g_playing_info->state = APP_STATE_PAUSED;
111 ttsd_data_set_client_state(g_playing_info->uid, APP_STATE_PAUSED);
113 int pid = ttsd_data_get_pid(g_playing_info->uid);
115 /* send message to client about changing state */
116 ttsdc_send_set_state_message(pid, g_playing_info->uid, APP_STATE_PAUSED);
119 SLOG(LOG_DEBUG, get_tag(), "=====");
120 SLOG(LOG_DEBUG, get_tag(), " ");
125 static int __create_audio_out(ttsp_audio_type_e type, int rate)
128 audio_sample_type_e sample_type;
130 if (TTSP_AUDIO_TYPE_RAW_S16 == type) {
131 sample_type = AUDIO_SAMPLE_TYPE_S16_LE;
133 sample_type = AUDIO_SAMPLE_TYPE_U8;
136 ret = audio_out_create(rate, AUDIO_CHANNEL_MONO, sample_type, SOUND_TYPE_VOICE, &g_audio_h);
137 if (AUDIO_IO_ERROR_NONE != ret) {
138 g_audio_state = AUDIO_STATE_NONE;
140 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to create audio");
143 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Create audio");
146 if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
147 ret = audio_out_ignore_session(g_audio_h);
148 if (AUDIO_IO_ERROR_NONE != ret) {
149 g_audio_state = AUDIO_STATE_NONE;
151 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to set ignore session");
156 ret = audio_out_set_interrupted_cb(g_audio_h, __player_audio_io_interrupted_cb, NULL);
157 if (AUDIO_IO_ERROR_NONE != ret) {
158 g_audio_state = AUDIO_STATE_NONE;
160 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to set callback function");
165 g_sampling_rate = rate;
167 g_audio_state = AUDIO_STATE_READY;
172 static int __destroy_audio_out()
174 if (NULL == g_audio_h) {
175 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Current handle is not valid");
180 ret = audio_out_destroy(g_audio_h);
181 if (AUDIO_IO_ERROR_NONE != ret) {
182 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to destroy audio");
185 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Destroy audio");
191 g_audio_state = AUDIO_STATE_NONE;
197 static void __end_play_thread(void *data, Ecore_Thread *thread)
199 SLOG(LOG_ERROR, get_tag(), "===== End thread");
202 static void __set_volume_using_voice_policy(int volume)
205 SLOG(LOG_WARN, get_tag(), "[Player WARNING] set volume policy");
206 int ret = sound_manager_set_volume_voice_policy(volume);
207 if (SOUND_MANAGER_ERROR_NONE != ret) {
208 SLOG(LOG_WARN, get_tag(), "[Player WARNING] Fail to set volume policy");
214 static void __unset_volume_using_voice_policy()
217 SLOG(LOG_WARN, get_tag(), "[Player WARNING] unset volume policy");
218 int ret = sound_manager_unset_volume_voice_policy();
219 if (SOUND_MANAGER_ERROR_NONE != ret) {
220 SLOG(LOG_WARN, get_tag(), "[Player WARNING] Fail to unset volume policy");
226 static void __play_thread(void *data, Ecore_Thread *thread)
228 SLOG(LOG_DEBUG, get_tag(), "===== Start thread");
230 if (NULL == g_playing_info) {
231 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] No current player");
235 player_s* player = g_playing_info;
236 sound_data_s* sound_data = NULL;
239 int len = SOUND_BUFFER_LENGTH;
242 /* set volume policy as 40% */
243 __set_volume_using_voice_policy(40);
245 if (true == player->is_paused_data) {
247 sound_data = player->paused_data;
248 player->paused_data = NULL;
252 player->is_paused_data = false;
255 if (NULL == sound_data) {
256 /* Request unprepare */
257 ret = audio_out_unprepare(g_audio_h);
258 if (AUDIO_IO_ERROR_NONE != ret) {
259 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
261 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Unprepare audio");
264 g_audio_state = AUDIO_STATE_READY;
266 /* unset volume policy, volume will be 100% */
267 __unset_volume_using_voice_policy();
270 SLOG(LOG_INFO, get_tag(), "[Player] Sound info : id(%d) data(%p) size(%d) audiotype(%d) rate(%d) event(%d)",
271 sound_data->utt_id, sound_data->data, sound_data->data_size, sound_data->audio_type, sound_data->rate, sound_data->event);
274 ret = ttsd_data_get_sound_data(player->uid, &sound_data);
275 if (0 != ret || NULL == sound_data) {
277 SLOG(LOG_DEBUG, get_tag(), "[Player] No sound data. Waiting mode");
278 /* release audio & recover session */
279 ret = audio_out_unprepare(g_audio_h);
280 if (AUDIO_IO_ERROR_NONE != ret) {
281 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
283 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Unprepare audio");
285 g_audio_state = AUDIO_STATE_READY;
287 /* unset volume policy, volume will be 100% */
288 __unset_volume_using_voice_policy();
290 /* wait for new audio data come */
293 if (NULL == g_playing_info) {
294 /* current playing uid is replaced */
295 SLOG(LOG_DEBUG, get_tag(), "[Player] Finish thread");
297 } else if (0 < ttsd_data_get_sound_data_size(player->uid)) {
298 /* new audio data come */
299 SLOG(LOG_DEBUG, get_tag(), "[Player] Resume thread");
304 /* set volume policy as 40%, when resume play thread*/
305 __set_volume_using_voice_policy(40);
307 /* resume play thread */
308 player->state = APP_STATE_PLAYING;
312 /* If wdata's event is 'start', current wdata is first data of engine for synthesis.
313 * If wdata's event is 'finish', player should check previous event to know whether this wdata is first or not.
314 * When previous wdata's event is 'finish' and current wdata's event is 'finish',
315 * the player should send utt started event.
317 if (TTSP_RESULT_EVENT_START == sound_data->event ||
318 (TTSP_RESULT_EVENT_FINISH == player->event && TTSP_RESULT_EVENT_FINISH == sound_data->event)) {
319 int pid = ttsd_data_get_pid(player->uid);
322 SLOG(LOG_WARN, get_tag(), "[Send WARNIING] Current player is not valid");
323 /* unset volume policy, volume will be 100% */
324 __unset_volume_using_voice_policy();
328 if (0 != ttsdc_send_utt_start_message(pid, player->uid, sound_data->utt_id)) {
329 SLOG(LOG_ERROR, get_tag(), "[Send ERROR] Fail to send Utterance Start Signal : pid(%d), uid(%d), uttid(%d)",
330 pid, player->uid, sound_data->utt_id);
332 SLOG(LOG_DEBUG, get_tag(), "[Player] Start utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
335 /* Save last event to check utterance start */
336 player->event = sound_data->event;
339 if (NULL == sound_data->data || 0 >= sound_data->data_size) {
340 if (TTSP_RESULT_EVENT_FINISH == sound_data->event) {
341 SLOG(LOG_DEBUG, get_tag(), "No sound data");
342 /* send utterence finish signal */
343 int pid = ttsd_data_get_pid(player->uid);
346 SLOG(LOG_WARN, get_tag(), "[Send WARNIING] Current player is not valid");
347 /* unset volume policy, volume will be 100% */
348 __unset_volume_using_voice_policy();
351 if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
352 SLOG(LOG_ERROR, get_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)",
353 pid, player->uid, sound_data->utt_id);
356 SLOG(LOG_DEBUG, get_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
361 if (g_sampling_rate != sound_data->rate || g_audio_type != sound_data->audio_type) {
362 SLOG(LOG_DEBUG, get_tag(), "[Player] Change audio handle : org type(%d) org rate(%d)", g_audio_type, g_sampling_rate);
363 if (NULL != g_audio_h) {
364 __destroy_audio_out();
367 if (0 > __create_audio_out(sound_data->audio_type, sound_data->rate)) {
368 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to create audio out");
369 /* unset volume policy, volume will be 100% */
370 __unset_volume_using_voice_policy();
375 while (APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) {
376 if ((unsigned int)idx >= sound_data->data_size)
379 if ((unsigned int)idx + SOUND_BUFFER_LENGTH > sound_data->data_size) {
380 len = sound_data->data_size - idx;
382 len = SOUND_BUFFER_LENGTH;
385 if (AUDIO_STATE_READY == g_audio_state) {
386 /* Request prepare */
387 ret = audio_out_prepare(g_audio_h);
388 if (AUDIO_IO_ERROR_NONE != ret) {
389 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to prepare audio : %d", ret);
390 g_playing_info = NULL;
391 /* unset volume policy, volume will be 100% */
392 __unset_volume_using_voice_policy();
395 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Prepare audio");
396 g_audio_state = AUDIO_STATE_PLAY;
399 char* temp_data = sound_data->data;
400 ret = audio_out_write(g_audio_h, &temp_data[idx], len);
402 SLOG(LOG_WARN, get_tag(), "[Player WARNING] Fail to audio write - %d", ret);
407 if (NULL == g_playing_info && APP_STATE_PAUSED != player->state) {
408 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Current player is NULL");
409 g_audio_state = AUDIO_STATE_READY;
410 ret = audio_out_unprepare(g_audio_h);
411 if (AUDIO_IO_ERROR_NONE != ret) {
412 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
414 /* unset volume policy, volume will be 100% */
415 __unset_volume_using_voice_policy();
417 if (NULL != sound_data) {
418 if (NULL != sound_data->data) {
419 free(sound_data->data);
420 sound_data->data = NULL;
430 if (APP_STATE_PAUSED == player->state) {
432 player->paused_data = sound_data;
434 player->is_paused_data = true;
437 g_audio_state = AUDIO_STATE_READY;
438 SLOG(LOG_DEBUG, get_tag(), "[Player] Stop player thread by pause");
440 /* Request prepare */
441 ret = audio_out_unprepare(g_audio_h);
442 if (AUDIO_IO_ERROR_NONE != ret) {
443 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
445 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Unprepare audio");
447 /* unset volume policy, volume will be 100% */
448 __unset_volume_using_voice_policy();
453 if (NULL == g_playing_info && APP_STATE_READY == player->state) {
455 g_audio_state = AUDIO_STATE_READY;
456 SLOG(LOG_DEBUG, get_tag(), "[Player] Stop player thread");
458 /* Request prepare */
459 ret = audio_out_unprepare(g_audio_h);
460 if (AUDIO_IO_ERROR_NONE != ret) {
461 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
463 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Unprepare audio");
466 if (NULL != sound_data) {
467 if (NULL != sound_data->data) {
468 free(sound_data->data);
469 sound_data->data = NULL;
475 /* unset volume policy, volume will be 100% */
476 __unset_volume_using_voice_policy();
480 if ((APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) &&
481 (TTSP_RESULT_EVENT_FINISH == sound_data->event)) {
482 /* send utterence finish signal */
483 int pid = ttsd_data_get_pid(player->uid);
486 SLOG(LOG_WARN, get_tag(), "[Send WARNIING] Current player is not valid");
487 /* unset volume policy, volume will be 100% */
488 __unset_volume_using_voice_policy();
492 if (0 != ttsdc_send_utt_finish_message(pid, player->uid, sound_data->utt_id)) {
493 SLOG(LOG_ERROR, get_tag(), "[Send ERROR] Fail to send Utterance Completed Signal : pid(%d), uid(%d), uttid(%d)",
494 pid, player->uid, sound_data->utt_id);
495 /* unset volume policy, volume will be 100% */
496 __unset_volume_using_voice_policy();
500 SLOG(LOG_DEBUG, get_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
503 if (NULL != sound_data) {
504 if (NULL != sound_data->data) {
505 free(sound_data->data);
506 sound_data->data = NULL;
513 if (NULL == g_playing_info) {
514 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Current player is NULL");
515 g_audio_state = AUDIO_STATE_READY;
516 ret = audio_out_unprepare(g_audio_h);
517 if (AUDIO_IO_ERROR_NONE != ret) {
518 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to unprepare audio : %d", ret);
520 /* unset volume policy, volume will be 100% */
521 __unset_volume_using_voice_policy();
531 int ttsd_player_init()
533 g_playing_info = NULL;
534 g_audio_state = AUDIO_STATE_NONE;
539 if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
540 ret = sound_manager_set_session_type(SOUND_SESSION_TYPE_MEDIA);
542 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to set session type");
545 ret = sound_manager_set_media_session_option(SOUND_SESSION_OPTION_PAUSE_OTHERS_WHEN_START, SOUND_SESSION_OPTION_INTERRUPTIBLE_DURING_PLAY);
547 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail set media session option");
549 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] set media session option");
553 ecore_thread_max_set(1);
555 ret = __create_audio_out(TTSP_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, get_tag(), "[Player ERROR] Not Initialized");
568 return TTSD_ERROR_OPERATION_FAILED;
573 SLOG(LOG_DEBUG, get_tag(), "[Player DEBUG] ==========================");
574 SLOG(LOG_DEBUG, get_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
575 SLOG(LOG_DEBUG, get_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, get_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
589 thread_count = ecore_thread_active_get();
592 SLOG(LOG_DEBUG, get_tag(), "[Player DEBUG] Thread is released");
594 ret = __destroy_audio_out();
598 /* clear g_player_list */
599 g_playing_info = NULL;
600 g_player_init = false;
605 int ttsd_player_create_instance(int uid)
607 if (false == g_player_init) {
608 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
612 /* Check uid is duplicated */
613 if (NULL != __player_get_item(uid)) {
614 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is already registered", uid);
618 player_s* new_client = (player_s*)calloc(1, sizeof(player_s));
619 if (NULL == new_client) {
620 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Fail to allocate memory");
621 return TTSP_ERROR_OUT_OF_MEMORY;
624 new_client->uid = uid;
625 new_client->event = TTSP_RESULT_EVENT_FINISH;
626 new_client->state = APP_STATE_READY;
627 new_client->is_paused_data = false;
629 new_client->paused_data = NULL;
631 SECURE_SLOG(LOG_DEBUG, get_tag(), "[Player] Create player : uid(%d)", uid);
633 g_player_list = g_list_append(g_player_list, new_client);
638 int ttsd_player_destroy_instance(int uid)
640 if (false == g_player_init) {
641 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
646 current = __player_get_item(uid);
647 if (NULL == current) {
648 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid);
652 if (NULL != g_playing_info) {
653 if (uid == g_playing_info->uid) {
654 g_playing_info = NULL;
659 player_s *data = NULL;
661 if (0 < g_list_length(g_player_list)) {
662 /* Get a first item */
663 iter = g_list_first(g_player_list);
665 while (NULL != iter) {
666 /* Get handle data from list */
667 data = (player_s*)iter->data;
671 if (uid == data->uid) {
672 g_player_list = g_list_remove_link(g_player_list, iter);
680 iter = g_list_next(iter);
684 SLOG(LOG_DEBUG, get_tag(), "[PLAYER Success] Destroy instance");
689 int ttsd_player_play(int uid)
691 if (false == g_player_init) {
692 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
696 if (NULL != g_playing_info) {
697 if (uid == g_playing_info->uid) {
698 SLOG(LOG_DEBUG, get_tag(), "[Player] uid(%d) has already played", g_playing_info->uid);
701 SLOG(LOG_WARN, get_tag(), "[Player WARNING] stop old player (%d)", g_playing_info->uid);
702 ttsd_player_stop(g_playing_info->uid);
706 SLOG(LOG_DEBUG, get_tag(), "[Player] start play : uid(%d)", uid);
708 /* Check sound queue size */
709 if (0 == ttsd_data_get_sound_data_size(uid)) {
710 SLOG(LOG_WARN, get_tag(), "[Player WARNING] A sound queue of current player(%d) is empty", uid);
716 current = __player_get_item(uid);
717 if (NULL == current) {
718 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid);
722 current->state = APP_STATE_PLAYING;
724 g_playing_info = current;
726 SLOG(LOG_DEBUG, get_tag(), "[Player DEBUG] Active thread count : %d", ecore_thread_active_get());
728 if (0 < ttsd_data_get_sound_data_size(current->uid)) {
729 SLOG(LOG_DEBUG, get_tag(), "[Player] Run thread");
730 ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
736 int ttsd_player_stop(int uid)
738 if (false == g_player_init) {
739 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
745 current = __player_get_item(uid);
746 if (NULL == current) {
747 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid);
751 /* check whether uid is current playing or not */
752 if (NULL != g_playing_info) {
753 if (uid == g_playing_info->uid) {
754 /* release current playing info */
755 g_playing_info = NULL;
758 SLOG(LOG_DEBUG, get_tag(), "[Player] No current playing");
761 if (true == current->is_paused_data) {
762 if (NULL != current->paused_data) {
763 if (NULL != current->paused_data->data) {
764 free(current->paused_data->data);
765 current->paused_data->data = NULL;
768 free(current->paused_data);
769 current->paused_data = NULL;
773 current->event = TTSP_RESULT_EVENT_FINISH;
774 current->state = APP_STATE_READY;
775 current->is_paused_data = false;
778 if (NULL == g_playing_info) {
779 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
780 SLOG(LOG_ERROR, get_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
781 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
783 /* The thread should be released */
784 int thread_count = ecore_thread_active_get();
786 while (0 < thread_count) {
791 SLOG(LOG_WARN, get_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
795 thread_count = ecore_thread_active_get();
798 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
799 SLOG(LOG_ERROR, get_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
800 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
803 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Stop player : uid(%d)", uid);
808 int ttsd_player_clear(int uid)
810 if (false == g_player_init) {
811 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
817 current = __player_get_item(uid);
818 if (NULL == current) {
819 SECURE_SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid);
823 if (true == current->is_paused_data) {
824 if (NULL != current->paused_data) {
825 if (NULL != current->paused_data->data) {
826 free(current->paused_data->data);
827 current->paused_data->data = NULL;
830 free(current->paused_data);
831 current->paused_data = NULL;
835 current->event = TTSP_RESULT_EVENT_FINISH;
836 current->state = APP_STATE_READY;
837 current->is_paused_data = false;
840 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Clear player : uid(%d)", uid);
845 int ttsd_player_pause(int uid)
847 SLOG(LOG_DEBUG, get_tag(), "[Player] pause player : uid(%d)", uid);
849 if (false == g_player_init) {
850 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
856 current = __player_get_item(uid);
857 if (NULL == current) {
858 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] ttsd_player_pause() : uid(%d) is not valid", uid);
862 /* check whether uid is current playing or not */
863 if (NULL != g_playing_info) {
864 if (uid == g_playing_info->uid) {
865 /* release current playing info */
866 g_playing_info = NULL;
872 current->state = APP_STATE_PAUSED;
874 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
875 SLOG(LOG_ERROR, get_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
876 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
878 /* The thread should be released */
879 int thread_count = ecore_thread_active_get();
881 while (0 < thread_count) {
886 SLOG(LOG_WARN, get_tag(), "[Player WARNING!!] Thread is blocked. Player release continue.");
890 thread_count = ecore_thread_active_get();
893 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
894 SLOG(LOG_ERROR, get_tag(), "[Player] Active thread count : %d", ecore_thread_active_get());
895 SLOG(LOG_DEBUG, get_tag(), "[Player] ==========================");
897 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] Pause player : uid(%d)", uid);
902 int ttsd_player_resume(int uid)
904 SLOG(LOG_DEBUG, get_tag(), "[Player] Resume player : uid(%d)", uid);
906 if (false == g_player_init) {
907 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
913 current = __player_get_item(uid);
914 if (NULL == current) {
915 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] uid(%d) is not valid", uid);
919 /* check current player */
920 if (NULL != g_playing_info)
921 g_playing_info = NULL;
923 current->state = APP_STATE_PLAYING;
924 g_playing_info = current;
926 SLOG(LOG_DEBUG, get_tag(), "[Player] Run thread");
927 ecore_thread_run(__play_thread, __end_play_thread, NULL, NULL);
932 int ttsd_player_all_stop()
934 if (false == g_player_init) {
935 SLOG(LOG_ERROR, get_tag(), "[Player ERROR] Not Initialized");
939 g_playing_info = NULL;
942 player_s *data = NULL;
944 if (0 < g_list_length(g_player_list)) {
945 /* Get a first item */
946 iter = g_list_first(g_player_list);
948 while (NULL != iter) {
949 /* Get handle data from list */
950 data = (player_s*)iter->data;
953 if (0 > ttsd_data_get_client_state(data->uid, &state)) {
954 SLOG(LOG_ERROR, get_tag(), "[player ERROR] uid(%d) is not valid", data->uid);
955 ttsd_player_destroy_instance(data->uid);
956 iter = g_list_next(iter);
960 if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
961 data->event = TTSP_RESULT_EVENT_FINISH;
962 data->state = APP_STATE_READY;
964 if (true == data->is_paused_data) {
965 if (NULL != data->paused_data) {
966 if (NULL != data->paused_data->data) {
967 free(data->paused_data->data);
968 data->paused_data->data = NULL;
971 free(data->paused_data);
972 data->paused_data = NULL;
976 data->is_paused_data = false;
981 iter = g_list_next(iter);
985 SLOG(LOG_DEBUG, get_tag(), "[Player SUCCESS] player all stop!!");