From: sooyeon Date: Wed, 14 Aug 2024 11:01:14 +0000 (+0900) Subject: Move creating AudioStream instance when playing tts is requested X-Git-Tag: accepted/tizen/8.0/unified/20241011.164854~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=180b3971a0311a981c0c173184c1d8dbdd3fa7d1;p=platform%2Fcore%2Fuifw%2Ftts.git Move creating AudioStream instance when playing tts is requested - Issue: At booting time, there is a case that focus server is not ready. Because focus server is not ready, initializing TTS engine is delayed with blocking a main thread. - Solution: Initializing AudioStream is moved to be invoked when playing TTS is requested. Change-Id: I141b9a1e7f2835675f625c778968d9308ec3c121 Signed-off-by: sooyeon --- diff --git a/server/ttsd_player.cpp b/server/ttsd_player.cpp index 2a966784..1b59d7f5 100644 --- a/server/ttsd_player.cpp +++ b/server/ttsd_player.cpp @@ -138,11 +138,30 @@ static void write_buffer_dump_file(const void* buffer, size_t length) } #endif +static int check_and_create_audio_stream(void) +{ + if (nullptr != g_audio_stream) + return 0; + + SLOG(LOG_ERROR, tts_tag(), "[BG] g_audio_stream is null. Create a new instance"); + g_audio_stream = new AudioStream(); + if (nullptr == g_audio_stream) { + SLOG(LOG_ERROR, tts_tag(), "[BG] Fail to allocate memory."); + return -1; + } + + return 0; +} + static void set_policy_for_playing(unsigned int uid) { /* In case of DEFAULT and INTERRUPT mode, acquire sound focus */ ttsd_mode_e mode = ttsd_data_get_mode(uid); SLOG(LOG_INFO, tts_tag(), "[Player INFO] Current uid(%d)'s mode(%d)", uid, (int)mode); + + if (-1 == check_and_create_audio_stream()) + return; + if (TTSD_MODE_DEFAULT == mode || TTSD_MODE_INTERRUPT == mode) g_audio_stream->acquireSoundFocus(); @@ -158,7 +177,8 @@ static void unset_policy_for_playing(unsigned int uid) /* In case of DEFAULT and INTERRUPT mode, release sound focus */ ttsd_mode_e mode = ttsd_data_get_mode(uid); SLOG(LOG_INFO, tts_tag(), "[Player INFO] Current uid(%d)'s mode(%d)", uid, (int)mode); - if (TTSD_MODE_DEFAULT == mode || TTSD_MODE_INTERRUPT == mode) + + if ((TTSD_MODE_DEFAULT == mode || TTSD_MODE_INTERRUPT == mode) && nullptr != g_audio_stream) g_audio_stream->releaseSoundFocus(); g_background_volume->recoverVolumeRatio(); @@ -215,6 +235,9 @@ static int notify_utterance_completed_event(unsigned int uid, int utt_id) static int play_sound_data(PlayerThread* player, unsigned int uid, sound_data_s* sound_data) { + if (-1 == check_and_create_audio_stream()) + return TTSD_ERROR_OUT_OF_MEMORY; + if (TTSD_ERROR_NONE != g_audio_stream->setAudioFormat(sound_data->audio_type, sound_data->rate)) { SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Fail to create audio out"); return TTSD_ERROR_OPERATION_FAILED; @@ -417,7 +440,6 @@ static void play_utterance_cb(PlayerThread* player, unsigned int uid) int ttsd_player_init() { g_background_volume = new BackgroundVolume(SND_MGR_DUCKING_DURATION); - g_audio_stream = new AudioStream(); g_player_thread = new PlayerThread(play_utterance_cb); g_is_set_policy = false; @@ -597,6 +619,9 @@ int ttsd_player_wait_to_play(unsigned int uid) return TTSD_ERROR_OPERATION_FAILED; } + if (-1 == check_and_create_audio_stream()) + return TTSD_ERROR_OUT_OF_MEMORY; + SLOG(LOG_INFO, tts_tag(), "[Player INFO] wait to play (%u)", uid); g_audio_stream->waitForPlay();