--- /dev/null
- static Eina_Bool process_wakeup_event_by_appid_timer(void* data)
+/*
+ * Copyright 2020 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <tizen.h>
+#include <service_app.h>
+#include <app_manager.h>
+#include <app.h>
+#include <malloc.h>
+#include <Ecore.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <glib.h>
+#include <dlfcn.h>
+#include <new>
+
+#include "service_main.h"
+#include "service_plugin.h"
+#include "service_ipc_dbus.h"
+
+/* Sound buf save for test */
+#if 0
+#define BUF_SAVE_MODE
+#endif
+
++static int g_last_wakeup_event_id = 0;
++
+typedef struct {
++ int id;
+ void* data;
+ CServicePlugin* plugin;
+} AsyncParam;
+
+bool CServicePlugin::is_ui_panel_enabled()
+{
+ /* By default we assume the ui panel is always enabled unless explicitly turned off */
+ bool ret = false;
+ if (mPluginSettings) {
+ ret = mPluginSettings->ui_panel_enabled;
+ }
+ MAS_LOGD("UI Panel Enabled : %d", ret);
+ return ret;
+}
+
+#if 0 /* + TEST_CODE */
+Eina_Bool __send_asr_result(void *data)
+{
+ MAS_LOGD("[ENTER]");
+
+ if (!strcmp((char*)data, "Today's")) {
+ masc_ui_dbus_send_asr_result(-1, 1, "Today's");
+ }
+ if (!strcmp((char*)data, "weather.")) {
+ masc_ui_dbus_send_asr_result(-1, 0, "Today's weather.");
+ }
+
+ MAS_LOGD("END");
+ return EINA_FALSE;
+}
+
+Eina_Bool __send_result(void *data)
+{
+ MAS_LOGD("[ENTER]");
+
+ int ret = masc_ui_dbus_send_result(-1, (const char*)data, (const char*)data, "test");
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to stop recording(%d)", ret);
+ return EINA_TRUE;
+ }
+
+ MAS_LOGD("END");
+ return EINA_FALSE;
+}
+#endif /* -TEST_CODE */
+
- if (NULL == data) return ECORE_CALLBACK_CANCEL;
++static void process_wakeup_event_by_appid_timer(void* data)
+{
- MAS_LOGD("[ENTER] appid(%s)", appid);
++ if (nullptr == data) return;
++
+ AsyncParam* param = static_cast<AsyncParam*>(data);
+
+ char* appid = static_cast<char*>(param->data);
- if (!appid) return ECORE_CALLBACK_CANCEL;
++ MAS_LOGD("[ENTER] appid(%s), id(%d), g_last_wakeup_event_id(%d)",
++ appid, param->id, g_last_wakeup_event_id);
++
++ if (!appid) {
++ delete param;
++ return;
++ }
++
++ if (param->id < g_last_wakeup_event_id) {
++ free(param->data);
++ delete param;
++ return;
++ }
+
+ pid_t pid = -1;
- if (appid) free(appid);
+
+ CServicePlugin* plugin = param->plugin;
+ CServiceIpcDbus* service_ipc = nullptr;
+ CServiceMain* service_main = nullptr;
+ if (plugin) {
+ service_ipc = plugin->get_service_ipc();
+ service_main = plugin->get_service_main();
+ }
++
+ if (service_ipc && service_main) {
+ bool use_custom_ui = service_main->get_client_custom_ui_option_by_appid(appid);
+ bool ui_panel_enabled = false;
+ if (param->plugin) ui_panel_enabled = param->plugin->is_ui_panel_enabled();
+ if (ui_panel_enabled) {
+ service_ipc->masc_ui_dbus_enable_common_ui(!use_custom_ui);
+ service_ipc->masc_ui_dbus_change_assistant(appid);
+ }
+
+ service_main->set_current_client_by_appid(appid);
+ if ((pid = service_main->get_client_pid_by_appid(appid)) != -1) {
+ service_main->client_send_preprocessing_information(pid);
+ service_ipc->change_active_state(pid, MA_ACTIVE_STATE_ACTIVE);
+ service_main->process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED);
+ } else {
+ // Appropriate MA Client not available, trying to launch new one
+ MAS_LOGD("MA Client with appid %s does not exist, launching client", appid);
+ service_main->launch_client_by_appid(appid, CLIENT_LAUNCH_MODE_ACTIVATION);
+ }
+ }
+
-
- MAS_LOGD("END");
- return ECORE_CALLBACK_CANCEL;
++ if (param->data) free(param->data);
+ delete param;
- static Eina_Bool process_wakeup_event_by_word_timer(void* data)
+}
+
- MAS_LOGD("[ENTER]");
++static void process_wakeup_event_by_word_timer(void* data)
+{
- if (NULL == data) return ECORE_CALLBACK_CANCEL;
++ if (nullptr == data) return;
+
- if (service_main) {
- const char* appid = service_main->get_client_appid_by_wakeup_word(wakeup_word);
- if (appid) {
- param = new(std::nothrow) AsyncParam;
- if (param) {
- param->data = static_cast<void*>(strdup(appid));
- param->plugin = plugin;
- process_wakeup_event_by_appid_timer(static_cast<void*>(param));
- }
+ AsyncParam* param = static_cast<AsyncParam*>(data);
++ MAS_LOGD("[ENTER] wakeword(%s), id(%d)", (const char*)(param->data), param->id);
++
++ if (!param->data) {
++ delete param;
++ return;
++ }
+
+ char* wakeup_word = static_cast<char*>(param->data);
++ const char* appid = nullptr;
+ CServicePlugin* plugin = param->plugin;
+ CServiceMain* service_main = nullptr;
+
+ if (plugin) {
+ service_main = plugin->get_service_main();
++ if (service_main) {
++ appid = service_main->get_client_appid_by_wakeup_word(wakeup_word);
++ }
+ }
+
++ free(param->data);
+ delete param;
+ param = nullptr;
+
- if (wakeup_word) free(wakeup_word);
-
++ if (service_main && appid) {
++ param = new(std::nothrow) AsyncParam;
++ if (param) {
++ param->id = param->id;
++ param->data = static_cast<void*>(strdup(appid));
++ param->plugin = plugin;
++ process_wakeup_event_by_appid_timer(static_cast<void*>(param));
+ }
+ }
+
- return ECORE_CALLBACK_CANCEL;
+ MAS_LOGD("END");
- ecore_thread_main_loop_begin();
- ecore_timer_add(0.0f, process_wakeup_event_by_appid_timer,
++ return;
+}
+
+static void __wakeup_event_cb(mas_wakeup_event_info wakeup_info, void* user_data)
+{
+ MAS_LOGD("dalton debug : %p", user_data);
+ MAS_LOGD("[SUCCESS] __wakeup_event_cb is called, wakeup_word(%s)", wakeup_info.wakeup_word);
+ int ret = -1;
+
+ CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
+ if (plugin) {
+ CServiceIpcDbus* service_ipc = plugin->get_service_ipc();
+ if (plugin->is_ui_panel_enabled() && service_ipc) {
+ int retry_cnt = 0;
+ while (0 != ret) {
+ ret = service_ipc->masc_ui_dbus_send_hello();
+ retry_cnt++;
+ if (5 < retry_cnt) {
+ MAS_LOGE("[ERROR] Fail to receive reply for hello, ret(%d)", ret);
+ break;
+ }
+ }
+ }
+ }
+
+#ifdef BUF_SAVE_MODE
+ if (mDumpFile) {
+ fclose(mDumpFile);
+ mDumpFile = NULL;
+ } else {
+ MAS_LOGD("[Recorder Info] File not found!");
+ }
+
+ while (1) {
+ snprintf(mDumpFilename, sizeof(mDumpFilename), "/tmp/ma_service_%d_%d", getpid(), mDumpCount);
+ int ret = access(mDumpFilename, 0);
+
+ if (0 == ret) {
+ MAS_LOGD("[Recorder ERROR] File is already exist");
+ if (0 == remove(mDumpFilename)) {
+ MAS_LOGD("[Recorder] Remove file");
+ break;
+ } else {
+ mDumpCount++;
+ }
+ } else {
+ break;
+ }
+ }
+
+ MAS_LOGD("[Recorder] Temp file name=[%s]", mDumpFilename);
+
+ /* open test file */
+ mDumpFile = fopen(mDumpFilename, "wb+x");
+ if (!mDumpFile) {
+ MAS_LOGD("[Recorder ERROR] File not found!");
+ return;
+ }
+ mDumpCount++;
+#endif
+
+#if 0 /* + TEST_CODE */
+ if (WAKEUP_EVENT_SUCCESS == event) {
+ ecore_thread_main_loop_begin();
+ ecore_timer_add(1.0, __send_asr_result, "Today's");
+ ecore_thread_main_loop_end();
+
+ ecore_thread_main_loop_begin();
+ ecore_timer_add(2.0, __send_asr_result, "weather.");
+ ecore_thread_main_loop_end();
+
+ ecore_thread_main_loop_begin();
+ ecore_timer_add(3.0, __send_result, "Partly cloudy with temperatures from 75 to 88");
+ ecore_thread_main_loop_end();
+ }
+#endif /* - TEST_CODE */
+ if (wakeup_info.wakeup_appid) {
+ AsyncParam* param = new(std::nothrow) AsyncParam;
+ if (param) {
++ param->id = ++g_last_wakeup_event_id;
+ param->data = static_cast<void*>(strdup(wakeup_info.wakeup_appid));
+ param->plugin = static_cast<CServicePlugin*>(user_data);
- ecore_thread_main_loop_end();
++ ecore_main_loop_thread_safe_call_async(process_wakeup_event_by_appid_timer,
+ static_cast<void*>(param));
- ecore_thread_main_loop_begin();
- ecore_timer_add(0.0f, process_wakeup_event_by_word_timer,
+ }
+ } else if (wakeup_info.wakeup_word) {
+ AsyncParam* param = new(std::nothrow) AsyncParam;
+ if (param) {
++ param->id = ++g_last_wakeup_event_id;
+ param->data = static_cast<void*>(strdup(wakeup_info.wakeup_word));
+ param->plugin = static_cast<CServicePlugin*>(user_data);
- ecore_thread_main_loop_end();
++ ecore_main_loop_thread_safe_call_async(process_wakeup_event_by_word_timer,
+ static_cast<void*>(param));
+ }
+ }
+}
+
+static bool __validate_streaming_event_order(pid_t pid, mas_speech_streaming_event_e *event)
+{
+ bool ret = false;
+
+ static int previous_pid = -1;
+ static mas_speech_streaming_event_e previous_event = MAS_SPEECH_STREAMING_EVENT_FINISH;
+
+ if (NULL == event) return false;
+
+ mas_speech_streaming_event_e expected_sequence[][2] = {
+ {MAS_SPEECH_STREAMING_EVENT_START, MAS_SPEECH_STREAMING_EVENT_CONTINUE},
+ {MAS_SPEECH_STREAMING_EVENT_START, MAS_SPEECH_STREAMING_EVENT_FINISH},
+ {MAS_SPEECH_STREAMING_EVENT_CONTINUE, MAS_SPEECH_STREAMING_EVENT_CONTINUE},
+ {MAS_SPEECH_STREAMING_EVENT_CONTINUE, MAS_SPEECH_STREAMING_EVENT_FINISH},
+ {MAS_SPEECH_STREAMING_EVENT_FINISH, MAS_SPEECH_STREAMING_EVENT_START},
+ /* If there is no audio data even after the start streaming request */
+ {MAS_SPEECH_STREAMING_EVENT_FINISH, MAS_SPEECH_STREAMING_EVENT_FINISH},
+ };
+
+ if (pid != previous_pid) {
+ /* When sending streaming event to a new client, it always sends START message first */
+ previous_event = MAS_SPEECH_STREAMING_EVENT_FINISH;
+ }
+
+ for (int loop = 0;loop < sizeof(expected_sequence) / sizeof(expected_sequence[0]);loop++) {
+ if (previous_event == expected_sequence[loop][0] &&
+ *event == expected_sequence[loop][1]) {
+ ret = true;
+ }
+ }
+ if (!ret) {
+ /* In case of FINISH -> CONTINUE without START, simply modify current event value */
+ if (MAS_SPEECH_STREAMING_EVENT_FINISH == previous_event &&
+ MAS_SPEECH_STREAMING_EVENT_CONTINUE == *event) {
+ *event = MAS_SPEECH_STREAMING_EVENT_START;
+ ret = true;
+
+ MAS_LOGD("[WARNING] forcibly changed CONTINUE to START : %d -> %d (PID %d -> %d)",
+ previous_event, *event, previous_pid, pid);
+ }
+ }
+
+ if (ret) {
+ previous_pid = pid;
+ previous_event = *event;
+ } else {
+ MAS_LOGE("[ERROR] State sequence validation failed : %d -> %d (PID %d -> %d)",
+ previous_event, *event, previous_pid, pid);
+ }
+ return ret;
+}
+
+void handle_speech_streaming_event_failure(void* data)
+{
+ AsyncParam* param = static_cast<AsyncParam*>(data);
+ if (NULL == param) return;
+
+ CServicePlugin* plugin = param->plugin;
+ CServiceMain* service_main = nullptr;
+ if (plugin) service_main = plugin->get_service_main();
+
+ if (service_main) {
+ service_main->client_send_recognition_result(0, MA_RECOGNITION_RESULT_EVENT_ERROR);
+ }
+
+ delete param;
+}
+
+static void __audio_streaming_cb(mas_speech_streaming_event_e event, void* buffer, int len, void *user_data)
+{
+ if (event == MAS_SPEECH_STREAMING_EVENT_FAIL) {
+ ecore_main_loop_thread_safe_call_async(handle_speech_streaming_event_failure, NULL);
+ return;
+ }
+ static int count = 0;
+ if (event != MAS_SPEECH_STREAMING_EVENT_CONTINUE || count % 100 == 0) {
+ MAS_LOGD("[SUCCESS] __audio_streaming_cb is called, event(%d), buffer(%p), len(%d)",
+ event, buffer, len);
+ }
+ ++count;
+
+ CServicePlugin* plugin = static_cast<CServicePlugin*>(user_data);
+ CServiceIpcDbus* service_ipc = nullptr;
+ CServiceMain* service_main = nullptr;
+ if (plugin) {
+ service_ipc = plugin->get_service_ipc();
+ service_main = plugin->get_service_main();
+ }
+
+ if (service_ipc && service_main) {
+ /* First check if we have dedicated audio processing app for current client */
+ pid_t pid = service_main->get_current_audio_processing_pid();
+ /* If not, send audio data to the main client */
+ if (-1 == pid) pid = service_main->get_current_client_pid();
+
+ int preprocessing_pid = service_main->get_current_preprocessing_client_pid();
+ if (pid == -1) {
+ MAS_LOGE("[ERROR] Fail to retrieve pid of current MA client");
+ } else {
+ if (__validate_streaming_event_order(pid, &event)) {
+ int ret = service_ipc->send_streaming_audio_data(pid,
+ event, buffer, len);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to send speech data, ret(%d)", ret);
+ }
+ if (pid != preprocessing_pid && -1 != preprocessing_pid) {
+ int ret = service_ipc->send_streaming_audio_data(preprocessing_pid,
+ event, buffer, len);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to send speech data to preprocessing client, ret(%d)", ret);
+ }
+ }
+ }
+ }
+ }
+#ifdef BUF_SAVE_MODE
+ if (mDumpFile)
+ fwrite(speech_data->buffer, 1, speech_data->len, mDumpFile);
+
+ if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) {
+ if (mDumpFile) {
+ MAS_LOGE("[Recorder SUCCESS] File Close");
+ fclose(mDumpFile);
+ mDumpFile = NULL;
+ } else {
+ MAS_LOGE("[Recorder ERROR] File not found!");
+ }
+ }
+#endif
+}
+
+static void __speech_status_cb(mas_speech_status_e status, void *user_data)
+{
+ MAS_LOGD("[SUCCESS] __speech_status_cb is called, status(%d)", status);
+}
+
+static void __error_cb(int error, const char* err_msg, void* user_data)
+{
+ MAS_LOGD("[SUCCESS] __error_cb is called, error(%d), err_msg(%s)", error, err_msg);
+
+ CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
+ if (nullptr == plugin) return;
+
+ CServiceIpcDbus* service_ipc = plugin->get_service_ipc();
+ if (plugin->is_ui_panel_enabled() && service_ipc) {
+ int ret = service_ipc->masc_ui_dbus_send_error_message(error, err_msg);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to send error message, ret(%d)", ret);
+ }
+ }
+}
+
+static void __setting_changed_cb(void *user_data)
+{
+ CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
+ if (nullptr == plugin) return;
+
+ CServiceMain* service_main = plugin->get_service_main();
+ if (service_main) {
+ service_main->prelaunch_default_assistant();
+ service_main->update_voice_key_support_mode();
+ }
+ MAS_LOGD("[SUCCESS] __setting_changed_cb is called");
+}
+
+static void __streaming_section_changed_cb(ma_audio_streaming_data_section_e section, void* user_data)
+{
+ MAS_LOGD("[SUCCESS] __streaming_section_changed_cb is called, section(%d)", section);
+
+ CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
+ if (nullptr == plugin) return;
+
+ CServiceIpcDbus *service_ipc = plugin->get_service_ipc();
+ CServiceMain* service_main = plugin->get_service_main();
+ if (service_ipc && service_main) {
+ pid_t pid = service_main->get_current_client_pid();
+ int ret = service_ipc->send_streaming_section_changed(pid, (int)section);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to send streaming section changed information, ret(%d)", ret);
+ }
+ }
+}
+
+static void __wakeup_engine_command_cb(mas_wakeup_engine_command_target_e target, const char* assistant_name, const char* command, void* user_data)
+{
+ MAS_LOGD("[SUCCESS] __wakeup_engine_command_cb is called, command(%s)", command);
+
+ CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
+ if (nullptr == plugin) return;
+
+ CServiceIpcDbus *service_ipc = plugin->get_service_ipc();
+ CServiceMain* service_main = plugin->get_service_main();
+ if (service_ipc && service_main) {
+ pid_t pid = service_main->get_client_pid_by_appid(assistant_name);
+ if (-1 != pid) {
+ int ret = service_ipc->send_wakeup_engine_command(pid, command);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to send wakeup engine command, ret(%d)", ret);
+ }
+ }
+ }
+}
+
+static void __wakeup_service_state_changed_cb(ma_service_state_e state, void* user_data)
+{
+ MAS_LOGD("[SUCCESS] __wakeup_service_state_changed_cb is called, state(%d)", state);
+
+ CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
+ if (nullptr == plugin) return;
+
+ CServiceMain* service_main = plugin->get_service_main();
+ if (service_main) {
+ service_main->set_current_service_state(state);
+ }
+}
+
+static void __wakeup_service_voice_key_status_changed_cb(ma_voice_key_status_e status, void* user_data)
+{
+ MAS_LOGD("[SUCCESS] __wakeup_service_voice_key_status_changed_cb is called, state(%d)", status);
+
+ CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
+ if (nullptr == plugin) return;
+
+ CServiceIpcDbus *service_ipc = plugin->get_service_ipc();
+ CServiceMain* service_main = plugin->get_service_main();
+ if (service_ipc && service_main) {
+ pid_t pid = service_main->get_current_client_pid();
+ int ret = service_ipc->change_voice_key_status(pid, status);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to send voice key status changed information, ret(%d)", ret);
+ }
+ }
+}
+
+int CServicePlugin::initialize(void)
+{
+ MAS_LOGD("[Enter]");
+
+ char filepath[512] = {'\0', };
+ const char *default_engine_path = MA_WAKEUP_MANAGER_PATH;
+ snprintf(filepath, 512, "%s/%s", default_engine_path, MA_DEFAULT_WAKEUP_MANAGER_FILENAME);
+
+ char *error;
+ mPluginHandle = nullptr;
+ mPluginHandle = dlopen(filepath, RTLD_LAZY);
+ if (nullptr != (error = dlerror())) {
+ MAS_LOGE("[ERROR] Fail to dlopen(%s), error(%s)", filepath, error);
+ if (mPluginHandle) dlclose(mPluginHandle);
+ mPluginHandle = nullptr;
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+ if (nullptr == mPluginHandle) {
+ MAS_LOGE("[ERROR] Fail to dlopen(%s), error(%s)", filepath, error);
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+
+ mWakeupManagerInterface.initialize =
+ (wakeup_manager_initialize)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_INITIALIZE);
+ mWakeupManagerInterface.deinitialize =
+ (wakeup_manager_deinitialize)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE);
+ mWakeupManagerInterface.get_settings =
+ (wakeup_manager_get_settings)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
+ mWakeupManagerInterface.add_assistant_wakeup_word =
+ (wakeup_manager_add_assistant_wakeup_word)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD);
+ mWakeupManagerInterface.remove_assistant_wakeup_word =
+ (wakeup_manager_remove_assistant_wakeup_word)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD);
+ mWakeupManagerInterface.add_assistant_language =
+ (wakeup_manager_add_assistant_language)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE);
+ mWakeupManagerInterface.set_assistant_wakeup_engine =
+ (wakeup_manager_set_assistant_wakeup_engine)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE);
+ mWakeupManagerInterface.set_default_assistant =
+ (wakeup_manager_set_default_assistant)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT);
+ mWakeupManagerInterface.get_default_assistant =
+ (wakeup_manager_get_default_assistant)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT);
+ mWakeupManagerInterface.set_language =
+ (wakeup_manager_set_language)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE);
+ mWakeupManagerInterface.activate =
+ (wakeup_manager_activate)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_ACTIVATE);
+ mWakeupManagerInterface.deactivate =
+ (wakeup_manager_deactivate)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_DEACTIVATE);
+ mWakeupManagerInterface.update_voice_feedback_state =
+ (wakeup_manager_update_voice_feedback_state)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE);
+ mWakeupManagerInterface.set_assistant_specific_command =
+ (wakeup_manager_set_assistant_specific_command)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND);
+ mWakeupManagerInterface.set_background_volume =
+ (wakeup_manager_set_background_volume)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME);
+ mWakeupManagerInterface.update_recognition_result =
+ (wakeup_manager_update_recognition_result)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT);
+ mWakeupManagerInterface.process_plugin_event =
+ (wakeup_manager_process_plugin_event)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT);
+ mWakeupManagerInterface.start_streaming_utterance_data =
+ (wakeup_manager_start_streaming_utterance_data)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA);
+ mWakeupManagerInterface.stop_streaming_utterance_data =
+ (wakeup_manager_stop_streaming_utterance_data)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA);
+ mWakeupManagerInterface.start_streaming_previous_utterance_data =
+ (wakeup_manager_start_streaming_previous_utterance_data)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA);
+ mWakeupManagerInterface.stop_streaming_previous_utterance_data =
+ (wakeup_manager_stop_streaming_previous_utterance_data)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA);
+ mWakeupManagerInterface.start_streaming_follow_up_data =
+ (wakeup_manager_start_streaming_follow_up_data)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA);
+ mWakeupManagerInterface.stop_streaming_follow_up_data =
+ (wakeup_manager_stop_streaming_follow_up_data)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA);
+ mWakeupManagerInterface.get_audio_format =
+ (wakeup_manager_get_audio_format)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT);
+ mWakeupManagerInterface.get_audio_source_type =
+ (wakeup_manager_get_audio_source_type)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE);
+ mWakeupManagerInterface.set_wake_word_audio_require_flag =
+ (wakeup_manager_set_wake_word_audio_require_flag)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG);
+ mWakeupManagerInterface.set_assistant_language =
+ (wakeup_manager_set_assistant_language)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_LANGUAGE);
+ mWakeupManagerInterface.set_voice_key_tap_duration =
+ (wakeup_manager_set_voice_key_tap_duration)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_TAP_DURATION);
+ mWakeupManagerInterface.unset_voice_key_tap_duration =
+ (wakeup_manager_unset_voice_key_tap_duration)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_UNSET_VOICE_KEY_TAP_DURATION);
+ mWakeupManagerInterface.set_voice_key_support_mode =
+ (wakeup_manager_set_voice_key_support_mode)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_SUPPORT_MODE);
+ mWakeupManagerInterface.set_wakeup_event_callback =
+ (wakeup_manager_set_wakeup_event_callback)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK);
+ mWakeupManagerInterface.set_utterance_streaming_callback =
+ (wakeup_manager_set_utterance_streaming_callback)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK);
+ mWakeupManagerInterface.set_previous_utterance_streaming_callback =
+ (wakeup_manager_set_previous_utterance_streaming_callback)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK);
+ mWakeupManagerInterface.set_follow_up_streaming_callback =
+ (wakeup_manager_set_follow_up_streaming_callback)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK);
+ mWakeupManagerInterface.set_speech_status_callback =
+ (wakeup_manager_set_speech_status_callback)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK);
+ mWakeupManagerInterface.set_setting_changed_callback =
+ (wakeup_manager_set_setting_changed_callback)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK);
+ mWakeupManagerInterface.set_error_callback =
+ (wakeup_manager_set_error_callback)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK);
+ mWakeupManagerInterface.set_streaming_section_changed_callback =
+ (wakeup_manager_set_streaming_section_changed_callback)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK);
+ mWakeupManagerInterface.set_wakeup_engine_command_callback =
+ (wakeup_manager_set_wakeup_engine_command_callback)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK);
+ mWakeupManagerInterface.set_wakeup_service_state_changed_callback =
+ (wakeup_manager_set_wakeup_service_state_changed_callback)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK);
+ mWakeupManagerInterface.set_voice_key_status_changed_callback =
+ (wakeup_manager_set_voice_key_status_changed_callback)dlsym(mPluginHandle,
+ MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_STATUS_CHANGED_CALLBACK);
+
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_initialize func = mWakeupManagerInterface.initialize;
+
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_INITIALIZE);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to initialize, ret(%d)", ret);
+ }
+ }
+
+ wakeup_manager_get_settings get_settings_func = mWakeupManagerInterface.get_settings;
+
+ if (NULL == get_settings_func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
+ } else {
+ size_t struct_size;
+ ret = get_settings_func(&mPluginSettings, &struct_size);
+ if (0 != ret || struct_size != sizeof(ma_plugin_settings)) {
+ MAS_LOGE("[ERROR] Fail to get settings, ret(%d), size %zu", ret, struct_size);
+ mPluginSettings = NULL;
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::deinitialize(void)
+{
+#ifdef BUF_SAVE_MODE
+ if (mDumpFile) {
+ fclose(mDumpFile);
+ mDumpFile = NULL;
+ } else {
+ MAS_LOGD("[Recorder ERROR] File not found!");
+ }
+#endif
+
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_deinitialize func = mWakeupManagerInterface.deinitialize;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to deinitialize, ret(%d)", ret);
+ }
+ }
+
+ dlclose(mPluginHandle);
+ mPluginHandle = NULL;
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+
+ return ret;
+}
+
+int CServicePlugin::get_settings(ma_plugin_settings **settings, size_t *struct_size)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_get_settings func = mWakeupManagerInterface.get_settings;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
+ } else {
+ ret = func(settings, struct_size);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to get settings, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_language(const char* language)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_language func = mWakeupManagerInterface.set_language;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE);
+ } else {
+ ret = func(language);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set langauge(%s), ret(%d)", language, ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_add_assistant_wakeup_word func = mWakeupManagerInterface.add_assistant_wakeup_word;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD);
+ } else {
+ ret = func(appid, wakeup_word, language);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to add wakeup word(%s)(%s)(%s), ret(%d)", appid, wakeup_word, language, ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::remove_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_remove_assistant_wakeup_word func = mWakeupManagerInterface.remove_assistant_wakeup_word;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD);
+ } else {
+ ret = func(appid, wakeup_word, language);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to remove wakeup word(%s)(%s)(%s), ret(%d)", appid, wakeup_word, language, ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::add_assistant_language(const char* appid, const char* language)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_add_assistant_language func = mWakeupManagerInterface.add_assistant_language;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE);
+ } else {
+ ret = func(appid, language);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%s), ret(%d)", appid, language, ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_assistant_wakeup_engine(const char* appid, const char* engine)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_assistant_wakeup_engine func = mWakeupManagerInterface.set_assistant_wakeup_engine;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE);
+ } else {
+ ret = func(appid, engine);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set wakeup engine(%s)(%s), ret(%d)", appid, engine, ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_default_assistant(const char* appid)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_default_assistant func = mWakeupManagerInterface.set_default_assistant;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT);
+ } else {
+ ret = func(appid);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set default assistant(%s), ret(%d)", appid, ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::get_default_assistant(const char** appid)
+{
+ int ret = -1;
+ if (NULL == appid) {
+ MAS_LOGE("[ERROR] appid is not valid");
+ return ret;
+ }
+ if (NULL != mPluginHandle) {
+ wakeup_manager_get_default_assistant func = mWakeupManagerInterface.get_default_assistant;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT);
+ } else {
+ ret = func(appid);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to get default assistant, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::activate(void)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_activate func = mWakeupManagerInterface.activate;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ACTIVATE);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to start recording, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::deactivate(void)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_deactivate func = mWakeupManagerInterface.deactivate;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEACTIVATE);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::update_voice_feedback_state(const char* appid, int state)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_update_voice_feedback_state func = mWakeupManagerInterface.update_voice_feedback_state;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE);
+ } else {
+ ret = func(appid, state);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_assistant_specific_command(const char* appid, const char* command)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_assistant_specific_command func = mWakeupManagerInterface.set_assistant_specific_command;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND);
+ } else {
+ ret = func(appid, command);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_background_volume(const char* appid, double ratio)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_background_volume func = mWakeupManagerInterface.set_background_volume;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME);
+ } else {
+ ret = func(appid, ratio);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set background volume, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::update_recognition_result(const char* appid, int state)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_update_recognition_result func = mWakeupManagerInterface.update_recognition_result;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT);
+ } else {
+ ret = func(appid, state);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to update result state, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::process_event(int event, void *data, int len)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_process_plugin_event func = mWakeupManagerInterface.process_plugin_event;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT);
+ } else {
+ ret = func((mas_plugin_event_e)event, data, len);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::start_streaming_utterance_data(void)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_start_streaming_utterance_data func = mWakeupManagerInterface.start_streaming_utterance_data;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::stop_streaming_utterance_data(void)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_stop_streaming_utterance_data func = mWakeupManagerInterface.stop_streaming_utterance_data;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::start_streaming_previous_utterance_data(void)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_start_streaming_previous_utterance_data func = mWakeupManagerInterface.start_streaming_previous_utterance_data;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to request previous speech data, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::stop_streaming_previous_utterance_data(void)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_stop_streaming_previous_utterance_data func = mWakeupManagerInterface.stop_streaming_previous_utterance_data;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to request previous speech data, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::start_streaming_follow_up_data(void)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_start_streaming_follow_up_data func = mWakeupManagerInterface.start_streaming_follow_up_data;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::stop_streaming_follow_up_data(void)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_stop_streaming_follow_up_data func = mWakeupManagerInterface.stop_streaming_follow_up_data;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::get_recording_audio_format(int *rate, int *channel, int *audio_type)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_get_audio_format func = mWakeupManagerInterface.get_audio_format;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT);
+ } else {
+ ret = func(rate, channel, audio_type);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to get recording audio format, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::get_recording_audio_source_type(char** type)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_get_audio_source_type func = mWakeupManagerInterface.get_audio_source_type;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE);
+ } else {
+ ret = func(type);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to get recording audio source type, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_voice_key_tap_duration(float duration)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_voice_key_tap_duration func = mWakeupManagerInterface.set_voice_key_tap_duration;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_TAP_DURATION);
+ } else {
+ ret = func(duration);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set voice key tap duration, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::unset_voice_key_tap_duration()
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_unset_voice_key_tap_duration func = mWakeupManagerInterface.unset_voice_key_tap_duration;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UNSET_VOICE_KEY_TAP_DURATION);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to unset voice key tap duration, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_voice_key_support_mode(int mode)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_voice_key_support_mode func = mWakeupManagerInterface.set_voice_key_support_mode;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_SUPPORT_MODE);
+ } else {
+ ret = func(mode);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set voice key support mode, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_wake_word_audio_require_flag(const char* appid, bool require)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_wake_word_audio_require_flag func = mWakeupManagerInterface.set_wake_word_audio_require_flag;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG);
+ } else {
+ ret = func(require);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set wake word audio require flag, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_assistant_language(const char* appid, const char* language)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_assistant_language func = mWakeupManagerInterface.set_assistant_language;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_LANGUAGE);
+ } else {
+ ret = func(appid, language);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set assistant language, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_callbacks(void)
+{
+ int ret = set_wakeup_event_callback(__wakeup_event_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set wakeup event cb");
+ return ret;
+ }
+
+ ret = set_utterance_streaming_callback(__audio_streaming_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set utterance streaming cb");
+ return ret;
+ }
+
+ ret = set_previous_utterance_streaming_callback(__audio_streaming_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set previous utterance streaming cb");
+ return ret;
+ }
+
+ ret = set_follow_up_streaming_callback(__audio_streaming_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set follow-up streaming cb");
+ return ret;
+ }
+
+ ret = set_speech_status_callback(__speech_status_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set speech status changed cb");
+ return ret;
+ }
+
+ ret = set_setting_changed_callback(__setting_changed_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set setting changed cb");
+ return ret;
+ }
+
+ ret = set_error_callback(__error_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set error cb");
+ return ret;
+ }
+
+ ret = set_streaming_section_changed_callback(__streaming_section_changed_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set streaming section changed cb");
+ return ret;
+ }
+
+ ret = set_wakeup_engine_command_callback(__wakeup_engine_command_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set wakeup engine command cb");
+ return ret;
+ }
+
+ ret = set_wakeup_service_state_changed_callback(__wakeup_service_state_changed_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set wakeup engine command cb");
+ return ret;
+ }
+
+ ret = set_voice_key_status_changed_callback(__wakeup_service_voice_key_status_changed_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set wakeup engine command cb");
+ return ret;
+ }
+
+ return 0;
+}
+
+int CServicePlugin::set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_wakeup_event_callback func = mWakeupManagerInterface.set_wakeup_event_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ MAS_LOGD("dalton debug : %p", user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set wakeup event callback, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_utterance_streaming_callback func = mWakeupManagerInterface.set_utterance_streaming_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set utterance streaming callback, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_previous_utterance_streaming_callback func = mWakeupManagerInterface.set_previous_utterance_streaming_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set utterance streaming callback, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_follow_up_streaming_callback func = mWakeupManagerInterface.set_follow_up_streaming_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set follow-up streaming callback, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] mPluginHandle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_speech_status_callback func = mWakeupManagerInterface.set_speech_status_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set speech status callback, ret(%d)", ret);
+ }
+ }
+ }
+ return ret;
+}
+
+int CServicePlugin::set_setting_changed_callback(wakeup_service_setting_changed_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_setting_changed_callback func = mWakeupManagerInterface.set_setting_changed_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set setting_changed callback, ret(%d)", ret);
+ }
+ }
+ }
+ return ret;
+}
+
+int CServicePlugin::set_error_callback(wakeup_service_error_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_error_callback func = mWakeupManagerInterface.set_error_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
+ }
+ }
+ }
+ return ret;
+}
+
+int CServicePlugin::set_streaming_section_changed_callback(wakeup_service_streaming_section_changed_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_streaming_section_changed_callback func = mWakeupManagerInterface.set_streaming_section_changed_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set streaming section changed callback, ret(%d)", ret);
+ }
+ }
+ }
+ return ret;
+}
+
+int CServicePlugin::set_wakeup_engine_command_callback(wakeup_service_wakeup_engine_command_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_wakeup_engine_command_callback func = mWakeupManagerInterface.set_wakeup_engine_command_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
+ }
+ }
+ }
+ return ret;
+}
+
+int CServicePlugin::set_wakeup_service_state_changed_callback(wakeup_service_wakeup_service_state_changed_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_wakeup_service_state_changed_callback func = mWakeupManagerInterface.set_wakeup_service_state_changed_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
+ }
+ }
+ }
+ return ret;
+}
+
+int CServicePlugin::set_voice_key_status_changed_callback(wakeup_service_voice_key_status_changed_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != mPluginHandle) {
+ wakeup_manager_set_voice_key_status_changed_callback func = mWakeupManagerInterface.set_voice_key_status_changed_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_STATUS_CHANGED_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
+ }
+ }
+ }
+ return ret;
+}
+