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 pthread_mutex_t g_cynara_mutex = PTHREAD_MUTEX_INITIALIZER;
49 static cynara *p_cynara = NULL;
51 static bool g_err_callback_status = false;
53 /* for changing volume on each sound stream */
54 static sound_stream_info_h g_stream_for_volume_h = NULL;
55 static virtual_sound_stream_h g_virtual_sound_stream_h = NULL;
64 static int __stt_get_feature_enabled()
66 if (0 == g_feature_enabled) {
68 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported");
69 return STT_ERROR_NOT_SUPPORTED;
71 } else if (-1 == g_feature_enabled) {
72 bool stt_supported = false;
73 bool mic_supported = false;
74 if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) {
75 if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) {
76 if (false == stt_supported || false == mic_supported) {
78 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported");
79 g_feature_enabled = 0;
80 return STT_ERROR_NOT_SUPPORTED;
84 g_feature_enabled = 1;
87 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value");
88 return STT_ERROR_NOT_SUPPORTED;
93 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value");
94 return STT_ERROR_NOT_SUPPORTED;
102 static int __check_privilege_initialize()
104 int ret = cynara_initialize(&p_cynara, NULL);
105 if (CYNARA_API_SUCCESS != ret)
106 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to initialize"); //LCOV_EXCL_LINE
108 return ret == CYNARA_API_SUCCESS;
111 static bool __check_privilege(const char* uid, const char * privilege)
114 char label_path[1024] = "/proc/self/attr/current";
115 char smack_label[1024] = {'\0',};
121 fp = fopen(label_path, "r");
123 if (0 >= fread(smack_label, 1, sizeof(smack_label), fp))
124 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to fread"); //LCOV_EXCL_LINE
129 pid_t pid = getpid();
130 char *session = cynara_session_from_pid(pid);
131 int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
132 SLOG(LOG_DEBUG, TAG_STTC, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
138 if (ret != CYNARA_API_ACCESS_ALLOWED)
143 static void __check_privilege_deinitialize()
146 cynara_finish(p_cynara);
150 static int __stt_check_privilege()
152 pthread_mutex_lock(&g_cynara_mutex);
155 ret = __check_privilege_initialize();
157 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed"); //LCOV_EXCL_LINE
158 pthread_mutex_unlock(&g_cynara_mutex);
159 return STT_ERROR_PERMISSION_DENIED;
163 snprintf(uid, 16, "%d", getuid());
165 ret = __check_privilege(uid, STT_PRIVILEGE_RECORDER);
166 __check_privilege_deinitialize();
168 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied"); //LCOV_EXCL_LINE
169 pthread_mutex_unlock(&g_cynara_mutex);
170 return STT_ERROR_PERMISSION_DENIED;
173 pthread_mutex_unlock(&g_cynara_mutex);
174 return STT_ERROR_NONE;
177 static int __stt_check_privilege_for_applaunch()
179 pthread_mutex_lock(&g_cynara_mutex);
182 ret = __check_privilege_initialize();
184 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed (applaunch)"); //LCOV_EXCL_LINE
185 pthread_mutex_unlock(&g_cynara_mutex);
186 return STT_ERROR_PERMISSION_DENIED;
190 snprintf(uid, 16, "%d", getuid());
192 ret = __check_privilege(uid, STT_PRIVILEGE_APPLAUNCH);
193 __check_privilege_deinitialize();
195 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied : appmanager.launch"); //LCOV_EXCL_LINE
196 pthread_mutex_unlock(&g_cynara_mutex);
197 return STT_ERROR_PERMISSION_DENIED;
200 pthread_mutex_unlock(&g_cynara_mutex);
201 return STT_ERROR_NONE;
204 static const char* __stt_get_error_code(stt_error_e err)
208 case STT_ERROR_NONE: return "STT_ERROR_NONE";
209 case STT_ERROR_OUT_OF_MEMORY: return "STT_ERROR_OUT_OF_MEMORY";
210 case STT_ERROR_IO_ERROR: return "STT_ERROR_IO_ERROR";
211 case STT_ERROR_INVALID_PARAMETER: return "STT_ERROR_INVALID_PARAMETER";
212 case STT_ERROR_TIMED_OUT: return "STT_ERROR_TIMED_OUT";
213 case STT_ERROR_RECORDER_BUSY: return "STT_ERROR_RECORDER_BUSY";
214 case STT_ERROR_OUT_OF_NETWORK: return "STT_ERROR_OUT_OF_NETWORK";
215 case STT_ERROR_PERMISSION_DENIED: return "STT_ERROR_PERMISSION_DENIED";
216 case STT_ERROR_NOT_SUPPORTED: return "STT_ERROR_NOT_SUPPORTED";
217 case STT_ERROR_INVALID_STATE: return "STT_ERROR_INVALID_STATE";
218 case STT_ERROR_INVALID_LANGUAGE: return "STT_ERROR_INVALID_LANGUAGE";
219 case STT_ERROR_ENGINE_NOT_FOUND: return "STT_ERROR_ENGINE_NOT_FOUND";
220 case STT_ERROR_OPERATION_FAILED: return "STT_ERROR_OPERATION_FAILED";
221 case STT_ERROR_NOT_SUPPORTED_FEATURE: return "STT_ERROR_NOT_SUPPORTED_FEATURE";
222 case STT_ERROR_SERVICE_RESET: return "STT_ERROR_SERVICE_RESET";
224 return "Invalid error code";
229 static int __stt_convert_config_error_code(stt_config_error_e code)
232 if (code == STT_CONFIG_ERROR_NONE) return STT_ERROR_NONE;
233 if (code == STT_CONFIG_ERROR_OUT_OF_MEMORY) return STT_ERROR_OUT_OF_MEMORY;
234 if (code == STT_CONFIG_ERROR_IO_ERROR) return STT_ERROR_IO_ERROR;
235 if (code == STT_CONFIG_ERROR_INVALID_PARAMETER) return STT_ERROR_INVALID_PARAMETER;
236 if (code == STT_CONFIG_ERROR_PERMISSION_DENIED) return STT_ERROR_PERMISSION_DENIED;
237 if (code == STT_CONFIG_ERROR_NOT_SUPPORTED) return STT_ERROR_NOT_SUPPORTED;
238 if (code == STT_CONFIG_ERROR_INVALID_STATE) return STT_ERROR_INVALID_STATE;
239 if (code == STT_CONFIG_ERROR_INVALID_LANGUAGE) return STT_ERROR_INVALID_LANGUAGE;
240 if (code == STT_CONFIG_ERROR_ENGINE_NOT_FOUND) return STT_ERROR_ENGINE_NOT_FOUND;
241 if (code == STT_CONFIG_ERROR_OPERATION_FAILED) return STT_ERROR_OPERATION_FAILED;
247 void __stt_config_lang_changed_cb(const char* before_language, const char* current_language, void* user_data)
249 SLOG(LOG_DEBUG, TAG_STTC, "Language changed : Before lang(%s) Current lang(%s)",
250 before_language, current_language);
252 if (0 == strcmp(before_language, current_language)) {
256 GList* client_list = NULL;
257 client_list = stt_client_get_client_list();
260 stt_client_s *data = NULL;
262 if (g_list_length(client_list) > 0) {
263 /* Get a first item */
264 iter = g_list_first(client_list);
266 while (NULL != iter) {
268 if (NULL != data->default_lang_changed_cb) {
269 SLOG(LOG_DEBUG, TAG_STTC, "Call default language changed callback : uid(%d)", data->uid);
270 data->default_lang_changed_cb(data->stt, before_language, current_language,
271 data->default_lang_changed_user_data);
275 iter = g_list_next(iter);
282 static Eina_Bool __reconnect_by_engine_changed(void *data)
284 stt_h stt = (stt_h)data;
286 stt_client_s* client = stt_client_get(stt);
287 if (NULL == client) {
288 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
292 if (STT_STATE_READY != client->current_state) {
297 int ret = stt_unprepare(stt);
299 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
301 ret = stt_prepare(stt);
303 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
309 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)
311 stt_h stt = (stt_h)user_data;
313 stt_client_s* client = stt_client_get(stt);
314 if (NULL == client) {
315 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
319 if (NULL != engine_id) SLOG(LOG_DEBUG, TAG_STTC, "Engine id(%s)", engine_id);
320 if (NULL != setting) SLOG(LOG_DEBUG, TAG_STTC, "Engine setting(%s)", setting);
321 if (NULL != language) SLOG(LOG_DEBUG, TAG_STTC, "Language(%s)", language);
322 SLOG(LOG_DEBUG, TAG_STTC, "Silence(%s), Credential(%s)", support_silence ? "on" : "off", need_credential ? "need" : "no need");
324 /* When the default engine is changed, please unload the old engine and load the new one. */
327 if (NULL == client->current_engine_id) {
328 if (STT_STATE_RECORDING == client->current_state || STT_STATE_PROCESSING == client->current_state) {
329 SLOG(LOG_INFO, TAG_STTC, "[INFO] stt cancel is invoked by engine_changed_cb, state(%d)", client->current_state);
330 ret = stt_cancel(stt);
332 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] STT client cancelling...");
335 ecore_idler_add(__reconnect_by_engine_changed, (void*)stt);
336 } else if (STT_STATE_READY == client->current_state) {
337 ret = stt_unprepare(stt);
339 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
341 ret = stt_prepare(stt);
343 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
348 /* call callback function */
349 if (NULL != client->engine_changed_cb) {
350 client->engine_changed_cb(stt, engine_id, language, support_silence, need_credential, client->engine_changed_user_data);
352 SLOG(LOG_WARN, TAG_STTC, "No registered callback function for engine change");
357 static int __stt_check_handle(stt_h stt, stt_client_s** client)
360 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input handle is null");
361 return STT_ERROR_INVALID_PARAMETER;
364 stt_client_s* temp = NULL;
365 temp = stt_client_get(stt);
369 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
370 return STT_ERROR_INVALID_PARAMETER;
374 return STT_ERROR_NONE;
377 int stt_create(stt_h* stt)
379 if (0 != __stt_get_feature_enabled()) {
380 return STT_ERROR_NOT_SUPPORTED;
382 if (0 != __stt_check_privilege()) {
383 return STT_ERROR_PERMISSION_DENIED;
386 SLOG(LOG_INFO, TAG_STTC, "===== Create STT");
389 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is null");
390 return STT_ERROR_INVALID_PARAMETER;
393 if (0 == stt_client_get_size()) {
394 if (0 != stt_dbus_open_connection()) {
396 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to open connection");
397 return STT_ERROR_OPERATION_FAILED;
402 if (0 != stt_client_new(stt)) {
404 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client!");
405 return STT_ERROR_OUT_OF_MEMORY;
409 stt_client_s* client = stt_client_get(*stt);
410 if (NULL == client) {
411 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client"); //LCOV_EXCL_LINE
412 stt_client_destroy(*stt);
413 return STT_ERROR_OPERATION_FAILED;
416 int ret = stt_config_mgr_initialize(client->uid);
417 ret = __stt_convert_config_error_code(ret);
419 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to init config manager : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
420 stt_client_destroy(*stt);
424 ret = stt_config_mgr_set_callback(client->uid, __stt_config_engine_changed_cb, __stt_config_lang_changed_cb, NULL, client->stt);
425 ret = __stt_convert_config_error_code(ret);
427 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set config changed : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
428 stt_client_destroy(*stt);
432 SLOG(LOG_INFO, TAG_STTC, "[Success] uid(%d)", (*stt)->handle);
434 SLOG(LOG_DEBUG, TAG_STTC, "=====");
435 SLOG(LOG_DEBUG, TAG_STTC, " ");
437 return STT_ERROR_NONE;
440 int stt_destroy(stt_h stt)
442 stt_client_s* client = NULL;
443 if (0 != __stt_get_feature_enabled()) {
444 return STT_ERROR_NOT_SUPPORTED;
446 if (0 != __stt_check_privilege()) {
447 return STT_ERROR_PERMISSION_DENIED;
449 if (0 != __stt_check_handle(stt, &client)) {
450 return STT_ERROR_INVALID_PARAMETER;
453 SLOG(LOG_INFO, TAG_STTC, "===== Destroy STT");
455 /* check used callback */
456 if (0 != stt_client_get_use_callback(client)) {
457 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Cannot destroy in Callback function");
458 return STT_ERROR_OPERATION_FAILED;
461 stt_config_mgr_finalize(client->uid);
466 switch (client->current_state) {
467 case STT_STATE_PROCESSING:
468 case STT_STATE_RECORDING:
469 case STT_STATE_READY:
470 ret = stt_dbus_request_finalize(client->uid);
472 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
474 case STT_STATE_CREATED:
475 if (NULL != g_connect_timer) {
476 SLOG(LOG_DEBUG, TAG_STTC, "Connect Timer is deleted");
477 ecore_timer_del(g_connect_timer);
478 g_connect_timer = NULL;
482 stt_client_destroy(stt);
488 if (0 == stt_client_get_size()) {
489 if (0 != stt_dbus_close_connection()) {
490 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to close connection"); //LCOV_EXCL_LINE
496 SLOG(LOG_INFO, TAG_STTC, "=====");
497 SLOG(LOG_DEBUG, TAG_STTC, " ");
499 return STT_ERROR_NONE;
502 bool __stt_config_supported_engine_cb(const char* engine_id, const char* engine_name,
503 const char* setting, bool support_silence, void* user_data)
505 stt_h stt = (stt_h)user_data;
507 stt_client_s* client = stt_client_get(stt);
508 if (NULL == client) {
510 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
515 /* call callback function */
516 if (NULL != client->supported_engine_cb) {
517 return client->supported_engine_cb(stt, engine_id, engine_name, client->supported_engine_user_data);
519 SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported engine"); //LCOV_EXCL_LINE
525 int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, void* user_data)
527 stt_client_s* client = NULL;
528 if (0 != __stt_get_feature_enabled()) {
529 return STT_ERROR_NOT_SUPPORTED;
531 if (0 != __stt_check_privilege()) {
532 return STT_ERROR_PERMISSION_DENIED;
534 if (0 != __stt_check_handle(stt, &client)) {
535 return STT_ERROR_INVALID_PARAMETER;
538 SLOG(LOG_INFO, TAG_STTC, "===== Foreach Supported engine");
540 if (NULL == callback) {
541 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
542 return STT_ERROR_INVALID_PARAMETER;
545 if (client->current_state != STT_STATE_CREATED) {
546 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state);
547 return STT_ERROR_INVALID_STATE;
550 client->supported_engine_cb = callback;
551 client->supported_engine_user_data = user_data;
554 ret = stt_config_mgr_get_engine_list(__stt_config_supported_engine_cb, client->stt);
555 ret = __stt_convert_config_error_code(ret);
557 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get engines : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
560 client->supported_engine_cb = NULL;
561 client->supported_engine_user_data = NULL;
563 SLOG(LOG_INFO, TAG_STTC, "=====");
564 SLOG(LOG_DEBUG, TAG_STTC, " ");
569 int stt_get_engine(stt_h stt, char** engine_id)
571 stt_client_s* client = NULL;
572 if (0 != __stt_get_feature_enabled()) {
573 return STT_ERROR_NOT_SUPPORTED;
575 if (0 != __stt_check_privilege()) {
576 return STT_ERROR_PERMISSION_DENIED;
578 if (0 != __stt_check_handle(stt, &client)) {
579 return STT_ERROR_INVALID_PARAMETER;
582 SLOG(LOG_INFO, TAG_STTC, "===== Get current engine");
584 if (NULL == engine_id) {
585 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
586 return STT_ERROR_INVALID_PARAMETER;
589 if (client->current_state != STT_STATE_CREATED) {
590 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state);
591 return STT_ERROR_INVALID_STATE;
596 if (NULL != client->current_engine_id) {
597 *engine_id = strdup(client->current_engine_id);
598 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", *engine_id);
601 ret = stt_config_mgr_get_engine(engine_id);
602 ret = __stt_convert_config_error_code(ret);
604 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request get current engine : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
606 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", *engine_id);
610 SLOG(LOG_INFO, TAG_STTC, "=====");
611 SLOG(LOG_DEBUG, TAG_STTC, " ");
616 int __stt_set_buxtonkey(const char* engine_id)
619 struct buxton_client * bux_cli;
620 struct buxton_layer * bux_layer;
621 struct buxton_value * bux_val;
623 int ret = buxton_open(&bux_cli, NULL, NULL);
625 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to open buxton client"); //LCOV_EXCL_LINE
626 return STT_ERROR_OPERATION_FAILED;
628 SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] buxton_open: %d", ret);
629 bux_layer = buxton_create_layer("system");
630 if (NULL == bux_layer) {
632 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_create_layer FAIL");
633 buxton_close(bux_cli);
635 return STT_ERROR_OPERATION_FAILED;
638 bux_val = buxton_value_create_string(engine_id);
639 if (NULL == bux_val) {
641 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_value_create_string FAIL");
642 buxton_free_layer(bux_layer);
643 buxton_close(bux_cli);
646 return STT_ERROR_OPERATION_FAILED;
650 ret = buxton_set_value_sync(bux_cli, bux_layer, STT_ENGINE_DB_CUSTOM, bux_val);
653 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to set value sync");
654 buxton_value_free(bux_val);
655 buxton_free_layer(bux_layer);
656 buxton_close(bux_cli);
661 return STT_ERROR_OPERATION_FAILED;
664 SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] buxton_set_value_sync: %d, %s", ret, STT_ENGINE_DB_CUSTOM);
666 buxton_value_free(bux_val);
667 buxton_free_layer(bux_layer);
668 buxton_close(bux_cli);
674 return STT_ERROR_NONE;
677 int stt_set_engine(stt_h stt, const char* engine_id)
679 stt_client_s* client = NULL;
680 if (0 != __stt_get_feature_enabled()) {
681 return STT_ERROR_NOT_SUPPORTED;
683 if (0 != __stt_check_privilege()) {
684 return STT_ERROR_PERMISSION_DENIED;
686 if (0 != __stt_check_privilege_for_applaunch()) {
687 return STT_ERROR_PERMISSION_DENIED;
689 if (0 != __stt_check_handle(stt, &client)) {
690 return STT_ERROR_INVALID_PARAMETER;
693 SLOG(LOG_INFO, TAG_STTC, "===== Set current engine");
695 if (NULL == engine_id) {
696 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
697 return STT_ERROR_INVALID_PARAMETER;
701 if (client->current_state != STT_STATE_CREATED) {
702 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state);
703 return STT_ERROR_INVALID_STATE;
706 if (NULL != client->current_engine_id) {
707 free(client->current_engine_id);
708 client->current_engine_id = NULL;
711 SLOG(LOG_INFO, TAG_STTC, "===== engined_id(%s)", engine_id);
713 client->current_engine_id = strdup(engine_id);
716 int ret = __stt_set_buxtonkey(engine_id);
718 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] set buxtonkey Failed!!!"); //LCOV_EXCL_LINE
722 SLOG(LOG_INFO, TAG_STTC, "=====");
723 SLOG(LOG_DEBUG, TAG_STTC, " ");
728 int stt_set_credential(stt_h stt, const char* credential)
730 stt_client_s* client = NULL;
731 if (0 != __stt_get_feature_enabled()) {
732 return STT_ERROR_NOT_SUPPORTED;
734 if (0 != __stt_check_privilege()) {
735 return STT_ERROR_PERMISSION_DENIED;
737 if (0 != __stt_check_handle(stt, &client)) {
738 return STT_ERROR_INVALID_PARAMETER;
741 SLOG(LOG_INFO, TAG_STTC, "===== Set credential");
743 if (NULL == credential) {
744 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
745 return STT_ERROR_INVALID_PARAMETER;
749 if (client->current_state != STT_STATE_CREATED && client->current_state != STT_STATE_READY) {
750 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED or READY", client->current_state); //LCOV_EXCL_LINE
751 return STT_ERROR_INVALID_STATE;
754 if (NULL != client->credential) {
755 free(client->credential);
756 client->credential = NULL;
758 client->credential = strdup(credential);
760 SLOG(LOG_INFO, TAG_STTC, "=====");
761 SLOG(LOG_DEBUG, TAG_STTC, " ");
763 return STT_ERROR_NONE;
766 int stt_set_private_data(stt_h stt, const char* key, const char* data)
768 stt_client_s* client = NULL;
769 if (0 != __stt_get_feature_enabled()) {
770 return STT_ERROR_NOT_SUPPORTED;
772 if (0 != __stt_check_privilege()) {
773 return STT_ERROR_PERMISSION_DENIED;
775 if (0 != __stt_check_handle(stt, &client)) {
776 return STT_ERROR_INVALID_PARAMETER;
779 SLOG(LOG_INFO, TAG_STTC, "===== Set private data");
781 if (NULL == key || NULL == data) {
782 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
783 return STT_ERROR_INVALID_PARAMETER;
787 if (STT_STATE_READY != client->current_state) {
788 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
789 return STT_ERROR_INVALID_STATE;
792 if (true != client->internal && (0 == strcmp(key, "server") || 0 == strcmp(key, "rampcode") || 0 == strcmp(key, "epd"))) {
793 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This is not an internal app"); //LCOV_EXCL_LINE
794 return STT_ERROR_INVALID_PARAMETER;
800 ret = stt_dbus_request_set_private_data(client->uid, key, data);
803 if (STT_ERROR_TIMED_OUT != ret) {
804 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data : %s", __stt_get_error_code(ret));
807 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry : %s", __stt_get_error_code(ret));
810 if (STT_RETRY_COUNT == count) {
811 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
819 SLOG(LOG_INFO, TAG_STTC, "=====");
820 SLOG(LOG_DEBUG, TAG_STTC, "");
822 return STT_ERROR_NONE;
825 int stt_get_private_data(stt_h stt, const char* key, char** data)
827 stt_client_s* client = NULL;
828 if (0 != __stt_get_feature_enabled()) {
829 return STT_ERROR_NOT_SUPPORTED;
831 if (0 != __stt_check_privilege()) {
832 return STT_ERROR_PERMISSION_DENIED;
834 if (0 != __stt_check_handle(stt, &client)) {
835 return STT_ERROR_INVALID_PARAMETER;
838 SLOG(LOG_INFO, TAG_STTC, "===== Get private data");
840 if (NULL == key || NULL == data) {
841 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
842 return STT_ERROR_INVALID_PARAMETER;
846 if (STT_STATE_READY != client->current_state) {
847 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
848 return STT_ERROR_INVALID_STATE;
854 ret = stt_dbus_request_get_private_data(client->uid, key, data);
857 if (STT_ERROR_TIMED_OUT != ret) {
858 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get private data : %s", __stt_get_error_code(ret));
861 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry : %s", __stt_get_error_code(ret));
864 if (STT_RETRY_COUNT == count) {
865 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
873 if (0 == strncmp(*data, "NULL", strlen(*data))) {
878 SLOG(LOG_INFO, TAG_STTC, "=====");
879 SLOG(LOG_DEBUG, TAG_STTC, "");
881 return STT_ERROR_NONE;
885 int stt_set_server_stt(stt_h stt, const char* key, char* user_data)
888 stt_client_s* client = NULL;
890 if (0 != __stt_get_feature_enabled()) {
891 return STT_ERROR_NOT_SUPPORTED;
893 if (0 != __stt_check_privilege()) {
894 return STT_ERROR_PERMISSION_DENIED;
896 if (0 != __stt_check_handle(stt, &client)) {
897 return STT_ERROR_INVALID_PARAMETER;
900 SLOG(LOG_INFO, TAG_STTC, "===== Set STT server");
902 if (NULL == key || NULL == user_data) {
903 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
904 return STT_ERROR_INVALID_PARAMETER;
907 if (STT_STATE_CREATED != client->current_state && STT_STATE_READY != client->current_state) {
908 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] The current state is invalid (%d).", client->current_state);
909 return STT_ERROR_INVALID_STATE;
913 client->internal = true;
915 char* private_key = NULL;
916 private_key = strdup(key);
917 if (NULL == private_key) {
918 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(private_key)");
919 return STT_ERROR_OUT_OF_MEMORY;
923 data = strdup(user_data);
925 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(data)");
928 return STT_ERROR_OUT_OF_MEMORY;
931 ret = stt_set_private_data(stt, private_key, data);
933 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data, ret(%d), key(%s)", ret, private_key);
941 SLOG(LOG_INFO, TAG_STTC, "======");
942 SLOG(LOG_DEBUG, TAG_STTC, " ");
948 static Eina_Bool __stt_connect_daemon(void *data)
950 stt_client_s* client = (stt_client_s*)data;
953 if (NULL == client) {
954 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); //LCOV_EXCL_LINE
955 g_connect_timer = NULL;
959 if (0 == stt_client_get_size() || NULL == stt_client_get_by_uid(client->uid)) {
960 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Client has been already destroyed"); //LCOV_EXCL_LINE
964 /* Check and Set vconfkey of custom engine before sending hello */
965 if (NULL != client->current_engine_id && 0 == __stt_check_privilege_for_applaunch()) {
967 ret = __stt_set_buxtonkey(client->current_engine_id);
970 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] set buxtonkey Failed!!! (inside __stt_connect_daemon)");
977 ret = stt_dbus_request_hello(client->uid);
980 if (STT_ERROR_INVALID_STATE == ret) {
981 g_connect_timer = NULL;
987 g_connect_timer = NULL;
988 SLOG(LOG_INFO, TAG_STTC, "===== Connect stt-service");
990 /* request initialization */
991 bool silence_supported = false;
992 bool credential_needed = false;
994 ret = stt_dbus_request_initialize(client->uid, &silence_supported, &credential_needed);
996 if (STT_ERROR_ENGINE_NOT_FOUND == ret) {
997 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
999 client->reason = STT_ERROR_ENGINE_NOT_FOUND;
1000 ecore_main_loop_thread_safe_call_async(__stt_notify_error, (void*)client);
1004 } else if (STT_ERROR_NONE != ret) {
1005 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] Fail to connection. Retry to connect"); //LCOV_EXCL_LINE
1008 /* success to connect stt-service */
1009 client->silence_supported = silence_supported;
1010 client->credential_needed = credential_needed;
1011 SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need");
1015 #ifdef __UNUSED_CODES__
1016 if (NULL != client->current_engine_id) {
1019 silence_supported = false;
1020 credential_needed = false;
1021 SLOG(LOG_DEBUG, TAG_STTC, "[WARNING] current_engine_id(%s)", client->current_engine_id);
1024 ret = stt_dbus_request_set_current_engine(client->uid, client->current_engine_id, &silence_supported, &credential_needed);
1026 if (STT_ERROR_TIMED_OUT != ret) {
1027 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set current engine : %s", __stt_get_error_code(ret));
1030 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1033 if (STT_RETRY_COUNT == count) {
1034 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1039 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", client->current_engine_id);
1041 /* success to change engine */
1042 client->silence_supported = silence_supported;
1043 SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need");
1049 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] uid(%d)", client->uid);
1051 client->before_state = client->current_state;
1052 client->current_state = STT_STATE_READY;
1054 if (NULL != client->state_changed_cb) {
1055 stt_client_use_callback(client);
1056 client->state_changed_cb(client->stt, client->before_state,
1057 client->current_state, client->state_changed_user_data);
1058 stt_client_not_use_callback(client);
1059 SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called");
1061 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
1064 SLOG(LOG_INFO, TAG_STTC, "=====");
1065 SLOG(LOG_DEBUG, TAG_STTC, " ");
1070 int stt_prepare(stt_h stt)
1072 stt_client_s* client = NULL;
1073 if (0 != __stt_get_feature_enabled()) {
1074 return STT_ERROR_NOT_SUPPORTED;
1076 if (0 != __stt_check_privilege()) {
1077 return STT_ERROR_PERMISSION_DENIED;
1079 if (0 != __stt_check_handle(stt, &client)) {
1080 return STT_ERROR_INVALID_PARAMETER;
1083 SLOG(LOG_INFO, TAG_STTC, "===== Prepare STT");
1086 if (client->current_state != STT_STATE_CREATED) {
1087 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'CREATED'", client->current_state);
1088 return STT_ERROR_INVALID_STATE;
1091 ecore_thread_main_loop_begin();
1092 g_connect_timer = ecore_timer_add(0.02, __stt_connect_daemon, (void*)client);
1093 ecore_thread_main_loop_end();
1095 SLOG(LOG_INFO, TAG_STTC, "=====");
1096 SLOG(LOG_DEBUG, TAG_STTC, " ");
1098 return STT_ERROR_NONE;
1101 int stt_unprepare(stt_h stt)
1103 stt_client_s* client = NULL;
1104 if (0 != __stt_get_feature_enabled()) {
1105 return STT_ERROR_NOT_SUPPORTED;
1107 if (0 != __stt_check_privilege()) {
1108 return STT_ERROR_PERMISSION_DENIED;
1110 if (0 != __stt_check_handle(stt, &client)) {
1111 return STT_ERROR_INVALID_PARAMETER;
1114 SLOG(LOG_INFO, TAG_STTC, "===== Unprepare STT");
1117 if (client->current_state != STT_STATE_READY) {
1118 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'READY'", client->current_state);
1119 return STT_ERROR_INVALID_STATE;
1125 ret = stt_dbus_request_finalize(client->uid);
1128 if (STT_ERROR_TIMED_OUT != ret) {
1129 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize : %s", __stt_get_error_code(ret));
1132 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1135 if (STT_RETRY_COUNT == count) {
1136 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1144 client->internal_state = STT_INTERNAL_STATE_NONE;
1146 client->before_state = client->current_state;
1147 client->current_state = STT_STATE_CREATED;
1149 if (NULL != client->state_changed_cb) {
1150 stt_client_use_callback(client);
1151 client->state_changed_cb(client->stt, client->before_state,
1152 client->current_state, client->state_changed_user_data);
1153 stt_client_not_use_callback(client);
1155 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
1158 if (g_connect_timer) {
1159 ecore_timer_del(g_connect_timer);
1160 g_connect_timer = NULL;
1163 SLOG(LOG_INFO, TAG_STTC, "=====");
1164 SLOG(LOG_DEBUG, TAG_STTC, " ");
1166 return STT_ERROR_NONE;
1169 bool __stt_config_supported_language_cb(const char* engine_id, const char* language, void* user_data)
1171 stt_h stt = (stt_h)user_data;
1173 stt_client_s* client = stt_client_get(stt);
1174 if (NULL == client) {
1175 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid"); //LCOV_EXCL_LINE
1179 SLOG(LOG_INFO, TAG_STTC, "===== supported language callback");
1181 /* call callback function */
1182 if (NULL != client->supported_lang_cb) {
1183 return client->supported_lang_cb(stt, language, client->supported_lang_user_data);
1185 SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported languages"); //LCOV_EXCL_LINE
1191 int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callback, void* user_data)
1193 stt_client_s* client = NULL;
1194 if (0 != __stt_get_feature_enabled()) {
1195 return STT_ERROR_NOT_SUPPORTED;
1197 if (0 != __stt_check_privilege()) {
1198 return STT_ERROR_PERMISSION_DENIED;
1200 if (0 != __stt_check_handle(stt, &client)) {
1201 return STT_ERROR_INVALID_PARAMETER;
1204 SLOG(LOG_INFO, TAG_STTC, "===== Foreach Supported Language");
1206 if (NULL == callback) {
1207 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1208 return STT_ERROR_INVALID_PARAMETER;
1212 char* current_engine_id = NULL;
1214 if (NULL == client->current_engine_id) {
1215 ret = stt_config_mgr_get_engine(¤t_engine_id);
1216 ret = __stt_convert_config_error_code(ret);
1218 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get default engine id : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1222 current_engine_id = strdup(client->current_engine_id);
1224 if (NULL == current_engine_id) {
1225 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
1226 return STT_ERROR_OUT_OF_MEMORY;
1231 client->supported_lang_cb = callback;
1232 client->supported_lang_user_data = user_data;
1234 ret = stt_config_mgr_get_language_list(current_engine_id, __stt_config_supported_language_cb, client->stt);
1235 ret = __stt_convert_config_error_code(ret);
1237 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get languages : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1240 if (NULL != current_engine_id) {
1241 free(current_engine_id);
1242 current_engine_id = NULL;
1245 client->supported_lang_cb = NULL;
1246 client->supported_lang_user_data = NULL;
1248 SLOG(LOG_INFO, TAG_STTC, "=====");
1249 SLOG(LOG_DEBUG, TAG_STTC, " ");
1254 int stt_get_default_language(stt_h stt, char** language)
1256 stt_client_s* client = NULL;
1257 if (0 != __stt_get_feature_enabled()) {
1258 return STT_ERROR_NOT_SUPPORTED;
1260 if (0 != __stt_check_privilege()) {
1261 return STT_ERROR_PERMISSION_DENIED;
1263 if (0 != __stt_check_handle(stt, &client)) {
1264 return STT_ERROR_INVALID_PARAMETER;
1267 SLOG(LOG_INFO, TAG_STTC, "===== Get Default Language");
1269 if (NULL == language) {
1270 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1271 return STT_ERROR_INVALID_PARAMETER;
1275 ret = stt_config_mgr_get_default_language(language);
1276 ret = __stt_convert_config_error_code(ret);
1278 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get default language : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1280 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current language = %s", *language);
1283 SLOG(LOG_INFO, TAG_STTC, "=====");
1284 SLOG(LOG_DEBUG, TAG_STTC, " ");
1289 int stt_get_state(stt_h stt, stt_state_e* state)
1291 stt_client_s* client = NULL;
1292 if (0 != __stt_get_feature_enabled()) {
1293 return STT_ERROR_NOT_SUPPORTED;
1295 if (0 != __stt_check_privilege()) {
1296 return STT_ERROR_PERMISSION_DENIED;
1298 if (0 != __stt_check_handle(stt, &client)) {
1299 return STT_ERROR_INVALID_PARAMETER;
1302 if (NULL == state) {
1303 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1304 return STT_ERROR_INVALID_PARAMETER;
1307 *state = client->current_state;
1309 SLOG(LOG_INFO, TAG_STTC, "===== Get state(%d)", *state);
1312 case STT_STATE_CREATED: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'CREATED'"); break;
1313 case STT_STATE_READY: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Ready'"); break;
1314 case STT_STATE_RECORDING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Recording'"); break;
1315 case STT_STATE_PROCESSING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Processing'"); break;
1316 default: SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid value"); break;
1319 return STT_ERROR_NONE;
1322 int stt_get_error_message(stt_h stt, char** err_msg)
1324 stt_client_s* client = NULL;
1325 if (0 != __stt_get_feature_enabled()) {
1326 return STT_ERROR_NOT_SUPPORTED;
1328 if (0 != __stt_check_privilege()) {
1329 return STT_ERROR_PERMISSION_DENIED;
1331 if (0 != __stt_check_handle(stt, &client)) {
1332 return STT_ERROR_INVALID_PARAMETER;
1335 if (NULL == err_msg) {
1336 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
1337 return STT_ERROR_INVALID_PARAMETER;
1340 if (false == g_err_callback_status) {
1341 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This callback should be called during an err_callback");
1342 return STT_ERROR_OPERATION_FAILED;
1345 if (NULL != client->err_msg) {
1346 *err_msg = strdup(client->err_msg);
1347 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Error msg (%s)", *err_msg); //LCOV_EXCL_LINE
1349 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Error msg (NULL)"); //LCOV_EXCL_LINE
1352 SLOG(LOG_INFO, TAG_STTC, "====="); //LCOV_EXCL_LINE
1353 SLOG(LOG_DEBUG, TAG_STTC, " "); //LCOV_EXCL_LINE
1355 return STT_ERROR_NONE;
1358 int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support)
1360 stt_client_s* client = NULL;
1361 if (0 != __stt_get_feature_enabled()) {
1362 return STT_ERROR_NOT_SUPPORTED;
1364 if (0 != __stt_check_privilege()) {
1365 return STT_ERROR_PERMISSION_DENIED;
1367 if (0 != __stt_check_handle(stt, &client)) {
1368 return STT_ERROR_INVALID_PARAMETER;
1371 if (NULL == type || NULL == support) {
1372 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1373 return STT_ERROR_INVALID_PARAMETER;
1377 if (client->current_state != STT_STATE_READY) {
1378 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1379 return STT_ERROR_INVALID_STATE;
1385 ret = stt_dbus_request_is_recognition_type_supported(client->uid, type, support);
1388 if (STT_ERROR_TIMED_OUT != ret) {
1389 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get recognition type supported : %s", __stt_get_error_code(ret));
1392 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1395 if (STT_RETRY_COUNT == count) {
1396 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1402 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] recognition type is %s", *support ? "true " : "false");
1407 return STT_ERROR_NONE;
1410 int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type)
1412 stt_client_s* client = NULL;
1413 if (0 != __stt_get_feature_enabled()) {
1414 return STT_ERROR_NOT_SUPPORTED;
1416 if (0 != __stt_check_privilege()) {
1417 return STT_ERROR_PERMISSION_DENIED;
1419 if (0 != __stt_check_handle(stt, &client)) {
1420 return STT_ERROR_INVALID_PARAMETER;
1424 if (client->current_state != STT_STATE_READY) {
1425 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1426 return STT_ERROR_INVALID_STATE;
1429 SLOG(LOG_INFO, TAG_STTC, "===== Set silence detection, supported(%d), type(%d)", client->silence_supported, type);
1431 if (true == client->silence_supported) {
1432 if (type >= STT_OPTION_SILENCE_DETECTION_FALSE && type <= STT_OPTION_SILENCE_DETECTION_AUTO) {
1433 client->silence = type;
1435 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Type is invalid");
1436 return STT_ERROR_INVALID_PARAMETER;
1439 return STT_ERROR_NOT_SUPPORTED_FEATURE;
1442 return STT_ERROR_NONE;
1445 int stt_set_start_sound(stt_h stt, const char* filename)
1447 stt_client_s* client = NULL;
1448 if (0 != __stt_get_feature_enabled()) {
1449 return STT_ERROR_NOT_SUPPORTED;
1451 if (0 != __stt_check_privilege()) {
1452 return STT_ERROR_PERMISSION_DENIED;
1454 if (0 != __stt_check_handle(stt, &client)) {
1455 return STT_ERROR_INVALID_PARAMETER;
1458 SLOG(LOG_INFO, TAG_STTC, "===== STT SET START SOUND");
1460 if (NULL == filename) {
1461 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1462 return STT_ERROR_INVALID_PARAMETER;
1465 if (0 != access(filename, F_OK)) {
1466 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] File does not exist"); //LCOV_EXCL_LINE
1467 return STT_ERROR_INVALID_PARAMETER;
1471 if (client->current_state != STT_STATE_READY) {
1472 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); //LCOV_EXCL_LINE
1473 return STT_ERROR_INVALID_STATE;
1479 ret = stt_dbus_request_set_start_sound(client->uid, filename);
1482 if (STT_ERROR_TIMED_OUT != ret) {
1483 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set start sound : %s", __stt_get_error_code(ret));
1486 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1489 if (STT_RETRY_COUNT == count) {
1490 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1496 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Set start sound : %s", filename);
1501 return STT_ERROR_NONE;
1504 int stt_unset_start_sound(stt_h stt)
1506 stt_client_s* client = NULL;
1507 if (0 != __stt_get_feature_enabled()) {
1508 return STT_ERROR_NOT_SUPPORTED;
1510 if (0 != __stt_check_privilege()) {
1511 return STT_ERROR_PERMISSION_DENIED;
1513 if (0 != __stt_check_handle(stt, &client)) {
1514 return STT_ERROR_INVALID_PARAMETER;
1517 SLOG(LOG_INFO, TAG_STTC, "===== STT UNSET START SOUND");
1520 if (client->current_state != STT_STATE_READY) {
1521 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1522 return STT_ERROR_INVALID_STATE;
1528 ret = stt_dbus_request_unset_start_sound(client->uid);
1531 if (STT_ERROR_TIMED_OUT != ret) {
1532 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to unset start sound : %s", __stt_get_error_code(ret));
1535 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1538 if (STT_RETRY_COUNT == count) {
1539 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1545 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Unset start sound");
1550 return STT_ERROR_NONE;
1553 int stt_set_stop_sound(stt_h stt, const char* filename)
1555 stt_client_s* client = NULL;
1556 if (0 != __stt_get_feature_enabled()) {
1557 return STT_ERROR_NOT_SUPPORTED;
1559 if (0 != __stt_check_privilege()) {
1560 return STT_ERROR_PERMISSION_DENIED;
1562 if (0 != __stt_check_handle(stt, &client)) {
1563 return STT_ERROR_INVALID_PARAMETER;
1566 SLOG(LOG_INFO, TAG_STTC, "===== STT SET STOP SOUND");
1568 if (NULL == filename) {
1569 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1570 return STT_ERROR_INVALID_PARAMETER;
1573 if (0 != access(filename, F_OK)) {
1574 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] File does not exist"); //LCOV_EXCL_LINE
1575 return STT_ERROR_INVALID_PARAMETER;
1579 if (client->current_state != STT_STATE_READY) {
1580 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); //LCOV_EXCL_LINE
1581 return STT_ERROR_INVALID_STATE;
1587 ret = stt_dbus_request_set_stop_sound(client->uid, filename);
1590 if (STT_ERROR_TIMED_OUT != ret) {
1591 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set stop sound : %s", __stt_get_error_code(ret));
1594 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1597 if (STT_RETRY_COUNT == count) {
1598 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1604 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Set stop sound : %s", filename);
1609 return STT_ERROR_NONE;
1612 int stt_unset_stop_sound(stt_h stt)
1614 stt_client_s* client = NULL;
1615 if (0 != __stt_get_feature_enabled()) {
1616 return STT_ERROR_NOT_SUPPORTED;
1618 if (0 != __stt_check_privilege()) {
1619 return STT_ERROR_PERMISSION_DENIED;
1621 if (0 != __stt_check_handle(stt, &client)) {
1622 return STT_ERROR_INVALID_PARAMETER;
1625 SLOG(LOG_INFO, TAG_STTC, "===== STT UNSET STOP SOUND");
1628 if (client->current_state != STT_STATE_READY) {
1629 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1630 return STT_ERROR_INVALID_STATE;
1636 ret = stt_dbus_request_unset_stop_sound(client->uid);
1639 if (STT_ERROR_TIMED_OUT != ret) {
1640 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to unset stop sound : %s", __stt_get_error_code(ret));
1643 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1646 if (STT_RETRY_COUNT == count) {
1647 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1653 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Unset stop sound");
1658 return STT_ERROR_NONE;
1661 int stt_start(stt_h stt, const char* language, const char* type)
1663 stt_client_s* client = NULL;
1664 if (0 != __stt_get_feature_enabled()) {
1665 return STT_ERROR_NOT_SUPPORTED;
1667 if (0 != __stt_check_privilege()) {
1668 return STT_ERROR_PERMISSION_DENIED;
1670 if (0 != __stt_check_handle(stt, &client)) {
1671 return STT_ERROR_INVALID_PARAMETER;
1674 SLOG(LOG_INFO, TAG_STTC, "===== STT START");
1677 if (client->current_state != STT_STATE_READY) {
1678 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1679 return STT_ERROR_INVALID_STATE;
1682 if (STT_INTERNAL_STATE_NONE != client->internal_state) {
1683 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state); //LCOV_EXCL_LINE
1684 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
1688 char appid[1024] = {0, };
1689 ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1);
1691 if ((AUL_R_OK != ret) || (0 == strlen(appid))) {
1692 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID"); //LCOV_EXCL_LINE
1694 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Current app id is %s", appid);
1698 if (NULL == language) {
1699 temp = strdup("default");
1701 temp = strdup(language);
1705 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
1706 return STT_ERROR_OUT_OF_MEMORY;
1709 if (true == client->credential_needed && NULL == client->credential) {
1710 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id); //LCOV_EXCL_LINE
1713 return STT_ERROR_PERMISSION_DENIED;
1716 client->internal_state = STT_INTERNAL_STATE_STARTING;
1717 ret = stt_dbus_request_start(client->uid, temp, type, client->silence, appid, client->credential);
1719 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1720 client->internal_state = STT_INTERNAL_STATE_NONE;
1722 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Start is successful but not done");
1728 SLOG(LOG_INFO, TAG_STTC, "=====");
1729 SLOG(LOG_DEBUG, TAG_STTC, " ");
1734 int stt_stop(stt_h stt)
1736 stt_client_s* client = NULL;
1737 if (0 != __stt_get_feature_enabled()) {
1738 return STT_ERROR_NOT_SUPPORTED;
1740 if (0 != __stt_check_privilege()) {
1741 return STT_ERROR_PERMISSION_DENIED;
1743 if (0 != __stt_check_handle(stt, &client)) {
1744 return STT_ERROR_INVALID_PARAMETER;
1747 SLOG(LOG_INFO, TAG_STTC, "===== STT STOP");
1750 if (client->current_state != STT_STATE_RECORDING) {
1751 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Current state(%d) is NOT RECORDING", client->current_state); //LCOV_EXCL_LINE
1752 return STT_ERROR_INVALID_STATE;
1755 if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
1756 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state); //LCOV_EXCL_LINE
1757 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
1758 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
1759 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); //LCOV_EXCL_LINE
1760 return STT_ERROR_IN_PROGRESS_TO_READY;
1761 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
1762 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); //LCOV_EXCL_LINE
1763 return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
1766 client->internal_state = STT_INTERNAL_STATE_STOPPING;
1767 int ret = stt_dbus_request_stop(client->uid);
1769 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to stop : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1770 client->internal_state = STT_INTERNAL_STATE_NONE;
1772 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Stop is successful but not done");
1775 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1776 SLOG(LOG_DEBUG, TAG_STTC, " ");
1782 int stt_cancel(stt_h stt)
1784 stt_client_s* client = NULL;
1785 if (0 != __stt_get_feature_enabled()) {
1786 return STT_ERROR_NOT_SUPPORTED;
1788 if (0 != __stt_check_privilege()) {
1789 return STT_ERROR_PERMISSION_DENIED;
1791 if (0 != __stt_check_handle(stt, &client)) {
1792 return STT_ERROR_INVALID_PARAMETER;
1795 SLOG(LOG_INFO, TAG_STTC, "===== STT CANCEL");
1798 if (STT_STATE_RECORDING != client->current_state && STT_STATE_PROCESSING != client->current_state) {
1799 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid state : Current state(%d) is 'Ready'", client->current_state); //LCOV_EXCL_LINE
1800 return STT_ERROR_INVALID_STATE;
1803 if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
1804 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state); //LCOV_EXCL_LINE
1805 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
1806 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
1807 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); //LCOV_EXCL_LINE
1808 return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
1809 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
1810 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); //LCOV_EXCL_LINE
1811 return STT_ERROR_IN_PROGRESS_TO_READY;
1814 client->internal_state = STT_INTERNAL_STATE_CANCELING;
1815 int ret = stt_dbus_request_cancel(client->uid);
1817 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to cancel : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1818 client->internal_state = STT_INTERNAL_STATE_NONE;
1820 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Cancel is successful but not done");
1823 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1824 SLOG(LOG_DEBUG, TAG_STTC, " ");
1829 int __stt_cb_set_volume(int uid, float volume)
1831 stt_client_s* client = NULL;
1833 client = stt_client_get_by_uid(uid);
1834 if (NULL == client) {
1836 SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid");
1837 return STT_ERROR_INVALID_PARAMETER;
1841 if (STT_STATE_RECORDING != client->current_state) {
1843 SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state);
1844 return STT_ERROR_INVALID_STATE;
1848 g_volume_db = volume;
1849 SLOG(LOG_INFO, TAG_STTC, "Set volume (%f)", g_volume_db);
1854 int stt_get_recording_volume(stt_h stt, float* volume)
1856 stt_client_s* client = NULL;
1857 if (0 != __stt_get_feature_enabled()) {
1858 return STT_ERROR_NOT_SUPPORTED;
1860 if (0 != __stt_check_privilege()) {
1861 return STT_ERROR_PERMISSION_DENIED;
1863 if (0 != __stt_check_handle(stt, &client)) {
1864 return STT_ERROR_INVALID_PARAMETER;
1867 if (NULL == volume) {
1868 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1869 return STT_ERROR_INVALID_PARAMETER;
1872 if (STT_STATE_RECORDING != client->current_state) {
1873 SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state); //LCOV_EXCL_LINE
1874 return STT_ERROR_INVALID_STATE;
1877 *volume = g_volume_db;
1879 SLOG(LOG_INFO, TAG_STTC, "Get recording volume (%f)", *volume);
1881 return STT_ERROR_NONE;
1885 bool __stt_result_time_cb(int index, int event, const char* text, long start_time, long end_time, void* user_data)
1887 stt_client_s* client = (stt_client_s*)user_data;
1890 if (NULL == client) {
1891 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid");
1895 if (NULL != client->result_time_cb) {
1896 SLOG(LOG_INFO, TAG_STTC, "(%d) event(%d) text(%s) start(%ld) end(%ld)",
1897 index, event, text, start_time, end_time);
1898 client->result_time_cb(client->stt, index, (stt_result_time_event_e)event,
1899 text, start_time, end_time, client->result_time_user_data);
1901 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Callback is NULL");
1909 int stt_foreach_detailed_result(stt_h stt, stt_result_time_cb callback, void* user_data)
1911 stt_client_s* client = NULL;
1912 if (0 != __stt_get_feature_enabled()) {
1913 return STT_ERROR_NOT_SUPPORTED;
1915 if (0 != __stt_check_privilege()) {
1916 return STT_ERROR_PERMISSION_DENIED;
1918 if (0 != __stt_check_handle(stt, &client)) {
1919 return STT_ERROR_INVALID_PARAMETER;
1922 SLOG(LOG_INFO, TAG_STTC, "===== STT FOREACH DETAILED RESULT");
1924 if (NULL == callback) {
1925 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1926 return STT_ERROR_INVALID_PARAMETER;
1929 client->result_time_cb = callback;
1930 client->result_time_user_data = user_data;
1933 ret = stt_config_mgr_foreach_time_info(__stt_result_time_cb, client);
1934 ret = __stt_convert_config_error_code(ret);
1936 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to foreach time info : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1939 client->result_time_cb = NULL;
1940 client->result_time_user_data = NULL;
1942 SLOG(LOG_INFO, TAG_STTC, "=====");
1943 SLOG(LOG_DEBUG, TAG_STTC, " ");
1948 static void __stt_notify_error(void *data)
1950 stt_client_s* client = (stt_client_s*)data;
1952 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error from sttd");
1955 if (NULL == client) {
1956 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); //LCOV_EXCL_LINE
1960 if (NULL == stt_client_get_by_uid(client->uid))
1963 if (NULL != client->error_cb) {
1964 stt_client_use_callback(client);
1965 g_err_callback_status = true;
1966 client->error_cb(client->stt, client->reason, client->error_user_data);
1967 g_err_callback_status = false;
1968 stt_client_not_use_callback(client);
1969 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is called : reason [%d]", client->reason);
1971 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null"); //LCOV_EXCL_LINE
1977 int __stt_cb_error(int uid, int reason, char* err_msg)
1981 GList* client_list = NULL;
1982 client_list = stt_client_get_client_list();
1985 stt_client_s *data = NULL;
1987 if (g_list_length(client_list) > 0) {
1988 /* Get a first item */
1989 iter = g_list_first(client_list);
1991 while (NULL != iter) {
1994 data->reason = reason;
1995 data->internal_state = STT_INTERNAL_STATE_NONE;
1996 if (NULL != data->err_msg) {
1997 free(data->err_msg);
1998 data->err_msg = NULL;
2000 if (NULL != err_msg)
2001 data->err_msg = strdup(err_msg);
2003 SLOG(LOG_INFO, TAG_STTC, "internal state is initialized to 0");
2005 if (NULL != data->error_cb) {
2006 ecore_main_loop_thread_safe_call_async(__stt_notify_error, data);
2008 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
2011 if (STT_ERROR_SERVICE_RESET == reason) {
2012 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Service reset");
2014 data->current_state = STT_STATE_CREATED;
2015 if (0 != stt_prepare(data->stt)) {
2016 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare");
2021 iter = g_list_next(iter);
2026 stt_client_s* client = stt_client_get_by_uid(uid);
2027 if (NULL == client) {
2028 SLOG(LOG_ERROR, TAG_STTC, "Handle not found"); //LCOV_EXCL_LINE
2032 client->reason = reason;
2033 client->internal_state = STT_INTERNAL_STATE_NONE;
2034 if (NULL != client->err_msg) {
2035 free(client->err_msg);
2036 client->err_msg = NULL;
2038 if (NULL != err_msg)
2039 client->err_msg = strdup(err_msg);
2041 SLOG(LOG_INFO, TAG_STTC, "internal state is initialized to 0");
2043 if (NULL != client->error_cb) {
2044 ecore_main_loop_thread_safe_call_async(__stt_notify_error, client);
2046 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
2049 if (STT_ERROR_SERVICE_RESET == reason) {
2050 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Service reset"); //LCOV_EXCL_LINE
2052 client->current_state = STT_STATE_CREATED;
2053 if (0 != stt_prepare(client->stt)) {
2054 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare"); //LCOV_EXCL_LINE
2062 static void __stt_notify_state_changed(void *data)
2064 stt_client_s* client = (stt_client_s*)data;
2067 if (NULL == client) {
2068 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); //LCOV_EXCL_LINE
2072 if (NULL == stt_client_get_by_uid(client->uid)) {
2076 if (STT_INTERNAL_STATE_STARTING == client->internal_state && STT_STATE_RECORDING == client->current_state) {
2077 client->internal_state = STT_INTERNAL_STATE_NONE;
2078 SLOG(LOG_INFO, TAG_STTC, "Internal state change to NONE");
2079 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state && STT_STATE_PROCESSING == client->current_state) {
2080 client->internal_state = STT_INTERNAL_STATE_NONE;
2081 SLOG(LOG_INFO, TAG_STTC, "Internal state change to NONE");
2082 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state && STT_STATE_READY == client->current_state) {
2083 client->internal_state = STT_INTERNAL_STATE_NONE;
2084 SLOG(LOG_INFO, TAG_STTC, "Internal state change to NONE");
2087 if (NULL != client->state_changed_cb) {
2088 stt_client_use_callback(client);
2089 client->state_changed_cb(client->stt, client->before_state,
2090 client->current_state, client->state_changed_user_data);
2091 stt_client_not_use_callback(client);
2092 SLOG(LOG_INFO, TAG_STTC, "State changed callback is called, State(%d)", client->current_state);
2094 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null, State(%d)", client->current_state); //LCOV_EXCL_LINE
2100 static Eina_Bool __stt_notify_result(void *data)
2102 stt_client_s* client = (stt_client_s*)data;
2105 if (NULL == client) {
2106 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); //LCOV_EXCL_LINE
2110 if (NULL == stt_client_get_by_uid(client->uid)) {
2114 if (NULL != client->recognition_result_cb) {
2115 stt_client_use_callback(client);
2116 client->recognition_result_cb(client->stt, client->event, (const char**)client->data_list, client->data_count,
2117 client->msg, client->recognition_result_user_data);
2118 stt_client_not_use_callback(client);
2119 SLOG(LOG_INFO, TAG_STTC, "client recognition result callback called");
2121 SLOG(LOG_WARN, TAG_STTC, "[WARNING] User recognition result callback is NULL");
2124 if (NULL != client->msg) {
2129 if (NULL != client->data_list) {
2131 temp = client->data_list;
2134 for (i = 0; i < client->data_count; i++) {
2135 if (NULL != temp[i]) {
2139 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result data is error"); //LCOV_EXCL_LINE
2142 free(client->data_list);
2143 client->data_list = NULL;
2146 client->data_count = 0;
2148 stt_config_mgr_remove_time_info_file();
2150 if (STT_RESULT_EVENT_FINAL_RESULT == client->event || STT_RESULT_EVENT_ERROR == client->event) {
2151 client->before_state = client->current_state;
2152 client->current_state = STT_STATE_READY;
2154 if (NULL != client->state_changed_cb) {
2155 ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client);
2157 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); //LCOV_EXCL_LINE
2164 int __stt_cb_result(int uid, int event, char** data, int data_count, const char* msg)
2166 stt_client_s* client = NULL;
2168 client = stt_client_get_by_uid(uid);
2169 if (NULL == client) {
2170 SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid"); //LCOV_EXCL_LINE
2171 return STT_ERROR_INVALID_PARAMETER;
2175 SECURE_SLOG(LOG_INFO, TAG_STTC, "Recognition Result Message = %s", msg);
2178 for (i = 0; i < data_count; i++) {
2179 if (NULL != data[i])
2180 SECURE_SLOG(LOG_INFO, TAG_STTC, "Recognition Result[%d] = %s", i, data[i]);
2183 if (NULL != client->recognition_result_cb) {
2184 client->event = event;
2186 client->msg = strdup(msg);
2189 client->data_count = data_count;
2191 if (data_count > 0) {
2193 temp = (char**)calloc(data_count, sizeof(char*));
2195 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); //LCOV_EXCL_LINE
2196 return STT_ERROR_OUT_OF_MEMORY;
2199 for (i = 0; i < data_count; i++) {
2200 if (NULL != data[i])
2201 temp[i] = strdup(data[i]);
2203 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result data is error"); //LCOV_EXCL_LINE
2206 client->data_list = temp;
2209 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] User result callback is null");
2212 __stt_notify_result(client);
2214 return STT_ERROR_NONE;
2217 int __stt_cb_set_state(int uid, int state)
2219 stt_client_s* client = stt_client_get_by_uid(uid);
2220 if (NULL == client) {
2221 SLOG(LOG_ERROR, TAG_STTC, "Handle not found"); //LCOV_EXCL_LINE
2225 stt_state_e state_from_daemon = (stt_state_e)state;
2227 if (client->current_state == state_from_daemon) {
2228 SLOG(LOG_DEBUG, TAG_STTC, "Current state has already been %d", client->current_state);
2232 client->before_state = client->current_state;
2233 client->current_state = state_from_daemon;
2235 ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client);
2239 static void __stt_notify_speech_status(void *data)
2241 stt_client_s* client = (stt_client_s*)data;
2244 if (NULL == client) {
2245 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify speech status : A handle is not valid"); //LCOV_EXCL_LINE
2249 if (NULL == stt_client_get_by_uid(client->uid)) {
2253 if (NULL != client->speech_status_cb) {
2254 stt_client_use_callback(client);
2255 client->speech_status_cb(client->stt, client->speech_status, client->speech_status_user_data);
2256 stt_client_not_use_callback(client);
2257 SLOG(LOG_INFO, TAG_STTC, "Speech status callback is called"); //LCOV_EXCL_LINE
2259 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Speech status callback is null"); //LCOV_EXCL_LINE
2265 int __stt_cb_speech_status(int uid, int status)
2267 stt_client_s* client = stt_client_get_by_uid(uid);
2268 if (NULL == client) {
2269 SLOG(LOG_ERROR, TAG_STTC, "Handle not found"); //LCOV_EXCL_LINE
2273 client->speech_status = status;
2275 ecore_main_loop_thread_safe_call_async(__stt_notify_speech_status, client);
2279 int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, void* user_data)
2281 stt_client_s* client = NULL;
2282 if (0 != __stt_get_feature_enabled()) {
2283 return STT_ERROR_NOT_SUPPORTED;
2285 if (0 != __stt_check_privilege()) {
2286 return STT_ERROR_PERMISSION_DENIED;
2288 if (0 != __stt_check_handle(stt, &client)) {
2289 return STT_ERROR_INVALID_PARAMETER;
2292 if (callback == NULL)
2293 return STT_ERROR_INVALID_PARAMETER;
2295 if (STT_STATE_CREATED != client->current_state) {
2296 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2297 return STT_ERROR_INVALID_STATE;
2300 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set recognition result cb");
2302 client->recognition_result_cb = callback;
2303 client->recognition_result_user_data = user_data;
2308 int stt_unset_recognition_result_cb(stt_h stt)
2310 stt_client_s* client = NULL;
2311 if (0 != __stt_get_feature_enabled()) {
2312 return STT_ERROR_NOT_SUPPORTED;
2314 if (0 != __stt_check_privilege()) {
2315 return STT_ERROR_PERMISSION_DENIED;
2317 if (0 != __stt_check_handle(stt, &client)) {
2318 return STT_ERROR_INVALID_PARAMETER;
2321 if (STT_STATE_CREATED != client->current_state) {
2322 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2323 return STT_ERROR_INVALID_STATE;
2326 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset recognition result cb");
2328 client->recognition_result_cb = NULL;
2329 client->recognition_result_user_data = NULL;
2334 int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data)
2336 stt_client_s* client = NULL;
2337 if (0 != __stt_get_feature_enabled()) {
2338 return STT_ERROR_NOT_SUPPORTED;
2340 if (0 != __stt_check_privilege()) {
2341 return STT_ERROR_PERMISSION_DENIED;
2343 if (0 != __stt_check_handle(stt, &client)) {
2344 return STT_ERROR_INVALID_PARAMETER;
2347 if (NULL == callback)
2348 return STT_ERROR_INVALID_PARAMETER;
2350 if (STT_STATE_CREATED != client->current_state) {
2351 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2352 return STT_ERROR_INVALID_STATE;
2355 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set state changed cb");
2357 client->state_changed_cb = callback;
2358 client->state_changed_user_data = user_data;
2363 int stt_unset_state_changed_cb(stt_h stt)
2365 stt_client_s* client = NULL;
2366 if (0 != __stt_get_feature_enabled()) {
2367 return STT_ERROR_NOT_SUPPORTED;
2369 if (0 != __stt_check_privilege()) {
2370 return STT_ERROR_PERMISSION_DENIED;
2372 if (0 != __stt_check_handle(stt, &client)) {
2373 return STT_ERROR_INVALID_PARAMETER;
2376 if (STT_STATE_CREATED != client->current_state) {
2377 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2378 return STT_ERROR_INVALID_STATE;
2381 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset state changed cb");
2383 client->state_changed_cb = NULL;
2384 client->state_changed_user_data = NULL;
2389 int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data)
2391 stt_client_s* client = NULL;
2392 if (0 != __stt_get_feature_enabled()) {
2393 return STT_ERROR_NOT_SUPPORTED;
2395 if (0 != __stt_check_privilege()) {
2396 return STT_ERROR_PERMISSION_DENIED;
2398 if (0 != __stt_check_handle(stt, &client)) {
2399 return STT_ERROR_INVALID_PARAMETER;
2402 if (NULL == callback)
2403 return STT_ERROR_INVALID_PARAMETER;
2405 if (STT_STATE_CREATED != client->current_state) {
2406 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2407 return STT_ERROR_INVALID_STATE;
2410 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set error cb");
2412 client->error_cb = callback;
2413 client->error_user_data = user_data;
2418 int stt_unset_error_cb(stt_h stt)
2420 stt_client_s* client = NULL;
2421 if (0 != __stt_get_feature_enabled()) {
2422 return STT_ERROR_NOT_SUPPORTED;
2424 if (0 != __stt_check_privilege()) {
2425 return STT_ERROR_PERMISSION_DENIED;
2427 if (0 != __stt_check_handle(stt, &client)) {
2428 return STT_ERROR_INVALID_PARAMETER;
2431 if (STT_STATE_CREATED != client->current_state) {
2432 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2433 return STT_ERROR_INVALID_STATE;
2436 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset error cb");
2438 client->error_cb = NULL;
2439 client->error_user_data = NULL;
2444 int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_cb callback, void* user_data)
2446 stt_client_s* client = NULL;
2447 if (0 != __stt_get_feature_enabled()) {
2448 return STT_ERROR_NOT_SUPPORTED;
2450 if (0 != __stt_check_privilege()) {
2451 return STT_ERROR_PERMISSION_DENIED;
2453 if (0 != __stt_check_handle(stt, &client)) {
2454 return STT_ERROR_INVALID_PARAMETER;
2457 if (NULL == callback)
2458 return STT_ERROR_INVALID_PARAMETER;
2460 if (STT_STATE_CREATED != client->current_state) {
2461 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2462 return STT_ERROR_INVALID_STATE;
2465 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set default language changed cb");
2467 client->default_lang_changed_cb = callback;
2468 client->default_lang_changed_user_data = user_data;
2473 int stt_unset_default_language_changed_cb(stt_h stt)
2475 stt_client_s* client = NULL;
2476 if (0 != __stt_get_feature_enabled()) {
2477 return STT_ERROR_NOT_SUPPORTED;
2479 if (0 != __stt_check_privilege()) {
2480 return STT_ERROR_PERMISSION_DENIED;
2482 if (0 != __stt_check_handle(stt, &client)) {
2483 return STT_ERROR_INVALID_PARAMETER;
2486 if (STT_STATE_CREATED != client->current_state) {
2487 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2488 return STT_ERROR_INVALID_STATE;
2491 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset default language changed cb");
2493 client->default_lang_changed_cb = NULL;
2494 client->default_lang_changed_user_data = NULL;
2499 int stt_set_engine_changed_cb(stt_h stt, stt_engine_changed_cb callback, void* user_data)
2501 stt_client_s* client = NULL;
2502 if (0 != __stt_get_feature_enabled()) {
2503 return STT_ERROR_NOT_SUPPORTED;
2505 if (0 != __stt_check_privilege()) {
2506 return STT_ERROR_PERMISSION_DENIED;
2508 if (0 != __stt_check_handle(stt, &client)) {
2509 return STT_ERROR_INVALID_PARAMETER;
2512 if (NULL == callback)
2513 return STT_ERROR_INVALID_PARAMETER;
2515 if (STT_STATE_CREATED != client->current_state) {
2516 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2517 return STT_ERROR_INVALID_STATE;
2520 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set engine changed cb");
2522 client->engine_changed_cb = callback;
2523 client->engine_changed_user_data = user_data;
2528 int stt_unset_engine_changed_cb(stt_h stt)
2530 stt_client_s* client = NULL;
2531 if (0 != __stt_get_feature_enabled()) {
2532 return STT_ERROR_NOT_SUPPORTED;
2534 if (0 != __stt_check_privilege()) {
2535 return STT_ERROR_PERMISSION_DENIED;
2537 if (0 != __stt_check_handle(stt, &client)) {
2538 return STT_ERROR_INVALID_PARAMETER;
2541 if (STT_STATE_CREATED != client->current_state) {
2542 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2543 return STT_ERROR_INVALID_STATE;
2546 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset engine changed cb");
2548 client->engine_changed_cb = NULL;
2549 client->engine_changed_user_data = NULL;
2555 int stt_set_speech_status_cb(stt_h stt, stt_speech_status_cb callback, void* user_data)
2557 stt_client_s* client = NULL;
2558 if (0 != __stt_get_feature_enabled()) {
2559 return STT_ERROR_NOT_SUPPORTED;
2561 if (0 != __stt_check_privilege()) {
2562 return STT_ERROR_PERMISSION_DENIED;
2564 if (0 != __stt_check_handle(stt, &client)) {
2565 return STT_ERROR_INVALID_PARAMETER;
2568 if (NULL == callback)
2569 return STT_ERROR_INVALID_PARAMETER;
2571 if (STT_STATE_CREATED != client->current_state) {
2572 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2573 return STT_ERROR_INVALID_STATE;
2576 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set speech status cb");
2578 client->speech_status_cb = callback;
2579 client->speech_status_user_data = user_data;
2584 int stt_unset_speech_status_cb(stt_h stt)
2586 stt_client_s* client = NULL;
2587 if (0 != __stt_get_feature_enabled()) {
2588 return STT_ERROR_NOT_SUPPORTED;
2590 if (0 != __stt_check_privilege()) {
2591 return STT_ERROR_PERMISSION_DENIED;
2593 if (0 != __stt_check_handle(stt, &client)) {
2594 return STT_ERROR_INVALID_PARAMETER;
2597 if (STT_STATE_CREATED != client->current_state) {
2598 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2599 return STT_ERROR_INVALID_STATE;
2602 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset speech status cb");
2604 client->speech_status_cb = NULL;
2605 client->speech_status_user_data = NULL;
2610 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)
2612 stt_client_s* client = NULL;
2613 if (0 != __stt_get_feature_enabled()) {
2614 return STT_ERROR_NOT_SUPPORTED;
2616 if (0 != __stt_check_privilege()) {
2617 return STT_ERROR_PERMISSION_DENIED;
2619 if (0 != __stt_check_handle(stt, &client)) {
2620 return STT_ERROR_INVALID_PARAMETER;
2622 if (NULL == filepath) {
2623 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
2624 return STT_ERROR_INVALID_PARAMETER;
2627 SLOG(LOG_INFO, TAG_STTC, "===== STT START FILE");
2630 if (client->current_state != STT_STATE_READY) {
2631 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
2632 return STT_ERROR_INVALID_STATE;
2635 if (STT_INTERNAL_STATE_NONE != client->internal_state) {
2636 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state);
2637 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
2641 char appid[1024] = {0, };
2642 ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1);
2644 if ((AUL_R_OK != ret) || (0 == strlen(appid))) {
2645 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID");
2647 SLOG(LOG_INFO, TAG_STTC, "[DEBUG] Current app id is %s", appid);
2651 if (NULL == language) {
2652 temp = strdup("default");
2654 temp = strdup(language);
2658 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
2659 return STT_ERROR_OUT_OF_MEMORY;
2662 if (true == client->credential_needed && NULL == client->credential) {
2663 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id);
2666 return STT_ERROR_PERMISSION_DENIED;
2669 client->internal_state = STT_INTERNAL_STATE_STARTING;
2670 ret = stt_dbus_request_start_file(client->uid, temp, type, client->silence, appid, client->credential, filepath, audio_type, sample_rate);
2672 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start file : %s", __stt_get_error_code(ret));
2673 client->internal_state = STT_INTERNAL_STATE_NONE;
2675 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Start is successful but not done");
2681 SLOG(LOG_DEBUG, TAG_STTC, "=====");
2682 SLOG(LOG_DEBUG, TAG_STTC, " ");
2687 int stt_cancel_file(stt_h stt)
2689 stt_client_s* client = NULL;
2690 if (0 != __stt_get_feature_enabled()) {
2691 return STT_ERROR_NOT_SUPPORTED;
2693 if (0 != __stt_check_privilege()) {
2694 return STT_ERROR_PERMISSION_DENIED;
2696 if (0 != __stt_check_handle(stt, &client)) {
2697 return STT_ERROR_INVALID_PARAMETER;
2700 SLOG(LOG_INFO, TAG_STTC, "===== STT CANCEL FILE");
2703 if (STT_STATE_RECORDING != client->current_state && STT_STATE_PROCESSING != client->current_state) {
2704 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid state : Current state(%d) is 'Ready'", client->current_state);
2705 return STT_ERROR_INVALID_STATE;
2708 if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
2709 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state);
2710 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
2711 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
2712 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state);
2713 return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
2714 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
2715 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state);
2716 return STT_ERROR_IN_PROGRESS_TO_READY;
2719 client->internal_state = STT_INTERNAL_STATE_CANCELING;
2720 int ret = stt_dbus_request_cancel_file(client->uid);
2722 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to cancel file : %s", __stt_get_error_code(ret));
2723 client->internal_state = STT_INTERNAL_STATE_NONE;
2725 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Cancel file is successful but not done");
2728 SLOG(LOG_DEBUG, TAG_STTC, "=====");
2729 SLOG(LOG_DEBUG, TAG_STTC, " ");
2734 int __stt_change_system_volume(stt_system_volume_event_e volume_event)
2736 int stream_type = -1;
2737 if (STT_SYSTEM_VOLUME_EVENT_CHANGE_FOR_FARFIELD == volume_event) {
2738 stream_type = SOUND_STREAM_TYPE_VOICE_RECOGNITION;
2739 } else if (STT_SYSTEM_VOLUME_EVENT_CHANGE_FOR_NEARFIELD == volume_event) {
2740 stream_type = SOUND_STREAM_TYPE_VOICE_RECOGNITION_SERVICE;
2742 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] volume type is invalid, type(%d)", volume_event);
2743 return STT_ERROR_INVALID_PARAMETER;
2746 SLOG(LOG_INFO, TAG_STTC, "[INFO] Change system volume, volume_type(%d)", volume_event);
2748 int ret = STT_ERROR_NONE;
2749 if (g_stream_for_volume_h) {
2750 SLOG(LOG_INFO, TAG_STTC, "[INFO] Stream is already created, destroy stream)");
2751 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
2753 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
2755 g_stream_for_volume_h = NULL;
2758 ret = sound_manager_create_stream_information_internal(stream_type, NULL, NULL, &g_stream_for_volume_h);
2760 SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Fail to create stream information, ret(%d)", ret);
2761 return STT_ERROR_OPERATION_FAILED;
2764 if (g_virtual_sound_stream_h) {
2765 SLOG(LOG_INFO, TAG_STTC, "[INFO] Virtual stream is already created, destroy virtual stream)");
2766 ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h);
2768 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy virtual stream, ret(%d)", ret);
2769 return STT_ERROR_OPERATION_FAILED;
2771 g_virtual_sound_stream_h = NULL;
2774 ret = sound_manager_create_virtual_stream(g_stream_for_volume_h, &g_virtual_sound_stream_h);
2776 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create virtual stream, ret(%d)", ret);
2777 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
2779 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
2781 g_stream_for_volume_h = NULL;
2782 return STT_ERROR_OPERATION_FAILED;
2785 ret = sound_manager_start_virtual_stream(g_virtual_sound_stream_h);
2787 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start virtual stream, ret(%d)", ret);
2788 ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h);
2790 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy virtual stream, ret(%d)", ret);
2792 g_virtual_sound_stream_h = NULL;
2794 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
2796 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
2798 g_stream_for_volume_h = NULL;
2800 return STT_ERROR_OPERATION_FAILED;
2803 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Change system volume");
2807 int __stt_recover_system_volume()
2809 SLOG(LOG_INFO, TAG_STTC, "[INFO] Recover system volume");
2811 int ret = STT_ERROR_NONE;
2813 if (g_virtual_sound_stream_h) {
2814 ret = sound_manager_stop_virtual_stream(g_virtual_sound_stream_h);
2816 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to stop virtual stream, ret(%d)", ret);
2817 return STT_ERROR_OPERATION_FAILED;
2819 ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h);
2821 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy virtual stream, ret(%d)", ret);
2822 return STT_ERROR_OPERATION_FAILED;
2824 g_virtual_sound_stream_h = NULL;
2827 if (g_stream_for_volume_h) {
2828 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
2830 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
2831 return STT_ERROR_OPERATION_FAILED;
2833 g_stream_for_volume_h = NULL;
2836 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Recover system volume");
2840 int stt_change_system_volume(stt_h stt, stt_system_volume_event_e volume_event)
2842 SLOG(LOG_DEBUG, TAG_STTC, "[STT] Change system volume, volume_event(%d)", volume_event);
2844 stt_client_s* client = NULL;
2845 if (0 != __stt_get_feature_enabled()) {
2846 return STT_ERROR_NOT_SUPPORTED;
2848 if (0 != __stt_check_privilege()) {
2849 return STT_ERROR_PERMISSION_DENIED;
2851 if (0 != __stt_check_handle(stt, &client)) {
2852 return STT_ERROR_INVALID_PARAMETER;
2856 if (client->current_state != STT_STATE_READY && client->current_state != STT_STATE_CREATED) {
2857 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY nor CREATED", client->current_state);
2858 return STT_ERROR_INVALID_STATE;
2861 /* change system volume */
2862 int ret = __stt_change_system_volume(volume_event);
2864 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to change volume");
2866 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Success to change volume");
2871 int stt_recover_system_volume(stt_h stt)
2873 SLOG(LOG_DEBUG, TAG_STTC, "[STT] recover system volume");
2875 stt_client_s* client = NULL;
2876 if (0 != __stt_get_feature_enabled()) {
2877 return STT_ERROR_NOT_SUPPORTED;
2879 if (0 != __stt_check_privilege()) {
2880 return STT_ERROR_PERMISSION_DENIED;
2882 if (0 != __stt_check_handle(stt, &client)) {
2883 return STT_ERROR_INVALID_PARAMETER;
2887 if (client->current_state != STT_STATE_READY && client->current_state != STT_STATE_CREATED) {
2888 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY nor CREATED", client->current_state);
2889 return STT_ERROR_INVALID_STATE;
2892 /* recover volume */
2893 int ret = __stt_recover_system_volume();
2895 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to recover volume");
2897 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Success to recover volume");