Add the new API for sending wakeup_word 24/276324/3
authorInHong Han <inhong1.han@samsung.com>
Fri, 13 May 2022 00:51:53 +0000 (09:51 +0900)
committerInHong Han <inhong1.han@samsung.com>
Thu, 16 Jun 2022 08:37:17 +0000 (17:37 +0900)
Change-Id: I9de33d07424b28939df7888e058f927161874e34

client/ma.c
client/ma_dbus.c
include/multi_assistant.h

index ab7c6125991be43967e845967098db4b7d2dee2d..85046fe15154f4d9e664d70d76bd4ee8b344a05f 100644 (file)
@@ -57,6 +57,19 @@ static int g_recorder_privilege_allowed = -1;
 static int g_volume_set_privilege_allowed = -1;
 static cynara *p_cynara = NULL;
 
+#define MAX_WAKE_WORD_LENGTH 20
+#define MAX_EXTRA_DATA_SIZE 1024
+#define MAX_EXTRA_DATA_DESC_LENGTH 1024
+
+typedef struct {
+       char wake_word[MAX_WAKE_WORD_LENGTH];
+       unsigned char extra_data[MAX_EXTRA_DATA_SIZE];
+       int extra_data_length;
+       char extra_data_desc[MAX_EXTRA_DATA_DESC_LENGTH];
+} wakeup_info_t;
+
+static wakeup_info_t g_wakeup_info;
+
 static void __ma_notify_state_changed(void* data);
 static void __ma_notify_error(void* data);
 
@@ -557,12 +570,32 @@ static void __ma_notify_state_changed(void * data)
 }
 
 //LCOV_EXCL_START
-int __ma_cb_active_state_changed(int state)
+int __ma_cb_active_state_changed(int state, const char* wakeup_word,
+       const unsigned char* extra_data, int extra_data_length, const char* extra_data_desc)
 {
-       ma_active_state_changed_cb callback = NULL;
-       void* user_data;
+       if (wakeup_word) strncpy(g_wakeup_info.wake_word, wakeup_word, MAX_WAKE_WORD_LENGTH);
+       else g_wakeup_info.wake_word[0] = '\0';
+       g_wakeup_info.wake_word[MAX_WAKE_WORD_LENGTH - 1] = '\0';
+
+       if (extra_data && extra_data_length > 0 && extra_data_length <= MAX_EXTRA_DATA_SIZE) {
+               memcpy(g_wakeup_info.extra_data, extra_data, extra_data_length);
+               g_wakeup_info.extra_data_length = extra_data_length;
+       } else {
+               memset(g_wakeup_info.extra_data, 0x00, MAX_EXTRA_DATA_SIZE);
+               g_wakeup_info.extra_data_length = 0;
+       }
+
+       if (extra_data_desc) strncpy(g_wakeup_info.extra_data_desc, extra_data_desc, MAX_EXTRA_DATA_DESC_LENGTH);
+       else g_wakeup_info.extra_data_desc[0] = '\0';
+       g_wakeup_info.extra_data_desc[MAX_EXTRA_DATA_DESC_LENGTH - 1] = '\0';
 
-       ma_client_get_active_state_changed_cb(g_ma, &callback, &user_data);
+       MA_SLOGD("%s %p %d %s", g_wakeup_info.wake_word,
+               g_wakeup_info.extra_data, g_wakeup_info.extra_data_length, g_wakeup_info.extra_data_desc);
+
+       ma_active_state_changed_cb active_state_callback = NULL;
+       void* active_state_user_data;
+
+       ma_client_get_active_state_changed_cb(g_ma, &active_state_callback, &active_state_user_data);
 
        ma_active_state_e current_state;
        ma_active_state_e previous_state;
@@ -572,9 +605,9 @@ int __ma_cb_active_state_changed(int state)
        current_state = (ma_active_state_e)state;
        ma_client_set_client_active_state(g_ma, current_state);
 
-       if (NULL != callback) {
+       if (NULL != active_state_callback) {
                ma_client_use_callback(g_ma);
-               callback(previous_state, current_state, user_data);
+               active_state_callback(previous_state, current_state, active_state_user_data);
                ma_client_not_use_callback(g_ma);
                MA_SLOGD("[DEBUG] Active state changed callback is called %d", current_state); //LCOV_EXCL_LINE
        } else {
@@ -583,8 +616,8 @@ int __ma_cb_active_state_changed(int state)
 
        ma_client_get_previous_active_state(g_ma, &current_state, &previous_state);
        MA_SLOGD(
-               "[INFO] previous : %d , current : %d active state changed",
-               previous_state, current_state
+               "[INFO] previous : %d , current : %d , wakeup_word : %s active state changed",
+               previous_state, current_state, wakeup_word
        );
        if (MA_ACTIVE_STATE_ACTIVE == state) {
                ma_start_receiving_audio_streaming_data(MA_AUDIO_STREAMING_DATA_TYPE_CURRENT_UTTERANCE);
@@ -2423,3 +2456,29 @@ int ma_remove_wake_word(const char* wake_word, const char *language) {
        }
        return ret;
 }
+
+int ma_get_wakeup_info_wake_word(char** wake_word)
+{
+       if (wake_word) {
+               *wake_word = g_wakeup_info.wake_word;
+       }
+       return 0;
+}
+
+int ma_get_wakeup_info_extra_data(unsigned char** extra_data, int* extra_data_length, char **extra_data_desc)
+{
+       if (extra_data) {
+               *extra_data = g_wakeup_info.extra_data;
+       }
+
+       if (extra_data_length) {
+               *extra_data_length = g_wakeup_info.extra_data_length;
+       }
+
+       if (extra_data_desc) {
+               *extra_data_desc = g_wakeup_info.extra_data_desc;
+       }
+
+       return 0;
+}
+
index a67a2adcf49900600c56600a90286feb09ced731..24bebec21a2f73f44c6c258e483074f407152616 100644 (file)
@@ -33,7 +33,8 @@ static bool g_streaming_requested = false;
 
 extern int __ma_cb_error(int reason, char* msg);
 extern int __ma_cb_audio_streaming(int event, char* buffer, int len);
-extern int __ma_cb_active_state_changed(int state);
+extern int __ma_cb_active_state_changed(int state, const char* wakeup_word,
+       const unsigned char* extra_data, int extra_data_length, const char* extra_data_desc);
 extern int __ma_cb_service_state_changed(int state);
 extern int __ma_cb_wakeup_engine_command(const char *command);
 extern int __ma_cb_preprocessing_information_changed(const char* app_id);
@@ -266,8 +267,17 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler* fd_handle
 
                else if (dbus_message_is_method_call(msg, if_name, MAS_METHOD_ACTIVE_STATE_CHANGE)) {
                        int state;
+                       char* wakeup_word = NULL;
+                       unsigned char* extra_data = NULL;
+                       int extra_data_length = 0;
+                       char* extra_data_desc = NULL;
+
                        dbus_message_get_args(msg, &err,
                                        DBUS_TYPE_INT32, &state,
+                                       DBUS_TYPE_STRING, &wakeup_word,
+                                       DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
+                                       &extra_data, &extra_data_length,
+                                       DBUS_TYPE_STRING, &extra_data_desc,
                                        DBUS_TYPE_INVALID);
 
                        MA_SLOGI("@@@ Active state : %d", state); //LCOV_EXCL_LINE
@@ -277,8 +287,20 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler* fd_handle
                                dbus_error_free(&err);
                                //LCOV_EXCL_STOP
                        } else {
-                               MA_SLOGD("@@ state(%d)", state); //LCOV_EXCL_LINE
-                               __ma_cb_active_state_changed(state);
+                               char* temp_wakeup_word = NULL;
+                               if (NULL != wakeup_word && strcmp("#NULL", wakeup_word)) {
+                                       temp_wakeup_word = strdup(wakeup_word);
+                               }
+                               char* temp_extra_data_desc = NULL;
+                               if (NULL != extra_data_desc && strcmp("#NULL", extra_data_desc)) {
+                                       temp_extra_data_desc = strdup(extra_data_desc);
+                               }
+                               MA_SLOGD("@@ state(%d), wakeup_word(%s)", state, temp_wakeup_word); //LCOV_EXCL_LINE
+                               __ma_cb_active_state_changed(state, temp_wakeup_word, extra_data, extra_data_length, temp_extra_data_desc);
+                               if (NULL != temp_wakeup_word)
+                                       free(temp_wakeup_word);
+                               if (NULL != temp_extra_data_desc)
+                                       free(temp_extra_data_desc);
                        }
 
                        MA_SLOGI("@@@"); //LCOV_EXCL_LINE
index 0e810a9f33c324131c3deb0ec3ca7375e623727e..80c4caf7dc4d228397ce9dd7a8a0cc3c349e0b18 100644 (file)
@@ -840,6 +840,51 @@ int ma_add_wake_word(const char* wake_word, const char *language);
  */
 int ma_remove_wake_word(const char* wake_word, const char *language);
 
+/**
+ * @brief Retrieves wake word information of the last wakeup event.
+ * @since_tizen 7.0
+ *
+ * @remarks You must not release @a wake_word using free().
+ *          @a wake_word can be changed whenever @a ma_active_state_changed_cb is called.
+ * @param[out] wake_word The wake word information, if exists.
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MA_ERROR_NONE Successful
+ * @retval #MA_ERROR_NOT_SUPPORTED Not supported
+ * @retval #MA_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MA_ERROR_INVALID_STATE Invalid state
+ * @retval #MA_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @pre The state should be #MA_STATE_READY.
+ * @see ma_active_state_changed_cb()
+ */
+int ma_get_wakeup_info_wake_word(char** wake_word);
+
+/**
+ * @brief Retrieves extra data information of the last wakeup event.
+ * @details When required, wakeup engine adds extra data information
+ *          that can be processed by the voice assistant.
+ *          The information MUST be defined by both wakeup engine and voice assistant.
+ * @since_tizen 7.0
+ *
+ * @remarks You must not release @a extra_data and @a extra_data_desc using free().
+ *          @a extra_data can be changed whenever @a ma_active_state_changed_cb is called.
+ * @param[out] extra_data The extra data information, if exists.
+ * @param[out] extra_data_length The length of extra data.
+ * @param[out] extra_data_desc The string value describing the type of extra data.
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MA_ERROR_NONE Successful
+ * @retval #MA_ERROR_NOT_SUPPORTED Not supported
+ * @retval #MA_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MA_ERROR_INVALID_STATE Invalid state
+ * @retval #MA_ERROR_OPERATION_FAILED Operation failed
+ *
+ * @pre The state should be #MA_STATE_READY.
+ * @see ma_active_state_changed_cb()
+ */
+int ma_get_wakeup_info_extra_data(unsigned char** extra_data, int* extra_data_length, char **extra_data_desc);
+
 #ifdef __cplusplus
 }
 #endif