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
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;
__recover_background_volume();
+ g_is_set_policy = false;
+
SLOG(LOG_DEBUG, tts_tag(), "[Player DEBUG] unset policy for playing");
return;
/* 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");
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) {
}
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;
}
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) {
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 */
} 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 */
/* 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");
/* 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.
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;
} 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) {
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();
}
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)",
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 */
/* 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");
__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)) {
}
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);
ttsd_data_clear_sound_data(&sound_data);
return;
}
- }
+ } // end of 1st while(1)
}
int __create_ducking_handle(void)