Add a new TTS Interrupt mode
[platform/core/uifw/tts.git] / server / ttsd_server.c
index f494287..24365e5 100644 (file)
@@ -528,23 +528,25 @@ int ttsd_server_initialize(int pid, int uid, bool* credential_needed)
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       char* appid = NULL;
-       if (0 != app_manager_get_app_id(pid, &appid)) {
-               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
-       }
-       bool is_agreed = false;
-       if (0 != ttsd_engine_check_app_agreed(appid, &is_agreed)) {
-               SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
+       if (true == *credential_needed) {
+               char* appid = NULL;
+               if (0 != app_manager_get_app_id(pid, &appid)) {
+                       SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
+               }
+               bool is_agreed = false;
+               if (0 != ttsd_engine_check_app_agreed(appid, &is_agreed)) {
+                       SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
+                       if (!appid)
+                               free(appid);
+                       return TTSD_ERROR_OPERATION_FAILED;
+               }
                if (!appid)
                        free(appid);
-               return TTSD_ERROR_OPERATION_FAILED;
-       }
-       if (!appid)
-               free(appid);
 
-       if (false == is_agreed) {
-               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
-               return TTSD_ERROR_PERMISSION_DENIED;
+               if (false == is_agreed) {
+                       SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
+                       return TTSD_ERROR_PERMISSION_DENIED;
+               }
        }
 
        if (0 != ttsd_data_new_client(pid, uid)) {
@@ -849,6 +851,19 @@ int ttsd_server_play(int uid, const char* credential)
                }
        }
 
+       /* check the current playback focus */
+       if (TTSD_MODE_INTERRUPT != ttsd_get_mode()) {
+               bool is_current_interrupt = false;
+               if (0 != ttsd_player_check_current_playback_focus(&is_current_interrupt)) {
+                       SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to check the current playback focus");
+               } else {
+                       if (true == is_current_interrupt) {
+                               SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Current playback focus is set on Interrupt mode. Cannot play default, screen reader, and noti modes.");
+                               return TTSD_ERROR_AUDIO_POLICY_BLOCKED;
+                       }
+               }
+       }
+
        int current_uid = ttsd_data_get_current_playing();
        SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
 
@@ -1141,6 +1156,26 @@ int ttsd_server_play_pcm(int uid)
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
+       if (APP_STATE_PAUSED == state) {
+               SLOG(LOG_DEBUG, tts_tag(), "[Server] uid(%d) is 'Pause' state : resume player", uid);
+
+               /* Resume player */
+               if (0 != ttsd_player_resume(uid)) {
+                       SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Fail to ttsd_player_resume()");
+               }
+       } else {
+               if (0 != ttsd_player_play_pcm(uid)) {
+                       SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play pcm sound : uid(%d)", uid);
+
+                       // Change ready state
+                       ttsd_server_stop_pcm(uid);
+
+                       int tmp_pid;
+                       tmp_pid = ttsd_data_get_pid(uid);
+                       ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
+               }
+       }
+
        return TTSD_ERROR_NONE;
 }
 
@@ -1154,16 +1189,16 @@ int ttsd_server_stop_pcm(int uid)
 
        SLOG(LOG_INFO, tts_tag(), "[Server] server stop, state(%d)", state);
 
-       if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state) {
-               if (0 != ttsd_player_clear(uid))
-                       SLOG(LOG_WARN, tts_tag(), "[Server] Fail to ttsd_player_stop()");
-
+       if (APP_STATE_PLAYING == state || APP_STATE_PAUSED == state || APP_STATE_READY == state) {
                ttsd_data_set_client_state(uid, APP_STATE_READY);
        }
 
        /* Reset all data */
        ttsd_data_clear_data(uid);
 
+       ttsd_player_stop(uid);
+
+
        return TTSD_ERROR_NONE;
 }
 
@@ -1236,16 +1271,17 @@ int ttsd_server_add_pcm(int uid, int event, void* data, int data_size, int audio
                        temp_sound_data = NULL;
                }
 
-               if (0 != ttsd_player_play(uid)) {
+/*             if (0 != ttsd_player_play(uid)) {
                        SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to play sound : uid(%d)", uid);
 
-                       /* Change ready state */
+                       // Change ready state
                        ttsd_server_stop(uid);
 
                        int tmp_pid;
                        tmp_pid = ttsd_data_get_pid(uid);
                        ttsdc_send_set_state_message(tmp_pid, uid, APP_STATE_READY);
                }
+*/
        } else {
                SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_ERROR");
        }