Merge "configs: msmcobalt: update decimator default volume" into audio-userspace.lnx.2.1-dev
diff --git a/configs/msmcobalt/audio_policy_configuration.xml b/configs/msmcobalt/audio_policy_configuration.xml
index 4bde15c..451c85e 100644
--- a/configs/msmcobalt/audio_policy_configuration.xml
+++ b/configs/msmcobalt/audio_policy_configuration.xml
@@ -116,6 +116,21 @@
                     <profile name="" format="AUDIO_FORMAT_AAC_HE_V2"
                              samplingRates="8000,11025,12000,16000,22050,24000,32000,44100,48000,64000,88200,96000"
                              channelMasks="AUDIO_CHANNEL_OUT_STEREO,AUDIO_CHANNEL_OUT_MONO"/>
+                    <profile name="" format="AUDIO_FORMAT_AC3"
+                             samplingRates="32000,44100,48000"
+                             channelMasks="AUDIO_CHANNEL_OUT_MONO,AUDIO_CHANNEL_OUT_STEREO,AUDIO_CHANNEL_OUT_2POINT1,AUDIO_CHANNEL_OUT_QUAD,AUDIO_CHANNEL_OUT_PENTA,AUDIO_CHANNEL_OUT_5POINT1"/>
+                    <profile name="" format="AUDIO_FORMAT_E_AC3"
+                             samplingRates="32000,44100,48000"
+                             channelMasks="AUDIO_CHANNEL_OUT_MONO,AUDIO_CHANNEL_OUT_STEREO,AUDIO_CHANNEL_OUT_2POINT1,AUDIO_CHANNEL_OUT_QUAD,AUDIO_CHANNEL_OUT_PENTA,AUDIO_CHANNEL_OUT_5POINT1,AUDIO_CHANNEL_OUT_6POINT1,AUDIO_CHANNEL_OUT_7POINT1"/>
+                    <profile name="" format="AUDIO_FORMAT_E_AC3_JOC"
+                             samplingRates="32000,44100,48000"
+                             channelMasks="AUDIO_CHANNEL_OUT_MONO,AUDIO_CHANNEL_OUT_STEREO,AUDIO_CHANNEL_OUT_2POINT1,AUDIO_CHANNEL_OUT_QUAD,AUDIO_CHANNEL_OUT_PENTA,AUDIO_CHANNEL_OUT_5POINT1,AUDIO_CHANNEL_OUT_6POINT1,AUDIO_CHANNEL_OUT_7POINT1"/>
+                    <profile name="" format="AUDIO_FORMAT_DTS"
+                             samplingRates="32000,44100,48000"
+                             channelMasks="AUDIO_CHANNEL_OUT_MONO,AUDIO_CHANNEL_OUT_STEREO,AUDIO_CHANNEL_OUT_2POINT1,AUDIO_CHANNEL_OUT_QUAD,AUDIO_CHANNEL_OUT_PENTA,AUDIO_CHANNEL_OUT_5POINT1"/>
+                    <profile name="" format="AUDIO_FORMAT_DTS_HD"
+                             samplingRates="32000,44100,48000,64000,88200,96000,128000,176400,192000"
+                             channelMasks="AUDIO_CHANNEL_OUT_MONO,AUDIO_CHANNEL_OUT_STEREO,AUDIO_CHANNEL_OUT_2POINT1,AUDIO_CHANNEL_OUT_QUAD,AUDIO_CHANNEL_OUT_PENTA,AUDIO_CHANNEL_OUT_5POINT1,AUDIO_CHANNEL_OUT_6POINT1,AUDIO_CHANNEL_OUT_7POINT1"/>
                     <profile name="" format="AUDIO_FORMAT_WMA"
                              samplingRates="8000,11025,12000,16000,22050,24000,32000,44100,48000"
                              channelMasks="AUDIO_CHANNEL_OUT_MONO,AUDIO_CHANNEL_OUT_STEREO,AUDIO_CHANNEL_OUT_2POINT1,AUDIO_CHANNEL_OUT_QUAD,AUDIO_CHANNEL_OUT_PENTA,AUDIO_CHANNEL_OUT_5POINT1,AUDIO_CHANNEL_OUT_6POINT1,AUDIO_CHANNEL_OUT_7POINT1"/>
diff --git a/configs/msmcobalt/msmcobalt.mk b/configs/msmcobalt/msmcobalt.mk
index 9b74162..bb6ee95 100644
--- a/configs/msmcobalt/msmcobalt.mk
+++ b/configs/msmcobalt/msmcobalt.mk
@@ -19,7 +19,7 @@
 AUDIO_FEATURE_ENABLED_FLUENCE := true
 AUDIO_FEATURE_ENABLED_HDMI_SPK := true
 AUDIO_FEATURE_ENABLED_HDMI_EDID := true
-#AUDIO_FEATURE_ENABLED_HDMI_PASSTHROUGH := true
+AUDIO_FEATURE_ENABLED_HDMI_PASSTHROUGH := true
 #AUDIO_FEATURE_ENABLED_KEEP_ALIVE := true
 #AUDIO_FEATURE_ENABLED_DS2_DOLBY_DAP := true
 #DOLBY_DDP := true
@@ -79,6 +79,7 @@
     hardware/qcom/audio/configs/msmcobalt/audio_platform_info_i2s.xml:system/etc/audio_platform_info_i2s.xml \
     hardware/qcom/audio/configs/msmcobalt/sound_trigger_mixer_paths.xml:system/etc/sound_trigger_mixer_paths.xml \
     hardware/qcom/audio/configs/msmcobalt/sound_trigger_mixer_paths_wcd9330.xml:system/etc/sound_trigger_mixer_paths_wcd9330.xml \
+    hardware/qcom/audio/configs/msmcobalt/sound_trigger_mixer_paths_wcd9340.xml:system/etc/sound_trigger_mixer_paths_wcd9340.xml \
     hardware/qcom/audio/configs/msmcobalt/sound_trigger_platform_info.xml:system/etc/sound_trigger_platform_info.xml \
     hardware/qcom/audio/configs/msmcobalt/graphite_ipc_platform_info.xml:system/etc/graphite_ipc_platform_info.xml \
     hardware/qcom/audio/configs/msmcobalt/audio_platform_info.xml:system/etc/audio_platform_info.xml
@@ -168,9 +169,9 @@
 PRODUCT_PROPERTY_OVERRIDES += \
 audio.offload.multiple.enabled=false
 
-#Disable Compress passthrough playback
+#Enable Compress passthrough playback
 PRODUCT_PROPERTY_OVERRIDES += \
-audio.offload.passthrough=false
+audio.offload.passthrough=true
 
 #Disable surround sound recording
 PRODUCT_PROPERTY_OVERRIDES += \
diff --git a/configs/msmcobalt/sound_trigger_mixer_paths_wcd9340.xml b/configs/msmcobalt/sound_trigger_mixer_paths_wcd9340.xml
index 3c75b8e..d12b62f 100755
--- a/configs/msmcobalt/sound_trigger_mixer_paths_wcd9340.xml
+++ b/configs/msmcobalt/sound_trigger_mixer_paths_wcd9340.xml
@@ -84,10 +84,10 @@
     </path>
 
     <path name="listen-cpe-handset-mic">
-        <ctl name="MAD Input" "DMIC0" />
-        <ctl name="MAD_SEL MUX" "SPE" />
-        <ctl name="MAD_INP MUX" "MAD" />
-        <ctl name="MAD_CPE1 Switch" 1 />
+        <ctl name="MAD Input" value="DMIC0" />
+        <ctl name="MAD_SEL MUX" value="SPE" />
+        <ctl name="MAD_INP MUX" value="MAD" />
+        <ctl name="MAD_CPE1 Switch" value="1" />
     </path>
 
     <path name="listen-cpe-handset-mic-ecpp">
diff --git a/configs/msmcobalt/sound_trigger_platform_info.xml b/configs/msmcobalt/sound_trigger_platform_info.xml
index 1f90bd5..7ce74aa 100644
--- a/configs/msmcobalt/sound_trigger_platform_info.xml
+++ b/configs/msmcobalt/sound_trigger_platform_info.xml
@@ -63,6 +63,15 @@
             <param detection_event_ids="0x00012C0D, 0x0, 0x00012C29" />
             <param capture_event_ids="0x00020013, 0x0,0x00020015" />
         </gcs_uid>
+        <gcs_uid>
+            <param uid="0x2" />
+            <param did="0x4" />
+            <param load_sound_model_ids="0x00012C0D, 0x1, 0x00012C14" />
+            <param confidence_levels_ids="0x00012C0D, 0x1, 0x00012C28" />
+            <param operation_mode_ids="0x00012C0D, 0x1 0x00012C28" />
+            <param detection_event_ids="0x00012C0D, 0x1, 0x00012C29" />
+            <param capture_event_ids="0x00020013, 0x1,0x00020015" />
+        </gcs_uid>
 
         <!-- Module and param ids with which the algorithm is integrated
             in non-graphite firmware (note these must come after gcs params) -->
diff --git a/hal/audio_extn/a2dp.c b/hal/audio_extn/a2dp.c
index 414fc79..7293ded 100644
--- a/hal/audio_extn/a2dp.c
+++ b/hal/audio_extn/a2dp.c
@@ -176,9 +176,9 @@
 /* API to identify DSP encoder captabilities */
 static void a2dp_offload_codec_cap_parser(char *value)
 {
-    char *tok = NULL;
+    char *tok = NULL,*saveptr;
 
-    tok = strtok(value, "-");
+    tok = strtok_r(value, "-", &saveptr);
     while (tok != NULL) {
         if (strcmp(tok, "sbc") == 0) {
             ALOGD("%s: SBC offload supported\n",__func__);
@@ -189,7 +189,7 @@
             a2dp.is_a2dp_offload_supported = true;
             break;
         }
-        tok = strtok(NULL,"-");
+        tok = strtok_r(NULL, "-", &saveptr);
     };
 }
 
@@ -549,8 +549,7 @@
     if(a2dp.a2dp_suspended == true) {
         //session will be restarted after suspend completion
         ALOGD("a2dp start requested during suspend state");
-        a2dp.a2dp_total_active_session_request++;
-        return 0;
+        return -ENOSYS;
     }
 
     if (!a2dp.a2dp_started && !a2dp.a2dp_total_active_session_request) {
@@ -593,14 +592,6 @@
         return -ENOSYS;
     }
 
-    if(a2dp.a2dp_suspended == true) {
-        ALOGD("STOP playback is called during suspend state");
-
-        // sessions are already closed during suspend, just update active sessions counts
-         if(a2dp.a2dp_total_active_session_request > 0)
-            a2dp.a2dp_total_active_session_request--;
-         return 0;
-    }
     if (a2dp.a2dp_started && (a2dp.a2dp_total_active_session_request > 0))
         a2dp.a2dp_total_active_session_request--;
 
@@ -614,8 +605,6 @@
             ALOGE("stop stream to BT IPC lib failed");
         else
             ALOGV("stop steam to BT IPC lib successful");
-        a2dp.is_handoff_in_progress = false;
-
          memset(&dummy_reset_config, 0x0, sizeof(struct sbc_enc_cfg_t));
         ctl_enc_config = mixer_get_ctl_by_name(a2dp.adev->mixer,
                                                MIXER_ENC_CONFIG_BLOCK);
@@ -672,44 +661,27 @@
          if (a2dp.bt_lib_handle && (a2dp.bt_state != A2DP_STATE_DISCONNECTED) ) {
              if ((!strncmp(value,"true",sizeof(value)))) {
                 ALOGD("Setting a2dp to suspend state");
-                int active_sessions = a2dp.a2dp_total_active_session_request, count = 0;
-                //Force close all active sessions on suspend (if any)
-                for(count  = 0; count< active_sessions; count ++)
-                    audio_extn_a2dp_stop_playback();
-                a2dp.a2dp_total_active_session_request = active_sessions;
                 a2dp.a2dp_suspended = true;
-
                 if(a2dp.audio_suspend_stream)
                    a2dp.audio_suspend_stream();
             } else if (a2dp.a2dp_suspended == true) {
                 ALOGD("Resetting a2dp suspend state");
                 if(a2dp.clear_a2dpsuspend_flag)
                     a2dp.clear_a2dpsuspend_flag();
-
                 a2dp.a2dp_suspended = false;
-                //Force restart all active sessions post suspend (if any)
-                if(a2dp.a2dp_total_active_session_request > 0){
-                    int active_sessions = a2dp.a2dp_total_active_session_request;
-                    a2dp.a2dp_total_active_session_request = 0;
-                    audio_extn_a2dp_start_playback();
-                    a2dp.a2dp_total_active_session_request = active_sessions;
-                }
             }
         }
         goto param_handled;
      }
-     ret = str_parms_get_str(parms,"reconfigA2dp", value, sizeof(value));
-     if (ret >= 0) {
-         if (a2dp.bt_lib_handle && (a2dp.bt_state != A2DP_STATE_DISCONNECTED)) {
-             if (!strncmp(value,"true",sizeof(value)))
-                 a2dp.is_handoff_in_progress = true;
-         }
-         goto param_handled;
-     }
 param_handled:
      ALOGV("end of a2dp setparam");
 }
 
+void audio_extn_a2dp_set_handoff_mode(bool is_on)
+{
+    a2dp.is_handoff_in_progress = is_on;
+}
+
 bool audio_extn_a2dp_is_force_device_switch()
 {
     //During encoder reconfiguration mode, force a2dp device switch
diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h
index 0fd7d3a..e8caeee 100644
--- a/hal/audio_extn/audio_extn.h
+++ b/hal/audio_extn/audio_extn.h
@@ -177,12 +177,14 @@
 #define audio_extn_a2dp_stop_playback()                  (0)
 #define audio_extn_a2dp_set_parameters(parms)            (0)
 #define audio_extn_a2dp_is_force_device_switch()         (0)
+#define audio_extn_a2dp_set_handoff_mode(is_on)          (0)
 #else
 void audio_extn_a2dp_init(void *adev);
 int audio_extn_a2dp_start_playback();
 void audio_extn_a2dp_stop_playback();
 void audio_extn_a2dp_set_parameters(struct str_parms *parms);
 bool audio_extn_a2dp_is_force_device_switch();
+void audio_extn_a2dp_set_handoff_mode(bool is_on);
 #endif
 
 #ifndef SSR_ENABLED
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 9894446..7d3c824 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -750,14 +750,6 @@
     if (audio_extn_spkr_prot_is_enabled())
          audio_extn_spkr_prot_calib_cancel(adev);
 
-
-    if (((SND_DEVICE_OUT_BT_A2DP == snd_device) ||
-       (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device))
-        && (audio_extn_a2dp_start_playback() < 0)) {
-           ALOGE(" fail to configure A2dp control path ");
-           return -EINVAL;
-    }
-
     if (platform_can_enable_spkr_prot_on_device(snd_device) &&
          audio_extn_spkr_prot_is_enabled()) {
        if (platform_get_spkr_prot_acdb_id(snd_device) < 0) {
@@ -777,6 +769,13 @@
         }
     } else {
         ALOGD("%s: snd_device(%d: %s)", __func__, snd_device, device_name);
+
+       if ((SND_DEVICE_OUT_BT_A2DP == snd_device) &&
+           (audio_extn_a2dp_start_playback() < 0)) {
+           ALOGE(" fail to configure A2dp control path ");
+           return -EINVAL;
+       }
+
         /* due to the possibility of calibration overwrite between listen
             and audio, notify listen hal before audio calibration is sent */
         audio_extn_sound_trigger_update_device_status(snd_device,
@@ -835,10 +834,6 @@
     if (adev->snd_dev_ref_cnt[snd_device] == 0) {
         ALOGD("%s: snd_device(%d: %s)", __func__, snd_device, device_name);
 
-        if ((SND_DEVICE_OUT_BT_A2DP == snd_device) ||
-           (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device))
-            audio_extn_a2dp_stop_playback();
-
         if (platform_can_enable_spkr_prot_on_device(snd_device) &&
              audio_extn_spkr_prot_is_enabled()) {
             audio_extn_spkr_prot_stop_processing(snd_device);
@@ -851,6 +846,9 @@
             audio_route_reset_and_update_path(adev->audio_route, device_name);
         }
 
+        if (SND_DEVICE_OUT_BT_A2DP == snd_device)
+            audio_extn_a2dp_stop_playback();
+
         if (snd_device == SND_DEVICE_OUT_HDMI)
             adev->is_channel_status_set = false;
         else if (SND_DEVICE_OUT_HEADPHONES == snd_device &&
@@ -4145,8 +4143,6 @@
         }
     }
 
-    audio_extn_set_parameters(adev, parms);
-    // reconfigure should be done only after updating a2dpstate in audio extn
     ret = str_parms_get_str(parms,"reconfigA2dp", value, sizeof(value));
     if (ret >= 0) {
         struct audio_usecase *usecase;
@@ -4156,13 +4152,17 @@
             if ((usecase->type == PCM_PLAYBACK) &&
                 (usecase->devices & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP)){
                 ALOGD("reconfigure a2dp... forcing device switch");
+                lock_output_stream(usecase->stream.out);
+                audio_extn_a2dp_set_handoff_mode(true);
                 //force device switch to re configure encoder
                 select_devices(adev, usecase->id);
+                audio_extn_a2dp_set_handoff_mode(false);
+                pthread_mutex_unlock(&usecase->stream.out->lock);
                 break;
             }
         }
     }
-
+    audio_extn_set_parameters(adev, parms);
 done:
     str_parms_destroy(parms);
     pthread_mutex_unlock(&adev->lock);
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 9c6cc6f..b41e040 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -2830,6 +2830,10 @@
         new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
         new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
         status = true;
+    } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device) {
+        *num_devices = 2;
+        new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
+        new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
     }
 
     ALOGD("%s: snd_device(%d) num devices(%d) new_snd_devices(%d)", __func__,
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 7d6f02b..24bee89 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -2678,8 +2678,13 @@
         new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
         new_snd_devices[1] = SND_DEVICE_OUT_USB_HEADSET;
         status = true;
+    } else if (SND_DEVICE_OUT_SPEAKER_AND_BT_A2DP == snd_device) {
+        *num_devices = 2;
+        new_snd_devices[0] = SND_DEVICE_OUT_SPEAKER;
+        new_snd_devices[1] = SND_DEVICE_OUT_BT_A2DP;
     }
 
+
     ALOGD("%s: snd_device(%d) num devices(%d) new_snd_devices(%d)", __func__,
         snd_device, *num_devices, *new_snd_devices);