Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 1 | /* st_hw_session.h |
| 2 | * |
| 3 | * This file contains the API to load sound models with |
| 4 | * DSP and start/stop detection of associated key phrases. |
| 5 | * |
Tahir Dawson | 016b9f9 | 2021-05-28 13:49:09 -0400 | [diff] [blame] | 6 | * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved. |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions are |
| 10 | * met: |
| 11 | * * Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * * Redistributions in binary form must reproduce the above |
| 14 | * copyright notice, this list of conditions and the following |
| 15 | * disclaimer in the documentation and/or other materials provided |
| 16 | * with the distribution. |
| 17 | * * Neither the name of The Linux Foundation nor the names of its |
| 18 | * contributors may be used to endorse or promote products derived |
| 19 | * from this software without specific prior written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 28 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 30 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 31 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | */ |
| 33 | #ifndef ST_HW_SESSION_H |
| 34 | #define ST_HW_SESSION_H |
| 35 | |
| 36 | #include <hardware/sound_trigger.h> |
| 37 | #include <tinyalsa/asoundlib.h> |
| 38 | #include "sound_trigger_platform.h" |
| 39 | #include "st_common_defs.h" |
| 40 | #include "opaque_header.h" |
| 41 | #include "st_buffering.h" |
| 42 | |
| 43 | enum sound_trigger_states { |
| 44 | SES_CREATED = 0x00, |
| 45 | SES_STARTED = 0x01, |
| 46 | SES_EVENT_RECEIVED = 0x02, |
| 47 | SES_BUFFERING = 0x04, |
| 48 | SES_INVALIDATED = 0x08, |
| 49 | }; |
| 50 | |
| 51 | typedef enum st_hw_sess_event_id { |
| 52 | ST_HW_SESS_EVENT_DETECTED, |
Quinn Male | 48490df | 2020-03-25 10:25:42 -0700 | [diff] [blame] | 53 | ST_HW_SESS_EVENT_BUFFERING_STOPPED, |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 54 | ST_HW_SESS_EVENT_MAX |
| 55 | } st_hw_sess_event_id_t; |
| 56 | |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 57 | typedef struct st_hw_sess_detected_ev { |
| 58 | uint64_t timestamp; |
| 59 | int detect_status; |
| 60 | void* detect_payload; |
| 61 | size_t payload_size; |
| 62 | } st_hw_sess_detected_ev_t; |
| 63 | |
| 64 | typedef struct st_hw_sess_event { |
| 65 | st_hw_sess_event_id_t event_id; |
| 66 | union { |
| 67 | st_hw_sess_detected_ev_t detected; |
| 68 | } payload; |
| 69 | } st_hw_sess_event_t; |
| 70 | |
| 71 | typedef void (*hw_ses_event_callback_t)(st_hw_sess_event_t *event, void *cookie); |
| 72 | |
Venkatesh Mangalappali | e4f1753 | 2019-06-04 16:30:28 -0700 | [diff] [blame] | 73 | struct st_hw_ses_config { |
Quinn Male | 5874945 | 2020-03-26 17:14:56 -0700 | [diff] [blame] | 74 | struct listnode sthw_cfg_list_node; |
| 75 | unsigned int model_id; |
Venkatesh Mangalappali | e4f1753 | 2019-06-04 16:30:28 -0700 | [diff] [blame] | 76 | unsigned int client_req_hist_buf; |
| 77 | unsigned int client_req_preroll; |
| 78 | unsigned char *conf_levels; |
| 79 | unsigned int num_conf_levels; |
Venkatesh Mangalappali | e4f1753 | 2019-06-04 16:30:28 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 82 | struct st_hw_session { |
| 83 | |
| 84 | struct st_session_fptrs *fptrs; |
| 85 | |
| 86 | unsigned int use_case_idx; |
| 87 | |
| 88 | struct pcm_config config; |
| 89 | struct st_vendor_info *vendor_uuid_info; |
| 90 | |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 91 | hw_ses_event_callback_t callback_to_st_session; |
| 92 | void *cookie; |
| 93 | |
| 94 | st_exec_mode_t exec_mode; |
| 95 | |
| 96 | enum sound_trigger_states state; |
Venkatesh Mangalappali | e4f1753 | 2019-06-04 16:30:28 -0700 | [diff] [blame] | 97 | sound_model_handle_t sm_handle; /* used when logging */ |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 98 | struct sound_trigger_device *stdev; |
| 99 | |
| 100 | st_device_t st_device; |
| 101 | char *st_device_name; |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 102 | struct listnode *second_stage_list; |
| 103 | uint32_t kw_start_idx; |
| 104 | uint32_t kw_end_idx; |
Tahir Dawson | 016b9f9 | 2021-05-28 13:49:09 -0400 | [diff] [blame] | 105 | uint32_t channel_idx; |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 106 | int32_t user_level; |
| 107 | bool enable_second_stage; |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 108 | bool is_generic_event; |
| 109 | struct listnode lsm_ss_cfg_list; |
| 110 | bool lpi_enable; |
Quinn Male | cc1affd | 2019-07-18 16:13:31 -0700 | [diff] [blame] | 111 | bool barge_in_mode; |
Venkatesh Mangalappali | e4f1753 | 2019-06-04 16:30:28 -0700 | [diff] [blame] | 112 | bool lab_enabled; |
| 113 | |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 114 | int rc_config_update_counter; |
| 115 | uint64_t first_stage_det_event_time; |
| 116 | uint64_t second_stage_det_event_time; |
| 117 | st_buffer_t *buffer; |
Venkatesh Mangalappali | e4f1753 | 2019-06-04 16:30:28 -0700 | [diff] [blame] | 118 | |
Quinn Male | 5874945 | 2020-03-26 17:14:56 -0700 | [diff] [blame] | 119 | struct listnode sthw_cfg_list; |
| 120 | uint32_t max_hist_buf; |
| 121 | uint32_t max_preroll; |
Venkatesh Mangalappali | e4f1753 | 2019-06-04 16:30:28 -0700 | [diff] [blame] | 122 | bool sthw_cfg_updated; |
Quinn Male | 5874945 | 2020-03-26 17:14:56 -0700 | [diff] [blame] | 123 | char *custom_data; |
| 124 | unsigned int custom_data_size; |
| 125 | unsigned int num_reg_sm; |
| 126 | |
| 127 | st_module_type_t f_stage_version; |
| 128 | uint32_t detected_preroll; |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | typedef struct st_hw_session st_hw_session_t; |
| 132 | |
| 133 | /* Function pointers to routing layers */ |
| 134 | typedef void (*sound_trigger_init_session_t)(st_hw_session_t *); |
| 135 | typedef int (*sound_trigger_reg_sm_t)(st_hw_session_t *, |
Quinn Male | 5874945 | 2020-03-26 17:14:56 -0700 | [diff] [blame] | 136 | void*, unsigned int, uint32_t); |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 137 | typedef int (*sound_trigger_reg_sm_params_t)(st_hw_session_t *, |
| 138 | unsigned int recognition_mode, bool capture_requested, |
Quinn Male | 5874945 | 2020-03-26 17:14:56 -0700 | [diff] [blame] | 139 | struct sound_trigger_recognition_config *rc_config); |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 140 | |
Quinn Male | 5874945 | 2020-03-26 17:14:56 -0700 | [diff] [blame] | 141 | typedef int (*sound_trigger_dereg_sm_t)(st_hw_session_t *, uint32_t); |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 142 | typedef int (*sound_trigger_dereg_sm_params_t)(st_hw_session_t *); |
| 143 | typedef int (*sound_trigger_start_t)(st_hw_session_t *); |
Venkatesh Mangalappali | e4f1753 | 2019-06-04 16:30:28 -0700 | [diff] [blame] | 144 | typedef int (*sound_trigger_restart_t)(st_hw_session_t *, unsigned int, |
Quinn Male | 5874945 | 2020-03-26 17:14:56 -0700 | [diff] [blame] | 145 | struct sound_trigger_recognition_config *); |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 146 | typedef int (*sound_trigger_stop_t)(st_hw_session_t *); |
Venkatesh Mangalappali | e4f1753 | 2019-06-04 16:30:28 -0700 | [diff] [blame] | 147 | typedef int (*sound_trigger_stop_buffering_t)(st_hw_session_t *); |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 148 | typedef int (*sound_trigger_set_device_t)(st_hw_session_t *, bool); |
| 149 | typedef int (*sound_trigger_read_pcm_t)(st_hw_session_t *, |
| 150 | unsigned char *, unsigned int ); |
| 151 | typedef void (*sound_trigger_lab_capture_t)(st_hw_session_t *); |
| 152 | typedef int (*sound_trigger_send_custom_chmix_coeff_t)(st_hw_session_t *, char *); |
| 153 | typedef int (*sound_trigger_disable_device_t)(st_hw_session_t *, bool); |
| 154 | typedef int (*sound_trigger_enable_device_t)(st_hw_session_t *, bool); |
| 155 | typedef int (*sound_trigger_get_param_data_t)(st_hw_session_t *, const char *, |
| 156 | void *, size_t, size_t *); |
| 157 | typedef int (*sound_trigger_send_detection_request_t)(st_hw_session_t *); |
Harshal Ahire | 63dfba5 | 2020-07-13 02:38:14 +0530 | [diff] [blame] | 158 | typedef int (*sound_trigger_get_module_version)(st_hw_session_t *, void *, size_t); |
| 159 | typedef int (*sound_trigger_open_session)(st_hw_session_t *); |
| 160 | typedef void (*sound_trigger_close_session)(st_hw_session_t *); |
| 161 | |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 162 | |
| 163 | struct st_session_fptrs { |
| 164 | sound_trigger_reg_sm_t reg_sm; |
| 165 | sound_trigger_reg_sm_params_t reg_sm_params; |
| 166 | sound_trigger_dereg_sm_t dereg_sm; |
| 167 | sound_trigger_dereg_sm_params_t dereg_sm_params; |
| 168 | sound_trigger_start_t start; |
| 169 | sound_trigger_restart_t restart; /* If sessionn already started used to |
| 170 | quickly restart the session, in case of lsm this is a no-op in-case of |
| 171 | gcs it will do a stop/start */ |
| 172 | sound_trigger_stop_t stop; |
| 173 | sound_trigger_stop_buffering_t stop_buffering; /* directs underlying |
| 174 | driver to stop sending PCM buffers, this will cause the pcm_read to |
| 175 | fail eventually, also signals the lab_capture thread in-case it is waiting |
| 176 | for data to be read from the big buffer */ |
| 177 | sound_trigger_set_device_t set_device; |
| 178 | sound_trigger_read_pcm_t read_pcm; |
| 179 | sound_trigger_lab_capture_t process_lab_capture; /* goes into a loop that |
| 180 | read a chunk of data from PCM device and writes to large buffer that |
| 181 | is part of the session */ |
| 182 | sound_trigger_send_custom_chmix_coeff_t send_custom_chmix_coeff; |
| 183 | sound_trigger_disable_device_t disable_device; |
| 184 | sound_trigger_enable_device_t enable_device; |
| 185 | sound_trigger_get_param_data_t get_param_data; |
| 186 | sound_trigger_send_detection_request_t send_detection_request; |
Harshal Ahire | 63dfba5 | 2020-07-13 02:38:14 +0530 | [diff] [blame] | 187 | sound_trigger_get_module_version get_module_version; |
| 188 | sound_trigger_open_session open_session; |
| 189 | sound_trigger_close_session close_session; |
Quinn Male | 2e88375 | 2019-03-22 11:28:54 -0700 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | #endif |