blob: 2c76e002473632fe1d7b130043a887ab5f61f7cb [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 *
Quinn Male48490df2020-03-25 10:25:42 -07006 * Copyright (c) 2017-2020, 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;
105 int32_t user_level;
106 bool enable_second_stage;
Quinn Male2e883752019-03-22 11:28:54 -0700107 bool is_generic_event;
108 struct listnode lsm_ss_cfg_list;
109 bool lpi_enable;
Quinn Malecc1affd2019-07-18 16:13:31 -0700110 bool barge_in_mode;
Venkatesh Mangalappalie4f17532019-06-04 16:30:28 -0700111 bool lab_enabled;
112
Quinn Male2e883752019-03-22 11:28:54 -0700113 int rc_config_update_counter;
114 uint64_t first_stage_det_event_time;
115 uint64_t second_stage_det_event_time;
116 st_buffer_t *buffer;
Venkatesh Mangalappalie4f17532019-06-04 16:30:28 -0700117
Quinn Male58749452020-03-26 17:14:56 -0700118 struct listnode sthw_cfg_list;
119 uint32_t max_hist_buf;
120 uint32_t max_preroll;
Venkatesh Mangalappalie4f17532019-06-04 16:30:28 -0700121 bool sthw_cfg_updated;
Quinn Male58749452020-03-26 17:14:56 -0700122 char *custom_data;
123 unsigned int custom_data_size;
124 unsigned int num_reg_sm;
125
126 st_module_type_t f_stage_version;
127 uint32_t detected_preroll;
Quinn Male2e883752019-03-22 11:28:54 -0700128};
129
130typedef struct st_hw_session st_hw_session_t;
131
132/* Function pointers to routing layers */
133typedef void (*sound_trigger_init_session_t)(st_hw_session_t *);
134typedef int (*sound_trigger_reg_sm_t)(st_hw_session_t *,
Quinn Male58749452020-03-26 17:14:56 -0700135 void*, unsigned int, uint32_t);
Quinn Male2e883752019-03-22 11:28:54 -0700136typedef int (*sound_trigger_reg_sm_params_t)(st_hw_session_t *,
137 unsigned int recognition_mode, bool capture_requested,
Quinn Male58749452020-03-26 17:14:56 -0700138 struct sound_trigger_recognition_config *rc_config);
Quinn Male2e883752019-03-22 11:28:54 -0700139
Quinn Male58749452020-03-26 17:14:56 -0700140typedef int (*sound_trigger_dereg_sm_t)(st_hw_session_t *, uint32_t);
Quinn Male2e883752019-03-22 11:28:54 -0700141typedef int (*sound_trigger_dereg_sm_params_t)(st_hw_session_t *);
142typedef int (*sound_trigger_start_t)(st_hw_session_t *);
Venkatesh Mangalappalie4f17532019-06-04 16:30:28 -0700143typedef int (*sound_trigger_restart_t)(st_hw_session_t *, unsigned int,
Quinn Male58749452020-03-26 17:14:56 -0700144 struct sound_trigger_recognition_config *);
Quinn Male2e883752019-03-22 11:28:54 -0700145typedef int (*sound_trigger_stop_t)(st_hw_session_t *);
Venkatesh Mangalappalie4f17532019-06-04 16:30:28 -0700146typedef int (*sound_trigger_stop_buffering_t)(st_hw_session_t *);
Quinn Male2e883752019-03-22 11:28:54 -0700147typedef int (*sound_trigger_set_device_t)(st_hw_session_t *, bool);
148typedef int (*sound_trigger_read_pcm_t)(st_hw_session_t *,
149 unsigned char *, unsigned int );
150typedef void (*sound_trigger_lab_capture_t)(st_hw_session_t *);
151typedef int (*sound_trigger_send_custom_chmix_coeff_t)(st_hw_session_t *, char *);
152typedef int (*sound_trigger_disable_device_t)(st_hw_session_t *, bool);
153typedef int (*sound_trigger_enable_device_t)(st_hw_session_t *, bool);
154typedef int (*sound_trigger_get_param_data_t)(st_hw_session_t *, const char *,
155 void *, size_t, size_t *);
156typedef int (*sound_trigger_send_detection_request_t)(st_hw_session_t *);
Harshal Ahire89337992020-07-13 02:38:14 +0530157typedef int (*sound_trigger_get_module_version)(st_hw_session_t *, void *, size_t);
158typedef int (*sound_trigger_open_session)(st_hw_session_t *);
159typedef void (*sound_trigger_close_session)(st_hw_session_t *);
160
Quinn Male2e883752019-03-22 11:28:54 -0700161
162struct st_session_fptrs {
163 sound_trigger_reg_sm_t reg_sm;
164 sound_trigger_reg_sm_params_t reg_sm_params;
165 sound_trigger_dereg_sm_t dereg_sm;
166 sound_trigger_dereg_sm_params_t dereg_sm_params;
167 sound_trigger_start_t start;
168 sound_trigger_restart_t restart; /* If sessionn already started used to
169 quickly restart the session, in case of lsm this is a no-op in-case of
170 gcs it will do a stop/start */
171 sound_trigger_stop_t stop;
172 sound_trigger_stop_buffering_t stop_buffering; /* directs underlying
173 driver to stop sending PCM buffers, this will cause the pcm_read to
174 fail eventually, also signals the lab_capture thread in-case it is waiting
175 for data to be read from the big buffer */
176 sound_trigger_set_device_t set_device;
177 sound_trigger_read_pcm_t read_pcm;
178 sound_trigger_lab_capture_t process_lab_capture; /* goes into a loop that
179 read a chunk of data from PCM device and writes to large buffer that
180 is part of the session */
181 sound_trigger_send_custom_chmix_coeff_t send_custom_chmix_coeff;
182 sound_trigger_disable_device_t disable_device;
183 sound_trigger_enable_device_t enable_device;
184 sound_trigger_get_param_data_t get_param_data;
185 sound_trigger_send_detection_request_t send_detection_request;
Harshal Ahire89337992020-07-13 02:38:14 +0530186 sound_trigger_get_module_version get_module_version;
187 sound_trigger_open_session open_session;
188 sound_trigger_close_session close_session;
Quinn Male2e883752019-03-22 11:28:54 -0700189};
190
191#endif