From 41e2b497424d36618847eefec6a83c8ec2baeedd Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Fri, 12 Mar 2021 17:20:26 +0900 Subject: [PATCH] Add bluetooth command to record voice using remote controller - Add a logic to check whether the current client is TC app or not. Change-Id: I36fcc9e5c179b1b64263c4fe482e18669c6cbed1 Signed-off-by: Suyeon Hwang --- server/sttd_engine_agent.c | 4 ++-- server/sttd_engine_agent.h | 2 +- server/sttd_recorder.c | 54 ++++++++++++++++++++++++++++++++++++++++++++-- server/sttd_recorder.h | 2 +- server/sttd_server.c | 15 +++++++++++-- 5 files changed, 69 insertions(+), 8 deletions(-) diff --git a/server/sttd_engine_agent.c b/server/sttd_engine_agent.c index bf5f10f..240829d 100644 --- a/server/sttd_engine_agent.c +++ b/server/sttd_engine_agent.c @@ -816,7 +816,7 @@ int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const ch return 0; } -int sttd_engine_agent_recognize_start_recorder(int uid) +int sttd_engine_agent_recognize_start_recorder(int uid, const char* appid) { if (NULL == g_engine_info) { SECURE_SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] The engine is not valid"); @@ -831,7 +831,7 @@ int sttd_engine_agent_recognize_start_recorder(int uid) SLOG(LOG_INFO, TAG_STTD, "[Engine Agent] Start recorder"); int ret; - ret = sttd_recorder_start(uid); + ret = sttd_recorder_start(uid, appid); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Engine Agent ERROR] Fail to start recorder : result(%d)", ret); stt_engine_recognize_cancel(); diff --git a/server/sttd_engine_agent.h b/server/sttd_engine_agent.h index 97ac59d..1b6c760 100644 --- a/server/sttd_engine_agent.h +++ b/server/sttd_engine_agent.h @@ -96,7 +96,7 @@ int sttd_engine_agent_check_app_agreed(const char* appid, bool* result); int sttd_engine_agent_recognize_start_engine(int uid, const char* lang, const char* recognition_type, int silence, const char* appid, const char* credential, void* user_param); -int sttd_engine_agent_recognize_start_recorder(int uid); +int sttd_engine_agent_recognize_start_recorder(int uid, const char* appid); int sttd_engine_agent_recognize_start_file(int uid, const char* filepath); diff --git a/server/sttd_recorder.c b/server/sttd_recorder.c index fcf688b..679e01f 100644 --- a/server/sttd_recorder.c +++ b/server/sttd_recorder.c @@ -95,6 +95,12 @@ static int g_count = 1; #endif #ifdef TV_BT_MODE +static char* g_tct_apps[5] = {"tct-stt-native-itc", + "tct-stt-native-utc", + "org.tizen.tbtcoreapp", + "Tizen.Stt.Tests", + "Tizen.Stt.Manual.Tests"}; + static float get_volume_decibel(char* data, int size, stte_audio_type_e type); //static stt_recorder_s* __get_recorder(int engine_id); @@ -237,7 +243,7 @@ const char* __stt_get_focus_changed_reason_code(sound_stream_focus_change_reason } } -void __recorder_focus_state_watch_cb(int id, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state, +void __recorder_focus_state_watch_cb(int id, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state, sound_stream_focus_change_reason_e reason, const char *extra_info, void *user_data) { SLOG(LOG_WARN, TAG_STTD, "[Recorder] focus_state_watch_cb is called, focus_state(%d), reason(%s)", (int)focus_state, __stt_get_focus_changed_reason_code(reason)); @@ -600,7 +606,27 @@ Eina_Bool __read_audio_func(void *data) } #endif -int sttd_recorder_start(int uid) +#ifdef TV_BT_MODE +bool __is_tct_app(const char* appid) +{ + int cnt = 0; + if (NULL == appid) { + SLOG(LOG_WARN, TAG_STTD, "[Recorder WARN] appid is NULL"); + return false; + } + + for (cnt = 0 ; cnt < 5 ; cnt++) { + if (0 == strncmp(appid, g_tct_apps[cnt], strlen(appid))) { + SLOG(LOG_INFO, TAG_STTD, "[Recoder INFO] Current app(%s) is TCT app.", appid); + return true; + } + } + + return false; +} +#endif + +int sttd_recorder_start(int uid, const char* appid) { if (STTD_RECORDER_STATE_RECORDING == g_recorder_state) return 0; @@ -635,6 +661,30 @@ int sttd_recorder_start(int uid) SLOG(LOG_WARN, TAG_STTD, "[Recorder WARNING] Fail to create timer of read_audio"); return STTD_ERROR_OPERATION_FAILED; } +#else + if (true == __is_tct_app(appid)) { + int ret = -1; + int bt_retry = 0; + bool started = false; + while (5 > bt_retry) { + ret = bt_hid_rc_start_sending_voice(NULL); + if (BT_ERROR_NONE == ret) { + SLOG(LOG_DEBUG, TAG_STTD, "[Recorder] Start bt audio"); + started = true; + break; + } else if (BT_ERROR_NOW_IN_PROGRESS == ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail bt_hid_rc_start_sending_voice()"); + usleep(50000); + bt_retry++; + } else { + SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] bt_hid_rc_start_sending_voice(): ret(%d)", ret); + break; + } + } + if (false == started) { + SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to start bt audio(%d)", ret); + } + } #endif g_recorder_state = STTD_RECORDER_STATE_RECORDING; diff --git a/server/sttd_recorder.h b/server/sttd_recorder.h index ec51764..27fb203 100644 --- a/server/sttd_recorder.h +++ b/server/sttd_recorder.h @@ -38,7 +38,7 @@ int sttd_recorder_create(stte_audio_type_e type, int channel, unsigned int sampl int sttd_recorder_destroy(); -int sttd_recorder_start(int uid); +int sttd_recorder_start(int uid, const char* appid); int sttd_recorder_stop(); diff --git a/server/sttd_server.c b/server/sttd_server.c index 06c8c25..e5a7be3 100644 --- a/server/sttd_server.c +++ b/server/sttd_server.c @@ -11,6 +11,7 @@ * limitations under the License. */ +#include #include #include #include @@ -1116,7 +1117,17 @@ void __sttd_server_recorder_start(void* data) return; } - int ret = sttd_engine_agent_recognize_start_recorder(uid); + char appid[1024] = {0, }; + int pid = sttd_client_get_pid(uid); + int ret = -1; + ret = aul_app_get_appid_bypid(pid, appid, sizeof(appid) - 1); + if ((AUL_R_OK != ret) || (0 == strlen(appid))) { + SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Fail to get application ID"); + } else { + SLOG(LOG_DEBUG, TAG_STTD, "[DEBUG] Current app id is %s", appid); + } + + ret = sttd_engine_agent_recognize_start_recorder(uid, appid); if (0 != ret) { SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to start recognition : result(%d)", ret); return; @@ -1280,7 +1291,7 @@ int sttd_server_start(int uid, const char* lang, const char* recognition_type, i if (true == is_sound_done) { SLOG(LOG_INFO, TAG_STTD, "[Server] No sound play"); - ret = sttd_engine_agent_recognize_start_recorder(uid); + ret = sttd_engine_agent_recognize_start_recorder(uid, appid); if (0 != ret) { stt_client_unset_current_recognition(); sttd_recorder_unset_audio_session(); -- 2.7.4