Merge "hal: Use correct param for loopback set param" into audio-hal.lnx.5.1
diff --git a/hal/audio_extn/keep_alive.c b/hal/audio_extn/keep_alive.c
index ce2cbda..90875d9 100644
--- a/hal/audio_extn/keep_alive.c
+++ b/hal/audio_extn/keep_alive.c
@@ -120,7 +120,7 @@
     ka.state = STATE_IDLE;
     ka.pcm = NULL;
     pthread_condattr_t attr;
-    if (property_get_bool("vendor.audio.keep_alive.disabled", false)) {
+    if (property_get_bool("vendor.audio.keep_alive.disabled", true)) {
         ALOGE("keep alive disabled");
         ka.state = STATE_DISABLED;
         return;
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 1594be2..79be457 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2143,13 +2143,14 @@
                 out_snd_device = platform_get_output_snd_device(adev->platform,
                                             usecase->stream.out);
                 voip_usecase = get_usecase_from_list(adev, USECASE_AUDIO_PLAYBACK_VOIP);
-                if (voip_usecase == NULL)
+                if (voip_usecase == NULL && adev->primary_output && !adev->primary_output->standby)
                     voip_usecase = get_usecase_from_list(adev, adev->primary_output->usecase);
 
                 if ((usecase->stream.out != NULL &&
                      voip_usecase != NULL &&
                      usecase->stream.out->usecase == voip_usecase->id) &&
                     adev->active_input &&
+                    adev->active_input->source == AUDIO_SOURCE_VOICE_COMMUNICATION &&
                     out_snd_device != usecase->out_snd_device) {
                     select_devices(adev, adev->active_input->usecase);
                 }
diff --git a/mm-audio/aenc-aac/qdsp6/test/omx_aac_enc_test.c b/mm-audio/aenc-aac/qdsp6/test/omx_aac_enc_test.c
index 97b7617..967a7e3 100644
--- a/mm-audio/aenc-aac/qdsp6/test/omx_aac_enc_test.c
+++ b/mm-audio/aenc-aac/qdsp6/test/omx_aac_enc_test.c
@@ -278,12 +278,6 @@
         status = -1;
         goto exit;
     }
-    ptr = (char *)malloc(strlen(input) + 1);
-    if (ptr == NULL) {
-        DEBUG_PRINT("Low memory\n");
-        status = -1;
-        goto exit;
-    }
     /* Check for negative input */
     if (*input == '-') {
         DEBUG_PRINT("Negative Number is not allowed\n");
@@ -322,8 +316,6 @@
             break;
     }
 exit:
-    if (ptr != NULL)
-        free(ptr);
     if (status != 0)
         exit(0);
     return value;
diff --git a/mm-audio/aenc-evrc/qdsp6/test/omx_evrc_enc_test.c b/mm-audio/aenc-evrc/qdsp6/test/omx_evrc_enc_test.c
index 8c89e61..d1b4837 100644
--- a/mm-audio/aenc-evrc/qdsp6/test/omx_evrc_enc_test.c
+++ b/mm-audio/aenc-evrc/qdsp6/test/omx_evrc_enc_test.c
@@ -291,12 +291,6 @@
         status = -1;
         goto exit;
     }
-    ptr = (char *)malloc(strlen(input) + 1);
-    if (ptr == NULL) {
-        DEBUG_PRINT("Low memory\n");
-        status = -1;
-        goto exit;
-    }
     /* Check for negative input */
     if (*input == '-') {
         DEBUG_PRINT("Negative Number is not allowed\n");
@@ -335,8 +329,6 @@
             break;
     }
 exit:
-    if (ptr != NULL)
-        free(ptr);
     if (status != 0)
         exit(0);
     return value;
diff --git a/mm-audio/aenc-qcelp13/qdsp6/test/omx_qcelp13_enc_test.c b/mm-audio/aenc-qcelp13/qdsp6/test/omx_qcelp13_enc_test.c
index d5ec4c7..f35af33 100644
--- a/mm-audio/aenc-qcelp13/qdsp6/test/omx_qcelp13_enc_test.c
+++ b/mm-audio/aenc-qcelp13/qdsp6/test/omx_qcelp13_enc_test.c
@@ -290,12 +290,6 @@
         status = -1;
         goto exit;
     }
-    ptr = (char *)malloc(strlen(input) + 1);
-    if (ptr == NULL) {
-        DEBUG_PRINT("Low memory\n");
-        status = -1;
-        goto exit;
-    }
     /* Check for negative input */
     if (*input == '-') {
         DEBUG_PRINT("Negative Number is not allowed\n");
@@ -334,8 +328,6 @@
             break;
     }
 exit:
-    if (ptr != NULL)
-        free(ptr);
     if (status != 0)
         exit(0);
     return value;
diff --git a/post_proc/bass_boost.c b/post_proc/bass_boost.c
index 68cd46f..02c68d4 100644
--- a/post_proc/bass_boost.c
+++ b/post_proc/bass_boost.c
@@ -32,6 +32,8 @@
 #include "effect_api.h"
 #include "bass_boost.h"
 
+#define BASSBOOST_MAX_LATENCY 30
+
 /* Offload bassboost UUID: 2c4a8c24-1581-487f-94f6-0002a5d5c51b */
 const effect_descriptor_t bassboost_descriptor = {
         {0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
@@ -101,6 +103,11 @@
            p->status = -EINVAL;
         p->vsize = sizeof(int16_t);
         break;
+    case BASSBOOST_PARAM_LATENCY:
+        if (p->vsize < sizeof(uint32_t))
+           p->status = -EINVAL;
+        p->vsize = sizeof(uint32_t);
+        break;
     default:
         p->status = -EINVAL;
     }
@@ -127,6 +134,10 @@
             *(int16_t *)value = 0;
         break;
 
+    case BASSBOOST_PARAM_LATENCY:
+        *(uint32_t *)value = BASSBOOST_MAX_LATENCY;
+        break;
+
     default:
         p->status = -EINVAL;
         break;
diff --git a/post_proc/bass_boost.h b/post_proc/bass_boost.h
index 8bf51d3..ff674d4 100644
--- a/post_proc/bass_boost.h
+++ b/post_proc/bass_boost.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2015, 2018, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -20,6 +20,8 @@
 #ifndef OFFLOAD_EFFECT_BASS_BOOST_H_
 #define OFFLOAD_EFFECT_BASS_BOOST_H_
 
+#define BASSBOOST_PARAM_LATENCY 0x80000000
+
 #include "bundle.h"
 
 enum {
diff --git a/post_proc/equalizer.c b/post_proc/equalizer.c
index c1c1303..479f848 100644
--- a/post_proc/equalizer.c
+++ b/post_proc/equalizer.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2014, 2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2014, 2017-2018, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -29,6 +29,8 @@
 #include "effect_api.h"
 #include "equalizer.h"
 
+#define EQUALIZER_MAX_LATENCY 0
+
 /* Offload equalizer UUID: a0dac280-401c-11e3-9379-0002a5d5c51b */
 const effect_descriptor_t equalizer_descriptor = {
         {0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type
@@ -253,6 +255,12 @@
         p->vsize = (2 + NUM_EQ_BANDS) * sizeof(uint16_t);
         break;
 
+    case EQ_PARAM_LATENCY:
+        if (p->vsize < sizeof(uint32_t))
+           p->status = -EINVAL;
+        p->vsize = sizeof(uint32_t);
+        break;
+
     default:
         p->status = -EINVAL;
     }
@@ -352,6 +360,10 @@
         }
     } break;
 
+    case EQ_PARAM_LATENCY:
+        *(uint32_t *)value = EQUALIZER_MAX_LATENCY;
+        break;
+
     default:
         p->status = -EINVAL;
         break;
diff --git a/post_proc/equalizer.h b/post_proc/equalizer.h
index 7fec058..2cd06c2 100644
--- a/post_proc/equalizer.h
+++ b/post_proc/equalizer.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2014, 2018, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -26,6 +26,8 @@
 #define INVALID_PRESET		 -2
 #define PRESET_CUSTOM		 -1
 
+#define EQ_PARAM_LATENCY 0x80000000
+
 extern const effect_descriptor_t equalizer_descriptor;
 
 typedef struct equalizer_context_s {
diff --git a/post_proc/reverb.c b/post_proc/reverb.c
index e97b651..a0a0441 100644
--- a/post_proc/reverb.c
+++ b/post_proc/reverb.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 - 2014, 2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013 - 2014, 2017-2018, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -30,6 +30,8 @@
 #include "effect_api.h"
 #include "reverb.h"
 
+#define REVERB_MAX_LATENCY 100
+
 /* Offload auxiliary environmental reverb UUID: 79a18026-18fd-4185-8233-0002a5d5c51b */
 const effect_descriptor_t aux_env_reverb_descriptor = {
         { 0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, { 0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e } },
@@ -522,6 +524,11 @@
            p->status = -EINVAL;
         p->vsize = sizeof(reverb_settings_t);
         break;
+    case REVERB_PARAM_LATENCY:
+        if (p->vsize < sizeof(uint32_t))
+            return -EINVAL;
+        p->vsize = sizeof(uint32_t);
+        break;
     default:
         p->status = -EINVAL;
     }
@@ -575,6 +582,9 @@
         reverb_settings->diffusion = reverb_get_diffusion(reverb_ctxt);
         reverb_settings->density = reverb_get_density(reverb_ctxt);
         break;
+    case REVERB_PARAM_LATENCY:
+        *(uint16_t *)value = REVERB_MAX_LATENCY;
+        break;
     default:
         p->status = -EINVAL;
         break;
diff --git a/post_proc/reverb.h b/post_proc/reverb.h
index 3bdd9af..cc11c46 100644
--- a/post_proc/reverb.h
+++ b/post_proc/reverb.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2014, 2018, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -24,6 +24,8 @@
 
 #define REVERB_DEFAULT_PRESET REVERB_PRESET_NONE
 
+#define REVERB_PARAM_LATENCY 0x80000000
+
 extern const effect_descriptor_t aux_env_reverb_descriptor;
 extern const effect_descriptor_t ins_env_reverb_descriptor;
 extern const effect_descriptor_t aux_preset_reverb_descriptor;
diff --git a/post_proc/virtualizer.c b/post_proc/virtualizer.c
index dfa7691..578cf0b 100644
--- a/post_proc/virtualizer.c
+++ b/post_proc/virtualizer.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2015, 2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2015, 2017-2018, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -29,6 +29,8 @@
 #include "effect_api.h"
 #include "virtualizer.h"
 
+#define VIRUALIZER_MAX_LATENCY 30
+
 /* Offload Virtualizer UUID: 509a4498-561a-4bea-b3b1-0002a5d5c51b */
 const effect_descriptor_t virtualizer_descriptor = {
         {0x37cc2c00, 0xdddd, 0x11db, 0x8577, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
@@ -304,6 +306,11 @@
            p->status = -EINVAL;
         p->vsize = sizeof(uint32_t);
         break;
+    case VIRTUALIZER_PARAM_LATENCY:
+        if (p->vsize < sizeof(uint32_t))
+            p->status = -EINVAL;
+        p->vsize = sizeof(uint32_t);
+        break;
     default:
         p->status = -EINVAL;
     }
@@ -347,6 +354,10 @@
         *(uint32_t *)value  = (uint32_t) virtualizer_get_virtualization_mode(virt_ctxt);
         break;
 
+    case VIRTUALIZER_PARAM_LATENCY:
+        *(uint32_t *)value = VIRUALIZER_MAX_LATENCY;
+        break;
+
     default:
         p->status = -EINVAL;
         break;
diff --git a/post_proc/virtualizer.h b/post_proc/virtualizer.h
index 904a0c6..c0e6a87 100644
--- a/post_proc/virtualizer.h
+++ b/post_proc/virtualizer.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2015, 2018, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -20,6 +20,8 @@
 #ifndef OFFLOAD_VIRTUALIZER_H_
 #define OFFLOAD_VIRTUALIZER_H_
 
+#define VIRTUALIZER_PARAM_LATENCY 0x80000000
+
 #include "bundle.h"
 
 extern const effect_descriptor_t virtualizer_descriptor;
diff --git a/qahw_api/inc/qahw_effect_bassboost.h b/qahw_api/inc/qahw_effect_bassboost.h
index 2ca8409..b397f21 100644
--- a/qahw_api/inc/qahw_effect_bassboost.h
+++ b/qahw_api/inc/qahw_effect_bassboost.h
@@ -40,7 +40,9 @@
 typedef enum
 {
     BASSBOOST_PARAM_STRENGTH_SUPPORTED,
-    BASSBOOST_PARAM_STRENGTH
+    BASSBOOST_PARAM_STRENGTH,
+    BASSBOOST_PARAM_LATENCY = 0x80000000 // Internal paramter specific to qahw.
+                                         // Used to get latency introduced by bassboost effect.
 } qahw_bassboost_params;
 
 #ifdef __cplusplus
diff --git a/qahw_api/inc/qahw_effect_environmentalreverb.h b/qahw_api/inc/qahw_effect_environmentalreverb.h
index a47eb28..61ef39e 100644
--- a/qahw_api/inc/qahw_effect_environmentalreverb.h
+++ b/qahw_api/inc/qahw_effect_environmentalreverb.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2011 The Android Open Source Project
@@ -22,7 +22,7 @@
 
 #include <qahw_effect_api.h>
 
-#if __cplusplus
+#ifdef __cplusplus
 extern "C" {
 #endif
 
@@ -55,7 +55,9 @@
     REVERB_PARAM_DIFFUSION,             // in permilles,    range 0 to 1000
     REVERB_PARAM_DENSITY,               // in permilles,    range 0 to 1000
     REVERB_PARAM_PROPERTIES,
-    REVERB_PARAM_BYPASS
+    REVERB_PARAM_BYPASS,
+    REVERB_PARAM_LATENCY = 0x80000000   // Internal paramter specific to qahw.
+                                        // Used to get latency introduced by reverb effect.
 } qahw_env_reverb_params;
 
 //qahw_reverb_settings is equal to SLEnvironmentalReverbSettings defined in OpenSL ES specification.
@@ -73,7 +75,7 @@
 } __attribute__((packed)) qahw_reverb_settings;
 
 
-#if __cplusplus
+#ifdef __cplusplus
 }  // extern "C"
 #endif
 
diff --git a/qahw_api/inc/qahw_effect_equalizer.h b/qahw_api/inc/qahw_effect_equalizer.h
index fd71c4c..e4d6c5b 100644
--- a/qahw_api/inc/qahw_effect_equalizer.h
+++ b/qahw_api/inc/qahw_effect_equalizer.h
@@ -50,7 +50,9 @@
     EQ_PARAM_CUR_PRESET,            // Gets/Sets the current preset.
     EQ_PARAM_GET_NUM_OF_PRESETS,    // Gets the total number of presets the equalizer supports.
     EQ_PARAM_GET_PRESET_NAME,       // Gets the preset name based on the index.
-    EQ_PARAM_PROPERTIES             // Gets/Sets all parameters at a time.
+    EQ_PARAM_PROPERTIES,            // Gets/Sets all parameters at a time.
+    EQ_PARAM_LATENCY = 0x80000000   // Internal paramter specific to qahw.
+                                    // Used to get latency introduced by equalizer effect.
 } qahw_equalizer_params;
 
 enum
diff --git a/qahw_api/inc/qahw_effect_virtualizer.h b/qahw_api/inc/qahw_effect_virtualizer.h
index 5ff95ce..481f0ef 100644
--- a/qahw_api/inc/qahw_effect_virtualizer.h
+++ b/qahw_api/inc/qahw_effect_virtualizer.h
@@ -75,7 +75,10 @@
     //                                   AUDIO_DEVICE_NONE when not virtualizing
     //   status     int -EINVAL if an error occurred
     //                  0       if the output value is successfully retrieved
-    VIRTUALIZER_PARAM_VIRTUALIZATION_MODE
+    VIRTUALIZER_PARAM_VIRTUALIZATION_MODE,
+    // Internal paramter specific to qahw.
+    // Used to get latency introduced by virtuaizer effect.
+    VIRTUALIZER_PARAM_LATENCY = 0x80000000
 } qahw_virtualizer_params;
 
 #ifdef __cplusplus