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;
59 STT_SYSTEM_VOLUME_EVENT_CHANGE_FOR_NEARFIELD,
60 STT_SYSTEM_VOLUME_EVENT_CHANGE_FOR_FARFIELD,
61 STT_SYSTEM_VOLUME_EVENT_RECOVER
62 } stt_system_volume_event_e;
72 static int __stt_get_feature_enabled()
74 if (0 == g_feature_enabled) {
76 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported");
77 return STT_ERROR_NOT_SUPPORTED;
79 } else if (-1 == g_feature_enabled) {
80 bool stt_supported = false;
81 bool mic_supported = false;
82 if (0 == system_info_get_platform_bool(STT_FEATURE_PATH, &stt_supported)) {
83 if (0 == system_info_get_platform_bool(STT_MIC_FEATURE_PATH, &mic_supported)) {
84 if (false == stt_supported || false == mic_supported) {
86 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] STT NOT supported");
87 g_feature_enabled = 0;
88 return STT_ERROR_NOT_SUPPORTED;
92 g_feature_enabled = 1;
95 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value");
96 return STT_ERROR_NOT_SUPPORTED;
101 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get feature value");
102 return STT_ERROR_NOT_SUPPORTED;
110 static int __check_privilege_initialize()
112 int ret = cynara_initialize(&p_cynara, NULL);
113 if (CYNARA_API_SUCCESS != ret)
114 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to initialize"); //LCOV_EXCL_LINE
116 return ret == CYNARA_API_SUCCESS;
119 static bool __check_privilege(const char* uid, const char * privilege)
122 char label_path[1024] = "/proc/self/attr/current";
123 char smack_label[1024] = {'\0',};
129 fp = fopen(label_path, "r");
131 if (0 >= fread(smack_label, 1, sizeof(smack_label), fp))
132 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] fail to fread"); //LCOV_EXCL_LINE
137 pid_t pid = getpid();
138 char *session = cynara_session_from_pid(pid);
139 int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
140 SLOG(LOG_DEBUG, TAG_STTC, "[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
146 if (ret != CYNARA_API_ACCESS_ALLOWED)
151 static void __check_privilege_deinitialize()
154 cynara_finish(p_cynara);
158 static int __stt_check_privilege()
162 if (0 == g_privilege_allowed) {
163 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied"); //LCOV_EXCL_LINE
164 return STT_ERROR_PERMISSION_DENIED;
165 } else if (-1 == g_privilege_allowed) {
166 if (false == __check_privilege_initialize()) {
167 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed"); //LCOV_EXCL_LINE
168 return STT_ERROR_PERMISSION_DENIED;
170 snprintf(uid, 16, "%d", getuid());
171 if (false == __check_privilege(uid, STT_PRIVILEGE_RECORDER)) {
172 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied"); //LCOV_EXCL_LINE
173 g_privilege_allowed = 0;
174 __check_privilege_deinitialize();
175 return STT_ERROR_PERMISSION_DENIED;
177 __check_privilege_deinitialize();
180 g_privilege_allowed = 1;
181 return STT_ERROR_NONE;
184 static int __stt_check_privilege_for_applaunch()
188 if (0 == g_privilege_applaunch_allowed) {
189 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission for applaunch is denied"); //LCOV_EXCL_LINE
190 return STT_ERROR_PERMISSION_DENIED;
191 } else if (-1 == g_privilege_applaunch_allowed) {
192 if (false == __check_privilege_initialize()) {
193 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed (applaunch)"); //LCOV_EXCL_LINE
194 return STT_ERROR_PERMISSION_DENIED;
196 snprintf(uid, 16, "%d", getuid());
197 if (false == __check_privilege(uid, STT_PRIVILEGE_APPLAUNCH)) {
198 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied : appmanager.launch"); //LCOV_EXCL_LINE
199 g_privilege_applaunch_allowed = 0;
200 __check_privilege_deinitialize();
201 return STT_ERROR_PERMISSION_DENIED;
203 __check_privilege_deinitialize();
206 g_privilege_applaunch_allowed = 1;
207 return STT_ERROR_NONE;
210 static const char* __stt_get_error_code(stt_error_e err)
214 case STT_ERROR_NONE: return "STT_ERROR_NONE";
215 case STT_ERROR_OUT_OF_MEMORY: return "STT_ERROR_OUT_OF_MEMORY";
216 case STT_ERROR_IO_ERROR: return "STT_ERROR_IO_ERROR";
217 case STT_ERROR_INVALID_PARAMETER: return "STT_ERROR_INVALID_PARAMETER";
218 case STT_ERROR_TIMED_OUT: return "STT_ERROR_TIMED_OUT";
219 case STT_ERROR_RECORDER_BUSY: return "STT_ERROR_RECORDER_BUSY";
220 case STT_ERROR_OUT_OF_NETWORK: return "STT_ERROR_OUT_OF_NETWORK";
221 case STT_ERROR_PERMISSION_DENIED: return "STT_ERROR_PERMISSION_DENIED";
222 case STT_ERROR_NOT_SUPPORTED: return "STT_ERROR_NOT_SUPPORTED";
223 case STT_ERROR_INVALID_STATE: return "STT_ERROR_INVALID_STATE";
224 case STT_ERROR_INVALID_LANGUAGE: return "STT_ERROR_INVALID_LANGUAGE";
225 case STT_ERROR_ENGINE_NOT_FOUND: return "STT_ERROR_ENGINE_NOT_FOUND";
226 case STT_ERROR_OPERATION_FAILED: return "STT_ERROR_OPERATION_FAILED";
227 case STT_ERROR_NOT_SUPPORTED_FEATURE: return "STT_ERROR_NOT_SUPPORTED_FEATURE";
228 case STT_ERROR_SERVICE_RESET: return "STT_ERROR_SERVICE_RESET";
230 return "Invalid error code";
235 static int __stt_convert_config_error_code(stt_config_error_e code)
238 if (code == STT_CONFIG_ERROR_NONE) return STT_ERROR_NONE;
239 if (code == STT_CONFIG_ERROR_OUT_OF_MEMORY) return STT_ERROR_OUT_OF_MEMORY;
240 if (code == STT_CONFIG_ERROR_IO_ERROR) return STT_ERROR_IO_ERROR;
241 if (code == STT_CONFIG_ERROR_INVALID_PARAMETER) return STT_ERROR_INVALID_PARAMETER;
242 if (code == STT_CONFIG_ERROR_PERMISSION_DENIED) return STT_ERROR_PERMISSION_DENIED;
243 if (code == STT_CONFIG_ERROR_NOT_SUPPORTED) return STT_ERROR_NOT_SUPPORTED;
244 if (code == STT_CONFIG_ERROR_INVALID_STATE) return STT_ERROR_INVALID_STATE;
245 if (code == STT_CONFIG_ERROR_INVALID_LANGUAGE) return STT_ERROR_INVALID_LANGUAGE;
246 if (code == STT_CONFIG_ERROR_ENGINE_NOT_FOUND) return STT_ERROR_ENGINE_NOT_FOUND;
247 if (code == STT_CONFIG_ERROR_OPERATION_FAILED) return STT_ERROR_OPERATION_FAILED;
253 void __stt_config_lang_changed_cb(const char* before_language, const char* current_language, void* user_data)
255 SLOG(LOG_DEBUG, TAG_STTC, "Language changed : Before lang(%s) Current lang(%s)",
256 before_language, current_language);
258 if (0 == strcmp(before_language, current_language)) {
262 GList* client_list = NULL;
263 client_list = stt_client_get_client_list();
266 stt_client_s *data = NULL;
268 if (g_list_length(client_list) > 0) {
269 /* Get a first item */
270 iter = g_list_first(client_list);
272 while (NULL != iter) {
274 if (NULL != data->default_lang_changed_cb) {
275 SLOG(LOG_DEBUG, TAG_STTC, "Call default language changed callback : uid(%d)", data->uid);
276 data->default_lang_changed_cb(data->stt, before_language, current_language,
277 data->default_lang_changed_user_data);
281 iter = g_list_next(iter);
288 static Eina_Bool __reconnect_by_engine_changed(void *data)
290 stt_h stt = (stt_h)data;
292 stt_client_s* client = stt_client_get(stt);
293 if (NULL == client) {
294 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
298 if (STT_STATE_READY != client->current_state) {
303 int ret = stt_unprepare(stt);
305 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
307 ret = stt_prepare(stt);
309 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
315 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)
317 stt_h stt = (stt_h)user_data;
319 stt_client_s* client = stt_client_get(stt);
320 if (NULL == client) {
321 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
325 if (NULL != engine_id) SLOG(LOG_DEBUG, TAG_STTC, "Engine id(%s)", engine_id);
326 if (NULL != setting) SLOG(LOG_DEBUG, TAG_STTC, "Engine setting(%s)", setting);
327 if (NULL != language) SLOG(LOG_DEBUG, TAG_STTC, "Language(%s)", language);
328 SLOG(LOG_DEBUG, TAG_STTC, "Silence(%s), Credential(%s)", support_silence ? "on" : "off", need_credential ? "need" : "no need");
330 /* When the default engine is changed, please unload the old engine and load the new one. */
333 if (NULL == client->current_engine_id) {
334 if (STT_STATE_RECORDING == client->current_state || STT_STATE_PROCESSING == client->current_state) {
335 SLOG(LOG_INFO, TAG_STTC, "[INFO] stt cancel is invoked by engine_changed_cb, state(%d)", client->current_state);
336 ret = stt_cancel(stt);
338 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] STT client cancelling...");
341 ecore_idler_add(__reconnect_by_engine_changed, (void*)stt);
342 } else if (STT_STATE_READY == client->current_state) {
343 ret = stt_unprepare(stt);
345 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
347 ret = stt_prepare(stt);
349 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare for setting a new engine... (%d)", ret);
354 /* call callback function */
355 if (NULL != client->engine_changed_cb) {
356 client->engine_changed_cb(stt, engine_id, language, support_silence, need_credential, client->engine_changed_user_data);
358 SLOG(LOG_WARN, TAG_STTC, "No registered callback function for engine change");
363 static int __stt_check_handle(stt_h stt, stt_client_s** client)
366 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input handle is null");
367 return STT_ERROR_INVALID_PARAMETER;
370 stt_client_s* temp = NULL;
371 temp = stt_client_get(stt);
375 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available");
376 return STT_ERROR_INVALID_PARAMETER;
380 return STT_ERROR_NONE;
383 int stt_create(stt_h* stt)
385 if (0 != __stt_get_feature_enabled()) {
386 return STT_ERROR_NOT_SUPPORTED;
388 if (0 != __stt_check_privilege()) {
389 return STT_ERROR_PERMISSION_DENIED;
392 SLOG(LOG_INFO, TAG_STTC, "===== Create STT");
395 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is null");
396 return STT_ERROR_INVALID_PARAMETER;
399 if (0 == stt_client_get_size()) {
400 if (0 != stt_dbus_open_connection()) {
402 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to open connection");
403 return STT_ERROR_OPERATION_FAILED;
408 if (0 != stt_client_new(stt)) {
410 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client!");
411 return STT_ERROR_OUT_OF_MEMORY;
415 stt_client_s* client = stt_client_get(*stt);
416 if (NULL == client) {
417 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create client"); //LCOV_EXCL_LINE
418 stt_client_destroy(*stt);
419 return STT_ERROR_OPERATION_FAILED;
422 int ret = stt_config_mgr_initialize(client->uid);
423 ret = __stt_convert_config_error_code(ret);
425 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to init config manager : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
426 stt_client_destroy(*stt);
430 ret = stt_config_mgr_set_callback(client->uid, __stt_config_engine_changed_cb, __stt_config_lang_changed_cb, NULL, client->stt);
431 ret = __stt_convert_config_error_code(ret);
433 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set config changed : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
434 stt_client_destroy(*stt);
438 SLOG(LOG_INFO, TAG_STTC, "[Success] uid(%d)", (*stt)->handle);
440 SLOG(LOG_DEBUG, TAG_STTC, "=====");
441 SLOG(LOG_DEBUG, TAG_STTC, " ");
443 return STT_ERROR_NONE;
446 int stt_destroy(stt_h stt)
448 stt_client_s* client = NULL;
449 if (0 != __stt_get_feature_enabled()) {
450 return STT_ERROR_NOT_SUPPORTED;
452 if (0 != __stt_check_privilege()) {
453 return STT_ERROR_PERMISSION_DENIED;
455 if (0 != __stt_check_handle(stt, &client)) {
456 return STT_ERROR_INVALID_PARAMETER;
459 SLOG(LOG_INFO, TAG_STTC, "===== Destroy STT");
461 /* check used callback */
462 if (0 != stt_client_get_use_callback(client)) {
463 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Cannot destroy in Callback function");
464 return STT_ERROR_OPERATION_FAILED;
467 stt_config_mgr_finalize(client->uid);
472 switch (client->current_state) {
473 case STT_STATE_PROCESSING:
474 case STT_STATE_RECORDING:
475 case STT_STATE_READY:
476 ret = stt_dbus_request_finalize(client->uid);
478 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
480 case STT_STATE_CREATED:
481 if (NULL != g_connect_timer) {
482 SLOG(LOG_DEBUG, TAG_STTC, "Connect Timer is deleted");
483 ecore_timer_del(g_connect_timer);
484 g_connect_timer = NULL;
488 stt_client_destroy(stt);
494 if (0 == stt_client_get_size()) {
495 if (0 != stt_dbus_close_connection()) {
496 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to close connection"); //LCOV_EXCL_LINE
502 SLOG(LOG_INFO, TAG_STTC, "=====");
503 SLOG(LOG_DEBUG, TAG_STTC, " ");
505 return STT_ERROR_NONE;
508 bool __stt_config_supported_engine_cb(const char* engine_id, const char* engine_name,
509 const char* setting, bool support_silence, void* user_data)
511 stt_h stt = (stt_h)user_data;
513 stt_client_s* client = stt_client_get(stt);
514 if (NULL == client) {
516 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid");
521 /* call callback function */
522 if (NULL != client->supported_engine_cb) {
523 return client->supported_engine_cb(stt, engine_id, engine_name, client->supported_engine_user_data);
525 SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported engine"); //LCOV_EXCL_LINE
531 int stt_foreach_supported_engines(stt_h stt, stt_supported_engine_cb callback, void* user_data)
533 stt_client_s* client = NULL;
534 if (0 != __stt_get_feature_enabled()) {
535 return STT_ERROR_NOT_SUPPORTED;
537 if (0 != __stt_check_privilege()) {
538 return STT_ERROR_PERMISSION_DENIED;
540 if (0 != __stt_check_handle(stt, &client)) {
541 return STT_ERROR_INVALID_PARAMETER;
544 SLOG(LOG_INFO, TAG_STTC, "===== Foreach Supported engine");
546 if (NULL == callback) {
547 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
548 return STT_ERROR_INVALID_PARAMETER;
551 if (client->current_state != STT_STATE_CREATED) {
552 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state);
553 return STT_ERROR_INVALID_STATE;
556 client->supported_engine_cb = callback;
557 client->supported_engine_user_data = user_data;
560 ret = stt_config_mgr_get_engine_list(__stt_config_supported_engine_cb, client->stt);
561 ret = __stt_convert_config_error_code(ret);
563 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get engines : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
566 client->supported_engine_cb = NULL;
567 client->supported_engine_user_data = NULL;
569 SLOG(LOG_INFO, TAG_STTC, "=====");
570 SLOG(LOG_DEBUG, TAG_STTC, " ");
575 int stt_get_engine(stt_h stt, char** engine_id)
577 stt_client_s* client = NULL;
578 if (0 != __stt_get_feature_enabled()) {
579 return STT_ERROR_NOT_SUPPORTED;
581 if (0 != __stt_check_privilege()) {
582 return STT_ERROR_PERMISSION_DENIED;
584 if (0 != __stt_check_handle(stt, &client)) {
585 return STT_ERROR_INVALID_PARAMETER;
588 SLOG(LOG_INFO, TAG_STTC, "===== Get current engine");
590 if (NULL == engine_id) {
591 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
592 return STT_ERROR_INVALID_PARAMETER;
595 if (client->current_state != STT_STATE_CREATED) {
596 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state);
597 return STT_ERROR_INVALID_STATE;
602 if (NULL != client->current_engine_id) {
603 *engine_id = strdup(client->current_engine_id);
604 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", *engine_id);
607 ret = stt_config_mgr_get_engine(engine_id);
608 ret = __stt_convert_config_error_code(ret);
610 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request get current engine : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
612 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", *engine_id);
616 SLOG(LOG_INFO, TAG_STTC, "=====");
617 SLOG(LOG_DEBUG, TAG_STTC, " ");
622 int __stt_set_buxtonkey(const char* engine_id)
625 struct buxton_client * bux_cli;
626 struct buxton_layer * bux_layer;
627 struct buxton_value * bux_val;
629 int ret = buxton_open(&bux_cli, NULL, NULL);
631 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to open buxton client"); //LCOV_EXCL_LINE
632 return STT_ERROR_OPERATION_FAILED;
634 SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] buxton_open: %d", ret);
635 bux_layer = buxton_create_layer("system");
636 if (NULL == bux_layer) {
638 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_create_layer FAIL");
639 buxton_close(bux_cli);
641 return STT_ERROR_OPERATION_FAILED;
644 bux_val = buxton_value_create_string(engine_id);
645 if (NULL == bux_val) {
647 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] buxton_value_create_string FAIL");
648 buxton_free_layer(bux_layer);
649 buxton_close(bux_cli);
652 return STT_ERROR_OPERATION_FAILED;
656 ret = buxton_set_value_sync(bux_cli, bux_layer, STT_ENGINE_DB_CUSTOM, bux_val);
659 SLOG(LOG_ERROR, stt_tag(), "[DBUS-BUXTON2] Fail to set value sync");
660 buxton_value_free(bux_val);
661 buxton_free_layer(bux_layer);
662 buxton_close(bux_cli);
667 return STT_ERROR_OPERATION_FAILED;
670 SLOG(LOG_DEBUG, stt_tag(), "[DBUS-BUXTON2] buxton_set_value_sync: %d, %s", ret, STT_ENGINE_DB_CUSTOM);
672 buxton_value_free(bux_val);
673 buxton_free_layer(bux_layer);
674 buxton_close(bux_cli);
680 return STT_ERROR_NONE;
683 int stt_set_engine(stt_h stt, const char* engine_id)
685 stt_client_s* client = NULL;
686 if (0 != __stt_get_feature_enabled()) {
687 return STT_ERROR_NOT_SUPPORTED;
689 if (0 != __stt_check_privilege()) {
690 return STT_ERROR_PERMISSION_DENIED;
692 if (0 != __stt_check_privilege_for_applaunch()) {
693 return STT_ERROR_PERMISSION_DENIED;
695 if (0 != __stt_check_handle(stt, &client)) {
696 return STT_ERROR_INVALID_PARAMETER;
699 SLOG(LOG_INFO, TAG_STTC, "===== Set current engine");
701 if (NULL == engine_id) {
702 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
703 return STT_ERROR_INVALID_PARAMETER;
707 if (client->current_state != STT_STATE_CREATED) {
708 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED", client->current_state);
709 return STT_ERROR_INVALID_STATE;
712 if (NULL != client->current_engine_id) {
713 free(client->current_engine_id);
714 client->current_engine_id = NULL;
717 SLOG(LOG_INFO, TAG_STTC, "===== engined_id(%s)", engine_id);
719 client->current_engine_id = strdup(engine_id);
722 int ret = __stt_set_buxtonkey(engine_id);
724 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] set buxtonkey Failed!!!"); //LCOV_EXCL_LINE
728 SLOG(LOG_INFO, TAG_STTC, "=====");
729 SLOG(LOG_DEBUG, TAG_STTC, " ");
734 int stt_set_credential(stt_h stt, const char* credential)
736 stt_client_s* client = NULL;
737 if (0 != __stt_get_feature_enabled()) {
738 return STT_ERROR_NOT_SUPPORTED;
740 if (0 != __stt_check_privilege()) {
741 return STT_ERROR_PERMISSION_DENIED;
743 if (0 != __stt_check_handle(stt, &client)) {
744 return STT_ERROR_INVALID_PARAMETER;
747 SLOG(LOG_INFO, TAG_STTC, "===== Set credential");
749 if (NULL == credential) {
750 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
751 return STT_ERROR_INVALID_PARAMETER;
755 if (client->current_state != STT_STATE_CREATED && client->current_state != STT_STATE_READY) {
756 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not CREATED or READY", client->current_state); //LCOV_EXCL_LINE
757 return STT_ERROR_INVALID_STATE;
760 if (NULL != client->credential) {
761 free(client->credential);
762 client->credential = NULL;
764 client->credential = strdup(credential);
766 SLOG(LOG_INFO, TAG_STTC, "=====");
767 SLOG(LOG_DEBUG, TAG_STTC, " ");
769 return STT_ERROR_NONE;
772 int stt_set_private_data(stt_h stt, const char* key, const char* data)
774 stt_client_s* client = NULL;
775 if (0 != __stt_get_feature_enabled()) {
776 return STT_ERROR_NOT_SUPPORTED;
778 if (0 != __stt_check_privilege()) {
779 return STT_ERROR_PERMISSION_DENIED;
781 if (0 != __stt_check_handle(stt, &client)) {
782 return STT_ERROR_INVALID_PARAMETER;
785 SLOG(LOG_INFO, TAG_STTC, "===== Set private data");
787 if (NULL == key || NULL == data) {
788 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
789 return STT_ERROR_INVALID_PARAMETER;
793 if (STT_STATE_READY != client->current_state) {
794 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
795 return STT_ERROR_INVALID_STATE;
798 if (true != client->internal && (0 == strcmp(key, "server") || 0 == strcmp(key, "rampcode") || 0 == strcmp(key, "epd"))) {
799 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This is not an internal app"); //LCOV_EXCL_LINE
800 return STT_ERROR_INVALID_PARAMETER;
806 ret = stt_dbus_request_set_private_data(client->uid, key, data);
809 if (STT_ERROR_TIMED_OUT != ret) {
810 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data : %s", __stt_get_error_code(ret));
813 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry : %s", __stt_get_error_code(ret));
816 if (STT_RETRY_COUNT == count) {
817 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
825 SLOG(LOG_INFO, TAG_STTC, "=====");
826 SLOG(LOG_DEBUG, TAG_STTC, "");
828 return STT_ERROR_NONE;
831 int stt_get_private_data(stt_h stt, const char* key, char** data)
833 stt_client_s* client = NULL;
834 if (0 != __stt_get_feature_enabled()) {
835 return STT_ERROR_NOT_SUPPORTED;
837 if (0 != __stt_check_privilege()) {
838 return STT_ERROR_PERMISSION_DENIED;
840 if (0 != __stt_check_handle(stt, &client)) {
841 return STT_ERROR_INVALID_PARAMETER;
844 SLOG(LOG_INFO, TAG_STTC, "===== Get private data");
846 if (NULL == key || NULL == data) {
847 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
848 return STT_ERROR_INVALID_PARAMETER;
852 if (STT_STATE_READY != client->current_state) {
853 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
854 return STT_ERROR_INVALID_STATE;
860 ret = stt_dbus_request_get_private_data(client->uid, key, data);
863 if (STT_ERROR_TIMED_OUT != ret) {
864 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get private data : %s", __stt_get_error_code(ret));
867 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry : %s", __stt_get_error_code(ret));
870 if (STT_RETRY_COUNT == count) {
871 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
879 if (0 == strncmp(*data, "NULL", strlen(*data))) {
884 SLOG(LOG_INFO, TAG_STTC, "=====");
885 SLOG(LOG_DEBUG, TAG_STTC, "");
887 return STT_ERROR_NONE;
891 int stt_set_server_stt(stt_h stt, const char* key, char* user_data)
894 stt_client_s* client = NULL;
896 if (0 != __stt_get_feature_enabled()) {
897 return STT_ERROR_NOT_SUPPORTED;
899 if (0 != __stt_check_privilege()) {
900 return STT_ERROR_PERMISSION_DENIED;
902 if (0 != __stt_check_handle(stt, &client)) {
903 return STT_ERROR_INVALID_PARAMETER;
906 SLOG(LOG_INFO, TAG_STTC, "===== Set STT server");
908 if (NULL == key || NULL == user_data) {
909 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid parameter");
910 return STT_ERROR_INVALID_PARAMETER;
913 if (STT_STATE_CREATED != client->current_state && STT_STATE_READY != client->current_state) {
914 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] The current state is invalid (%d).", client->current_state);
915 return STT_ERROR_INVALID_STATE;
919 client->internal = true;
921 char* private_key = NULL;
922 private_key = strdup(key);
923 if (NULL == private_key) {
924 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(private_key)");
925 return STT_ERROR_OUT_OF_MEMORY;
929 data = strdup(user_data);
931 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory(data)");
934 return STT_ERROR_OUT_OF_MEMORY;
937 ret = stt_set_private_data(stt, private_key, data);
939 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set private data, ret(%d), key(%s)", ret, private_key);
947 SLOG(LOG_INFO, TAG_STTC, "======");
948 SLOG(LOG_DEBUG, TAG_STTC, " ");
954 static Eina_Bool __stt_connect_daemon(void *data)
956 stt_client_s* client = (stt_client_s*)data;
959 if (NULL == client) {
960 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] A handle is not available"); //LCOV_EXCL_LINE
961 g_connect_timer = NULL;
965 if (0 == stt_client_get_size() || NULL == stt_client_get_by_uid(client->uid)) {
966 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Client has been already destroyed"); //LCOV_EXCL_LINE
970 /* Check and Set vconfkey of custom engine before sending hello */
971 if (1 == g_privilege_applaunch_allowed && NULL != client->current_engine_id) {
973 ret = __stt_set_buxtonkey(client->current_engine_id);
976 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] set buxtonkey Failed!!! (inside __stt_connect_daemon)");
983 ret = stt_dbus_request_hello(client->uid);
986 if (STT_ERROR_INVALID_STATE == ret) {
987 g_connect_timer = NULL;
993 g_connect_timer = NULL;
994 SLOG(LOG_INFO, TAG_STTC, "===== Connect stt-service");
996 /* request initialization */
997 bool silence_supported = false;
998 bool credential_needed = false;
1000 ret = stt_dbus_request_initialize(client->uid, &silence_supported, &credential_needed);
1002 if (STT_ERROR_ENGINE_NOT_FOUND == ret) {
1003 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to initialize : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1005 client->reason = STT_ERROR_ENGINE_NOT_FOUND;
1006 ecore_main_loop_thread_safe_call_async(__stt_notify_error, (void*)client);
1010 } else if (STT_ERROR_NONE != ret) {
1011 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] Fail to connection. Retry to connect"); //LCOV_EXCL_LINE
1014 /* success to connect stt-service */
1015 client->silence_supported = silence_supported;
1016 client->credential_needed = credential_needed;
1017 SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need");
1021 #ifdef __UNUSED_CODES__
1022 if (NULL != client->current_engine_id) {
1025 silence_supported = false;
1026 credential_needed = false;
1027 SLOG(LOG_DEBUG, TAG_STTC, "[WARNING] current_engine_id(%s)", client->current_engine_id);
1030 ret = stt_dbus_request_set_current_engine(client->uid, client->current_engine_id, &silence_supported, &credential_needed);
1032 if (STT_ERROR_TIMED_OUT != ret) {
1033 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set current engine : %s", __stt_get_error_code(ret));
1036 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1039 if (STT_RETRY_COUNT == count) {
1040 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1045 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current engine uuid = %s", client->current_engine_id);
1047 /* success to change engine */
1048 client->silence_supported = silence_supported;
1049 SLOG(LOG_DEBUG, TAG_STTC, "Supported options : silence(%s), credential(%s)", silence_supported ? "support" : "no support", credential_needed ? "need" : "no need");
1055 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] uid(%d)", client->uid);
1057 client->before_state = client->current_state;
1058 client->current_state = STT_STATE_READY;
1060 if (NULL != client->state_changed_cb) {
1061 stt_client_use_callback(client);
1062 client->state_changed_cb(client->stt, client->before_state,
1063 client->current_state, client->state_changed_user_data);
1064 stt_client_not_use_callback(client);
1065 SLOG(LOG_DEBUG, TAG_STTC, "State changed callback is called");
1067 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
1070 SLOG(LOG_INFO, TAG_STTC, "=====");
1071 SLOG(LOG_DEBUG, TAG_STTC, " ");
1076 int stt_prepare(stt_h stt)
1078 stt_client_s* client = NULL;
1079 if (0 != __stt_get_feature_enabled()) {
1080 return STT_ERROR_NOT_SUPPORTED;
1082 if (0 != __stt_check_privilege()) {
1083 return STT_ERROR_PERMISSION_DENIED;
1085 if (0 != __stt_check_handle(stt, &client)) {
1086 return STT_ERROR_INVALID_PARAMETER;
1089 SLOG(LOG_INFO, TAG_STTC, "===== Prepare STT");
1092 if (client->current_state != STT_STATE_CREATED) {
1093 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'CREATED'", client->current_state);
1094 return STT_ERROR_INVALID_STATE;
1097 ecore_thread_main_loop_begin();
1098 g_connect_timer = ecore_timer_add(0.02, __stt_connect_daemon, (void*)client);
1099 ecore_thread_main_loop_end();
1101 SLOG(LOG_INFO, TAG_STTC, "=====");
1102 SLOG(LOG_DEBUG, TAG_STTC, " ");
1104 return STT_ERROR_NONE;
1107 int stt_unprepare(stt_h stt)
1109 stt_client_s* client = NULL;
1110 if (0 != __stt_get_feature_enabled()) {
1111 return STT_ERROR_NOT_SUPPORTED;
1113 if (0 != __stt_check_privilege()) {
1114 return STT_ERROR_PERMISSION_DENIED;
1116 if (0 != __stt_check_handle(stt, &client)) {
1117 return STT_ERROR_INVALID_PARAMETER;
1120 SLOG(LOG_INFO, TAG_STTC, "===== Unprepare STT");
1123 if (client->current_state != STT_STATE_READY) {
1124 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not 'READY'", client->current_state);
1125 return STT_ERROR_INVALID_STATE;
1131 ret = stt_dbus_request_finalize(client->uid);
1134 if (STT_ERROR_TIMED_OUT != ret) {
1135 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request finalize : %s", __stt_get_error_code(ret));
1138 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1141 if (STT_RETRY_COUNT == count) {
1142 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1150 client->internal_state = STT_INTERNAL_STATE_NONE;
1152 client->before_state = client->current_state;
1153 client->current_state = STT_STATE_CREATED;
1155 if (NULL != client->state_changed_cb) {
1156 stt_client_use_callback(client);
1157 client->state_changed_cb(client->stt, client->before_state,
1158 client->current_state, client->state_changed_user_data);
1159 stt_client_not_use_callback(client);
1161 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null");
1164 if (g_connect_timer) {
1165 ecore_timer_del(g_connect_timer);
1166 g_connect_timer = NULL;
1169 SLOG(LOG_INFO, TAG_STTC, "=====");
1170 SLOG(LOG_DEBUG, TAG_STTC, " ");
1172 return STT_ERROR_NONE;
1175 bool __stt_config_supported_language_cb(const char* engine_id, const char* language, void* user_data)
1177 stt_h stt = (stt_h)user_data;
1179 stt_client_s* client = stt_client_get(stt);
1180 if (NULL == client) {
1181 SLOG(LOG_ERROR, TAG_STTC, "[WARNING] A handle is not valid"); //LCOV_EXCL_LINE
1185 SLOG(LOG_INFO, TAG_STTC, "===== supported language callback");
1187 /* call callback function */
1188 if (NULL != client->supported_lang_cb) {
1189 return client->supported_lang_cb(stt, language, client->supported_lang_user_data);
1191 SLOG(LOG_WARN, TAG_STTC, "No registered callback function of supported languages"); //LCOV_EXCL_LINE
1197 int stt_foreach_supported_languages(stt_h stt, stt_supported_language_cb callback, void* user_data)
1199 stt_client_s* client = NULL;
1200 if (0 != __stt_get_feature_enabled()) {
1201 return STT_ERROR_NOT_SUPPORTED;
1203 if (0 != __stt_check_privilege()) {
1204 return STT_ERROR_PERMISSION_DENIED;
1206 if (0 != __stt_check_handle(stt, &client)) {
1207 return STT_ERROR_INVALID_PARAMETER;
1210 SLOG(LOG_INFO, TAG_STTC, "===== Foreach Supported Language");
1212 if (NULL == callback) {
1213 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1214 return STT_ERROR_INVALID_PARAMETER;
1218 char* current_engine_id = NULL;
1220 if (NULL == client->current_engine_id) {
1221 ret = stt_config_mgr_get_engine(¤t_engine_id);
1222 ret = __stt_convert_config_error_code(ret);
1224 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get default engine id : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1228 current_engine_id = strdup(client->current_engine_id);
1230 if (NULL == current_engine_id) {
1231 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
1232 return STT_ERROR_OUT_OF_MEMORY;
1237 client->supported_lang_cb = callback;
1238 client->supported_lang_user_data = user_data;
1240 ret = stt_config_mgr_get_language_list(current_engine_id, __stt_config_supported_language_cb, client->stt);
1241 ret = __stt_convert_config_error_code(ret);
1243 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get languages : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1246 if (NULL != current_engine_id) {
1247 free(current_engine_id);
1248 current_engine_id = NULL;
1251 client->supported_lang_cb = NULL;
1252 client->supported_lang_user_data = NULL;
1254 SLOG(LOG_INFO, TAG_STTC, "=====");
1255 SLOG(LOG_DEBUG, TAG_STTC, " ");
1260 int stt_get_default_language(stt_h stt, char** language)
1262 stt_client_s* client = NULL;
1263 if (0 != __stt_get_feature_enabled()) {
1264 return STT_ERROR_NOT_SUPPORTED;
1266 if (0 != __stt_check_privilege()) {
1267 return STT_ERROR_PERMISSION_DENIED;
1269 if (0 != __stt_check_handle(stt, &client)) {
1270 return STT_ERROR_INVALID_PARAMETER;
1273 SLOG(LOG_INFO, TAG_STTC, "===== Get Default Language");
1275 if (NULL == language) {
1276 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1277 return STT_ERROR_INVALID_PARAMETER;
1281 ret = stt_config_mgr_get_default_language(language);
1282 ret = __stt_convert_config_error_code(ret);
1284 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get default language : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1286 SLOG(LOG_DEBUG, TAG_STTC, "[SUCCESS] Current language = %s", *language);
1289 SLOG(LOG_INFO, TAG_STTC, "=====");
1290 SLOG(LOG_DEBUG, TAG_STTC, " ");
1295 int stt_get_state(stt_h stt, stt_state_e* state)
1297 stt_client_s* client = NULL;
1298 if (0 != __stt_get_feature_enabled()) {
1299 return STT_ERROR_NOT_SUPPORTED;
1301 if (0 != __stt_check_privilege()) {
1302 return STT_ERROR_PERMISSION_DENIED;
1304 if (0 != __stt_check_handle(stt, &client)) {
1305 return STT_ERROR_INVALID_PARAMETER;
1308 if (NULL == state) {
1309 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1310 return STT_ERROR_INVALID_PARAMETER;
1313 *state = client->current_state;
1315 SLOG(LOG_INFO, TAG_STTC, "===== Get state(%d)", *state);
1318 case STT_STATE_CREATED: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'CREATED'"); break;
1319 case STT_STATE_READY: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Ready'"); break;
1320 case STT_STATE_RECORDING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Recording'"); break;
1321 case STT_STATE_PROCESSING: SLOG(LOG_DEBUG, TAG_STTC, "Current state is 'Processing'"); break;
1322 default: SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid value"); break;
1325 return STT_ERROR_NONE;
1328 int stt_get_error_message(stt_h stt, char** err_msg)
1330 stt_client_s* client = NULL;
1331 if (0 != __stt_get_feature_enabled()) {
1332 return STT_ERROR_NOT_SUPPORTED;
1334 if (0 != __stt_check_privilege()) {
1335 return STT_ERROR_PERMISSION_DENIED;
1337 if (0 != __stt_check_handle(stt, &client)) {
1338 return STT_ERROR_INVALID_PARAMETER;
1341 if (NULL == err_msg) {
1342 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
1343 return STT_ERROR_INVALID_PARAMETER;
1346 if (false == g_err_callback_status) {
1347 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] This callback should be called during an err_callback");
1348 return STT_ERROR_OPERATION_FAILED;
1351 if (NULL != client->err_msg) {
1352 *err_msg = strdup(client->err_msg);
1353 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Error msg (%s)", *err_msg); //LCOV_EXCL_LINE
1355 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Error msg (NULL)"); //LCOV_EXCL_LINE
1358 SLOG(LOG_INFO, TAG_STTC, "====="); //LCOV_EXCL_LINE
1359 SLOG(LOG_DEBUG, TAG_STTC, " "); //LCOV_EXCL_LINE
1361 return STT_ERROR_NONE;
1364 int stt_is_recognition_type_supported(stt_h stt, const char* type, bool* support)
1366 stt_client_s* client = NULL;
1367 if (0 != __stt_get_feature_enabled()) {
1368 return STT_ERROR_NOT_SUPPORTED;
1370 if (0 != __stt_check_privilege()) {
1371 return STT_ERROR_PERMISSION_DENIED;
1373 if (0 != __stt_check_handle(stt, &client)) {
1374 return STT_ERROR_INVALID_PARAMETER;
1377 if (NULL == type || NULL == support) {
1378 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1379 return STT_ERROR_INVALID_PARAMETER;
1383 if (client->current_state != STT_STATE_READY) {
1384 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1385 return STT_ERROR_INVALID_STATE;
1391 ret = stt_dbus_request_is_recognition_type_supported(client->uid, type, support);
1394 if (STT_ERROR_TIMED_OUT != ret) {
1395 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get recognition type supported : %s", __stt_get_error_code(ret));
1398 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1401 if (STT_RETRY_COUNT == count) {
1402 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1408 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] recognition type is %s", *support ? "true " : "false");
1413 return STT_ERROR_NONE;
1416 int stt_set_silence_detection(stt_h stt, stt_option_silence_detection_e type)
1418 stt_client_s* client = NULL;
1419 if (0 != __stt_get_feature_enabled()) {
1420 return STT_ERROR_NOT_SUPPORTED;
1422 if (0 != __stt_check_privilege()) {
1423 return STT_ERROR_PERMISSION_DENIED;
1425 if (0 != __stt_check_handle(stt, &client)) {
1426 return STT_ERROR_INVALID_PARAMETER;
1430 if (client->current_state != STT_STATE_READY) {
1431 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1432 return STT_ERROR_INVALID_STATE;
1435 SLOG(LOG_INFO, TAG_STTC, "===== Set silence detection, supported(%d), type(%d)", client->silence_supported, type);
1437 if (true == client->silence_supported) {
1438 if (type >= STT_OPTION_SILENCE_DETECTION_FALSE && type <= STT_OPTION_SILENCE_DETECTION_AUTO) {
1439 client->silence = type;
1441 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Type is invalid");
1442 return STT_ERROR_INVALID_PARAMETER;
1445 return STT_ERROR_NOT_SUPPORTED_FEATURE;
1448 return STT_ERROR_NONE;
1451 int stt_set_start_sound(stt_h stt, const char* filename)
1453 stt_client_s* client = NULL;
1454 if (0 != __stt_get_feature_enabled()) {
1455 return STT_ERROR_NOT_SUPPORTED;
1457 if (0 != __stt_check_privilege()) {
1458 return STT_ERROR_PERMISSION_DENIED;
1460 if (0 != __stt_check_handle(stt, &client)) {
1461 return STT_ERROR_INVALID_PARAMETER;
1464 SLOG(LOG_INFO, TAG_STTC, "===== STT SET START SOUND");
1466 if (NULL == filename) {
1467 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1468 return STT_ERROR_INVALID_PARAMETER;
1471 if (0 != access(filename, F_OK)) {
1472 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] File does not exist"); //LCOV_EXCL_LINE
1473 return STT_ERROR_INVALID_PARAMETER;
1477 if (client->current_state != STT_STATE_READY) {
1478 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); //LCOV_EXCL_LINE
1479 return STT_ERROR_INVALID_STATE;
1485 ret = stt_dbus_request_set_start_sound(client->uid, filename);
1488 if (STT_ERROR_TIMED_OUT != ret) {
1489 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set start sound : %s", __stt_get_error_code(ret));
1492 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1495 if (STT_RETRY_COUNT == count) {
1496 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1502 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Set start sound : %s", filename);
1507 return STT_ERROR_NONE;
1510 int stt_unset_start_sound(stt_h stt)
1512 stt_client_s* client = NULL;
1513 if (0 != __stt_get_feature_enabled()) {
1514 return STT_ERROR_NOT_SUPPORTED;
1516 if (0 != __stt_check_privilege()) {
1517 return STT_ERROR_PERMISSION_DENIED;
1519 if (0 != __stt_check_handle(stt, &client)) {
1520 return STT_ERROR_INVALID_PARAMETER;
1523 SLOG(LOG_INFO, TAG_STTC, "===== STT UNSET START SOUND");
1526 if (client->current_state != STT_STATE_READY) {
1527 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1528 return STT_ERROR_INVALID_STATE;
1534 ret = stt_dbus_request_unset_start_sound(client->uid);
1537 if (STT_ERROR_TIMED_OUT != ret) {
1538 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to unset start sound : %s", __stt_get_error_code(ret));
1541 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1544 if (STT_RETRY_COUNT == count) {
1545 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1551 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Unset start sound");
1556 return STT_ERROR_NONE;
1559 int stt_set_stop_sound(stt_h stt, const char* filename)
1561 stt_client_s* client = NULL;
1562 if (0 != __stt_get_feature_enabled()) {
1563 return STT_ERROR_NOT_SUPPORTED;
1565 if (0 != __stt_check_privilege()) {
1566 return STT_ERROR_PERMISSION_DENIED;
1568 if (0 != __stt_check_handle(stt, &client)) {
1569 return STT_ERROR_INVALID_PARAMETER;
1572 SLOG(LOG_INFO, TAG_STTC, "===== STT SET STOP SOUND");
1574 if (NULL == filename) {
1575 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1576 return STT_ERROR_INVALID_PARAMETER;
1579 if (0 != access(filename, F_OK)) {
1580 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] File does not exist"); //LCOV_EXCL_LINE
1581 return STT_ERROR_INVALID_PARAMETER;
1585 if (client->current_state != STT_STATE_READY) {
1586 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state); //LCOV_EXCL_LINE
1587 return STT_ERROR_INVALID_STATE;
1593 ret = stt_dbus_request_set_stop_sound(client->uid, filename);
1596 if (STT_ERROR_TIMED_OUT != ret) {
1597 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to set stop sound : %s", __stt_get_error_code(ret));
1600 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1603 if (STT_RETRY_COUNT == count) {
1604 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1610 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Set stop sound : %s", filename);
1615 return STT_ERROR_NONE;
1618 int stt_unset_stop_sound(stt_h stt)
1620 stt_client_s* client = NULL;
1621 if (0 != __stt_get_feature_enabled()) {
1622 return STT_ERROR_NOT_SUPPORTED;
1624 if (0 != __stt_check_privilege()) {
1625 return STT_ERROR_PERMISSION_DENIED;
1627 if (0 != __stt_check_handle(stt, &client)) {
1628 return STT_ERROR_INVALID_PARAMETER;
1631 SLOG(LOG_INFO, TAG_STTC, "===== STT UNSET STOP SOUND");
1634 if (client->current_state != STT_STATE_READY) {
1635 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1636 return STT_ERROR_INVALID_STATE;
1642 ret = stt_dbus_request_unset_stop_sound(client->uid);
1645 if (STT_ERROR_TIMED_OUT != ret) {
1646 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to unset stop sound : %s", __stt_get_error_code(ret));
1649 SLOG(LOG_WARN, TAG_STTC, "[WARNING] retry");
1652 if (STT_RETRY_COUNT == count) {
1653 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to request");
1659 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Unset stop sound");
1664 return STT_ERROR_NONE;
1667 int stt_start(stt_h stt, const char* language, const char* type)
1669 stt_client_s* client = NULL;
1670 if (0 != __stt_get_feature_enabled()) {
1671 return STT_ERROR_NOT_SUPPORTED;
1673 if (0 != __stt_check_privilege()) {
1674 return STT_ERROR_PERMISSION_DENIED;
1676 if (0 != __stt_check_handle(stt, &client)) {
1677 return STT_ERROR_INVALID_PARAMETER;
1680 SLOG(LOG_INFO, TAG_STTC, "===== STT START");
1683 if (client->current_state != STT_STATE_READY) {
1684 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
1685 return STT_ERROR_INVALID_STATE;
1688 if (STT_INTERNAL_STATE_NONE != client->internal_state) {
1689 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state); //LCOV_EXCL_LINE
1690 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
1694 char appid[1024] = {0, };
1695 ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1);
1697 if ((AUL_R_OK != ret) || (0 == strlen(appid))) {
1698 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID"); //LCOV_EXCL_LINE
1700 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Current app id is %s", appid);
1704 if (NULL == language) {
1705 temp = strdup("default");
1707 temp = strdup(language);
1711 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
1712 return STT_ERROR_OUT_OF_MEMORY;
1715 if (true == client->credential_needed && NULL == client->credential) {
1716 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id); //LCOV_EXCL_LINE
1719 return STT_ERROR_PERMISSION_DENIED;
1722 client->internal_state = STT_INTERNAL_STATE_STARTING;
1723 ret = stt_dbus_request_start(client->uid, temp, type, client->silence, appid, client->credential);
1725 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1726 client->internal_state = STT_INTERNAL_STATE_NONE;
1728 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Start is successful but not done");
1734 SLOG(LOG_INFO, TAG_STTC, "=====");
1735 SLOG(LOG_DEBUG, TAG_STTC, " ");
1740 int stt_stop(stt_h stt)
1742 stt_client_s* client = NULL;
1743 if (0 != __stt_get_feature_enabled()) {
1744 return STT_ERROR_NOT_SUPPORTED;
1746 if (0 != __stt_check_privilege()) {
1747 return STT_ERROR_PERMISSION_DENIED;
1749 if (0 != __stt_check_handle(stt, &client)) {
1750 return STT_ERROR_INVALID_PARAMETER;
1753 SLOG(LOG_INFO, TAG_STTC, "===== STT STOP");
1756 if (client->current_state != STT_STATE_RECORDING) {
1757 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Current state(%d) is NOT RECORDING", client->current_state); //LCOV_EXCL_LINE
1758 return STT_ERROR_INVALID_STATE;
1761 if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
1762 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state); //LCOV_EXCL_LINE
1763 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
1764 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
1765 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); //LCOV_EXCL_LINE
1766 return STT_ERROR_IN_PROGRESS_TO_READY;
1767 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
1768 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); //LCOV_EXCL_LINE
1769 return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
1772 client->internal_state = STT_INTERNAL_STATE_STOPPING;
1773 int ret = stt_dbus_request_stop(client->uid);
1775 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to stop : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1776 client->internal_state = STT_INTERNAL_STATE_NONE;
1778 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Stop is successful but not done");
1781 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1782 SLOG(LOG_DEBUG, TAG_STTC, " ");
1788 int stt_cancel(stt_h stt)
1790 stt_client_s* client = NULL;
1791 if (0 != __stt_get_feature_enabled()) {
1792 return STT_ERROR_NOT_SUPPORTED;
1794 if (0 != __stt_check_privilege()) {
1795 return STT_ERROR_PERMISSION_DENIED;
1797 if (0 != __stt_check_handle(stt, &client)) {
1798 return STT_ERROR_INVALID_PARAMETER;
1801 SLOG(LOG_INFO, TAG_STTC, "===== STT CANCEL");
1804 if (STT_STATE_RECORDING != client->current_state && STT_STATE_PROCESSING != client->current_state) {
1805 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid state : Current state(%d) is 'Ready'", client->current_state); //LCOV_EXCL_LINE
1806 return STT_ERROR_INVALID_STATE;
1809 if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
1810 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state); //LCOV_EXCL_LINE
1811 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
1812 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
1813 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state); //LCOV_EXCL_LINE
1814 return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
1815 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
1816 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state); //LCOV_EXCL_LINE
1817 return STT_ERROR_IN_PROGRESS_TO_READY;
1820 client->internal_state = STT_INTERNAL_STATE_CANCELING;
1821 int ret = stt_dbus_request_cancel(client->uid);
1823 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to cancel : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1824 client->internal_state = STT_INTERNAL_STATE_NONE;
1826 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Cancel is successful but not done");
1829 SLOG(LOG_DEBUG, TAG_STTC, "=====");
1830 SLOG(LOG_DEBUG, TAG_STTC, " ");
1835 int __stt_cb_set_volume(int uid, float volume)
1837 stt_client_s* client = NULL;
1839 client = stt_client_get_by_uid(uid);
1840 if (NULL == client) {
1842 SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid");
1843 return STT_ERROR_INVALID_PARAMETER;
1847 if (STT_STATE_RECORDING != client->current_state) {
1849 SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state);
1850 return STT_ERROR_INVALID_STATE;
1854 g_volume_db = volume;
1855 SLOG(LOG_INFO, TAG_STTC, "Set volume (%f)", g_volume_db);
1860 int stt_get_recording_volume(stt_h stt, float* volume)
1862 stt_client_s* client = NULL;
1863 if (0 != __stt_get_feature_enabled()) {
1864 return STT_ERROR_NOT_SUPPORTED;
1866 if (0 != __stt_check_privilege()) {
1867 return STT_ERROR_PERMISSION_DENIED;
1869 if (0 != __stt_check_handle(stt, &client)) {
1870 return STT_ERROR_INVALID_PARAMETER;
1873 if (NULL == volume) {
1874 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1875 return STT_ERROR_INVALID_PARAMETER;
1878 if (STT_STATE_RECORDING != client->current_state) {
1879 SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Invalid state : NO 'Recording' state, cur(%d)", client->current_state); //LCOV_EXCL_LINE
1880 return STT_ERROR_INVALID_STATE;
1883 *volume = g_volume_db;
1885 SLOG(LOG_INFO, TAG_STTC, "Get recording volume (%f)", *volume);
1887 return STT_ERROR_NONE;
1891 bool __stt_result_time_cb(int index, int event, const char* text, long start_time, long end_time, void* user_data)
1893 stt_client_s* client = (stt_client_s*)user_data;
1896 if (NULL == client) {
1897 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid");
1901 if (NULL != client->result_time_cb) {
1902 SLOG(LOG_INFO, TAG_STTC, "(%d) event(%d) text(%s) start(%ld) end(%ld)",
1903 index, event, text, start_time, end_time);
1904 client->result_time_cb(client->stt, index, (stt_result_time_event_e)event,
1905 text, start_time, end_time, client->result_time_user_data);
1907 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Callback is NULL");
1915 int stt_foreach_detailed_result(stt_h stt, stt_result_time_cb callback, void* user_data)
1917 stt_client_s* client = NULL;
1918 if (0 != __stt_get_feature_enabled()) {
1919 return STT_ERROR_NOT_SUPPORTED;
1921 if (0 != __stt_check_privilege()) {
1922 return STT_ERROR_PERMISSION_DENIED;
1924 if (0 != __stt_check_handle(stt, &client)) {
1925 return STT_ERROR_INVALID_PARAMETER;
1928 SLOG(LOG_INFO, TAG_STTC, "===== STT FOREACH DETAILED RESULT");
1930 if (NULL == callback) {
1931 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL"); //LCOV_EXCL_LINE
1932 return STT_ERROR_INVALID_PARAMETER;
1935 client->result_time_cb = callback;
1936 client->result_time_user_data = user_data;
1939 ret = stt_config_mgr_foreach_time_info(__stt_result_time_cb, client);
1940 ret = __stt_convert_config_error_code(ret);
1942 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to foreach time info : %s", __stt_get_error_code(ret)); //LCOV_EXCL_LINE
1945 client->result_time_cb = NULL;
1946 client->result_time_user_data = NULL;
1948 SLOG(LOG_INFO, TAG_STTC, "=====");
1949 SLOG(LOG_DEBUG, TAG_STTC, " ");
1954 static void __stt_notify_error(void *data)
1956 stt_client_s* client = (stt_client_s*)data;
1958 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error from sttd");
1961 if (NULL == client) {
1962 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); //LCOV_EXCL_LINE
1966 if (NULL == stt_client_get_by_uid(client->uid))
1969 if (NULL != client->error_cb) {
1970 stt_client_use_callback(client);
1971 g_err_callback_status = true;
1972 client->error_cb(client->stt, client->reason, client->error_user_data);
1973 g_err_callback_status = false;
1974 stt_client_not_use_callback(client);
1975 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is called : reason [%d]", client->reason);
1977 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null"); //LCOV_EXCL_LINE
1983 int __stt_cb_error(int uid, int reason, char* err_msg)
1987 GList* client_list = NULL;
1988 client_list = stt_client_get_client_list();
1991 stt_client_s *data = NULL;
1993 if (g_list_length(client_list) > 0) {
1994 /* Get a first item */
1995 iter = g_list_first(client_list);
1997 while (NULL != iter) {
2000 data->reason = reason;
2001 data->internal_state = STT_INTERNAL_STATE_NONE;
2002 if (NULL != data->err_msg) {
2003 free(data->err_msg);
2004 data->err_msg = NULL;
2006 if (NULL != err_msg)
2007 data->err_msg = strdup(err_msg);
2009 SLOG(LOG_INFO, TAG_STTC, "internal state is initialized to 0");
2011 if (NULL != data->error_cb) {
2012 ecore_main_loop_thread_safe_call_async(__stt_notify_error, data);
2014 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
2017 if (STT_ERROR_SERVICE_RESET == reason) {
2018 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Service reset");
2020 data->current_state = STT_STATE_CREATED;
2021 if (0 != stt_prepare(data->stt)) {
2022 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare");
2027 iter = g_list_next(iter);
2032 stt_client_s* client = stt_client_get_by_uid(uid);
2033 if (NULL == client) {
2034 SLOG(LOG_ERROR, TAG_STTC, "Handle not found"); //LCOV_EXCL_LINE
2038 client->reason = reason;
2039 client->internal_state = STT_INTERNAL_STATE_NONE;
2040 if (NULL != client->err_msg) {
2041 free(client->err_msg);
2042 client->err_msg = NULL;
2044 if (NULL != err_msg)
2045 client->err_msg = strdup(err_msg);
2047 SLOG(LOG_INFO, TAG_STTC, "internal state is initialized to 0");
2049 if (NULL != client->error_cb) {
2050 ecore_main_loop_thread_safe_call_async(__stt_notify_error, client);
2052 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Error callback is null");
2055 if (STT_ERROR_SERVICE_RESET == reason) {
2056 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Service reset"); //LCOV_EXCL_LINE
2058 client->current_state = STT_STATE_CREATED;
2059 if (0 != stt_prepare(client->stt)) {
2060 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to prepare"); //LCOV_EXCL_LINE
2068 static void __stt_notify_state_changed(void *data)
2070 stt_client_s* client = (stt_client_s*)data;
2073 if (NULL == client) {
2074 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); //LCOV_EXCL_LINE
2078 if (NULL == stt_client_get_by_uid(client->uid)) {
2082 if (STT_INTERNAL_STATE_STARTING == client->internal_state && STT_STATE_RECORDING == client->current_state) {
2083 client->internal_state = STT_INTERNAL_STATE_NONE;
2084 SLOG(LOG_INFO, TAG_STTC, "Internal state change to NONE");
2085 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state && STT_STATE_PROCESSING == client->current_state) {
2086 client->internal_state = STT_INTERNAL_STATE_NONE;
2087 SLOG(LOG_INFO, TAG_STTC, "Internal state change to NONE");
2088 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state && STT_STATE_READY == client->current_state) {
2089 client->internal_state = STT_INTERNAL_STATE_NONE;
2090 SLOG(LOG_INFO, TAG_STTC, "Internal state change to NONE");
2093 if (NULL != client->state_changed_cb) {
2094 stt_client_use_callback(client);
2095 client->state_changed_cb(client->stt, client->before_state,
2096 client->current_state, client->state_changed_user_data);
2097 stt_client_not_use_callback(client);
2098 SLOG(LOG_INFO, TAG_STTC, "State changed callback is called, State(%d)", client->current_state);
2100 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null, State(%d)", client->current_state); //LCOV_EXCL_LINE
2106 static Eina_Bool __stt_notify_result(void *data)
2108 stt_client_s* client = (stt_client_s*)data;
2111 if (NULL == client) {
2112 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify error : A handle is not valid"); //LCOV_EXCL_LINE
2116 if (NULL == stt_client_get_by_uid(client->uid)) {
2120 if (NULL != client->recognition_result_cb) {
2121 stt_client_use_callback(client);
2122 client->recognition_result_cb(client->stt, client->event, (const char**)client->data_list, client->data_count,
2123 client->msg, client->recognition_result_user_data);
2124 stt_client_not_use_callback(client);
2125 SLOG(LOG_INFO, TAG_STTC, "client recognition result callback called");
2127 SLOG(LOG_WARN, TAG_STTC, "[WARNING] User recognition result callback is NULL");
2130 if (NULL != client->msg) {
2135 if (NULL != client->data_list) {
2137 temp = client->data_list;
2140 for (i = 0; i < client->data_count; i++) {
2141 if (NULL != temp[i]) {
2145 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result data is error"); //LCOV_EXCL_LINE
2148 free(client->data_list);
2149 client->data_list = NULL;
2152 client->data_count = 0;
2154 stt_config_mgr_remove_time_info_file();
2156 if (STT_RESULT_EVENT_FINAL_RESULT == client->event || STT_RESULT_EVENT_ERROR == client->event) {
2157 client->before_state = client->current_state;
2158 client->current_state = STT_STATE_READY;
2160 if (NULL != client->state_changed_cb) {
2161 ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client);
2163 SLOG(LOG_WARN, TAG_STTC, "[WARNING] State changed callback is null"); //LCOV_EXCL_LINE
2170 int __stt_cb_result(int uid, int event, char** data, int data_count, const char* msg)
2172 stt_client_s* client = NULL;
2174 client = stt_client_get_by_uid(uid);
2175 if (NULL == client) {
2176 SLOG(LOG_ERROR, TAG_STTC, "Handle is NOT valid"); //LCOV_EXCL_LINE
2177 return STT_ERROR_INVALID_PARAMETER;
2181 SECURE_SLOG(LOG_INFO, TAG_STTC, "Recognition Result Message = %s", msg);
2184 for (i = 0; i < data_count; i++) {
2185 if (NULL != data[i])
2186 SECURE_SLOG(LOG_INFO, TAG_STTC, "Recognition Result[%d] = %s", i, data[i]);
2189 if (NULL != client->recognition_result_cb) {
2190 client->event = event;
2192 client->msg = strdup(msg);
2195 client->data_count = data_count;
2197 if (data_count > 0) {
2199 temp = (char**)calloc(data_count, sizeof(char*));
2201 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); //LCOV_EXCL_LINE
2202 return STT_ERROR_OUT_OF_MEMORY;
2205 for (i = 0; i < data_count; i++) {
2206 if (NULL != data[i])
2207 temp[i] = strdup(data[i]);
2209 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Result data is error"); //LCOV_EXCL_LINE
2212 client->data_list = temp;
2215 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] User result callback is null");
2218 __stt_notify_result(client);
2220 return STT_ERROR_NONE;
2223 int __stt_cb_set_state(int uid, int state)
2225 stt_client_s* client = stt_client_get_by_uid(uid);
2226 if (NULL == client) {
2227 SLOG(LOG_ERROR, TAG_STTC, "Handle not found"); //LCOV_EXCL_LINE
2231 stt_state_e state_from_daemon = (stt_state_e)state;
2233 if (client->current_state == state_from_daemon) {
2234 SLOG(LOG_DEBUG, TAG_STTC, "Current state has already been %d", client->current_state);
2238 client->before_state = client->current_state;
2239 client->current_state = state_from_daemon;
2241 ecore_main_loop_thread_safe_call_async(__stt_notify_state_changed, client);
2245 static void __stt_notify_speech_status(void *data)
2247 stt_client_s* client = (stt_client_s*)data;
2250 if (NULL == client) {
2251 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to notify speech status : A handle is not valid"); //LCOV_EXCL_LINE
2255 if (NULL == stt_client_get_by_uid(client->uid)) {
2259 if (NULL != client->speech_status_cb) {
2260 stt_client_use_callback(client);
2261 client->speech_status_cb(client->stt, client->speech_status, client->speech_status_user_data);
2262 stt_client_not_use_callback(client);
2263 SLOG(LOG_INFO, TAG_STTC, "Speech status callback is called"); //LCOV_EXCL_LINE
2265 SLOG(LOG_WARN, TAG_STTC, "[WARNING] Speech status callback is null"); //LCOV_EXCL_LINE
2271 int __stt_cb_speech_status(int uid, int status)
2273 stt_client_s* client = stt_client_get_by_uid(uid);
2274 if (NULL == client) {
2275 SLOG(LOG_ERROR, TAG_STTC, "Handle not found"); //LCOV_EXCL_LINE
2279 client->speech_status = status;
2281 ecore_main_loop_thread_safe_call_async(__stt_notify_speech_status, client);
2285 int stt_set_recognition_result_cb(stt_h stt, stt_recognition_result_cb callback, void* user_data)
2287 stt_client_s* client = NULL;
2288 if (0 != __stt_get_feature_enabled()) {
2289 return STT_ERROR_NOT_SUPPORTED;
2291 if (0 != __stt_check_privilege()) {
2292 return STT_ERROR_PERMISSION_DENIED;
2294 if (0 != __stt_check_handle(stt, &client)) {
2295 return STT_ERROR_INVALID_PARAMETER;
2298 if (callback == NULL)
2299 return STT_ERROR_INVALID_PARAMETER;
2301 if (STT_STATE_CREATED != client->current_state) {
2302 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2303 return STT_ERROR_INVALID_STATE;
2306 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set recognition result cb");
2308 client->recognition_result_cb = callback;
2309 client->recognition_result_user_data = user_data;
2314 int stt_unset_recognition_result_cb(stt_h stt)
2316 stt_client_s* client = NULL;
2317 if (0 != __stt_get_feature_enabled()) {
2318 return STT_ERROR_NOT_SUPPORTED;
2320 if (0 != __stt_check_privilege()) {
2321 return STT_ERROR_PERMISSION_DENIED;
2323 if (0 != __stt_check_handle(stt, &client)) {
2324 return STT_ERROR_INVALID_PARAMETER;
2327 if (STT_STATE_CREATED != client->current_state) {
2328 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2329 return STT_ERROR_INVALID_STATE;
2332 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset recognition result cb");
2334 client->recognition_result_cb = NULL;
2335 client->recognition_result_user_data = NULL;
2340 int stt_set_state_changed_cb(stt_h stt, stt_state_changed_cb callback, void* user_data)
2342 stt_client_s* client = NULL;
2343 if (0 != __stt_get_feature_enabled()) {
2344 return STT_ERROR_NOT_SUPPORTED;
2346 if (0 != __stt_check_privilege()) {
2347 return STT_ERROR_PERMISSION_DENIED;
2349 if (0 != __stt_check_handle(stt, &client)) {
2350 return STT_ERROR_INVALID_PARAMETER;
2353 if (NULL == callback)
2354 return STT_ERROR_INVALID_PARAMETER;
2356 if (STT_STATE_CREATED != client->current_state) {
2357 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2358 return STT_ERROR_INVALID_STATE;
2361 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set state changed cb");
2363 client->state_changed_cb = callback;
2364 client->state_changed_user_data = user_data;
2369 int stt_unset_state_changed_cb(stt_h stt)
2371 stt_client_s* client = NULL;
2372 if (0 != __stt_get_feature_enabled()) {
2373 return STT_ERROR_NOT_SUPPORTED;
2375 if (0 != __stt_check_privilege()) {
2376 return STT_ERROR_PERMISSION_DENIED;
2378 if (0 != __stt_check_handle(stt, &client)) {
2379 return STT_ERROR_INVALID_PARAMETER;
2382 if (STT_STATE_CREATED != client->current_state) {
2383 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2384 return STT_ERROR_INVALID_STATE;
2387 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset state changed cb");
2389 client->state_changed_cb = NULL;
2390 client->state_changed_user_data = NULL;
2395 int stt_set_error_cb(stt_h stt, stt_error_cb callback, void* user_data)
2397 stt_client_s* client = NULL;
2398 if (0 != __stt_get_feature_enabled()) {
2399 return STT_ERROR_NOT_SUPPORTED;
2401 if (0 != __stt_check_privilege()) {
2402 return STT_ERROR_PERMISSION_DENIED;
2404 if (0 != __stt_check_handle(stt, &client)) {
2405 return STT_ERROR_INVALID_PARAMETER;
2408 if (NULL == callback)
2409 return STT_ERROR_INVALID_PARAMETER;
2411 if (STT_STATE_CREATED != client->current_state) {
2412 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2413 return STT_ERROR_INVALID_STATE;
2416 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set error cb");
2418 client->error_cb = callback;
2419 client->error_user_data = user_data;
2424 int stt_unset_error_cb(stt_h stt)
2426 stt_client_s* client = NULL;
2427 if (0 != __stt_get_feature_enabled()) {
2428 return STT_ERROR_NOT_SUPPORTED;
2430 if (0 != __stt_check_privilege()) {
2431 return STT_ERROR_PERMISSION_DENIED;
2433 if (0 != __stt_check_handle(stt, &client)) {
2434 return STT_ERROR_INVALID_PARAMETER;
2437 if (STT_STATE_CREATED != client->current_state) {
2438 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2439 return STT_ERROR_INVALID_STATE;
2442 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset error cb");
2444 client->error_cb = NULL;
2445 client->error_user_data = NULL;
2450 int stt_set_default_language_changed_cb(stt_h stt, stt_default_language_changed_cb callback, void* user_data)
2452 stt_client_s* client = NULL;
2453 if (0 != __stt_get_feature_enabled()) {
2454 return STT_ERROR_NOT_SUPPORTED;
2456 if (0 != __stt_check_privilege()) {
2457 return STT_ERROR_PERMISSION_DENIED;
2459 if (0 != __stt_check_handle(stt, &client)) {
2460 return STT_ERROR_INVALID_PARAMETER;
2463 if (NULL == callback)
2464 return STT_ERROR_INVALID_PARAMETER;
2466 if (STT_STATE_CREATED != client->current_state) {
2467 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2468 return STT_ERROR_INVALID_STATE;
2471 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set default language changed cb");
2473 client->default_lang_changed_cb = callback;
2474 client->default_lang_changed_user_data = user_data;
2479 int stt_unset_default_language_changed_cb(stt_h stt)
2481 stt_client_s* client = NULL;
2482 if (0 != __stt_get_feature_enabled()) {
2483 return STT_ERROR_NOT_SUPPORTED;
2485 if (0 != __stt_check_privilege()) {
2486 return STT_ERROR_PERMISSION_DENIED;
2488 if (0 != __stt_check_handle(stt, &client)) {
2489 return STT_ERROR_INVALID_PARAMETER;
2492 if (STT_STATE_CREATED != client->current_state) {
2493 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2494 return STT_ERROR_INVALID_STATE;
2497 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset default language changed cb");
2499 client->default_lang_changed_cb = NULL;
2500 client->default_lang_changed_user_data = NULL;
2505 int stt_set_engine_changed_cb(stt_h stt, stt_engine_changed_cb callback, void* user_data)
2507 stt_client_s* client = NULL;
2508 if (0 != __stt_get_feature_enabled()) {
2509 return STT_ERROR_NOT_SUPPORTED;
2511 if (0 != __stt_check_privilege()) {
2512 return STT_ERROR_PERMISSION_DENIED;
2514 if (0 != __stt_check_handle(stt, &client)) {
2515 return STT_ERROR_INVALID_PARAMETER;
2518 if (NULL == callback)
2519 return STT_ERROR_INVALID_PARAMETER;
2521 if (STT_STATE_CREATED != client->current_state) {
2522 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2523 return STT_ERROR_INVALID_STATE;
2526 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set engine changed cb");
2528 client->engine_changed_cb = callback;
2529 client->engine_changed_user_data = user_data;
2534 int stt_unset_engine_changed_cb(stt_h stt)
2536 stt_client_s* client = NULL;
2537 if (0 != __stt_get_feature_enabled()) {
2538 return STT_ERROR_NOT_SUPPORTED;
2540 if (0 != __stt_check_privilege()) {
2541 return STT_ERROR_PERMISSION_DENIED;
2543 if (0 != __stt_check_handle(stt, &client)) {
2544 return STT_ERROR_INVALID_PARAMETER;
2547 if (STT_STATE_CREATED != client->current_state) {
2548 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2549 return STT_ERROR_INVALID_STATE;
2552 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset engine changed cb");
2554 client->engine_changed_cb = NULL;
2555 client->engine_changed_user_data = NULL;
2561 int stt_set_speech_status_cb(stt_h stt, stt_speech_status_cb callback, void* user_data)
2563 stt_client_s* client = NULL;
2564 if (0 != __stt_get_feature_enabled()) {
2565 return STT_ERROR_NOT_SUPPORTED;
2567 if (0 != __stt_check_privilege()) {
2568 return STT_ERROR_PERMISSION_DENIED;
2570 if (0 != __stt_check_handle(stt, &client)) {
2571 return STT_ERROR_INVALID_PARAMETER;
2574 if (NULL == callback)
2575 return STT_ERROR_INVALID_PARAMETER;
2577 if (STT_STATE_CREATED != client->current_state) {
2578 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2579 return STT_ERROR_INVALID_STATE;
2582 SLOG(LOG_INFO, TAG_STTC, "[INFO] Set speech status cb");
2584 client->speech_status_cb = callback;
2585 client->speech_status_user_data = user_data;
2590 int stt_unset_speech_status_cb(stt_h stt)
2592 stt_client_s* client = NULL;
2593 if (0 != __stt_get_feature_enabled()) {
2594 return STT_ERROR_NOT_SUPPORTED;
2596 if (0 != __stt_check_privilege()) {
2597 return STT_ERROR_PERMISSION_DENIED;
2599 if (0 != __stt_check_handle(stt, &client)) {
2600 return STT_ERROR_INVALID_PARAMETER;
2603 if (STT_STATE_CREATED != client->current_state) {
2604 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Current state(%d) is not 'Created'", client->current_state);
2605 return STT_ERROR_INVALID_STATE;
2608 SLOG(LOG_INFO, TAG_STTC, "[INFO] Unset speech status cb");
2610 client->speech_status_cb = NULL;
2611 client->speech_status_user_data = NULL;
2616 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)
2618 stt_client_s* client = NULL;
2619 if (0 != __stt_get_feature_enabled()) {
2620 return STT_ERROR_NOT_SUPPORTED;
2622 if (0 != __stt_check_privilege()) {
2623 return STT_ERROR_PERMISSION_DENIED;
2625 if (0 != __stt_check_handle(stt, &client)) {
2626 return STT_ERROR_INVALID_PARAMETER;
2628 if (NULL == filepath) {
2629 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Input parameter is NULL");
2630 return STT_ERROR_INVALID_PARAMETER;
2633 SLOG(LOG_INFO, TAG_STTC, "===== STT START FILE");
2636 if (client->current_state != STT_STATE_READY) {
2637 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY", client->current_state);
2638 return STT_ERROR_INVALID_STATE;
2641 if (STT_INTERNAL_STATE_NONE != client->internal_state) {
2642 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is NOT none : %d", client->internal_state);
2643 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
2647 char appid[1024] = {0, };
2648 ret = aul_app_get_appid_bypid(getpid(), appid, sizeof(appid) - 1);
2650 if ((AUL_R_OK != ret) || (0 == strlen(appid))) {
2651 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to get application ID");
2653 SLOG(LOG_INFO, TAG_STTC, "[DEBUG] Current app id is %s", appid);
2657 if (NULL == language) {
2658 temp = strdup("default");
2660 temp = strdup(language);
2664 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory");
2665 return STT_ERROR_OUT_OF_MEMORY;
2668 if (true == client->credential_needed && NULL == client->credential) {
2669 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Do not have app credential for this engine(%s)", client->current_engine_id);
2672 return STT_ERROR_PERMISSION_DENIED;
2675 client->internal_state = STT_INTERNAL_STATE_STARTING;
2676 ret = stt_dbus_request_start_file(client->uid, temp, type, client->silence, appid, client->credential, filepath, audio_type, sample_rate);
2678 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start file : %s", __stt_get_error_code(ret));
2679 client->internal_state = STT_INTERNAL_STATE_NONE;
2681 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Start is successful but not done");
2687 SLOG(LOG_DEBUG, TAG_STTC, "=====");
2688 SLOG(LOG_DEBUG, TAG_STTC, " ");
2693 int stt_cancel_file(stt_h stt)
2695 stt_client_s* client = NULL;
2696 if (0 != __stt_get_feature_enabled()) {
2697 return STT_ERROR_NOT_SUPPORTED;
2699 if (0 != __stt_check_privilege()) {
2700 return STT_ERROR_PERMISSION_DENIED;
2702 if (0 != __stt_check_handle(stt, &client)) {
2703 return STT_ERROR_INVALID_PARAMETER;
2706 SLOG(LOG_INFO, TAG_STTC, "===== STT CANCEL FILE");
2709 if (STT_STATE_RECORDING != client->current_state && STT_STATE_PROCESSING != client->current_state) {
2710 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid state : Current state(%d) is 'Ready'", client->current_state);
2711 return STT_ERROR_INVALID_STATE;
2714 if (STT_INTERNAL_STATE_STARTING == client->internal_state) {
2715 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STARTING : %d", client->internal_state);
2716 return STT_ERROR_IN_PROGRESS_TO_RECORDING;
2717 } else if (STT_INTERNAL_STATE_STOPPING == client->internal_state) {
2718 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is STOPPING : %d", client->internal_state);
2719 return STT_ERROR_IN_PROGRESS_TO_PROCESSING;
2720 } else if (STT_INTERNAL_STATE_CANCELING == client->internal_state) {
2721 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State : Internal state is CANCELING : %d", client->internal_state);
2722 return STT_ERROR_IN_PROGRESS_TO_READY;
2725 client->internal_state = STT_INTERNAL_STATE_CANCELING;
2726 int ret = stt_dbus_request_cancel_file(client->uid);
2728 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to cancel file : %s", __stt_get_error_code(ret));
2729 client->internal_state = STT_INTERNAL_STATE_NONE;
2731 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Cancel file is successful but not done");
2734 SLOG(LOG_DEBUG, TAG_STTC, "=====");
2735 SLOG(LOG_DEBUG, TAG_STTC, " ");
2740 int __stt_change_system_volume(stt_system_volume_event_e volume_event)
2742 int stream_type = -1;
2743 if (STT_SYSTEM_VOLUME_EVENT_CHANGE_FOR_FARFIELD == volume_event) {
2744 stream_type = SOUND_STREAM_TYPE_VOICE_RECOGNITION;
2745 } else if (STT_SYSTEM_VOLUME_EVENT_CHANGE_FOR_NEARFIELD == volume_event) {
2746 stream_type = SOUND_STREAM_TYPE_VOICE_RECOGNITION_SERVICE;
2748 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] volume type is invalid, type(%d)", volume_event);
2749 return STT_ERROR_INVALID_PARAMETER;
2752 SLOG(LOG_INFO, TAG_STTC, "[INFO] Change system volume, volume_type(%d)", volume_event);
2754 int ret = STT_ERROR_NONE;
2755 if (g_stream_for_volume_h) {
2756 SLOG(LOG_INFO, TAG_STTC, "[INFO] Stream is already created, destroy stream)");
2757 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
2759 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
2761 g_stream_for_volume_h = NULL;
2764 ret = sound_manager_create_stream_information_internal(stream_type, NULL, NULL, &g_stream_for_volume_h);
2766 SLOG(LOG_DEBUG, TAG_STTC, "[ERROR] Fail to create stream information, ret(%d)", ret);
2767 return STT_ERROR_OPERATION_FAILED;
2770 if (g_virtual_sound_stream_h) {
2771 SLOG(LOG_INFO, TAG_STTC, "[INFO] Virtual stream is already created, destroy virtual stream)");
2772 ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h);
2774 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy virtual stream, ret(%d)", ret);
2775 return STT_ERROR_OPERATION_FAILED;
2777 g_virtual_sound_stream_h = NULL;
2780 ret = sound_manager_create_virtual_stream(g_stream_for_volume_h, &g_virtual_sound_stream_h);
2782 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to create virtual stream, ret(%d)", ret);
2783 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
2785 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
2787 g_stream_for_volume_h = NULL;
2788 return STT_ERROR_OPERATION_FAILED;
2791 ret = sound_manager_start_virtual_stream(g_virtual_sound_stream_h);
2793 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to start virtual stream, ret(%d)", ret);
2794 ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h);
2796 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy virtual stream, ret(%d)", ret);
2798 g_virtual_sound_stream_h = NULL;
2800 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
2802 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
2804 g_stream_for_volume_h = NULL;
2806 return STT_ERROR_OPERATION_FAILED;
2809 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Change system volume");
2813 int __stt_recover_system_volume()
2815 SLOG(LOG_INFO, TAG_STTC, "[INFO] Recover system volume");
2817 int ret = STT_ERROR_NONE;
2819 if (g_virtual_sound_stream_h) {
2820 ret = sound_manager_stop_virtual_stream(g_virtual_sound_stream_h);
2822 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to stop virtual stream, ret(%d)", ret);
2823 return STT_ERROR_OPERATION_FAILED;
2825 ret = sound_manager_destroy_virtual_stream(g_virtual_sound_stream_h);
2827 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy virtual stream, ret(%d)", ret);
2828 return STT_ERROR_OPERATION_FAILED;
2830 g_virtual_sound_stream_h = NULL;
2833 if (g_stream_for_volume_h) {
2834 ret = sound_manager_destroy_stream_information(g_stream_for_volume_h);
2836 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to destroy stream information, ret(%d)", ret);
2837 return STT_ERROR_OPERATION_FAILED;
2839 g_stream_for_volume_h = NULL;
2842 SLOG(LOG_INFO, TAG_STTC, "[SUCCESS] Recover system volume");
2846 int stt_change_system_volume(stt_h stt, stt_system_volume_event_e volume_event)
2848 SLOG(LOG_DEBUG, TAG_STTC, "[STT] Change system volume, volume_event(%d)", volume_event);
2850 stt_client_s* client = NULL;
2851 if (0 != __stt_get_feature_enabled()) {
2852 return STT_ERROR_NOT_SUPPORTED;
2854 if (0 != __stt_check_privilege()) {
2855 return STT_ERROR_PERMISSION_DENIED;
2857 if (0 != __stt_check_handle(stt, &client)) {
2858 return STT_ERROR_INVALID_PARAMETER;
2862 if (client->current_state != STT_STATE_READY && client->current_state != STT_STATE_CREATED) {
2863 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY nor CREATED", client->current_state);
2864 return STT_ERROR_INVALID_STATE;
2867 /* change system volume */
2868 int ret = __stt_change_system_volume(volume_event);
2870 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to change volume");
2872 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Success to change volume");
2877 int stt_recover_system_volume(stt_h stt)
2879 SLOG(LOG_DEBUG, TAG_STTC, "[STT] recover system volume");
2881 stt_client_s* client = NULL;
2882 if (0 != __stt_get_feature_enabled()) {
2883 return STT_ERROR_NOT_SUPPORTED;
2885 if (0 != __stt_check_privilege()) {
2886 return STT_ERROR_PERMISSION_DENIED;
2888 if (0 != __stt_check_handle(stt, &client)) {
2889 return STT_ERROR_INVALID_PARAMETER;
2893 if (client->current_state != STT_STATE_READY && client->current_state != STT_STATE_CREATED) {
2894 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Invalid State: Current state(%d) is not READY nor CREATED", client->current_state);
2895 return STT_ERROR_INVALID_STATE;
2898 /* recover volume */
2899 int ret = __stt_recover_system_volume();
2901 SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to recover volume");
2903 SLOG(LOG_DEBUG, TAG_STTC, "[DEBUG] Success to recover volume");