pthread_mutex_unlock(&g_buf_save_mutex);
}
+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();
/* 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();
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;
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;
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();