Merge remote-tracking branch 'quic/LA.BR.1' into HEAD

* quic/LA.BR.1: (37 commits)
  hal: Performance mode during recording usecase
  audio: Support for compress offload recovery
  audio: Fix for clip skip issue during SSR
  hal: add checks for calibration buffer allocation failures
  mm-audio: aenc-aac: fix integer overflow for encoded buffer timestamp calculation
  hal: Add support for 8909 QRD skue
  hal: Fix for FM mute issue on start of FM record
  hal: Fix array length computation for backend id array.
  hal : set Non SA+ app type for PCM Capture
  hal : Fix for SA+ app type selection for PCM Capture usecase
  hal : Fix for SA+ app type selection for PCM Capture usecase
  hal: use 0 as default return value for out_get_render_position
  audio: hal: Add support for pm8916 on msm8909
  hal: Define a new combo device for AANC and Fluence
  hal: Define a new combo device for AANC and Fluence
  hal: use 0 as default return value for out_get_render_position
  hal: Update DS2 implementation to support ACDB based license mechanism
  hal : Overwrite the APP type for PCM RX and TX path
  audio: HAL to support for peripheral manager
  hal : Set the input device for VOIP calls using audio path
  ...
Conflicts:
	hal/Android.mk
	hal/audio_extn/audio_extn.c
	hal/audio_extn/audio_extn.h
	hal/audio_extn/dolby.c
	hal/audio_extn/utils.c
	hal/audio_hw.c
	hal/msm8916/hw_info.c
	hal/msm8916/platform.c
	hal/msm8974/platform.c
	hal/platform_api.h
Change-Id: Ibfa171e8f3af713dbb2cffbaf2ca2b0df3e8ae73
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 3750945..977f77e 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -1210,17 +1210,21 @@
             ret = compress_next_track(out->compr);
             if(ret == 0) {
                 ALOGD("copl(%p):calling compress_partial_drain", out);
-                compress_partial_drain(out->compr);
+                ret = compress_partial_drain(out->compr);
                 ALOGD("copl(%p):out of compress_partial_drain", out);
+                if (ret < 0)
+                    ret = -errno;
             }
-            else if(ret == -ETIMEDOUT)
+            else if (ret == -ETIMEDOUT)
                 compress_drain(out->compr);
             else
                 ALOGE("%s: Next track returned error %d",__func__, ret);
-            send_callback = true;
-            event = STREAM_CBK_EVENT_DRAIN_READY;
-            /* Resend the metadata for next iteration */
-            out->send_new_metadata = 1;
+            if (ret != -ENETRESET) {
+                send_callback = true;
+                event = STREAM_CBK_EVENT_DRAIN_READY;
+                ALOGV("copl(%p):send drain callback, ret %d", out, ret);
+            } else
+                ALOGE("%s: Block drain ready event during SSR", __func__);
             break;
         case OFFLOAD_CMD_DRAIN:
             ALOGD("copl(%p):calling compress_drain", out);
@@ -2164,6 +2168,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;
@@ -2184,6 +2189,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;
         }
@@ -2220,12 +2232,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);
         }