Merge "configs: msm8937: Add speaker and headphones paths in mixer xml"
diff --git a/configs/sdm670/audio_platform_info_skuw.xml b/configs/sdm670/audio_platform_info_skuw.xml
index d8d1f78..0d197c5 100755
--- a/configs/sdm670/audio_platform_info_skuw.xml
+++ b/configs/sdm670/audio_platform_info_skuw.xml
@@ -67,8 +67,8 @@
     <config_params>
         <!-- In the below value string, the value indicates default mono -->
         <!-- speaker. It can be set to either left or right              -->
-        <param key="spkr_1_tz_name" value="wsatz.13"/>
-        <param key="spkr_2_tz_name" value="wsatz.14"/>
+        <param key="spkr_1_tz_name" value="wsatz.11"/>
+        <param key="spkr_2_tz_name" value="wsatz.12"/>
         <param key="true_32_bit" value="true"/>
         <param key="native_audio_mode" value="true"/>
         <param key="hfp_pcm_dev_id" value="39"/>
diff --git a/hal/audio_extn/ffv.c b/hal/audio_extn/ffv.c
index 71aeb3d..596f49b 100644
--- a/hal/audio_extn/ffv.c
+++ b/hal/audio_extn/ffv.c
@@ -60,14 +60,14 @@
 #define AUDIO_PARAMETER_FFV_CHANNEL_INDEX "ffv_channel_index"
 
 #if LINUX_ENABLED
-#define ST_FFV_CONFIG_FILE_PATH "/etc/BF_1out.cfg"
+#define FFV_CONFIG_FILE_PATH "/etc/BF_1out.cfg"
 #ifdef __LP64__
 #define FFV_LIB "/usr/lib64/libffv.so"
 #else
 #define FFV_LIB "/usr/lib/libffv.so"
 #endif
 #else
-#define ST_FFV_CONFIG_FILE_PATH "/vendor/etc/BF_1out.cfg"
+#define FFV_CONFIG_FILE_PATH "/vendor/etc/BF_1out.cfg"
 #ifdef __LP64__
 #define FFV_LIB "/vendor/lib64/libffv.so"
 #else
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 80bac42..5bd9b4d 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -1361,7 +1361,9 @@
               platform_get_snd_device_name(snd_device),
               platform_get_snd_device_name(usecase->out_snd_device),
               platform_check_backends_match(snd_device, usecase->out_snd_device));
-        if ((usecase->type != PCM_CAPTURE) && (usecase != uc_info)) {
+        if ((usecase->type != PCM_CAPTURE) &&
+            (usecase->type != VOICE_CALL) &&
+            (usecase != uc_info)) {
             uc_derive_snd_device = derive_playback_snd_device(adev->platform,
                                                usecase, uc_info, snd_device);
             if (((uc_derive_snd_device != usecase->out_snd_device) || force_routing) &&
@@ -5394,7 +5396,8 @@
 
     lock_input_stream(in);
     pthread_mutex_lock(&in->dev->lock);
-    if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) &&
+    if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
+         in->dev->mode == AUDIO_MODE_IN_COMMUNICATION) &&
             in->enable_aec != enable &&
             (memcmp(&desc.type, FX_IID_AEC, sizeof(effect_uuid_t)) == 0)) {
         in->enable_aec = enable;
@@ -5408,7 +5411,8 @@
             (memcmp(&desc.type, FX_IID_NS, sizeof(effect_uuid_t)) == 0)) {
         in->enable_ns = enable;
         if (!in->standby) {
-            if (in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) {
+            if (in->source == AUDIO_SOURCE_VOICE_COMMUNICATION ||
+                in->dev->mode == AUDIO_MODE_IN_COMMUNICATION) {
                 if (enable_disable_effect(in->dev, EFFECT_NS, enable) == ENOSYS)
                     select_devices(in->dev, in->usecase);
             } else
@@ -6647,7 +6651,8 @@
     bool valid_ch = audio_channel_count_from_in_mask(in->channel_mask) == 1;
 
 #ifndef COMPRESS_VOIP_ENABLED
-    if (valid_rate && valid_ch) {
+    if (valid_rate && valid_ch &&
+        in->dev->mode == AUDIO_MODE_IN_COMMUNICATION) {
         in->usecase = USECASE_AUDIO_RECORD_VOIP;
         in->config = default_pcm_config_voip_copp;
         in->config.period_size = VOIP_IO_BUF_SIZE(in->sample_rate,
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 27a5c39..e74353e 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -4026,8 +4026,6 @@
                 snd_device = SND_DEVICE_OUT_BT_SCO_WB;
             else
                 snd_device = SND_DEVICE_OUT_BT_SCO;
-        } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
-                snd_device = SND_DEVICE_OUT_BT_A2DP;
         } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
                 if (my_data->is_vbat_speaker) {
                     if (my_data->mono_speaker == SPKR_1)
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 3924a17..9a5d647 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -3861,8 +3861,6 @@
                     } else
                             snd_device = SND_DEVICE_OUT_VOICE_SPEAKER;
                 }
-        } else if (devices & AUDIO_DEVICE_OUT_ALL_A2DP) {
-            snd_device = SND_DEVICE_OUT_BT_A2DP;
         } else if (devices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET ||
                    devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
             snd_device = SND_DEVICE_OUT_USB_HEADSET;
@@ -6218,6 +6216,13 @@
     /*this is populated by check_codec_backend_cfg hence set default value to false*/
     backend_cfg.passthrough_enabled = false;
 
+     /*check if the stream sample 44.1Khz rate is supported of configured device sample rate. If not
+       open afe at default sample rate.
+      */
+    if (backend_idx != HEADPHONE_44_1_BACKEND &&
+        usecase->stream.out->sample_rate == OUTPUT_SAMPLING_RATE_44100)
+        backend_cfg.sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
+
     /* Set Backend sampling rate to 176.4 for DSD64 and
      * 352.8Khz for DSD128.
      * Set Bit Width to 16
@@ -6241,7 +6246,8 @@
     for (i = 0; i < num_devices; i++) {
         ALOGI("%s: new_snd_devices[%d] is %d", __func__, i, new_snd_devices[i]);
         if ((platform_check_codec_backend_cfg(adev, usecase, new_snd_devices[i],
-                                             &backend_cfg))) {
+                                             &backend_cfg)) ||
+             (!platform_check_backends_match(usecase->out_snd_device, snd_device))) {
             ret = platform_set_codec_backend_cfg(adev, new_snd_devices[i],
                                            backend_cfg);
             if (!ret) {
diff --git a/hal/voice.c b/hal/voice.c
index 0a48a05..70bb7e1 100644
--- a/hal/voice.c
+++ b/hal/voice.c
@@ -226,16 +226,17 @@
         goto error_start_voice;
     }
 
-    uc_info->in_snd_device = SND_DEVICE_NONE;
-    uc_info->out_snd_device = SND_DEVICE_NONE;
-
-    if (audio_is_bluetooth_sco_device(uc_info->devices) && !adev->bt_sco_on) {
-        ALOGE("start_call: couldn't find BT SCO, SCO is not ready");
+    if ((audio_is_bluetooth_sco_device(uc_info->devices) && !adev->bt_sco_on) ||
+        audio_is_a2dp_out_device(uc_info->devices)) {
+        ALOGE("start_call: BT SCO is chosen but SCO is not ready, or A2DP is selected");
         adev->voice.in_call = false;
         ret = -EIO;
         goto error_start_voice;
     }
 
+    uc_info->in_snd_device = SND_DEVICE_NONE;
+    uc_info->out_snd_device = SND_DEVICE_NONE;
+
     list_add_tail(&adev->usecase_list, &uc_info->list);
 
     select_devices(adev, usecase_id);
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;