blob: e08ea12f0989bc6e04d59dbf80c4f123f113b6aa [file] [log] [blame]
Quinn Male2e883752019-03-22 11:28:54 -07001/* 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 Dawson016b9f92021-05-28 13:49:09 -04006 * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
Quinn Male2e883752019-03-22 11:28:54 -07007 *
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
43enum 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
51typedef enum st_hw_sess_event_id {
52 ST_HW_SESS_EVENT_DETECTED,
Quinn Male48490df2020-03-25 10:25:42 -070053 ST_HW_SESS_EVENT_BUFFERING_STOPPED,
Quinn Male2e883752019-03-22 11:28:54 -070054 ST_HW_SESS_EVENT_MAX
55} st_hw_sess_event_id_t;
56
Quinn Male2e883752019-03-22 11:28:54 -070057typedef 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
64typedef 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
71typedef void (*hw_ses_event_callback_t)(st_hw_sess_event_t *event, void *cookie);
72
Venkatesh Mangalappalie4f17532019-06-04 16:30:28 -070073struct st_hw_ses_config {
Quinn Male58749452020-03-26 17:14:56 -070074 struct listnode sthw_cfg_list_node;
75 unsigned int model_id;
Venkatesh Mangalappalie4f17532019-06-04 16:30:28 -070076 unsigned int client_req_hist_buf;
77 unsigned int client_req_preroll;
78 unsigned char *conf_levels;
79 unsigned int num_conf_levels;
Venkatesh Mangalappalie4f17532019-06-04 16:30:28 -070080};
81
Quinn Male2e883752019-03-22 11:28:54 -070082struct 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 Male2e883752019-03-22 11:28:54 -070091 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 Mangalappalie4f17532019-06-04 16:30:28 -070097 sound_model_handle_t sm_handle; /* used when logging */
Quinn Male2e883752019-03-22 11:28:54 -070098 struct sound_trigger_device *stdev;
99
100 st_device_t st_device;
101 char *st_device_name;
Quinn Male2e883752019-03-22 11:28:54 -0700102 struct listnode *second_stage_list;
103 uint32_t kw_start_idx;
104 uint32_t kw_end_idx;
Tahir Dawson016b9f92021-05-28 13:49:09 -0400105 uint32_t channel_idx;
Quinn Male2e883752019-03-22 11:28:54 -0700106 int32_t user_level;
107 bool enable_second_stage;
Quinn Male2e883752019-03-22 11:28:54 -0700108 bool is_generic_event;
109 struct listnode lsm_ss_cfg_list;
110 bool lpi_enable;
Quinn Malecc1affd2019-07-18 16:13:31 -0700111 bool barge_in_mode;
Venkatesh Mangalappalie4f17532019-06-04 16:30:28 -0700112 bool lab_enabled;
113
Quinn Male2e883752019-03-22 11:28:54 -0700114 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 Mangalappalie4f17532019-06-04 16:30:28 -0700118
Quinn Male58749452020-03-26 17:14:56 -0700119 struct listnode sthw_cfg_list;
120 uint32_t max_hist_buf;
121 uint32_t max_preroll;
Venkatesh Mangalappalie4f17532019-06-04 16:30:28 -0700122 bool sthw_cfg_updated;
Quinn Male58749452020-03-26 17:14:56 -0700123 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 Male2e883752019-03-22 11:28:54 -0700129};
130
131typedef struct st_hw_session st_hw_session_t;
132
133/* Function pointers to routing layers */
134typedef void (*sound_trigger_init_session_t)(st_hw_session_t *);
135typedef int (*sound_trigger_reg_sm_t)(st_hw_session_t *,
Quinn Male58749452020-03-26 17:14:56 -0700136 void*, unsigned int, uint32_t);
Quinn Male2e883752019-03-22 11:28:54 -0700137typedef int (*sound_trigger_reg_sm_params_t)(st_hw_session_t *,
138 unsigned int recognition_mode, bool capture_requested,
Quinn Male58749452020-03-26 17:14:56 -0700139 struct sound_trigger_recognition_config *rc_config);
Quinn Male2e883752019-03-22 11:28:54 -0700140
Quinn Male58749452020-03-26 17:14:56 -0700141typedef int (*sound_trigger_dereg_sm_t)(st_hw_session_t *, uint32_t);
Quinn Male2e883752019-03-22 11:28:54 -0700142typedef int (*sound_trigger_dereg_sm_params_t)(st_hw_session_t *);
143typedef int (*sound_trigger_start_t)(st_hw_session_t *);
Venkatesh Mangalappalie4f17532019-06-04 16:30:28 -0700144typedef int (*sound_trigger_restart_t)(st_hw_session_t *, unsigned int,
Quinn Male58749452020-03-26 17:14:56 -0700145 struct sound_trigger_recognition_config *);
Quinn Male2e883752019-03-22 11:28:54 -0700146typedef int (*sound_trigger_stop_t)(st_hw_session_t *);
Venkatesh Mangalappalie4f17532019-06-04 16:30:28 -0700147typedef int (*sound_trigger_stop_buffering_t)(st_hw_session_t *);
Quinn Male2e883752019-03-22 11:28:54 -0700148typedef int (*sound_trigger_set_device_t)(st_hw_session_t *, bool);
149typedef int (*sound_trigger_read_pcm_t)(st_hw_session_t *,
150 unsigned char *, unsigned int );
151typedef void (*sound_trigger_lab_capture_t)(st_hw_session_t *);
152typedef int (*sound_trigger_send_custom_chmix_coeff_t)(st_hw_session_t *, char *);
153typedef int (*sound_trigger_disable_device_t)(st_hw_session_t *, bool);
154typedef int (*sound_trigger_enable_device_t)(st_hw_session_t *, bool);
155typedef int (*sound_trigger_get_param_data_t)(st_hw_session_t *, const char *,
156 void *, size_t, size_t *);
157typedef int (*sound_trigger_send_detection_request_t)(st_hw_session_t *);
Harshal Ahire63dfba52020-07-13 02:38:14 +0530158typedef int (*sound_trigger_get_module_version)(st_hw_session_t *, void *, size_t);
159typedef int (*sound_trigger_open_session)(st_hw_session_t *);
160typedef void (*sound_trigger_close_session)(st_hw_session_t *);
161
Quinn Male2e883752019-03-22 11:28:54 -0700162
163struct 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 Ahire63dfba52020-07-13 02:38:14 +0530187 sound_trigger_get_module_version get_module_version;
188 sound_trigger_open_session open_session;
189 sound_trigger_close_session close_session;
Quinn Male2e883752019-03-22 11:28:54 -0700190};
191
192#endif