diff options
author | rioskao <rioskao@google.com> | 2019-04-04 23:48:37 -0700 |
---|---|---|
committer | rioskao <rioskao@google.com> | 2019-04-26 15:19:16 +0800 |
commit | ed98af889dc986bac62d762e60a2230e2595fa84 (patch) | |
tree | 1edff37c71d4ef9279212d8b40df372cc7021473 | |
parent | 7f02252dc8af0993d9c12748b655612253fa043d (diff) | |
download | android_hardware_knowles_athletico_sound_trigger_hal-ed98af889dc986bac62d762e60a2230e2595fa84.tar.gz android_hardware_knowles_athletico_sound_trigger_hal-ed98af889dc986bac62d762e60a2230e2595fa84.tar.bz2 android_hardware_knowles_athletico_sound_trigger_hal-ed98af889dc986bac62d762e60a2230e2595fa84.zip |
sthal: support downlink audio
note: create media buffer for DA
setup route when music playing.
Test: test in-device music with music IQ
Bug: 120055055
Change-Id: Ibb9271352b28cfef266f3aa63e6b1be0baca6212
-rw-r--r-- | cvq_ioctl.h | 4 | ||||
-rw-r--r-- | cvq_util.c | 58 | ||||
-rw-r--r-- | sound_trigger_hw_iaxxx.c | 96 |
3 files changed, 155 insertions, 3 deletions
diff --git a/cvq_ioctl.h b/cvq_ioctl.h index 68e63d0..1c7ceba 100644 --- a/cvq_ioctl.h +++ b/cvq_ioctl.h @@ -82,6 +82,8 @@ #define BUF_INSTANCE_ID 1 #define BUF_PRIORITY 1 +#define DA_BUF_INSTANCE_ID 3 + #define HOTWORD_DETECTION 0 #define AMBIENT_DETECTION 1 #define ENTITY_DETECTION 2 @@ -159,6 +161,8 @@ int destroy_sensor_package(struct iaxxx_odsp_hw *odsp_hdl); int setup_mixer_package(struct iaxxx_odsp_hw *odsp_hdl); int destroy_mixer_package(struct iaxxx_odsp_hw *odsp_hdl); +int setup_downlink_buffer(struct iaxxx_odsp_hw *odsp_hdl); +int destroy_downlink_buffer(struct iaxxx_odsp_hw *odsp_hdl); int setup_mic_buffer(struct iaxxx_odsp_hw *odsp_hdl, enum buffer_configuration bc); int destroy_mic_buffer(struct iaxxx_odsp_hw *odsp_hdl); int set_buffer_route(struct audio_route *route_hdl, bool bargein); @@ -1186,6 +1186,64 @@ exit: return err; } +int setup_downlink_buffer(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + struct iaxxx_create_config_data cdata; + + ALOGD("+%s+", __func__); + + // Create the 8 seconds Buffer plugin for Downlink Audio + cdata.type = CONFIG_FILE; + cdata.data.fdata.filename = BUFFER_CONFIG_VAL_MULTI_SEC; + err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl, + DA_BUF_INSTANCE_ID, + IAXXX_HMD_BLOCK_ID, + cdata); + if (err != 0) { + ALOGE("%s: ERROR: DA buffer configuration failed %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + // Create Buffer plugin + err = iaxxx_odsp_plugin_create(odsp_hdl, + DA_BUF_INSTANCE_ID, + BUF_PRIORITY, BUF_PKG_ID, + BUF_PLUGIN_IDX, + IAXXX_HMD_BLOCK_ID, + PLUGIN_DEF_CONFIG_ID); + if (err != 0) { + ALOGE("%s: ERROR: Failed to create DA Buffer error %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + ALOGD("-%s-", __func__); + +exit: + return err; +} + +int destroy_downlink_buffer(struct iaxxx_odsp_hw *odsp_hdl) +{ + int err = 0; + + ALOGD("+%s+", __func__); + err = iaxxx_odsp_plugin_destroy(odsp_hdl, + DA_BUF_INSTANCE_ID, + IAXXX_HMD_BLOCK_ID); + if (err == -1) { + ALOGE("%s: ERROR: Failed to destroy DA buffer plugin %d(%s)", + __func__, errno, strerror(errno)); + goto exit; + } + + ALOGD("-%s-", __func__); + +exit: + return err; +} + int setup_mic_buffer(struct iaxxx_odsp_hw *odsp_hdl, enum buffer_configuration bc) { struct iaxxx_create_config_data cdata; diff --git a/sound_trigger_hw_iaxxx.c b/sound_trigger_hw_iaxxx.c index e056fc3..c39631a 100644 --- a/sound_trigger_hw_iaxxx.c +++ b/sound_trigger_hw_iaxxx.c @@ -59,7 +59,7 @@ #define CVQ_ENDPOINT (IAXXX_SYSID_PLUGIN_1_OUT_EP_0) #define COMMON_8SEC_BUF_ENDPOINT (IAXXX_SYSID_PLUGIN_1_OUT_EP_1) -//#define NEWSIQ_MUSICIQ_BUF_ENDPOINT (IAXXX_SYSID_PLUGIN_11_OUT_EP_0) +#define DA_BUF_ENDPOINT (IAXXX_SYSID_PLUGIN_3_OUT_EP_1) #define IAXXX_VQ_EVENT_STR "IAXXX_VQ_EVENT" #define IAXXX_RECOVERY_EVENT_STR "IAXXX_RECOVERY_EVENT" @@ -147,6 +147,7 @@ struct knowles_sound_trigger_device { bool is_music_playing; bool is_bargein_route_enabled; bool is_buffer_package_loaded; + bool is_da_buffer_enabled; bool is_st_hal_ready; unsigned int current_enable; @@ -821,6 +822,25 @@ static int handle_input_source(struct knowles_sound_trigger_device *stdev, goto exit; } } + //setup DA buffer and route. + if (stdev->is_da_buffer_enabled == false && + stdev->is_music_playing == true && + stdev->is_buffer_package_loaded == true) { + err = setup_downlink_buffer(stdev->odsp_hdl); + if (err != 0) { + ALOGE("Failed to load DA buffer package"); + goto exit; + } + stdev->is_da_buffer_enabled = true; + err = enable_downlink_audio_route(stdev->route_hdl, + stdev->is_da_buffer_enabled); + if (err != 0) { + ALOGE("Failed to enable downlink-audio route"); + stdev->is_da_buffer_enabled = false; + destroy_downlink_buffer(stdev->odsp_hdl); + goto exit; + } + } } else { if (!is_any_model_active(stdev)) { ALOGD("None of keywords are active"); @@ -842,6 +862,23 @@ static int handle_input_source(struct knowles_sound_trigger_device *stdev, goto exit; } } + //disable DA buffer and route. + if (stdev->is_music_playing == true && + stdev->is_da_buffer_enabled == true) { + stdev->is_da_buffer_enabled = false; + err = enable_downlink_audio_route(stdev->route_hdl, + stdev->is_da_buffer_enabled); + if (err != 0) { + ALOGE("Failed to disable downlink-audio route"); + stdev->is_da_buffer_enabled = true; + goto exit; + } + err = destroy_downlink_buffer(stdev->odsp_hdl); + if (err != 0) { + ALOGE("Failed to unload DA buffer package"); + goto exit; + } + } if (stdev->is_mic_route_enabled == true) { stdev->is_mic_route_enabled = false; err = enable_mic_route(stdev->route_hdl, false, ct); @@ -912,6 +949,24 @@ static int restart_recognition(struct knowles_sound_trigger_device *stdev) if (err != 0) { ALOGE("Failed to restart bargein route"); } + + //setup DA buffer and route. + if (stdev->is_da_buffer_enabled == true) { + err = setup_downlink_buffer(stdev->odsp_hdl); + if (err != 0) { + ALOGE("Failed to restart DA buffer package"); + } + err = enable_downlink_audio_route(stdev->route_hdl, + !stdev->is_da_buffer_enabled); + if (err != 0) { + ALOGE("Failed to tear downlink-audio route"); + } + err = enable_downlink_audio_route(stdev->route_hdl, + stdev->is_da_buffer_enabled); + if (err != 0) { + ALOGE("Failed to restart downlink-audio route"); + } + } } // [TODO] Recovery function still TBD. @@ -2019,6 +2074,7 @@ static int stdev_open(const hw_module_t *module, const char *name, stdev->is_music_playing = false; stdev->is_bargein_route_enabled = false; stdev->is_buffer_package_loaded = false; + stdev->is_da_buffer_enabled = false; stdev->current_enable = 0; stdev->bc = NOT_CONFIGURED; @@ -2133,6 +2189,22 @@ int sound_trigger_hw_call_back(audio_event_type_t event, if (stdev->is_music_playing != false) { stdev->is_music_playing = false; if (stdev->is_mic_route_enabled != false) { + //Disable DA buffer + if (stdev->is_da_buffer_enabled == true) { + stdev->is_da_buffer_enabled = false; + ret = enable_downlink_audio_route(stdev->route_hdl, + stdev->is_da_buffer_enabled); + if (ret != 0) { + ALOGE("Failed to disable downlink-audio route"); + stdev->is_da_buffer_enabled = true; + goto exit; + } + ret = destroy_downlink_buffer(stdev->odsp_hdl); + if (ret != 0) { + ALOGE("Failed to unload DA buffer package"); + goto exit; + } + } // Atleast one keyword model is active so update the routes // Check if the bargein route is enabled if not enable bargein route // Check each model, if it is active then update it's route @@ -2210,6 +2282,24 @@ int sound_trigger_hw_call_back(audio_event_type_t event, if (stdev->is_music_playing != true) { stdev->is_music_playing = true; if (stdev->is_mic_route_enabled != false) { + //setup DA buffer and route. + if (stdev->is_da_buffer_enabled == false && + stdev->is_music_playing == true && + stdev->is_buffer_package_loaded == true) { + ret = setup_downlink_buffer(stdev->odsp_hdl); + if (ret != 0) { + ALOGE("Failed to load DA buffer package"); + goto exit; + } + stdev->is_da_buffer_enabled = true; + ret = enable_downlink_audio_route(stdev->route_hdl, + stdev->is_da_buffer_enabled); + if (ret != 0) { + ALOGE("Failed to enable downlink-audio route"); + stdev->is_da_buffer_enabled = false; + goto exit; + } + } // Atleast one keyword model is active so update the routes // Check if the bargein route is enabled if not enable bargein route // Check each model, if it is active then update it's route @@ -2312,8 +2402,8 @@ int sound_trigger_hw_call_back(audio_event_type_t event, break; case AMBIENT_KW_ID: case ENTITY_KW_ID: - stream_end_point = COMMON_8SEC_BUF_ENDPOINT; - //if downlink audio using another endpoint + stream_end_point = stdev->is_da_buffer_enabled ? + DA_BUF_ENDPOINT : COMMON_8SEC_BUF_ENDPOINT; break; default: stream_end_point = COMMON_8SEC_BUF_ENDPOINT; |