Merge "configs: sdm670: add support for Fluence V8 feature"
diff --git a/hal/acdb.c b/hal/acdb.c
index cbb96bd..182e513 100644
--- a/hal/acdb.c
+++ b/hal/acdb.c
@@ -143,10 +143,12 @@
         if (my_data->acdb_handle)
             dlclose(my_data->acdb_handle);
 
-        struct listnode *node;
-        struct meta_key_list *key_info;
-        list_for_each(node, &my_data->acdb_meta_key_list) {
+        struct listnode *node = NULL;
+        struct meta_key_list *key_info = NULL;
+        struct listnode *tempnode = NULL;
+        list_for_each_safe(node, tempnode, &my_data->acdb_meta_key_list) {
             key_info = node_to_item(node, struct meta_key_list, list);
+            list_remove(node);
             free(key_info);
         }
         free(my_data);
diff --git a/hal/audio_extn/spkr_protection.c b/hal/audio_extn/spkr_protection.c
index ea4d856..589a391 100644
--- a/hal/audio_extn/spkr_protection.c
+++ b/hal/audio_extn/spkr_protection.c
@@ -70,8 +70,8 @@
 #define MIN_RESISTANCE_LOOKUP (3.2)
 #define MAX_RESISTANCE_LOOKUP (8)
 #define SPV3_LOOKUP_TABLE_ROWS (49)
-/* default limiter threshold is 0dB */
-#define DEFAULT_LIMITER_TH (0x0)
+/* default limiter threshold is 0dB(0x7FFFFFF in natural value) */
+#define DEFAULT_LIMITER_TH (0x07FFFFFF)
 #define AFE_API_VERSION_SUPPORT_SPV3 (0x2)
 enum spv3_boost_max_state {
     BOOST_NO_MAX_STATE,
@@ -275,15 +275,15 @@
 
 /* 3.2ohm : 0.1ohm : 8ohm lookup table */
 static int spv3_limiter_th_q27_table[SPV3_LOOKUP_TABLE_ROWS] = {
-    -526133494, -508685189, -491236884, -473788580, -457682452, -441576325,
-    -426812375, -410706248, -395942298, -382520525, -367756575, -354334802,
-    -340913029, -327491256, -315411661, -301989888, -289910292, -277830697,
-    -265751101, -255013683, -242934088, -232196669, -221459251, -210721833,
-    -199984415, -190589174, -179851756, -170456515, -159719096, -150323855,
-    -140928614, -131533373, -122138132, -114085069, -104689828, -95294587,
-    -87241523,  -79188460,  -69793219,  -61740155,  -53687091,  -45634028,
-    -37580964,  -29527900,  -22817014,  -14763950,  -6710886,   0,
-    0
+    85469248, 86758070, 88066327, 89394311, 90637910, 91898809,
+    93070036, 94364769, 95567425, 96674043, 97906130, 99039829,
+    100186656, 101346763, 102402340, 103588104, 104667026, 105757185,
+    106858699, 107847451, 108970736, 109979029, 110996653, 112023692,
+    113060235, 113975074, 115029672, 115960448, 117033416, 117980405,
+    118935056, 119897432, 120867596, 121705410, 122690202, 123682964,
+    124540293, 125403565, 126418282, 127294571, 128176935, 129065415,
+    129960054, 130860894, 131616362, 132528683, 133447328, 134217728,
+    134217728
 };
 static struct speaker_prot_session handle;
 static int vi_feed_no_channels;
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 56d9aec..c31a8d8 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -6777,7 +6777,7 @@
          *sample_rate = stream_sr;
 
      if (snd_device == SND_DEVICE_OUT_HDMI)
-         *sample_rate = platform_get_supported_sampling_rate_on_hdmi(stream_sr);
+         *sample_rate = platform_get_supported_copp_sampling_rate(stream_sr);
 
      ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr
 , *sample_rate);
@@ -7882,7 +7882,7 @@
     return MAX_CODEC_BACKENDS;
 }
 
-int platform_get_supported_sampling_rate_on_hdmi(uint32_t stream_sr)
+int platform_get_supported_copp_sampling_rate(uint32_t stream_sr)
 {
     int sample_rate;
     switch (stream_sr){
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index ce12dba..4a6ba5b 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -6925,8 +6925,9 @@
      } else
          *sample_rate = stream_sr;
 
-    if (snd_device == SND_DEVICE_OUT_HDMI)
-        *sample_rate = platform_get_supported_sampling_rate_on_hdmi(stream_sr);
+    if ((snd_device == SND_DEVICE_OUT_HDMI) || (snd_device == SND_DEVICE_OUT_DISPLAY_PORT) ||
+                  (snd_device == SND_DEVICE_OUT_USB_HEADSET))
+        *sample_rate = platform_get_supported_copp_sampling_rate(stream_sr);
 
      ALOGI("sn_device %d device sr %d stream sr %d copp sr %d", snd_device, device_sr, stream_sr, *sample_rate);
 
@@ -7736,7 +7737,7 @@
 
     return MAX_CODEC_BACKENDS;
 }
-int platform_get_supported_sampling_rate_on_hdmi(uint32_t stream_sr)
+int platform_get_supported_copp_sampling_rate(uint32_t stream_sr)
 {
     int sample_rate;
     switch (stream_sr){
diff --git a/hal/platform_api.h b/hal/platform_api.h
index 0674761..e72c6e9 100644
--- a/hal/platform_api.h
+++ b/hal/platform_api.h
@@ -184,7 +184,7 @@
 
 int platform_set_channel_allocation(void *platform, int channel_alloc);
 int platform_get_edid_info(void *platform);
-int platform_get_supported_sampling_rate_on_hdmi(uint32_t stream_sr);
+int platform_get_supported_copp_sampling_rate(uint32_t stream_sr);
 int platform_set_channel_map(void *platform, int ch_count, char *ch_map,
                              int snd_id);
 int platform_set_stream_channel_map(void *platform, audio_channel_mask_t channel_mask,
diff --git a/qahw/Android.mk b/qahw/Android.mk
index c7df9e3..0b782f0 100644
--- a/qahw/Android.mk
+++ b/qahw/Android.mk
@@ -27,6 +27,7 @@
 LOCAL_COPY_HEADERS      += inc/qahw_effect_api.h
 
 LOCAL_PRELINK_MODULE    := false
+LOCAL_VENDOR_MODULE     := true
 
 include $(BUILD_SHARED_LIBRARY)
 
diff --git a/qahw/inc/qahw_effect_api.h b/qahw/inc/qahw_effect_api.h
index de53cd3..dbd61e2 100644
--- a/qahw/inc/qahw_effect_api.h
+++ b/qahw/inc/qahw_effect_api.h
@@ -31,8 +31,6 @@
 
 #include <system/audio.h>
 
-#include "qahw.h"
-
 __BEGIN_DECLS
 
 #define QAHW_EFFECT_API_VERSION_0_0 QAHW_MAKE_API_VERSION(0, 0)
diff --git a/qahw/src/qahw_effect.c b/qahw/src/qahw_effect.c
index cf7b3fd..2eff79f 100644
--- a/qahw/src/qahw_effect.c
+++ b/qahw/src/qahw_effect.c
@@ -38,6 +38,7 @@
 #include <hardware/audio_effect.h>
 #include <stdlib.h>
 
+#include "qahw.h"
 #include "qahw_effect_api.h"
 
 // The current effect API version.
diff --git a/qahw_api/Android.mk b/qahw_api/Android.mk
index ba402ba..fa4e6cb 100644
--- a/qahw_api/Android.mk
+++ b/qahw_api/Android.mk
@@ -34,6 +34,7 @@
 LOCAL_COPY_HEADERS      += inc/qahw_effect_visualizer.h
 
 LOCAL_PRELINK_MODULE    := false
+LOCAL_VENDOR_MODULE     := true
 
 include $(BUILD_SHARED_LIBRARY)
 
diff --git a/qahw_api/test/Android.mk b/qahw_api/test/Android.mk
index ec4e698..06e8a5a 100644
--- a/qahw_api/test/Android.mk
+++ b/qahw_api/test/Android.mk
@@ -20,10 +20,10 @@
     libutils \
     libcutils
 
-LOCAL_LDLIBS := -lpthread
 LOCAL_32_BIT_ONLY := true
 
 LOCAL_C_INCLUDES += $(hal-play-inc)
+LOCAL_VENDOR_MODULE := true
 
 include $(BUILD_EXECUTABLE)
 
@@ -43,4 +43,6 @@
 hal-rec-inc     = $(TARGET_OUT_HEADERS)/mm-audio/qahw_api/inc
 
 LOCAL_C_INCLUDES += $(hal-rec-inc)
+LOCAL_VENDOR_MODULE := true
+
 include $(BUILD_EXECUTABLE)
diff --git a/qahw_api/test/qahw_effect_test.c b/qahw_api/test/qahw_effect_test.c
index bc249f3..9ea362f 100644
--- a/qahw_api/test/qahw_effect_test.c
+++ b/qahw_api/test/qahw_effect_test.c
@@ -34,6 +34,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
+#include <signal.h>
 
 #include "qahw_api.h"
 #include "qahw_defs.h"
@@ -111,6 +112,12 @@
 #define NUM_EQ_BANDS 5
 const uint16_t qahw_equalizer_band_freqs[NUM_EQ_BANDS] = {60, 230, 910, 3600, 14000}; /* frequencies in HZ */
 
+/* Handler to handle input command_thread_func signal */
+void stop_effect_command_thread_handler(int signal __unused)
+{
+   pthread_exit(NULL);
+}
+
 /* THREAD BODY OF BASSBOOST */
 void *bassboost_thread_func(void* data) {
     thread_data_t            *thr_ctxt = (thread_data_t *)data;
@@ -489,6 +496,12 @@
     qahw_effect_param_t *param = (qahw_effect_param_t *)buf32;
     qahw_effect_param_t *param_2 = (qahw_effect_param_t *)buf32_2;
 
+    /* Register the SIGUSR1 to close this thread properly
+       as it is waiting for input in while loop */
+    if (signal(SIGUSR1, stop_effect_command_thread_handler) == SIG_ERR) {
+        fprintf(stderr, "Failed to register SIGUSR1:%d\n",errno);
+    }
+
     while(!thr_ctxt->exit) {
         if (fgets(cmd_str, sizeof(cmd_str), stdin) == NULL) {
             fprintf(stderr, "read error\n");
diff --git a/qahw_api/test/qahw_multi_record_test.c b/qahw_api/test/qahw_multi_record_test.c
index d618101..2e0a396 100644
--- a/qahw_api/test/qahw_multi_record_test.c
+++ b/qahw_api/test/qahw_multi_record_test.c
@@ -588,7 +588,7 @@
     printf("                                               For mono channel 16kHz rate for 30seconds\n\n");
 }
 
-static void qti_audio_server_death_notify_cb(void *ctxt) {
+static void qti_audio_server_death_notify_cb(void *ctxt __unused) {
     fprintf(log_file, "qas died\n");
     fprintf(stderr, "qas died\n");
     stop_record = true;
@@ -769,7 +769,7 @@
     /* set global setparams entered by user.
      * Also other global setparams can be concatenated if required.
      */
-    if (params[0].kvpairs != NULL) {
+    if (params[0].kvpairs[0] != 0) {
         size_t len;
         len = strcspn(params[0].kvpairs, ",");
         while (len < strlen(params[0].kvpairs)) {
diff --git a/qahw_api/test/qahw_playback_test.c b/qahw_api/test/qahw_playback_test.c
index fceff8b..2469b3c 100644
--- a/qahw_api/test/qahw_playback_test.c
+++ b/qahw_api/test/qahw_playback_test.c
@@ -854,10 +854,12 @@
         // destory effect command thread
         params->cmd_data.exit = true;
         usleep(100000);  // give a chance for thread to exit gracefully
-        rc = pthread_cancel(params->cmd_data.cmd_thread);
+
+        //Send signal for input command_thread_func to stop
+        rc = pthread_kill(params->cmd_data.cmd_thread, SIGUSR1);
         if (rc != 0) {
-            fprintf(log_file, "Fail to cancel thread!\n");
-            fprintf(stderr, "Fail to cancel thread!\n");
+            fprintf(log_file, "Fail to kill effect command thread!\n");
+            fprintf(stderr, "Fail to kill effect command thread!\n");
         }
         rc = pthread_join(params->cmd_data.cmd_thread, NULL);
         if (rc < 0) {
@@ -1197,7 +1199,7 @@
 int tigger_event(qahw_stream_handle_t* out_handle)
 {
     qahw_param_payload payload;
-    struct event_data event_payload = {0};
+    struct event_data event_payload = {0, 0, 0, 0, 0, 0, 0};
     int ret = 0;
 
     event_payload.num_events = 1;
diff --git a/qahw_api/test/qahw_playback_test.h b/qahw_api/test/qahw_playback_test.h
index 3ec8f25..b643c1d 100644
--- a/qahw_api/test/qahw_playback_test.h
+++ b/qahw_api/test/qahw_playback_test.h
@@ -159,8 +159,12 @@
 #define is_qap_session_active(argc, argv, kvp_string)                    (0)
 #define get_play_list(fp, stream_param, num_of_streams, kvp_str)         (0)
 #define check_for_playlist(kvp_string)                                   (0)
-#define start_playback_through_qap(kvp_string, num_of_streams,\
-                                         qap_out_hal_handle_t)           (0)
+inline int start_playback_through_qap(char * kvp_string __unused,
+                                      int num_of_streams __unused,
+                                      qahw_module_handle_t *qap_out_hal_handle_t __unused)
+{
+    return 0;
+}
 #define start_playback_through_qap_playlist(cmd_kvp_str, num_of_streams,\
                    kvp_string, stream_param, qap_wrapper_session_active,\
                    qap_out_hal_handle_t)                                 (0)