2 * Copyright 2020 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <service_app.h>
31 #include "service_main.h"
32 #include "service_plugin.h"
33 #include "service_ipc_dbus.h"
35 /* Sound buf save for test */
40 #ifdef PRINT_DETAILED_TIMEINFO
41 static long long int get_time_interval_count(
42 std::chrono::time_point<std::chrono::steady_clock> time_point_1,
43 std::chrono::time_point<std::chrono::steady_clock> time_point_2) {
44 auto interval = time_point_2 - time_point_1;
45 return static_cast<long long int>(
46 std::chrono::duration_cast<std::chrono::milliseconds>(interval).count());
50 static int g_last_wakeup_event_id = 0;
54 char* wakeup_word{nullptr};
55 char* wakeup_appid{nullptr};
56 unsigned char* extra_data{nullptr};
57 size_t extra_data_length{0};
58 char* extra_data_desc{nullptr};
59 CServicePlugin* plugin{nullptr};
62 bool CServicePlugin::is_ui_panel_enabled()
64 /* By default we assume the ui panel is always enabled unless explicitly turned off */
66 if (mPluginSettings) {
67 ret = mPluginSettings->ui_panel_enabled;
69 MAS_LOGD("UI Panel Enabled : %d", ret);
73 #if 0 /* + TEST_CODE */
74 Eina_Bool __send_asr_result(void *data)
78 if (!strcmp((char*)data, "Today's")) {
79 masc_ui_dbus_send_asr_result(-1, 1, "Today's");
81 if (!strcmp((char*)data, "weather.")) {
82 masc_ui_dbus_send_asr_result(-1, 0, "Today's weather.");
89 Eina_Bool __send_result(void *data)
93 int ret = masc_ui_dbus_send_result(-1, (const char*)data, (const char*)data, "test");
95 MAS_LOGE("[ERROR] Fail to stop recording(%d)", ret);
102 #endif /* -TEST_CODE */
104 static void process_wakeup_event_by_appid_timer(void* data)
106 if (nullptr == data) return;
108 AsyncParam* param = static_cast<AsyncParam*>(data);
110 char* wakeup_word = param->wakeup_word;
111 char* wakeup_appid = param->wakeup_appid;
112 unsigned char *extra_data = param->extra_data;
113 size_t extra_data_length = param->extra_data_length;
114 char* extra_data_desc = param->extra_data_desc;
115 MAS_LOGI("[ENTER] appid(%s), word(%s), id(%d), g_last_wakeup_event_id(%d)",
116 wakeup_appid, wakeup_word, param->id, g_last_wakeup_event_id);
119 if (param->wakeup_word) free(param->wakeup_word);
120 if (param->extra_data) free(param->extra_data);
121 if (param->extra_data_desc) free(param->extra_data_desc);
126 if (param->id < g_last_wakeup_event_id) {
127 if (param->wakeup_word) free(param->wakeup_word);
128 if (param->wakeup_appid) free(param->wakeup_appid);
129 if (param->extra_data) free(param->extra_data);
130 if (param->extra_data_desc) free(param->extra_data_desc);
137 CServicePlugin* plugin = param->plugin;
138 CServiceIpcDbus* service_ipc = nullptr;
139 CServiceMain* service_main = nullptr;
141 service_ipc = plugin->get_service_ipc();
142 service_main = plugin->get_service_main();
145 if (service_ipc && service_main) {
146 bool use_custom_ui = service_main->get_client_custom_ui_option_by_appid(wakeup_appid);
147 bool ui_panel_enabled = false;
148 if (param->plugin) ui_panel_enabled = param->plugin->is_ui_panel_enabled();
149 if (ui_panel_enabled) {
150 service_ipc->masc_ui_dbus_enable_common_ui(!use_custom_ui);
151 service_ipc->masc_ui_dbus_change_assistant(wakeup_appid);
154 service_main->set_current_client_by_appid(wakeup_appid);
155 if ((pid = service_main->get_client_pid_by_appid(wakeup_appid)) != -1) {
156 service_main->client_send_preprocessing_information(pid);
157 service_ipc->change_active_state(pid, MA_ACTIVE_STATE_ACTIVE, wakeup_word,
158 extra_data, extra_data_length, extra_data_desc);
159 service_main->process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED);
161 // Appropriate MA Client not available, trying to launch new one
162 MAS_LOGI("MA Client with appid %s does not exist, launching client", wakeup_appid);
163 service_main->launch_client_by_appid(wakeup_appid, wakeup_word,
164 extra_data, extra_data_length, extra_data_desc, CLIENT_LAUNCH_MODE_ACTIVATION);
168 if (param->wakeup_word) free(param->wakeup_word);
169 if (param->wakeup_appid) free(param->wakeup_appid);
170 if (param->extra_data) free(param->extra_data);
171 if (param->extra_data_desc) free(param->extra_data_desc);
175 static void process_wakeup_event_by_word_timer(void* data)
177 if (nullptr == data) return;
179 AsyncParam* param = static_cast<AsyncParam*>(data);
180 MAS_LOGI("[ENTER] wakeword(%s), id(%d)", (const char*)(param->wakeup_word), param->id);
182 if (!param->wakeup_word) {
183 if (param->wakeup_appid) free(param->wakeup_appid);
184 if (param->extra_data) free(param->extra_data);
185 if (param->extra_data_desc) free(param->extra_data_desc);
190 std::string wakeup_word{param->wakeup_word};
191 unsigned char *extra_data = nullptr;
192 size_t extra_data_length = param->extra_data_length;
193 if (param->extra_data && extra_data_length > 0) {
194 extra_data = (unsigned char*)malloc(extra_data_length);
196 memcpy(extra_data, param->extra_data, extra_data_length);
198 std::string extra_data_desc{param->extra_data_desc ? param->extra_data_desc : ""};
199 const char* appid = nullptr;
201 CServicePlugin* plugin = param->plugin;
202 CServiceMain* service_main = nullptr;
205 service_main = plugin->get_service_main();
207 appid = service_main->get_client_appid_by_wakeup_word(param->wakeup_word);
211 if (param->wakeup_word) free(param->wakeup_word);
212 if (param->wakeup_appid) free(param->wakeup_appid);
213 if (param->extra_data) free(param->extra_data);
214 if (param->extra_data_desc) free(param->extra_data_desc);
218 if (service_main && appid) {
219 param = new(std::nothrow) AsyncParam;
222 param->wakeup_word = strdup(wakeup_word.c_str());
223 param->wakeup_appid = strdup(appid);
224 if (extra_data && extra_data_length > 0) {
225 param->extra_data = (unsigned char*)malloc(extra_data_length);
226 if (param->extra_data)
227 memcpy(param->extra_data, extra_data, extra_data_length);
229 param->extra_data_length = extra_data_length;
230 param->extra_data_desc = strdup(extra_data_desc.c_str());
231 param->plugin = plugin;
232 process_wakeup_event_by_appid_timer(static_cast<void*>(param));
237 extra_data = nullptr;
243 static void __wakeup_event_cb(mas_wakeup_event_info wakeup_info, void* user_data)
245 MAS_LOGI("[SUCCESS] __wakeup_event_cb is called, wakeup_word(%s)", wakeup_info.wakeup_word);
248 CServiceMain* service_main = nullptr;
249 CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
251 service_main = plugin->get_service_main();
252 CServiceIpcDbus* service_ipc = plugin->get_service_ipc();
253 if (plugin->is_ui_panel_enabled() && service_ipc) {
256 ret = service_ipc->masc_ui_dbus_send_hello();
259 MAS_LOGE("[ERROR] Fail to receive reply for hello, ret(%d)", ret);
271 MAS_LOGD("[Recorder Info] File not found!");
275 snprintf(mDumpFilename, sizeof(mDumpFilename), "/tmp/ma_service_%d_%d", getpid(), mDumpCount);
276 int ret = access(mDumpFilename, 0);
279 MAS_LOGD("[Recorder ERROR] File is already exist");
280 if (0 == remove(mDumpFilename)) {
281 MAS_LOGD("[Recorder] Remove file");
291 MAS_LOGD("[Recorder] Temp file name=[%s]", mDumpFilename);
294 mDumpFile = fopen(mDumpFilename, "wb+x");
296 MAS_LOGD("[Recorder ERROR] File not found!");
302 #if 0 /* + TEST_CODE */
303 if (WAKEUP_EVENT_SUCCESS == event) {
304 ecore_thread_main_loop_begin();
305 ecore_timer_add(1.0, __send_asr_result, "Today's");
306 ecore_thread_main_loop_end();
308 ecore_thread_main_loop_begin();
309 ecore_timer_add(2.0, __send_asr_result, "weather.");
310 ecore_thread_main_loop_end();
312 ecore_thread_main_loop_begin();
313 ecore_timer_add(3.0, __send_result, "Partly cloudy with temperatures from 75 to 88");
314 ecore_thread_main_loop_end();
316 #endif /* - TEST_CODE */
318 if (wakeup_info.wakeup_appid) {
319 AsyncParam* param = new(std::nothrow) AsyncParam;
321 param->id = ++g_last_wakeup_event_id;
323 wakeup_info.wakeup_word ? strdup(wakeup_info.wakeup_word) : nullptr;
324 param->wakeup_appid = strdup(wakeup_info.wakeup_appid);
325 if (wakeup_info.extra_data && wakeup_info.extra_data_length > 0) {
326 param->extra_data = (unsigned char*)malloc(wakeup_info.extra_data_length);
327 if (param->extra_data)
328 memcpy(param->extra_data, wakeup_info.extra_data, wakeup_info.extra_data_length);
329 param->extra_data_length = wakeup_info.extra_data_length;
331 param->extra_data = nullptr;
332 param->extra_data_length = 0;
334 param->extra_data_desc =
335 wakeup_info.extra_data_description ? strdup(wakeup_info.extra_data_description) : nullptr;
336 param->plugin = static_cast<CServicePlugin*>(user_data);
337 ecore_main_loop_thread_safe_call_async(process_wakeup_event_by_appid_timer,
338 static_cast<void*>(param));
340 } else if (wakeup_info.wakeup_word) {
341 AsyncParam* param = new(std::nothrow) AsyncParam;
343 param->id = ++g_last_wakeup_event_id;
344 param->wakeup_word = strdup(wakeup_info.wakeup_word);
345 param->wakeup_appid = nullptr;
346 if (wakeup_info.extra_data && wakeup_info.extra_data_length) {
347 param->extra_data = (unsigned char*)malloc(wakeup_info.extra_data_length);
348 if (param->extra_data)
349 memcpy(param->extra_data, wakeup_info.extra_data, wakeup_info.extra_data_length);
350 param->extra_data_length = wakeup_info.extra_data_length;
352 param->extra_data = nullptr;
353 param->extra_data_length = 0;
355 param->extra_data_desc =
356 wakeup_info.extra_data_description ? strdup(wakeup_info.extra_data_description) : nullptr;
357 param->plugin = static_cast<CServicePlugin*>(user_data);
358 ecore_main_loop_thread_safe_call_async(process_wakeup_event_by_word_timer,
359 static_cast<void*>(param));
364 static bool __validate_streaming_event_order(std::string appid, mas_speech_streaming_event_e *event)
368 static std::string previous_appid;
369 static mas_speech_streaming_event_e previous_event = MAS_SPEECH_STREAMING_EVENT_FINISH;
371 if (NULL == event) return false;
373 mas_speech_streaming_event_e expected_sequence[][2] = {
374 {MAS_SPEECH_STREAMING_EVENT_START, MAS_SPEECH_STREAMING_EVENT_CONTINUE},
375 {MAS_SPEECH_STREAMING_EVENT_START, MAS_SPEECH_STREAMING_EVENT_FINISH},
376 {MAS_SPEECH_STREAMING_EVENT_CONTINUE, MAS_SPEECH_STREAMING_EVENT_CONTINUE},
377 {MAS_SPEECH_STREAMING_EVENT_CONTINUE, MAS_SPEECH_STREAMING_EVENT_FINISH},
378 {MAS_SPEECH_STREAMING_EVENT_FINISH, MAS_SPEECH_STREAMING_EVENT_START},
379 /* If there is no audio data even after the start streaming request */
380 {MAS_SPEECH_STREAMING_EVENT_FINISH, MAS_SPEECH_STREAMING_EVENT_FINISH},
383 if (appid != previous_appid) {
384 /* When sending streaming event to a new client, it always sends START message first */
385 previous_event = MAS_SPEECH_STREAMING_EVENT_FINISH;
388 for (int loop = 0;loop < sizeof(expected_sequence) / sizeof(expected_sequence[0]);loop++) {
389 if (previous_event == expected_sequence[loop][0] &&
390 *event == expected_sequence[loop][1]) {
395 /* In case of FINISH -> CONTINUE without START, simply modify current event value */
396 if (MAS_SPEECH_STREAMING_EVENT_FINISH == previous_event &&
397 MAS_SPEECH_STREAMING_EVENT_CONTINUE == *event) {
398 *event = MAS_SPEECH_STREAMING_EVENT_START;
401 MAS_LOGD("[WARNING] forcibly changed CONTINUE to START : %d -> %d (PID %s -> %s)",
402 previous_event, *event, previous_appid.c_str(), appid.c_str());
407 previous_appid = appid;
408 previous_event = *event;
410 MAS_LOGE("[ERROR] State sequence validation failed : %d -> %d (APPID %s -> %s)",
411 previous_event, *event, previous_appid.c_str(), appid.c_str());
416 void handle_speech_streaming_event_failure(void* data)
418 AsyncParam* param = static_cast<AsyncParam*>(data);
419 if (NULL == param) return;
421 CServicePlugin* plugin = param->plugin;
422 CServiceMain* service_main = nullptr;
423 if (plugin) service_main = plugin->get_service_main();
426 pid_t pid = service_main->get_current_client_pid();
427 service_main->client_send_recognition_result(pid, MA_RECOGNITION_RESULT_EVENT_ERROR);
433 static void __audio_streaming_cb(mas_speech_streaming_event_e event, void* buffer, int len, void *user_data)
435 #ifdef PRINT_DETAILED_TIMEINFO
436 auto started = std::chrono::steady_clock::now();
437 auto checkpoint_1 = started;
438 auto checkpoint_2 = started;
439 auto checkpoint_3 = started;
442 CServicePlugin* plugin = static_cast<CServicePlugin*>(user_data);
444 if (event == MAS_SPEECH_STREAMING_EVENT_FAIL) {
445 AsyncParam* param = new(std::nothrow) AsyncParam;
447 param->plugin = plugin;
448 param->wakeup_word = nullptr;
449 param->wakeup_appid = nullptr;
450 param->extra_data = nullptr;
451 param->extra_data_length = 0;
452 param->extra_data_desc = nullptr;
453 ecore_main_loop_thread_safe_call_async(
454 handle_speech_streaming_event_failure, static_cast<void*>(param));
458 static int count = 0;
459 if (event != MAS_SPEECH_STREAMING_EVENT_CONTINUE || count % 100 == 0) {
460 MAS_LOGI("[SUCCESS] __audio_streaming_cb is called, event(%d), buffer(%p), len(%d)",
465 CServiceIpcDbus* service_ipc = nullptr;
466 CServiceMain* service_main = nullptr;
468 service_ipc = plugin->get_service_ipc();
469 service_main = plugin->get_service_main();
472 #ifdef PRINT_DETAILED_TIMEINFO
473 checkpoint_1 = std::chrono::steady_clock::now();
476 if (service_ipc && service_main) {
477 /* First check if we have dedicated audio processing app for current client */
478 boost::optional<std::string> appid =
479 service_main->get_current_audio_processing_appid();
481 /* If not, send audio data to the main client */
482 if (!appid) appid = service_main->get_current_client_appid();
484 boost::optional<std::string> preprocessing_appid =
485 service_main->get_current_preprocessing_client_appid();
488 MAS_LOGE("[ERROR] Fail to retrieve target appid of current MA client");
490 if (__validate_streaming_event_order(*appid, &event)) {
491 #ifdef PRINT_DETAILED_TIMEINFO
492 checkpoint_2 = std::chrono::steady_clock::now();
494 int ret = service_ipc->send_streaming_audio_data(*appid,
497 MAS_LOGE("[ERROR] Fail to send speech data, ret(%d)", ret);
499 if (preprocessing_appid && (*appid).compare(*preprocessing_appid) != 0) {
500 int ret = service_ipc->send_streaming_audio_data(*preprocessing_appid,
503 MAS_LOGE("[ERROR] Fail to send speech data to preprocessing client, ret(%d)", ret);
506 #ifdef PRINT_DETAILED_TIMEINFO
507 checkpoint_3 = std::chrono::steady_clock::now();
514 fwrite(speech_data->buffer, 1, speech_data->len, mDumpFile);
516 if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) {
518 MAS_LOGE("[Recorder SUCCESS] File Close");
522 MAS_LOGE("[Recorder ERROR] File not found!");
527 #ifdef PRINT_DETAILED_TIMEINFO
528 auto finished = std::chrono::steady_clock::now();
529 long long int total_count = get_time_interval_count(started, finished);
531 if(total_count > 30) {
532 long long int count1 = get_time_interval_count(started, checkpoint_1);
533 long long int count2 = get_time_interval_count(checkpoint_1, checkpoint_2);
534 long long int count3 = get_time_interval_count(checkpoint_2, checkpoint_3);
535 long long int count4 = get_time_interval_count(checkpoint_3, finished);
537 MAS_LOGE("Spent audio streaming callback time : %lld ms [%lld %lld %lld %lld]",
538 total_count, count1, count2, count3, count4);
543 static void __speech_status_cb(mas_speech_status_e status, void *user_data)
545 MAS_LOGD("[SUCCESS] __speech_status_cb is called, status(%d)", status);
548 static void __error_cb(int error, const char* err_msg, void* user_data)
550 MAS_LOGE("[SUCCESS] __error_cb is called, error(%d), err_msg(%s)", error, err_msg);
552 CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
553 if (nullptr == plugin) return;
555 CServiceIpcDbus* service_ipc = plugin->get_service_ipc();
556 if (plugin->is_ui_panel_enabled() && service_ipc) {
557 int ret = service_ipc->masc_ui_dbus_send_error_message(error, err_msg);
559 MAS_LOGE("[ERROR] Fail to send error message, ret(%d)", ret);
564 static void __setting_changed_cb(void *user_data)
566 CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
567 if (nullptr == plugin) return;
569 CServiceMain* service_main = plugin->get_service_main();
571 service_main->prelaunch_default_assistant();
572 service_main->update_voice_key_support_mode();
574 MAS_LOGD("[SUCCESS] __setting_changed_cb is called");
577 static void __streaming_section_changed_cb(ma_audio_streaming_data_section_e section, void* user_data)
579 MAS_LOGI("[SUCCESS] __streaming_section_changed_cb is called, section(%d)", section);
581 CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
582 if (nullptr == plugin) return;
584 CServiceIpcDbus *service_ipc = plugin->get_service_ipc();
585 CServiceMain* service_main = plugin->get_service_main();
586 if (service_ipc && service_main) {
587 pid_t pid = service_main->get_current_client_pid();
588 int ret = service_ipc->send_streaming_section_changed(pid, (int)section);
590 MAS_LOGE("[ERROR] Fail to send streaming section changed information, ret(%d)", ret);
595 static void __wakeup_engine_command_cb(mas_wakeup_engine_command_target_e target, const char* assistant_name, const char* command, void* user_data)
597 MAS_LOGD("[SUCCESS] __wakeup_engine_command_cb is called, command(%s)", command);
599 CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
600 if (nullptr == plugin) return;
602 CServiceIpcDbus *service_ipc = plugin->get_service_ipc();
603 CServiceMain* service_main = plugin->get_service_main();
604 if (service_ipc && service_main) {
605 pid_t pid = service_main->get_client_pid_by_appid(assistant_name);
607 int ret = service_ipc->send_wakeup_engine_command(pid, command);
609 MAS_LOGE("[ERROR] Fail to send wakeup engine command, ret(%d)", ret);
615 static void __wakeup_service_state_changed_cb(ma_service_state_e state, void* user_data)
617 MAS_LOGD("[SUCCESS] __wakeup_service_state_changed_cb is called, state(%d)", state);
619 CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
620 if (nullptr == plugin) return;
622 CServiceMain* service_main = plugin->get_service_main();
624 service_main->set_current_service_state(state);
628 static void __wakeup_service_voice_key_status_changed_cb(ma_voice_key_status_e status, void* user_data)
630 MAS_LOGD("[SUCCESS] __wakeup_service_voice_key_status_changed_cb is called, state(%d)", status);
632 CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
633 if (nullptr == plugin) return;
635 CServiceIpcDbus *service_ipc = plugin->get_service_ipc();
636 CServiceMain* service_main = plugin->get_service_main();
637 if (service_ipc && service_main) {
638 pid_t pid = service_main->get_current_client_pid();
639 int ret = service_ipc->change_voice_key_status(pid, status);
641 MAS_LOGE("[ERROR] Fail to send voice key status changed information, ret(%d)", ret);
646 static void __loaded_engine_changed_cb(void* user_data)
648 MAS_LOGD("[SUCCESS] __loaded_engine_changed_cb is called");
650 CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
651 if (nullptr == plugin) return;
653 CServiceMain* service_main = plugin->get_service_main();
655 /* Make sure the app doesn't restart within a conversation session */
656 ma_service_state_e service_state = service_main->get_current_service_state();
657 if (service_state == MA_SERVICE_STATE_INACTIVE ||
658 service_state == MA_SERVICE_STATE_LISTENING) {
659 MAS_LOGE("[SUCCESS] Restarting service");
660 service_main->app_restart();
662 MAS_LOGE("Cannot restart service when service_state is %d", service_state);
667 int CServicePlugin::initialize(void)
671 char filepath[512] = {'\0', };
672 const char *default_engine_path = MA_WAKEUP_MANAGER_PATH;
673 snprintf(filepath, 512, "%s/%s", default_engine_path, MA_DEFAULT_WAKEUP_MANAGER_FILENAME);
676 mPluginHandle = nullptr;
677 mPluginHandle = dlopen(filepath, RTLD_LAZY);
678 if (nullptr != (error = dlerror())) {
679 MAS_LOGE("[ERROR] Fail to dlopen(%s), error(%s)", filepath, error);
680 if (mPluginHandle) dlclose(mPluginHandle);
681 mPluginHandle = nullptr;
682 return -1; //MAS_ERROR_OPERATION_FAILED;
684 if (nullptr == mPluginHandle) {
685 MAS_LOGE("[ERROR] Fail to dlopen(%s), error(%s)", filepath, error);
686 return -1; //MAS_ERROR_OPERATION_FAILED;
689 mWakeupManagerInterface.initialize =
690 (wakeup_manager_initialize)dlsym(mPluginHandle,
691 MA_WAKEUP_MANAGER_FUNC_INITIALIZE);
692 mWakeupManagerInterface.deinitialize =
693 (wakeup_manager_deinitialize)dlsym(mPluginHandle,
694 MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE);
695 mWakeupManagerInterface.get_settings =
696 (wakeup_manager_get_settings)dlsym(mPluginHandle,
697 MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
698 mWakeupManagerInterface.add_assistant_wakeup_word =
699 (wakeup_manager_add_assistant_wakeup_word)dlsym(mPluginHandle,
700 MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD);
701 mWakeupManagerInterface.remove_assistant_wakeup_word =
702 (wakeup_manager_remove_assistant_wakeup_word)dlsym(mPluginHandle,
703 MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD);
704 mWakeupManagerInterface.add_assistant_language =
705 (wakeup_manager_add_assistant_language)dlsym(mPluginHandle,
706 MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE);
707 mWakeupManagerInterface.add_assistant_wakeup_engine =
708 (wakeup_manager_add_assistant_wakeup_engine)dlsym(mPluginHandle,
709 MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_ENGINE);
710 mWakeupManagerInterface.set_default_assistant =
711 (wakeup_manager_set_default_assistant)dlsym(mPluginHandle,
712 MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT);
713 mWakeupManagerInterface.get_default_assistant =
714 (wakeup_manager_get_default_assistant)dlsym(mPluginHandle,
715 MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT);
716 mWakeupManagerInterface.set_language =
717 (wakeup_manager_set_language)dlsym(mPluginHandle,
718 MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE);
719 mWakeupManagerInterface.activate =
720 (wakeup_manager_activate)dlsym(mPluginHandle,
721 MA_WAKEUP_MANAGER_FUNC_ACTIVATE);
722 mWakeupManagerInterface.deactivate =
723 (wakeup_manager_deactivate)dlsym(mPluginHandle,
724 MA_WAKEUP_MANAGER_FUNC_DEACTIVATE);
725 mWakeupManagerInterface.update_voice_feedback_state =
726 (wakeup_manager_update_voice_feedback_state)dlsym(mPluginHandle,
727 MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE);
728 mWakeupManagerInterface.set_assistant_specific_command =
729 (wakeup_manager_set_assistant_specific_command)dlsym(mPluginHandle,
730 MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND);
731 mWakeupManagerInterface.set_background_volume =
732 (wakeup_manager_set_background_volume)dlsym(mPluginHandle,
733 MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME);
734 mWakeupManagerInterface.update_recognition_result =
735 (wakeup_manager_update_recognition_result)dlsym(mPluginHandle,
736 MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT);
737 mWakeupManagerInterface.process_plugin_event =
738 (wakeup_manager_process_plugin_event)dlsym(mPluginHandle,
739 MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT);
740 mWakeupManagerInterface.start_streaming_utterance_data =
741 (wakeup_manager_start_streaming_utterance_data)dlsym(mPluginHandle,
742 MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA);
743 mWakeupManagerInterface.stop_streaming_utterance_data =
744 (wakeup_manager_stop_streaming_utterance_data)dlsym(mPluginHandle,
745 MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA);
746 mWakeupManagerInterface.start_streaming_previous_utterance_data =
747 (wakeup_manager_start_streaming_previous_utterance_data)dlsym(mPluginHandle,
748 MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA);
749 mWakeupManagerInterface.stop_streaming_previous_utterance_data =
750 (wakeup_manager_stop_streaming_previous_utterance_data)dlsym(mPluginHandle,
751 MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA);
752 mWakeupManagerInterface.start_streaming_follow_up_data =
753 (wakeup_manager_start_streaming_follow_up_data)dlsym(mPluginHandle,
754 MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA);
755 mWakeupManagerInterface.stop_streaming_follow_up_data =
756 (wakeup_manager_stop_streaming_follow_up_data)dlsym(mPluginHandle,
757 MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA);
758 mWakeupManagerInterface.get_audio_format =
759 (wakeup_manager_get_audio_format)dlsym(mPluginHandle,
760 MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT);
761 mWakeupManagerInterface.get_audio_source_type =
762 (wakeup_manager_get_audio_source_type)dlsym(mPluginHandle,
763 MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE);
764 mWakeupManagerInterface.set_wake_word_audio_require_flag =
765 (wakeup_manager_set_wake_word_audio_require_flag)dlsym(mPluginHandle,
766 MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG);
767 mWakeupManagerInterface.set_assistant_language =
768 (wakeup_manager_set_assistant_language)dlsym(mPluginHandle,
769 MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_LANGUAGE);
770 mWakeupManagerInterface.set_voice_key_tap_duration =
771 (wakeup_manager_set_voice_key_tap_duration)dlsym(mPluginHandle,
772 MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_TAP_DURATION);
773 mWakeupManagerInterface.unset_voice_key_tap_duration =
774 (wakeup_manager_unset_voice_key_tap_duration)dlsym(mPluginHandle,
775 MA_WAKEUP_MANAGER_FUNC_UNSET_VOICE_KEY_TAP_DURATION);
776 mWakeupManagerInterface.set_voice_key_support_mode =
777 (wakeup_manager_set_voice_key_support_mode)dlsym(mPluginHandle,
778 MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_SUPPORT_MODE);
779 mWakeupManagerInterface.set_wakeup_event_callback =
780 (wakeup_manager_set_wakeup_event_callback)dlsym(mPluginHandle,
781 MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK);
782 mWakeupManagerInterface.set_utterance_streaming_callback =
783 (wakeup_manager_set_utterance_streaming_callback)dlsym(mPluginHandle,
784 MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK);
785 mWakeupManagerInterface.set_previous_utterance_streaming_callback =
786 (wakeup_manager_set_previous_utterance_streaming_callback)dlsym(mPluginHandle,
787 MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK);
788 mWakeupManagerInterface.set_follow_up_streaming_callback =
789 (wakeup_manager_set_follow_up_streaming_callback)dlsym(mPluginHandle,
790 MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK);
791 mWakeupManagerInterface.set_speech_status_callback =
792 (wakeup_manager_set_speech_status_callback)dlsym(mPluginHandle,
793 MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK);
794 mWakeupManagerInterface.set_setting_changed_callback =
795 (wakeup_manager_set_setting_changed_callback)dlsym(mPluginHandle,
796 MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK);
797 mWakeupManagerInterface.set_error_callback =
798 (wakeup_manager_set_error_callback)dlsym(mPluginHandle,
799 MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK);
800 mWakeupManagerInterface.set_streaming_section_changed_callback =
801 (wakeup_manager_set_streaming_section_changed_callback)dlsym(mPluginHandle,
802 MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK);
803 mWakeupManagerInterface.set_wakeup_engine_command_callback =
804 (wakeup_manager_set_wakeup_engine_command_callback)dlsym(mPluginHandle,
805 MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK);
806 mWakeupManagerInterface.set_wakeup_service_state_changed_callback =
807 (wakeup_manager_set_wakeup_service_state_changed_callback)dlsym(mPluginHandle,
808 MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK);
809 mWakeupManagerInterface.set_voice_key_status_changed_callback =
810 (wakeup_manager_set_voice_key_status_changed_callback)dlsym(mPluginHandle,
811 MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_STATUS_CHANGED_CALLBACK);
812 mWakeupManagerInterface.set_loaded_engine_changed_callback =
813 (wakeup_manager_set_loaded_engine_changed_callback)dlsym(mPluginHandle,
814 MA_WAKEUP_MANAGER_FUNC_SET_LOADED_ENGINE_CHANGED_CALLBACK);
817 if (NULL != mPluginHandle) {
818 wakeup_manager_initialize func = mWakeupManagerInterface.initialize;
821 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_INITIALIZE);
825 MAS_LOGE("[ERROR] Fail to initialize, ret(%d)", ret);
829 wakeup_manager_get_settings get_settings_func = mWakeupManagerInterface.get_settings;
831 if (NULL == get_settings_func) {
832 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
835 ret = get_settings_func(&mPluginSettings, &struct_size);
836 if (0 != ret || struct_size != sizeof(ma_plugin_settings)) {
837 MAS_LOGE("[ERROR] Fail to get settings, ret(%d), size %zu", ret, struct_size);
838 mPluginSettings = NULL;
842 MAS_LOGE("[ERROR] mPluginHandle is not valid");
847 int CServicePlugin::deinitialize(void)
854 MAS_LOGD("[Recorder ERROR] File not found!");
859 if (NULL != mPluginHandle) {
860 wakeup_manager_deinitialize func = mWakeupManagerInterface.deinitialize;
862 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE);
866 MAS_LOGE("[ERROR] Fail to deinitialize, ret(%d)", ret);
870 dlclose(mPluginHandle);
871 mPluginHandle = NULL;
873 MAS_LOGE("[ERROR] mPluginHandle is not valid");
879 int CServicePlugin::get_settings(ma_plugin_settings **settings, size_t *struct_size)
882 if (NULL != mPluginHandle) {
883 wakeup_manager_get_settings func = mWakeupManagerInterface.get_settings;
885 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
887 ret = func(settings, struct_size);
889 MAS_LOGE("[ERROR] Fail to get settings, ret(%d)", ret);
893 MAS_LOGE("[ERROR] mPluginHandle is not valid");
898 int CServicePlugin::set_language(const char* language)
901 if (NULL != mPluginHandle) {
902 wakeup_manager_set_language func = mWakeupManagerInterface.set_language;
904 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE);
906 ret = func(language);
908 MAS_LOGE("[ERROR] Fail to set langauge(%s), ret(%d)", language, ret);
912 MAS_LOGE("[ERROR] mPluginHandle is not valid");
917 int CServicePlugin::add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language)
920 if (NULL != mPluginHandle) {
921 wakeup_manager_add_assistant_wakeup_word func = mWakeupManagerInterface.add_assistant_wakeup_word;
923 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD);
925 ret = func(appid, wakeup_word, language);
927 MAS_LOGE("[ERROR] Fail to add wakeup word(%s)(%s)(%s), ret(%d)", appid, wakeup_word, language, ret);
931 MAS_LOGE("[ERROR] mPluginHandle is not valid");
936 int CServicePlugin::remove_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language)
939 if (NULL != mPluginHandle) {
940 wakeup_manager_remove_assistant_wakeup_word func = mWakeupManagerInterface.remove_assistant_wakeup_word;
942 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD);
944 ret = func(appid, wakeup_word, language);
946 MAS_LOGE("[ERROR] Fail to remove wakeup word(%s)(%s)(%s), ret(%d)", appid, wakeup_word, language, ret);
950 MAS_LOGE("[ERROR] mPluginHandle is not valid");
955 int CServicePlugin::add_assistant_language(const char* appid, const char* language)
958 if (NULL != mPluginHandle) {
959 wakeup_manager_add_assistant_language func = mWakeupManagerInterface.add_assistant_language;
961 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE);
963 ret = func(appid, language);
965 MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%s), ret(%d)", appid, language, ret);
969 MAS_LOGE("[ERROR] mPluginHandle is not valid");
974 int CServicePlugin::add_assistant_wakeup_engine(const char* appid, const char* engine)
977 if (NULL != mPluginHandle) {
978 wakeup_manager_add_assistant_wakeup_engine func = mWakeupManagerInterface.add_assistant_wakeup_engine;
980 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_ENGINE);
982 ret = func(appid, engine);
984 MAS_LOGE("[ERROR] Fail to set wakeup engine(%s)(%s), ret(%d)", appid, engine, ret);
988 MAS_LOGE("[ERROR] mPluginHandle is not valid");
993 int CServicePlugin::set_default_assistant(const char* appid)
996 if (NULL != mPluginHandle) {
997 wakeup_manager_set_default_assistant func = mWakeupManagerInterface.set_default_assistant;
999 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT);
1003 MAS_LOGE("[ERROR] Fail to set default assistant(%s), ret(%d)", appid, ret);
1007 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1012 int CServicePlugin::get_default_assistant(const char** appid)
1015 if (NULL == appid) {
1016 MAS_LOGE("[ERROR] appid is not valid");
1019 if (NULL != mPluginHandle) {
1020 wakeup_manager_get_default_assistant func = mWakeupManagerInterface.get_default_assistant;
1022 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT);
1026 MAS_LOGE("[ERROR] Fail to get default assistant, ret(%d)", ret);
1030 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1035 int CServicePlugin::activate(void)
1038 if (NULL != mPluginHandle) {
1039 wakeup_manager_activate func = mWakeupManagerInterface.activate;
1041 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ACTIVATE);
1045 MAS_LOGE("[ERROR] Fail to start recording, ret(%d)", ret);
1049 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1054 int CServicePlugin::deactivate(void)
1057 if (NULL != mPluginHandle) {
1058 wakeup_manager_deactivate func = mWakeupManagerInterface.deactivate;
1060 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEACTIVATE);
1064 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
1068 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1073 int CServicePlugin::update_voice_feedback_state(const char* appid, int state)
1076 if (NULL != mPluginHandle) {
1077 wakeup_manager_update_voice_feedback_state func = mWakeupManagerInterface.update_voice_feedback_state;
1079 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE);
1081 ret = func(appid, state);
1083 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
1087 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1092 int CServicePlugin::set_assistant_specific_command(const char* appid, const char* command)
1095 if (NULL != mPluginHandle) {
1096 wakeup_manager_set_assistant_specific_command func = mWakeupManagerInterface.set_assistant_specific_command;
1098 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND);
1100 ret = func(appid, command);
1102 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
1106 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1111 int CServicePlugin::set_background_volume(const char* appid, double ratio)
1114 if (NULL != mPluginHandle) {
1115 wakeup_manager_set_background_volume func = mWakeupManagerInterface.set_background_volume;
1117 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME);
1119 ret = func(appid, ratio);
1121 MAS_LOGE("[ERROR] Fail to set background volume, ret(%d)", ret);
1125 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1130 int CServicePlugin::update_recognition_result(const char* appid, int state)
1133 if (NULL != mPluginHandle) {
1134 wakeup_manager_update_recognition_result func = mWakeupManagerInterface.update_recognition_result;
1136 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT);
1138 ret = func(appid, state);
1140 MAS_LOGE("[ERROR] Fail to update result state, ret(%d)", ret);
1144 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1149 int CServicePlugin::process_event(int event, void *data, int len)
1152 if (NULL != mPluginHandle) {
1153 wakeup_manager_process_plugin_event func = mWakeupManagerInterface.process_plugin_event;
1155 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT);
1157 ret = func((mas_plugin_event_e)event, data, len);
1159 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
1163 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1168 int CServicePlugin::start_streaming_utterance_data(void)
1172 if (NULL != mPluginHandle) {
1173 wakeup_manager_start_streaming_utterance_data func = mWakeupManagerInterface.start_streaming_utterance_data;
1175 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA);
1179 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
1183 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1188 int CServicePlugin::stop_streaming_utterance_data(void)
1191 if (NULL != mPluginHandle) {
1192 wakeup_manager_stop_streaming_utterance_data func = mWakeupManagerInterface.stop_streaming_utterance_data;
1194 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA);
1198 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
1202 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1207 int CServicePlugin::start_streaming_previous_utterance_data(void)
1210 if (NULL != mPluginHandle) {
1211 wakeup_manager_start_streaming_previous_utterance_data func = mWakeupManagerInterface.start_streaming_previous_utterance_data;
1213 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA);
1217 MAS_LOGE("[ERROR] Fail to request previous speech data, ret(%d)", ret);
1221 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1226 int CServicePlugin::stop_streaming_previous_utterance_data(void)
1229 if (NULL != mPluginHandle) {
1230 wakeup_manager_stop_streaming_previous_utterance_data func = mWakeupManagerInterface.stop_streaming_previous_utterance_data;
1232 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA);
1236 MAS_LOGE("[ERROR] Fail to request previous speech data, ret(%d)", ret);
1240 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1245 int CServicePlugin::start_streaming_follow_up_data(void)
1248 if (NULL != mPluginHandle) {
1249 wakeup_manager_start_streaming_follow_up_data func = mWakeupManagerInterface.start_streaming_follow_up_data;
1251 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA);
1255 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
1259 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1264 int CServicePlugin::stop_streaming_follow_up_data(void)
1267 if (NULL != mPluginHandle) {
1268 wakeup_manager_stop_streaming_follow_up_data func = mWakeupManagerInterface.stop_streaming_follow_up_data;
1270 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA);
1274 MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
1278 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1283 int CServicePlugin::get_recording_audio_format(int *rate, int *channel, int *audio_type)
1286 if (NULL != mPluginHandle) {
1287 wakeup_manager_get_audio_format func = mWakeupManagerInterface.get_audio_format;
1289 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT);
1291 ret = func(rate, channel, audio_type);
1293 MAS_LOGE("[ERROR] Fail to get recording audio format, ret(%d)", ret);
1297 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1302 int CServicePlugin::get_recording_audio_source_type(char** type)
1305 if (NULL != mPluginHandle) {
1306 wakeup_manager_get_audio_source_type func = mWakeupManagerInterface.get_audio_source_type;
1308 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE);
1312 MAS_LOGE("[ERROR] Fail to get recording audio source type, ret(%d)", ret);
1316 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1321 int CServicePlugin::set_voice_key_tap_duration(float duration)
1324 if (NULL != mPluginHandle) {
1325 wakeup_manager_set_voice_key_tap_duration func = mWakeupManagerInterface.set_voice_key_tap_duration;
1327 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_TAP_DURATION);
1329 ret = func(duration);
1331 MAS_LOGE("[ERROR] Fail to set voice key tap duration, ret(%d)", ret);
1335 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1340 int CServicePlugin::unset_voice_key_tap_duration()
1343 if (NULL != mPluginHandle) {
1344 wakeup_manager_unset_voice_key_tap_duration func = mWakeupManagerInterface.unset_voice_key_tap_duration;
1346 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UNSET_VOICE_KEY_TAP_DURATION);
1350 MAS_LOGE("[ERROR] Fail to unset voice key tap duration, ret(%d)", ret);
1354 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1359 int CServicePlugin::set_voice_key_support_mode(int mode)
1362 if (NULL != mPluginHandle) {
1363 wakeup_manager_set_voice_key_support_mode func = mWakeupManagerInterface.set_voice_key_support_mode;
1365 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_SUPPORT_MODE);
1369 MAS_LOGE("[ERROR] Fail to set voice key support mode, ret(%d)", ret);
1373 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1378 int CServicePlugin::set_wake_word_audio_require_flag(const char* appid, bool require)
1381 if (NULL != mPluginHandle) {
1382 wakeup_manager_set_wake_word_audio_require_flag func = mWakeupManagerInterface.set_wake_word_audio_require_flag;
1384 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG);
1386 ret = func(require);
1388 MAS_LOGE("[ERROR] Fail to set wake word audio require flag, ret(%d)", ret);
1392 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1397 int CServicePlugin::set_assistant_language(const char* appid, const char* language)
1400 if (NULL != mPluginHandle) {
1401 wakeup_manager_set_assistant_language func = mWakeupManagerInterface.set_assistant_language;
1403 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_LANGUAGE);
1405 ret = func(appid, language);
1407 MAS_LOGE("[ERROR] Fail to set assistant language, ret(%d)", ret);
1411 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1416 int CServicePlugin::set_callbacks(void)
1418 int ret = set_wakeup_event_callback(__wakeup_event_cb, this);
1420 MAS_LOGE("Fail to set wakeup event cb");
1424 ret = set_utterance_streaming_callback(__audio_streaming_cb, this);
1426 MAS_LOGE("Fail to set utterance streaming cb");
1430 ret = set_previous_utterance_streaming_callback(__audio_streaming_cb, this);
1432 MAS_LOGE("Fail to set previous utterance streaming cb");
1436 ret = set_follow_up_streaming_callback(__audio_streaming_cb, this);
1438 MAS_LOGE("Fail to set follow-up streaming cb");
1442 ret = set_speech_status_callback(__speech_status_cb, this);
1444 MAS_LOGE("Fail to set speech status changed cb");
1448 ret = set_setting_changed_callback(__setting_changed_cb, this);
1450 MAS_LOGE("Fail to set setting changed cb");
1454 ret = set_error_callback(__error_cb, this);
1456 MAS_LOGE("Fail to set error cb");
1460 ret = set_streaming_section_changed_callback(__streaming_section_changed_cb, this);
1462 MAS_LOGE("Fail to set streaming section changed cb");
1466 ret = set_wakeup_engine_command_callback(__wakeup_engine_command_cb, this);
1468 MAS_LOGE("Fail to set wakeup engine command cb");
1472 ret = set_wakeup_service_state_changed_callback(__wakeup_service_state_changed_cb, this);
1474 MAS_LOGE("Fail to set wakeup engine command cb");
1478 ret = set_voice_key_status_changed_callback(__wakeup_service_voice_key_status_changed_cb, this);
1480 MAS_LOGE("Fail to set wakeup engine command cb");
1484 ret = set_loaded_engine_changed_callback(__loaded_engine_changed_cb, this);
1486 MAS_LOGE("Fail to set loaded engine changed cb");
1493 int CServicePlugin::set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data)
1496 if (NULL != mPluginHandle) {
1497 wakeup_manager_set_wakeup_event_callback func = mWakeupManagerInterface.set_wakeup_event_callback;
1499 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK);
1501 ret = func(callback, user_data);
1503 MAS_LOGE("[ERROR] Fail to set wakeup event callback, ret(%d)", ret);
1507 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1512 int CServicePlugin::set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
1515 if (NULL != mPluginHandle) {
1516 wakeup_manager_set_utterance_streaming_callback func = mWakeupManagerInterface.set_utterance_streaming_callback;
1518 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK);
1520 ret = func(callback, user_data);
1522 MAS_LOGE("[ERROR] Fail to set utterance streaming callback, ret(%d)", ret);
1526 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1531 int CServicePlugin::set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
1534 if (NULL != mPluginHandle) {
1535 wakeup_manager_set_previous_utterance_streaming_callback func = mWakeupManagerInterface.set_previous_utterance_streaming_callback;
1537 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK);
1539 ret = func(callback, user_data);
1541 MAS_LOGE("[ERROR] Fail to set utterance streaming callback, ret(%d)", ret);
1545 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1550 int CServicePlugin::set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
1553 if (NULL != mPluginHandle) {
1554 wakeup_manager_set_follow_up_streaming_callback func = mWakeupManagerInterface.set_follow_up_streaming_callback;
1556 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK);
1558 ret = func(callback, user_data);
1560 MAS_LOGE("[ERROR] Fail to set follow-up streaming callback, ret(%d)", ret);
1564 MAS_LOGE("[ERROR] mPluginHandle is not valid");
1569 int CServicePlugin::set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data)
1572 if (NULL != mPluginHandle) {
1573 wakeup_manager_set_speech_status_callback func = mWakeupManagerInterface.set_speech_status_callback;
1575 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK);
1577 ret = func(callback, user_data);
1579 MAS_LOGE("[ERROR] Fail to set speech status callback, ret(%d)", ret);
1586 int CServicePlugin::set_setting_changed_callback(wakeup_service_setting_changed_cb callback, void* user_data)
1589 if (NULL != mPluginHandle) {
1590 wakeup_manager_set_setting_changed_callback func = mWakeupManagerInterface.set_setting_changed_callback;
1592 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK);
1594 ret = func(callback, user_data);
1596 MAS_LOGE("[ERROR] Fail to set setting_changed callback, ret(%d)", ret);
1603 int CServicePlugin::set_error_callback(wakeup_service_error_cb callback, void* user_data)
1606 if (NULL != mPluginHandle) {
1607 wakeup_manager_set_error_callback func = mWakeupManagerInterface.set_error_callback;
1609 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK);
1611 ret = func(callback, user_data);
1613 MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
1620 int CServicePlugin::set_streaming_section_changed_callback(wakeup_service_streaming_section_changed_cb callback, void* user_data)
1623 if (NULL != mPluginHandle) {
1624 wakeup_manager_set_streaming_section_changed_callback func = mWakeupManagerInterface.set_streaming_section_changed_callback;
1626 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK);
1628 ret = func(callback, user_data);
1630 MAS_LOGE("[ERROR] Fail to set streaming section changed callback, ret(%d)", ret);
1637 int CServicePlugin::set_wakeup_engine_command_callback(wakeup_service_wakeup_engine_command_cb callback, void* user_data)
1640 if (NULL != mPluginHandle) {
1641 wakeup_manager_set_wakeup_engine_command_callback func = mWakeupManagerInterface.set_wakeup_engine_command_callback;
1643 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK);
1645 ret = func(callback, user_data);
1647 MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
1654 int CServicePlugin::set_wakeup_service_state_changed_callback(wakeup_service_wakeup_service_state_changed_cb callback, void* user_data)
1657 if (NULL != mPluginHandle) {
1658 wakeup_manager_set_wakeup_service_state_changed_callback func = mWakeupManagerInterface.set_wakeup_service_state_changed_callback;
1660 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK);
1662 ret = func(callback, user_data);
1664 MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
1671 int CServicePlugin::set_voice_key_status_changed_callback(wakeup_service_voice_key_status_changed_cb callback, void* user_data)
1674 if (NULL != mPluginHandle) {
1675 wakeup_manager_set_voice_key_status_changed_callback func = mWakeupManagerInterface.set_voice_key_status_changed_callback;
1677 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_STATUS_CHANGED_CALLBACK);
1679 ret = func(callback, user_data);
1681 MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
1688 int CServicePlugin::set_loaded_engine_changed_callback(wakeup_service_loaded_engine_changed_cb callback, void* user_data)
1691 if (NULL != mPluginHandle) {
1692 wakeup_manager_set_loaded_engine_changed_callback func = mWakeupManagerInterface.set_loaded_engine_changed_callback;
1694 MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_LOADED_ENGINE_CHANGED_CALLBACK);
1696 ret = func(callback, user_data);
1698 MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);