Fix dbus delay when requesting hello
[platform/core/uifw/stt.git] / server / sttd_server.c
index a239e72..38b7a7f 100644 (file)
@@ -1084,10 +1084,16 @@ void __sttd_server_recorder_start(void* data)
                return;
        }
 
-       /* Notify uid state change */
-       sttdc_send_set_state(uid, APP_STATE_RECORDING);
-
-       SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Start recognition");
+       app_state_e temp_app_state;
+       if (0 != sttd_client_get_state(uid, &temp_app_state)) {
+               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid ");
+               return;
+       }
+       if (APP_STATE_READY != temp_app_state && 0 != stt_client_get_current_recognition()) {
+               /* Notify uid state change */
+               sttdc_send_set_state(uid, APP_STATE_RECORDING);
+               SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Start recognition");
+       }
 }
 
 void __sttd_start_sound_completed_cb(int id, void *user_data)
@@ -1181,10 +1187,20 @@ int sttd_server_start(int uid, const char* lang, const char* recognition_type, i
        if (NULL != sound) {
                int id = 0;
                intptr_t puid = (intptr_t)uid;
-               ret = wav_player_start(sound, SOUND_TYPE_MEDIA, __sttd_start_sound_completed_cb, (void*)puid, &id);
-               if (WAV_PLAYER_ERROR_NONE != ret) {
-                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to play wav");
+               sound_stream_info_h wav_stream_info_h;
+               if (0 != sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, NULL, NULL, &wav_stream_info_h)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to create stream info for playing wav");
                        is_sound_done = true;
+               } else {
+                       ret = wav_player_start_new(sound, wav_stream_info_h, __sttd_start_sound_completed_cb, (void*)puid, &id);
+                       if (WAV_PLAYER_ERROR_NONE != ret) {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to play wav");
+                               is_sound_done = true;
+                       }
+
+                       if (0 != sound_manager_destroy_stream_information(wav_stream_info_h)) {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to destroy stream info for playing wav");
+                       }
                }
                free(sound);
                sound = NULL;
@@ -1210,6 +1226,8 @@ int sttd_server_start(int uid, const char* lang, const char* recognition_type, i
 
        g_recording_log_count = 0;
 
+       app_state_e temp_app_state;
+
        if (true == is_sound_done) {
                SLOG(LOG_DEBUG, TAG_STTD, "[Server] No sound play");
 
@@ -1226,8 +1244,14 @@ int sttd_server_start(int uid, const char* lang, const char* recognition_type, i
                        return ret;
                }
 
-               /* Notify uid state change */
-               sttdc_send_set_state(uid, APP_STATE_RECORDING);
+               if (0 != sttd_client_get_state(uid, &temp_app_state)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] uid is NOT valid");
+                       return STTD_ERROR_INVALID_PARAMETER;
+               }
+               if (APP_STATE_READY != temp_app_state && 0 != stt_client_get_current_recognition()) {
+                       /* Notify uid state change */
+                       sttdc_send_set_state(uid, APP_STATE_RECORDING);
+               }
 
                SLOG(LOG_DEBUG, TAG_STTD, "[Server SUCCESS] Start recognition");
                return STTD_RESULT_STATE_DONE;
@@ -1353,13 +1377,21 @@ int sttd_server_stop(int uid)
        if (NULL != sound) {
                int id = 0;
                intptr_t puid = (intptr_t)uid;
-               ret = wav_player_start(sound, SOUND_TYPE_MEDIA, __sttd_stop_sound_completed_cb, (void*)puid, &id);
-               if (WAV_PLAYER_ERROR_NONE != ret) {
-                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to play wav");
+               sound_stream_info_h wav_stream_info_h;
+               if (0 != sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, NULL, NULL, &wav_stream_info_h)) {
+                       SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to create stream info for playing wav");
                } else {
-                       SLOG(LOG_DEBUG, TAG_STTD, "[Server] Play wav : %s", sound);
-               }
+                       ret = wav_player_start_new(sound, wav_stream_info_h, __sttd_stop_sound_completed_cb, (void*)puid, &id);
+                       if (WAV_PLAYER_ERROR_NONE != ret) {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to play wav");
+                       } else {
+                               SLOG(LOG_DEBUG, TAG_STTD, "[Server] Play wav : %s", sound);
+                       }
 
+                       if (0 != sound_manager_destroy_stream_information(wav_stream_info_h)) {
+                               SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to destroy stream info for playing wav");
+                       }
+               }
                free(sound);
 
                g_processing_timer = ecore_timer_add(g_processing_timeout, __time_out_for_processing, NULL);