Fix to call __set_policy_for_playing 82/239382/1
authorsooyeon.kim <sooyeon.kim@samsung.com>
Fri, 24 Jul 2020 09:02:39 +0000 (18:02 +0900)
committersooyeon.kim <sooyeon.kim@samsung.com>
Fri, 24 Jul 2020 09:02:39 +0000 (18:02 +0900)
Change-Id: If8f94c6d58ff8cdb97691d24d738ea889a413248
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
server/ttsd_player.c

index e4faaa8..e2d0d72 100644 (file)
@@ -87,6 +87,8 @@ static sound_stream_ducking_h g_system_stream_ducking;
 static sound_stream_ducking_h g_notification_stream_ducking;
 static sound_stream_ducking_h g_alarm_stream_ducking;
 
+static bool g_is_set_policy;
+
 // static bool ducking_flag;
 
 #define SND_MGR_DUCKING_DURATION 500
@@ -414,6 +416,8 @@ static void __set_policy_for_playing(int volume)
                SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to set stream info");
        }
 
+       g_is_set_policy = true;
+
        SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] set policy for playing");
 
        return;
@@ -445,6 +449,8 @@ static void __unset_policy_for_playing()
 
        __recover_background_volume();
 
+       g_is_set_policy = false;
+
        SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] unset policy for playing");
 
        return;
@@ -536,7 +542,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
 
        /* set volume policy as 40% */
        __set_policy_for_playing(40);
-       while (1) {
+       while (1) { // 1st while(1)
                /* check g_playing_info one more time */
                if (NULL == g_playing_info) {
                        SLOG(LOG_INFO, tts_tag(), "[Player INFO] No current player");
@@ -550,6 +556,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                        if (NULL != sound_data) {
                                ttsd_data_clear_sound_data(&sound_data);
                        }
+
                        sound_data = (sound_data_s*)calloc(1, sizeof(sound_data_s));
                        char* temp = (char*)calloc(player->paused_data->data_size + 5, sizeof(char));
                        if (NULL == sound_data || NULL == temp || player->paused_data->data_size <= 0) {
@@ -561,7 +568,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                }
                                sound_data = player->paused_data;
                                player->paused_data = NULL;
-                       } else {
+                       } else { // NULL != sound_data && NULL != temp && player->paused_data->data_size > 0
                                SLOG(LOG_INFO, tts_tag(), "[Player INFO] Copy paused_data to sound_data");
                                sound_data->data = NULL;
                                sound_data->rate = 0;
@@ -599,7 +606,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                        }
                        SLOG(LOG_INFO, tts_tag(), "[Player] Sound info : id(%d) data(%p) size(%d) audiotype(%d) rate(%d) event(%d)", 
                                sound_data->utt_id, sound_data->data, sound_data->data_size, sound_data->audio_type, sound_data->rate, sound_data->event);
-               } else {
+               } else { // NO player->is_paused_data
                        sound_data = NULL;
                        ret = ttsd_data_get_sound_data(player->uid, &sound_data);
                        if (0 != ret || NULL == sound_data) {
@@ -607,7 +614,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                SLOG(LOG_ERROR, tts_tag(), "[Player] No sound data. Waiting mode");
 
                                /* wait for new audio data come */
-                               while (1) {
+                               while (1) { // 2nd while(1)
                                        usleep(10000);
                                        if (NULL == g_playing_info) {
                                                /* current playing uid is replaced */
@@ -628,7 +635,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                        } else if (0 < ttsd_data_get_sound_data_size(player->uid)) {
                                                /* new audio data come */
                                                SLOG(LOG_INFO, tts_tag(), "[Player] Resume thread");
-                                               break;
+                                               break; // exit from 2nd while(1)
                                        }
 
                                        /* If engine is not on processing */
@@ -646,10 +653,10 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                                        /* unset volume policy, volume will be 100% */
                                                        __unset_policy_for_playing();
                                                }
-                                       } else {
+                                       } else { // TTSD_SYNTHESIS_CONTROL_DOING
                                                SLOG(LOG_ERROR, tts_tag(), "[Player] Sound data is NULL, while engine is on processing to synthesize");
                                        }
-                               }
+                               } // 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");
 
@@ -661,7 +668,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                /* resume play thread */
                                player->state = APP_STATE_PLAYING;
                                continue;
-                       }
+                       } // NULL == sound_data
 
                        /* If wdata's event is 'start', current wdata is first data of engine for synthesis.
                         * If wdata's event is 'finish', player should check previous event to know whether this wdata is first or not.
@@ -685,7 +692,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                                pid, player->uid, sound_data->utt_id);
                                }
                                SLOG(LOG_INFO, tts_tag(), "[Player] Start utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
-                       }
+                       } // (TTSE_RESULT_EVENT_START == sound_data->event || (TTSE_RESULT_EVENT_FINISH == player->event && TTSE_RESULT_EVENT_FINISH == sound_data->event))
 
                        /* Save last event to check utterance start */
                        player->event = sound_data->event;
@@ -713,13 +720,14 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                        } else {
                                                SLOG(LOG_INFO, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
                                        }
-                               }
+                               } // TTSE_RESULT_EVENT_FINISH == sound_data->event
                                SLOG(LOG_INFO, tts_tag(), "[Player] Event(%d) utterance : uid(%d), uttid(%d)", sound_data->event, player->uid, sound_data->utt_id);
                                ttsd_data_clear_sound_data(&sound_data);
                                continue;
-                       }
-               }
+                       } // (NULL == sound_data->data || 0 >= sound_data->data_size)
+               } // NO player->is_paused_data
 
+               // If there is any change in audio format, recreate audio handle
                if (g_sampling_rate != sound_data->rate || g_audio_type != sound_data->audio_type) {
                        SLOG(LOG_INFO, tts_tag(), "[Player] Change audio handle : org type(%d) org rate(%d)", g_audio_type, g_sampling_rate);
                        if (NULL != g_audio_h) {
@@ -750,12 +758,18 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                len = SOUND_BUFFER_LENGTH;
                        }
 
+                       // Check whether set_policy is done or not
+                       if (false == g_is_set_policy) {
+                               SLOG(LOG_INFO, tts_tag(), "[Player INFO] Set policy");
+                               __set_policy_for_playing(40);
+                       }
+
                        if (AUDIO_STATE_READY == g_audio_state || AUDIO_STATE_WAIT_FOR_PLAYING == g_audio_state) {
                                /* Request prepare */
                                ret = audio_out_prepare(g_audio_h);
                                if (AUDIO_IO_ERROR_NONE != ret) {
                                        SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to prepare audio : %d", ret);
-
+                                       g_playing_info = NULL;
                                        /* unset volume policy, volume will be 100% */
                                        __unset_policy_for_playing();
 
@@ -765,7 +779,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                }
                                SLOG(LOG_DEBUG, tts_tag(), "[Player SUCCESS] Prepare audio");
                                g_audio_state = AUDIO_STATE_PLAY;
-                       }
+                       } // (AUDIO_STATE_READY == g_audio_state || AUDIO_STATE_WAIT_FOR_PLAYING == g_audio_state)
 
                        char* temp_data = sound_data->data;
                        SLOG(LOG_INFO, tts_tag(), "[Player INFO] Before audio_out_write. data(%p), data[%d](%p), uid(%d), utt_id(%d), len(%d)",
@@ -795,7 +809,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                ttsd_data_clear_sound_data(&sound_data);
 
                                return;
-                       }
+                       } // (NULL == g_playing_info && APP_STATE_PAUSED != player->state)
 
                        if (APP_STATE_PAUSED == player->state) {
                                /* Save data */
@@ -821,11 +835,11 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                                /* unset volume policy, volume will be 100% */
                                __unset_policy_for_playing();
                                return;
-                       }
-               }
+                       } // (APP_STATE_PAUSED == player->state)
+               } // while (APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state)
 
                if (NULL == g_playing_info && APP_STATE_READY == player->state) {
-                       /* player_stop */ 
+                       /* player_stop */
                        g_audio_state = AUDIO_STATE_READY;
                        SLOG(LOG_DEBUG, tts_tag(), "[Player] Stop player thread");
 
@@ -841,7 +855,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                        __unset_policy_for_playing();
                        ttsd_data_clear_sound_data(&sound_data);
                        return;
-               }
+               } // (NULL == g_playing_info && APP_STATE_READY == player->state)
 
                if ((APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) &&
                        (TTSE_RESULT_EVENT_FINISH == sound_data->event)) {
@@ -866,7 +880,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                        }
 
                        SLOG(LOG_INFO, tts_tag(), "[Player] Finish utterance : uid(%d), uttid(%d)", player->uid, sound_data->utt_id);
-               }
+               } // ((APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) && (TTSE_RESULT_EVENT_FINISH == sound_data->event))
 
                ttsd_data_clear_sound_data(&sound_data);
 
@@ -882,7 +896,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                        ttsd_data_clear_sound_data(&sound_data);
                        return;
                }
-       }
+       } // end of 1st while(1)
 }
 
 int __create_ducking_handle(void)