blob: ed8e6e83afa56488b8f7d09c9c99130cbc638bc5 [file] [log] [blame]
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#define LOG_TAG "soundtrigger"
17/* #define LOG_NDEBUG 0 */
18#define LOG_NDDEBUG 0
19
20#include <errno.h>
21#include <stdbool.h>
22#include <stdlib.h>
23#include <dlfcn.h>
Jiyong Park6431fe62017-06-29 15:15:58 +090024#include <pthread.h>
25#include <unistd.h>
Haynes Mathew Georgee6e2d442018-02-22 18:51:56 -080026#include <log/log.h>
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -070027#include "audio_hw.h"
28#include "audio_extn.h"
29#include "platform.h"
30#include "platform_api.h"
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +000031
32/*-------------------- Begin: AHAL-STHAL Interface ---------------------------*/
33/*
34 * Maintain the proprietary interface between AHAL and STHAL locally to avoid
35 * the compilation dependency of interface header file from STHAL.
36 */
37
38#define MAKE_HAL_VERSION(maj, min) ((((maj) & 0xff) << 8) | ((min) & 0xff))
39#define MAJOR_VERSION(ver) (((ver) & 0xff00) >> 8)
40#define MINOR_VERSION(ver) ((ver) & 0x00ff)
41
42/* Proprietary interface version used for compatibility with STHAL */
43#define STHAL_PROP_API_VERSION_1_0 MAKE_HAL_VERSION(1, 0)
44#define STHAL_PROP_API_CURRENT_VERSION STHAL_PROP_API_VERSION_1_0
45
46#define ST_EVENT_CONFIG_MAX_STR_VALUE 32
47
48typedef enum {
49 ST_EVENT_SESSION_REGISTER,
50 ST_EVENT_SESSION_DEREGISTER
51} sound_trigger_event_type_t;
52
53typedef enum {
54 AUDIO_EVENT_CAPTURE_DEVICE_INACTIVE,
55 AUDIO_EVENT_CAPTURE_DEVICE_ACTIVE,
56 AUDIO_EVENT_PLAYBACK_STREAM_INACTIVE,
57 AUDIO_EVENT_PLAYBACK_STREAM_ACTIVE,
58 AUDIO_EVENT_STOP_LAB,
59 AUDIO_EVENT_SSR,
60 AUDIO_EVENT_NUM_ST_SESSIONS,
61 AUDIO_EVENT_READ_SAMPLES,
62 AUDIO_EVENT_DEVICE_CONNECT,
63 AUDIO_EVENT_DEVICE_DISCONNECT,
64 AUDIO_EVENT_SVA_EXEC_MODE,
65 AUDIO_EVENT_SVA_EXEC_MODE_STATUS,
66 AUDIO_EVENT_CAPTURE_STREAM_INACTIVE,
67 AUDIO_EVENT_CAPTURE_STREAM_ACTIVE,
68} audio_event_type_t;
69
70typedef enum {
71 USECASE_TYPE_PCM_PLAYBACK,
72 USECASE_TYPE_PCM_CAPTURE,
73 USECASE_TYPE_VOICE_CALL,
74 USECASE_TYPE_VOIP_CALL,
75} audio_stream_usecase_type_t;
76
77typedef enum {
78 SND_CARD_STATUS_OFFLINE,
79 SND_CARD_STATUS_ONLINE,
80 CPE_STATUS_OFFLINE,
81 CPE_STATUS_ONLINE
82} ssr_event_status_t;
83
84struct sound_trigger_session_info {
85 void* p_ses; /* opaque pointer to st_session obj */
86 int capture_handle;
87 struct pcm *pcm;
88 struct pcm_config config;
89};
90
91struct audio_read_samples_info {
92 struct sound_trigger_session_info *ses_info;
93 void *buf;
94 size_t num_bytes;
95};
96
97struct audio_hal_usecase {
98 audio_stream_usecase_type_t type;
99};
100
101struct sound_trigger_event_info {
102 struct sound_trigger_session_info st_ses;
103};
104
105struct audio_event_info {
106 union {
107 ssr_event_status_t status;
108 int value;
109 struct sound_trigger_session_info ses_info;
110 struct audio_read_samples_info aud_info;
111 char str_value[ST_EVENT_CONFIG_MAX_STR_VALUE];
112 struct audio_hal_usecase usecase;
113 }u;
114};
115
116/* STHAL callback which is called by AHAL */
117typedef int (*sound_trigger_hw_call_back_t)(audio_event_type_t,
118 struct audio_event_info*);
119
120/*---------------- End: AHAL-STHAL Interface ----------------------------------*/
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700121
122#define XSTR(x) STR(x)
123#define STR(x) #x
124
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000125#define DLSYM(handle, ptr, symbol, err) \
126do { \
127 ptr = dlsym(handle, #symbol); \
128 if (ptr == NULL) { \
129 ALOGE("%s: dlsym %s failed . %s", __func__, #symbol, dlerror()); \
130 err = -ENODEV; \
131 } \
132} while(0)
133
Andy Hung7ddf8672016-03-31 10:30:42 -0700134#ifdef __LP64__
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000135#define SOUND_TRIGGER_LIBRARY_PATH "/vendor/lib64/hw/sound_trigger.primary.%s.so"
Andy Hung7ddf8672016-03-31 10:30:42 -0700136#else
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000137#define SOUND_TRIGGER_LIBRARY_PATH "/vendor/lib/hw/sound_trigger.primary.%s.so"
Andy Hung7ddf8672016-03-31 10:30:42 -0700138#endif
Andy Hung4bd229e2016-03-07 18:29:16 -0800139
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000140/*
141 * Current proprietary API version used by AHAL. Queried by STHAL
142 * for compatibility check with AHAL
143 */
144const unsigned int sthal_prop_api_version = STHAL_PROP_API_CURRENT_VERSION;
145
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700146struct sound_trigger_info {
147 struct sound_trigger_session_info st_ses;
148 bool lab_stopped;
149 struct listnode list;
150};
151
152struct sound_trigger_audio_device {
153 void *lib_handle;
154 struct audio_device *adev;
155 sound_trigger_hw_call_back_t st_callback;
156 struct listnode st_ses_list;
157 pthread_mutex_t lock;
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000158 unsigned int sthal_prop_api_version;
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700159};
160
161static struct sound_trigger_audio_device *st_dev;
162
163static struct sound_trigger_info *
164get_sound_trigger_info(int capture_handle)
165{
166 struct sound_trigger_info *st_ses_info = NULL;
167 struct listnode *node;
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000168 ALOGV("%s: list empty %d capture_handle %d", __func__,
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700169 list_empty(&st_dev->st_ses_list), capture_handle);
170 list_for_each(node, &st_dev->st_ses_list) {
171 st_ses_info = node_to_item(node, struct sound_trigger_info , list);
172 if (st_ses_info->st_ses.capture_handle == capture_handle)
173 return st_ses_info;
174 }
175 return NULL;
176}
177
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000178static int populate_usecase(struct audio_hal_usecase *usecase,
179 struct audio_usecase *uc_info)
180{
181 int status = 0;
182
183 switch (uc_info->type) {
184 case PCM_PLAYBACK:
185 if (uc_info->id == USECASE_AUDIO_PLAYBACK_VOIP)
186 usecase->type = USECASE_TYPE_VOIP_CALL;
187 else
188 usecase->type = USECASE_TYPE_PCM_PLAYBACK;
189 break;
190
191 case PCM_CAPTURE:
192 if (uc_info->id == USECASE_AUDIO_RECORD_VOIP)
193 usecase->type = USECASE_TYPE_VOIP_CALL;
194 else
195 usecase->type = USECASE_TYPE_PCM_CAPTURE;
196 break;
197
198 case VOICE_CALL:
199 usecase->type = USECASE_TYPE_VOICE_CALL;
200 break;
201
202 default:
203 ALOGE("%s: unsupported usecase type %d", __func__, uc_info->type);
204 status = -EINVAL;
205 }
206 return status;
207}
208
Haynes Mathew Georgeceafc552017-05-24 15:44:23 -0700209static void stdev_snd_mon_cb(void * stream __unused, struct str_parms * parms)
210{
211 if (!parms)
212 return;
213
214 audio_extn_sound_trigger_set_parameters(NULL, parms);
215 return;
216}
217
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700218int audio_hw_call_back(sound_trigger_event_type_t event,
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000219 struct sound_trigger_event_info* config)
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700220{
221 int status = 0;
222 struct sound_trigger_info *st_ses_info;
223
224 if (!st_dev)
225 return -EINVAL;
226
227 pthread_mutex_lock(&st_dev->lock);
228 switch (event) {
229 case ST_EVENT_SESSION_REGISTER:
230 if (!config) {
231 ALOGE("%s: NULL config", __func__);
232 status = -EINVAL;
233 break;
234 }
235 st_ses_info= calloc(1, sizeof(struct sound_trigger_info ));
236 if (!st_ses_info) {
237 ALOGE("%s: st_ses_info alloc failed", __func__);
238 status = -ENOMEM;
239 break;
240 }
241 memcpy(&st_ses_info->st_ses, &config->st_ses, sizeof (config->st_ses));
242 ALOGV("%s: add capture_handle %d pcm %p", __func__,
243 st_ses_info->st_ses.capture_handle, st_ses_info->st_ses.pcm);
244 list_add_tail(&st_dev->st_ses_list, &st_ses_info->list);
245 break;
246
247 case ST_EVENT_SESSION_DEREGISTER:
248 if (!config) {
249 ALOGE("%s: NULL config", __func__);
250 status = -EINVAL;
251 break;
252 }
253 st_ses_info = get_sound_trigger_info(config->st_ses.capture_handle);
254 if (!st_ses_info) {
255 ALOGE("%s: pcm %p not in the list!", __func__, config->st_ses.pcm);
256 status = -EINVAL;
257 break;
258 }
259 ALOGV("%s: remove capture_handle %d pcm %p", __func__,
260 st_ses_info->st_ses.capture_handle, st_ses_info->st_ses.pcm);
261 list_remove(&st_ses_info->list);
262 free(st_ses_info);
263 break;
264 default:
265 ALOGW("%s: Unknown event %d", __func__, event);
266 break;
267 }
268 pthread_mutex_unlock(&st_dev->lock);
269 return status;
270}
271
272int audio_extn_sound_trigger_read(struct stream_in *in, void *buffer,
273 size_t bytes)
274{
275 int ret = -1;
276 struct sound_trigger_info *st_info = NULL;
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000277 struct audio_event_info event;
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700278
279 if (!st_dev)
280 return ret;
281
282 if (!in->is_st_session_active) {
283 ALOGE(" %s: Sound trigger is not active", __func__);
284 goto exit;
285 }
286 if (in->standby)
287 in->standby = false;
288
289 pthread_mutex_lock(&st_dev->lock);
290 st_info = get_sound_trigger_info(in->capture_handle);
291 pthread_mutex_unlock(&st_dev->lock);
292 if (st_info) {
293 event.u.aud_info.ses_info = &st_info->st_ses;
294 event.u.aud_info.buf = buffer;
295 event.u.aud_info.num_bytes = bytes;
296 ret = st_dev->st_callback(AUDIO_EVENT_READ_SAMPLES, &event);
297 }
298
299exit:
300 if (ret) {
301 if (-ENETRESET == ret)
302 in->is_st_session_active = false;
303 memset(buffer, 0, bytes);
304 ALOGV("%s: read failed status %d - sleep", __func__, ret);
305 usleep((bytes * 1000000) / (audio_stream_in_frame_size((struct audio_stream_in *)in) *
306 in->config.rate));
307 }
308 return ret;
309}
310
311void audio_extn_sound_trigger_stop_lab(struct stream_in *in)
312{
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700313 struct sound_trigger_info *st_ses_info = NULL;
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000314 struct audio_event_info event;
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700315
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000316 if (!st_dev || !in || !in->is_st_session_active)
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700317 return;
318
319 pthread_mutex_lock(&st_dev->lock);
320 st_ses_info = get_sound_trigger_info(in->capture_handle);
321 pthread_mutex_unlock(&st_dev->lock);
322 if (st_ses_info) {
323 event.u.ses_info = st_ses_info->st_ses;
324 ALOGV("%s: AUDIO_EVENT_STOP_LAB pcm %p", __func__, st_ses_info->st_ses.pcm);
325 st_dev->st_callback(AUDIO_EVENT_STOP_LAB, &event);
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000326 in->is_st_session_active = false;
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700327 }
328}
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000329
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700330void audio_extn_sound_trigger_check_and_get_session(struct stream_in *in)
331{
332 struct sound_trigger_info *st_ses_info = NULL;
333 struct listnode *node;
334
335 if (!st_dev || !in)
336 return;
337
338 pthread_mutex_lock(&st_dev->lock);
339 in->is_st_session = false;
340 ALOGV("%s: list %d capture_handle %d", __func__,
341 list_empty(&st_dev->st_ses_list), in->capture_handle);
342 list_for_each(node, &st_dev->st_ses_list) {
343 st_ses_info = node_to_item(node, struct sound_trigger_info , list);
344 if (st_ses_info->st_ses.capture_handle == in->capture_handle) {
345 in->pcm = st_ses_info->st_ses.pcm;
346 in->config = st_ses_info->st_ses.config;
347 in->channel_mask = audio_channel_in_mask_from_count(in->config.channels);
348 in->is_st_session = true;
349 in->is_st_session_active = true;
Joe Onorato188b6222016-03-01 11:02:27 -0800350 ALOGV("%s: capture_handle %d is sound trigger", __func__, in->capture_handle);
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700351 break;
352 }
353 }
354 pthread_mutex_unlock(&st_dev->lock);
355}
356
357void audio_extn_sound_trigger_update_device_status(snd_device_t snd_device,
358 st_event_type_t event)
359{
360 int device_type = -1;
361
362 if (!st_dev)
363 return;
364
365 if (snd_device >= SND_DEVICE_OUT_BEGIN &&
Ravi Kumar Alamanda888dc3d2015-10-01 15:53:33 -0700366 snd_device < SND_DEVICE_OUT_END) {
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700367 device_type = PCM_PLAYBACK;
Ravi Kumar Alamanda888dc3d2015-10-01 15:53:33 -0700368 } else if (snd_device >= SND_DEVICE_IN_BEGIN &&
369 snd_device < SND_DEVICE_IN_END) {
370 if (snd_device == SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)
371 return;
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700372 device_type = PCM_CAPTURE;
Ravi Kumar Alamanda888dc3d2015-10-01 15:53:33 -0700373 } else {
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700374 ALOGE("%s: invalid device 0x%x, for event %d",
375 __func__, snd_device, event);
376 return;
377 }
378
Joe Onorato188b6222016-03-01 11:02:27 -0800379 ALOGV("%s: device 0x%x of type %d for Event %d",
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700380 __func__, snd_device, device_type, event);
381 if (device_type == PCM_CAPTURE) {
382 switch(event) {
383 case ST_EVENT_SND_DEVICE_FREE:
384 st_dev->st_callback(AUDIO_EVENT_CAPTURE_DEVICE_INACTIVE, NULL);
385 break;
386 case ST_EVENT_SND_DEVICE_BUSY:
387 st_dev->st_callback(AUDIO_EVENT_CAPTURE_DEVICE_ACTIVE, NULL);
388 break;
389 default:
390 ALOGW("%s:invalid event %d for device 0x%x",
391 __func__, event, snd_device);
392 }
393 }/*Events for output device, if required can be placed here in else*/
394}
395
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000396void audio_extn_sound_trigger_update_stream_status(struct audio_usecase *uc_info,
397 st_event_type_t event)
398{
399 bool raise_event = false;
400 struct audio_event_info ev_info;
401 audio_event_type_t ev;
402
403 if (!st_dev)
404 return;
405
406 if (st_dev->sthal_prop_api_version < STHAL_PROP_API_VERSION_1_0)
407 return;
408
409 if (uc_info == NULL) {
410 ALOGE("%s: null usecase", __func__);
411 return;
412 }
413
414 bool valid_type =
415 (uc_info->type == PCM_PLAYBACK &&
416 platform_snd_device_has_speaker(uc_info->out_snd_device)) ||
417 (uc_info->type == PCM_CAPTURE) ||
418 (uc_info->type == VOICE_CALL);
419
420 if (valid_type && platform_sound_trigger_usecase_needs_event(uc_info->id)) {
421 ALOGV("%s: uc_id %d of type %d for Event %d, with Raise=%d",
422 __func__, uc_info->id, uc_info->type, event, raise_event);
423 if (uc_info->type == PCM_CAPTURE) {
424 ev = (event == ST_EVENT_STREAM_BUSY) ? AUDIO_EVENT_CAPTURE_STREAM_ACTIVE :
425 AUDIO_EVENT_CAPTURE_STREAM_INACTIVE;
426 } else {
427 ev = (event == ST_EVENT_STREAM_BUSY) ? AUDIO_EVENT_PLAYBACK_STREAM_ACTIVE :
428 AUDIO_EVENT_PLAYBACK_STREAM_INACTIVE;
429 }
430 if (!populate_usecase(&ev_info.u.usecase, uc_info)) {
431 ALOGI("%s: send event %d: usecase id %d, type %d",
432 __func__, ev, uc_info->id, uc_info->type);
433 st_dev->st_callback(ev, &ev_info);
434 }
435 }
436}
437
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700438void audio_extn_sound_trigger_set_parameters(struct audio_device *adev __unused,
439 struct str_parms *params)
440{
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000441 struct audio_event_info event;
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700442 char value[32];
443 int ret, val;
444
445 if(!st_dev || !params) {
446 ALOGE("%s: str_params NULL", __func__);
447 return;
448 }
449
450 ret = str_parms_get_str(params, "SND_CARD_STATUS", value,
451 sizeof(value));
452 if (ret > 0) {
453 if (strstr(value, "OFFLINE")) {
454 event.u.status = SND_CARD_STATUS_OFFLINE;
455 st_dev->st_callback(AUDIO_EVENT_SSR, &event);
456 }
457 else if (strstr(value, "ONLINE")) {
458 event.u.status = SND_CARD_STATUS_ONLINE;
459 st_dev->st_callback(AUDIO_EVENT_SSR, &event);
460 }
461 else
462 ALOGE("%s: unknown snd_card_status", __func__);
463 }
464
465 ret = str_parms_get_str(params, "CPE_STATUS", value, sizeof(value));
466 if (ret > 0) {
467 if (strstr(value, "OFFLINE")) {
468 event.u.status = CPE_STATUS_OFFLINE;
469 st_dev->st_callback(AUDIO_EVENT_SSR, &event);
470 }
471 else if (strstr(value, "ONLINE")) {
472 event.u.status = CPE_STATUS_ONLINE;
473 st_dev->st_callback(AUDIO_EVENT_SSR, &event);
474 }
475 else
476 ALOGE("%s: unknown CPE status", __func__);
477 }
478
479 ret = str_parms_get_int(params, "SVA_NUM_SESSIONS", &val);
480 if (ret >= 0) {
481 event.u.value = val;
482 st_dev->st_callback(AUDIO_EVENT_NUM_ST_SESSIONS, &event);
483 }
484}
485
486int audio_extn_sound_trigger_init(struct audio_device *adev)
487{
488 int status = 0;
489 char sound_trigger_lib[100];
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000490 void *sthal_prop_api_version;
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700491
Joe Onorato188b6222016-03-01 11:02:27 -0800492 ALOGV("%s: Enter", __func__);
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700493
494 st_dev = (struct sound_trigger_audio_device*)
495 calloc(1, sizeof(struct sound_trigger_audio_device));
496 if (!st_dev) {
497 ALOGE("%s: ERROR. sound trigger alloc failed", __func__);
498 return -ENOMEM;
499 }
500
501 snprintf(sound_trigger_lib, sizeof(sound_trigger_lib),
Andy Hung4bd229e2016-03-07 18:29:16 -0800502 SOUND_TRIGGER_LIBRARY_PATH,
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700503 XSTR(SOUND_TRIGGER_PLATFORM_NAME));
504
505 st_dev->lib_handle = dlopen(sound_trigger_lib, RTLD_NOW);
506
507 if (st_dev->lib_handle == NULL) {
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000508 ALOGE("%s: error %s", __func__, dlerror());
509 status = -ENODEV;
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700510 goto cleanup;
511 }
Joe Onorato188b6222016-03-01 11:02:27 -0800512 ALOGV("%s: DLOPEN successful for %s", __func__, sound_trigger_lib);
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700513
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000514 DLSYM(st_dev->lib_handle, st_dev->st_callback, sound_trigger_hw_call_back,
515 status);
516 if (status)
517 goto cleanup;
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700518
Mikhail Naganov4ee6e3e2018-03-21 16:28:35 +0000519 DLSYM(st_dev->lib_handle, sthal_prop_api_version,
520 sthal_prop_api_version, status);
521 if (status) {
522 st_dev->sthal_prop_api_version = 0;
523 status = 0; /* passthru for backward compability */
524 } else {
525 st_dev->sthal_prop_api_version = *(int*)sthal_prop_api_version;
526 if (MAJOR_VERSION(st_dev->sthal_prop_api_version) !=
527 MAJOR_VERSION(STHAL_PROP_API_CURRENT_VERSION)) {
528 ALOGE("%s: Incompatible API versions ahal:0x%x != sthal:0x%x",
529 __func__, STHAL_PROP_API_CURRENT_VERSION,
530 st_dev->sthal_prop_api_version);
531 goto cleanup;
532 }
533 ALOGD("%s: sthal is using proprietary API version 0x%04x", __func__,
534 st_dev->sthal_prop_api_version);
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700535 }
536
537 st_dev->adev = adev;
538 list_init(&st_dev->st_ses_list);
Haynes Mathew Georgeceafc552017-05-24 15:44:23 -0700539 audio_extn_snd_mon_register_listener(st_dev, stdev_snd_mon_cb);
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700540
541 return 0;
542
543cleanup:
544 if (st_dev->lib_handle)
545 dlclose(st_dev->lib_handle);
546 free(st_dev);
547 st_dev = NULL;
548 return status;
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700549}
550
551void audio_extn_sound_trigger_deinit(struct audio_device *adev)
552{
Joe Onorato188b6222016-03-01 11:02:27 -0800553 ALOGV("%s: Enter", __func__);
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700554 if (st_dev && (st_dev->adev == adev) && st_dev->lib_handle) {
Haynes Mathew Georgeceafc552017-05-24 15:44:23 -0700555 audio_extn_snd_mon_unregister_listener(st_dev);
Ravi Kumar Alamandaa417cc52015-05-01 16:41:56 -0700556 dlclose(st_dev->lib_handle);
557 free(st_dev);
558 st_dev = NULL;
559 }
560}