-
Notifications
You must be signed in to change notification settings - Fork 0
/
sound_trigger_hw.h
343 lines (299 loc) · 10 KB
/
sound_trigger_hw.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/* sound_trigger_hw.h
*
* This file contains the API to load sound models with
* DSP and start/stop detection of associated key phrases.
*
* Copyright (c) 2013-2020, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SOUND_TRIGGER_HW_H
#define SOUND_TRIGGER_HW_H
#include <stdlib.h>
#include <cutils/list.h>
#include <pthread.h>
#include <errno.h>
#include <hardware/sound_trigger.h>
#include <tinyalsa/asoundlib.h>
#include <audio_route/audio_route.h>
#include <cutils/properties.h>
#include "sound_trigger_prop_intf.h"
#include "sound_trigger_platform.h"
#include "st_common_defs.h"
#include "st_session.h"
#include "st_second_stage.h"
#include "sml_model_parser.h"
#define AUDIO_HAL_NAME_PREFIX "audio.primary"
#if LINUX_ENABLED
#ifdef __LP64__
#define AUDIO_HAL_LIBRARY_PATH1 "/usr/lib64"
#define AUDIO_HAL_LIBRARY_PATH2 AUDIO_HAL_LIBRARY_PATH1
#else
#define AUDIO_HAL_LIBRARY_PATH1 "/usr/lib"
#define AUDIO_HAL_LIBRARY_PATH2 AUDIO_HAL_LIBRARY_PATH1
#endif
#else
#ifdef __LP64__
#define AUDIO_HAL_LIBRARY_PATH1 "/vendor/lib64/hw"
#define AUDIO_HAL_LIBRARY_PATH2 "/system/lib64/hw"
#else
#define AUDIO_HAL_LIBRARY_PATH1 "/vendor/lib/hw"
#define AUDIO_HAL_LIBRARY_PATH2 "/system/lib/hw"
#endif
#endif
typedef enum {
ST_DEVICE_SSR_APE = 0x1,
ST_DEVICE_SSR_CPE = 0x2
}st_ssr_state_t;
#define TRANSIT_WAKE_LOCK_NAME "sthal_transit_wake_lock"
#define TRANSIT_SSR_TIMEOUT_SEC (10)
#define TRANSIT_MIN_SLEEP_TIME_SEC (1)
typedef enum {
TRANSIT_NONE,
TRANSIT_CPE_TO_APE,
TRANSIT_APE_TO_CPE
}transit_dir_t;
#define USECASE_STRING_SIZE (50)
#define DEFAULT_NUM_LAB_READS (16)
struct use_case_info {
bool active;
int pcm_id;
int pcm_back_end;
char use_case[USECASE_STRING_SIZE];
};
/* ADPCM decoder APIs */
typedef int (*g722_init_decoder_t)(void *decoder_inp);
typedef int (*g722_dec_get_total_byte_size_t)(int *total_byte_size);
typedef int (*g722_dec_process_t)(short *in_buf, short *out_buf,
int in_bytes, int *out_samples,
void *decoder_inp);
/* MULAW decoder APIs */
typedef int (*mulaw_dec_process_t)(short *out_buf, char *in_buf,
unsigned int in_bytes);
/* Listen Sound Model Library APIs */
#include "ListenSoundModelLib.h"
typedef listen_status_enum (*smlib_getSoundModelHeader_t)
(
listen_model_type *pSoundModel,
listen_sound_model_header *pListenSoundModelHeader
);
typedef listen_status_enum (*smlib_releaseSoundModelHeader_t)
(
listen_sound_model_header *pListenSoundModelHeader
);
typedef listen_status_enum (*smlib_getKeywordPhrases_t)
(
listen_model_type *pSoundModel,
uint16_t *numKeywords,
keywordId_t *keywords
);
typedef listen_status_enum (*smlib_getUserNames_t)
(
listen_model_type *pSoundModel,
uint16_t *numUsers,
userId_t *users
);
typedef listen_status_enum (*smlib_getMergedModelSize_t)
(
uint16_t numModels,
listen_model_type *pModels[],
uint32_t *nOutputModelSize
);
typedef listen_status_enum (*smlib_mergeModels_t)
(
uint16_t numModels,
listen_model_type *pModels[],
listen_model_type *pMergedModel
);
typedef listen_status_enum (*getSizeAfterDeleting_t)
(
listen_model_type *pInputModel,
keywordId_t keywordId,
userId_t userId,
uint32_t *nOutputModelSize
);
typedef listen_status_enum (*deleteFromModel_t)
(
listen_model_type *pInputModel,
keywordId_t keywordId,
userId_t userId,
listen_model_type *pResultModel
);
struct sound_trigger_device {
struct sound_trigger_hw_device device;
struct sound_trigger_properties *hw_properties;
pthread_mutex_t lock;
pthread_cond_t cond;
struct listnode sound_model_list;
struct mixer *mixer;
struct audio_route *audio_route;
int snd_card;
volatile int session_id;
volatile int gcs_token;
pthread_mutex_t ref_cnt_lock;
int *dev_ref_cnt;
struct listnode available_devices;
int *dev_enable_cnt;
pthread_t transitions_thread;
pthread_cond_t transitions_cond;
unsigned int tx_concurrency_active;
unsigned int rx_concurrency_active;
bool reset_backend;
bool conc_capture_supported;
bool conc_voice_call_supported;
bool conc_voice_active;
bool conc_voip_call_supported;
bool conc_voip_active;
bool session_allowed;
bool rx_concurrency_disabled;
bool sw_mad;
bool bg_kwd;
int num_sessions_configured;
unsigned int max_cpe_sessions;
unsigned int avail_cpe_phrases;
unsigned int avail_cpe_users;
unsigned int max_ape_sessions;
unsigned int avail_ape_phrases;
unsigned int avail_ape_users;
unsigned int max_wdsp_sessions;
unsigned int max_arm_sessions;
bool support_dev_switch;
bool transit_to_adsp_on_playback;
bool transit_to_adsp_on_battery_charging;
bool transit_to_non_lpi_on_battery_charging;
bool lpi_enable;
bool vad_enable;
int transit_wait_time;
bool stop_transitions_thread_loop;
transit_dir_t transit_dir;
bool dedicated_sva_path;
bool dedicated_headset_path;
bool disable_hwmad;
st_platform_lpi_enable_t platform_lpi_enable;
unsigned int rx_conc_max_st_ses;
struct use_case_info *ape_pcm_use_cases;
struct use_case_info *arm_pcm_use_cases;
bool detect_failure;
void *platform;
st_hw_type_t hw_type;
st_exec_mode_t exec_mode;
st_exec_mode_t client_req_exec_mode;
int client_req_exec_mode_status;
bool audio_ec_enabled;
void *audio_hal_handle;
audio_hw_call_back_t audio_hal_cb;
unsigned int sthal_prop_api_version;
bool is_gcs;
struct listnode vendor_uuid_list;
void *smlib_handle;
smlib_getSoundModelHeader_t smlib_getSoundModelHeader;
smlib_releaseSoundModelHeader_t smlib_releaseSoundModelHeader;
smlib_getKeywordPhrases_t smlib_getKeywordPhrases;
smlib_getUserNames_t smlib_getUserNames;
smlib_getMergedModelSize_t smlib_getMergedModelSize;
smlib_mergeModels_t smlib_mergeModels;
getSizeAfterDeleting_t smlib_getSizeAfterDeleting;
deleteFromModel_t smlib_deleteFromModel;
void *mulaw_dec_lib_handle;
mulaw_dec_process_t mulaw_dec_process;
struct listnode adm_cfg_list;
struct listnode ec_ref_dev_list;
struct listnode active_rx_dev_list;
bool ssr_offline_received;
int lpma_handle;
bool is_charging;
bool enable_debug_dumps;
bool support_barge_in_mode;
bool support_dynamic_ec_update;
bool screen_off;
bool barge_in_mode;
int ec_reset_pending_cnt;
};
typedef struct sound_trigger_device sound_trigger_device_t;
st_session_t* get_sound_trigger_session
(
struct sound_trigger_device *stdev,
sound_model_handle_t sound_model_handle
);
struct audio_device_info {
struct listnode list;
audio_devices_t type;
char address[AUDIO_DEVICE_MAX_ADDRESS_LEN];
};
void update_hw_mad_exec_mode(st_exec_mode_t mode, st_profile_type_t profile_type);
#define ST_DEBUG_DUMP_LOCATION "/data/vendor/audio"
#define ST_DBG_DECLARE(args...) args
#define ST_DBG_FILE_OPEN_WR(fptr, fpath, fname, fextn, fcount) \
do {\
char fptr_fn[100];\
\
snprintf(fptr_fn, sizeof(fptr_fn), fpath"/"fname"_%d."fextn, fcount);\
fptr = fopen(fptr_fn, "wb");\
if (!fptr) { \
ALOGE("%s: File open failed %s: %s", \
__func__, fptr_fn, strerror(errno)); \
} \
} while (0)
#define ST_DBG_FILE_CLOSE(fptr) \
do {\
if (fptr) { fclose (fptr); }\
} while (0)
#define ST_DBG_FILE_WRITE(fptr, buf, buf_size) \
do {\
if (fptr) {\
size_t ret_bytes = fwrite(buf, 1, buf_size, fptr);\
if (ret_bytes != (size_t)buf_size) {\
ALOGE("%s: fwrite %zu < %zu", __func__,\
ret_bytes, (size_t)buf_size);\
}\
fflush(fptr);\
}\
} while (0)
int dbg_trace_max_lab_reads;
#define ST_DBG_ATRACE_ASYNC_BEGIN_IF(cond, name, cookie)\
do {\
if (cond) ATRACE_ASYNC_BEGIN(name, cookie);\
} while(0)
#define ST_DBG_ATRACE_ASYNC_END_IF(cond, name, cookie)\
do {\
if (cond) ATRACE_ASYNC_END(name, cookie);\
} while(0)
static inline void dbg_trace_parse_max_lab_reads()
{
char value[PROPERTY_VALUE_MAX];
if (property_get("persist.vendor.sthal.dbg_max_dsp_buf_reads", value, NULL))
dbg_trace_max_lab_reads = atoi(value);
else
dbg_trace_max_lab_reads = DEFAULT_NUM_LAB_READS;
}
#ifndef LINUX_ENABLED
#include <hardware_legacy/power.h>
#else
#define acquire_wake_lock(a, b) (0)
#define release_wake_lock(a) (0)
#define PARTIAL_WAKE_LOCK 1
#endif
#endif /* SOUND_TRIGGER_HW_H */