typedef enum {
AUDIO_STATE_NONE = 0,
AUDIO_STATE_READY,
+ AUDIO_STATE_WAIT_FOR_PLAYING,
AUDIO_STATE_PLAY
} audio_state_e;
}
SLOG(LOG_WARN, tts_tag(), "[Player] focus state changed to (%d) with reason(%d) and extra info(%s)", (int)focus_state, (int)reason_for_change, extra_info);
- if (NULL == g_playing_info) {
- SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
- return;
- }
-
- if (APP_STATE_PLAYING == g_playing_info->state && focus_mask == SOUND_STREAM_FOCUS_FOR_PLAYBACK && SOUND_STREAM_FOCUS_STATE_RELEASED == focus_state) {
+ if ((AUDIO_STATE_PLAY == g_audio_state || AUDIO_STATE_WAIT_FOR_PLAYING == g_audio_state) && focus_mask == SOUND_STREAM_FOCUS_FOR_PLAYBACK && SOUND_STREAM_FOCUS_STATE_RELEASED == focus_state) {
if (TTSD_MODE_DEFAULT == ttsd_get_mode()) {
g_audio_state = AUDIO_STATE_READY;
- int uid = g_playing_info->uid;
-
- if (0 != ttsd_player_pause(uid)) {
- SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to pause the player");
+ if (NULL == g_playing_info) {
+ SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
return;
}
- ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
- int pid = ttsd_data_get_pid(uid);
- /* send message to client about changing state */
- ttsdc_send_set_state_message(pid, uid, APP_STATE_PAUSED);
+ if (APP_STATE_PLAYING == g_playing_info->state) {
+ int uid = g_playing_info->uid;
+
+ if (0 != ttsd_player_pause(uid)) {
+ SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to pause the player");
+ return;
+ }
+
+ ttsd_data_set_client_state(uid, APP_STATE_PAUSED);
+ int pid = ttsd_data_get_pid(uid);
+ /* send message to client about changing state */
+ ttsdc_send_set_state_message(pid, uid, APP_STATE_PAUSED);
+ }
} else {
SLOG(LOG_DEBUG, tts_tag(), "[Player] Ignore focus state cb - mode(%d)", ttsd_get_mode());
}
return;
}
- if (NULL == g_playing_info) {
- SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
- return;
- }
+ if (SOUND_STREAM_FOCUS_CHANGED_BY_VOICE_INFORMATION == reason && NULL != extra_info && 0 == strncmp(extra_info, "TTSD_MODE_INTERRUPT", strlen(extra_info))) {
+ /* If the focus is changed by "Interrupt" mode and current players of "SR" and "Noti" modes are on going, please stop all players. */
+ SLOG(LOG_INFO, tts_tag(), "[Player INFO] All stop the playing or the request to play. audio state(%d)", g_audio_state);
- if (APP_STATE_PLAYING == g_playing_info->state && SOUND_STREAM_FOCUS_CHANGED_BY_VOICE_INFORMATION == reason &&
- NULL != extra_info && 0 == strncmp(extra_info, "TTSD_MODE_INTERRUPT", strlen(extra_info))) {
- /* If the focus is changed by "Interrupt" mode and current players of "SR" and "Noti" modes are on going, please stop the current players. */
+// if (AUDIO_STATE_PLAY == g_audio_state || AUDIO_STATE_WAIT_FOR_PLAYING == g_audio_state)
g_audio_state = AUDIO_STATE_READY;
- int uid = g_playing_info->uid;
+ ttsd_send_all_stop();
- if (0 != ttsd_server_stop(uid)) {
- SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to stop TTS server");
- return;
- }
- if (0 != ttsd_player_stop(uid)) {
- SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to stop the player");
+/* if (NULL == g_playing_info) {
+ SLOG(LOG_WARN, tts_tag(), "[Player WARNING] No current player");
return;
}
- ttsd_data_set_client_state(uid, APP_STATE_READY);
- int pid = ttsd_data_get_pid(uid);
- /* send message to client about changing state */
- ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
- } else {
- SLOG(LOG_DEBUG, tts_tag(), "[Player] Extra info is not Interrupt mode(%s) or not playing state(%d).", extra_info, g_playing_info->state);
+ if (APP_STATE_PLAYING == g_playing_info->state) {
+ int uid = g_playing_info->uid;
+
+ if (0 != ttsd_server_stop(uid)) {
+ SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to stop TTS server");
+ return;
+ }
+ if (0 != ttsd_player_stop(uid)) {
+ SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to stop the player");
+ return;
+ }
+
+ ttsd_data_set_client_state(uid, APP_STATE_READY);
+ int pid = ttsd_data_get_pid(uid);
+ // send message to client about changing state
+ ttsdc_send_set_state_message(pid, uid, APP_STATE_READY);
+ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "[Player] Not playing state");
+ }
+*/ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "[Player] Extra info is not Interrupt mode(%s) or not playing state(%d).", (NULL == extra_info) ? "NULL" : extra_info, g_audio_state);
}
return;
SLOG(LOG_INFO, tts_tag(), "[Player] Finish to wait for new audio data come");
- if (AUDIO_STATE_READY == g_audio_state) {
+ if (AUDIO_STATE_READY == g_audio_state || AUDIO_STATE_WAIT_FOR_PLAYING == g_audio_state) {
/* set volume policy as 40%, when resume play thread*/
__set_policy_for_playing(40);
}
len = SOUND_BUFFER_LENGTH;
}
- if (AUDIO_STATE_READY == g_audio_state) {
+ 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) {
g_bg_volume_ratio = ratio;
return TTSD_ERROR_NONE;
}
+
+int ttsd_player_wait_to_play(int uid)
+{
+ SLOG(LOG_INFO, tts_tag(), "[Player INFO] wait to play (%d)", uid);
+
+ g_audio_state = AUDIO_STATE_WAIT_FOR_PLAYING;
+
+ return TTSD_ERROR_NONE;
+}
{
/* clear client data */
ttsd_data_clear_data(uid);
- ttsd_data_set_client_state(uid, APP_STATE_READY);
- /* send message */
- if (0 != ttsdc_send_set_state_message(pid, uid, APP_STATE_READY)) {
- /* remove client */
- ttsd_data_delete_client(uid);
+ if (APP_STATE_READY != state) {
+ ttsd_data_set_client_state(uid, APP_STATE_READY);
+
+ /* send message */
+ if (0 != ttsdc_send_set_state_message(pid, uid, APP_STATE_READY)) {
+ /* remove client */
+ ttsd_data_delete_client(uid);
+ }
}
return true;
return;
}
+int ttsd_send_all_stop()
+{
+ SLOG(LOG_INFO, tts_tag(), "[Server] Send to stop all requests");
+
+ /* stop all player */
+ ttsd_player_all_stop();
+
+ /* send interrupt message to all clients */
+ ttsd_data_foreach_clients(__get_client_cb, NULL);
+
+ return TTSD_ERROR_NONE;
+}
+
/*
* Server APIs
*/
}
/* Change current play */
+ if (0 != ttsd_player_wait_to_play(uid)) {
+ SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to set to wait for playing : uid(%d)", uid);
+ }
+
if (0 != ttsd_data_set_client_state(uid, APP_STATE_PLAYING)) {
SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set state : uid(%d)", uid);
return TTSD_ERROR_OPERATION_FAILED;