hal: stop sound trigger buffering during close

If the framework doesn't call read before standby and closes the
record session, sound trigger buffering will not be stopped and
sound trigger hal continue buffering internally. Fix this by
stopping buffering during record session close.

Change-Id: I83941610b3152f26e5ae9c449dbb8f9846b266a2
CRs-fixed: 966060
diff --git a/hal/audio_extn/soundtrigger.c b/hal/audio_extn/soundtrigger.c
index 3c16c88..8882b90 100644
--- a/hal/audio_extn/soundtrigger.c
+++ b/hal/audio_extn/soundtrigger.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2013-2014, 2016 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
@@ -174,7 +174,7 @@
     struct sound_trigger_info  *st_ses_info = NULL;
     audio_event_info_t event;
 
-    if (!st_dev || !in)
+    if (!st_dev || !in || !in->is_st_session_active)
        return;
 
     pthread_mutex_lock(&st_dev->lock);
@@ -184,6 +184,7 @@
         event.u.ses_info = st_ses_info->st_ses;
         ALOGV("%s: AUDIO_EVENT_STOP_LAB pcm %p", __func__, st_ses_info->st_ses.pcm);
         st_dev->st_callback(AUDIO_EVENT_STOP_LAB, &event);
+        in->is_st_session_active = false;
     }
 }
 void audio_extn_sound_trigger_check_and_get_session(struct stream_in *in)
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 7ee27f5..fc7c84e 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -3834,6 +3834,10 @@
             audio_extn_compr_cap_format_supported(in->config.format))
         audio_extn_compr_cap_deinit();
 
+    if (in->is_st_session) {
+        ALOGV("%s: sound trigger pcm stop lab", __func__);
+        audio_extn_sound_trigger_stop_lab(in);
+    }
     free(stream);
     return;
 }