Extract function for waiting synthesis 78/271878/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Mon, 24 May 2021 11:07:05 +0000 (20:07 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Thu, 3 Mar 2022 12:12:14 +0000 (21:12 +0900)
Change-Id: I92c385d1d3dc2d5c4871d19a4e28f62c7f76bfbc
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
server/ttsd_player.cpp

index 0192847..e103eac 100644 (file)
@@ -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