Merge "hal: Enhance VoIP call auto recovery if SSR occurs during call"
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 74e03e1..d8c48b9 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -237,7 +237,7 @@
     return id;
 }
 
-static int get_snd_card_state(struct audio_device *adev)
+int get_snd_card_state(struct audio_device *adev)
 {
     int snd_scard_state;
 
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index d782078..e537377 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -303,6 +303,8 @@
 
 int pcm_ioctl(struct pcm *pcm, int request, ...);
 
+int get_snd_card_state(struct audio_device *adev);
+
 #define LITERAL_TO_STRING(x) #x
 #define CHECK(condition) LOG_ALWAYS_FATAL_IF(!(condition), "%s",\
             __FILE__ ":" LITERAL_TO_STRING(__LINE__)\
diff --git a/hal/voice_extn/compress_voip.c b/hal/voice_extn/compress_voip.c
index f428f2b..841f866 100644
--- a/hal/voice_extn/compress_voip.c
+++ b/hal/voice_extn/compress_voip.c
@@ -558,9 +558,16 @@
     int ret = 0;
     struct audio_device *adev = out->dev;
     struct audio_usecase *uc_info;
+    int snd_card_status = get_snd_card_state(adev);
 
     ALOGD("%s: enter", __func__);
 
+    if (SND_CARD_STATE_OFFLINE == snd_card_status) {
+        ret = -ENETRESET;
+        ALOGE("%s: sound card is not active/SSR returning error %d ", __func__, ret);
+        goto error;
+    }
+
     if (!voip_data.out_stream_count)
         ret = voice_extn_compress_voip_open_output_stream(out);
 
@@ -570,6 +577,7 @@
     uc_info->stream.out = out;
     uc_info->devices = out->devices;
 
+error:
     ALOGV("%s: exit: status(%d)", __func__, ret);
     return ret;
 }
@@ -579,15 +587,23 @@
     int ret = 0;
     struct audio_usecase *uc_info;
     struct audio_device *adev = in->dev;
+    int snd_card_status = get_snd_card_state(adev);
 
     ALOGD("%s: enter", __func__);
 
+    if (SND_CARD_STATE_OFFLINE == snd_card_status) {
+        ret = -ENETRESET;
+        ALOGE("%s: sound card is not active/SSR returning error %d ", __func__, ret);
+        goto error;
+    }
+
     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;
 
+error:
     ALOGV("%s: exit: status(%d)", __func__, ret);
     return ret;
 }
@@ -603,6 +619,7 @@
         voip_data.out_stream_count--;
         ret = voip_stop_call(adev);
         voip_data.out_stream = NULL;
+        out->pcm = NULL;
     }
 
     ALOGV("%s: exit: status(%d)", __func__, ret);
@@ -643,6 +660,7 @@
     if(voip_data.in_stream_count > 0) {
        voip_data.in_stream_count--;
        status = voip_stop_call(adev);
+       in->pcm = NULL;
     }
 
     ALOGV("%s: exit: status(%d)", __func__, status);