hal: VoIP call auto recovery if SSR happens during call

Add support for VoIP call auto recovery if subsystem
restart(SSR) happens during VoIP call.

Change-Id: I5617c22b79548de668b28a97c116008e7c704dee
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index c1d237c..74e03e1 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -1778,6 +1778,10 @@
     if (ret != 0) {
         if (out->pcm)
             ALOGE("%s: error %d - %s", __func__, ret, pcm_get_error(out->pcm));
+        if (out->usecase == USECASE_COMPRESS_VOIP_CALL) {
+            voice_extn_compress_voip_close_output_stream(&out->stream.common);
+            out->standby = true;
+        }
         out_standby(&out->stream.common);
         usleep(bytes * 1000000 / audio_stream_frame_size(&out->stream.common) /
                         out_get_sample_rate(&out->stream.common));
@@ -2184,6 +2188,10 @@
     pthread_mutex_unlock(&in->lock);
 
     if (ret != 0) {
+        if (in->usecase == USECASE_COMPRESS_VOIP_CALL) {
+            voice_extn_compress_voip_close_input_stream(&in->stream.common);
+            in->standby = true;
+        }
         in_standby(&in->stream.common);
         ALOGV("%s: read failed - sleeping for buffer duration", __func__);
         usleep(bytes * 1000000 / audio_stream_frame_size(&in->stream.common) /
diff --git a/hal/voice_extn/compress_voip.c b/hal/voice_extn/compress_voip.c
index deb3172..f428f2b 100644
--- a/hal/voice_extn/compress_voip.c
+++ b/hal/voice_extn/compress_voip.c
@@ -561,6 +561,9 @@
 
     ALOGD("%s: enter", __func__);
 
+    if (!voip_data.out_stream_count)
+        ret = voice_extn_compress_voip_open_output_stream(out);
+
     ret = voip_start_call(adev, &out->config);
     out->pcm = voip_data.pcm_rx;
     uc_info = get_usecase_from_list(adev, USECASE_COMPRESS_VOIP_CALL);
@@ -579,6 +582,9 @@
 
     ALOGD("%s: enter", __func__);
 
+    if (!voip_data.in_stream_count)
+        ret = voice_extn_compress_voip_open_input_stream(in);
+
     ret = voip_start_call(adev, &in->config);
     in->pcm = voip_data.pcm_tx;
 
@@ -593,10 +599,11 @@
     int ret = 0;
 
     ALOGD("%s: enter", __func__);
-
-    voip_data.out_stream_count--;
-    ret = voip_stop_call(adev);
-    voip_data.out_stream = NULL;
+    if (voip_data.out_stream_count > 0) {
+        voip_data.out_stream_count--;
+        ret = voip_stop_call(adev);
+        voip_data.out_stream = NULL;
+    }
 
     ALOGV("%s: exit: status(%d)", __func__, ret);
     return ret;
@@ -633,12 +640,13 @@
 
     ALOGD("%s: enter", __func__);
 
-    voip_data.in_stream_count--;
-    status = voip_stop_call(adev);
+    if(voip_data.in_stream_count > 0) {
+       voip_data.in_stream_count--;
+       status = voip_stop_call(adev);
+    }
 
     ALOGV("%s: exit: status(%d)", __func__, status);
     return status;
-
 }
 
 int voice_extn_compress_voip_open_input_stream(struct stream_in *in)