summaryrefslogtreecommitdiff
path: root/sound_trigger_hw_iaxxx.c
diff options
context:
space:
mode:
authorrioskao <rioskao@google.com>2020-02-03 20:28:21 +0800
committerrioskao <rioskao@google.com>2020-02-07 15:49:26 +0800
commitb13c249fab439469981491633df0f2a5ca88de79 (patch)
treeb1d780e12d835e24b7a8ae3ace4c34f3416dfc6d /sound_trigger_hw_iaxxx.c
parent3012c22051428e89285dac13f1dc2a034115234d (diff)
downloadsound_trigger_hal-b13c249fab439469981491633df0f2a5ca88de79.tar.gz
sthal: avoid deadlock when recognition callback
note: -Should release stdev_lock when processing recognition event. The callback function would hold lock in SoundTrigger framework. Sometimes, ST framework processes the function_call from client side that hold lock in ST framework too. That causes deadlock condition in STHAL and ST framework. -Remove useless parameter. bug: 148666532 Test: stress recoginition trigger for hotword and ambient Change-Id: I47826d59551f07ac765dfd1378b9fb8dbddbace5
Diffstat (limited to 'sound_trigger_hw_iaxxx.c')
-rw-r--r--sound_trigger_hw_iaxxx.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/sound_trigger_hw_iaxxx.c b/sound_trigger_hw_iaxxx.c
index b8f4c24..953a291 100644
--- a/sound_trigger_hw_iaxxx.c
+++ b/sound_trigger_hw_iaxxx.c
@@ -142,7 +142,6 @@ struct knowles_sound_trigger_device {
int opened;
int send_sock;
int recv_sock;
- struct sound_trigger_recognition_config *last_keyword_detected_config;
// Information about streaming
int is_streaming;
@@ -2514,11 +2513,13 @@ static void *callback_thread_loop(void *context)
ALOGD("Sending recognition callback for id %d",
kwid);
+ /* Exit the critical section of interaction with
+ * firmware, release the lock to avoid deadlock
+ * when processing recognition event */
+ pthread_mutex_unlock(&stdev->lock);
model->recognition_callback(&event->common,
model->recognition_cookie);
- // Update the config so that it will be used
- // during the streaming
- stdev->last_keyword_detected_config = model->config;
+ pthread_mutex_lock(&stdev->lock);
free(event);
} else {
@@ -2538,12 +2539,13 @@ static void *callback_thread_loop(void *context)
ALOGD("Sending recognition callback for id %d",
kwid);
+ /* Exit the critical section of interaction with
+ * firmware, release the lock to avoid deadlock
+ * when processing recognition event */
+ pthread_mutex_unlock(&stdev->lock);
model->recognition_callback(&event->common,
model->recognition_cookie);
- // Update the config so that it will be used
- // during the streaming
- stdev->last_keyword_detected_config = model->config;
-
+ pthread_mutex_lock(&stdev->lock);
free(event);
} else {
ALOGE("Failed to allocate memory for the event");
@@ -3217,20 +3219,6 @@ exit:
return ret;
}
-__attribute__ ((visibility ("default")))
-audio_io_handle_t stdev_get_audio_handle()
-{
- if (g_stdev.last_keyword_detected_config == NULL) {
- ALOGI("%s: Config is NULL so returning audio handle as 0", __func__);
- return 0;
- }
-
- ALOGI("%s: Audio Handle is %d",
- __func__, g_stdev.last_keyword_detected_config->capture_handle);
-
- return g_stdev.last_keyword_detected_config->capture_handle;
-}
-
static int open_streaming_lib(struct knowles_sound_trigger_device *stdev) {
int ret = 0;
@@ -3499,7 +3487,6 @@ static int stdev_open(const hw_module_t *module, const char *name,
stdev->models[i].data_sz = 0;
stdev->models[i].is_loaded = false;
stdev->models[i].is_active = false;
- stdev->last_keyword_detected_config = NULL;
stdev->models[i].is_state_query = false;
}
@@ -3843,6 +3830,12 @@ int sound_trigger_hw_call_back(audio_event_type_t event,
}
}
+ /* There is not valid model to provide pcm samples. */
+ if (i == MAX_MODELS) {
+ ret = -EINVAL;
+ goto exit;
+ }
+
/* Open Stream Driver */
if (index != -1 && stdev->adnc_strm_handle[index] == 0) {
if (stdev->adnc_strm_open == NULL) {