Reprepare instantly for the client speicifed by server 78/288378/4
authorSuyeon Hwang <stom.hwang@samsung.com>
Tue, 7 Feb 2023 06:07:42 +0000 (15:07 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Tue, 21 Feb 2023 03:05:08 +0000 (12:05 +0900)
- Requirement:
In order to start engine quickly, one of the clients needs to reprepare
instantly.

- Contents:
This patch adds new logic for repreparing. Through this patch, one of
clients which is specified by the server library will reprepare instantly
when the service is out. This specified client will help quick tts engine
launch.

Change-Id: Ied3e804378c835ea2e744bb948462337802ebc39
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts_core.c

index 24ac8a5..9098e4c 100644 (file)
@@ -1195,6 +1195,12 @@ int tts_core_foreach_supported_voices(tts_client_s* client, const char* engine_i
 
 static void set_service_out_for_each_client(gpointer data, gpointer user_data)
 {
+       unsigned int instant_reprepare_uid = TTS_INVALID_UID;
+       if (NULL != user_data) {
+               instant_reprepare_uid = *((unsigned int *)user_data);
+               SLOG(LOG_INFO, TAG_TTSC, "[INFO] Instant on client UID(%u)", instant_reprepare_uid);
+       }
+
        tts_client_s *client = (tts_client_s *)data;
        if (false == tts_client_is_valid_client(client)) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Client is not valid");
@@ -1208,9 +1214,18 @@ static void set_service_out_for_each_client(gpointer data, gpointer user_data)
        }
 
        tts_client_set_service_out(client, true);
-       tts_client_set_current_state(client, TTS_STATE_READY);
        tts_core_notify_error_async(client, TTS_ERROR_SERVICE_RESET, -1, "Daemon Reset");
 
+       unsigned int uid = tts_client_get_uid(client);
+       if (uid != instant_reprepare_uid) {
+               SLOG(LOG_INFO, TAG_TTSC, "[INFO] On-demand repreparation required. UID(%u)", uid);
+               tts_client_set_current_state(client, TTS_STATE_READY);
+       } else {
+               SLOG(LOG_INFO, TAG_TTSC, "[INFO] Instantly repreparation required. UID(%u)", uid);
+               tts_client_set_current_state(client, TTS_STATE_CREATED);
+               tts_core_prepare(client);
+       }
+
        const tts_service_state_e before_state = tts_client_get_current_service_state(client);
        tts_core_notify_service_state_changed(client, before_state, TTS_SERVICE_STATE_BLOCKED);
 }
@@ -1222,8 +1237,14 @@ int tts_core_handle_service_reset()
        GList* client_list = tts_client_get_client_list();
        RETVM_IF(NULL == client_list, TTS_ERROR_OPERATION_FAILED, "[ERROR] Fail to get client list");
 
+       unsigned int instant_reprepare_uid = TTS_INVALID_UID;
+       int ret = tts_config_mgr_get_instant_reprepare_client(&instant_reprepare_uid);
+       if (TTS_CONFIG_ERROR_NONE != ret) {
+               SLOG(LOG_WARN, TAG_TTSC, "[WARN] Fail to get instant reprepare uid. Skip instant reprepare");
+       }
+
        SLOG(LOG_INFO, TAG_TTSC, "[INFO] Set service out to all clients");
-       g_list_foreach(client_list, set_service_out_for_each_client, NULL);
+       g_list_foreach(client_list, set_service_out_for_each_client, &instant_reprepare_uid);
        g_list_free(client_list);
 
        return TTS_ERROR_NONE;