audio: Support for compress offload recovery

- Add support to return error for compress time stamp query
  during SSR

 CRs-Fixed: 683288

Change-Id: Ie6849bbd3de9474fa556bfe4b183a10a44e4b3e8
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 4e33dfb..d3b41aa 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2027,6 +2027,7 @@
                                    uint32_t *dsp_frames)
 {
     struct stream_out *out = (struct stream_out *)stream;
+    struct audio_device *adev = out->dev;
     if (is_offload_usecase(out->usecase) && (dsp_frames != NULL)) {
         ssize_t ret = 0;
         *dsp_frames = 0;
@@ -2047,6 +2048,13 @@
         } else if(ret < 0) {
             ALOGE(" ERROR: Unable to get time stamp from compress driver");
             return -EINVAL;
+        } else if (get_snd_card_state(adev) == SND_CARD_STATE_OFFLINE){
+            /*
+             * Handle corner case where compress session is closed during SSR
+             * and timestamp is queried
+             */
+            ALOGE(" ERROR: sound card not active, return error");
+            return -EINVAL;
         } else {
             return 0;
         }
@@ -2083,12 +2091,20 @@
 
     if (is_offload_usecase(out->usecase)) {
         if (out->compr != NULL) {
-            compress_get_tstamp(out->compr, &dsp_frames,
+            ret = compress_get_tstamp(out->compr, &dsp_frames,
                     &out->sample_rate);
             ALOGVV("%s rendered frames %ld sample_rate %d",
                    __func__, dsp_frames, out->sample_rate);
             *frames = dsp_frames;
-            ret = 0;
+            if (ret < 0)
+                ret = -errno;
+            if (-ENETRESET == ret) {
+                ALOGE(" ERROR: sound card not active Unable to get time stamp from compress driver");
+                set_snd_card_state(adev,SND_CARD_STATE_OFFLINE);
+                ret = -EINVAL;
+            } else
+                ret = 0;
+
             /* this is the best we can do */
             clock_gettime(CLOCK_MONOTONIC, timestamp);
         }