Back Merge :: To resolve merg conflict prjs-platform/hardware/qcom/audio

Change-Id: I9af84a86fcd0e6f9c78657be0deac61f48641bc4
diff --git a/Android.mk b/Android.mk
index b27eb60..14938b8 100644
--- a/Android.mk
+++ b/Android.mk
@@ -18,7 +18,7 @@
 include $(MY_LOCAL_PATH)/qahw_api/Android.mk
 endif
 
-ifneq ($(TARGET_USES_AOSP_FOR_AUDIO), true)
+ifeq ($(USE_LEGACY_AUDIO_DAEMON), true)
 include $(MY_LOCAL_PATH)/audiod/Android.mk
 endif
 
diff --git a/configs/msm8937/audio_output_policy.conf b/configs/msm8937/audio_output_policy.conf
index 3d6b978..6686015 100644
--- a/configs/msm8937/audio_output_policy.conf
+++ b/configs/msm8937/audio_output_policy.conf
@@ -25,22 +25,15 @@
     bit_width 16
     app_type 69936
   }
-  direct {
-    flags AUDIO_OUTPUT_FLAG_DIRECT
-    formats AUDIO_FORMAT_PCM_16_BIT
-    sampling_rates 48000
-    bit_width 16
-    app_type 69936
-  }
   direct_pcm_16 {
-    flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+    flags AUDIO_OUTPUT_FLAG_DIRECT
     formats AUDIO_FORMAT_PCM_16_BIT|AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT
     sampling_rates 44100|48000|96000|192000
     bit_width 16
     app_type 69936
   }
   direct_pcm_24 {
-    flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+    flags AUDIO_OUTPUT_FLAG_DIRECT
     formats AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT
     sampling_rates 44100|48000|96000|192000
     bit_width 24
diff --git a/configs/msm8937/audio_policy.conf b/configs/msm8937/audio_policy.conf
index b7b858e..6a1cd54 100644
--- a/configs/msm8937/audio_policy.conf
+++ b/configs/msm8937/audio_policy.conf
@@ -47,19 +47,12 @@
          devices AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_EARPIECE|AUDIO_DEVICE_OUT_WIRED_HEADSET|AUDIO_DEVICE_OUT_WIRED_HEADPHONE|AUDIO_DEVICE_OUT_LINE|AUDIO_DEVICE_OUT_ALL_SCO|AUDIO_DEVICE_OUT_AUX_DIGITAL|AUDIO_DEVICE_OUT_PROXY
          flags AUDIO_OUTPUT_FLAG_DEEP_BUFFER
       }
-      multichannel {
-        sampling_rates 44100|48000
-        channel_masks dynamic
-        formats AUDIO_FORMAT_PCM_16_BIT
-        devices AUDIO_DEVICE_OUT_AUX_DIGITAL|AUDIO_DEVICE_OUT_PROXY
-        flags AUDIO_OUTPUT_FLAG_DIRECT
-      }
       direct_pcm {
         sampling_rates 8000|11025|16000|22050|32000|44100|48000|64000|88200|96000|176400|192000
         channel_masks 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
         formats AUDIO_FORMAT_PCM_16_BIT|AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT
         devices AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_EARPIECE|AUDIO_DEVICE_OUT_WIRED_HEADSET|AUDIO_DEVICE_OUT_WIRED_HEADPHONE|AUDIO_DEVICE_OUT_LINE|AUDIO_DEVICE_OUT_ALL_SCO|AUDIO_DEVICE_OUT_PROXY|AUDIO_DEVICE_OUT_AUX_DIGITAL
-        flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+        flags AUDIO_OUTPUT_FLAG_DIRECT
       }
       compress_offload {
         sampling_rates 8000|11025|12000|16000|22050|24000|32000|44100|48000|64000|88200|96000|176400|192000
diff --git a/configs/msm8937/audio_policy_configuration.xml b/configs/msm8937/audio_policy_configuration.xml
index 44abe28..253528e 100644
--- a/configs/msm8937/audio_policy_configuration.xml
+++ b/configs/msm8937/audio_policy_configuration.xml
@@ -73,13 +73,8 @@
                     <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                              samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
                 </mixPort>
-                <mixPort name="multichannel" role="source"
-                        flags="AUDIO_OUTPUT_FLAG_DIRECT">
-                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
-                             samplingRates="8000,11025,16000,22050,32000,44100,48000,64000,88200,96000,128000,176400,192000" channelMasks="dynamic"/>
-                </mixPort>
                 <mixPort name="direct_pcm" role="source"
-                        flags="AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM">
+                        flags="AUDIO_OUTPUT_FLAG_DIRECT">
                     <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                              samplingRates="8000,11025,12000,16000,22050,24000,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"/>
@@ -255,9 +250,9 @@
                 <route type="mix" sink="Line"
                        sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx"/>
                 <route type="mix" sink="HDMI"
-                       sources="primary output,raw,deep_buffer,multichannel,direct_pcm,compressed_offload"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload"/>
                 <route type="mix" sink="Proxy"
-                       sources="primary output,raw,deep_buffer,multichannel,direct_pcm,compressed_offload"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload"/>
                 <route type="mix" sink="FM"
                        sources="primary output"/>
                 <route type="mix" sink="BT SCO All"
diff --git a/configs/msm8937/msm8937.mk b/configs/msm8937/msm8937.mk
index e87628a..bf28b8c 100644
--- a/configs/msm8937/msm8937.mk
+++ b/configs/msm8937/msm8937.mk
@@ -30,6 +30,7 @@
 AUDIO_FEATURE_ENABLED_HW_ACCELERATED_EFFECTS := false
 AUDIO_FEATURE_ENABLED_DS2_DOLBY_DAP := true
 AUDIO_FEATURE_ENABLED_AUDIOSPHERE := true
+DOLBY_ENABLE := false
 endif
 
 USE_XML_AUDIO_POLICY_CONF := 1
diff --git a/configs/msm8953/audio_output_policy.conf b/configs/msm8953/audio_output_policy.conf
index 3d6b978..6686015 100644
--- a/configs/msm8953/audio_output_policy.conf
+++ b/configs/msm8953/audio_output_policy.conf
@@ -25,22 +25,15 @@
     bit_width 16
     app_type 69936
   }
-  direct {
-    flags AUDIO_OUTPUT_FLAG_DIRECT
-    formats AUDIO_FORMAT_PCM_16_BIT
-    sampling_rates 48000
-    bit_width 16
-    app_type 69936
-  }
   direct_pcm_16 {
-    flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+    flags AUDIO_OUTPUT_FLAG_DIRECT
     formats AUDIO_FORMAT_PCM_16_BIT|AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT
     sampling_rates 44100|48000|96000|192000
     bit_width 16
     app_type 69936
   }
   direct_pcm_24 {
-    flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+    flags AUDIO_OUTPUT_FLAG_DIRECT
     formats AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT
     sampling_rates 44100|48000|96000|192000
     bit_width 24
diff --git a/configs/msm8953/audio_policy.conf b/configs/msm8953/audio_policy.conf
index b11d0ae..95c20ad 100644
--- a/configs/msm8953/audio_policy.conf
+++ b/configs/msm8953/audio_policy.conf
@@ -47,19 +47,12 @@
          devices AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_EARPIECE|AUDIO_DEVICE_OUT_WIRED_HEADSET|AUDIO_DEVICE_OUT_WIRED_HEADPHONE|AUDIO_DEVICE_OUT_LINE|AUDIO_DEVICE_OUT_ALL_SCO|AUDIO_DEVICE_OUT_AUX_DIGITAL|AUDIO_DEVICE_OUT_PROXY
          flags AUDIO_OUTPUT_FLAG_DEEP_BUFFER
       }
-      multichannel {
-        sampling_rates 44100|48000
-        channel_masks dynamic
-        formats AUDIO_FORMAT_PCM_16_BIT
-        devices AUDIO_DEVICE_OUT_AUX_DIGITAL|AUDIO_DEVICE_OUT_PROXY
-        flags AUDIO_OUTPUT_FLAG_DIRECT
-      }
       direct_pcm {
         sampling_rates 8000|11025|16000|22050|32000|44100|48000|64000|88200|96000|176400|192000
         channel_masks 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
         formats AUDIO_FORMAT_PCM_16_BIT|AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT
         devices AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_EARPIECE|AUDIO_DEVICE_OUT_WIRED_HEADSET|AUDIO_DEVICE_OUT_WIRED_HEADPHONE|AUDIO_DEVICE_OUT_LINE|AUDIO_DEVICE_OUT_ALL_SCO|AUDIO_DEVICE_OUT_PROXY|AUDIO_DEVICE_OUT_AUX_DIGITAL
-        flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+        flags AUDIO_OUTPUT_FLAG_DIRECT
       }
       compress_offload {
         sampling_rates 8000|11025|12000|16000|22050|24000|32000|44100|48000|64000|88200|96000|176400|192000
diff --git a/configs/msm8953/audio_policy_configuration.xml b/configs/msm8953/audio_policy_configuration.xml
index b1ea1b9..981e383 100644
--- a/configs/msm8953/audio_policy_configuration.xml
+++ b/configs/msm8953/audio_policy_configuration.xml
@@ -73,13 +73,8 @@
                     <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                              samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
                 </mixPort>
-                <mixPort name="multichannel" role="source"
-                        flags="AUDIO_OUTPUT_FLAG_DIRECT">
-                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
-                             samplingRates="8000,11025,16000,22050,32000,44100,48000,64000,88200,96000,128000,176400,192000" channelMasks="dynamic"/>
-                </mixPort>
                 <mixPort name="direct_pcm" role="source"
-                        flags="AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM">
+                        flags="AUDIO_OUTPUT_FLAG_DIRECT">
                     <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                              samplingRates="8000,11025,12000,16000,22050,24000,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"/>
@@ -266,9 +261,9 @@
                 <route type="mix" sink="Line"
                        sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx"/>
                 <route type="mix" sink="HDMI"
-                       sources="primary output,raw,deep_buffer,multichannel,direct_pcm,compressed_offload"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload"/>
                 <route type="mix" sink="Proxy"
-                       sources="primary output,raw,deep_buffer,multichannel,direct_pcm,compressed_offload"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload"/>
                 <route type="mix" sink="FM"
                        sources="primary output"/>
                 <route type="mix" sink="BT SCO All"
diff --git a/configs/msm8953/msm8953.mk b/configs/msm8953/msm8953.mk
index f4cacd6..abcc1d2 100644
--- a/configs/msm8953/msm8953.mk
+++ b/configs/msm8953/msm8953.mk
@@ -29,6 +29,7 @@
 AUDIO_FEATURE_ENABLED_HW_ACCELERATED_EFFECTS := false
 AUDIO_FEATURE_ENABLED_DS2_DOLBY_DAP := true
 AUDIO_FEATURE_ENABLED_AUDIOSPHERE := true
+DOLBY_ENABLE := false
 endif
 
 USE_XML_AUDIO_POLICY_CONF := 1
diff --git a/configs/msm8996/audio_output_policy.conf b/configs/msm8996/audio_output_policy.conf
index 453b1a8..7945768 100644
--- a/configs/msm8996/audio_output_policy.conf
+++ b/configs/msm8996/audio_output_policy.conf
@@ -25,22 +25,15 @@
     bit_width 16
     app_type 69936
   }
-  direct {
-    flags AUDIO_OUTPUT_FLAG_DIRECT
-    formats AUDIO_FORMAT_PCM_16_BIT
-    sampling_rates 48000
-    bit_width 16
-    app_type 69936
-  }
   direct_pcm_16 {
-    flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+    flags AUDIO_OUTPUT_FLAG_DIRECT
     formats AUDIO_FORMAT_PCM_16_BIT|AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT
     sampling_rates 44100|48000|96000|192000
     bit_width 16
     app_type 69936
   }
   direct_pcm_24 {
-    flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+    flags AUDIO_OUTPUT_FLAG_DIRECT
     formats AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT
     sampling_rates 44100|48000|96000|192000
     bit_width 24
diff --git a/configs/msm8996/audio_policy.conf b/configs/msm8996/audio_policy.conf
index 641ec55..8addea7 100644
--- a/configs/msm8996/audio_policy.conf
+++ b/configs/msm8996/audio_policy.conf
@@ -50,19 +50,12 @@
         devices AUDIO_DEVICE_OUT_AUX_DIGITAL
         flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_NON_BLOCKING
       }
-      multichannel {
-        sampling_rates 8000|11025|16000|22050|32000|44100|48000|64000|88200|96000|128000|176400|192000
-        channel_masks dynamic
-        formats AUDIO_FORMAT_PCM_16_BIT
-        devices AUDIO_DEVICE_OUT_AUX_DIGITAL|AUDIO_DEVICE_OUT_PROXY
-        flags AUDIO_OUTPUT_FLAG_DIRECT
-      }
       direct_pcm {
         sampling_rates 8000|11025|12000|16000|22050|24000|32000|44100|48000|64000|88200|96000|176400|192000
         channel_masks 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
         formats AUDIO_FORMAT_PCM_16_BIT|AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT
         devices AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_EARPIECE|AUDIO_DEVICE_OUT_WIRED_HEADSET|AUDIO_DEVICE_OUT_WIRED_HEADPHONE|AUDIO_DEVICE_OUT_LINE|AUDIO_DEVICE_OUT_ALL_SCO|AUDIO_DEVICE_OUT_PROXY
-        flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+        flags AUDIO_OUTPUT_FLAG_DIRECT
       }
       compress_offload {
         sampling_rates 8000|11025|12000|16000|22050|24000|32000|44100|48000|64000|88200|96000|176400|192000
diff --git a/configs/msm8996/audio_policy_configuration.xml b/configs/msm8996/audio_policy_configuration.xml
index e8d4cd0..0f513c6 100644
--- a/configs/msm8996/audio_policy_configuration.xml
+++ b/configs/msm8996/audio_policy_configuration.xml
@@ -73,13 +73,8 @@
                     <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                              samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
                 </mixPort>
-                <mixPort name="multichannel" role="source"
-                        flags="AUDIO_OUTPUT_FLAG_DIRECT">
-                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
-                             samplingRates="8000,11025,16000,22050,32000,44100,48000,64000,88200,96000,128000,176400,192000" channelMasks="dynamic"/>
-                </mixPort>
                 <mixPort name="direct_pcm" role="source"
-                        flags="AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM">
+                        flags="AUDIO_OUTPUT_FLAG_DIRECT">
                     <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                              samplingRates="8000,11025,12000,16000,22050,24000,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"/>
@@ -266,9 +261,9 @@
                 <route type="mix" sink="Line"
                        sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,voip_rx"/>
                 <route type="mix" sink="HDMI"
-                       sources="primary output,raw,deep_buffer,multichannel,direct_pcm,compressed_offload"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload"/>
                 <route type="mix" sink="Proxy"
-                       sources="primary output,raw,deep_buffer,multichannel,direct_pcm,compressed_offload"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload"/>
                 <route type="mix" sink="FM"
                        sources="primary output"/>
                 <route type="mix" sink="BT SCO All"
diff --git a/configs/msm8996/msm8996.mk b/configs/msm8996/msm8996.mk
index d3aeb5e..68b13d4 100644
--- a/configs/msm8996/msm8996.mk
+++ b/configs/msm8996/msm8996.mk
@@ -29,6 +29,7 @@
 AUDIO_FEATURE_ENABLED_HW_ACCELERATED_EFFECTS := false
 AUDIO_FEATURE_ENABLED_DS2_DOLBY_DAP := true
 AUDIO_FEATURE_ENABLED_AUDIOSPHERE := true
+DOLBY_ENABLE := false
 endif
 
 USE_XML_AUDIO_POLICY_CONF := 1
diff --git a/configs/msm8998/audio_output_policy.conf b/configs/msm8998/audio_output_policy.conf
index 3a610c1..3e4f5fd 100644
--- a/configs/msm8998/audio_output_policy.conf
+++ b/configs/msm8998/audio_output_policy.conf
@@ -32,29 +32,22 @@
     bit_width 16
     app_type 69936
   }
-  direct {
-    flags AUDIO_OUTPUT_FLAG_DIRECT
-    formats AUDIO_FORMAT_PCM_16_BIT
-    sampling_rates 48000
-    bit_width 16
-    app_type 69936
-  }
   direct_pcm_16 {
-    flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+    flags AUDIO_OUTPUT_FLAG_DIRECT
     formats AUDIO_FORMAT_PCM_16_BIT|AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT|AUDIO_FORMAT_PCM_32_BIT
     sampling_rates 44100|48000|96000|192000
     bit_width 16
     app_type 69936
   }
   direct_pcm_24 {
-    flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+    flags AUDIO_OUTPUT_FLAG_DIRECT
     formats AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT|AUDIO_FORMAT_PCM_32_BIT
     sampling_rates 44100|48000|96000|176400|192000|352800|384000
     bit_width 24
     app_type 69940
   }
   direct_pcm_32 {
-    flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+    flags AUDIO_OUTPUT_FLAG_DIRECT
     formats AUDIO_FORMAT_PCM_32_BIT
     sampling_rates 44100|48000|96000|176400|192000|352800|384000
     bit_width 32
diff --git a/configs/msm8998/audio_policy.conf b/configs/msm8998/audio_policy.conf
index 8fb5676..f275e16 100644
--- a/configs/msm8998/audio_policy.conf
+++ b/configs/msm8998/audio_policy.conf
@@ -50,19 +50,12 @@
         devices AUDIO_DEVICE_OUT_AUX_DIGITAL
         flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_NON_BLOCKING
       }
-      multichannel {
-        sampling_rates 8000|11025|16000|22050|32000|44100|48000|64000|88200|96000|128000|176400|192000
-        channel_masks dynamic
-        formats AUDIO_FORMAT_PCM_16_BIT
-        devices AUDIO_DEVICE_OUT_AUX_DIGITAL|AUDIO_DEVICE_OUT_PROXY
-        flags AUDIO_OUTPUT_FLAG_DIRECT
-      }
       direct_pcm {
         sampling_rates 8000|11025|12000|16000|22050|24000|32000|44100|48000|64000|88200|96000|176400|192000|352800|384000
         channel_masks 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
         formats AUDIO_FORMAT_PCM_16_BIT|AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT|AUDIO_FORMAT_PCM_32_BIT
         devices AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_EARPIECE|AUDIO_DEVICE_OUT_WIRED_HEADSET|AUDIO_DEVICE_OUT_WIRED_HEADPHONE|AUDIO_DEVICE_OUT_LINE|AUDIO_DEVICE_OUT_ALL_SCO|AUDIO_DEVICE_OUT_PROXY|AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_BLUETOOTH_A2DP|AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES|AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER
-        flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+        flags AUDIO_OUTPUT_FLAG_DIRECT
       }
       compress_offload {
         sampling_rates 8000|11025|12000|16000|22050|24000|32000|44100|48000|64000|88200|96000|176400|192000
diff --git a/configs/msm8998/audio_policy_configuration.xml b/configs/msm8998/audio_policy_configuration.xml
index b6d2490..0a6bf32 100644
--- a/configs/msm8998/audio_policy_configuration.xml
+++ b/configs/msm8998/audio_policy_configuration.xml
@@ -78,13 +78,8 @@
                     <profile name="" format="dynamic"
                              samplingRates="dynamic" channelMasks="dynamic"/>
                 </mixPort>
-                <mixPort name="multichannel" role="source"
-                        flags="AUDIO_OUTPUT_FLAG_DIRECT">
-                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
-                             samplingRates="8000,11025,16000,22050,32000,44100,48000,64000,88200,96000,128000,176400,192000" channelMasks="dynamic"/>
-                </mixPort>
                 <mixPort name="direct_pcm" role="source"
-                        flags="AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM">
+                        flags="AUDIO_OUTPUT_FLAG_DIRECT">
                     <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                              samplingRates="8000,11025,12000,16000,22050,24000,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"/>
@@ -317,9 +312,9 @@
                 <route type="mix" sink="Line"
                        sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,dsd_compress_passthrough,voip_rx"/>
                 <route type="mix" sink="HDMI"
-                       sources="primary output,raw,deep_buffer,multichannel,direct_pcm,compressed_offload,compress_passthrough"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,compress_passthrough"/>
                 <route type="mix" sink="Proxy"
-                       sources="primary output,raw,deep_buffer,multichannel,direct_pcm,compressed_offload"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload"/>
                 <route type="mix" sink="FM"
                        sources="primary output"/>
                 <route type="mix" sink="BT SCO All"
diff --git a/configs/msm8998/mixer_paths_skuk.xml b/configs/msm8998/mixer_paths_skuk.xml
index 6f620e3..a618681 100644
--- a/configs/msm8998/mixer_paths_skuk.xml
+++ b/configs/msm8998/mixer_paths_skuk.xml
@@ -695,7 +695,7 @@
     </path>
 
     <path name="audio-ull-playback display-port">
-        <ctl name="DISPLAY_PORT Mixer MultiMedia3" value="1" />
+        <ctl name="DISPLAY_PORT Mixer MultiMedia8" value="1" />
     </path>
 
     <path name="audio-ull-playback bt-sco">
diff --git a/configs/msm8998/mixer_paths_tasha.xml b/configs/msm8998/mixer_paths_tasha.xml
index 8952928..f174500 100644
--- a/configs/msm8998/mixer_paths_tasha.xml
+++ b/configs/msm8998/mixer_paths_tasha.xml
@@ -765,7 +765,7 @@
     </path>
 
     <path name="audio-ull-playback display-port">
-        <ctl name="DISPLAY_PORT Mixer MultiMedia3" value="1" />
+        <ctl name="DISPLAY_PORT Mixer MultiMedia8" value="1" />
     </path>
 
     <path name="audio-ull-playback bt-sco">
diff --git a/configs/msm8998/mixer_paths_tavil.xml b/configs/msm8998/mixer_paths_tavil.xml
index 7fbef34..47f6fd1 100644
--- a/configs/msm8998/mixer_paths_tavil.xml
+++ b/configs/msm8998/mixer_paths_tavil.xml
@@ -703,7 +703,7 @@
     </path>
 
     <path name="audio-ull-playback display-port">
-        <ctl name="DISPLAY_PORT Mixer MultiMedia3" value="1" />
+        <ctl name="DISPLAY_PORT Mixer MultiMedia8" value="1" />
     </path>
 
     <path name="audio-ull-playback bt-sco">
diff --git a/configs/msm8998/msm8998.mk b/configs/msm8998/msm8998.mk
index c25550e..07a4bff 100644
--- a/configs/msm8998/msm8998.mk
+++ b/configs/msm8998/msm8998.mk
@@ -29,8 +29,12 @@
 AUDIO_FEATURE_ENABLED_HW_ACCELERATED_EFFECTS := false
 AUDIO_FEATURE_ENABLED_AUDIOSPHERE := true
 AUDIO_FEATURE_ENABLED_USB_TUNNEL_AUDIO := true
-AUDIO_FEATURE_ENABLED_SPLIT_A2DP := true
-AUDIO_FEATURE_ENABLED_3D_AUDIO := true
+AUDIO_FEATURE_ENABLED_SPLIT_A2DP := false
+AUDIO_FEATURE_ENABLED_3D_AUDIO := false
+AUDIO_FEATURE_ENABLED_VOICE_PRINT := false
+USE_LEGACY_AUDIO_DAEMON := false
+USE_LEGACY_AUDIO_MEASUREMENT := false
+DOLBY_ENABLE := false
 endif
 
 USE_XML_AUDIO_POLICY_CONF := 1
diff --git a/configs/msm8998/sound_trigger_platform_info.xml b/configs/msm8998/sound_trigger_platform_info.xml
index 036b393..c9b7ef6 100644
--- a/configs/msm8998/sound_trigger_platform_info.xml
+++ b/configs/msm8998/sound_trigger_platform_info.xml
@@ -128,7 +128,7 @@
 
     <adm_config>
         <param adm_cfg_profile="FLUENCE" />
-        <param app_type="69943" />
+        <param app_type="69944" />
         <param sample_rate="16000" />
         <param bit_width="16" />
     </adm_config>
diff --git a/configs/sdm660/audio_output_policy.conf b/configs/sdm660/audio_output_policy.conf
index f1694b5..87bf09a 100644
--- a/configs/sdm660/audio_output_policy.conf
+++ b/configs/sdm660/audio_output_policy.conf
@@ -25,29 +25,22 @@
     bit_width 16
     app_type 69936
   }
-  direct {
-    flags AUDIO_OUTPUT_FLAG_DIRECT
-    formats AUDIO_FORMAT_PCM_16_BIT
-    sampling_rates 48000
-    bit_width 16
-    app_type 69936
-  }
   direct_pcm_16 {
-    flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+    flags AUDIO_OUTPUT_FLAG_DIRECT
     formats AUDIO_FORMAT_PCM_16_BIT|AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT|AUDIO_FORMAT_PCM_32_BIT
     sampling_rates 44100|48000|96000|192000
     bit_width 16
     app_type 69936
   }
   direct_pcm_24 {
-    flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+    flags AUDIO_OUTPUT_FLAG_DIRECT
     formats AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT|AUDIO_FORMAT_PCM_32_BIT
     sampling_rates 44100|48000|96000|176400|192000|352800|384000
     bit_width 24
     app_type 69940
   }
   direct_pcm_32 {
-    flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+    flags AUDIO_OUTPUT_FLAG_DIRECT
     formats AUDIO_FORMAT_PCM_32_BIT
     sampling_rates 44100|48000|96000|176400|192000|352800|384000
     bit_width 32
diff --git a/configs/sdm660/audio_policy.conf b/configs/sdm660/audio_policy.conf
index 8fb5676..f275e16 100644
--- a/configs/sdm660/audio_policy.conf
+++ b/configs/sdm660/audio_policy.conf
@@ -50,19 +50,12 @@
         devices AUDIO_DEVICE_OUT_AUX_DIGITAL
         flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_NON_BLOCKING
       }
-      multichannel {
-        sampling_rates 8000|11025|16000|22050|32000|44100|48000|64000|88200|96000|128000|176400|192000
-        channel_masks dynamic
-        formats AUDIO_FORMAT_PCM_16_BIT
-        devices AUDIO_DEVICE_OUT_AUX_DIGITAL|AUDIO_DEVICE_OUT_PROXY
-        flags AUDIO_OUTPUT_FLAG_DIRECT
-      }
       direct_pcm {
         sampling_rates 8000|11025|12000|16000|22050|24000|32000|44100|48000|64000|88200|96000|176400|192000|352800|384000
         channel_masks 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
         formats AUDIO_FORMAT_PCM_16_BIT|AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT|AUDIO_FORMAT_PCM_32_BIT
         devices AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_EARPIECE|AUDIO_DEVICE_OUT_WIRED_HEADSET|AUDIO_DEVICE_OUT_WIRED_HEADPHONE|AUDIO_DEVICE_OUT_LINE|AUDIO_DEVICE_OUT_ALL_SCO|AUDIO_DEVICE_OUT_PROXY|AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_BLUETOOTH_A2DP|AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES|AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER
-        flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+        flags AUDIO_OUTPUT_FLAG_DIRECT
       }
       compress_offload {
         sampling_rates 8000|11025|12000|16000|22050|24000|32000|44100|48000|64000|88200|96000|176400|192000
diff --git a/configs/sdm660/audio_policy_configuration.xml b/configs/sdm660/audio_policy_configuration.xml
index b6d2490..0a6bf32 100644
--- a/configs/sdm660/audio_policy_configuration.xml
+++ b/configs/sdm660/audio_policy_configuration.xml
@@ -78,13 +78,8 @@
                     <profile name="" format="dynamic"
                              samplingRates="dynamic" channelMasks="dynamic"/>
                 </mixPort>
-                <mixPort name="multichannel" role="source"
-                        flags="AUDIO_OUTPUT_FLAG_DIRECT">
-                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
-                             samplingRates="8000,11025,16000,22050,32000,44100,48000,64000,88200,96000,128000,176400,192000" channelMasks="dynamic"/>
-                </mixPort>
                 <mixPort name="direct_pcm" role="source"
-                        flags="AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM">
+                        flags="AUDIO_OUTPUT_FLAG_DIRECT">
                     <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                              samplingRates="8000,11025,12000,16000,22050,24000,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"/>
@@ -317,9 +312,9 @@
                 <route type="mix" sink="Line"
                        sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,dsd_compress_passthrough,voip_rx"/>
                 <route type="mix" sink="HDMI"
-                       sources="primary output,raw,deep_buffer,multichannel,direct_pcm,compressed_offload,compress_passthrough"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,compress_passthrough"/>
                 <route type="mix" sink="Proxy"
-                       sources="primary output,raw,deep_buffer,multichannel,direct_pcm,compressed_offload"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload"/>
                 <route type="mix" sink="FM"
                        sources="primary output"/>
                 <route type="mix" sink="BT SCO All"
diff --git a/configs/sdm660/mixer_paths.xml b/configs/sdm660/mixer_paths.xml
index c0c788e..7aea7b3 100644
--- a/configs/sdm660/mixer_paths.xml
+++ b/configs/sdm660/mixer_paths.xml
@@ -287,6 +287,10 @@
     <ctl name="SpkrLeft SWR DAC_Port Switch" value="0" />
     <ctl name="SpkrRight SWR DAC_Port Switch" value="0" />
     <ctl name="SpkrLeft WSA PA Gain" value="G_0_DB" />
+    <ctl name="SpkrRight WSA PA Gain" value="G_0_DB" />
+    <ctl name="SpkrLeft WSA PA Mute" value="1" />
+    <ctl name="SpkrRight WSA PA Mute" value="1" />
+    <ctl name="EAR SPKR PA Gain" value="G_DEFAULT" />
 
     <!-- Volume controls -->
     <ctl name="HPHL Volume" value="9" />
@@ -1597,8 +1601,8 @@
 
     <path name="speaker">
         <ctl name="INT4_MI2S_RX Channels" value="Two" />
-        <ctl name="RX4 MIX1 INP1" value="RX1" />
-        <ctl name="RX5 MIX1 INP1" value="RX2" />
+        <ctl name="RX4 MIX1 INP1" value="RX4" />
+        <ctl name="RX5 MIX1 INP1" value="RX5" />
         <ctl name="COMP1 Switch" value="1" />
         <ctl name="COMP2 Switch" value="1" />
         <ctl name="SpkrLeft COMP Switch" value="1" />
@@ -1609,26 +1613,30 @@
         <ctl name="SpkrRight BOOST Switch" value="1" />
         <ctl name="SpkrRight VISENSE Switch" value="1" />
         <ctl name="SpkrRight SWR DAC_Port Switch" value="1" />
+        <ctl name="SpkrLeft WSA PA Mute" value="0" />
+        <ctl name="SpkrRight WSA PA Mute" value="0" />
     </path>
 
     <path name="speaker-mono">
         <ctl name="INT4_MI2S_RX Channels" value="One" />
-        <ctl name="RX4 MIX1 INP1" value="RX1" />
+        <ctl name="RX4 MIX1 INP1" value="RX4" />
         <ctl name="COMP1 Switch" value="1" />
         <ctl name="SpkrLeft COMP Switch" value="1" />
         <ctl name="SpkrLeft BOOST Switch" value="1" />
         <ctl name="SpkrLeft VISENSE Switch" value="1" />
         <ctl name="SpkrLeft SWR DAC_Port Switch" value="1" />
+        <ctl name="SpkrLeft WSA PA Mute" value="0" />
     </path>
 
     <path name="speaker-mono-2">
         <ctl name="INT4_MI2S_RX Channels" value="One" />
-        <ctl name="RX5 MIX1 INP1" value="RX2" />
+        <ctl name="RX5 MIX1 INP1" value="RX4" />
         <ctl name="COMP2 Switch" value="1" />
         <ctl name="SpkrRight COMP Switch" value="1" />
         <ctl name="SpkrRight BOOST Switch" value="1" />
         <ctl name="SpkrRight VISENSE Switch" value="1" />
         <ctl name="SpkrRight SWR DAC_Port Switch" value="1" />
+        <ctl name="SpkrRight WSA PA Mute" value="0" />
     </path>
 
     <path name="speaker-fluid">
@@ -1674,6 +1682,7 @@
 
     <path name="speaker-mic">
         <path name="adc1" />
+        <ctl name="IIR1 INP1 MUX" value="DEC1" />
     </path>
 
     <path name="speaker-mic-liquid">
@@ -1728,11 +1737,13 @@
     </path>
 
     <path name="handset">
+        <ctl name="EAR SPKR PA Gain" value="G_3_DB" />
         <path name="speaker-mono" />
     </path>
 
     <path name="handset-mic">
         <path name="adc1" />
+        <ctl name="IIR1 INP1 MUX" value="DEC1" />
     </path>
 
     <path name="handset-mic-db">
@@ -1781,6 +1792,7 @@
 
     <path name="headset-mic">
         <path name="adc2" />
+        <ctl name="IIR1 INP1 MUX" value="DEC1" />
     </path>
 
     <path name="headset-mic-liquid">
@@ -2028,7 +2040,7 @@
 
     <path name="dmic-broadside">
         <path name="speaker-dmic-broadside" />
-        <ctl name="IIR1 INP1 MUX" value="DEC7" />
+        <ctl name="IIR1 INP1 MUX" value="DEC1" />
     </path>
 
     <path name="voice-speaker-dmic-broadside">
diff --git a/configs/sdm660/mixer_paths_mtp.xml b/configs/sdm660/mixer_paths_mtp.xml
index 307e557..a11d843 100644
--- a/configs/sdm660/mixer_paths_mtp.xml
+++ b/configs/sdm660/mixer_paths_mtp.xml
@@ -287,6 +287,9 @@
     <ctl name="SpkrLeft SWR DAC_Port Switch" value="0" />
     <ctl name="SpkrRight SWR DAC_Port Switch" value="0" />
     <ctl name="SpkrLeft WSA PA Gain" value="G_0_DB" />
+    <ctl name="SpkrRight WSA PA Gain" value="G_0_DB" />
+    <ctl name="SpkrLeft WSA PA Mute" value="1" />
+    <ctl name="SpkrRight WSA PA Mute" value="1" />
     <ctl name="EAR SPKR PA Gain" value="G_DEFAULT" />
 
     <!-- Volume controls -->
@@ -1610,6 +1613,8 @@
         <ctl name="SpkrRight BOOST Switch" value="1" />
         <ctl name="SpkrRight VISENSE Switch" value="1" />
         <ctl name="SpkrRight SWR DAC_Port Switch" value="1" />
+        <ctl name="SpkrLeft WSA PA Mute" value="0" />
+        <ctl name="SpkrRight WSA PA Mute" value="0" />
     </path>
 
     <path name="speaker-mono">
@@ -1620,6 +1625,7 @@
         <ctl name="SpkrLeft BOOST Switch" value="1" />
         <ctl name="SpkrLeft VISENSE Switch" value="1" />
         <ctl name="SpkrLeft SWR DAC_Port Switch" value="1" />
+        <ctl name="SpkrLeft WSA PA Mute" value="0" />
     </path>
 
     <path name="speaker-mono-2">
@@ -1630,6 +1636,7 @@
         <ctl name="SpkrRight BOOST Switch" value="1" />
         <ctl name="SpkrRight VISENSE Switch" value="1" />
         <ctl name="SpkrRight SWR DAC_Port Switch" value="1" />
+        <ctl name="SpkrRight WSA PA Mute" value="0" />
     </path>
 
     <path name="speaker-fluid">
@@ -1729,8 +1736,8 @@
     </path>
 
     <path name="handset">
+        <ctl name="EAR SPKR PA Gain" value="G_3_DB" />
         <path name="speaker-mono" />
-        <ctl name="EAR SPKR PA Gain" value="G_6_DB" />
     </path>
 
     <path name="handset-mic">
diff --git a/configs/sdm660/mixer_paths_skuk.xml b/configs/sdm660/mixer_paths_skuk.xml
index 2acfbad..81bd534 100644
--- a/configs/sdm660/mixer_paths_skuk.xml
+++ b/configs/sdm660/mixer_paths_skuk.xml
@@ -701,7 +701,7 @@
     </path>
 
     <path name="audio-ull-playback display-port">
-        <ctl name="DISPLAY_PORT Mixer MultiMedia3" value="1" />
+        <ctl name="DISPLAY_PORT Mixer MultiMedia8" value="1" />
     </path>
 
     <path name="audio-ull-playback bt-sco">
diff --git a/configs/sdm660/mixer_paths_skush.xml b/configs/sdm660/mixer_paths_skush.xml
index f51037c..67ef5e1 100644
--- a/configs/sdm660/mixer_paths_skush.xml
+++ b/configs/sdm660/mixer_paths_skush.xml
@@ -1686,7 +1686,8 @@
     </path>
 
     <path name="speaker-mic">
-        <path name="dmic3" />
+        <path name="dmic1" />
+        <ctl name="IIR1 INP1 MUX" value="DEC1" />
     </path>
 
     <path name="speaker-mic-liquid">
@@ -1749,6 +1750,7 @@
 
     <path name="handset-mic">
         <path name="dmic4" />
+        <ctl name="IIR1 INP1 MUX" value="DEC1" />
     </path>
 
     <path name="handset-mic-db">
@@ -1763,9 +1765,9 @@
 
     <path name="three-mic">
         <ctl name="INT3_MI2S_TX Channels" value="Three" />
-        <ctl name="DEC1 MUX" value="DMIC3" />
+        <ctl name="DEC1 MUX" value="DMIC1" />
         <ctl name="DEC2 MUX" value="DMIC4" />
-        <ctl name="DEC3 MUX" value="DMIC1" />
+        <ctl name="DEC3 MUX" value="DMIC3" />
         <ctl name="I2S TX2 INP1" value="DEC3" />
     </path>
 
@@ -1794,6 +1796,7 @@
 
     <path name="headset-mic">
         <path name="adc2" />
+        <ctl name="IIR1 INP1 MUX" value="DEC1" />
     </path>
 
     <path name="headset-mic-liquid">
@@ -1961,13 +1964,13 @@
     <!-- Dual MIC devices -->
     <path name="handset-dmic-endfire">
         <ctl name="DEC1 MUX" value="DMIC4" />
-        <ctl name="DEC2 MUX" value="DMIC1" />
+        <ctl name="DEC2 MUX" value="DMIC3" />
         <ctl name="INT3_MI2S_TX Channels" value="Two" />
     </path>
 
     <path name="speaker-dmic-endfire">
-        <ctl name="DEC1 MUX" value="DMIC3" />
-        <ctl name="DEC2 MUX" value="DMIC1" />
+        <ctl name="DEC1 MUX" value="DMIC1" />
+        <ctl name="DEC2 MUX" value="DMIC3" />
         <ctl name="INT3_MI2S_TX Channels" value="Two" />
     </path>
 
@@ -2035,13 +2038,13 @@
 
     <path name="speaker-dmic-broadside">
         <ctl name="INT3_MI2S_TX Channels" value="Two" />
-        <ctl name="DEC1 MUX" value="DMIC3" />
+        <ctl name="DEC1 MUX" value="DMIC1" />
         <ctl name="DEC2 MUX" value="DMIC4" />
     </path>
 
     <path name="dmic-broadside">
         <path name="speaker-dmic-broadside" />
-        <ctl name="IIR1 INP1 MUX" value="DEC7" />
+        <ctl name="IIR1 INP1 MUX" value="DEC1" />
     </path>
 
     <path name="voice-speaker-dmic-broadside">
@@ -2051,9 +2054,9 @@
     <!-- Quad MIC devices -->
     <path name="speaker-qmic">
         <ctl name="INT3_MI2S_TX Channels" value="Four" />
-        <ctl name="DEC1 MUX" value="DMIC3" />
+        <ctl name="DEC1 MUX" value="DMIC1" />
         <ctl name="DEC2 MUX" value="DMIC4" />
-        <ctl name="DEC3 MUX" value="DMIC1" />
+        <ctl name="DEC3 MUX" value="DMIC3" />
         <ctl name="I2S TX2 INP1" value="DEC3" />
         <ctl name="DEC4 MUX" value="DMIC2" />
         <ctl name="I2S TX2 INP2" value="DEC4" />
diff --git a/configs/sdm660/mixer_paths_wcd9340.xml b/configs/sdm660/mixer_paths_wcd9340.xml
index 5cfc68e..6160cb3 100644
--- a/configs/sdm660/mixer_paths_wcd9340.xml
+++ b/configs/sdm660/mixer_paths_wcd9340.xml
@@ -479,27 +479,27 @@
     <ctl name="ASRC1 Output Mode" value="INT" />
 
     <!-- IIR/voice anc -->
-    <ctl name="IIR0 Band1" id ="0" value="268435456" />
+    <ctl name="IIR0 Band1" id ="0" value="0" />
     <ctl name="IIR0 Band1" id ="1" value="0" />
     <ctl name="IIR0 Band1" id ="2" value="0" />
     <ctl name="IIR0 Band1" id ="3" value="0" />
     <ctl name="IIR0 Band1" id ="4" value="0" />
-    <ctl name="IIR0 Band2" id ="0" value="268435456" />
+    <ctl name="IIR0 Band2" id ="0" value="0" />
     <ctl name="IIR0 Band2" id ="1" value="0" />
     <ctl name="IIR0 Band2" id ="2" value="0" />
     <ctl name="IIR0 Band2" id ="3" value="0" />
     <ctl name="IIR0 Band2" id ="4" value="0" />
-    <ctl name="IIR0 Band3" id ="0" value="268435456" />
+    <ctl name="IIR0 Band3" id ="0" value="0" />
     <ctl name="IIR0 Band3" id ="1" value="0" />
     <ctl name="IIR0 Band3" id ="2" value="0" />
     <ctl name="IIR0 Band3" id ="3" value="0" />
     <ctl name="IIR0 Band3" id ="4" value="0" />
-    <ctl name="IIR0 Band4" id ="0" value="268435456" />
+    <ctl name="IIR0 Band4" id ="0" value="0" />
     <ctl name="IIR0 Band4" id ="1" value="0" />
     <ctl name="IIR0 Band4" id ="2" value="0" />
     <ctl name="IIR0 Band4" id ="3" value="0" />
     <ctl name="IIR0 Band4" id ="4" value="0" />
-    <ctl name="IIR0 Band5" id ="0" value="268435456" />
+    <ctl name="IIR0 Band5" id ="0" value="0" />
     <ctl name="IIR0 Band5" id ="1" value="0" />
     <ctl name="IIR0 Band5" id ="2" value="0" />
     <ctl name="IIR0 Band5" id ="3" value="0" />
@@ -1859,6 +1859,31 @@
    </path>
 
    <path name="sidetone-iir">
+        <ctl name="IIR0 Band1" id ="0" value="268435456" />
+        <ctl name="IIR0 Band1" id ="1" value="0" />
+        <ctl name="IIR0 Band1" id ="2" value="0" />
+        <ctl name="IIR0 Band1" id ="3" value="0" />
+        <ctl name="IIR0 Band1" id ="4" value="0" />
+        <ctl name="IIR0 Band2" id ="0" value="268435456" />
+        <ctl name="IIR0 Band2" id ="1" value="0" />
+        <ctl name="IIR0 Band2" id ="2" value="0" />
+        <ctl name="IIR0 Band2" id ="3" value="0" />
+        <ctl name="IIR0 Band2" id ="4" value="0" />
+        <ctl name="IIR0 Band3" id ="0" value="268435456" />
+        <ctl name="IIR0 Band3" id ="1" value="0" />
+        <ctl name="IIR0 Band3" id ="2" value="0" />
+        <ctl name="IIR0 Band3" id ="3" value="0" />
+        <ctl name="IIR0 Band3" id ="4" value="0" />
+        <ctl name="IIR0 Band4" id ="0" value="268435456" />
+        <ctl name="IIR0 Band4" id ="1" value="0" />
+        <ctl name="IIR0 Band4" id ="2" value="0" />
+        <ctl name="IIR0 Band4" id ="3" value="0" />
+        <ctl name="IIR0 Band4" id ="4" value="0" />
+        <ctl name="IIR0 Band5" id ="0" value="268435456" />
+        <ctl name="IIR0 Band5" id ="1" value="0" />
+        <ctl name="IIR0 Band5" id ="2" value="0" />
+        <ctl name="IIR0 Band5" id ="3" value="0" />
+        <ctl name="IIR0 Band5" id ="4" value="0" />
         <ctl name="IIR0 Enable Band1" value="1" />
         <ctl name="IIR0 Enable Band2" value="1" />
         <ctl name="IIR0 Enable Band3" value="1" />
diff --git a/configs/sdm660/sdm660.mk b/configs/sdm660/sdm660.mk
index 5496d34..dee74b1 100644
--- a/configs/sdm660/sdm660.mk
+++ b/configs/sdm660/sdm660.mk
@@ -40,8 +40,9 @@
 AUDIO_FEATURE_ENABLED_AUDIOSPHERE := true
 AUDIO_FEATURE_ENABLED_GEF_SUPPORT := true
 AUDIO_FEATURE_ENABLED_USB_TUNNEL_AUDIO := true
-AUDIO_FEATURE_ENABLED_SPLIT_A2DP := true
-AUDIO_FEATURE_ENABLED_3D_AUDIO := true
+AUDIO_FEATURE_ENABLED_SPLIT_A2DP := false
+AUDIO_FEATURE_ENABLED_3D_AUDIO := false
+DOLBY_ENABLE := false
 endif
 
 USE_XML_AUDIO_POLICY_CONF := 1
diff --git a/configs/sdm845/audio_output_policy.conf b/configs/sdm845/audio_output_policy.conf
index 3a610c1..3e4f5fd 100644
--- a/configs/sdm845/audio_output_policy.conf
+++ b/configs/sdm845/audio_output_policy.conf
@@ -32,29 +32,22 @@
     bit_width 16
     app_type 69936
   }
-  direct {
-    flags AUDIO_OUTPUT_FLAG_DIRECT
-    formats AUDIO_FORMAT_PCM_16_BIT
-    sampling_rates 48000
-    bit_width 16
-    app_type 69936
-  }
   direct_pcm_16 {
-    flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+    flags AUDIO_OUTPUT_FLAG_DIRECT
     formats AUDIO_FORMAT_PCM_16_BIT|AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT|AUDIO_FORMAT_PCM_32_BIT
     sampling_rates 44100|48000|96000|192000
     bit_width 16
     app_type 69936
   }
   direct_pcm_24 {
-    flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+    flags AUDIO_OUTPUT_FLAG_DIRECT
     formats AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT|AUDIO_FORMAT_PCM_32_BIT
     sampling_rates 44100|48000|96000|176400|192000|352800|384000
     bit_width 24
     app_type 69940
   }
   direct_pcm_32 {
-    flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+    flags AUDIO_OUTPUT_FLAG_DIRECT
     formats AUDIO_FORMAT_PCM_32_BIT
     sampling_rates 44100|48000|96000|176400|192000|352800|384000
     bit_width 32
diff --git a/configs/sdm845/audio_policy.conf b/configs/sdm845/audio_policy.conf
index 8fb5676..f275e16 100644
--- a/configs/sdm845/audio_policy.conf
+++ b/configs/sdm845/audio_policy.conf
@@ -50,19 +50,12 @@
         devices AUDIO_DEVICE_OUT_AUX_DIGITAL
         flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_NON_BLOCKING
       }
-      multichannel {
-        sampling_rates 8000|11025|16000|22050|32000|44100|48000|64000|88200|96000|128000|176400|192000
-        channel_masks dynamic
-        formats AUDIO_FORMAT_PCM_16_BIT
-        devices AUDIO_DEVICE_OUT_AUX_DIGITAL|AUDIO_DEVICE_OUT_PROXY
-        flags AUDIO_OUTPUT_FLAG_DIRECT
-      }
       direct_pcm {
         sampling_rates 8000|11025|12000|16000|22050|24000|32000|44100|48000|64000|88200|96000|176400|192000|352800|384000
         channel_masks 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
         formats AUDIO_FORMAT_PCM_16_BIT|AUDIO_FORMAT_PCM_24_BIT_PACKED|AUDIO_FORMAT_PCM_8_24_BIT|AUDIO_FORMAT_PCM_32_BIT
         devices AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_EARPIECE|AUDIO_DEVICE_OUT_WIRED_HEADSET|AUDIO_DEVICE_OUT_WIRED_HEADPHONE|AUDIO_DEVICE_OUT_LINE|AUDIO_DEVICE_OUT_ALL_SCO|AUDIO_DEVICE_OUT_PROXY|AUDIO_DEVICE_OUT_USB_DEVICE|AUDIO_DEVICE_OUT_BLUETOOTH_A2DP|AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES|AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER
-        flags AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM
+        flags AUDIO_OUTPUT_FLAG_DIRECT
       }
       compress_offload {
         sampling_rates 8000|11025|12000|16000|22050|24000|32000|44100|48000|64000|88200|96000|176400|192000
diff --git a/configs/sdm845/audio_policy_configuration.xml b/configs/sdm845/audio_policy_configuration.xml
index 914dfc5..1b14765 100644
--- a/configs/sdm845/audio_policy_configuration.xml
+++ b/configs/sdm845/audio_policy_configuration.xml
@@ -78,13 +78,8 @@
                     <profile name="" format="dynamic"
                              samplingRates="dynamic" channelMasks="dynamic"/>
                 </mixPort>
-                <mixPort name="multichannel" role="source"
-                        flags="AUDIO_OUTPUT_FLAG_DIRECT">
-                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
-                             samplingRates="8000,11025,16000,22050,32000,44100,48000,64000,88200,96000,128000,176400,192000" channelMasks="dynamic"/>
-                </mixPort>
                 <mixPort name="direct_pcm" role="source"
-                        flags="AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM">
+                        flags="AUDIO_OUTPUT_FLAG_DIRECT">
                     <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
                              samplingRates="8000,11025,12000,16000,22050,24000,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"/>
@@ -317,9 +312,9 @@
                 <route type="mix" sink="Line"
                        sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,dsd_compress_passthrough,voip_rx"/>
                 <route type="mix" sink="HDMI"
-                       sources="primary output,raw,deep_buffer,multichannel,direct_pcm,compressed_offload,compress_passthrough"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload,compress_passthrough"/>
                 <route type="mix" sink="Proxy"
-                       sources="primary output,raw,deep_buffer,multichannel,direct_pcm,compressed_offload"/>
+                       sources="primary output,raw,deep_buffer,direct_pcm,compressed_offload"/>
                 <route type="mix" sink="FM"
                        sources="primary output"/>
                 <route type="mix" sink="BT SCO All"
diff --git a/configs/sdm845/sdm845.mk b/configs/sdm845/sdm845.mk
index fa4b3ad..2a08c02 100644
--- a/configs/sdm845/sdm845.mk
+++ b/configs/sdm845/sdm845.mk
@@ -29,8 +29,9 @@
 AUDIO_FEATURE_ENABLED_HW_ACCELERATED_EFFECTS := false
 AUDIO_FEATURE_ENABLED_AUDIOSPHERE := true
 AUDIO_FEATURE_ENABLED_USB_TUNNEL_AUDIO := true
-AUDIO_FEATURE_ENABLED_SPLIT_A2DP := true
-AUDIO_FEATURE_ENABLED_3D_AUDIO := true
+AUDIO_FEATURE_ENABLED_SPLIT_A2DP := false
+AUDIO_FEATURE_ENABLED_3D_AUDIO := false
+DOLBY_ENABLE := false
 endif
 
 USE_XML_AUDIO_POLICY_CONF := 1
diff --git a/hal/audio_extn/a2dp.c b/hal/audio_extn/a2dp.c
index 40632bc..659d72c 100644
--- a/hal/audio_extn/a2dp.c
+++ b/hal/audio_extn/a2dp.c
@@ -808,7 +808,8 @@
 {
     bool ret = false;
 
-    if ((a2dp.is_a2dp_offload_supported) &&
+    if ((a2dp.bt_state != A2DP_STATE_DISCONNECTED) &&
+        (a2dp.is_a2dp_offload_supported) &&
         (a2dp.audio_check_a2dp_ready))
            ret = a2dp.audio_check_a2dp_ready();
     return ret;
@@ -843,7 +844,9 @@
         ALOGE(" a2dp handle is not identified");
         return latency;
     }
-    codec_info = a2dp.audio_get_codec_config(&multi_cast, &num_dev,
+
+    if (a2dp.a2dp_started)
+        codec_info = a2dp.audio_get_codec_config(&multi_cast, &num_dev,
                                &codec_type);
 
     memset(value, '\0', sizeof(char)*PROPERTY_VALUE_MAX);
diff --git a/hal/audio_extn/ssr.c b/hal/audio_extn/ssr.c
index 51a6a26..f64a861 100644
--- a/hal/audio_extn/ssr.c
+++ b/hal/audio_extn/ssr.c
@@ -367,7 +367,7 @@
              */
             ALOGD("%s: SSR supports only channel representation position, channel_mask(%#x)"
                               ,__func__, config->channel_mask);
-            config->channel_mask = AUDIO_CHANNEL_IN_5POINT1;
+            config->channel_mask = AUDIO_CHANNEL_IN_6;
             ret = 0;
             *update_params = true;
         } else {
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c
index fd35e28..caa177a 100644
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.c
@@ -89,7 +89,6 @@
 
 const struct string_to_enum s_flag_name_to_enum_table[] = {
     STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DIRECT),
-    STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DIRECT_PCM),
     STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_PRIMARY),
     STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_FAST),
     STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_RAW),
@@ -1269,11 +1268,15 @@
         platform_send_audio_calibration(adev->platform, usecase,
                          usecase->stream.in->app_type_cfg.app_type,
                          usecase->stream.in->app_type_cfg.sample_rate);
-    } else {
+    } else if (type == PCM_HFP_CALL) {
         /* when app type is default. the sample rate is not used to send cal */
         platform_send_audio_calibration(adev->platform, usecase,
                          platform_get_default_app_type_v2(adev->platform, usecase->type),
                          48000);
+    } else {
+        /* No need to send audio calibration for voice and voip call usecases */
+        if ((type != VOICE_CALL) && (type != VOIP_CALL))
+            ALOGW("%s: No audio calibration for usecase type = %d",  __func__, type);
     }
 }
 
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 6644b48..a42158e 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -606,73 +606,90 @@
  *   ASRC mode for incoming Headphone 44.1 or Native DSD use case.
  *   e.g. Naitve DSD or Headphone 44.1 -> + 48
  */
-static void check_and_set_asrc_mode(struct audio_device *adev, snd_device_t snd_device)
+static void check_and_set_asrc_mode(struct audio_device *adev,
+                                          struct audio_usecase *uc_info,
+                                          snd_device_t snd_device)
 {
     ALOGV("%s snd device %d", __func__, snd_device);
-    int new_backend_idx = platform_get_backend_index(snd_device);
+    int i, num_new_devices = 0;
+    snd_device_t split_new_snd_devices[SND_DEVICE_OUT_END];
+    /*
+    *Split snd device for new combo use case
+    *e.g. Headphopne 44.1-> + Ringtone (Headphone + Speaker)
+    */
+    if (platform_split_snd_device(adev->platform,
+                                 snd_device,
+                                 &num_new_devices,
+                                 split_new_snd_devices) == 0) {
+        for (i = 0; i < num_new_devices; i++)
+            check_and_set_asrc_mode(adev, uc_info, split_new_snd_devices[i]);
+    } else {
+        int new_backend_idx = platform_get_backend_index(snd_device);
+        if (((new_backend_idx == HEADPHONE_BACKEND) ||
+                (new_backend_idx == HEADPHONE_44_1_BACKEND) ||
+                (new_backend_idx == DSD_NATIVE_BACKEND)) &&
+                !adev->asrc_mode_enabled) {
+            struct listnode *node = NULL;
+            struct audio_usecase *uc = NULL;
+            struct stream_out *curr_out = NULL;
+            int usecase_backend_idx = DEFAULT_CODEC_BACKEND;
+            int i, num_devices, ret = 0;
+            snd_device_t split_snd_devices[SND_DEVICE_OUT_END];
 
-    if (((new_backend_idx == HEADPHONE_BACKEND) ||
-            (new_backend_idx == HEADPHONE_44_1_BACKEND) ||
-            (new_backend_idx == DSD_NATIVE_BACKEND)) &&
-            !adev->asrc_mode_enabled) {
-        struct listnode *node = NULL;
-        struct audio_usecase *uc = NULL;
-        struct stream_out *curr_out = NULL;
-        int usecase_backend_idx = DEFAULT_CODEC_BACKEND;
-        int i, num_devices, ret = 0;
-        snd_device_t split_snd_devices[SND_DEVICE_OUT_END];
-
-        list_for_each(node, &adev->usecase_list) {
-            uc = node_to_item(node, struct audio_usecase, list);
-            curr_out = (struct stream_out*) uc->stream.out;
-
-            if (curr_out && PCM_PLAYBACK == uc->type) {
-                ret = platform_split_snd_device(adev->platform,
-                                         uc->out_snd_device,
-                                         &num_devices,
-                                         split_snd_devices);
-                if (ret < 0 || num_devices == 0) {
-                    ALOGV("%s: Unable to split uc->out_snd_device: %d",__func__, uc->out_snd_device);
-                    split_snd_devices[0] = uc->out_snd_device;
-                    num_devices = 1;
-                }
-                for (i = 0; i < num_devices; i++) {
-                    usecase_backend_idx = platform_get_backend_index(split_snd_devices[i]);
-                    ALOGD("%s:snd_dev %d usecase_backend_idx %d",__func__, split_snd_devices[i],usecase_backend_idx);
-                    if((new_backend_idx == HEADPHONE_BACKEND) &&
-                           ((usecase_backend_idx == HEADPHONE_44_1_BACKEND) ||
-                           (usecase_backend_idx == DSD_NATIVE_BACKEND))) {
-                        ALOGD("%s:DSD or native stream detected enabling asrcmode in hardware",
-                              __func__);
-                        enable_asrc_mode(adev);
-                        break;
-                    } else if(((new_backend_idx == HEADPHONE_44_1_BACKEND) ||
-                              (new_backend_idx == DSD_NATIVE_BACKEND)) &&
-                              (usecase_backend_idx == HEADPHONE_BACKEND)) {
-                        ALOGD("%s:48K stream detected, disabling and enabling it with asrcmode in hardware",
-                              __func__);
-                        disable_audio_route(adev, uc);
-                        disable_snd_device(adev, uc->out_snd_device);
-                        // Apply true-high-quality-mode if DSD or > 44.1KHz or >=24-bit
-                        if (new_backend_idx == DSD_NATIVE_BACKEND)
-                          audio_route_apply_and_update_path(adev->audio_route,
-                                                    "hph-true-highquality-mode");
-                        else if ((new_backend_idx == HEADPHONE_44_1_BACKEND) &&
-                                 (curr_out->bit_width >= 24))
-                            audio_route_apply_and_update_path(adev->audio_route,
-                                                         "hph-highquality-mode");
-                        enable_asrc_mode(adev);
-                        enable_snd_device(adev, uc->out_snd_device);
-                        enable_audio_route(adev, uc);
-                        break;
+            list_for_each(node, &adev->usecase_list) {
+                uc = node_to_item(node, struct audio_usecase, list);
+                curr_out = (struct stream_out*) uc->stream.out;
+                if (curr_out && PCM_PLAYBACK == uc->type && uc != uc_info) {
+                    /*
+                    *Split snd device for existing combo use case
+                    *e.g. Ringtone (Headphone + Speaker) + Headphopne 44.1
+                    */
+                    ret = platform_split_snd_device(adev->platform,
+                                             uc->out_snd_device,
+                                             &num_devices,
+                                             split_snd_devices);
+                    if (ret < 0 || num_devices == 0) {
+                        ALOGV("%s: Unable to split uc->out_snd_device: %d",__func__, uc->out_snd_device);
+                        split_snd_devices[0] = uc->out_snd_device;
+                        num_devices = 1;
                     }
+                    for (i = 0; i < num_devices; i++) {
+                        usecase_backend_idx = platform_get_backend_index(split_snd_devices[i]);
+                        ALOGD("%s:snd_dev %d usecase_backend_idx %d",__func__, split_snd_devices[i],usecase_backend_idx);
+                        if((new_backend_idx == HEADPHONE_BACKEND) &&
+                               ((usecase_backend_idx == HEADPHONE_44_1_BACKEND) ||
+                               (usecase_backend_idx == DSD_NATIVE_BACKEND))) {
+                            ALOGD("%s:DSD or native stream detected enabling asrcmode in hardware",
+                                  __func__);
+                            enable_asrc_mode(adev);
+                            break;
+                        } else if(((new_backend_idx == HEADPHONE_44_1_BACKEND) ||
+                                  (new_backend_idx == DSD_NATIVE_BACKEND)) &&
+                                  (usecase_backend_idx == HEADPHONE_BACKEND)) {
+                            ALOGD("%s:48K stream detected, disabling and enabling it with asrcmode in hardware",
+                                  __func__);
+                            disable_audio_route(adev, uc);
+                            disable_snd_device(adev, uc->out_snd_device);
+                            // Apply true-high-quality-mode if DSD or > 44.1KHz or >=24-bit
+                            if (new_backend_idx == DSD_NATIVE_BACKEND)
+                                audio_route_apply_and_update_path(adev->audio_route,
+                                                        "hph-true-highquality-mode");
+                            else if ((new_backend_idx == HEADPHONE_44_1_BACKEND) &&
+                                     (curr_out->bit_width >= 24))
+                                audio_route_apply_and_update_path(adev->audio_route,
+                                                             "hph-highquality-mode");
+                            enable_asrc_mode(adev);
+                            enable_snd_device(adev, uc->out_snd_device);
+                            enable_audio_route(adev, uc);
+                            break;
+                        }
+                    }
+                    // reset split devices count
+                    num_devices = 0;
                 }
-                // reset split devices count
-                num_devices = 0;
+                if (adev->asrc_mode_enabled)
+                    break;
             }
-            if (adev->asrc_mode_enabled)
-                break;
-
         }
     }
 }
@@ -798,8 +815,6 @@
     } else {
         ALOGD("%s: snd_device(%d: %s)", __func__, snd_device, device_name);
 
-       if (platform_check_codec_asrc_support(adev->platform))
-           check_and_set_asrc_mode(adev, snd_device);
 
        if ((SND_DEVICE_OUT_BT_A2DP == snd_device) &&
            (audio_extn_a2dp_start_playback() < 0)) {
@@ -1023,6 +1038,8 @@
     struct listnode *node;
     struct audio_usecase *usecase;
     bool switch_device[AUDIO_USECASE_MAX];
+    snd_device_t uc_derive_snd_device;
+    snd_device_t derive_snd_device[AUDIO_USECASE_MAX];
     int i, num_uc_to_switch = 0;
     int status = 0;
     bool force_restart_session = false;
@@ -1070,11 +1087,11 @@
               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));
+        uc_derive_snd_device = derive_playback_snd_device(adev->platform,
+                                           usecase, uc_info, snd_device);
         if (usecase->type != PCM_CAPTURE &&
             usecase != uc_info &&
-            (derive_playback_snd_device(adev->platform,
-                                        usecase, uc_info,
-                                        snd_device) != usecase->out_snd_device || force_routing) &&
+            ((uc_derive_snd_device != usecase->out_snd_device) || force_routing) &&
             ((usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) ||
              (usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) ||
              (usecase->devices & AUDIO_DEVICE_OUT_USB_DEVICE) ||
@@ -1088,6 +1105,8 @@
                       platform_get_snd_device_name(usecase->out_snd_device));
                 disable_audio_route(adev, usecase);
                 switch_device[usecase->id] = true;
+                /* Enable existing usecase on derived playback device */
+                derive_snd_device[usecase->id] = uc_derive_snd_device;
                 num_uc_to_switch++;
         }
     }
@@ -1110,7 +1129,7 @@
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
             if (switch_device[usecase->id]) {
-                enable_snd_device(adev, snd_device);
+                enable_snd_device(adev, derive_snd_device[usecase->id]);
             }
         }
 
@@ -1120,7 +1139,7 @@
             usecase = node_to_item(node, struct audio_usecase, list);
             /* Update the out_snd_device only before enabling the audio route */
             if (switch_device[usecase->id]) {
-                usecase->out_snd_device = snd_device;
+                usecase->out_snd_device = derive_snd_device[usecase->id];
                 if (usecase->type != VOICE_CALL) {
                     ALOGD("%s:becf: enabling usecase (%s) on (%s)", __func__,
                          use_case_table[usecase->id],
@@ -1620,6 +1639,8 @@
     /* Enable new sound devices */
     if (out_snd_device != SND_DEVICE_NONE) {
         check_usecases_codec_backend(adev, usecase, out_snd_device);
+        if (platform_check_codec_asrc_support(adev->platform))
+            check_and_set_asrc_mode(adev, usecase, out_snd_device);
         enable_snd_device(adev, out_snd_device);
     }
 
@@ -1927,13 +1948,13 @@
     return false;
 }
 
-static audio_usecase_t get_offload_usecase(struct audio_device *adev, bool is_direct_pcm)
+static audio_usecase_t get_offload_usecase(struct audio_device *adev, bool is_compress)
 {
     audio_usecase_t ret_uc = USECASE_INVALID;
     unsigned int offload_uc_index;
     unsigned int num_usecase = sizeof(offload_usecases)/sizeof(offload_usecases[0]);
     if (!adev->multi_offload_enable) {
-        if (is_direct_pcm)
+        if (!is_compress)
             ret_uc = USECASE_AUDIO_PLAYBACK_OFFLOAD2;
         else
             ret_uc = USECASE_AUDIO_PLAYBACK_OFFLOAD;
@@ -2525,11 +2546,12 @@
 {
     struct stream_out *out = (struct stream_out *)stream;
 
-    if (is_offload_usecase(out->usecase))
+    if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)
         return out->compr_config.fragment_size;
     else if(out->usecase == USECASE_COMPRESS_VOIP_CALL)
         return voice_extn_compress_voip_out_get_buffer_size(out);
-    else if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM)
+    else if (is_offload_usecase(out->usecase) &&
+             out->flags == AUDIO_OUTPUT_FLAG_DIRECT)
         return out->hal_fragment_size;
 
     return out->config.period_size * out->af_period_multiplier *
@@ -2854,7 +2876,8 @@
     ret = str_parms_get_str(query, "is_direct_pcm_track", value, sizeof(value));
     if (ret >= 0) {
         value[0] = '\0';
-        if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) {
+        if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT &&
+            !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) {
             ALOGV("in direct_pcm");
             strlcat(value, "true", sizeof(value ));
         } else {
@@ -3031,7 +3054,7 @@
 
     if (SND_CARD_STATE_OFFLINE == snd_scard_state) {
 
-        if ((!(out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) && is_offload_usecase(out->usecase)) {
+        if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
             /*during SSR for compress usecase we should return error to flinger*/
             ALOGD(" copl %s: sound card is not active/SSR state", __func__);
             pthread_mutex_unlock(&out->lock);
@@ -3097,7 +3120,7 @@
                 out->is_compr_metadata_avail = false;
             }
         }
-        if ((out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) &&
+        if (!(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
                       (out->convert_buffer) != NULL) {
 
             if ((bytes > out->hal_fragment_size)) {
@@ -3253,7 +3276,7 @@
         /* Below piece of code is not guarded against any lock beacuse audioFliner serializes
          * this operation and adev_close_output_stream(where out gets reset).
          */
-        if (!out->non_blocking && (out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) {
+        if (!out->non_blocking && !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) {
             *dsp_frames = get_actual_pcm_frames_rendered(out);
              ALOGVV("dsp_frames %d sampleRate %d",(int)*dsp_frames,out->sample_rate);
              return 0;
@@ -3322,7 +3345,7 @@
      * this operation and adev_close_output_stream( where out gets reset).
      */
     if (is_offload_usecase(out->usecase) && !out->non_blocking &&
-        (out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) {
+        !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) {
         *frames = get_actual_pcm_frames_rendered(out);
         /* this is the best we can do */
         clock_gettime(CLOCK_MONOTONIC, timestamp);
@@ -3794,7 +3817,10 @@
             pthread_mutex_unlock(&adev->lock);
             in->standby = true;
         }
-        memset(buffer, 0, bytes);
+        if (!audio_extn_cin_attached_usecase(in->usecase)) {
+            bytes_read = bytes;
+            memset(buffer, 0, bytes);
+        }
         in_standby(&in->stream.common);
         ALOGV("%s: read failed status %d- sleeping for buffer duration", __func__, ret);
         usleep((uint64_t)bytes * 1000000 / audio_stream_in_frame_size(stream) /
@@ -3924,44 +3950,7 @@
     }
 
     /* Init use case and pcm_config */
-    if ((out->flags & AUDIO_OUTPUT_FLAG_DIRECT) &&
-        !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD ||
-        (out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) &&
-        (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL ||
-        out->devices & AUDIO_DEVICE_OUT_PROXY)) {
-
-        pthread_mutex_lock(&adev->lock);
-        if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
-            /*
-            * Do not handle stereo output in Multi-channel cases
-            * Stereo case is handled in normal playback path
-            */
-            if (out->supported_channel_masks[0] == AUDIO_CHANNEL_OUT_STEREO)
-                ret = AUDIO_CHANNEL_OUT_STEREO;
-        }
-
-        if (out->devices & AUDIO_DEVICE_OUT_PROXY)
-            ret = audio_extn_read_afe_proxy_channel_masks(out);
-        pthread_mutex_unlock(&adev->lock);
-        if (ret != 0)
-            goto error_open;
-
-        if (config->sample_rate == 0)
-            config->sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
-        if (config->channel_mask == 0)
-            config->channel_mask = AUDIO_CHANNEL_OUT_5POINT1;
-        if (config->format == 0)
-            config->format = AUDIO_FORMAT_PCM_16_BIT;
-
-        out->channel_mask = config->channel_mask;
-        out->sample_rate = config->sample_rate;
-        out->format = config->format;
-        out->usecase = USECASE_AUDIO_PLAYBACK_MULTI_CH;
-        out->config = pcm_config_hdmi_multi;
-        out->config.rate = config->sample_rate;
-        out->config.channels = audio_channel_count_from_out_mask(out->channel_mask);
-        out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels * 2);
-    } else if ((out->dev->mode == AUDIO_MODE_IN_COMMUNICATION || voice_extn_compress_voip_is_active(out->dev)) &&
+    if ((out->dev->mode == AUDIO_MODE_IN_COMMUNICATION || voice_extn_compress_voip_is_active(out->dev)) &&
                (out->flags == (AUDIO_OUTPUT_FLAG_DIRECT | AUDIO_OUTPUT_FLAG_VOIP_RX)) &&
                (voice_extn_compress_voip_is_config_supported(config))) {
         ret = voice_extn_compress_voip_open_output_stream(out);
@@ -3971,7 +3960,7 @@
             goto error_open;
         }
     } else if ((out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) ||
-               (out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) {
+               (out->flags == AUDIO_OUTPUT_FLAG_DIRECT)) {
 
         if (config->offload_info.version != AUDIO_INFO_INITIALIZER.version ||
             config->offload_info.size != AUDIO_INFO_INITIALIZER.size) {
@@ -4002,20 +3991,17 @@
             goto error_open;
         }
 
-        if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) {
-            out->stream.pause = out_pause;
-            out->stream.flush = out_flush;
-            out->stream.resume = out_resume;
-            out->usecase = get_offload_usecase(adev, true);
-            ALOGV("DIRECT_PCM usecase ... usecase selected %d ", out->usecase);
-        } else {
+        out->stream.pause = out_pause;
+        out->stream.resume = out_resume;
+        out->stream.flush = out_flush;
+        if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
             out->stream.set_callback = out_set_callback;
-            out->stream.pause = out_pause;
-            out->stream.resume = out_resume;
             out->stream.drain = out_drain;
-            out->stream.flush = out_flush;
-            out->usecase = get_offload_usecase(adev, false);
+            out->usecase = get_offload_usecase(adev, true /* is_compress */);
             ALOGV("Compress Offload usecase .. usecase selected %d", out->usecase);
+        } else {
+            out->usecase = get_offload_usecase(adev, false /* is_compress */);
+            ALOGV("non-offload DIRECT_usecase ... usecase selected %d ", out->usecase);
         }
 
         if (out->usecase == USECASE_INVALID) {
@@ -4037,7 +4023,7 @@
             out->channel_mask = config->channel_mask;
             config->offload_info.channel_mask = config->channel_mask;
         } else {
-            ALOGE("out->channel_mask not set for OFFLOAD/DIRECT_PCM");
+            ALOGE("out->channel_mask not set for OFFLOAD/DIRECT usecase");
             ret = -EINVAL;
             goto error_open;
         }
@@ -4088,7 +4074,7 @@
                                                   out->compr_config.codec->format);
             out->hal_ip_format = out->format;
 
-            /*for direct PCM playback populate bit_width based on selected alsa format as
+            /*for direct non-compress playback populate bit_width based on selected alsa format as
              *hal input format and alsa format might differ based on platform support.
              */
             out->bit_width = audio_bytes_per_sample(
@@ -4164,12 +4150,12 @@
         /* Disable gapless if any of the following is true
          * passthrough playback
          * AV playback
-         * Direct PCM playback
+         * non compressed Direct playback
          */
         if (audio_extn_passthru_is_passthrough_stream(out) ||
                 (config->format == AUDIO_FORMAT_DSD) ||
                 config->offload_info.has_video ||
-                out->flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) {
+                !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) {
             check_and_set_gapless_mode(adev, false);
         } else
             check_and_set_gapless_mode(adev, true);
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index f887904..8d7132c 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -71,6 +71,7 @@
 #define MIXER_XML_PATH_WCD9326 "/etc/mixer_paths_wcd9326.xml"
 #define MIXER_XML_PATH_WCD9335 "/etc/mixer_paths_wcd9335.xml"
 #define PLATFORM_INFO_XML_PATH_EXTCODEC  "/etc/audio_platform_info_extcodec.xml"
+#define PLATFORM_INFO_XML_PATH_SKUSH  "/etc/audio_platform_info_skush.xml"
 #define PLATFORM_INFO_XML_PATH      "/etc/audio_platform_info.xml"
 #define MIXER_XML_PATH_WCD9326_I2S "/etc/mixer_paths_wcd9326_i2s.xml"
 #define MIXER_XML_PATH_WCD9330_I2S "/etc/mixer_paths_wcd9330_i2s.xml"
@@ -81,6 +82,7 @@
 #define MIXER_XML_PATH_MTP "/system/etc/mixer_paths_mtp.xml"
 #define MIXER_XML_PATH_SKU2 "/system/etc/mixer_paths_qrd_sku2.xml"
 #define PLATFORM_INFO_XML_PATH_EXTCODEC  "/system/etc/audio_platform_info_extcodec.xml"
+#define PLATFORM_INFO_XML_PATH_SKUSH "/system/etc/audio_platform_info_skush.xml"
 #define MIXER_XML_PATH_WCD9326 "/system/etc/mixer_paths_wcd9326.xml"
 #define MIXER_XML_PATH_WCD9335 "/system/etc/mixer_paths_wcd9335.xml"
 #define MIXER_XML_PATH_SKUN "/system/etc/mixer_paths_qrd_skun.xml"
@@ -2188,6 +2190,9 @@
     /* Initialize ACDB and PCM ID's */
     if (is_external_codec)
         platform_info_init(PLATFORM_INFO_XML_PATH_EXTCODEC, my_data);
+    else if (!strncmp(snd_card_name, "sdm660-snd-card-skush",
+               sizeof("sdm660-snd-card-skush")))
+        platform_info_init(PLATFORM_INFO_XML_PATH_SKUSH, my_data);
     else
         platform_info_init(PLATFORM_INFO_XML_PATH, my_data);
 
@@ -5173,6 +5178,7 @@
     unsigned int sample_rate;
     unsigned int channels;
     bool passthrough_enabled = false;
+    bool voice_call_active = false;
     int backend_idx = DEFAULT_CODEC_BACKEND;
     struct platform_data *my_data = (struct platform_data *)adev->platform;
     int na_mode = platform_get_native_support();
@@ -5205,6 +5211,7 @@
         bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
         sample_rate =  CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
         channels = CODEC_BACKEND_DEFAULT_CHANNELS;
+        voice_call_active = true;
     } else {
         /*
          * The backend should be configured at highest bit width and/or
@@ -5244,7 +5251,7 @@
     }
 
     /* Native playback is preferred for Headphone/HS device over 192Khz */
-    if (codec_device_supports_native_playback(usecase->devices)) {
+    if (!voice_call_active && codec_device_supports_native_playback(usecase->devices)) {
         if (audio_is_true_native_stream_active(adev)) {
             if (check_hdset_combo_device(snd_device)) {
                 /*
@@ -5255,8 +5262,8 @@
                  */
                     sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
                     bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
-                    ALOGD("%s:becf: afe: port has to run at 48k for a combo device",
-                          __func__);
+                    ALOGD("%s:becf: afe: port to run at 48k if combo device or in voice call"
+                           , __func__);
             } else {
              /*
               * in single BE mode, if native audio playback
@@ -5321,7 +5328,7 @@
                sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
     }
 
-    if (backend_idx == HDMI_RX_BACKEND) {
+    if ((backend_idx == HDMI_RX_BACKEND) || (backend_idx == DISP_PORT_RX_BACKEND)) {
         struct audio_backend_cfg hdmi_backend_cfg;
         hdmi_backend_cfg.bit_width = bit_width;
         hdmi_backend_cfg.sample_rate = sample_rate;
@@ -5494,9 +5501,9 @@
         /* update cfg against other existing capture usecases on same backend */
         list_for_each(node, &adev->usecase_list) {
             uc = node_to_item(node, struct audio_usecase, list);
-            if (uc->type == PCM_CAPTURE &&
+            in = (struct stream_in *) uc->stream.in;
+            if (in != NULL && uc->type == PCM_CAPTURE &&
                 backend_idx == platform_get_backend_index(uc->in_snd_device)) {
-                in = (struct stream_in *) uc->stream.in;
                 uc_channels = audio_channel_count_from_in_mask(in->channel_mask);
 
                 ALOGV("%s:txbecf: uc %s, id %d, sr %d, bw %d, ch %d, device %s",
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 93b28ca..0bdebff 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -5062,6 +5062,7 @@
     unsigned int sample_rate;
     unsigned int channels;
     bool passthrough_enabled = false;
+    bool voice_call_active = false;
     int backend_idx = DEFAULT_CODEC_BACKEND;
     struct platform_data *my_data = (struct platform_data *)adev->platform;
     int na_mode = platform_get_native_support();
@@ -5095,6 +5096,7 @@
         bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
         sample_rate =  CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
         channels = CODEC_BACKEND_DEFAULT_CHANNELS;
+        voice_call_active = true;
     } else {
         /*
          * The backend should be configured at highest bit width and/or
@@ -5134,7 +5136,7 @@
     }
 
     /* Native playback is preferred for Headphone/HS device over 192Khz */
-    if (codec_device_supports_native_playback(usecase->devices)) {
+    if (!voice_call_active && codec_device_supports_native_playback(usecase->devices)) {
         if (audio_is_true_native_stream_active(adev)) {
             if (check_hdset_combo_device(snd_device)) {
                 /*
@@ -5145,8 +5147,8 @@
                  */
                     sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
                     bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
-                    ALOGD("%s:becf: afe: port has to run at 48k for a combo device",
-                          __func__);
+                    ALOGD("%s:becf: afe: port to run at 48k if combo device or in voice call"
+                           , __func__);
             } else {
              /*
               * in single BE mode, if native audio playback
@@ -5360,9 +5362,9 @@
         /* update cfg against other existing capture usecases on same backend */
         list_for_each(node, &adev->usecase_list) {
             uc = node_to_item(node, struct audio_usecase, list);
-            if (uc->type == PCM_CAPTURE &&
+            in = (struct stream_in *) uc->stream.in;
+            if (in != NULL && uc->type == PCM_CAPTURE &&
                 backend_idx == platform_get_backend_index(uc->in_snd_device)) {
-                in = (struct stream_in *) uc->stream.in;
                 uc_channels = audio_channel_count_from_in_mask(in->channel_mask);
 
                 ALOGV("%s:txbecf: uc %s, id %d, sr %d, bw %d, ch %d, device %s",
diff --git a/policy_hal/AudioPolicyManager.cpp b/policy_hal/AudioPolicyManager.cpp
index 8a572fa..c258a39 100644
--- a/policy_hal/AudioPolicyManager.cpp
+++ b/policy_hal/AudioPolicyManager.cpp
@@ -1374,41 +1374,14 @@
     return false;
 }
 
-bool static tryForDirectPCM(int bitWidth, audio_output_flags_t *flags, uint32_t samplingRate)
+bool static tryForDirectPCM(audio_output_flags_t flags)
 {
-    bool playerDirectPCM = false; // Output request for Track created by mediaplayer
     bool trackDirectPCM = false;  // Output request for track created by other apps
-    bool offloadDisabled = property_get_bool("audio.offload.disable", false);
 
-    // Direct PCM is allowed only if
-    // In case of mediaPlayer playback
-    // 16 bit direct pcm or 24bit direct PCM property is set and
-    // the FLAG requested is DIRECT_PCM ( NuPlayer case) or
-    // In case of AudioTracks created by apps
-    // track offload is enabled and FLAG requested is FLAG_NONE.
-
-    if (offloadDisabled) {
-        ALOGI("offload disabled by audio.offload.disable=%d", offloadDisabled);
-    }
-
-    if (*flags == AUDIO_OUTPUT_FLAG_DIRECT_PCM) {
-       if (bitWidth == 24 || bitWidth == 32)
-           playerDirectPCM =
-                property_get_bool("audio.offload.pcm.24bit.enable", false);
-       else
-           playerDirectPCM =
-                property_get_bool("audio.offload.pcm.16bit.enable", false);
-       // Reset flag to NONE so that we can still reuse direct pcm criteria check
-       // in getOutputforDevice
-       *flags = AUDIO_OUTPUT_FLAG_NONE;
-    } else if ((*flags == AUDIO_OUTPUT_FLAG_NONE) && (samplingRate % SAMPLE_RATE_8000 == 0)) {
+    if (flags == AUDIO_OUTPUT_FLAG_NONE) {
         trackDirectPCM = property_get_bool("audio.offload.track.enable", true);
     }
-
-    ALOGI("Direct PCM %s for this request",
-       (!offloadDisabled && (trackDirectPCM || playerDirectPCM))?"can be enabled":"is disabled");
-
-    return (!offloadDisabled && (trackDirectPCM || playerDirectPCM));
+    return trackDirectPCM;
 }
 
 status_t AudioPolicyManagerCustom::getOutputForAttr(const audio_attributes_t *attr,
@@ -1421,14 +1394,13 @@
                                                     audio_port_handle_t selectedDeviceId,
                                                     audio_port_handle_t *portId)
 {
-
     audio_offload_info_t tOffloadInfo = AUDIO_INFO_INITIALIZER;
     audio_config_t tConfig;
 
     uint32_t bitWidth = (audio_bytes_per_sample(config->format) * 8);
 
     memcpy(&tConfig, config, sizeof(audio_config_t));
-    if (tryForDirectPCM(bitWidth, &flags, config->sample_rate) &&
+    if ((flags == AUDIO_OUTPUT_FLAG_DIRECT || tryForDirectPCM(flags)) &&
         (!memcmp(&config->offload_info, &tOffloadInfo, sizeof(audio_offload_info_t)))) {
         tConfig.offload_info.sample_rate  = config->sample_rate;
         tConfig.offload_info.channel_mask = config->channel_mask;
@@ -1705,6 +1677,20 @@
         flags = (audio_output_flags_t)(flags | AUDIO_OUTPUT_FLAG_DIRECT);
     }
 
+    // Do internal direct magic here
+    bool offload_disabled = property_get_bool("audio.offload.disable", false);
+    if ((flags == AUDIO_OUTPUT_FLAG_NONE) &&
+        (stream == AUDIO_STREAM_MUSIC) &&
+        (offloadInfo != NULL) && !offload_disabled &&
+        ((offloadInfo->usage == AUDIO_USAGE_MEDIA) || (offloadInfo->usage == AUDIO_USAGE_GAME))) {
+        audio_output_flags_t old_flags = flags;
+        flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DIRECT);
+        ALOGD("AudioCustomHAL --> Force Direct Flag .. old flags(0x%x)", old_flags);
+    } else if (flags == AUDIO_OUTPUT_FLAG_DIRECT && offload_disabled) {
+        ALOGD("AudioCustomHAL --> offloading is disabled: Force Remove Direct Flag");
+        flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_NONE);
+    }
+
     bool forced_deep = false;
     // only allow deep buffering for music stream type
     if (stream != AUDIO_STREAM_MUSIC) {
@@ -1719,31 +1705,11 @@
         flags = AUDIO_OUTPUT_FLAG_TTS;
     }
 
-    // check if direct output for track offload already exits
-    bool is_track_offload_active = false;
-    for (size_t i = 0; i < mOutputs.size(); i++) {
-        sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
-        if (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) {
-            is_track_offload_active = true;
-            ALOGD("Track offload already active");
-            break;
-        }
-    }
-
-    // Do offload magic here
-    if ((flags == AUDIO_OUTPUT_FLAG_NONE) &&
-        (stream == AUDIO_STREAM_MUSIC) &&
-        (offloadInfo != NULL) && !is_track_offload_active &&
-        ((offloadInfo->usage == AUDIO_USAGE_MEDIA) || (offloadInfo->usage == AUDIO_USAGE_GAME))) {
-        flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_DIRECT_PCM);
-        ALOGD("AudioCustomHAL --> Force Direct Flag .. flag (0x%x)", flags);
-    }
-
     sp<IOProfile> profile;
 
     // skip direct output selection if the request can obviously be attached to a mixed output
     // and not explicitly requested
-    if (((flags & (AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_DIRECT_PCM)) == 0) &&
+    if (((flags & AUDIO_OUTPUT_FLAG_DIRECT) == 0) &&
             audio_is_linear_pcm(format) && samplingRate <= SAMPLE_RATE_HZ_MAX &&
             audio_channel_count_from_out_mask(channelMask) <= 2) {
         goto non_direct_output;
@@ -1759,7 +1725,7 @@
     // Supplementary annotation:
     // For sake of track offload introduced, we need a rollback for both compress offload
     // and track offload use cases.
-    if ((flags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_DIRECT_PCM)) &&
+    if ((flags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_DIRECT)) &&
                 (mEffects.isNonOffloadableEffectEnabled() || mMasterMono)) {
         ALOGD("non offloadable effect is enabled, try with non direct output");
         goto non_direct_output;
@@ -1773,9 +1739,9 @@
 
     if (profile != 0) {
 
-        if (!(flags & AUDIO_OUTPUT_FLAG_DIRECT_PCM) &&
-             (profile->getFlags() & AUDIO_OUTPUT_FLAG_DIRECT_PCM)) {
-            ALOGI("got Direct_PCM without requesting ... reject ");
+        if (!(flags & AUDIO_OUTPUT_FLAG_DIRECT) &&
+             (profile->getFlags() & AUDIO_OUTPUT_FLAG_DIRECT)) {
+            ALOGI("got Direct without requesting ... reject ");
             profile = NULL;
             goto non_direct_output;
         }
@@ -1786,7 +1752,7 @@
         // do no check for reuse and also don't close previous output if its offload
         // previous output will be closed during track destruction
         if (!(property_get_bool("audio.offload.multiple.enabled", false) &&
-                ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0))) {
+                ((flags & AUDIO_OUTPUT_FLAG_DIRECT) != 0))) {
             for (size_t i = 0; i < mOutputs.size(); i++) {
                 sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
                 if (!desc->isDuplicated() && (profile == desc->mProfile)) {
diff --git a/qahw_api/test/qahw_playback_test.c b/qahw_api/test/qahw_playback_test.c
index 71229c1..d114ede 100644
--- a/qahw_api/test/qahw_playback_test.c
+++ b/qahw_api/test/qahw_playback_test.c
@@ -27,6 +27,8 @@
 #include <errno.h>
 #include <time.h>
 #include <signal.h>
+#include <cutils/str_parms.h>
+#include <tinyalsa/asoundlib.h>
 #include "qahw_api.h"
 #include "qahw_defs.h"
 #include "qahw_effect_api.h"
@@ -53,6 +55,9 @@
 #define MAX_PLAYBACK_STREAMS   2
 #define PRIMARY_STREAM_INDEX   0
 
+#define KVPAIRS_MAX 100
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[1]))
+
 static int get_wav_header_length (FILE* file_stream);
 static void init_streams(void);
 
@@ -76,6 +81,12 @@
 };
 
 typedef enum {
+    USB_MODE_DEVICE,
+    USB_MODE_HOST,
+    USB_MODE_NONE
+} usb_mode_type_t;
+
+typedef enum {
     AAC_LC = 1,
     AAC_HE_V1,
     AAC_HE_V2
@@ -126,23 +137,28 @@
 };
 
 typedef struct {
-    qahw_module_handle_t *qahw_mod_handle;
+    qahw_module_handle_t *qahw_in_hal_handle;
+    qahw_module_handle_t *qahw_out_hal_handle;
     audio_io_handle_t handle;
     char* filename;
     FILE* file_stream;
     int filetype;
     int stream_index;
     audio_devices_t output_device;
+    audio_devices_t input_device;
     audio_config_t config;
     audio_output_flags_t flags;
     qahw_stream_handle_t* out_handle;
+    qahw_stream_handle_t* in_handle;
     int channels;
     aac_format_type_t aac_fmt_type;
     wma_format_type_t wma_fmt_type;
     char *kvpair_values;
     bool flags_set;
+    usb_mode_type_t usb_mode;
     int effect_index;
     bool drift_query;
+    char *device_url;
     thread_func_t ethread_func;
     thread_data_t *ethread_data;
     cmd_data_t cmd_data;
@@ -153,6 +169,11 @@
 }stream_config;
 
 
+qahw_module_handle_t *primary_hal_handle = NULL;
+qahw_module_handle_t *usb_hal_handle = NULL;
+qahw_module_handle_t *bt_hal_handle = NULL;
+
+
 FILE * log_file = NULL;
 volatile bool stop_playback = false;
 const char *log_filename = NULL;
@@ -219,14 +240,17 @@
     for ( i = 0; i < MAX_PLAYBACK_STREAMS; i++) {
         memset(&stream_param[i], 0, sizeof(stream_config));
 
-        stream_param[i].qahw_mod_handle                     =   nullptr;
+        stream_param[i].qahw_out_hal_handle                 =   nullptr;
+        stream_param[i].qahw_in_hal_handle                  =   nullptr;
         stream_param[i].filename                            =   nullptr;
         stream_param[i].file_stream                         =   nullptr;
         stream_param[i].filetype                            =   FILE_WAV;
         stream_param[i].stream_index                        =   i+1;
         stream_param[i].output_device                       =   AUDIO_DEVICE_OUT_SPEAKER;
+        stream_param[i].input_device                        =   AUDIO_DEVICE_NONE;
         stream_param[i].flags                               =   AUDIO_OUTPUT_FLAG_NONE;
         stream_param[i].out_handle                          =   nullptr;
+        stream_param[i].in_handle                           =   nullptr;
         stream_param[i].channels                            =   2;
         stream_param[i].config.offload_info.sample_rate     =   44100;
         stream_param[i].config.offload_info.bit_width       =   16;
@@ -234,9 +258,11 @@
         stream_param[i].wma_fmt_type                        =   WMA;
         stream_param[i].kvpair_values                       =   nullptr;
         stream_param[i].flags_set                           =   false;
+        stream_param[i].usb_mode                            =   USB_MODE_DEVICE;
         stream_param[i].effect_index                        =   -1;
         stream_param[i].ethread_func                        =   nullptr;
         stream_param[i].ethread_data                        =   nullptr;
+        stream_param[i].device_url                          =   "stream";
 
         pthread_mutex_init(&stream_param[i].write_lock, (const pthread_mutexattr_t *)NULL);
         pthread_cond_init(&stream_param[i].write_cond, (const pthread_condattr_t *) NULL);
@@ -412,6 +438,32 @@
         usleep(100000);
     }
 }
+static int is_eof(stream_config *stream) {
+    if (stream->filename) {
+        if (feof(stream->file_stream)) {
+            fprintf(log_file, "stream %d: error in fread, error %d\n", stream->stream_index, ferror(stream->file_stream));
+            fprintf(stderr, "stream %d: error in fread, error %d\n", stream->stream_index, ferror(stream->file_stream));
+            return true;
+        }
+    } else if (AUDIO_DEVICE_NONE != stream->input_device)
+        /*
+         * assuming this is called after we got -ve bytes value from hal read
+         */
+        return true;
+    return false;
+}
+static int read_bytes(stream_config *stream, void *buff, int size) {
+    if (stream->filename)
+        return fread(buff, 1, size, stream->file_stream);
+    else if (AUDIO_DEVICE_NONE != stream->input_device) {
+        qahw_in_buffer_t in_buf;
+        memset(&in_buf,0, sizeof(qahw_in_buffer_t));
+        in_buf.buffer = buff;
+        in_buf.bytes = size;
+        return qahw_in_read(stream->in_handle, &in_buf);
+    }
+
+}
 
 /* Entry point function for stream playback
  * Opens the stream
@@ -424,7 +476,6 @@
 {
     int rc = 0;
     stream_config *params = (stream_config*) stream_data;
-    const char* stream_name = "output_stream";
     bool proxy_thread_active = false;
     pthread_t proxy_thread;
 
@@ -434,13 +485,13 @@
 
     if (params->output_device & AUDIO_DEVICE_OUT_ALL_A2DP)
         params->output_device = AUDIO_DEVICE_OUT_PROXY;
-    rc = qahw_open_output_stream(params->qahw_mod_handle,
+    rc = qahw_open_output_stream(params->qahw_out_hal_handle,
                              params->handle,
                              params->output_device,
                              params->flags,
                              &(params->config),
                              &(params->out_handle),
-                             stream_name);
+                             params->device_url);
 
     if (rc) {
         fprintf(log_file, "stream %d: could not open output stream, error - %d \n", params->stream_index, rc);
@@ -541,7 +592,7 @@
     }
 
     if (params->output_device & AUDIO_DEVICE_OUT_PROXY) {
-        proxy_params.acp.qahw_mod_handle = params->qahw_mod_handle;
+        proxy_params.acp.qahw_mod_handle = params->qahw_out_hal_handle;
         proxy_params.acp.handle = stream_handle;
         stream_handle--;
         proxy_params.acp.input_device = AUDIO_DEVICE_IN_PROXY;
@@ -585,10 +636,11 @@
 
     while (!exit && !stop_playback) {
         if (!bytes_remaining) {
-            bytes_read = fread(data_ptr, 1, bytes_wanted, params->file_stream);
-            fprintf(log_file, "\nstream %d: fread from file %zd bytes\n", params->stream_index, bytes_read);
+            fprintf(log_file, "\nstream %d: reading bytes %zd\n", params->stream_index, bytes_wanted);
+            bytes_read = read_bytes(params, data_ptr, bytes_wanted);
+            fprintf(log_file, "stream %d: read bytes %zd\n", params->stream_index, bytes_read);
             if (bytes_read <= 0) {
-                if (feof(params->file_stream)) {
+                if (is_eof(params)) {
                     fprintf(log_file, "stream %d: end of file\n", params->stream_index);
                     if (is_offload) {
                         pthread_mutex_lock(&params->drain_lock);
@@ -598,9 +650,6 @@
                         fprintf(log_file, "stream %d: playback completed successfully\n", params->stream_index);
                         pthread_mutex_unlock(&params->drain_lock);
                     }
-                } else {
-                    fprintf(log_file, "stream %d: error in fread, error %d\n", params->stream_index, ferror(params->file_stream));
-                    fprintf(stderr, "stream %d: error in fread, error %d\n", params->stream_index, ferror(params->file_stream));
                 }
                 exit = true;
                 continue;
@@ -679,6 +728,9 @@
         fprintf(stderr, "stream %d: could not close output stream, error - %d \n", params->stream_index, rc);
     }
 
+    if (data_ptr)
+        free(data_ptr);
+
     fprintf(log_file, "stream %d: stream closed\n", params->stream_index);
     return;
 
@@ -882,6 +934,9 @@
            usage();
            return;
     }
+    stream_info->config.sample_rate = stream_info->config.offload_info.sample_rate;
+    stream_info->config.format = stream_info->config.offload_info.format;
+    stream_info->config.channel_mask = stream_info->config.offload_info.channel_mask = audio_channel_in_mask_from_count(stream_info->channels);
     return;
 }
 
@@ -992,12 +1047,241 @@
     aptx_cfg->bt_addr.lap = addr[2];
 }
 
+typedef struct {
+    char *string;
+    int val;
+} param_converter_type;
+
+param_converter_type format_table[] = {
+    {"AUDIO_FORMAT_PCM_16_BIT",        AUDIO_FORMAT_PCM_16_BIT},
+    {"AUDIO_FORMAT_PCM_32_BIT",        AUDIO_FORMAT_PCM_32_BIT},
+    {"AUDIO_FORMAT_PCM_8_BIT",         AUDIO_FORMAT_PCM_8_BIT},
+    {"AUDIO_FORMAT_PCM_8_24_BIT",      AUDIO_FORMAT_PCM_8_24_BIT},
+    {"AUDIO_FORMAT_PCM_24_BIT_PACKED", AUDIO_FORMAT_PCM_24_BIT_PACKED}
+};
+
+
+int rate_table[] = {48000, 44100};
+
+
+static int get_kvpairs_string(char *kvpairs, const char *key, char *value) {
+    struct str_parms *parms = NULL;
+
+    if (!kvpairs)
+        return -1;
+
+    parms = str_parms_create_str(kvpairs);
+    if (str_parms_get_str(parms, key, value, KVPAIRS_MAX) < 0)
+        return -1;
+
+    str_parms_destroy(parms);
+    return 1;
+}
+
+static int get_pcm_format(char *kvpairs) {
+    bool match = false;
+    int i = 0;
+    char value[KVPAIRS_MAX] = {0};
+
+    if(!kvpairs)
+        return -1;
+
+
+    if (get_kvpairs_string(kvpairs, QAHW_PARAMETER_STREAM_SUP_FORMATS, value) < 0)
+        return -1;
+
+    fprintf(log_file, "formats=%s\n", value);
+
+   /*
+    * for now we assume usb hal/pcm device announces suport for one format ONLY
+    */
+    for (i = 0; i < sizeof(format_table); i++) {
+        if(!strncmp(format_table[i].string, value, sizeof(value))) {
+            match = true;
+            break;
+        }
+    }
+
+    if (match)
+        return format_table[i].val;
+    else
+        return -1;
+
+}
+
+
+static int get_rate(char *kvpairs) {
+    int match = false;
+    int rate = 0;
+    int i = 0;
+    char value[KVPAIRS_MAX] = {0};
+
+    if(!kvpairs)
+        return -1;
+
+    if (get_kvpairs_string(kvpairs, QAHW_PARAMETER_STREAM_SUP_SAMPLING_RATES, value) < 0)
+        return -1;
+
+    fprintf(log_file, "sample rates=%s\n", value);
+   /*
+    * for now we assume usb hal/pcm device announces suport for one rate ONLY
+    */
+
+    rate = atoi(value);
+    for (i = 0; i < ARRAY_SIZE(rate_table); i++)
+        if (rate_table[i] == rate)
+            match = true;
+
+    if (match)
+        return rate;
+    else
+        return -1;
+}
+
+
+static int get_channels(char *kvpairs) {
+    int ch = -1;
+    char value[KVPAIRS_MAX] = {0};
+
+    if(!kvpairs)
+        return -1;
+
+    if (get_kvpairs_string(kvpairs, QAHW_PARAMETER_STREAM_SUP_CHANNELS, value) < 0)
+        return -1;
+
+    fprintf(log_file, "channels=%s\n", value);
+
+   /*
+    * this is to work around a bug in usb hal which annouces support for stereo
+    * though the pcm dev/host stream is mono.
+    */
+    if (strstr(value, "MONO"))
+        ch = 1;
+    else if (strstr(value, "STEREO"))
+        ch = 2;
+
+    return ch;
+}
+
+
+static int detect_stream_params(stream_config *stream) {
+    bool detection_needed = false;
+    bool is_usb_loopback = false;
+    int direction = PCM_OUT;
+    audio_devices_t dev = stream->input_device;
+
+    int rc = 0;
+    char *param_string = NULL;
+    int ch = 0;
+
+    if (AUDIO_DEVICE_IN_USB_DEVICE == stream->input_device ||
+        AUDIO_DEVICE_OUT_USB_DEVICE == stream->output_device)
+        if (USB_MODE_DEVICE == stream->usb_mode)
+            detection_needed = true;
+
+    if (!detection_needed)
+    /*
+     * we will go with given params through args or with default params.
+     */
+        return true;
+
+    if (AUDIO_DEVICE_IN_USB_DEVICE == stream->input_device)
+        direction = PCM_IN;
+    else
+        direction = PCM_OUT;
+
+    fprintf(log_file, "%s: opening %s stream\n", __func__, ((direction == PCM_IN)? "input":"output"));
+
+    if (PCM_IN == direction)
+        rc = qahw_open_input_stream(stream->qahw_in_hal_handle,
+                                stream->handle,
+                                stream->input_device,
+                                &(stream->config),
+                                &(stream->in_handle),
+                                AUDIO_OUTPUT_FLAG_NONE,
+                                stream->device_url,
+                                AUDIO_SOURCE_DEFAULT);
+    else
+        rc = qahw_open_output_stream(stream->qahw_out_hal_handle,
+                                stream->handle,
+                                stream->output_device,
+                                stream->flags,
+                                &(stream->config),
+                                &(stream->out_handle),
+                                stream->device_url);
+
+    if (rc) {
+        fprintf(log_file, "stream could not be opened\n");
+        fprintf(stderr, "stream could not be opened\n");
+        return rc;
+    }
+
+    fprintf(log_file,"\n**Supported Parameters**\n");
+    if (PCM_IN == direction)
+        param_string = qahw_in_get_parameters(stream->in_handle, QAHW_PARAMETER_STREAM_SUP_SAMPLING_RATES);
+    else
+        param_string = qahw_out_get_parameters(stream->out_handle, QAHW_PARAMETER_STREAM_SUP_SAMPLING_RATES);
+
+    if ((stream->config.sample_rate = get_rate(param_string)) <= 0) {
+        fprintf(log_file, "Unable to extract sample rate val =(%d) string(%s)\n", stream->config.sample_rate, param_string);
+        fprintf(stderr, "Unable to extract sample rate val =(%d) string(%s)\n", stream->config.sample_rate, param_string);
+        return -1;
+    }
+    if (PCM_IN == direction)
+        param_string = qahw_in_get_parameters(stream->in_handle, QAHW_PARAMETER_STREAM_SUP_CHANNELS);
+    else
+        param_string = qahw_out_get_parameters(stream->out_handle, QAHW_PARAMETER_STREAM_SUP_CHANNELS);
+
+    if ((ch = get_channels(param_string)) <= 0) {
+        fprintf(log_file, "Unable to extract channels =(%d) string(%s)\n", ch, param_string);
+        fprintf(stderr, "Unable to extract channels =(%d) string(%s)\n", ch, param_string);
+        return -1;
+    }
+    stream->config.channel_mask = audio_channel_in_mask_from_count(ch);
+
+    if (PCM_IN == direction)
+        param_string = qahw_in_get_parameters(stream->in_handle, QAHW_PARAMETER_STREAM_SUP_FORMATS);
+    else
+        param_string = qahw_out_get_parameters(stream->out_handle, QAHW_PARAMETER_STREAM_SUP_FORMATS);
+
+    if ((stream->config.format = get_pcm_format(param_string)) <= 0) {
+        fprintf(log_file, "Unable to extract pcm format val =(%d) string(%s)\n", stream->config.format, param_string);
+        fprintf(stderr, "Unable to extract pcm format val =(%d) string(%s)\n", stream->config.format, param_string);
+        return -1;
+    }
+    stream->config.offload_info.format = stream->config.format;
+    fprintf(log_file, "\n**Extracted Parameters**\nrate=%d\nch=%d,ch_mask=0x%x\nformats=%d\n\n",
+        stream->config.sample_rate,
+        ch, stream->config.channel_mask,
+        stream->config.format);
+    /*
+     * Detection done now close usb stream it will be re-open later
+     */
+    fprintf(log_file, "%s:closing the usb stream\n", __func__);
+
+    if (PCM_IN == direction)
+        rc = qahw_close_input_stream(stream->in_handle);
+    else
+        rc = qahw_close_output_stream(stream->out_handle);
+
+    if (rc) {
+        fprintf(log_file, "%s:stream could not be closed\n", __func__);
+        fprintf(stderr, "%s:stream could not be closed\n", __func__);
+        return rc;
+    }
+    stream->config.offload_info.sample_rate = stream->config.sample_rate;
+    stream->config.offload_info.format = stream->config.format;
+    stream->config.offload_info.channel_mask = stream->config.channel_mask;
+    return rc;
+
+}
 void usage() {
     printf(" \n Command \n");
     printf(" \n hal_play_test -f file-path <options>   - Plays audio file from the path provided\n");
     printf(" \n Options\n");
     printf(" -f  --file-path <file path>               - file path to be used for playback.\n");
     printf("                                             file path must be provided unless -K(--kpi) is used\n\n");
+    printf("                                             file path must be provided unless -s(input data is not from a file) is used\n\n");
     printf(" -r  --sample-rate <sampling rate>         - Required for Non-WAV streams\n");
     printf("                                             For AAC-HE pls specify half the sample rate\n\n");
     printf(" -c  --channel count <channels>            - Required for Non-WAV streams\n\n");
@@ -1005,6 +1289,9 @@
     printf(" -v  --volume <float volume level>         - Volume level float value between 0.0 - 1.0.\n");
     printf(" -d  --device <decimal value>              - see system/media/audio/include/system/audio.h for device values\n");
     printf("                                             Optional Argument and Default value is 2, i.e Speaker\n\n");
+    printf(" -s  --source-device <decimal value>       - see system/media/audio/include/system/audio.h for device values\n");
+    printf("                                             obtain data from a device instead of an SD card file\n\n");
+    printf("                                             for example catpure data from USB HAL(device) and play it on Regular HAL(device)\n\n");
     printf(" -t  --file-type <file type>               - 1:WAV 2:MP3 3:AAC 4:AAC_ADTS 5:FLAC\n");
     printf("                                             6:ALAC 7:VORBIS 8:WMA 10:AAC_LATM \n");
     printf("                                             Required for non WAV formats\n\n");
@@ -1027,55 +1314,77 @@
     printf(" -q  --query drift                         - Required for querying avtime vs hdmi drift\n");
     printf(" -P                                        - Argument to do multi-stream playback, currently 2 streams are supported to run concurrently\n");
     printf("                                             Put -P and mention required attributes for the next stream\n");
+    printf("                                             0:bassboost 1:virtualizer 2:equalizer 3:visualizer(NA) 4:reverb 5:audiosphere others:null");
+    printf(" PLUS                                      - For multi-stream playback, currently 2 streams are supported to play concurrently\n");
+    printf("                                             Put PLUS and mention required attributes for the next files");
+    printf(" -u  --device-nodeurl                      - URL of PCM device\n");
+    printf("                                             in the following format card=x;device=x");
+    printf("                                             this option is mandatory in working with USB HAL");
+    printf(" -m  --mode                                - usb operating mode(Device Mode is default)\n");
+    printf("                                             0:Device Mode(host drives the stream and its params and so no need to give params as input)\n");
+    printf("                                             1:Host Mode(user can give stream and stream params via a stream(SD card file) or setup loopback with given params\n");
     printf(" \n Examples \n");
-    printf(" hal_play_test -f /etc/Anukoledenadu.wav     -> plays Wav stream with default params\n\n");
-    printf(" hal_play_test -f /etc/MateRani.mp3 -t 2 -d 2 -v 0.01 -r 44100 -c 2 \n");
+    printf(" hal_play_test -f /data/Anukoledenadu.wav  -> plays Wav stream with default params\n\n");
+    printf(" hal_play_test -f /data/MateRani.mp3 -t 2 -d 2 -v 0.01 -r 44100 -c 2 \n");
     printf("                                          -> plays MP3 stream(-t = 2) on speaker device(-d = 2)\n");
     printf("                                          -> 2 channels and 44100 sample rate\n\n");
-    printf(" hal_play_test -f /etc/v1-CBR-32kHz-stereo-40kbps.mp3 -t 2 -d 128 -v 0.01 -r 32000 -c 2 -D /data/proxy_dump.wav\n");
+    printf(" hal_play_test -f /data/v1-CBR-32kHz-stereo-40kbps.mp3 -t 2 -d 128 -v 0.01 -r 32000 -c 2 -D /data/proxy_dump.wav\n");
     printf("                                          -> plays MP3 stream(-t = 2) on BT device(-d = 128)\n");
     printf("                                          -> 2 channels and 32000 sample rate\n");
     printf("                                          -> dumps pcm data to file at /data/proxy_dump.wav\n\n");
-    printf(" hal_play_test -f /etc/AACLC-71-48000Hz-384000bps.aac  -t 4 -d 2 -v 0.05 -r 48000 -c 2 -a 1 \n");
+    printf(" hal_play_test -f /data/AACLC-71-48000Hz-384000bps.aac  -t 4 -d 2 -v 0.05 -r 48000 -c 2 -a 1 \n");
     printf("                                          -> plays AAC-ADTS stream(-t = 4) on speaker device(-d = 2)\n");
     printf("                                          -> AAC format type is LC(-a = 1)\n");
     printf("                                          -> 2 channels and 48000 sample rate\n\n");
-    printf(" hal_play_test -f /etc/AACHE-adts-stereo-32000KHz-128000Kbps.aac  -t 4 -d 2 -v 0.05 -r 16000 -c 2 -a 3 \n");
+    printf(" hal_play_test -f /data/AACHE-adts-stereo-32000KHz-128000Kbps.aac  -t 4 -d 2 -v 0.05 -r 16000 -c 2 -a 3 \n");
     printf("                                          -> plays AAC-ADTS stream(-t = 4) on speaker device(-d = 2)\n");
     printf("                                          -> AAC format type is HE V2(-a = 3)\n");
     printf("                                          -> 2 channels and 16000 sample rate\n");
     printf("                                          -> note that the sample rate is half the actual sample rate\n\n");
-    printf(" hal_play_test -f /etc/2.0_16bit_48khz.m4a -k 1536000,16,0,0,4096,14,16388,0,10,2,40,48000,1536000,48000 -t 6 -r 48000 -c 2 -v 0.5 \n");
+    printf(" hal_play_test -f /data/2.0_16bit_48khz.m4a -k 1536000,16,0,0,4096,14,16388,0,10,2,40,48000,1536000,48000 -t 6 -r 48000 -c 2 -v 0.5 \n");
     printf("                                          -> Play alac clip (-t = 6)\n");
     printf("                                          -> kvpair(-k) values represent media-info of clip & values should be in below mentioned sequence\n");
     printf("                                          ->alac_avg_bit_rate,alac_bit_depth,alac_channel_layout,alac_compatible_version,\n");
     printf("                                          ->alac_frame_length,alac_kb,alac_max_frame_bytes,alac_max_run,alac_mb,\n");
     printf("                                          ->alac_num_channels,alac_pb,alac_sampling_rate,avg_bit_rate,sample_rate\n\n");
-    printf(" hal_play_test -f /etc/DIL CHAHTA HAI.flac -k 0,4096,13740,4096,14 -t 5 -r 48000 -c 2 -v 0.5 \n");
+    printf(" hal_play_test -f /data/DIL CHAHTA HAI.flac -k 0,4096,13740,4096,14 -t 5 -r 48000 -c 2 -v 0.5 \n");
     printf("                                          -> Play flac clip (-t = 5)\n");
     printf("                                          -> kvpair(-k) values represent media-info of clip & values should be in below mentioned sequence\n");
     printf("                                          ->avg_bit_rate,flac_max_blk_size,flac_max_frame_size\n");
     printf("                                          ->flac_min_blk_size,flac_min_frame_size,sample_rate\n");
-    printf(" hal_play_test -f /etc/vorbis.mka -k 500000,48000,1 -t 7 -r 48000 -c 2 -v 0.5 \n");
+    printf(" hal_play_test -f /data/vorbis.mka -k 500000,48000,1 -t 7 -r 48000 -c 2 -v 0.5 \n");
     printf("                                          -> Play vorbis clip (-t = 7)\n");
     printf("                                          -> kvpair(-k) values represent media-info of clip & values should be in below mentioned sequence\n");
     printf("                                          ->avg_bit_rate,sample_rate,vorbis_bitstream_fmt\n");
-    printf(" hal_play_test -f /etc/file.wma -k 192000,48000,16,8192,3,15,0,0,353 -t 8 -w 1 -r 48000 -c 2 -v 0.5 \n");
+    printf(" hal_play_test -f /data/file.wma -k 192000,48000,16,8192,3,15,0,0,353 -t 8 -w 1 -r 48000 -c 2 -v 0.5 \n");
     printf("                                          -> Play wma clip (-t = 8)\n");
     printf("                                          -> kvpair(-k) values represent media-info of clip & values should be in below mentioned sequence\n");
     printf("                                          ->avg_bit_rate,sample_rate,wma_bit_per_sample,wma_block_align\n");
     printf("                                          ->wma_channel_mask,wma_encode_option,wma_format_tag\n");
-    printf(" hal_play_test -f /etc/03_Kuch_Khaas_BE.btaptx -t 9 -d 2 -v 0.2 -r 44100 -c 2 -A 00:02:5b:00:ff:03 \n");
+    printf(" hal_play_test -f /data/03_Kuch_Khaas_BE.btaptx -t 9 -d 2 -v 0.2 -r 44100 -c 2 -A 00:02:5b:00:ff:03 \n");
     printf("                                          -> Play aptx clip (-t = 9)\n");
     printf("                                          -> 2 channels and 44100 sample rate\n");
     printf("                                          -> BT addr: bt_addr=00:02:5b:00:ff:03\n\n");
     printf(" hal_play_test -f /data/silence.ac3 -t 9 -r 48000 -c 2 -v 0.05 -F 16433 -P -f /data/music_48k.ac3 -t 9 -r 48000 -c 2 -F 32817\n");
     printf("                                          -> Plays a silence clip as main stream and music clip as associated\n\n");
     printf(" hal_play_test -K -F 4                    -> Measure latency KPIs for low latency output\n\n");
-    printf(" hal_play_test -f /etc//Moto_320kbps.mp3 -t 2 -d 2 -v 0.1 -r 44100 -c 2 -e 2\n");
+    printf(" hal_play_test -f /data/Moto_320kbps.mp3 -t 2 -d 2 -v 0.1 -r 44100 -c 2 -e 2\n");
     printf("                                          -> plays MP3 stream(-t = 2) on speaker device(-d = 2)\n");
     printf("                                          -> 2 channels and 44100 sample rate\n\n");
     printf("                                          -> sound effect equalizer enabled\n\n");
+    printf(" hal_play_test -d 2 -v 0.05 -s 2147487744 -u \"card=1\\;device=0\" \n");
+    printf("                                          -> capture audio stream from usb device(HAL)@ 44.1 KHz, 2ch\n");
+    printf("                                          -> and loop/play it back on to primary HAL \n\n");
+    printf("                                          -> Device Mode is default\n");
+    printf("                                          -> card=1\\;device=0 -> specifies the URL, pls not that the ';' is escaped\n\n");
+    printf(" hal_play_test -f /data/Anukoledenadu.wav -d 16384 -u \"card=1\\;device=0\" \n");
+    printf("                                          -> Play PCM to USB out\n\n");
+    printf(" hal_play_test -d 16384 -u \"card=1\\;device=0\" -s 2\n");
+    printf("                                          ->Capture PCM from Local Mic and play it on USB(usb to primary hal loopback)\n\n");
+    printf(" hal_play_test -d 16384 -u \"card=1\\;device=0\" -s 2 -P -d 2 -v 0.05 -s 2147487744 -u \"card=1\\;device=0\"\n");
+    printf("                                          ->full duplex, setup both primary to usb and usb to primary loopbacks\n");
+    printf("                                          ->Note:-P separates the steam params for both the loopbacks\n");
+    printf("                                          ->Note:all the USB device commmands(above) should be accompanied with the host side commands\n\n");
 }
 
 static int get_wav_header_length (FILE* file_stream)
@@ -1110,11 +1419,81 @@
     return wav_header_len;
 }
 
+static qahw_module_handle_t * load_hal(audio_devices_t dev) {
+    qahw_module_handle_t *hal = NULL;
+
+    if ((AUDIO_DEVICE_IN_USB_DEVICE == dev) ||
+        (AUDIO_DEVICE_OUT_USB_DEVICE == dev)){
+        if (!usb_hal_handle) {
+            fprintf(log_file,"\nLoading usb HAL\n");
+            if ((usb_hal_handle = qahw_load_module(QAHW_MODULE_ID_USB)) == NULL) {
+                fprintf(log_file,"failure in Loading usb HAL\n");
+                fprintf(stderr,"failure in Loading usb HAL\n");
+                return NULL;
+            }
+        }
+        hal = usb_hal_handle;
+    }
+/*  else if ((AUDIO_DEVICE_IN_BLUETOOTH_A2DP == dev) ||
+               (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP == dev)){
+        if (!bt_hal_handle) {
+            fprintf(log_file,"Loading BT HAL\n");
+            if ((bt_hal_handle = qahw_load_module(QAHW_MODULE_ID_A2DP)) == NULL) {
+                fprintf(log_file,"failure in Loading BT HAL\n");
+                fprintf(stderr,"failure in Loading BT HAL\n");
+                return NULL;
+            }
+        }
+        hal = bt_hal_handle;
+    }*/
+    else {
+        if (!primary_hal_handle) {
+            fprintf(log_file,"\nLoading Primary HAL\n");
+            if ((primary_hal_handle = qahw_load_module(QAHW_MODULE_ID_PRIMARY)) == NULL) {
+                fprintf(log_file,"failure in Loading Primary HAL\n");
+                fprintf(stderr,"failure in Loading primary HAL\n");
+                return NULL;
+            }
+        }
+        hal = primary_hal_handle;
+    }
+    return hal;
+}
+/*
+ * this function unloads all the loaded hal modules so this should be called
+ * after all the stream playback are concluded.
+ */
+static int unload_hals() {
+
+    if (usb_hal_handle) {
+        fprintf(log_file,"\nUnLoading usb HAL\n");
+        if (qahw_unload_module(usb_hal_handle) < 0) {
+            fprintf(log_file,"failure in Un Loading usb HAL\n");
+            fprintf(stderr,"failure in Un Loading usb HAL\n");
+            return -1;
+        }
+    }
+    if (bt_hal_handle) {
+        fprintf(log_file,"UnLoading BT HAL\n");
+        if (qahw_unload_module(bt_hal_handle) < 0) {
+            fprintf(log_file,"failure in UnLoading BT HAL\n");
+            fprintf(stderr,"failure in Un Loading BT HAL\n");
+            return -1;
+        }
+    }
+    if (primary_hal_handle) {
+        fprintf(log_file,"\nUnLoading Primary HAL\n");
+        if (qahw_unload_module(primary_hal_handle) < 0) {
+            fprintf(log_file,"failure in Un Loading Primary HAL\n");
+            fprintf(stderr,"failure in Un Loading primary HAL\n");
+            return -1;
+        }
+    }
+    return 1;
+}
+
 
 int main(int argc, char* argv[]) {
-
-    qahw_module_handle_t *qahw_mod_handle = NULL;
-    const char *mod_name = "audio.primary";
     char *ba = NULL;
     qahw_param_payload payload;
     qahw_param_id param_id;
@@ -1126,6 +1505,7 @@
 
     log_file = stdout;
     proxy_params.acp.file_name = "/data/pcm_dump.wav";
+    stream_config *stream = NULL;
     init_streams();
 
     int num_of_streams = 1;
@@ -1133,7 +1513,8 @@
     struct option long_options[] = {
         /* These options set a flag. */
         {"file-path",     required_argument,    0, 'f'},
-        {"device",        required_argument,    0, 'd'},
+        {"output-device", required_argument,    0, 'd'},
+        {"input-device",  required_argument,    0, 's'},
         {"sample-rate",   required_argument,    0, 'r'},
         {"channels",      required_argument,    0, 'c'},
         {"bitwidth",      required_argument,    0, 'b'},
@@ -1150,6 +1531,8 @@
         {"effect-path",   required_argument,    0, 'e'},
         {"bt-addr",       required_argument,    0, 'A'},
         {"query drift",   no_argument,          0, 'q'},
+        {"device-nodeurl",required_argument,    0, 'u'},
+        {"mode",          required_argument,    0, 'm'},
         {"help",          no_argument,          0, 'h'},
         {0, 0, 0, 0}
     };
@@ -1173,7 +1556,7 @@
 
     while ((opt = getopt_long(argc,
                               argv,
-                              "-f:r:c:b:d:v:l:t:a:w:k:PD:KF:e:A:qh",
+                              "-f:r:c:b:d:s:v:l:t:a:w:k:PD:KF:e:A:u:m:qh",
                               long_options,
                               &option_index)) != -1) {
 
@@ -1185,9 +1568,11 @@
             break;
         case 'r':
             stream_param[i].config.offload_info.sample_rate = atoi(optarg);
+            stream_param[i].config.sample_rate = atoi(optarg);
             break;
         case 'c':
             stream_param[i].channels = atoi(optarg);
+            stream_param[i].config.channel_mask = audio_channel_out_mask_from_count(atoi(optarg));
             break;
         case 'b':
             stream_param[i].config.offload_info.bit_width = atoi(optarg);
@@ -1195,6 +1580,9 @@
         case 'd':
             stream_param[i].output_device = atoll(optarg);
             break;
+        case 's':
+            stream_param[i].input_device = atoll(optarg);
+            break;
         case 'v':
             vol_level = atof(optarg);
             break;
@@ -1261,6 +1649,12 @@
             i++;
             fprintf(log_file, "Stream index incremented to %d\n", i);
             break;
+        case 'u':
+            stream_param[i].device_url = optarg;
+            break;
+        case 'm':
+            stream_param[i].usb_mode = atoi(optarg);
+            break;
         case 'h':
             usage();
             return 0;
@@ -1284,8 +1678,6 @@
         goto exit;
     }
 
-    qahw_mod_handle = qahw_load_module(mod_name);
-
     /* Register the SIGINT to close the App properly */
     if (signal(SIGINT, stop_signal_handler) == SIG_ERR) {
         fprintf(log_file, "Failed to register SIGINT:%d\n",errno);
@@ -1293,69 +1685,97 @@
     }
 
     for (i = 0; i < num_of_streams; i++) {
-        fprintf(log_file, "Playing:%s\n", stream_param[i].filename);
-        
-        stream_param[i].qahw_mod_handle = qahw_mod_handle;
+        stream = &stream_param[i];
 
-        if (kpi_mode == false) {
+        if ((kpi_mode == false) && 
+            (AUDIO_DEVICE_NONE == stream->input_device)){
             if (stream_param[PRIMARY_STREAM_INDEX].filename == nullptr) {
                 fprintf(log_file, "Primary file name is must for non kpi-mode\n");
                 fprintf(stderr, "Primary file name is must for non kpi-mode\n");
                 goto exit;
             }
-            if ((stream_param[i].file_stream = fopen(stream_param[i].filename, "r"))== NULL) {
-                fprintf(log_file, "Cannot open audio file %s\n", stream_param[i].filename);
-                fprintf(stderr, "Cannot open audio file %s\n", stream_param[i].filename);
-                goto exit;
-            }
         }
 
-        if (stream_param[i].output_device & AUDIO_DEVICE_OUT_ALL_A2DP)
+        if (stream->output_device != AUDIO_DEVICE_NONE)
+            if ((stream->qahw_out_hal_handle = load_hal(stream->output_device)) <= 0)
+                goto exit;
+
+        if (stream->input_device != AUDIO_DEVICE_NONE)
+            if ((stream->qahw_in_hal_handle = load_hal(stream->input_device))== 0)
+                goto exit;
+
+        if ((AUDIO_DEVICE_NONE != stream->output_device) &&
+            (AUDIO_DEVICE_NONE != stream->input_device))
+            /*
+             * hal loopback at what params we need to probably detect.
+             */
+             if(detect_stream_params(stream) < 0)
+                goto exit;
+
+        if (stream->filename) {
+            if ((stream->file_stream = fopen(stream->filename, "r"))== NULL) {
+                fprintf(log_file, "Cannot open audio file %s\n", stream->filename);
+                fprintf(stderr, "Cannot open audio file %s\n", stream->filename);
+                goto exit;
+            }
+            fprintf(log_file, "Playing from:%s\n", stream->filename);
+            get_file_format(&stream_param[i]);
+        } else if (AUDIO_DEVICE_NONE != stream->input_device) {
+            fprintf(log_file, "Playing from device:%x\n", stream->input_device);
+            fprintf(log_file, "Playing from url:%s\n", stream->device_url);
+            fprintf(log_file, "setting up input hal and stream:%s\n", stream->device_url);
+
+            rc = qahw_open_input_stream(stream->qahw_in_hal_handle,
+                                    stream->handle,
+                                    stream->input_device,
+                                    &(stream->config),
+                                    &(stream->in_handle),
+                                    AUDIO_OUTPUT_FLAG_NONE,
+                                    stream->device_url,
+                                    AUDIO_SOURCE_UNPROCESSED);
+            if (rc) {
+                fprintf(log_file, "input stream could not be re-opened\n");
+                fprintf(stderr, "input stream could not be re-opened\n");
+                return rc;
+            }
+            stream->flags = AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_NON_BLOCKING;
+            stream->flags |= AUDIO_OUTPUT_FLAG_DIRECT;
+        } else if (kpi_mode == true)
+            stream->config.format = stream->config.offload_info.format = AUDIO_FORMAT_PCM_16_BIT;
+
+        if (stream->output_device & AUDIO_DEVICE_OUT_ALL_A2DP)
             fprintf(log_file, "Saving pcm data to file: %s\n", proxy_params.acp.file_name);
 
         /* Set device connection state for HDMI */
-        if (stream_param[i].output_device == AUDIO_DEVICE_OUT_AUX_DIGITAL) {
+        if (stream->output_device == AUDIO_DEVICE_OUT_AUX_DIGITAL) {
             char param[100] = {0};
             snprintf(param, sizeof(param), "%s=%d", "connect", AUDIO_DEVICE_OUT_AUX_DIGITAL);
-            qahw_set_parameters(qahw_mod_handle, param);
+            qahw_set_parameters(stream->qahw_out_hal_handle, param);
         }
 
-        if (kpi_mode == true) {
-            stream_param[i].config.offload_info.format = AUDIO_FORMAT_PCM_16_BIT;
-        } else {
-            get_file_format(&stream_param[i]);
-        }
-
-        fprintf(log_file, "stream %d: File Type:%d\n", stream_param[i].stream_index, stream_param[i].filetype);
-        fprintf(log_file, "stream %d: Audio Format:%d\n", stream_param[i].stream_index, stream_param[i].config.offload_info.format);
-        fprintf(log_file, "stream %d: Output Device:%d\n", stream_param[i].stream_index, stream_param[i].output_device);
-        fprintf(log_file, "stream %d: Output Flags:%d\n", stream_param[i].stream_index, stream_param[i].flags);
-        fprintf(log_file, "stream %d: Sample Rate:%d\n", stream_param[i].stream_index, stream_param[i].config.offload_info.sample_rate);
-        fprintf(log_file, "stream %d: Channels:%d\n", stream_param[i].stream_index, stream_param[i].channels);
-        fprintf(log_file, "stream %d: Bitwidth:%d\n", stream_param[i].stream_index, stream_param[i].config.offload_info.bit_width);
-        fprintf(log_file, "stream %d: AAC Format Type:%d\n", stream_param[i].stream_index, stream_param[i].aac_fmt_type);
-        fprintf(log_file, "stream %d: Kvpair Values:%s\n", stream_param[i].stream_index, stream_param[i].kvpair_values);
+        fprintf(log_file, "stream %d: File Type:%d\n", stream->stream_index, stream->filetype);
+        fprintf(log_file, "stream %d: Audio Format:%d\n", stream->stream_index, stream->config.offload_info.format);
+        fprintf(log_file, "stream %d: Output Device:%d\n", stream->stream_index, stream->output_device);
+        fprintf(log_file, "stream %d: Output Flags:%d\n", stream->stream_index, stream->flags);
+        fprintf(log_file, "stream %d: Sample Rate:%d\n", stream->stream_index, stream->config.offload_info.sample_rate);
+        fprintf(log_file, "stream %d: Channels:%d\n", stream->stream_index, stream->channels);
+        fprintf(log_file, "stream %d: Bitwidth:%d\n", stream->stream_index, stream->config.offload_info.bit_width);
+        fprintf(log_file, "stream %d: AAC Format Type:%d\n", stream->stream_index, stream->aac_fmt_type);
+        fprintf(log_file, "stream %d: Kvpair Values:%s\n", stream->stream_index, stream->kvpair_values);
         fprintf(log_file, "Log file:%s\n", log_filename);
         fprintf(log_file, "Volume level:%f\n", vol_level);
 
-        stream_param[i].config.offload_info.channel_mask = stream_param[i].config.channel_mask;
-        stream_param[i].config.offload_info.version = AUDIO_OFFLOAD_INFO_VERSION_CURRENT;
-        stream_param[i].config.offload_info.size = sizeof(audio_offload_info_t);
+        stream->config.offload_info.version = AUDIO_OFFLOAD_INFO_VERSION_CURRENT;
+        stream->config.offload_info.size = sizeof(audio_offload_info_t);
 
-        stream_param[i].config.channel_mask = audio_channel_out_mask_from_count(stream_param[i].channels);
-        stream_param[i].config.format = stream_param[i].config.offload_info.format;
-        stream_param[i].config.sample_rate = stream_param[i].config.offload_info.sample_rate;
-
-        fprintf(log_file, "stream %d: playing to output_device=%d \n", stream_param[i].stream_index, stream_param[i].output_device);
-
-        if (stream_param[i].filetype == FILE_APTX) {
+        if (stream->filetype == FILE_APTX) {
             if (ba != NULL) {
                 parse_aptx_dec_bt_addr(ba, &aptx_params);
                 payload = (qahw_param_payload)aptx_params;
                 param_id = QAHW_PARAM_APTX_DEC;
                 fprintf(log_file, "Send BT addr nap %d, uap %d lap %d to HAL\n", aptx_params.bt_addr.nap,
                             aptx_params.bt_addr.uap, aptx_params.bt_addr.lap);
-                rc = qahw_set_param_data(qahw_mod_handle, param_id, &payload);
+                rc = qahw_set_param_data(stream->qahw_out_hal_handle, param_id, &payload);
                 if (rc != 0)
                      fprintf(log_file, "Error.Failed Set BT addr\n");
                      fprintf(stderr, "Error.Failed Set BT addr\n");
@@ -1368,8 +1788,8 @@
 
         rc = pthread_create(&playback_thread[i], NULL, start_stream_playback, (void *)&stream_param[i]);
         if (rc) {
-            fprintf(log_file, "stream %d: failed to create thread\n", stream_param[i].stream_index);
-            fprintf(stderr, "stream %d: failed to create thread\n", stream_param[i].stream_index);
+            fprintf(log_file, "stream %d: failed to create thread\n", stream->stream_index);
+            fprintf(stderr, "stream %d: failed to create thread\n", stream->stream_index);
             exit(0);
         }
 
@@ -1391,19 +1811,24 @@
          if (stream_param[i].output_device == AUDIO_DEVICE_OUT_AUX_DIGITAL) {
              char param[100] = {0};
              snprintf(param, sizeof(param), "%s=%d", "disconnect", AUDIO_DEVICE_OUT_AUX_DIGITAL);
-             qahw_set_parameters(qahw_mod_handle, param);
+             qahw_set_parameters(stream_param[i].qahw_out_hal_handle, param);
          }
 
         if (stream_param[i].file_stream != nullptr)
             fclose(stream_param[i].file_stream);
+        else if (AUDIO_DEVICE_NONE != stream_param[i].input_device) {
+            if (stream->in_handle) {
+                rc = qahw_close_input_stream(stream->in_handle);
+                if (rc) {
+                    fprintf(log_file, "input stream could not be closed\n");
+                    fprintf(stderr, "input stream could not be closed\n");
+                    return rc;
+                }
+            }
+        }
     }
 
-    rc = qahw_unload_module(qahw_mod_handle);
-    if (rc) {
-        fprintf(log_file, "could not unload hal  %d \n", rc);
-        fprintf(stderr, "could not unload hal  %d \n", rc);
-        return -1;
-    }
+    rc = unload_hals();
 
     if ((log_file != stdout) && (log_file != nullptr))
         fclose(log_file);