MA_AUDIO_STREAMING_DATA_SECTION_WAKE_WORD, /**< Wake word section started */
} ma_audio_streaming_data_section_e;
+typedef enum {
+ WAKEUP_ENGINE_COMMAND_TARGET_ALL_ASSISTANTS = 0, /**< All assistants - name not required */
+ WAKEUP_ENGINE_COMMAND_TARGET_SPECIFIC_ASSISTANTS, /**< Specific assistant - name required */
+ WAKEUP_ENGINE_COMMAND_TARGET_DEPENDENCY_MODULE, /**< Dependency module - name not required */
+} wakeup_engine_command_target_e;
+
typedef void (*ma_audio_streaming_data_section_changed_cb)(ma_audio_streaming_data_section_e section, void* user_data);
typedef void (*wakeup_service_wakeup_event_cb)(wakeup_event_info wakeup_info, const char* wakeup_word, void* user_data);
typedef void (*wakeup_service_streaming_section_changed_cb)(ma_audio_streaming_data_section_e section, void* user_data);
-typedef void (*wakeup_service_wakeup_engine_command_cb)(const char* assistant_name, const char* command, void* user_data);
+typedef void (*wakeup_service_wakeup_engine_command_cb)(wakeup_engine_command_target_e target, const char* assistant_name, const char* command, void* user_data);
#ifdef __cplusplus
}
EXPORT_API int mas_dependency_set_background_volume(double ratio);
EXPORT_API int mas_dependency_get_audio_format(int* rate, int* channel, int* audio_type);
EXPORT_API int mas_dependency_get_audio_source_type(char** type);
+EXPORT_API int mas_dependency_process_wakeup_engine_command(const char* engine_name, const char* command);
#ifdef __cplusplus
}
dependency_default_audio_get_audio_source_type(type);
return 0;
}
+
+int mas_dependency_process_wakeup_engine_command(const char* engine_name, const char* command)
+{
+ LOGD("Wakeup Engine %s has sent a command : %s", engine_name, command);
+ return 0;
+}
\ No newline at end of file
int dependency_resolver_set_background_volume(double ratio);
int dependency_resolver_get_audio_format(int* rate, int* channel, int* audio_type);
int dependency_resolver_get_audio_source_type(char** type);
+int dependency_resolver_process_wakeup_engine_command(const char* engine, const char* command);
/**************************************************************************************
*** Definitions for dependencies
typedef int (*mas_dependency_get_audio_format)(int* rate, int* channel, int* audio_type);
#define MAS_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE "mas_dependency_get_audio_source_type"
typedef int (*mas_dependency_get_audio_source_type)(char** type);
+#define MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND "mas_dependency_process_wakeup_engine_command"
+typedef int (*mas_dependency_process_wakeup_engine_command)(const char* engine_name, const char* command);
typedef struct {
mas_dependency_initialize initialize;
mas_dependency_set_background_volume set_background_volume;
mas_dependency_get_audio_format get_audio_format;
mas_dependency_get_audio_source_type get_audio_source_type;
+ mas_dependency_process_wakeup_engine_command process_wakeup_engine_command;
} mas_dependency;
#ifdef __cplusplus
virtual bool on_streaming_audio_data(
wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) = 0;
virtual bool on_audio_streaming_data_section(ma_audio_streaming_data_section_e section) = 0;
- virtual bool on_wakeup_engine_command(string assistant_name, string command) = 0;
+ virtual bool on_wakeup_engine_command(
+ wakeup_engine_command_target_e target, string engine_name, string assistant_name, string command) = 0;
};
class CWakeupEngineManager
bool on_speech_status(string engine_name, wakeup_service_speech_status_e status);
bool on_error(string engine_name, int error_code, string error_message);
bool on_audio_data_require_status(string engine_name, bool require);
- bool on_wakeup_engine_command(string engine_name, string assistant_name, string command);
+ bool on_wakeup_engine_command(string engine_name,
+ wakeup_engine_command_target_e target, string assistant_name, string command);
private:
typedef struct {
int version;
virtual void on_streaming_audio_data(
wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) = 0;
virtual void on_audio_streaming_data_section(ma_audio_streaming_data_section_e section) = 0;
- virtual void on_wakeup_engine_command(const char* assistant_name, const char* command) = 0;
+ virtual void on_wakeup_engine_command(
+ wakeup_engine_command_target_e target, const char* name, const char* command) = 0;
};
class ISettingValueObserver {
bool on_streaming_audio_data(
wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) override;
bool on_audio_streaming_data_section(ma_audio_streaming_data_section_e section) override;
- bool on_wakeup_engine_command(string assistant_name, string command) override;
+ bool on_wakeup_engine_command(
+ wakeup_engine_command_target_e target, string engine, string name, string command) override;
void set_wakeup_manager(CWakeupManager *manager) { mWakeupManager = manager; }
private:
MA_AUDIO_STREAMING_DATA_SECTION_WAKE_WORD, /**< Wake word section started */
} ma_audio_streaming_data_section_e;
+typedef enum {
+ WAKEUP_ENGINE_COMMAND_TARGET_ALL_ASSISTANTS = 0, /**< All assistants - name not required */
+ WAKEUP_ENGINE_COMMAND_TARGET_SPECIFIC_ASSISTANT, /**< Specific assistant - name required */
+ WAKEUP_ENGINE_COMMAND_TARGET_DEPENDENCY_MODULE, /**< Dependency module - name not required */
+} wakeup_engine_command_target_e;
+
typedef void (*ma_audio_streaming_data_section_changed_cb)(ma_audio_streaming_data_section_e section, void* user_data);
typedef void (*wakeup_service_wakeup_event_cb)(wakeup_event_info wakeup_info, void* user_data);
typedef void (*wakeup_service_streaming_section_changed_cb)(ma_audio_streaming_data_section_e section, void* user_data);
-typedef void (*wakeup_service_engine_command_cb)(const char* assistant_name, const char* command, void* user_data);
+typedef void (*wakeup_service_engine_command_cb)(wakeup_engine_command_target_e target, const char* assistant_name, const char* command, void* user_data);
typedef enum {
MA_PLUGIN_EVENT_VOICE_KEY_PRESSED = 0,
g_mas_dependency.get_audio_source_type =
(mas_dependency_get_audio_source_type)dlsym(g_handle,
MAS_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE);
+ g_mas_dependency.process_wakeup_engine_command =
+ (mas_dependency_process_wakeup_engine_command)dlsym(g_handle,
+ MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND);
int ret = -1;
int dependency_version = 0;
return ret;
}
+
+int dependency_resolver_process_wakeup_engine_command(const char* engine, const char* command)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ mas_dependency_process_wakeup_engine_command func = g_mas_dependency.process_wakeup_engine_command;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND);
+ } else {
+ try {
+ ret = func(engine, command);
+ } catch (const std::exception& e) {
+ MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+ MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND, e.what());
+ }
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to process wakeup engine command, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+
+ return ret;
+}
return true;
}
-bool CWakeupEngineManager::on_wakeup_engine_command(string engine_name, string assistant_name, string command)
+bool CWakeupEngineManager::on_wakeup_engine_command(string engine_name, wakeup_engine_command_target_e target, string assistant_name, string command)
{
MWR_LOGD("[ENTER]");
for (const auto& observer : mObservers) {
if (observer) {
- const auto& iter = find_if(mEngineInfo.begin(), mEngineInfo.end(),
- [engine_name](const EngineInfo& info) {
- return (0 == info.engine_name.compare(engine_name));
- });
- if (mEngineInfo.end() != iter) {
- for (const auto& assistant : iter->assistant_list) {
- if (0 == assistant_name.compare(assistant) || 0 == assistant_name.length())
- if (!observer->on_wakeup_engine_command(assistant, command)) {
- LOGE("[Recorder WARNING] One of the observer returned false");
+ if (WAKEUP_ENGINE_COMMAND_TARGET_DEPENDENCY_MODULE == target) {
+ if (!observer->on_wakeup_engine_command(target, engine_name, assistant_name, command)) {
+ LOGE("[Recorder WARNING] One of the observer returned false");
+ }
+ } else {
+ const auto& iter = find_if(mEngineInfo.begin(), mEngineInfo.end(),
+ [engine_name](const EngineInfo& info) {
+ return (0 == info.engine_name.compare(engine_name));
+ });
+ if (mEngineInfo.end() != iter) {
+ for (const auto& assistant : iter->assistant_list) {
+ if (0 == assistant_name.compare(assistant) ||
+ WAKEUP_ENGINE_COMMAND_TARGET_ALL_ASSISTANTS == target) {
+ if (!observer->on_wakeup_engine_command(target, engine_name, assistant, command)) {
+ LOGE("[Recorder WARNING] One of the observer returned false");
+ }
+ }
}
}
}
if (info.interface.set_wakeup_engine_command_callback) {
info.interface.set_wakeup_engine_command_callback(
- [](const char* assistant_name, const char* command, void* user_data) {
+ [](wakeup_engine_command_target_e target,
+ const char* assistant_name, const char* command, void* user_data) {
CallbackUserData* data = static_cast<CallbackUserData*>(user_data);
if (nullptr == data) return;
if (nullptr == data->manager) return;
if (nullptr == command) return;
data->manager->on_wakeup_engine_command(
- data->engine_name, (assistant_name ? assistant_name : ""), command);
+ data->engine_name, target, (assistant_name ? assistant_name : ""), command);
}, &(callback_user_data.back()));
}
}
bool CWakeupManager::CEngineEventObserver::on_wakeup_engine_command(
- string assistant_name, string command)
+ wakeup_engine_command_target_e target, string engine_name, string assistant_name, string command)
{
if (nullptr == mWakeupManager) return false;
- vector<IWakeupEventObserver*> observers = mWakeupManager->get_wakeup_observers();
- for (const auto& observer : observers) {
- observer->on_wakeup_engine_command(assistant_name.c_str(), command.c_str());
+ if (WAKEUP_ENGINE_COMMAND_TARGET_DEPENDENCY_MODULE == target) {
+ dependency_resolver_process_wakeup_engine_command(engine_name.c_str(), command.c_str());
+ }
+
+ if (WAKEUP_ENGINE_COMMAND_TARGET_ALL_ASSISTANTS == target ||
+ WAKEUP_ENGINE_COMMAND_TARGET_SPECIFIC_ASSISTANT == target) {
+ vector<IWakeupEventObserver*> observers = mWakeupManager->get_wakeup_observers();
+ for (const auto& observer : observers) {
+ observer->on_wakeup_engine_command(target, assistant_name.c_str(), command.c_str());
+ }
}
return true;
void on_streaming_audio_data(
wakeup_speech_streaming_event_e event, void* buffer, unsigned int len) override;
void on_audio_streaming_data_section(ma_audio_streaming_data_section_e section) override;
- void on_wakeup_engine_command(const char* assistant_name, const char* command) override;
+ void on_wakeup_engine_command(
+ wakeup_engine_command_target_e target, const char* assistant_name, const char* command) override;
};
class CSettingValueObserver : public ISettingValueObserver
}
void CWakeupEventObserver::on_wakeup_engine_command(
- const char* assistant_name, const char* command)
+ wakeup_engine_command_target_e target, const char* assistant_name, const char* command)
{
if (g_wakeup_engine_command_cb) {
- g_wakeup_engine_command_cb(assistant_name, command, g_wakeup_engine_command_user_data);
+ g_wakeup_engine_command_cb(target, assistant_name, command, g_wakeup_engine_command_user_data);
}
}
}
}
-static void __wakeup_engine_command_cb(const char* assistant_name, const char* command, void* user_data)
+static void __wakeup_engine_command_cb(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);