From 42f74908125f42ff3f50efe2f62e142a20cdddb5 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Mon, 29 May 2017 19:33:36 +0900 Subject: [PATCH] add sound focus state watch callback Change-Id: I5b6bdd8bdaa9ad9df52104935b067141cd83dd55 Signed-off-by: Wonnam Jang --- server/sttd_recorder.c | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/server/sttd_recorder.c b/server/sttd_recorder.c index b24bc07..52b66ef 100644 --- a/server/sttd_recorder.c +++ b/server/sttd_recorder.c @@ -59,6 +59,8 @@ static sttd_recorder_state g_recorder_state = STTD_RECORDER_STATE_NONE; static int g_buffer_count; +static int g_stream_focus_id; + /* Sound buf save for test */ /* #define BUF_SAVE_MODE @@ -156,18 +158,12 @@ const char* __stt_get_focus_changed_reason_code(sound_stream_focus_change_reason } } -void __recorder_focus_state_cb(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_e focus_state, - sound_stream_focus_change_reason_e reason, int sound_behavior, const char *extra_info, void *user_data) +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_DEBUG, TAG_STTD, "[Recorder] Focus state changed cb"); - - if (stream_info != g_stream_info_h) { - SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Invalid stream info handle"); - return; - } - SLOG(LOG_WARN, TAG_STTD, "[Recorder] focus state changed to (%d) with reason(%s)", (int)focus_state, __stt_get_focus_changed_reason_code(reason)); + 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)); - if (STTD_RECORDER_STATE_RECORDING == g_recorder_state && SOUND_STREAM_FOCUS_STATE_RELEASED == focus_state) { + if (STTD_RECORDER_STATE_RECORDING == g_recorder_state && SOUND_STREAM_FOCUS_STATE_ACQUIRED == focus_state) { SLOG(LOG_WARN, TAG_STTD, "[Recorder] Focus released as interrupt"); if (NULL != g_interrupt_cb) { g_interrupt_cb(); @@ -175,7 +171,6 @@ void __recorder_focus_state_cb(sound_stream_info_h stream_info, sound_stream_foc } } - int sttd_recorder_initialize(stt_recorder_audio_cb audio_cb, stt_recorder_interrupt_cb interrupt_cb) { if (NULL == audio_cb || NULL == interrupt_cb) { @@ -197,10 +192,14 @@ int sttd_recorder_initialize(stt_recorder_audio_cb audio_cb, stt_recorder_interr g_recorder_state = STTD_RECORDER_STATE_NONE; g_recorder = NULL; - if (0 != sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_RECOGNITION, __recorder_focus_state_cb, NULL, &g_stream_info_h)) { + if (0 != sound_manager_create_stream_information(SOUND_STREAM_TYPE_VOICE_RECOGNITION, NULL, NULL, &g_stream_info_h)) { SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to create stream info"); } + if (0 != sound_manager_add_focus_state_watch_cb(SOUND_STREAM_FOCUS_FOR_BOTH, __recorder_focus_state_watch_cb, NULL, &g_stream_focus_id)) { + SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to add focus state watch callback"); + } + #ifdef TV_BT_MODE if (BT_ERROR_NONE != bt_initialize()) { SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to init bt"); @@ -222,6 +221,10 @@ int sttd_recorder_deinitialize() SLOG(LOG_ERROR, TAG_STTD, "[Server ERROR] Fail to destroy audio in handle mutex."); } + if (0 != sound_manager_remove_focus_state_watch_cb(g_stream_focus_id)) { + SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to remove focus state watch callback"); + } + if (0 != sound_manager_destroy_stream_information(g_stream_info_h)) { SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to destroy stream info"); } @@ -509,14 +512,9 @@ int sttd_recorder_start(int uid) return STTD_ERROR_INVALID_PARAMETER; } - ret = sound_manager_acquire_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_RECORDING, SOUND_BEHAVIOR_NONE, NULL); - if (SOUND_MANAGER_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to acquire focus : %d", ret); - } else { - ret = audio_in_set_sound_stream_info(g_recorder->audio_h, g_stream_info_h); - if (AUDIO_IO_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to set stream info"); - } + ret = audio_in_set_sound_stream_info(g_recorder->audio_h, g_stream_info_h); + if (AUDIO_IO_ERROR_NONE != ret) { + SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to set stream info"); } ret = audio_in_prepare(g_recorder->audio_h); @@ -619,11 +617,6 @@ int sttd_recorder_stop() g_recorder_state = STTD_RECORDER_STATE_READY; - ret = sound_manager_release_focus(g_stream_info_h, SOUND_STREAM_FOCUS_FOR_RECORDING, SOUND_BEHAVIOR_NONE, NULL); - if (SOUND_MANAGER_ERROR_NONE != ret) { - SLOG(LOG_ERROR, TAG_STTD, "[Recorder ERROR] Fail to release focus :%d", ret); - } - #ifdef BUF_SAVE_MODE fclose(g_pFile); #endif -- 2.7.4