2 * Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
15 #include <cynara-client.h>
16 #include <cynara-error.h>
17 #include <cynara-session.h>
23 #include <sys/types.h>
25 #include <system_info.h>
28 #include <sound_manager.h>
29 #include <sound_manager_internal.h>
32 #include "stt_client.h"
34 #include "stt_config_mgr.h"
35 #include "stt_internal.h"
39 static void __stt_notify_state_changed(void *data);
40 static void __stt_notify_error(void *data);
42 static Ecore_Timer* g_connect_timer = NULL;
43 static float g_volume_db = 0;
45 static int g_feature_enabled = -1;
47 static int g_privilege_allowed = -1;
48 static int g_privilege_applaunch_allowed = -1;
50 static cynara *p_cynara = NULL;
52 static bool g_err_callback_status = false;
54 /* for changing volume on each sound stream */
55 static sound_stream_info_h g_stream_for_volume_h = NULL;
56 static virtual_sound_stream_h g_virtual_sound_stream_h = NULL;
65 static int __stt_get_feature_enabled()
67 if (0 == g_feature_enabled) {
69 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported");
70 return STT_ERROR_NOT_SUPPORTED;
72 } else if (-1 == g_feature_enabled) {
73 bool stt_supported = false;
74 bool mic_supported = false;
75 if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) {
76 if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) {
77 if (false == stt_supported || false == mic_supported) {
79 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported");
80 g_feature_enabled = 0;
81 return STT_ERROR_NOT_SUPPORTED;
85 g_feature_enabled = 1;
88 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value");
89 return STT_ERROR_NOT_SUPPORTED;
94 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value");
95 return STT_ERROR_NOT_SUPPORTED;
103 static int __check_privilege_initialize()
105 int ret = cynara_initialize(&p_cynara, NULL);
106 if (CYNARA_API_SUCCESS != ret)
107 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to initialize"); //LCOV_EXCL_LINE
109 return ret == CYNARA_API_SUCCESS;
112 static bool __check_privilege(const char* uid, const char * privilege)
115 char label_path[1024] = "/proc/self/attr/current";
116 char smack_label[1024] = {'\0',};
122 fp = fopen(label_path, "r");
124 if (0 >= fread(smack_label, 1, sizeof(smack_label), fp))
125 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to fread"); //LCOV_EXCL_LINE
130 pid_t pid = getpid();
131 char *session = cynara_session_from_pid(pid);
132 int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
133 SLOG(LOG_DEBUG, TAG_STTC, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
139 if (ret != CYNARA_API_ACCESS_ALLOWED)
144 static void __check_privilege_deinitialize()
147 cynara_finish(p_cynara);
151 static int __stt_check_privilege()
155 if (0 == g_privilege_allowed) {
156 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied"); //LCOV_EXCL_LINE
157 return STT_ERROR_PERMISSION_DENIED;
158 } else if (-1 == g_privilege_allowed) {
159 if (false == __check_privilege_initialize()) {
160 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed"); //LCOV_EXCL_LINE
161 return STT_ERROR_PERMISSION_DENIED;
163 snprintf(uid, 16, "%d", getuid());
164 if (false == __check_privilege(uid, STT_PRIVILEGE_RECORDER)) {
165 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied"); //LCOV_EXCL_LINE
166 g_privilege_allowed = 0;
167 __check_privilege_deinitialize();
168 return STT_ERROR_PERMISSION_DENIED;
170 __check_privilege_deinitialize();
173 g_privilege_allowed = 1;
174 return STT_ERROR_NONE;
177 static int __stt_check_privilege_for_applaunch()
181 if (0 == g_privilege_applaunch_allowed) {
182 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission for applaunch is denied"); //LCOV_EXCL_LINE
183 return STT_ERROR_PERMISSION_DENIED;
184 } else if (-1 == g_privilege_applaunch_allowed) {
185 if (false == __check_privilege_initialize()) {
186 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed (applaunch)"); //LCOV_EXCL_LINE
187 return STT_ERROR_PERMISSION_DENIED;
189 snprintf(uid, 16, "%d", getuid());
190 if (false == __check_privilege(uid, STT_PRIVILEGE_APPLAUNCH)) {
191 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied : appmanager.launch"); //LCOV_EXCL_LINE
192 g_privilege_applaunch_allowed = 0;
193 __check_privilege_deinitialize();
194 return STT_ERROR_PERMISSION_DENIED;
196 __check_privilege_deinitialize();
199 g_privilege_applaunch_allowed = 1;
200 return STT_ERROR_NONE;
203 static const char* __stt_get_error_code(stt_error_e err)
207 case STT_ERROR_NONE: return "STT_ERROR_NONE";
208 case STT_ERROR_OUT_OF_MEMORY: return "STT_ERROR_OUT_OF_MEMORY";
209 case STT_ERROR_IO_ERROR: return "STT_ERROR_IO_ERROR";
210 case STT_ERROR_INVALID_PARAMETER: return "STT_ERROR_INVALID_PARAMETER";
211 case STT_ERROR_TIMED_OUT: return "STT_ERROR_TIMED_OUT";
212 case STT_ERROR_RECORDER_BUSY: return "STT_ERROR_RECORDER_BUSY";
213 case STT_ERROR_OUT_OF_NETWORK: return "STT_ERROR_OUT_OF_NETWORK";
214 case STT_ERROR_PERMISSION_DENIED: return "STT_ERROR_PERMISSION_DENIED";
215 case STT_ERROR_NOT_SUPPORTED: return "STT_ERROR_NOT_SUPPORTED";
216 case STT_ERROR_INVALID_STATE: return "STT_ERROR_INVALID_STATE";
217 case STT_ERROR_INVALID_LANGUAGE: return "STT_ERROR_INVALID_LANGUAGE";
218 case STT_ERROR_ENGINE_NOT_FOUND: return "STT_ERROR_ENGINE_NOT_FOUND";
219 case STT_ERROR_OPERATION_FAILED: return "STT_ERROR_OPERATION_FAILED";
220 case STT_ERROR_NOT_SUPPORTED_FEATURE: return "STT_ERROR_NOT_SUPPORTED_FEATURE";
221 case STT_ERROR_SERVICE_RESET: return "STT_ERROR_SERVICE_RESET";
223 return "Invalid error code";
228 static int __stt_convert_config_error_code(stt_config_error_e code)
231 if (code == STT_CONFIG_ERROR_NONE) return STT_ERROR_NONE;
232 if (code == STT_CONFIG_ERROR_OUT_OF_MEMORY) return STT_ERROR_OUT_OF_MEMORY;
233 if (code == STT_CONFIG_ERROR_IO_ERROR) return STT_ERROR_IO_ERROR;
234 if (code == STT_CONFIG_ERROR_INVALID_PARAMETER) return STT_ERROR_INVALID_PARAMETER;
235 if (code == STT_CONFIG_ERROR_PERMISSION_DENIED) return STT_ERROR_PERMISSION_DENIED;
236 if (code == STT_CONFIG_ERROR_NOT_SUPPORTED) return STT_ERROR_NOT_SUPPORTED;
237 if (code == STT_CONFIG_ERROR_INVALID_STATE) return STT_ERROR_INVALID_STATE;
238 if (code == STT_CONFIG_ERROR_INVALID_LANGUAGE) return STT_ERROR_INVALID_LANGUAGE;
239 if (code == STT_CONFIG_ERROR_ENGINE_NOT_FOUND) return STT_ERROR_ENGINE_NOT_FOUND;
240 if (code == STT_CONFIG_ERROR_OPERATION_FAILED) return STT_ERROR_OPERATION_FAILED;
246 void __stt_config_lang_changed_cb(const char* before_language, const char* current_language, void* user_data)
248 SLOG(LOG_DEBUG, TAG_STTC, "Language changed : Before lang(%s) Current lang(%s)",
249 before_language, current_language);
251 if (0 == strcmp(before_language, current_language)) {
255 GList* client_list = NULL;
256 client_list = stt_client_get_client_list();
259 stt_client_s *data = NULL;
261 if (g_list_length(client_list) > 0) {
262 /* Get a first item */
263 iter = g_list_first(client_list);
265 while (NULL != iter) {
267 if (NULL != data->default_lang_changed_cb) {
268 SLOG(LOG_DEBUG, TAG_STTC, "Call default language changed callback : uid(%d)", data->uid);
269 data->default_lang_changed_cb(data->stt, before_language, current_language,
270 data->default_lang_changed_user_data);
274 iter = g_list_next(iter);
281 static Eina_Bool __reconnect_by_engine_changed(void *data)
283 stt_h stt = (stt_h)data;
285 stt_client_s* client = stt_client_get(stt);
286 if (NULL == client) {
287 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
291 if (STT_STATE_READY != client->current_state) {
296 int ret = stt_unprepare(stt);
298 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
300 ret = stt_prepare(stt);
302 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
308 void __stt_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, bool support_silence, bool need_credential, void* user_data)
310 stt_h stt = (stt_h)user_data;
312 stt_client_s* client = stt_client_get(stt);
313 if (NULL == client) {
314 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
318 if (NULL != engine_id) SLOG(LOG_DEBUG, TAG_STTC, "Engine id(%s)", engine_id);
319 if (NULL != setting) SLOG(LOG_DEBUG, TAG_STTC, "Engine setting(%s)", setting);
320 if (NULL != language) SLOG(LOG_DEBUG, TAG_STTC, "Language(%s)", language);
321 SLOG(LOG_DEBUG, TAG_STTC, "Silence(%s), Credential(%s)", support_silence ? "on" : "off", need_credential ? "need" : "no need");
323 /* When the default engine is changed, please unload the old engine and load the new one. */
326 if (NULL == client->current_engine_id) {
327 if (STT_STATE_RECORDING == client->current_state || STT_STATE_PROCESSING == client->current_state) {
328 SLOG(LOG_INFO, TAG_STTC, "[INFO] stt cancel is invoked by engine_changed_cb, state(%d)", client->current_state);
329 ret = stt_cancel(stt);
331 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] STT client cancelling...");
334 ecore_idler_add(__reconnect_by_engine_changed, (void*)stt);
335 } else if (STT_STATE_READY == client->current_state) {
336 ret = stt_unprepare(stt);
338 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
340 ret = stt_prepare(stt);
342 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
347 /* call callback function */
348 if (NULL != client->engine_changed_cb) {
349 client->engine_changed_cb(stt, engine_id, language, support_silence, need_credential, client->engine_changed_user_data);
351 SLOG(LOG_WARN, TAG_STTC, "No registered callback function for engine change");
356 static int __stt_check_handle(stt_h stt, stt_client_s** client)
359 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input handle is null");
360 return STT_ERROR_INVALID_PARAMETER;
363 stt_client_s* temp = NULL;
364 temp = stt_client_get(stt);
368 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
369 return STT_ERROR_INVALID_PARAMETER;
373 return STT_ERROR_NONE;
376 int stt_create(stt_h* stt)
378 if (0 != __stt_get_feature_enabled()) {
379 return STT_ERROR_NOT_SUPPORTED;
381 if (0 != __stt_check_privilege()) {
382 return STT_ERROR_PERMISSION_DENIED;
385 SLOG(LOG_INFO, TAG_STTC, "===== Create STT");
388 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is null");
389 return STT_ERROR_INVALID_PARAMETER;
392 if (0 == stt_client_get_size()) {
393 if (0 != stt_dbus_open_connection()) {
395 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to open connection");
396 return STT_ERROR_OPERATION_FAILED;
401 if (0 != stt_client_new(stt)) {
403 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client!");
404 return STT_ERROR_OUT_OF_MEMORY;
408 stt_client_s* client = stt_client_get(*stt);
409 if (NULL == client) {
410 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client"); //LCOV_EXCL_LINE
411 stt_client_destroy(*stt);
412 return STT_ERROR_OPERATION_FAILED;
415 int ret = stt_config_mgr_initialize(client->uid);
416 ret = __stt_convert_config_error_code(ret);
418 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to init config manager : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
419 stt_client_destroy(*stt);
423 ret = stt_config_mgr_set_callback(client->uid, __stt_config_engine_changed_cb, __stt_config_lang_changed_cb, NULL, client->stt);
424 ret = __stt_convert_config_error_code(ret);
426 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set config changed : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
427 stt_client_destroy(*stt);
431 SLOG(LOG_INFO, TAG_STTC, "[Success] uid(%d)", (*stt)->handle);
433 SLOG(LOG_DEBUG, TAG_STTC, "=====");
434 SLOG(LOG_DEBUG, TAG_STTC, " ");
436 return STT_ERROR_NONE;
439 int stt_destroy(stt_h stt)
441 stt_client_s* client = NULL;
442 if (0 != __stt_get_feature_enabled()) {
443 return STT_ERROR_NOT_SUPPORTED;
445 if (0 != __stt_check_privilege()) {
446 return STT_ERROR_PERMISSION_DENIED;
448 if (0 != __stt_check_handle(stt, &client)) {
449 return STT_ERROR_INVALID_PARAMETER;
452 SLOG(LOG_INFO, TAG_STTC, "===== Destroy STT");
454 /* check used callback */
455 if (0 != stt_client_get_use_callback(client)) {
456 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Cannot destroy in Callback function");
457 return STT_ERROR_OPERATION_FAILED;
460 stt_config_mgr_finalize(client->uid);
465 switch (client->current_state) {
466 case STT_STATE_PROCESSING:
467 case STT_STATE_RECORDING:
468 case STT_STATE_READY:
469 ret = stt_dbus_request_finalize(client->uid);
471 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
473 case STT_STATE_CREATED:
474 if (NULL != g_connect_timer) {
475 SLOG(LOG_DEBUG, TAG_STTC, "Connect Timer is deleted");
476 ecore_timer_del(g_connect_timer);
477 g_connect_timer = NULL;
481 stt_client_destroy(stt);
487 if (0 == stt_client_get_size()) {
488 if (0 != stt_dbus_close_connection()) {
489 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to close connection"); //LCOV_EXCL_LINE
495 SLOG(LOG_INFO, TAG_STTC, "=====");
496 SLOG(LOG_DEBUG, TAG_STTC, " ");
498 return STT_ERROR_NONE;
501 bool __stt_config_supported_engine_cb(const char* engine_id, const char* engine_name,
502 const char* setting, bool support_silence, void* user_data)
504 stt_h stt = (stt_h)user_data;
506 stt_client_s* client = stt_client_get(stt);
507 if (NULL == client) {
509 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
514 /* call callback function */
515 if (NULL != client->supported_engine_cb) {
516 return client->supported_engine_cb(stt, engine_id, engine_name, client->supported_engine_user_data);
518 SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported engine"); //LCOV_EXCL_LINE
524 int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, void* user_data)
526 stt_client_s* client = NULL;
527 if (0 != __stt_get_feature_enabled()) {
528 return STT_ERROR_NOT_SUPPORTED;
530 if (0 != __stt_check_privilege()) {
531 return STT_ERROR_PERMISSION_DENIED;
533 if (0 != __stt_check_handle(stt, &client)) {
534 return STT_ERROR_INVALID_PARAMETER;
537 SLOG(LOG_INFO, TAG_STTC, "===== Foreach Supported engine");
539 if (NULL == callback) {
540 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
541 return STT_ERROR_INVALID_PARAMETER;
544 if (client->current_state != STT_STATE_CREATED) {
545 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state);
546 return STT_ERROR_INVALID_STATE;
549 client->supported_engine_cb = callback;
550 client->supported_engine_user_data = user_data;
553 ret = stt_config_mgr_get_engine_list(__stt_config_supported_engine_cb, client->stt);
554 ret = __stt_convert_config_error_code(ret);
556 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get engines : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
559 client->supported_engine_cb = NULL;
560 client->supported_engine_user_data = NULL;
562 SLOG(LOG_INFO, TAG_STTC, "=====");
563 SLOG(LOG_DEBUG, TAG_STTC, " ");
568 int stt_get_engine(stt_h stt, char** engine_id)
570 stt_client_s* client = NULL;
571 if (0 != __stt_get_feature_enabled()) {
572 return STT_ERROR_NOT_SUPPORTED;
574 if (0 != __stt_check_privilege()) {
575 return STT_ERROR_PERMISSION_DENIED;
577 if (0 != __stt_check_handle(stt, &client)) {
578 return STT_ERROR_INVALID_PARAMETER;
581 SLOG(LOG_INFO, TAG_STTC, "===== Get current engine");
583 if (NULL == engine_id) {
584 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
585 return STT_ERROR_INVALID_PARAMETER;
588 if (client->current_state != STT_STATE_CREATED) {
589 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state);
590 return STT_ERROR_INVALID_STATE;
595 if (NULL != client->current_engine_id) {
596 *engine_id = strdup(client->current_engine_id);
597 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", *engine_id);
600 ret = stt_config_mgr_get_engine(engine_id);
601 ret = __stt_convert_config_error_code(ret);
603 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request get current engine : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
605 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", *engine_id);
609 SLOG(LOG_INFO, TAG_STTC, "=====");
610 SLOG(LOG_DEBUG, TAG_STTC, " ");
615 int __stt_set_buxtonkey(const char* engine_id)
618 struct buxton_client * bux_cli;
619 struct buxton_layer * bux_layer;
620 struct buxton_value * bux_val;
622 int ret = buxton_open(&bux_cli, NULL, NULL);
624 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to open buxton client"); //LCOV_EXCL_LINE
625 return STT_ERROR_OPERATION_FAILED;
627 SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] buxton_open: %d", ret);
628 bux_layer = buxton_create_layer("system");
629 if (NULL == bux_layer) {
631 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_create_layer FAIL");
632 buxton_close(bux_cli);
634 return STT_ERROR_OPERATION_FAILED;
637 bux_val = buxton_value_create_string(engine_id);
638 if (NULL == bux_val) {
640 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_value_create_string FAIL");
641 buxton_free_layer(bux_layer);
642 buxton_close(bux_cli);
645 return STT_ERROR_OPERATION_FAILED;
649 ret = buxton_set_value_sync(bux_cli, bux_layer, STT_ENGINE_DB_CUSTOM, bux_val);
652 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to set value sync");
653 buxton_value_free(bux_val);
654 buxton_free_layer(bux_layer);
655 buxton_close(bux_cli);
660 return STT_ERROR_OPERATION_FAILED;
663 SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] buxton_set_value_sync: %d, %s", ret, STT_ENGINE_DB_CUSTOM);
665 buxton_value_free(bux_val);
666 buxton_free_layer(bux_layer);
667 buxton_close(bux_cli);
673 return STT_ERROR_NONE;
676 int stt_set_engine(stt_h stt, const char* engine_id)
678 stt_client_s* client = NULL;
679 if (0 != __stt_get_feature_enabled()) {
680 return STT_ERROR_NOT_SUPPORTED;
682 if (0 != __stt_check_privilege()) {
683 return STT_ERROR_PERMISSION_DENIED;
685 if (0 != __stt_check_privilege_for_applaunch()) {
686 return STT_ERROR_PERMISSION_DENIED;
688 if (0 != __stt_check_handle(stt, &client)) {
689 return STT_ERROR_INVALID_PARAMETER;
692 SLOG(LOG_INFO, TAG_STTC, "===== Set current engine");
694 if (NULL == engine_id) {
695 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
696 return STT_ERROR_INVALID_PARAMETER;
700 if (client->current_state != STT_STATE_CREATED) {
701 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state);
702 return STT_ERROR_INVALID_STATE;
705 if (NULL != client->current_engine_id) {
706 free(client->current_engine_id);
707 client->current_engine_id = NULL;
710 SLOG(LOG_INFO, TAG_STTC, "===== engined_id(%s)", engine_id);
712 client->current_engine_id = strdup(engine_id);
715 int ret = __stt_set_buxtonkey(engine_id);
717 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] set buxtonkey Failed!!!"); //LCOV_EXCL_LINE
721 SLOG(LOG_INFO, TAG_STTC, "=====");
722 SLOG(LOG_DEBUG, TAG_STTC, " ");
727 int stt_set_credential(stt_h stt, const char* credential)
729 stt_client_s* client = NULL;
730 if (0 != __stt_get_feature_enabled()) {
731 return STT_ERROR_NOT_SUPPORTED;
733 if (0 != __stt_check_privilege()) {
734 return STT_ERROR_PERMISSION_DENIED;
736 if (0 != __stt_check_handle(stt, &client)) {
737 return STT_ERROR_INVALID_PARAMETER;
740 SLOG(LOG_INFO, TAG_STTC, "===== Set credential");
742 if (NULL == credential) {
743 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
744 return STT_ERROR_INVALID_PARAMETER;
748 if (client->current_state != STT_STATE_CREATED && client->current_state != STT_STATE_READY) {
749 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED or READY", client->current_state); //LCOV_EXCL_LINE
750 return STT_ERROR_INVALID_STATE;
753 if (NULL != client->credential) {
754 free(client->credential);
755 client->credential = NULL;
757 client->credential = strdup(credential);
759 SLOG(LOG_INFO, TAG_STTC, "=====");
760 SLOG(LOG_DEBUG, TAG_STTC, " ");
762 return STT_ERROR_NONE;
765 int stt_set_private_data(stt_h stt, const char* key, const char* data)
767 stt_client_s* client = NULL;
768 if (0 != __stt_get_feature_enabled()) {
769 return STT_ERROR_NOT_SUPPORTED;
771 if (0 != __stt_check_privilege()) {
772 return STT_ERROR_PERMISSION_DENIED;
774 if (0 != __stt_check_handle(stt, &client)) {
775 return STT_ERROR_INVALID_PARAMETER;
778 SLOG(LOG_INFO, TAG_STTC, "===== Set private data");
780 if (NULL == key || NULL == data) {
781 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
782 return STT_ERROR_INVALID_PARAMETER;
786 if (STT_STATE_READY != client->current_state) {
787 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
788 return STT_ERROR_INVALID_STATE;
791 if (true != client->internal && (0 == strcmp(key, "server") || 0 == strcmp(key, "rampcode") || 0 == strcmp(key, "epd"))) {
792 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This is not an internal app"); //LCOV_EXCL_LINE
793 return STT_ERROR_INVALID_PARAMETER;
799 ret = stt_dbus_request_set_private_data(client->uid, key, data);
802 if (STT_ERROR_TIMED_OUT != ret) {
803 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data : %s", __stt_get_error_code(ret));
806 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry : %s", __stt_get_error_code(ret));
809 if (STT_RETRY_COUNT == count) {
810 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
818 SLOG(LOG_INFO, TAG_STTC, "=====");
819 SLOG(LOG_DEBUG, TAG_STTC, "");
821 return STT_ERROR_NONE;
824 int stt_get_private_data(stt_h stt, const char* key, char** data)
826 stt_client_s* client = NULL;
827 if (0 != __stt_get_feature_enabled()) {
828 return STT_ERROR_NOT_SUPPORTED;
830 if (0 != __stt_check_privilege()) {
831 return STT_ERROR_PERMISSION_DENIED;
833 if (0 != __stt_check_handle(stt, &client)) {
834 return STT_ERROR_INVALID_PARAMETER;
837 SLOG(LOG_INFO, TAG_STTC, "===== Get private data");
839 if (NULL == key || NULL == data) {
840 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
841 return STT_ERROR_INVALID_PARAMETER;
845 if (STT_STATE_READY != client->current_state) {
846 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
847 return STT_ERROR_INVALID_STATE;
853 ret = stt_dbus_request_get_private_data(client->uid, key, data);
856 if (STT_ERROR_TIMED_OUT != ret) {
857 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get private data : %s", __stt_get_error_code(ret));
860 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry : %s", __stt_get_error_code(ret));
863 if (STT_RETRY_COUNT == count) {
864 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
872 if (0 == strncmp(*data, "NULL", strlen(*data))) {
877 SLOG(LOG_INFO, TAG_STTC, "=====");
878 SLOG(LOG_DEBUG, TAG_STTC, "");
880 return STT_ERROR_NONE;
884 int stt_set_server_stt(stt_h stt, const char* key, char* user_data)
887 stt_client_s* client = NULL;
889 if (0 != __stt_get_feature_enabled()) {
890 return STT_ERROR_NOT_SUPPORTED;
892 if (0 != __stt_check_privilege()) {
893 return STT_ERROR_PERMISSION_DENIED;
895 if (0 != __stt_check_handle(stt, &client)) {
896 return STT_ERROR_INVALID_PARAMETER;
899 SLOG(LOG_INFO, TAG_STTC, "===== Set STT server");
901 if (NULL == key || NULL == user_data) {
902 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
903 return STT_ERROR_INVALID_PARAMETER;
906 if (STT_STATE_CREATED != client->current_state && STT_STATE_READY != client->current_state) {
907 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] The current state is invalid (%d).", client->current_state);
908 return STT_ERROR_INVALID_STATE;
912 client->internal = true;
914 char* private_key = NULL;
915 private_key = strdup(key);
916 if (NULL == private_key) {
917 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(private_key)");
918 return STT_ERROR_OUT_OF_MEMORY;
922 data = strdup(user_data);
924 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(data)");
927 return STT_ERROR_OUT_OF_MEMORY;
930 ret = stt_set_private_data(stt, private_key, data);
932 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data, ret(%d), key(%s)", ret, private_key);
940 SLOG(LOG_INFO, TAG_STTC, "======");
941 SLOG(LOG_DEBUG, TAG_STTC, " ");
947 static Eina_Bool __stt_connect_daemon(void *data)
949 stt_client_s* client = (stt_client_s*)data;
952 if (NULL == client) {
953 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); //LCOV_EXCL_LINE
954 g_connect_timer = NULL;
958 if (0 == stt_client_get_size() || NULL == stt_client_get_by_uid(client->uid)) {
959 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Client has been already destroyed"); //LCOV_EXCL_LINE
963 /* Check and Set vconfkey of custom engine before sending hello */
964 if (1 == g_privilege_applaunch_allowed && NULL != client->current_engine_id) {
966 ret = __stt_set_buxtonkey(client->current_engine_id);
969 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] set buxtonkey Failed!!! (inside __stt_connect_daemon)");
976 ret = stt_dbus_request_hello(client->uid);
979 if (STT_ERROR_INVALID_STATE == ret) {
980 g_connect_timer = NULL;
986 g_connect_timer = NULL;
987 SLOG(LOG_INFO, TAG_STTC, "===== Connect stt-service");
989 /* request initialization */
990 bool silence_supported = false;
991 bool credential_needed = false;
993 ret = stt_dbus_request_initialize(client->uid, &silence_supported, &credential_needed);
995 if (STT_ERROR_ENGINE_NOT_FOUND == ret) {
996 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
998 client->reason = STT_ERROR_ENGINE_NOT_FOUND;
999 ecore_main_loop_thread_safe_call_async(__stt_notify_error, (void*)client);
1003 } else if (STT_ERROR_NONE != ret) {
1004 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] Fail to connection. Retry to connect"); //LCOV_EXCL_LINE
1007 /* success to connect stt-service */
1008 client->silence_supported = silence_supported;
1009 client->credential_needed = credential_needed;
1010 SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need");
1014 #ifdef __UNUSED_CODES__
1015 if (NULL != client->current_engine_id) {
1018 silence_supported = false;
1019 credential_needed = false;
1020 SLOG(LOG_DEBUG, TAG_STTC, "[WARNING] current_engine_id(%s)", client->current_engine_id);
1023 ret = stt_dbus_request_set_current_engine(client->uid, client->current_engine_id, &silence_supported, &credential_needed);
1025 if (STT_ERROR_TIMED_OUT != ret) {
1026 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set current engine : %s", __stt_get_error_code(ret));
1029 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1032 if (STT_RETRY_COUNT == count) {
1033 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1038 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", client->current_engine_id);
1040 /* success to change engine */
1041 client->silence_supported = silence_supported;
1042 SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need");
1048 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] uid(%d)", client->uid);
1050 client->before_state = client->current_state;
1051 client->current_state = STT_STATE_READY;
1053 if (NULL != client->state_changed_cb) {
1054 stt_client_use_callback(client);
1055 client->state_changed_cb(client->stt, client->before_state,
1056 client->current_state, client->state_changed_user_data);
1057 stt_client_not_use_callback(client);
1058 SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called");
1060 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
1063 SLOG(LOG_INFO, TAG_STTC, "=====");
1064 SLOG(LOG_DEBUG, TAG_STTC, " ");
1069 int stt_prepare(stt_h stt)
1071 stt_client_s* client = NULL;
1072 if (0 != __stt_get_feature_enabled()) {
1073 return STT_ERROR_NOT_SUPPORTED;
1075 if (0 != __stt_check_privilege()) {
1076 return STT_ERROR_PERMISSION_DENIED;
1078 if (0 != __stt_check_handle(stt, &client)) {
1079 return STT_ERROR_INVALID_PARAMETER;
1082 SLOG(LOG_INFO, TAG_STTC, "===== Prepare STT");
1085 if (client->current_state != STT_STATE_CREATED) {
1086 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'CREATED'", client->current_state);
1087 return STT_ERROR_INVALID_STATE;
1090 ecore_thread_main_loop_begin();
1091 g_connect_timer = ecore_timer_add(0.02, __stt_connect_daemon, (void*)client);
1092 ecore_thread_main_loop_end();
1094 SLOG(LOG_INFO, TAG_STTC, "=====");
1095 SLOG(LOG_DEBUG, TAG_STTC, " ");
1097 return STT_ERROR_NONE;
1100 int stt_unprepare(stt_h stt)
1102 stt_client_s* client = NULL;
1103 if (0 != __stt_get_feature_enabled()) {
1104 return STT_ERROR_NOT_SUPPORTED;
1106 if (0 != __stt_check_privilege()) {
1107 return STT_ERROR_PERMISSION_DENIED;
1109 if (0 != __stt_check_handle(stt, &client)) {
1110 return STT_ERROR_INVALID_PARAMETER;
1113 SLOG(LOG_INFO, TAG_STTC, "===== Unprepare STT");
1116 if (client->current_state != STT_STATE_READY) {
1117 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'READY'", client->current_state);
1118 return STT_ERROR_INVALID_STATE;
1124 ret = stt_dbus_request_finalize(client->uid);
1127 if (STT_ERROR_TIMED_OUT != ret) {
1128 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize : %s", __stt_get_error_code(ret));
1131 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1134 if (STT_RETRY_COUNT == count) {
1135 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1143 client->internal_state = STT_INTERNAL_STATE_NONE;
1145 client->before_state = client->current_state;
1146 client->current_state = STT_STATE_CREATED;
1148 if (NULL != client->state_changed_cb) {
1149 stt_client_use_callback(client);
1150 client->state_changed_cb(client->stt, client->before_state,
1151 client->current_state, client->state_changed_user_data);
1152 stt_client_not_use_callback(client);
1154 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
1157 if (g_connect_timer) {
1158 ecore_timer_del(g_connect_timer);
1159 g_connect_timer = NULL;
1162 SLOG(LOG_INFO, TAG_STTC, "=====");
1163 SLOG(LOG_DEBUG, TAG_STTC, " ");
1165 return STT_ERROR_NONE;
1168 bool __stt_config_supported_language_cb(const char* engine_id, const char* language, void* user_data)
1170 stt_h stt = (stt_h)user_data;
1172 stt_client_s* client = stt_client_get(stt);
1173 if (NULL == client) {
1174 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid"); //LCOV_EXCL_LINE
1178 SLOG(LOG_INFO, TAG_STTC, "===== supported language callback");
1180 /* call callback function */
1181 if (NULL != client->supported_lang_cb) {
1182 return client->supported_lang_cb(stt, language, client->supported_lang_user_data);
1184 SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported languages"); //LCOV_EXCL_LINE
1190 int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callback, void* user_data)
1192 stt_client_s* client = NULL;
1193 if (0 != __stt_get_feature_enabled()) {
1194 return STT_ERROR_NOT_SUPPORTED;
1196 if (0 != __stt_check_privilege()) {
1197 return STT_ERROR_PERMISSION_DENIED;
1199 if (0 != __stt_check_handle(stt, &client)) {
1200 return STT_ERROR_INVALID_PARAMETER;
1203 SLOG(LOG_INFO, TAG_STTC, "===== Foreach Supported Language");
1205 if (NULL == callback) {
1206 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1207 return STT_ERROR_INVALID_PARAMETER;
1211 char* current_engine_id = NULL;
1213 if (NULL == client->current_engine_id) {
1214 ret = stt_config_mgr_get_engine(¤t_engine_id);
1215 ret = __stt_convert_config_error_code(ret);
1217 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get default engine id : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1221 current_engine_id = strdup(client->current_engine_id);
1223 if (NULL == current_engine_id) {
1224 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
1225 return STT_ERROR_OUT_OF_MEMORY;
1230 client->supported_lang_cb = callback;
1231 client->supported_lang_user_data = user_data;
1233 ret = stt_config_mgr_get_language_list(current_engine_id, __stt_config_supported_language_cb, client->stt);
1234 ret = __stt_convert_config_error_code(ret);
1236 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get languages : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1239 if (NULL != current_engine_id) {
1240 free(current_engine_id);
1241 current_engine_id = NULL;
1244 client->supported_lang_cb = NULL;
1245 client->supported_lang_user_data = NULL;
1247 SLOG(LOG_INFO, TAG_STTC, "=====");
1248 SLOG(LOG_DEBUG, TAG_STTC, " ");
1253 int stt_get_default_language(stt_h stt, char** language)
1255 stt_client_s* client = NULL;
1256 if (0 != __stt_get_feature_enabled()) {
1257 return STT_ERROR_NOT_SUPPORTED;
1259 if (0 != __stt_check_privilege()) {
1260 return STT_ERROR_PERMISSION_DENIED;
1262 if (0 != __stt_check_handle(stt, &client)) {
1263 return STT_ERROR_INVALID_PARAMETER;
1266 SLOG(LOG_INFO, TAG_STTC, "===== Get Default Language");
1268 if (NULL == language) {
1269 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1270 return STT_ERROR_INVALID_PARAMETER;
1274 ret = stt_config_mgr_get_default_language(language);
1275 ret = __stt_convert_config_error_code(ret);
1277 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get default language : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1279 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current language = %s", *language);
1282 SLOG(LOG_INFO, TAG_STTC, "=====");
1283 SLOG(LOG_DEBUG, TAG_STTC, " ");
1288 int stt_get_state(stt_h stt, stt_state_e* state)
1290 stt_client_s* client = NULL;
1291 if (0 != __stt_get_feature_enabled()) {
1292 return STT_ERROR_NOT_SUPPORTED;
1294 if (0 != __stt_check_privilege()) {
1295 return STT_ERROR_PERMISSION_DENIED;
1297 if (0 != __stt_check_handle(stt, &client)) {
1298 return STT_ERROR_INVALID_PARAMETER;
1301 if (NULL == state) {
1302 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1303 return STT_ERROR_INVALID_PARAMETER;
1306 *state = client->current_state;
1308 SLOG(LOG_INFO, TAG_STTC, "===== Get state(%d)", *state);
1311 case STT_STATE_CREATED: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'CREATED'"); break;
1312 case STT_STATE_READY: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Ready'"); break;
1313 case STT_STATE_RECORDING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Recording'"); break;
1314 case STT_STATE_PROCESSING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Processing'"); break;
1315 default: SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid value"); break;
1318 return STT_ERROR_NONE;
1321 int stt_get_error_message(stt_h stt, char** err_msg)
1323 stt_client_s* client = NULL;
1324 if (0 != __stt_get_feature_enabled()) {
1325 return STT_ERROR_NOT_SUPPORTED;
1327 if (0 != __stt_check_privilege()) {
1328 return STT_ERROR_PERMISSION_DENIED;
1330 if (0 != __stt_check_handle(stt, &client)) {
1331 return STT_ERROR_INVALID_PARAMETER;
1334 if (NULL == err_msg) {
1335 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
1336 return STT_ERROR_INVALID_PARAMETER;
1339 if (false == g_err_callback_status) {
1340 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This callback should be called during an err_callback");
1341 return STT_ERROR_OPERATION_FAILED;
1344 if (NULL != client->err_msg) {
1345 *err_msg = strdup(client->err_msg);
1346 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Error msg (%s)", *err_msg); //LCOV_EXCL_LINE
1348 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Error msg (NULL)"); //LCOV_EXCL_LINE
1351 SLOG(LOG_INFO, TAG_STTC, "====="); //LCOV_EXCL_LINE
1352 SLOG(LOG_DEBUG, TAG_STTC, " "); //LCOV_EXCL_LINE
1354 return STT_ERROR_NONE;
1357 int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support)
1359 stt_client_s* client = NULL;
1360 if (0 != __stt_get_feature_enabled()) {
1361 return STT_ERROR_NOT_SUPPORTED;
1363 if (0 != __stt_check_privilege()) {
1364 return STT_ERROR_PERMISSION_DENIED;
1366 if (0 != __stt_check_handle(stt, &client)) {
1367 return STT_ERROR_INVALID_PARAMETER;
1370 if (NULL == type || NULL == support) {
1371 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1372 return STT_ERROR_INVALID_PARAMETER;
1376 if (client->current_state != STT_STATE_READY) {
1377 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1378 return STT_ERROR_INVALID_STATE;
1384 ret = stt_dbus_request_is_recognition_type_supported(client->uid, type, support);
1387 if (STT_ERROR_TIMED_OUT != ret) {
1388 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get recognition type supported : %s", __stt_get_error_code(ret));
1391 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1394 if (STT_RETRY_COUNT == count) {
1395 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1401 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] recognition type is %s", *support ? "true " : "false");
1406 return STT_ERROR_NONE;
1409 int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type)
1411 stt_client_s* client = NULL;
1412 if (0 != __stt_get_feature_enabled()) {
1413 return STT_ERROR_NOT_SUPPORTED;
1415 if (0 != __stt_check_privilege()) {
1416 return STT_ERROR_PERMISSION_DENIED;
1418 if (0 != __stt_check_handle(stt, &client)) {
1419 return STT_ERROR_INVALID_PARAMETER;
1423 if (client->current_state != STT_STATE_READY) {
1424 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1425 return STT_ERROR_INVALID_STATE;
1428 SLOG(LOG_INFO, TAG_STTC, "===== Set silence detection, supported(%d), type(%d)", client->silence_supported, type);
1430 if (true == client->silence_supported) {
1431 if (type >= STT_OPTION_SILENCE_DETECTION_FALSE && type <= STT_OPTION_SILENCE_DETECTION_AUTO) {
1432 client->silence = type;
1434 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Type is invalid");
1435 return STT_ERROR_INVALID_PARAMETER;
1438 return STT_ERROR_NOT_SUPPORTED_FEATURE;
1441 return STT_ERROR_NONE;
1444 int stt_set_start_sound(stt_h stt, const char* filename)
1446 stt_client_s* client = NULL;
1447 if (0 != __stt_get_feature_enabled()) {
1448 return STT_ERROR_NOT_SUPPORTED;
1450 if (0 != __stt_check_privilege()) {
1451 return STT_ERROR_PERMISSION_DENIED;
1453 if (0 != __stt_check_handle(stt, &client)) {
1454 return STT_ERROR_INVALID_PARAMETER;
1457 SLOG(LOG_INFO, TAG_STTC, "===== STT SET START SOUND");
1459 if (NULL == filename) {
1460 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1461 return STT_ERROR_INVALID_PARAMETER;
1464 if (0 != access(filename, F_OK)) {
1465 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] File does not exist"); //LCOV_EXCL_LINE
1466 return STT_ERROR_INVALID_PARAMETER;
1470 if (client->current_state != STT_STATE_READY) {
1471 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); //LCOV_EXCL_LINE
1472 return STT_ERROR_INVALID_STATE;
1478 ret = stt_dbus_request_set_start_sound(client->uid, filename);
1481 if (STT_ERROR_TIMED_OUT != ret) {
1482 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set start sound : %s", __stt_get_error_code(ret));
1485 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1488 if (STT_RETRY_COUNT == count) {
1489 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1495 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Set start sound : %s", filename);
1500 return STT_ERROR_NONE;
1503 int stt_unset_start_sound(stt_h stt)
1505 stt_client_s* client = NULL;
1506 if (0 != __stt_get_feature_enabled()) {
1507 return STT_ERROR_NOT_SUPPORTED;
1509 if (0 != __stt_check_privilege()) {
1510 return STT_ERROR_PERMISSION_DENIED;
1512 if (0 != __stt_check_handle(stt, &client)) {
1513 return STT_ERROR_INVALID_PARAMETER;
1516 SLOG(LOG_INFO, TAG_STTC, "===== STT UNSET START SOUND");
1519 if (client->current_state != STT_STATE_READY) {
1520 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1521 return STT_ERROR_INVALID_STATE;
1527 ret = stt_dbus_request_unset_start_sound(client->uid);
1530 if (STT_ERROR_TIMED_OUT != ret) {
1531 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to unset start sound : %s", __stt_get_error_code(ret));
1534 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1537 if (STT_RETRY_COUNT == count) {
1538 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1544 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Unset start sound");
1549 return STT_ERROR_NONE;
1552 int stt_set_stop_sound(stt_h stt, const char* filename)
1554 stt_client_s* client = NULL;
1555 if (0 != __stt_get_feature_enabled()) {
1556 return STT_ERROR_NOT_SUPPORTED;
1558 if (0 != __stt_check_privilege()) {
1559 return STT_ERROR_PERMISSION_DENIED;
1561 if (0 != __stt_check_handle(stt, &client)) {
1562 return STT_ERROR_INVALID_PARAMETER;
1565 SLOG(LOG_INFO, TAG_STTC, "===== STT SET STOP SOUND");
1567 if (NULL == filename) {
1568 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1569 return STT_ERROR_INVALID_PARAMETER;
1572 if (0 != access(filename, F_OK)) {
1573 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] File does not exist"); //LCOV_EXCL_LINE
1574 return STT_ERROR_INVALID_PARAMETER;
1578 if (client->current_state != STT_STATE_READY) {
1579 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); //LCOV_EXCL_LINE
1580 return STT_ERROR_INVALID_STATE;
1586 ret = stt_dbus_request_set_stop_sound(client->uid, filename);
1589 if (STT_ERROR_TIMED_OUT != ret) {
1590 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set stop sound : %s", __stt_get_error_code(ret));
1593 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1596 if (STT_RETRY_COUNT == count) {
1597 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1603 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Set stop sound : %s", filename);
1608 return STT_ERROR_NONE;
1611 int stt_unset_stop_sound(stt_h stt)
1613 stt_client_s* client = NULL;
1614 if (0 != __stt_get_feature_enabled()) {
1615 return STT_ERROR_NOT_SUPPORTED;
1617 if (0 != __stt_check_privilege()) {
1618 return STT_ERROR_PERMISSION_DENIED;
1620 if (0 != __stt_check_handle(stt, &client)) {
1621 return STT_ERROR_INVALID_PARAMETER;
1624 SLOG(LOG_INFO, TAG_STTC, "===== STT UNSET STOP SOUND");
1627 if (client->current_state != STT_STATE_READY) {
1628 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1629 return STT_ERROR_INVALID_STATE;
1635 ret = stt_dbus_request_unset_stop_sound(client->uid);
1638 if (STT_ERROR_TIMED_OUT != ret) {
1639 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to unset stop sound : %s", __stt_get_error_code(ret));
1642 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1645 if (STT_RETRY_COUNT == count) {
1646 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1652 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Unset stop sound");
1657 return STT_ERROR_NONE;
1660 int stt_start(stt_h stt, const char* language, const char* type)
1662 stt_client_s* client = NULL;
1663 if (0 != __stt_get_feature_enabled()) {
1664 return STT_ERROR_NOT_SUPPORTED;
1666 if (0 != __stt_check_privilege()) {
1667 return STT_ERROR_PERMISSION_DENIED;
1669 if (0 != __stt_check_handle(stt, &client)) {
1670 return STT_ERROR_INVALID_PARAMETER;
1673 SLOG(LOG_INFO, TAG_STTC, "===== STT START");
1676 if (client->current_state != STT_STATE_READY) {
1677 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1678 return STT_ERROR_INVALID_STATE;
1681 if (STT_INTERNAL_STATE_NONE != client->internal_state) {
1682 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state); //LCOV_EXCL_LINE
1683 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
1687 char appid[1024] = {0, };
1688 ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1);
1690 if ((AUL_R_OK != ret) || (0 == strlen(appid))) {
1691 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID"); //LCOV_EXCL_LINE
1693 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Current app id is %s", appid);
1697 if (NULL == language) {
1698 temp = strdup("default");
1700 temp = strdup(language);
1704 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
1705 return STT_ERROR_OUT_OF_MEMORY;
1708 if (true == client->credential_needed && NULL == client->credential) {
1709 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id); //LCOV_EXCL_LINE
1712 return STT_ERROR_PERMISSION_DENIED;
1715 client->internal_state = STT_INTERNAL_STATE_STARTING;
1716 ret = stt_dbus_request_start(client->uid, temp, type, client->silence, appid, client->credential);
1718 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1719 client->internal_state = STT_INTERNAL_STATE_NONE;
1721 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Start is successful but not done");
1727 SLOG(LOG_INFO, TAG_STTC, "=====");
1728 SLOG(LOG_DEBUG, TAG_STTC, " ");
1733 int stt_stop(stt_h stt)
1735 stt_client_s* client = NULL;
1736 if (0 != __stt_get_feature_enabled()) {
1737 return STT_ERROR_NOT_SUPPORTED;
1739 if (0 != __stt_check_privilege()) {
1740 return STT_ERROR_PERMISSION_DENIED;
1742 if (0 != __stt_check_handle(stt, &client)) {
1743 return STT_ERROR_INVALID_PARAMETER;
1746 SLOG(LOG_INFO, TAG_STTC, "===== STT STOP");
1749 if (client->current_state != STT_STATE_RECORDING) {
1750 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Current state(%d) is NOT RECORDING", client->current_state); //LCOV_EXCL_LINE
1751 return STT_ERROR_INVALID_STATE;
1754 if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
1755 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state); //LCOV_EXCL_LINE
1756 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
1757 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
1758 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); //LCOV_EXCL_LINE
1759 return STT_ERROR_IN_PROGRESS_TO_READY;
1760 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
1761 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); //LCOV_EXCL_LINE
1762 return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
1765 client->internal_state = STT_INTERNAL_STATE_STOPPING;
1766 int ret = stt_dbus_request_stop(client->uid);
1768 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to stop : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1769 client->internal_state = STT_INTERNAL_STATE_NONE;
1771 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Stop is successful but not done");
1774 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1775 SLOG(LOG_DEBUG, TAG_STTC, " ");
1781 int stt_cancel(stt_h stt)
1783 stt_client_s* client = NULL;
1784 if (0 != __stt_get_feature_enabled()) {
1785 return STT_ERROR_NOT_SUPPORTED;
1787 if (0 != __stt_check_privilege()) {
1788 return STT_ERROR_PERMISSION_DENIED;
1790 if (0 != __stt_check_handle(stt, &client)) {
1791 return STT_ERROR_INVALID_PARAMETER;
1794 SLOG(LOG_INFO, TAG_STTC, "===== STT CANCEL");
1797 if (STT_STATE_RECORDING != client->current_state && STT_STATE_PROCESSING != client->current_state) {
1798 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid state : Current state(%d) is 'Ready'", client->current_state); //LCOV_EXCL_LINE
1799 return STT_ERROR_INVALID_STATE;
1802 if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
1803 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state); //LCOV_EXCL_LINE
1804 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
1805 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
1806 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); //LCOV_EXCL_LINE
1807 return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
1808 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
1809 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); //LCOV_EXCL_LINE
1810 return STT_ERROR_IN_PROGRESS_TO_READY;
1813 client->internal_state = STT_INTERNAL_STATE_CANCELING;
1814 int ret = stt_dbus_request_cancel(client->uid);
1816 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to cancel : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1817 client->internal_state = STT_INTERNAL_STATE_NONE;
1819 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Cancel is successful but not done");
1822 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1823 SLOG(LOG_DEBUG, TAG_STTC, " ");
1828 int __stt_cb_set_volume(int uid, float volume)
1830 stt_client_s* client = NULL;
1832 client = stt_client_get_by_uid(uid);
1833 if (NULL == client) {
1835 SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid");
1836 return STT_ERROR_INVALID_PARAMETER;
1840 if (STT_STATE_RECORDING != client->current_state) {
1842 SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state);
1843 return STT_ERROR_INVALID_STATE;
1847 g_volume_db = volume;
1848 SLOG(LOG_INFO, TAG_STTC, "Set volume (%f)", g_volume_db);
1853 int stt_get_recording_volume(stt_h stt, float* volume)
1855 stt_client_s* client = NULL;
1856 if (0 != __stt_get_feature_enabled()) {
1857 return STT_ERROR_NOT_SUPPORTED;
1859 if (0 != __stt_check_privilege()) {
1860 return STT_ERROR_PERMISSION_DENIED;
1862 if (0 != __stt_check_handle(stt, &client)) {
1863 return STT_ERROR_INVALID_PARAMETER;
1866 if (NULL == volume) {
1867 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1868 return STT_ERROR_INVALID_PARAMETER;
1871 if (STT_STATE_RECORDING != client->current_state) {
1872 SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state); //LCOV_EXCL_LINE
1873 return STT_ERROR_INVALID_STATE;
1876 *volume = g_volume_db;
1878 SLOG(LOG_INFO, TAG_STTC, "Get recording volume (%f)", *volume);
1880 return STT_ERROR_NONE;
1884 bool __stt_result_time_cb(int index, int event, const char* text, long start_time, long end_time, void* user_data)
1886 stt_client_s* client = (stt_client_s*)user_data;
1889 if (NULL == client) {
1890 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid");
1894 if (NULL != client->result_time_cb) {
1895 SLOG(LOG_INFO, TAG_STTC, "(%d) event(%d) text(%s) start(%ld) end(%ld)",
1896 index, event, text, start_time, end_time);
1897 client->result_time_cb(client->stt, index, (stt_result_time_event_e)event,
1898 text, start_time, end_time, client->result_time_user_data);
1900 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Callback is NULL");
1908 int stt_foreach_detailed_result(stt_h stt, stt_result_time_cb callback, void* user_data)
1910 stt_client_s* client = NULL;
1911 if (0 != __stt_get_feature_enabled()) {
1912 return STT_ERROR_NOT_SUPPORTED;
1914 if (0 != __stt_check_privilege()) {
1915 return STT_ERROR_PERMISSION_DENIED;
1917 if (0 != __stt_check_handle(stt, &client)) {
1918 return STT_ERROR_INVALID_PARAMETER;
1921 SLOG(LOG_INFO, TAG_STTC, "===== STT FOREACH DETAILED RESULT");
1923 if (NULL == callback) {
1924 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1925 return STT_ERROR_INVALID_PARAMETER;
1928 client->result_time_cb = callback;
1929 client->result_time_user_data = user_data;
1932 ret = stt_config_mgr_foreach_time_info(__stt_result_time_cb, client);
1933 ret = __stt_convert_config_error_code(ret);
1935 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to foreach time info : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1938 client->result_time_cb = NULL;
1939 client->result_time_user_data = NULL;
1941 SLOG(LOG_INFO, TAG_STTC, "=====");
1942 SLOG(LOG_DEBUG, TAG_STTC, " ");
1947 static void __stt_notify_error(void *data)
1949 stt_client_s* client = (stt_client_s*)data;
1951 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error from sttd");
1954 if (NULL == client) {
1955 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); //LCOV_EXCL_LINE
1959 if (NULL == stt_client_get_by_uid(client->uid))
1962 if (NULL != client->error_cb) {
1963 stt_client_use_callback(client);
1964 g_err_callback_status = true;
1965 client->error_cb(client->stt, client->reason, client->error_user_data);
1966 g_err_callback_status = false;
1967 stt_client_not_use_callback(client);
1968 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is called : reason [%d]", client->reason);
1970 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null"); //LCOV_EXCL_LINE
1976 int __stt_cb_error(int uid, int reason, char* err_msg)
1980 GList* client_list = NULL;
1981 client_list = stt_client_get_client_list();
1984 stt_client_s *data = NULL;
1986 if (g_list_length(client_list) > 0) {
1987 /* Get a first item */
1988 iter = g_list_first(client_list);
1990 while (NULL != iter) {
1993 data->reason = reason;
1994 data->internal_state = STT_INTERNAL_STATE_NONE;
1995 if (NULL != data->err_msg) {
1996 free(data->err_msg);
1997 data->err_msg = NULL;
1999 if (NULL != err_msg)
2000 data->err_msg = strdup(err_msg);
2002 SLOG(LOG_INFO, TAG_STTC, "internal state is initialized to 0");
2004 if (NULL != data->error_cb) {
2005 ecore_main_loop_thread_safe_call_async(__stt_notify_error, data);
2007 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
2010 if (STT_ERROR_SERVICE_RESET == reason) {
2011 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Service reset");
2013 data->current_state = STT_STATE_CREATED;
2014 if (0 != stt_prepare(data->stt)) {
2015 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare");
2020 iter = g_list_next(iter);
2025 stt_client_s* client = stt_client_get_by_uid(uid);
2026 if (NULL == client) {
2027 SLOG(LOG_ERROR, TAG_STTC, "Handle not found"); //LCOV_EXCL_LINE
2031 client->reason = reason;
2032 client->internal_state = STT_INTERNAL_STATE_NONE;
2033 if (NULL != client->err_msg) {
2034 free(client->err_msg);
2035 client->err_msg = NULL;
2037 if (NULL != err_msg)
2038 client->err_msg = strdup(err_msg);
2040 SLOG(LOG_INFO, TAG_STTC, "internal state is initialized to 0");
2042 if (NULL != client->error_cb) {
2043 ecore_main_loop_thread_safe_call_async(__stt_notify_error, client);
2045 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
2048 if (STT_ERROR_SERVICE_RESET == reason) {
2049 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Service reset"); //LCOV_EXCL_LINE
2051 client->current_state = STT_STATE_CREATED;
2052 if (0 != stt_prepare(client->stt)) {
2053 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare"); //LCOV_EXCL_LINE
2061 static void __stt_notify_state_changed(void *data)
2063 stt_client_s* client = (stt_client_s*)data;
2066 if (NULL == client) {
2067 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); //LCOV_EXCL_LINE
2071 if (NULL == stt_client_get_by_uid(client->uid)) {
2075 if (STT_INTERNAL_STATE_STARTING == client->internal_state && STT_STATE_RECORDING == client->current_state) {
2076 client->internal_state = STT_INTERNAL_STATE_NONE;
2077 SLOG(LOG_INFO, TAG_STTC, "Internal state change to NONE");
2078 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state && STT_STATE_PROCESSING == client->current_state) {
2079 client->internal_state = STT_INTERNAL_STATE_NONE;
2080 SLOG(LOG_INFO, TAG_STTC, "Internal state change to NONE");
2081 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state && STT_STATE_READY == client->current_state) {
2082 client->internal_state = STT_INTERNAL_STATE_NONE;
2083 SLOG(LOG_INFO, TAG_STTC, "Internal state change to NONE");
2086 if (NULL != client->state_changed_cb) {
2087 stt_client_use_callback(client);
2088 client->state_changed_cb(client->stt, client->before_state,
2089 client->current_state, client->state_changed_user_data);
2090 stt_client_not_use_callback(client);
2091 SLOG(LOG_INFO, TAG_STTC, "State changed callback is called, State(%d)", client->current_state);
2093 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null, State(%d)", client->current_state); //LCOV_EXCL_LINE
2099 static Eina_Bool __stt_notify_result(void *data)
2101 stt_client_s* client = (stt_client_s*)data;
2104 if (NULL == client) {
2105 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); //LCOV_EXCL_LINE
2109 if (NULL == stt_client_get_by_uid(client->uid)) {
2113 if (NULL != client->recognition_result_cb) {
2114 stt_client_use_callback(client);
2115 client->recognition_result_cb(client->stt, client->event, (const char**)client->data_list, client->data_count,
2116 client->msg, client->recognition_result_user_data);
2117 stt_client_not_use_callback(client);
2118 SLOG(LOG_INFO, TAG_STTC, "client recognition result callback called");
2120 SLOG(LOG_WARN, TAG_STTC, "[WARNING] User recognition result callback is NULL");
2123 if (NULL != client->msg) {
2128 if (NULL != client->data_list) {
2130 temp = client->data_list;
2133 for (i = 0; i < client->data_count; i++) {
2134 if (NULL != temp[i]) {
2138 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result data is error"); //LCOV_EXCL_LINE
2141 free(client->data_list);
2142 client->data_list = NULL;
2145 client->data_count = 0;
2147 stt_config_mgr_remove_time_info_file();
2149 if (STT_RESULT_EVENT_FINAL_RESULT == client->event || STT_RESULT_EVENT_ERROR == client->event) {
2150 client->before_state = client->current_state;
2151 client->current_state = STT_STATE_READY;
2153 if (NULL != client->state_changed_cb) {
2154 ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client);
2156 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); //LCOV_EXCL_LINE
2163 int __stt_cb_result(int uid, int event, char** data, int data_count, const char* msg)
2165 stt_client_s* client = NULL;
2167 client = stt_client_get_by_uid(uid);
2168 if (NULL == client) {
2169 SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid"); //LCOV_EXCL_LINE
2170 return STT_ERROR_INVALID_PARAMETER;
2174 SECURE_SLOG(LOG_INFO, TAG_STTC, "Recognition Result Message = %s", msg);
2177 for (i = 0; i < data_count; i++) {
2178 if (NULL != data[i])
2179 SECURE_SLOG(LOG_INFO, TAG_STTC, "Recognition Result[%d] = %s", i, data[i]);
2182 if (NULL != client->recognition_result_cb) {
2183 client->event = event;
2185 client->msg = strdup(msg);
2188 client->data_count = data_count;
2190 if (data_count > 0) {
2192 temp = (char**)calloc(data_count, sizeof(char*));
2194 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); //LCOV_EXCL_LINE
2195 return STT_ERROR_OUT_OF_MEMORY;
2198 for (i = 0; i < data_count; i++) {
2199 if (NULL != data[i])
2200 temp[i] = strdup(data[i]);
2202 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result data is error"); //LCOV_EXCL_LINE
2205 client->data_list = temp;
2208 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] User result callback is null");
2211 __stt_notify_result(client);
2213 return STT_ERROR_NONE;
2216 int __stt_cb_set_state(int uid, int state)
2218 stt_client_s* client = stt_client_get_by_uid(uid);
2219 if (NULL == client) {
2220 SLOG(LOG_ERROR, TAG_STTC, "Handle not found"); //LCOV_EXCL_LINE
2224 stt_state_e state_from_daemon = (stt_state_e)state;
2226 if (client->current_state == state_from_daemon) {
2227 SLOG(LOG_DEBUG, TAG_STTC, "Current state has already been %d", client->current_state);
2231 client->before_state = client->current_state;
2232 client->current_state = state_from_daemon;
2234 ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client);
2238 static void __stt_notify_speech_status(void *data)
2240 stt_client_s* client = (stt_client_s*)data;
2243 if (NULL == client) {
2244 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify speech status : A handle is not valid"); //LCOV_EXCL_LINE
2248 if (NULL == stt_client_get_by_uid(client->uid)) {
2252 if (NULL != client->speech_status_cb) {
2253 stt_client_use_callback(client);
2254 client->speech_status_cb(client->stt, client->speech_status, client->speech_status_user_data);
2255 stt_client_not_use_callback(client);
2256 SLOG(LOG_INFO, TAG_STTC, "Speech status callback is called"); //LCOV_EXCL_LINE
2258 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Speech status callback is null"); //LCOV_EXCL_LINE
2264 int __stt_cb_speech_status(int uid, int status)
2266 stt_client_s* client = stt_client_get_by_uid(uid);
2267 if (NULL == client) {
2268 SLOG(LOG_ERROR, TAG_STTC, "Handle not found"); //LCOV_EXCL_LINE
2272 client->speech_status = status;
2274 ecore_main_loop_thread_safe_call_async(__stt_notify_speech_status, client);
2278 int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, void* user_data)
2280 stt_client_s* client = NULL;
2281 if (0 != __stt_get_feature_enabled()) {
2282 return STT_ERROR_NOT_SUPPORTED;
2284 if (0 != __stt_check_privilege()) {
2285 return STT_ERROR_PERMISSION_DENIED;
2287 if (0 != __stt_check_handle(stt, &client)) {
2288 return STT_ERROR_INVALID_PARAMETER;
2291 if (callback == NULL)
2292 return STT_ERROR_INVALID_PARAMETER;
2294 if (STT_STATE_CREATED != client->current_state) {
2295 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2296 return STT_ERROR_INVALID_STATE;
2299 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set recognition result cb");
2301 client->recognition_result_cb = callback;
2302 client->recognition_result_user_data = user_data;
2307 int stt_unset_recognition_result_cb(stt_h stt)
2309 stt_client_s* client = NULL;
2310 if (0 != __stt_get_feature_enabled()) {
2311 return STT_ERROR_NOT_SUPPORTED;
2313 if (0 != __stt_check_privilege()) {
2314 return STT_ERROR_PERMISSION_DENIED;
2316 if (0 != __stt_check_handle(stt, &client)) {
2317 return STT_ERROR_INVALID_PARAMETER;
2320 if (STT_STATE_CREATED != client->current_state) {
2321 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2322 return STT_ERROR_INVALID_STATE;
2325 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset recognition result cb");
2327 client->recognition_result_cb = NULL;
2328 client->recognition_result_user_data = NULL;
2333 int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data)
2335 stt_client_s* client = NULL;
2336 if (0 != __stt_get_feature_enabled()) {
2337 return STT_ERROR_NOT_SUPPORTED;
2339 if (0 != __stt_check_privilege()) {
2340 return STT_ERROR_PERMISSION_DENIED;
2342 if (0 != __stt_check_handle(stt, &client)) {
2343 return STT_ERROR_INVALID_PARAMETER;
2346 if (NULL == callback)
2347 return STT_ERROR_INVALID_PARAMETER;
2349 if (STT_STATE_CREATED != client->current_state) {
2350 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2351 return STT_ERROR_INVALID_STATE;
2354 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set state changed cb");
2356 client->state_changed_cb = callback;
2357 client->state_changed_user_data = user_data;
2362 int stt_unset_state_changed_cb(stt_h stt)
2364 stt_client_s* client = NULL;
2365 if (0 != __stt_get_feature_enabled()) {
2366 return STT_ERROR_NOT_SUPPORTED;
2368 if (0 != __stt_check_privilege()) {
2369 return STT_ERROR_PERMISSION_DENIED;
2371 if (0 != __stt_check_handle(stt, &client)) {
2372 return STT_ERROR_INVALID_PARAMETER;
2375 if (STT_STATE_CREATED != client->current_state) {
2376 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2377 return STT_ERROR_INVALID_STATE;
2380 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset state changed cb");
2382 client->state_changed_cb = NULL;
2383 client->state_changed_user_data = NULL;
2388 int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data)
2390 stt_client_s* client = NULL;
2391 if (0 != __stt_get_feature_enabled()) {
2392 return STT_ERROR_NOT_SUPPORTED;
2394 if (0 != __stt_check_privilege()) {
2395 return STT_ERROR_PERMISSION_DENIED;
2397 if (0 != __stt_check_handle(stt, &client)) {
2398 return STT_ERROR_INVALID_PARAMETER;
2401 if (NULL == callback)
2402 return STT_ERROR_INVALID_PARAMETER;
2404 if (STT_STATE_CREATED != client->current_state) {
2405 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2406 return STT_ERROR_INVALID_STATE;
2409 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set error cb");
2411 client->error_cb = callback;
2412 client->error_user_data = user_data;
2417 int stt_unset_error_cb(stt_h stt)
2419 stt_client_s* client = NULL;
2420 if (0 != __stt_get_feature_enabled()) {
2421 return STT_ERROR_NOT_SUPPORTED;
2423 if (0 != __stt_check_privilege()) {
2424 return STT_ERROR_PERMISSION_DENIED;
2426 if (0 != __stt_check_handle(stt, &client)) {
2427 return STT_ERROR_INVALID_PARAMETER;
2430 if (STT_STATE_CREATED != client->current_state) {
2431 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2432 return STT_ERROR_INVALID_STATE;
2435 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset error cb");
2437 client->error_cb = NULL;
2438 client->error_user_data = NULL;
2443 int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_cb callback, void* user_data)
2445 stt_client_s* client = NULL;
2446 if (0 != __stt_get_feature_enabled()) {
2447 return STT_ERROR_NOT_SUPPORTED;
2449 if (0 != __stt_check_privilege()) {
2450 return STT_ERROR_PERMISSION_DENIED;
2452 if (0 != __stt_check_handle(stt, &client)) {
2453 return STT_ERROR_INVALID_PARAMETER;
2456 if (NULL == callback)
2457 return STT_ERROR_INVALID_PARAMETER;
2459 if (STT_STATE_CREATED != client->current_state) {
2460 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2461 return STT_ERROR_INVALID_STATE;
2464 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set default language changed cb");
2466 client->default_lang_changed_cb = callback;
2467 client->default_lang_changed_user_data = user_data;
2472 int stt_unset_default_language_changed_cb(stt_h stt)
2474 stt_client_s* client = NULL;
2475 if (0 != __stt_get_feature_enabled()) {
2476 return STT_ERROR_NOT_SUPPORTED;
2478 if (0 != __stt_check_privilege()) {
2479 return STT_ERROR_PERMISSION_DENIED;
2481 if (0 != __stt_check_handle(stt, &client)) {
2482 return STT_ERROR_INVALID_PARAMETER;
2485 if (STT_STATE_CREATED != client->current_state) {
2486 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2487 return STT_ERROR_INVALID_STATE;
2490 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset default language changed cb");
2492 client->default_lang_changed_cb = NULL;
2493 client->default_lang_changed_user_data = NULL;
2498 int stt_set_engine_changed_cb(stt_h stt, stt_engine_changed_cb callback, void* user_data)
2500 stt_client_s* client = NULL;
2501 if (0 != __stt_get_feature_enabled()) {
2502 return STT_ERROR_NOT_SUPPORTED;
2504 if (0 != __stt_check_privilege()) {
2505 return STT_ERROR_PERMISSION_DENIED;
2507 if (0 != __stt_check_handle(stt, &client)) {
2508 return STT_ERROR_INVALID_PARAMETER;
2511 if (NULL == callback)
2512 return STT_ERROR_INVALID_PARAMETER;
2514 if (STT_STATE_CREATED != client->current_state) {
2515 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2516 return STT_ERROR_INVALID_STATE;
2519 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set engine changed cb");
2521 client->engine_changed_cb = callback;
2522 client->engine_changed_user_data = user_data;
2527 int stt_unset_engine_changed_cb(stt_h stt)
2529 stt_client_s* client = NULL;
2530 if (0 != __stt_get_feature_enabled()) {
2531 return STT_ERROR_NOT_SUPPORTED;
2533 if (0 != __stt_check_privilege()) {
2534 return STT_ERROR_PERMISSION_DENIED;
2536 if (0 != __stt_check_handle(stt, &client)) {
2537 return STT_ERROR_INVALID_PARAMETER;
2540 if (STT_STATE_CREATED != client->current_state) {
2541 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2542 return STT_ERROR_INVALID_STATE;
2545 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset engine changed cb");
2547 client->engine_changed_cb = NULL;
2548 client->engine_changed_user_data = NULL;
2554 int stt_set_speech_status_cb(stt_h stt, stt_speech_status_cb callback, void* user_data)
2556 stt_client_s* client = NULL;
2557 if (0 != __stt_get_feature_enabled()) {
2558 return STT_ERROR_NOT_SUPPORTED;
2560 if (0 != __stt_check_privilege()) {
2561 return STT_ERROR_PERMISSION_DENIED;
2563 if (0 != __stt_check_handle(stt, &client)) {
2564 return STT_ERROR_INVALID_PARAMETER;
2567 if (NULL == callback)
2568 return STT_ERROR_INVALID_PARAMETER;
2570 if (STT_STATE_CREATED != client->current_state) {
2571 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2572 return STT_ERROR_INVALID_STATE;
2575 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set speech status cb");
2577 client->speech_status_cb = callback;
2578 client->speech_status_user_data = user_data;
2583 int stt_unset_speech_status_cb(stt_h stt)
2585 stt_client_s* client = NULL;
2586 if (0 != __stt_get_feature_enabled()) {
2587 return STT_ERROR_NOT_SUPPORTED;
2589 if (0 != __stt_check_privilege()) {
2590 return STT_ERROR_PERMISSION_DENIED;
2592 if (0 != __stt_check_handle(stt, &client)) {
2593 return STT_ERROR_INVALID_PARAMETER;
2596 if (STT_STATE_CREATED != client->current_state) {
2597 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2598 return STT_ERROR_INVALID_STATE;
2601 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset speech status cb");
2603 client->speech_status_cb = NULL;
2604 client->speech_status_user_data = NULL;
2609 int stt_start_file(stt_h stt, const char* language, const char* type, const char* filepath, stt_audio_type_e audio_type, int sample_rate)
2611 stt_client_s* client = NULL;
2612 if (0 != __stt_get_feature_enabled()) {
2613 return STT_ERROR_NOT_SUPPORTED;
2615 if (0 != __stt_check_privilege()) {
2616 return STT_ERROR_PERMISSION_DENIED;
2618 if (0 != __stt_check_handle(stt, &client)) {
2619 return STT_ERROR_INVALID_PARAMETER;
2621 if (NULL == filepath) {
2622 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
2623 return STT_ERROR_INVALID_PARAMETER;
2626 SLOG(LOG_INFO, TAG_STTC, "===== STT START FILE");
2629 if (client->current_state != STT_STATE_READY) {
2630 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
2631 return STT_ERROR_INVALID_STATE;
2634 if (STT_INTERNAL_STATE_NONE != client->internal_state) {
2635 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state);
2636 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
2640 char appid[1024] = {0, };
2641 ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1);
2643 if ((AUL_R_OK != ret) || (0 == strlen(appid))) {
2644 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID");
2646 SLOG(LOG_INFO, TAG_STTC, "[DEBUG] Current app id is %s", appid);
2650 if (NULL == language) {
2651 temp = strdup("default");
2653 temp = strdup(language);
2657 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
2658 return STT_ERROR_OUT_OF_MEMORY;
2661 if (true == client->credential_needed && NULL == client->credential) {
2662 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id);
2665 return STT_ERROR_PERMISSION_DENIED;
2668 client->internal_state = STT_INTERNAL_STATE_STARTING;
2669 ret = stt_dbus_request_start_file(client->uid, temp, type, client->silence, appid, client->credential, filepath, audio_type, sample_rate);
2671 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start file : %s", __stt_get_error_code(ret));
2672 client->internal_state = STT_INTERNAL_STATE_NONE;
2674 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Start is successful but not done");
2680 SLOG(LOG_DEBUG, TAG_STTC, "=====");
2681 SLOG(LOG_DEBUG, TAG_STTC, " ");
2686 int stt_cancel_file(stt_h stt)
2688 stt_client_s* client = NULL;
2689 if (0 != __stt_get_feature_enabled()) {
2690 return STT_ERROR_NOT_SUPPORTED;
2692 if (0 != __stt_check_privilege()) {
2693 return STT_ERROR_PERMISSION_DENIED;
2695 if (0 != __stt_check_handle(stt, &client)) {
2696 return STT_ERROR_INVALID_PARAMETER;
2699 SLOG(LOG_INFO, TAG_STTC, "===== STT CANCEL FILE");
2702 if (STT_STATE_RECORDING != client->current_state && STT_STATE_PROCESSING != client->current_state) {
2703 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid state : Current state(%d) is 'Ready'", client->current_state);
2704 return STT_ERROR_INVALID_STATE;
2707 if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
2708 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state);
2709 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
2710 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
2711 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state);
2712 return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
2713 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
2714 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state);
2715 return STT_ERROR_IN_PROGRESS_TO_READY;
2718 client->internal_state = STT_INTERNAL_STATE_CANCELING;
2719 int ret = stt_dbus_request_cancel_file(client->uid);
2721 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to cancel file : %s", __stt_get_error_code(ret));
2722 client->internal_state = STT_INTERNAL_STATE_NONE;
2724 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Cancel file is successful but not done");
2727 SLOG(LOG_DEBUG, TAG_STTC, "=====");
2728 SLOG(LOG_DEBUG, TAG_STTC, " ");
2733 int __stt_change_system_volume(stt_system_volume_event_e volume_event)
2735 int stream_type = -1;
2736 if (STT_SYSTEM_VOLUME_EVENT_CHANGE_FOR_FARFIELD == volume_event) {
2737 stream_type = SOUND_STREAM_TYPE_VOICE_RECOGNITION;
2738 } else if (STT_SYSTEM_VOLUME_EVENT_CHANGE_FOR_NEARFIELD == volume_event) {
2739 stream_type = SOUND_STREAM_TYPE_VOICE_RECOGNITION_SERVICE;
2741 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] volume type is invalid, type(%d)", volume_event);
2742 return STT_ERROR_INVALID_PARAMETER;
2745 SLOG(LOG_INFO, TAG_STTC, "[INFO] Change system volume, volume_type(%d)", volume_event);
2747 int ret = STT_ERROR_NONE;
2748 if (g_stream_for_volume_h) {
2749 SLOG(LOG_INFO, TAG_STTC, "[INFO] Stream is already created, destroy stream)");
2750 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
2752 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
2754 g_stream_for_volume_h = NULL;
2757 ret = sound_manager_create_stream_information_internal(stream_type, NULL, NULL, &g_stream_for_volume_h);
2759 SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Fail to create stream information, ret(%d)", ret);
2760 return STT_ERROR_OPERATION_FAILED;
2763 if (g_virtual_sound_stream_h) {
2764 SLOG(LOG_INFO, TAG_STTC, "[INFO] Virtual stream is already created, destroy virtual stream)");
2765 ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h);
2767 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy virtual stream, ret(%d)", ret);
2768 return STT_ERROR_OPERATION_FAILED;
2770 g_virtual_sound_stream_h = NULL;
2773 ret = sound_manager_create_virtual_stream(g_stream_for_volume_h, &g_virtual_sound_stream_h);
2775 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create virtual stream, ret(%d)", ret);
2776 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
2778 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
2780 g_stream_for_volume_h = NULL;
2781 return STT_ERROR_OPERATION_FAILED;
2784 ret = sound_manager_start_virtual_stream(g_virtual_sound_stream_h);
2786 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start virtual stream, ret(%d)", ret);
2787 ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h);
2789 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy virtual stream, ret(%d)", ret);
2791 g_virtual_sound_stream_h = NULL;
2793 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
2795 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
2797 g_stream_for_volume_h = NULL;
2799 return STT_ERROR_OPERATION_FAILED;
2802 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Change system volume");
2806 int __stt_recover_system_volume()
2808 SLOG(LOG_INFO, TAG_STTC, "[INFO] Recover system volume");
2810 int ret = STT_ERROR_NONE;
2812 if (g_virtual_sound_stream_h) {
2813 ret = sound_manager_stop_virtual_stream(g_virtual_sound_stream_h);
2815 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to stop virtual stream, ret(%d)", ret);
2816 return STT_ERROR_OPERATION_FAILED;
2818 ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h);
2820 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy virtual stream, ret(%d)", ret);
2821 return STT_ERROR_OPERATION_FAILED;
2823 g_virtual_sound_stream_h = NULL;
2826 if (g_stream_for_volume_h) {
2827 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
2829 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
2830 return STT_ERROR_OPERATION_FAILED;
2832 g_stream_for_volume_h = NULL;
2835 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Recover system volume");
2839 int stt_change_system_volume(stt_h stt, stt_system_volume_event_e volume_event)
2841 SLOG(LOG_DEBUG, TAG_STTC, "[STT] Change system volume, volume_event(%d)", volume_event);
2843 stt_client_s* client = NULL;
2844 if (0 != __stt_get_feature_enabled()) {
2845 return STT_ERROR_NOT_SUPPORTED;
2847 if (0 != __stt_check_privilege()) {
2848 return STT_ERROR_PERMISSION_DENIED;
2850 if (0 != __stt_check_handle(stt, &client)) {
2851 return STT_ERROR_INVALID_PARAMETER;
2855 if (client->current_state != STT_STATE_READY && client->current_state != STT_STATE_CREATED) {
2856 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY nor CREATED", client->current_state);
2857 return STT_ERROR_INVALID_STATE;
2860 /* change system volume */
2861 int ret = __stt_change_system_volume(volume_event);
2863 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to change volume");
2865 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Success to change volume");
2870 int stt_recover_system_volume(stt_h stt)
2872 SLOG(LOG_DEBUG, TAG_STTC, "[STT] recover system volume");
2874 stt_client_s* client = NULL;
2875 if (0 != __stt_get_feature_enabled()) {
2876 return STT_ERROR_NOT_SUPPORTED;
2878 if (0 != __stt_check_privilege()) {
2879 return STT_ERROR_PERMISSION_DENIED;
2881 if (0 != __stt_check_handle(stt, &client)) {
2882 return STT_ERROR_INVALID_PARAMETER;
2886 if (client->current_state != STT_STATE_READY && client->current_state != STT_STATE_CREATED) {
2887 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY nor CREATED", client->current_state);
2888 return STT_ERROR_INVALID_STATE;
2891 /* recover volume */
2892 int ret = __stt_recover_system_volume();
2894 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to recover volume");
2896 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Success to recover volume");