From f164e0a0861f95b6a158b67af7031de306c36d48 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Mon, 24 May 2021 20:07:05 +0900 Subject: [PATCH] Extract function for waiting synthesis Change-Id: I92c385d1d3dc2d5c4871d19a4e28f62c7f76bfbc Signed-off-by: Suyeon Hwang --- server/ttsd_player.cpp | 71 +++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 44 deletions(-) diff --git a/server/ttsd_player.cpp b/server/ttsd_player.cpp index 0192847..e103eac 100644 --- a/server/ttsd_player.cpp +++ b/server/ttsd_player.cpp @@ -418,6 +418,26 @@ static int __play_sound_data(player_s* player, sound_data_s* sound_data) return TTSD_ERROR_NONE; } +static void __wait_sound_data(player_s* player) +{ + while (0 >= ttsd_data_get_sound_data_size(player->uid)) { // 2nd while(1) + usleep(10000); + if (false == __is_player_valid(player)) { + return; + } + + /* If engine is not on processing */ + ttsd_synthesis_control_e synth_control = ttsd_get_synth_control(); + if (TTSD_SYNTHESIS_CONTROL_DOING != synth_control) { + SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control); + if (AudioStream::AUDIO_STATE_PLAY == g_audio_stream->getState()) { + g_audio_stream->unprepareAudioOut(); + __unset_policy_for_playing(); + } + } + } +} + static void __play_thread_old(void *data, Ecore_Thread *thread) { SLOG(LOG_DEBUG, tts_tag(), "@@@ Start thread"); @@ -431,9 +451,6 @@ static void __play_thread_old(void *data, Ecore_Thread *thread) sound_data_s* sound_data = NULL; int ret = -1; - - /* set volume policy as 40% */ - __set_policy_for_playing(); while (1) { // 1st while(1) /* check g_playing_info one more time */ if (false == __is_player_valid(player)) { @@ -449,10 +466,7 @@ static void __play_thread_old(void *data, Ecore_Thread *thread) ttsd_data_set_paused_data_existing(player->uid, false); if (NULL == sound_data) { - /* Request unprepare */ g_audio_stream->unprepareAudioOut(); - - /* unset volume policy, volume will be 100% */ __unset_policy_for_playing(); return; } @@ -466,46 +480,15 @@ static void __play_thread_old(void *data, Ecore_Thread *thread) /* empty queue */ SLOG(LOG_ERROR, tts_tag(), "[Player] No sound data. Waiting mode"); - /* wait for new audio data come */ - while (1) { // 2nd while(1) - usleep(10000); - if (false == __is_player_valid(player)) { - /* current playing uid is replaced */ - SLOG(LOG_INFO, tts_tag(), "[Player] Finish thread"); - if (AudioStream::AUDIO_STATE_PLAY == g_audio_stream->getState()) { - /* release audio & recover session */ - g_audio_stream->unprepareAudioOut(); - } - /* unset volume policy, volume will be 100% */ - __unset_policy_for_playing(); - return; - } else if (0 < ttsd_data_get_sound_data_size(player->uid)) { - /* new audio data come */ - SLOG(LOG_INFO, tts_tag(), "[Player] Resume thread"); - break; // exit from 2nd while(1) - } - - /* If engine is not on processing */ - ttsd_synthesis_control_e synth_control = ttsd_get_synth_control(); - if (TTSD_SYNTHESIS_CONTROL_DOING != synth_control) { - SLOG(LOG_INFO, tts_tag(), "[Server INFO] synth_control(%d)", synth_control); - if (AudioStream::AUDIO_STATE_PLAY == g_audio_stream->getState()) { - /* release audio & recover session */ - g_audio_stream->unprepareAudioOut(); - - /* unset volume policy, volume will be 100% */ - __unset_policy_for_playing(); - } - } - } // end of 2nd while(1). waiting for new audio data come - - SLOG(LOG_INFO, tts_tag(), "[Player] Finish to wait for new audio data come"); - - if (AudioStream::AUDIO_STATE_READY == g_audio_stream->getState() || AudioStream::AUDIO_STATE_WAIT_FOR_PLAYING == g_audio_stream->getState()) { - /* set volume policy as 40%, when resume play thread*/ - __set_policy_for_playing(); + __wait_sound_data(player); + if (false == __is_player_valid(player)) { + SLOG(LOG_INFO, tts_tag(), "[Player] Finish thread"); + g_audio_stream->unprepareAudioOut(); + __unset_policy_for_playing(); + return; } + SLOG(LOG_INFO, tts_tag(), "[Player] Finish to wait for new audio data come"); continue; } // NULL == sound_data -- 2.7.4