From: Wonnam Jang Date: Mon, 8 Oct 2018 08:51:01 +0000 (+0900) Subject: Sync with tizen 4.0 branch X-Git-Tag: accepted/tizen/unified/20181010.061738~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b6e06afc544143e6b05f3fb0cc59a9386784a430;p=platform%2Fcore%2Fuifw%2Fvoice-control.git Sync with tizen 4.0 branch Change-Id: I22ddb9911deeafa4b12dc3d89fea3b0059fec383 Signed-off-by: Wonnam Jang --- diff --git a/client/vc_mgr.c b/client/vc_mgr.c index 553ef4c..39e46e9 100644 --- a/client/vc_mgr.c +++ b/client/vc_mgr.c @@ -3443,7 +3443,7 @@ int __vc_mgr_cb_feedback_streaming(int pid, int utt_id, vc_feedback_event_e even } } - return ret; + return ret; } @@ -4079,6 +4079,7 @@ static void __tts_feedback_thread(void* data, Ecore_Thread* thread) } if (200 < cnt) { SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Wrong request, there's no pcm data"); + vc_mgr_data_clear_feedback_data(&feedback_data); return; } cnt++; @@ -4086,6 +4087,7 @@ static void __tts_feedback_thread(void* data, Ecore_Thread* thread) SLOG(LOG_INFO, TAG_VCM, "[INFO] Finish to wait for new feedback data come"); /* resume feedback thread */ + vc_mgr_data_clear_feedback_data(&feedback_data); continue; } diff --git a/client/vc_mgr_data.cpp b/client/vc_mgr_data.cpp index 866d3da..26482c1 100644 --- a/client/vc_mgr_data.cpp +++ b/client/vc_mgr_data.cpp @@ -96,20 +96,22 @@ int vc_mgr_data_get_feedback_data_size() int vc_mgr_data_clear_feedback_data(vc_feedback_data_s** data) { - SLOG(LOG_DEBUG, TAG_VCM, "[DATA] clear feedback data"); + SLOG(LOG_DEBUG, TAG_VCM, "[DATA] clear feedback data, empty(%d)", g_feedback_data.empty()); pthread_mutex_lock(&g_feedback_data_mutex); if (!g_feedback_data.empty()) { - SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] pid(%d), utt_id(%d), data(%p) size(%d) rate(%d)", (*data)->pid, (*data)->utt_id, (*data)->data, (*data)->data_size, (*data)->rate); + if (NULL != *data) { + SLOG(LOG_DEBUG, TAG_VCM, "[DEBUG] pid(%d), utt_id(%d), data(%p) size(%d) rate(%d)", (*data)->pid, (*data)->utt_id, (*data)->data, (*data)->data_size, (*data)->rate); - if (NULL != (*data)->data) { - free((*data)->data); - (*data)->data = NULL; - } + if (NULL != (*data)->data) { + free((*data)->data); + (*data)->data = NULL; + } - free(*data); - *data = NULL; + free(*data); + *data = NULL; + } } pthread_mutex_unlock(&g_feedback_data_mutex); diff --git a/include/voice_control_internal.h b/include/voice_control_internal.h index 8bc1961..cfbb9ea 100644 --- a/include/voice_control_internal.h +++ b/include/voice_control_internal.h @@ -1,18 +1,18 @@ -/* - * Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - */ +/** + * Copyright (c) 2011-2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ #ifndef __VOICE_CONTROL_INTERNAL_H__ @@ -42,19 +42,19 @@ typedef enum { /** -* @brief Called when client gets the asr recognition result from vc-daemon. -* -* @param[in] event The result event -* @param[in] result ASR text -* @param[in] user_data The user data passed from the callback registration function -* -* @return @c true when asr result is consumed \n @c false to propagate. -* -* @pre An application registers callback function using vc_mgr_set_pre_result_cb(). -* -* @see vc_widget_set_asr_result_cb() -* @see vc_widget_unset_asr_result_cb() -*/ + * @brief Called when client gets the asr recognition result from vc-daemon. + * + * @param[in] event The result event + * @param[in] result ASR text + * @param[in] user_data The user data passed from the callback registration function + * + * @return @c true when asr result is consumed \n @c false to propagate. + * + * @pre An application registers callback function using vc_mgr_set_pre_result_cb(). + * + * @see vc_widget_set_asr_result_cb() + * @see vc_widget_unset_asr_result_cb() + */ typedef bool (*vc_asr_result_cb)(vc_result_event_e event, const char* result, void *user_data); /** diff --git a/include/voice_control_manager.h b/include/voice_control_manager.h index 430daa5..3d4ece3 100644 --- a/include/voice_control_manager.h +++ b/include/voice_control_manager.h @@ -1,18 +1,18 @@ -/* -* Copyright (c) 2011-2018 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the License); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* 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. -*/ +/** + * Copyright (c) 2011-2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ #ifndef __VOICE_CONTROL_MANAGER_H__ @@ -247,55 +247,57 @@ typedef int (*vc_mgr_private_data_requested_cb)(const char *key, char **data, vo /* for TTS feedback */ /** -* @brief Called when engine sends audio formats necessary for playing TTS feedback -* @since_tizen 5.0 -* -* @param[in] rate Audio sampling rate -* @param[in] channel Audio channel (e.g. #VC_AUDIO_CHANNEL_MONO, #VC_AUDIO_CHANNEL_STEREO) -* @param[in] audio_type Audio type (e.g. #VC_AUDIO_TYPE_PCM_S16_LE, #VC_AUDIO_TYPE_PCM_U8) -* @param[in] user_data The user data passed from the callback registration function -* -* @pre An application registers callback function using vc_mgr_set_feedback_audio_format_cb(). -* -* @see vc_mgr_set_feedback_audio_format_cb() -* @see vc_mgr_unset_feedback_audio_format_cb() -*/ + * @brief Called when engine sends audio formats necessary for playing TTS feedback + * @since_tizen 5.0 + * + * @param[in] rate Audio sampling rate + * @param[in] channel Audio channel (e.g. #VC_AUDIO_CHANNEL_MONO, #VC_AUDIO_CHANNEL_STEREO) + * @param[in] audio_type Audio type (e.g. #VC_AUDIO_TYPE_PCM_S16_LE, #VC_AUDIO_TYPE_PCM_U8) + * @param[in] user_data The user data passed from the callback registration function + * + * @pre An application registers callback function using vc_mgr_set_feedback_audio_format_cb(). + * + * @see vc_mgr_set_feedback_audio_format_cb() + * @see vc_mgr_unset_feedback_audio_format_cb() + */ typedef void (*vc_mgr_feedback_audio_format_cb)(int rate, vc_audio_channel_e channel, vc_audio_type_e audio_type, void *user_data); /** -* @brief Called when engine sends audio streaming for TTS feedback -* @since_tizen 5.0 -* -* @param[in] event TTS feedback event (e.g. #VC_FEEDBACK_EVENT_START, #VC_FEEDBACK_EVENT_CONTINUE) -* @param[in] buffer Audio streaming data -* @param[in] len Length of the audio streaming data -* @param[in] user_data The user data passed from the callback registration function -* -* @pre An application registers callback function using vc_mgr_set_feedback_streaming_cb(). -* -* @see vc_mgr_set_feedback_streaming_cb() -* @see vc_mgr_unset_feedback_streaming_cb() -*/ + * @brief Called when engine sends audio streaming for TTS feedback + * @since_tizen 5.0 + * + * @remarks The @a buffer must be released with free() by you when you no longer need it. + * + * @param[in] event TTS feedback event (e.g. #VC_FEEDBACK_EVENT_START, #VC_FEEDBACK_EVENT_CONTINUE) + * @param[in] buffer Audio streaming data + * @param[in] len Length of the audio streaming data + * @param[in] user_data The user data passed from the callback registration function + * + * @pre An application registers callback function using vc_mgr_set_feedback_streaming_cb(). + * + * @see vc_mgr_set_feedback_streaming_cb() + * @see vc_mgr_unset_feedback_streaming_cb() + */ typedef void (*vc_mgr_feedback_streaming_cb)(vc_feedback_event_e event, char* buffer, int len, void *user_data); /** -* @brief Called when the vc client sends audio streaming for TTS feedback -* @since_tizen 5.0 -* -* @remarks The @a buffer must be released with free() by you when you no longer need it. -* -* @param[in] pid The process id of the vc client -* @param[in] utt_id The utterance id -* @param[in] event TTS feedback event (e.g. #VC_FEEDBACK_EVENT_START, #VC_FEEDBACK_EVENT_CONTINUE) -* @param[in] buffer Audio streaming data -* @param[in] len Length of the audio streaming data -* @param[in] user_data The user data passed from the callback registration function -* -* @pre An application registers callback function using vc_mgr_set_vc_tts_streaming_cb(). -* -* @see vc_mgr_set_vc_tts_streaming_cb() -* @see vc_mgr_unset_vc_tts_streaming_cb() -*/ + * @brief Called when the vc client sends audio streaming for TTS feedback + * @since_tizen 5.0 + * + * @remarks The @a buffer must be released with free() by you when you no longer need it. + * + * @param[in] pid The process id of the vc client + * @param[in] utt_id The utterance id + * @param[in] event TTS feedback event (e.g. #VC_FEEDBACK_EVENT_START, #VC_FEEDBACK_EVENT_CONTINUE) + * @param[in] buffer Audio streaming data + * @param[in] len Length of the audio streaming data + * @param[in] user_data The user data passed from the callback registration function + * + * @pre An application registers callback function using vc_mgr_set_vc_tts_streaming_cb(). + * + * @see vc_mgr_set_vc_tts_streaming_cb() + * @see vc_mgr_unset_vc_tts_streaming_cb() + */ typedef void (*vc_mgr_vc_tts_streaming_cb)(int pid, int utt_id, vc_feedback_event_e event, char* buffer, int len, void *user_data); /** diff --git a/server/vcd_main.h b/server/vcd_main.h index 04ecdbf..70bcd18 100644 --- a/server/vcd_main.h +++ b/server/vcd_main.h @@ -72,7 +72,8 @@ typedef enum { VCD_STATE_READY = 1, VCD_STATE_RECORDING = 2, VCD_STATE_PROCESSING = 3, - VCD_STATE_UPDATING = 4 + VCD_STATE_SYNTHESIZING = 4, + VCD_STATE_UPDATING = 5 } vcd_state_e; typedef enum { diff --git a/server/vcd_server.c b/server/vcd_server.c index 4f369e0..f2e34f1 100644 --- a/server/vcd_server.c +++ b/server/vcd_server.c @@ -1098,16 +1098,16 @@ int vcd_send_error(vce_error_e error, const char* msg, void *user_data) /* for TTS feedback */ int vcd_send_feedback_audio_format(int rate, vce_audio_channel_e channel, vce_audio_type_e audio_type) { - SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback audio format"); + SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback audio format, g_current_uid(%d)", g_current_uid); /* send TTS feedback audio format to VC manager */ int ret = VCD_ERROR_NONE; int pid = g_current_uid / 1000; if (-1 == g_current_uid || vcd_client_manager_get_pid() == pid) { - ret = vcdc_send_feedback_audio_format_to_manager(vcd_client_manager_get_pid(), rate, channel, audio_type); - if (VCD_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback audio format to VC manager"); - } + ret = vcdc_send_feedback_audio_format_to_manager(vcd_client_manager_get_pid(), rate, channel, audio_type); + if (VCD_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback audio format to VC manager"); + } } else { SLOG(LOG_INFO, TAG_VCD, "[Server INFO] Do not send TTS feedback audio format to VC manager"); } @@ -1120,14 +1120,14 @@ int vcd_send_feedback_streaming(vce_feedback_event_e event, char* buffer, int le if (-1 == g_current_uid && VCE_FEEDBACK_EVENT_START == event) { g_current_utt_id = (g_current_utt_id + 1) % 1000; g_current_uid = vcd_client_manager_get_pid() * 1000 + g_current_utt_id; - SLOG(LOG_INFO, TAG_VCD, "[Server info] set current uid and utt_id as manager pid"); + SLOG(LOG_INFO, TAG_VCD, "[Server info] set current uid and utt_id as manager pid(%d)", vcd_client_manager_get_pid()); } int ret = VCD_ERROR_NONE; int pid = g_current_uid / 1000; int utt_id = g_current_uid % 1000; - SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback streaming to pid(%d), is_mgr_client(%d)", pid, (pid == vcd_client_manager_get_pid() ? true : false)); + SLOG(LOG_INFO, TAG_VCD, "[Server DEBUG] Engine - Send TTS feedback streaming event(%d), uid(%d), is_mgr_client(%d)", event, g_current_uid, (pid == vcd_client_manager_get_pid() ? true : false)); if (pid == vcd_client_manager_get_pid()) { /* send TTS feedback streaming to manager client */ @@ -1138,14 +1138,21 @@ int vcd_send_feedback_streaming(vce_feedback_event_e event, char* buffer, int le } else { /* send TTS feedback streaming to client */ ret = vcdc_send_feedback_streaming(pid, utt_id, event, buffer, len); - if (VCD_ERROR_NONE != ret) { + if (VCD_ERROR_NONE != ret) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to send TTS feedback streaming to client"); - } + } } if (VCE_FEEDBACK_EVENT_FINISH == event) { /* reset current uid */ g_current_uid = -1; + + /* Set service state to ready if state is synthesizing */ + vcd_state_e state = vcd_config_get_service_state(); + if (VCD_STATE_SYNTHESIZING == state) { + vcd_config_set_service_state(VCD_STATE_READY); + } + SLOG(LOG_INFO, TAG_VCD, "[Server info] feedback streaming finish event, reset current uid & service state(%d)", vcd_config_get_service_state()); } return ret; } @@ -1845,8 +1852,8 @@ int vcd_server_mgr_start(vcd_recognition_mode_e recognition_mode, bool exclusive /* 1. check current state */ vcd_state_e state = vcd_config_get_service_state(); - if (VCD_STATE_READY != state) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready"); + if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizine, state(%d)", state); return VCD_ERROR_INVALID_STATE; } if (-1 == vcd_client_manager_get_pid()) { @@ -2091,8 +2098,8 @@ int vcd_server_mgr_send_specific_engine_request(int pid, const char* engine_app_ return VCD_ERROR_INVALID_PARAMETER; } vcd_state_e state = vcd_config_get_service_state(); - if (VCD_STATE_READY != state) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready"); + if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state); return VCD_ERROR_INVALID_STATE; } @@ -2118,8 +2125,8 @@ int vcd_server_mgr_do_action(int pid, int type, const char* action) } vcd_state_e state = vcd_config_get_service_state(); - if (VCD_STATE_READY != state) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready"); + if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state); return VCD_ERROR_INVALID_STATE; } @@ -2514,6 +2521,7 @@ static void __start_tts_request_thread(void* data, Ecore_Thread* thread) while (1) { int ret = -1; + int cnt = 0; /* Get tts text data */ ret = vcd_data_get_first_tts_text_data(&tts_text_data); @@ -2527,6 +2535,23 @@ static void __start_tts_request_thread(void* data, Ecore_Thread* thread) continue; } + while (1) { + vcd_state_e state = vcd_config_get_service_state(); + if (VCD_STATE_READY != state) { + if (0 == cnt++ % 10) + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Waiting to request TTS, state(%d)", state); + usleep(100000); + continue; + } + break; + } + + /* Set service state to synthesizing */ + vcd_config_set_service_state(VCD_STATE_SYNTHESIZING); + + /* Set current uid */ + g_current_uid = tts_text_data->uid; + /* Request tts to engine */ ret = vcd_engine_request_tts(tts_text_data->pid, tts_text_data->utt_id, tts_text_data->text, tts_text_data->language); if (0 != ret) { @@ -2556,20 +2581,21 @@ int vcd_server_request_tts(int pid, const char* text, const char* language, int } vcd_state_e state = vcd_config_get_service_state(); - if (VCD_STATE_READY != state) { + if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready, state(%d)", state); return VCD_ERROR_INVALID_STATE; } + int uid = -1; g_current_utt_id = (g_current_utt_id + 1) % 1000; *utt_id = g_current_utt_id; if (0 == to_vcm) { - g_current_uid = pid * 1000 + g_current_utt_id; + uid = pid * 1000 + g_current_utt_id; } else { - g_current_uid = vcd_client_manager_get_pid() * 1000 + g_current_utt_id; + uid = vcd_client_manager_get_pid() * 1000 + g_current_utt_id; } SLOG(LOG_INFO, TAG_VCD, "[Server INFO] pid(%d), text(%s), language(%s), to_vcm(%d), ", pid, text, language, to_vcm); - SLOG(LOG_INFO, TAG_VCD, "[Server INFO] current_uid(%d), current_utt_id(%d)", g_current_uid, g_current_utt_id); + SLOG(LOG_INFO, TAG_VCD, "[Server INFO] current_uid(%d), current_utt_id(%d)", uid, g_current_utt_id); vc_tts_text_data_s* tts_text_data; tts_text_data = (vc_tts_text_data_s*)calloc(1, sizeof(vc_tts_text_data_s)); @@ -2577,7 +2603,7 @@ int vcd_server_request_tts(int pid, const char* text, const char* language, int SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Fail to callocate memory "); return VCD_ERROR_OUT_OF_MEMORY; } - tts_text_data->uid = g_current_uid; + tts_text_data->uid = uid; tts_text_data->pid = pid; tts_text_data->utt_id = g_current_utt_id; tts_text_data->text = strdup(text); @@ -2606,7 +2632,7 @@ int vcd_server_cancel_tts(int pid, int utt_id) } vcd_state_e state = vcd_config_get_service_state(); - if (VCD_STATE_READY != state) { + if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) { SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready, state(%d)", state); return VCD_ERROR_INVALID_STATE; } @@ -2642,8 +2668,8 @@ int vcd_server_get_tts_audio_format(int pid, int* rate, int* channel, int* audio } vcd_state_e state = vcd_config_get_service_state(); - if (VCD_STATE_READY != state) { - SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready"); + if (VCD_STATE_READY != state && VCD_STATE_SYNTHESIZING != state) { + SLOG(LOG_ERROR, TAG_VCD, "[Server ERROR] Current state is not ready and not synthesizing, state(%d)", state); return VCD_ERROR_INVALID_STATE; }