Merge "hal: Fix input device selection for stereo recording"
diff --git a/hal/Android.mk b/hal/Android.mk
index 037be56..a7e0a02 100644
--- a/hal/Android.mk
+++ b/hal/Android.mk
@@ -26,6 +26,7 @@
 LOCAL_SRC_FILES := \
 	audio_hw.c \
 	voice.c \
+	platform_info.c \
 	$(AUDIO_PLATFORM)/platform.c
 
 LOCAL_SRC_FILES += audio_extn/audio_extn.c
@@ -97,19 +98,30 @@
     LOCAL_CFLAGS += -DDS1_DOLBY_DDP_ENABLED
     LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
     LOCAL_ADDITIONAL_DEPENDENCIES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
+    LOCAL_SRC_FILES += audio_extn/dolby.c
 endif
 
+ifneq ($(strip $(AUDIO_FEATURE_DISABLED_DS1_DOLBY_DAP)),true)
+    LOCAL_CFLAGS += -DDS1_DOLBY_DAP_ENABLED
+ifeq ($(strip $(AUDIO_FEATURE_DISABLED_DS1_DOLBY_DDP)),true)
+    LOCAL_SRC_FILES += audio_extn/dolby.c
+endif
+endif
+
+
 LOCAL_SHARED_LIBRARIES := \
 	liblog \
 	libcutils \
 	libtinyalsa \
 	libtinycompress \
 	libaudioroute \
-	libdl
+	libdl \
+	libexpat
 
 LOCAL_C_INCLUDES += \
 	external/tinyalsa/include \
 	external/tinycompress/include \
+	external/expat/lib \
 	$(call include-path-for, audio-route) \
 	$(call include-path-for, audio-effects) \
 	$(LOCAL_PATH)/$(AUDIO_PLATFORM) \
diff --git a/hal/audio_extn/audio_extn.c b/hal/audio_extn/audio_extn.c
index 80ce063..89903ba 100644
--- a/hal/audio_extn/audio_extn.c
+++ b/hal/audio_extn/audio_extn.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -29,8 +29,6 @@
 #include "audio_hw.h"
 #include "audio_extn.h"
 
-#include "sound/compress_params.h"
-
 #define MAX_SLEEP_RETRY 100
 #define WIFI_INIT_WAIT_SLEEP 50
 
@@ -321,6 +319,7 @@
    audio_extn_fm_set_parameters(adev, parms);
    audio_extn_listen_set_parameters(adev, parms);
    audio_extn_hfp_set_parameters(adev, parms);
+   audio_extn_ddp_set_parameters(adev, parms);
 }
 
 void audio_extn_get_parameters(const struct audio_device *adev,
@@ -359,57 +358,3 @@
     return 0;
 }
 #endif /* AUXPCM_BT_ENABLED */
-
-
-#ifdef DS1_DOLBY_DDP_ENABLED
-
-bool audio_extn_dolby_is_supported_format(audio_format_t format)
-{
-    if (format == AUDIO_FORMAT_AC3 ||
-            format == AUDIO_FORMAT_EAC3)
-        return true;
-    else
-        return false;
-}
-
-int audio_extn_dolby_get_snd_codec_id(audio_format_t format)
-{
-    int id = 0;
-
-    switch (format) {
-    case AUDIO_FORMAT_AC3:
-        id = SND_AUDIOCODEC_AC3;
-        break;
-    case AUDIO_FORMAT_EAC3:
-        id = SND_AUDIOCODEC_EAC3;
-        break;
-    default:
-        ALOGE("%s: Unsupported audio format :%x", __func__, format);
-    }
-
-    return id;
-}
-
-int audio_extn_dolby_set_DMID(struct audio_device *adev)
-{
-    struct mixer_ctl *ctl;
-    const char *mixer_ctl_name = "DS1 Security";
-    char c_dmid[128] = {0};
-    int i_dmid, ret;
-
-    property_get("dmid",c_dmid,"0");
-    i_dmid = atoi(c_dmid);
-
-    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
-    if (!ctl) {
-        ALOGE("%s: Could not get ctl for mixer cmd - %s",
-              __func__, mixer_ctl_name);
-        return -EINVAL;
-    }
-    ALOGV("%s Dolby device manufacturer id is:%d",__func__,i_dmid);
-    ret = mixer_ctl_set_value(ctl, 0, i_dmid);
-
-    return ret;
-}
-#endif /* DS1_DOLBY_DDP_ENABLED */
-
diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h
index 72f8642..fb428db 100644
--- a/hal/audio_extn/audio_extn.h
+++ b/hal/audio_extn/audio_extn.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -155,14 +155,31 @@
 void audio_extn_compr_cap_deinit();
 #endif
 
-#ifndef DS1_DOLBY_DDP_ENABLED
-#define audio_extn_dolby_is_supported_format(format)    (0)
-#define audio_extn_dolby_get_snd_codec_id(format)       (0)
-#define audio_extn_dolby_set_DMID(adev)                 (0)
+#if defined(DS1_DOLBY_DDP_ENABLED) || defined(DS1_DOLBY_DAP_ENABLED)
+void audio_extn_dolby_set_dmid(struct audio_device *adev);
 #else
-bool audio_extn_dolby_is_supported_format(audio_format_t format);
-int audio_extn_dolby_get_snd_codec_id(audio_format_t format);
-int audio_extn_dolby_set_DMID(struct audio_device *adev);
+#define audio_extn_dolby_set_dmid(adev)                 (0)
+#endif
+
+#ifndef DS1_DOLBY_DDP_ENABLED
+#define audio_extn_dolby_set_endpoint()                 (0)
+#else
+void audio_extn_dolby_set_endpoint(struct audio_device *adev);
+#endif
+
+#ifndef DS1_DOLBY_DDP_ENABLED
+#define audio_extn_ddp_set_parameters(adev, parms)      (0)
+#define audio_extn_is_dolby_format(format)              (0)
+#define audio_extn_dolby_get_snd_codec_id(format)       (0)
+#define audio_extn_dolby_send_ddp_endp_params(adev)     (0)
+#else
+bool audio_extn_is_dolby_format(audio_format_t format);
+int audio_extn_dolby_get_snd_codec_id(struct audio_device *adev,
+                                      struct stream_out *out,
+                                      audio_format_t format);
+void audio_extn_ddp_set_parameters(struct audio_device *adev,
+                                   struct str_parms *parms);
+void audio_extn_dolby_send_ddp_endp_params(struct audio_device *adev);
 #endif
 
 #ifndef HFP_ENABLED
diff --git a/hal/audio_extn/dolby.c b/hal/audio_extn/dolby.c
new file mode 100644
index 0000000..bcc7381
--- /dev/null
+++ b/hal/audio_extn/dolby.c
@@ -0,0 +1,456 @@
+/*
+ * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
+ * Not a Contribution.
+ *
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "audio_hw_dolby"
+/*#define LOG_NDEBUG 0*/
+#define LOG_NDDEBUG 0
+
+#include <errno.h>
+#include <cutils/properties.h>
+#include <stdlib.h>
+#include <dlfcn.h>
+#include <cutils/str_parms.h>
+#include <cutils/log.h>
+
+#include "audio_hw.h"
+#include "platform.h"
+#include "platform_api.h"
+#include "audio_extn.h"
+#include "sound/compress_params.h"
+
+#ifdef DS1_DOLBY_DDP_ENABLED
+
+#define AUDIO_PARAMETER_DDP_DEV          "ddp_device"
+#define AUDIO_PARAMETER_DDP_CH_CAP       "ddp_chancap"
+#define AUDIO_PARAMETER_DDP_MAX_OUT_CHAN "ddp_maxoutchan"
+#define AUDIO_PARAMETER_DDP_OUT_MODE     "ddp_outmode"
+#define AUDIO_PARAMETER_DDP_OUT_LFE_ON   "ddp_outlfeon"
+#define AUDIO_PARAMETER_DDP_COMP_MODE    "ddp_compmode"
+#define AUDIO_PARAMETER_DDP_STEREO_MODE  "ddp_stereomode"
+
+#define PARAM_ID_MAX_OUTPUT_CHANNELS    0x00010DE2
+#define PARAM_ID_CTL_RUNNING_MODE       0x0
+#define PARAM_ID_CTL_ERROR_CONCEAL      0x00010DE3
+#define PARAM_ID_CTL_ERROR_MAX_RPTS     0x00010DE4
+#define PARAM_ID_CNV_ERROR_CONCEAL      0x00010DE5
+#define PARAM_ID_CTL_SUBSTREAM_SELECT   0x00010DE6
+#define PARAM_ID_CTL_INPUT_MODE         0x0
+#define PARAM_ID_OUT_CTL_OUTMODE        0x00010DE0
+#define PARAM_ID_OUT_CTL_OUTLFE_ON      0x00010DE1
+#define PARAM_ID_OUT_CTL_COMPMODE       0x00010D74
+#define PARAM_ID_OUT_CTL_STEREO_MODE    0x00010D76
+#define PARAM_ID_OUT_CTL_DUAL_MODE      0x00010D75
+#define PARAM_ID_OUT_CTL_DRCSCALE_HIGH  0x00010D7A
+#define PARAM_ID_OUT_CTL_DRCSCALE_LOW   0x00010D79
+#define PARAM_ID_OUT_CTL_OUT_PCMSCALE   0x00010D78
+#define PARAM_ID_OUT_CTL_MDCT_BANDLIMIT 0x00010DE7
+#define PARAM_ID_OUT_CTL_DRC_SUPPRESS   0x00010DE8
+
+/* DS1-DDP Endp Params */
+#define DDP_ENDP_NUM_PARAMS 17
+#define DDP_ENDP_NUM_DEVICES 22
+static int ddp_endp_params_id[DDP_ENDP_NUM_PARAMS] = {
+    PARAM_ID_MAX_OUTPUT_CHANNELS, PARAM_ID_CTL_RUNNING_MODE,
+    PARAM_ID_CTL_ERROR_CONCEAL, PARAM_ID_CTL_ERROR_MAX_RPTS,
+    PARAM_ID_CNV_ERROR_CONCEAL, PARAM_ID_CTL_SUBSTREAM_SELECT,
+    PARAM_ID_CTL_INPUT_MODE, PARAM_ID_OUT_CTL_OUTMODE,
+    PARAM_ID_OUT_CTL_OUTLFE_ON, PARAM_ID_OUT_CTL_COMPMODE,
+    PARAM_ID_OUT_CTL_STEREO_MODE, PARAM_ID_OUT_CTL_DUAL_MODE,
+    PARAM_ID_OUT_CTL_DRCSCALE_HIGH, PARAM_ID_OUT_CTL_DRCSCALE_LOW,
+    PARAM_ID_OUT_CTL_OUT_PCMSCALE, PARAM_ID_OUT_CTL_MDCT_BANDLIMIT,
+    PARAM_ID_OUT_CTL_DRC_SUPPRESS
+};
+
+static struct ddp_endp_params {
+    int  device;
+    int  dev_ch_cap;
+    int  param_val[DDP_ENDP_NUM_PARAMS];
+    bool is_param_valid[DDP_ENDP_NUM_PARAMS];
+} ddp_endp_params[DDP_ENDP_NUM_DEVICES] = {
+          {AUDIO_DEVICE_OUT_EARPIECE, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 } },
+          {AUDIO_DEVICE_OUT_SPEAKER, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_WIRED_HEADSET, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_WIRED_HEADPHONE, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_BLUETOOTH_SCO, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_AUX_DIGITAL, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 2, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_AUX_DIGITAL, 6,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 2, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_AUX_DIGITAL, 8,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 2, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_USB_ACCESSORY, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_USB_DEVICE, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_FM, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_FM_TX, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_ANC_HEADSET, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_ANC_HEADPHONE, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+          {AUDIO_DEVICE_OUT_PROXY, 2,
+              {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0},
+              {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} },
+};
+
+int update_ddp_endp_table(int device, int dev_ch_cap, int param_id,
+                          int param_val)
+{
+    int idx = 0;
+    int param_idx = 0;
+    ALOGV("%s: dev 0x%x dev_ch_cap %d param_id 0x%x param_val %d",
+           __func__, device, dev_ch_cap , param_id, param_val);
+
+    for(idx=0; idx<DDP_ENDP_NUM_DEVICES; idx++) {
+        if(ddp_endp_params[idx].device == device) {
+            if(ddp_endp_params[idx].dev_ch_cap == dev_ch_cap) {
+                break;
+            }
+        }
+    }
+
+    if(idx>=DDP_ENDP_NUM_DEVICES) {
+        ALOGE("%s: device not available in DDP endp config table", __func__);
+        return -EINVAL;
+    }
+
+    for(param_idx=0; param_idx<DDP_ENDP_NUM_PARAMS; param_idx++) {
+        if (ddp_endp_params_id[param_idx] == param_id) {
+            break;
+        }
+    }
+
+    if(param_idx>=DDP_ENDP_NUM_PARAMS) {
+        ALOGE("param not available in DDP endp config table");
+        return -EINVAL;
+    }
+
+    ALOGV("ddp_endp_params[%d].param_val[%d] = %d", idx, param_idx, param_val);
+    ddp_endp_params[idx].param_val[param_idx] = param_val;
+    return 0;
+}
+
+void send_ddp_endp_params_stream(struct stream_out *out,
+                                 int device, int dev_ch_cap,
+                                 bool set_cache)
+{
+    int idx, i;
+    int ddp_endp_params_data[2*DDP_ENDP_NUM_PARAMS + 1];
+    int length = 0;
+    for(idx=0; idx<DDP_ENDP_NUM_DEVICES; idx++) {
+        if(ddp_endp_params[idx].device & device) {
+            if(ddp_endp_params[idx].dev_ch_cap == dev_ch_cap) {
+                break;
+            }
+        }
+    }
+    if(idx>=DDP_ENDP_NUM_DEVICES) {
+        ALOGE("device not available in DDP endp config table");
+        return;
+    }
+
+    length += 1; /* offset 0 is for num of parameter. increase offset by 1 */
+    for (i=0; i<DDP_ENDP_NUM_PARAMS; i++) {
+        if(ddp_endp_params[idx].is_param_valid[i]) {
+            ddp_endp_params_data[length++] = ddp_endp_params_id[i];
+            ddp_endp_params_data[length++] = ddp_endp_params[idx].param_val[i];
+        }
+    }
+    ddp_endp_params_data[0] = (length-1)/2;
+    if(length) {
+        char mixer_ctl_name[128];
+        struct audio_device *adev = out->dev;
+        struct mixer_ctl *ctl;
+        int pcm_device_id = platform_get_pcm_device_id(out->usecase,
+                                                       PCM_PLAYBACK);
+        snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
+                 "Audio Stream %d Dec Params", pcm_device_id);
+        ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
+        if (!ctl) {
+            ALOGE("%s: Could not get ctl for mixer cmd - %s",
+                  __func__, mixer_ctl_name);
+            return;
+        }
+        mixer_ctl_set_array(ctl, ddp_endp_params_data, length);
+    }
+    return;
+}
+
+void send_ddp_endp_params(struct audio_device *adev,
+                          int ddp_dev, int dev_ch_cap)
+{
+    struct listnode *node;
+    struct audio_usecase *usecase;
+
+    list_for_each(node, &adev->usecase_list) {
+        usecase = node_to_item(node, struct audio_usecase, list);
+        if ((usecase->type == PCM_PLAYBACK) &&
+            (usecase->devices & ddp_dev) &&
+            (usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
+            ((usecase->stream.out->format == AUDIO_FORMAT_AC3) ||
+             (usecase->stream.out->format == AUDIO_FORMAT_EAC3))) {
+            send_ddp_endp_params_stream(usecase->stream.out, ddp_dev,
+                                        dev_ch_cap, false /* set cache */);
+        }
+    }
+}
+
+void audio_extn_dolby_send_ddp_endp_params(struct audio_device *adev)
+{
+    struct listnode *node;
+    struct audio_usecase *usecase;
+    list_for_each(node, &adev->usecase_list) {
+        usecase = node_to_item(node, struct audio_usecase, list);
+        if ((usecase->type == PCM_PLAYBACK) &&
+            (usecase->devices & AUDIO_DEVICE_OUT_ALL) &&
+            (usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) &&
+            ((usecase->stream.out->format == AUDIO_FORMAT_AC3) ||
+             (usecase->stream.out->format == AUDIO_FORMAT_EAC3))) {
+            send_ddp_endp_params_stream(usecase->stream.out, usecase->devices,
+                           usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL ?
+                           adev->cur_hdmi_channels : 2, false /* set cache */);
+        }
+    }
+}
+
+void audio_extn_ddp_set_parameters(struct audio_device *adev,
+                                   struct str_parms *parms)
+{
+    int ddp_dev, dev_ch_cap;
+    int val, ret;
+    char value[32]={0};
+    ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_DEV, value,
+                            sizeof(value));
+    if (ret >= 0) {
+        ddp_dev = atoi(value);
+        if (!(AUDIO_DEVICE_OUT_ALL & ddp_dev))
+            return;
+    } else
+        return;
+
+    ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_CH_CAP, value,
+                            sizeof(value));
+    if (ret >= 0) {
+        dev_ch_cap = atoi(value);
+        if ((dev_ch_cap != 2) && (dev_ch_cap != 6) && (dev_ch_cap != 8))
+            return;
+    } else
+        return;
+
+    ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_MAX_OUT_CHAN, value,
+                            sizeof(value));
+    if (ret >= 0) {
+        val = atoi(value);
+        update_ddp_endp_table(ddp_dev, dev_ch_cap,
+                              PARAM_ID_MAX_OUTPUT_CHANNELS, val);
+    }
+
+    ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_OUT_MODE, value,
+                            sizeof(value));
+    if (ret >= 0) {
+        val = atoi(value);
+        update_ddp_endp_table(ddp_dev, dev_ch_cap,
+                              PARAM_ID_OUT_CTL_OUTMODE, val);
+    }
+
+    ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_OUT_LFE_ON, value,
+                            sizeof(value));
+    if (ret >= 0) {
+        val = atoi(value);
+        update_ddp_endp_table(ddp_dev, dev_ch_cap,
+                              PARAM_ID_OUT_CTL_OUTLFE_ON, val);
+    }
+
+    ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_COMP_MODE, value,
+                            sizeof(value));
+    if (ret >= 0) {
+        val = atoi(value);
+        update_ddp_endp_table(ddp_dev, dev_ch_cap,
+                              PARAM_ID_OUT_CTL_COMPMODE, val);
+    }
+
+    ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_STEREO_MODE, value,
+                            sizeof(value));
+    if (ret >= 0) {
+        val = atoi(value);
+        update_ddp_endp_table(ddp_dev, dev_ch_cap,
+                              PARAM_ID_OUT_CTL_STEREO_MODE, val);
+    }
+
+    send_ddp_endp_params(adev, ddp_dev, dev_ch_cap);
+}
+
+int audio_extn_dolby_get_snd_codec_id(struct audio_device *adev,
+                                      struct stream_out *out,
+                                      audio_format_t format)
+{
+    int id = 0;
+
+    switch (format) {
+    case AUDIO_FORMAT_AC3:
+        id = SND_AUDIOCODEC_AC3;
+        send_ddp_endp_params_stream(out, out->devices,
+                            out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL ?
+                            adev->cur_hdmi_channels : 2, true /* set_cache */);
+#ifndef DS1_DOLBY_DAP_ENABLED
+        audio_extn_dolby_set_dmid(adev);
+#endif
+        break;
+    case AUDIO_FORMAT_EAC3:
+        id = SND_AUDIOCODEC_EAC3;
+        send_ddp_endp_params_stream(out, out->devices,
+                            out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL ?
+                            adev->cur_hdmi_channels : 2, true /* set_cache */);
+#ifndef DS1_DOLBY_DAP_ENABLED
+        audio_extn_dolby_set_dmid(adev);
+#endif
+        break;
+    default:
+        ALOGE("%s: Unsupported audio format :%x", __func__, format);
+    }
+
+    return id;
+}
+
+bool audio_extn_is_dolby_format(audio_format_t format)
+{
+    if (format == AUDIO_FORMAT_AC3 ||
+            format == AUDIO_FORMAT_EAC3)
+        return true;
+    else
+        return false;
+}
+
+#endif /* DS1_DOLBY_DDP_ENABLED */
+
+#ifdef DS1_DOLBY_DAP_ENABLED
+void audio_extn_dolby_set_endpoint(struct audio_device *adev)
+{
+    struct listnode *node;
+    struct audio_usecase *usecase;
+    struct mixer_ctl *ctl;
+    const char *mixer_ctl_name = "DS1 DAP Endpoint";
+    int endpoint = 0, ret;
+    bool send = false;
+
+    list_for_each(node, &adev->usecase_list) {
+        usecase = node_to_item(node, struct audio_usecase, list);
+        if ((usecase->type == PCM_PLAYBACK) &&
+            (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY)) {
+            endpoint |= usecase->devices & AUDIO_DEVICE_OUT_ALL;
+            send = true;
+        }
+    }
+    if (!send)
+        return;
+
+    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
+    if (!ctl) {
+        ALOGE("%s: Could not get ctl for mixer cmd - %s",
+              __func__, mixer_ctl_name);
+        return;
+    }
+    ret = mixer_ctl_set_value(ctl, 0, endpoint);
+    if (ret)
+        ALOGE("%s: Dolby set endpint cannot be set error:%d",__func__, ret);
+
+    return;
+}
+#endif /* DS1_DOLBY_DAP_ENABLED */
+
+
+#if defined(DS1_DOLBY_DDP_ENABLED) || defined(DS1_DOLBY_DAP_ENABLED)
+void audio_extn_dolby_set_dmid(struct audio_device *adev)
+{
+    struct listnode *node;
+    struct audio_usecase *usecase;
+    struct mixer_ctl *ctl;
+    const char *mixer_ctl_name = "DS1 Security";
+    char c_dmid[128] = {0};
+    int i_dmid, ret;
+    bool send = false;
+
+    list_for_each(node, &adev->usecase_list) {
+        usecase = node_to_item(node, struct audio_usecase, list);
+        if ((usecase->type == PCM_PLAYBACK) &&
+            (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY))
+            send = true;
+    }
+    if (!send)
+        return;
+
+    property_get("dmid",c_dmid,"0");
+    i_dmid = atoi(c_dmid);
+
+    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
+    if (!ctl) {
+        ALOGE("%s: Could not get ctl for mixer cmd - %s",
+              __func__, mixer_ctl_name);
+        return;
+    }
+    ALOGV("%s Dolby device manufacturer id is:%d",__func__,i_dmid);
+    ret = mixer_ctl_set_value(ctl, 0, i_dmid);
+    if (ret)
+        ALOGE("%s: Dolby DMID cannot be set error:%d",__func__, ret);
+
+    return;
+}
+#endif /* DS1_DOLBY_DDP_ENABLED || DS1_DOLBY_DAP_ENABLED */
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 19fdda2..04a7aba 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -53,8 +53,10 @@
 #include "voice_extn.h"
 
 #include "sound/compress_params.h"
+
 #define MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE (256 * 1024)
-#define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (8 * 1024)
+#define MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE (2 * 1024)
+#define COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING (2 * 1024)
 #define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
 #define COMPRESS_OFFLOAD_NUM_FRAGMENTS 4
 /* ToDo: Check and update a proper value in msec */
@@ -152,8 +154,62 @@
 static unsigned int audio_device_ref_count;
 
 static int set_voice_volume_l(struct audio_device *adev, float volume);
-static uint32_t get_offload_buffer_size();
-static int set_gapless_mode(struct audio_device *adev);
+
+/* Read  offload buffer size from a property.
+ * If value is not power of 2  round it to
+ * power of 2.
+ */
+static uint32_t get_offload_buffer_size(audio_offload_info_t* info)
+{
+    char value[PROPERTY_VALUE_MAX] = {0};
+    uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
+    if((property_get("audio.offload.buffer.size.kb", value, "")) &&
+            atoi(value)) {
+        fragment_size =  atoi(value) * 1024;
+        //ring buffer size needs to be 4k aligned.
+        CHECK(!(fragment_size * COMPRESS_OFFLOAD_NUM_FRAGMENTS % 4096));
+    }
+
+    if (info != NULL && info->has_video && info->is_streaming) {
+        fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE_FOR_AV_STREAMING;
+        ALOGV("%s: offload fragment size reduced for AV streaming to %d",
+               __func__, out->compr_config.fragment_size);
+    }
+
+    if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
+        fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
+    else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
+        fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
+    ALOGVV("%s: fragment_size %d", __func__, fragment_size);
+    return fragment_size;
+}
+
+static int check_and_set_gapless_mode(struct audio_device *adev) {
+
+
+    char value[PROPERTY_VALUE_MAX] = {0};
+    bool gapless_enabled = false;
+    const char *mixer_ctl_name = "Compress Gapless Playback";
+    struct mixer_ctl *ctl;
+
+    ALOGV("%s:", __func__);
+    property_get("audio.offload.gapless.enabled", value, NULL);
+    gapless_enabled = atoi(value) || !strncmp("true", value, 4);
+
+    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
+    if (!ctl) {
+        ALOGE("%s: Could not get ctl for mixer cmd - %s",
+                               __func__, mixer_ctl_name);
+        return -EINVAL;
+    }
+
+    if (mixer_ctl_set_value(ctl, 0, gapless_enabled) < 0) {
+        ALOGE("%s: Could not set gapless mode %d",
+                       __func__, gapless_enabled);
+         return -EINVAL;
+    }
+    return 0;
+}
 
 static bool is_supported_format(audio_format_t format)
 {
@@ -199,6 +255,10 @@
     else
         snd_device = usecase->out_snd_device;
 
+#ifdef DS1_DOLBY_DAP_ENABLED
+    audio_extn_dolby_set_dmid(adev);
+    audio_extn_dolby_set_endpoint(adev);
+#endif
     strcpy(mixer_path, use_case_table[usecase->id]);
     platform_add_backend_name(mixer_path, snd_device);
     ALOGV("%s: apply mixer path: %s", __func__, mixer_path);
@@ -831,6 +891,7 @@
 {
     struct stream_out *out = (struct stream_out *) context;
     struct listnode *item;
+    int ret = 0;
 
     setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_AUDIO);
     set_sched_policy(0, SP_FOREGROUND);
@@ -880,8 +941,14 @@
             event = STREAM_CBK_EVENT_WRITE_READY;
             break;
         case OFFLOAD_CMD_PARTIAL_DRAIN:
-            compress_next_track(out->compr);
-            compress_partial_drain(out->compr);
+            ret = compress_next_track(out->compr);
+            if(ret == 0)
+                compress_partial_drain(out->compr);
+            else if(ret == -ETIMEDOUT)
+                compress_drain(out->compr);
+            else
+                ALOGE("%s: Next track returned error %d",__func__, ret);
+
             send_callback = true;
             event = STREAM_CBK_EVENT_DRAIN_READY;
             break;
@@ -1116,6 +1183,11 @@
         if (out->offload_callback)
             compress_nonblock(out->compr, out->non_blocking);
 
+#ifdef DS1_DOLBY_DDP_ENABLED
+        if (audio_extn_is_dolby_format(out->format))
+            audio_extn_dolby_send_ddp_endp_params(adev);
+#endif
+
         if (adev->visualizer_start_output != NULL)
             adev->visualizer_start_output(out->handle, out->pcm_device_id);
         if (adev->offload_effects_start_output != NULL)
@@ -1284,11 +1356,21 @@
     struct compr_gapless_mdata tmp_mdata;
     tmp_mdata.encoder_delay = 0;
     tmp_mdata.encoder_padding = 0;
+
     if (!out || !parms) {
         ALOGE("%s: return invalid ",__func__);
         return -EINVAL;
     }
 
+    ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_FORMAT, value, sizeof(value));
+    if (ret >= 0) {
+        if (atoi(value) == SND_AUDIOSTREAMFORMAT_MP4ADTS) {
+            out->compr_config.codec->format = SND_AUDIOSTREAMFORMAT_MP4ADTS;
+            ALOGV("ADTS format is set in offload mode");
+        }
+        out->send_new_metadata = 1;
+    }
+
     ret = str_parms_get_str(parms, AUDIO_OFFLOAD_CODEC_SAMPLE_RATE, value, sizeof(value));
     if(ret >= 0)
         is_meta_data_params = true;
@@ -1449,7 +1531,8 @@
         voice_extn_out_get_parameters(out, query, reply);
         str = str_parms_to_str(reply);
         if (!strncmp(str, "", sizeof(""))) {
-           str = strdup(keys);
+            free(str);
+            str = strdup(keys);
         }
     }
     str_parms_destroy(query);
@@ -1826,6 +1909,18 @@
         /* no audio source uses val == 0 */
         if ((in->source != val) && (val != 0)) {
             in->source = val;
+            if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) &&
+                (in->dev->mode == AUDIO_MODE_IN_COMMUNICATION) &&
+                (voice_extn_compress_voip_is_format_supported(in->format)) &&
+                (in->config.rate == 8000 || in->config.rate == 16000) &&
+                (popcount(in->channel_mask) == 1)) {
+                ret = voice_extn_compress_voip_open_input_stream(in);
+                if (ret != 0) {
+                    ALOGE("%s: Compress voip input cannot be opened, error:%d",
+                          __func__, ret);
+                    goto done;
+                }
+            }
         }
     }
 
@@ -1840,6 +1935,7 @@
         }
     }
 
+done:
     pthread_mutex_unlock(&adev->lock);
     pthread_mutex_unlock(&in->lock);
 
@@ -2053,7 +2149,7 @@
             goto error_open;
         }
         if (!is_supported_format(config->offload_info.format) &&
-                !audio_extn_dolby_is_supported_format(config->offload_info.format)) {
+                !audio_extn_is_dolby_format(config->offload_info.format)) {
             ALOGE("%s: Unsupported audio format", __func__);
             ret = -EINVAL;
             goto error_open;
@@ -2076,13 +2172,14 @@
         out->stream.drain = out_drain;
         out->stream.flush = out_flush;
 
-        if (audio_extn_dolby_is_supported_format(config->offload_info.format))
+        if (audio_extn_is_dolby_format(config->offload_info.format))
             out->compr_config.codec->id =
-                audio_extn_dolby_get_snd_codec_id(config->offload_info.format);
+                audio_extn_dolby_get_snd_codec_id(adev, out,
+                                                  config->offload_info.format);
         else
             out->compr_config.codec->id =
                 get_snd_codec_id(config->offload_info.format);
-        out->compr_config.fragment_size = get_offload_buffer_size();
+        out->compr_config.fragment_size = get_offload_buffer_size(&config->offload_info);
         out->compr_config.fragments = COMPRESS_OFFLOAD_NUM_FRAGMENTS;
         out->compr_config.codec->sample_rate =
                     compress_get_alsa_rate(config->offload_info.sample_rate);
@@ -2091,6 +2188,7 @@
         out->compr_config.codec->ch_in =
                     popcount(config->channel_mask);
         out->compr_config.codec->ch_out = out->compr_config.codec->ch_in;
+        out->compr_config.codec->format = SND_AUDIOSTREAMFORMAT_RAW;
 
         if (flags & AUDIO_OUTPUT_FLAG_NON_BLOCKING)
             out->non_blocking = 1;
@@ -2103,18 +2201,8 @@
         ALOGV("%s: offloaded output offload_info version %04x bit rate %d",
                 __func__, config->offload_info.version,
                 config->offload_info.bit_rate);
-
-        if (audio_extn_dolby_is_supported_format(out->format)) {
-            ret = audio_extn_dolby_set_DMID(adev);
-            if (ret != 0) {
-                ALOGE("%s: Dolby DMID cannot be set error:%d",
-                      __func__, ret);
-                goto error_open;
-            }
-        }
-
         //Decide if we need to use gapless mode by default
-        set_gapless_mode(adev);
+        check_and_set_gapless_mode(adev);
 
     } else if (out->flags & AUDIO_OUTPUT_FLAG_INCALL_MUSIC) {
         ret = voice_check_and_set_incall_music_usecase(adev, out);
@@ -2448,16 +2536,7 @@
     in->config.rate = config->sample_rate;
     in->format = config->format;
 
-    if ((in->dev->mode == AUDIO_MODE_IN_COMMUNICATION) &&
-        (voice_extn_compress_voip_is_config_supported(config))) {
-        ret = voice_extn_compress_voip_open_input_stream(in);
-        if (ret != 0)
-        {
-            ALOGE("%s: Compress voip input cannot be opened, error:%d",
-                  __func__, ret);
-            goto err_open;
-        }
-    } else if (channel_count == 6) {
+    if (channel_count == 6) {
         if(audio_extn_ssr_get_enabled()) {
             if(audio_extn_ssr_init(adev, in)) {
                 ALOGE("%s: audio_extn_ssr_init failed", __func__);
@@ -2469,7 +2548,8 @@
             goto err_open;
         }
     } else if (audio_extn_compr_cap_enabled() &&
-            audio_extn_compr_cap_format_supported(config->format)) {
+            audio_extn_compr_cap_format_supported(config->format) &&
+            (in->dev->mode != AUDIO_MODE_IN_COMMUNICATION)) {
         audio_extn_compr_cap_init(adev, in);
     } else {
         in->config.channels = channel_count;
@@ -2650,55 +2730,6 @@
     return 0;
 }
 
-/* Read  offload buffer size from a property.
- * If value is not power of 2  round it to
- * power of 2.
- */
-static uint32_t get_offload_buffer_size()
-{
-    char value[PROPERTY_VALUE_MAX] = {0};
-    uint32_t fragment_size = COMPRESS_OFFLOAD_FRAGMENT_SIZE;
-    if((property_get("audio.offload.buffer.size.kb", value, "")) &&
-            atoi(value)) {
-        fragment_size =  atoi(value) * 1024;
-        //ring buffer size needs to be 4k aligned.
-        CHECK(!(fragment_size * COMPRESS_OFFLOAD_NUM_FRAGMENTS % 4096));
-    }
-    if(fragment_size < MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
-        fragment_size = MIN_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
-    else if(fragment_size > MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE)
-        fragment_size = MAX_COMPRESS_OFFLOAD_FRAGMENT_SIZE;
-    ALOGVV("%s: fragment_size %d", __func__, fragment_size);
-    return fragment_size;
-}
-
-static int set_gapless_mode(struct audio_device *adev) {
-
-
-    char value[PROPERTY_VALUE_MAX] = {0};
-    bool gapless_enabled = false;
-    const char *mixer_ctl_name = "Compress Gapless Playback";
-    struct mixer_ctl *ctl;
-
-    ALOGV("%s:", __func__);
-    property_get("audio.offload.gapless.enabled", value, NULL);
-    gapless_enabled = atoi(value) || !strncmp("true", value, 4);
-
-    ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
-    if (!ctl) {
-        ALOGE("%s: Could not get ctl for mixer cmd - %s",
-                               __func__, mixer_ctl_name);
-        return -EINVAL;
-    }
-
-    if (mixer_ctl_set_value(ctl, 0, gapless_enabled) < 0) {
-        ALOGE("%s: Could not set gapless mode %d",
-                       __func__, gapless_enabled);
-         return -EINVAL;
-    }
-    return 0;
-
-}
 static struct hw_module_methods_t hal_module_methods = {
     .open = adev_open,
 };
diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c
index 298c60d..c1ba595 100644
--- a/hal/msm8960/platform.c
+++ b/hal/msm8960/platform.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
  * Not a contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -391,6 +391,16 @@
     return device_id;
 }
 
+int platform_get_snd_device_index(char *snd_device_index_name)
+{
+    return -ENODEV;
+}
+
+int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
+{
+    return -ENODEV;
+}
+
 int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
 {
     struct platform_data *my_data = (struct platform_data *)platform;
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 312c327..40fed4e 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -76,7 +76,7 @@
 
 /* Audio calibration related functions */
 typedef void (*acdb_deallocate_t)();
-typedef int  (*acdb_init_t)();
+typedef int  (*acdb_init_t)(char *);
 typedef void (*acdb_send_audio_cal_t)(int, int);
 typedef void (*acdb_send_voice_cal_t)(int, int);
 typedef int (*acdb_reload_vocvoltable_t)(int);
@@ -222,7 +222,7 @@
 };
 
 /* ACDB IDs (audio DSP path configuration IDs) for each sound device */
-static const int acdb_device_table[SND_DEVICE_MAX] = {
+static int acdb_device_table[SND_DEVICE_MAX] = {
     [SND_DEVICE_NONE] = -1,
     [SND_DEVICE_OUT_HANDSET] = 7,
     [SND_DEVICE_OUT_SPEAKER] = 14,
@@ -240,7 +240,7 @@
     [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17,
     [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37,
     [SND_DEVICE_OUT_AFE_PROXY] = 0,
-    [SND_DEVICE_OUT_USB_HEADSET] = 0,
+    [SND_DEVICE_OUT_USB_HEADSET] = 45,
     [SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET] = 14,
     [SND_DEVICE_OUT_TRANSMISSION_FM] = 0,
     [SND_DEVICE_OUT_ANC_HEADSET] = 26,
@@ -294,6 +294,84 @@
     [SND_DEVICE_IN_CAPTURE_VI_FEEDBACK] = 102,
 };
 
+struct snd_device_index {
+    char name[100];
+    unsigned int index;
+};
+
+#define TO_NAME_INDEX(X)   #X, X
+
+/* Used to get index from parsed sting */
+struct snd_device_index snd_device_name_index[SND_DEVICE_MAX] = {
+    {TO_NAME_INDEX(SND_DEVICE_OUT_HANDSET)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_REVERSE)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_HEADPHONES)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HANDSET)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_SPEAKER)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_HEADPHONES)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_HDMI)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_HDMI)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_BT_SCO_WB)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_AFE_PROXY)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_USB_HEADSET)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_USB_HEADSET)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_TRANSMISSION_FM)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HEADSET)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_FB_HEADSET)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_HEADSET)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_VOICE_ANC_FB_HEADSET)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_ANC_HANDSET)},
+    {TO_NAME_INDEX(SND_DEVICE_OUT_SPEAKER_PROTECTED)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_NS)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_MIC_AEC_NS)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_NS)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_DMIC_AEC_NS)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_NS)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_MIC_AEC_NS)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_NS)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_DMIC_AEC_NS)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HEADSET_MIC_FLUENCE)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_HEADSET_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HDMI_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_BT_SCO_MIC_WB)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_CAMCORDER_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_DMIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_DMIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_SPEAKER_QMIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_MIC_NS)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_STEREO)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_USB_HEADSET_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_FM)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_AANC_HANDSET_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_QUAD_MIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_HANDSET_STEREO_DMIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_SPEAKER_STEREO_DMIC)},
+    {TO_NAME_INDEX(SND_DEVICE_IN_CAPTURE_VI_FEEDBACK)},
+};
+
 #define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
 #define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
 
@@ -565,13 +643,16 @@
                   __func__, LIB_ACDB_LOADER);
 
         my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle,
-                                                    "acdb_loader_init_ACDB");
+                                                    "acdb_loader_init_v2");
         if (my_data->acdb_init == NULL)
-            ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror());
+            ALOGE("%s: dlsym error %s for acdb_loader_init_v2", __func__, dlerror());
         else
-            my_data->acdb_init();
+            my_data->acdb_init(snd_card_name);
     }
 
+    /* Initialize ACDB ID's */
+    platform_info_init();
+
     /* If platform is apq8084 and baseband is MDM, load CSD Client specific
      * symbols. Voice call is handled by MDM and apps processor talks to
      * MDM through CSD Client
@@ -669,6 +750,46 @@
     return device_id;
 }
 
+int platform_get_snd_device_index(char *snd_device_index_name)
+{
+    int ret = 0;
+    int i;
+
+    if (snd_device_index_name == NULL) {
+        ALOGE("%s: snd_device_index_name is NULL", __func__);
+        ret = -ENODEV;
+        goto done;
+    }
+
+    for (i=0; i < SND_DEVICE_MAX; i++) {
+        if(strcmp(snd_device_name_index[i].name, snd_device_index_name) == 0) {
+            ret = snd_device_name_index[i].index;
+            goto done;
+        }
+    }
+    ALOGE("%s: Could not find index for snd_device_index_name = %s",
+            __func__, snd_device_index_name);
+    ret = -ENODEV;
+done:
+    return ret;
+}
+
+int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id)
+{
+    int ret = 0;
+
+    if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
+        ALOGE("%s: Invalid snd_device = %d",
+            __func__, snd_device);
+        ret = -EINVAL;
+        goto done;
+    }
+
+    acdb_device_table[snd_device] = acdb_id;
+done:
+    return ret;
+}
+
 int platform_send_audio_calibration(void *platform, snd_device_t snd_device)
 {
     struct platform_data *my_data = (struct platform_data *)platform;
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index bb1f787..3ea068d 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -147,7 +147,7 @@
  * the buffer size of an input/output stream
  */
 #define DEEP_BUFFER_OUTPUT_PERIOD_SIZE 960
-#define DEEP_BUFFER_OUTPUT_PERIOD_COUNT 8
+#define DEEP_BUFFER_OUTPUT_PERIOD_COUNT 4
 #define LOW_LATENCY_OUTPUT_PERIOD_SIZE 240
 #define LOW_LATENCY_OUTPUT_PERIOD_COUNT 2
 
@@ -174,7 +174,7 @@
 #define INCALL_MUSIC_UPLINK_PCM_DEVICE 1
 #define INCALL_MUSIC_UPLINK2_PCM_DEVICE 16
 #define SPKR_PROT_CALIB_RX_PCM_DEVICE 5
-#define SPKR_PROT_CALIB_TX_PCM_DEVICE 22
+#define SPKR_PROT_CALIB_TX_PCM_DEVICE 25
 #define PLAYBACK_OFFLOAD_DEVICE 9
 #define COMPRESS_VOIP_CALL_PCM_DEVICE 3
 
diff --git a/hal/platform_api.h b/hal/platform_api.h
index 4096ef0..a5f5074 100644
--- a/hal/platform_api.h
+++ b/hal/platform_api.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
  * Not a contribution.
  *
  * Copyright (C) 2013 The Android Open Source Project
@@ -17,8 +17,8 @@
  * limitations under the License.
  */
 
-#ifndef QCOM_AUDIO_PLATFORM_API_H
-#define QCOM_AUDIO_PLATFORM_API_H
+#ifndef AUDIO_PLATFORM_API_H
+#define AUDIO_PLATFORM_API_H
 
 void *platform_init(struct audio_device *adev);
 void platform_deinit(void *platform);
@@ -27,6 +27,8 @@
                                       char *device_name);
 void platform_add_backend_name(char *mixer_path, snd_device_t snd_device);
 int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type);
+int platform_get_snd_device_index(char *snd_device_index_name);
+int platform_set_snd_device_acdb_id(snd_device_t snd_device, unsigned int acdb_id);
 int platform_send_audio_calibration(void *platform, snd_device_t snd_device);
 int platform_switch_voice_call_device_pre(void *platform);
 int platform_switch_voice_call_device_post(void *platform,
@@ -57,4 +59,7 @@
 
 bool platform_listen_update_status(snd_device_t snd_device);
 
-#endif // QCOM_AUDIO_PLATFORM_API_H
+/* From platform_info_parser.c */
+int platform_info_init(void);
+
+#endif // AUDIO_PLATFORM_API_H
diff --git a/hal/platform_info.c b/hal/platform_info.c
new file mode 100644
index 0000000..8f56107
--- /dev/null
+++ b/hal/platform_info.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2014, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of The Linux Foundation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define LOG_TAG "platform_info"
+#define LOG_NDDEBUG 0
+
+#include <errno.h>
+#include <stdio.h>
+#include <expat.h>
+#include <cutils/log.h>
+#include <audio_hw.h>
+#include "platform_api.h"
+#include <platform.h>
+
+#define PLATFORM_INFO_XML_PATH      "/system/etc/audio_platform_info.xml"
+#define BUF_SIZE                    1024
+
+static void process_device(const XML_Char **attr)
+{
+    int index;
+
+    if (strcmp(attr[0], "name") != 0) {
+        ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
+        goto done;
+    }
+
+    index = platform_get_snd_device_index((char *)attr[1]);
+    if (index < 0) {
+        ALOGE("%s: Device %s in %s not found, no ACDB ID set!",
+              __func__, attr[1], PLATFORM_INFO_XML_PATH);
+        goto done;
+    }
+
+    if (strcmp(attr[2], "acdb_id") != 0) {
+        ALOGE("%s: Device %s in %s has no acdb_id, no ACDB ID set!",
+              __func__, attr[1], PLATFORM_INFO_XML_PATH);
+        goto done;
+    }
+
+    if(platform_set_snd_device_acdb_id(index, atoi((char *)attr[3])) < 0) {
+        ALOGE("%s: Device %s in %s, ACDB ID %d was not set!",
+              __func__, attr[1], PLATFORM_INFO_XML_PATH, atoi((char *)attr[3]));
+        goto done;
+    }
+
+done:
+    return;
+}
+
+static void start_tag(void *userdata, const XML_Char *tag_name,
+                      const XML_Char **attr)
+{
+    const XML_Char              *attr_name = NULL;
+    const XML_Char              *attr_value = NULL;
+    unsigned int                i;
+
+    if (strcmp(tag_name, "device") == 0)
+        process_device(attr);
+
+    return;
+}
+
+static void end_tag(void *userdata, const XML_Char *tag_name)
+{
+
+}
+
+int platform_info_init(void)
+{
+    XML_Parser      parser;
+    FILE            *file;
+    int             ret = 0;
+    int             bytes_read;
+    void            *buf;
+
+    file = fopen(PLATFORM_INFO_XML_PATH, "r");
+    if (!file) {
+        ALOGD("%s: Failed to open %s, using defaults.",
+            __func__, PLATFORM_INFO_XML_PATH);
+        ret = -ENODEV;
+        goto done;
+    }
+
+    parser = XML_ParserCreate(NULL);
+    if (!parser) {
+        ALOGE("%s: Failed to create XML parser!", __func__);
+        ret = -ENODEV;
+        goto err_close_file;
+    }
+
+    XML_SetElementHandler(parser, start_tag, end_tag);
+
+    while (1) {
+        buf = XML_GetBuffer(parser, BUF_SIZE);
+        if (buf == NULL) {
+            ALOGE("%s: XML_GetBuffer failed", __func__);
+            ret = -ENOMEM;
+            goto err_free_parser;
+        }
+
+        bytes_read = fread(buf, 1, BUF_SIZE, file);
+        if (bytes_read < 0) {
+            ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read);
+             ret = bytes_read;
+            goto err_free_parser;
+        }
+
+        if (XML_ParseBuffer(parser, bytes_read,
+                            bytes_read == 0) == XML_STATUS_ERROR) {
+            ALOGE("%s: XML_ParseBuffer failed, for %s",
+                __func__, PLATFORM_INFO_XML_PATH);
+            ret = -EINVAL;
+            goto err_free_parser;
+        }
+
+        if (bytes_read == 0)
+            break;
+    }
+
+err_free_parser:
+    XML_ParserFree(parser);
+err_close_file:
+    fclose(file);
+done:
+    return ret;
+}
diff --git a/hal_mpq/audio_stream_out.c b/hal_mpq/audio_stream_out.c
index c475a1e..454b1d6 100644
--- a/hal_mpq/audio_stream_out.c
+++ b/hal_mpq/audio_stream_out.c
@@ -1051,23 +1051,19 @@
 }
 
 /*TODO: do we need to apply volume at the session open*/
-static int set_compress_volume(struct alsa_handle *handle, int left, int right)
+static int set_compress_volume(struct alsa_handle *handle, float left, float right)
 {
 
     struct audio_device *adev = handle->out->dev;
     struct mixer_ctl *ctl;
     int volume[2];
 
-    char mixer_ctl_name[44]; // max length of name is 44 as defined
-    char device_id[STRING_LENGTH_OF_INTEGER+1];
+    char mixer_ctl_name[MIXER_PATH_MAX_LENGTH];
+    ALOGV("%s:setting volume l %f r %f ", __func__, left, right);
 
     memset(mixer_ctl_name, 0, sizeof(mixer_ctl_name));
-    strlcpy(mixer_ctl_name, "Compress Playback Volume", sizeof(mixer_ctl_name));
-
-    memset(device_id, 0, sizeof(device_id));
-    snprintf(device_id, "%d", handle->device_id, sizeof(device_id));
-
-    strlcat(mixer_ctl_name, device_id, sizeof(mixer_ctl_name));
+    snprintf(mixer_ctl_name, sizeof(mixer_ctl_name),
+          "Compress Playback %d Volume", handle->device_id);
 
     ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
     if (!ctl) {
@@ -1075,8 +1071,8 @@
                 __func__, mixer_ctl_name);
         return -EINVAL;
     }
-    volume[0] = (int)(left * COMPRESS_PLAYBACK_VOLUME_MAX);
-    volume[1] = (int)(right * COMPRESS_PLAYBACK_VOLUME_MAX);
+    volume[0] = (int)(left * (float) COMPRESS_PLAYBACK_VOLUME_MAX);
+    volume[1] = (int)(right * (float) COMPRESS_PLAYBACK_VOLUME_MAX);
     mixer_ctl_set_array(ctl, volume, sizeof(volume)/sizeof(volume[0]));
 
     return 0;
@@ -1709,8 +1705,8 @@
     uc_info->out_snd_device = SND_DEVICE_NONE;
 
     /* This must be called before adding this usecase to the list */
-    //if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL)
-    //    check_and_set_hdmi_channels(adev, out->config.channels);
+    if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL)
+        check_and_set_hdmi_channels(adev, handle->config.channels);
 
     list_add_tail(&adev->usecase_list, &uc_info->list);
 
@@ -2105,7 +2101,7 @@
     struct alsa_handle *handle;
     struct audio_device *adev = out->dev;
     int ret = -ENOSYS;
-    ALOGV("%s", __func__);
+    ALOGV("%s:setting volume l %f r %f ", __func__, left, right);
     pthread_mutex_lock(&out->lock);
     list_for_each(node, &out->session_list) {
         handle = node_to_item(node, struct alsa_handle, list);
@@ -2118,7 +2114,7 @@
             out->left_volume = left;
             out->right_volume = right;
 
-            //ret = set_compress_volume(handle, left, right);
+            ret = set_compress_volume(handle, left, right);
         }
     }
     pthread_mutex_unlock(&out->lock);
diff --git a/hal_mpq/mpq8092/platform.c b/hal_mpq/mpq8092/platform.c
index 3c1b4f7..6c50034 100644
--- a/hal_mpq/mpq8092/platform.c
+++ b/hal_mpq/mpq8092/platform.c
@@ -176,6 +176,7 @@
     [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = "speaker-and-anc-headphones",
     [SND_DEVICE_OUT_ANC_HANDSET] = "anc-handset",
     [SND_DEVICE_OUT_SPEAKER_PROTECTED] = "speaker-protected",
+    [SND_DEVICE_OUT_SPDIF] = "spdif",
 
     /* Capture sound devices */
     [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic",
@@ -249,6 +250,7 @@
     [SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET] = 26,
     [SND_DEVICE_OUT_ANC_HANDSET] = 103,
     [SND_DEVICE_OUT_SPEAKER_PROTECTED] = 101,
+    [SND_DEVICE_OUT_SPDIF] = 18,
 
     [SND_DEVICE_IN_HANDSET_MIC] = 4,
     [SND_DEVICE_IN_HANDSET_MIC_AEC] = 106,
@@ -607,6 +609,8 @@
         strlcat(mixer_path, " capture-fm", MIXER_PATH_MAX_LENGTH);
     else if (snd_device == SND_DEVICE_OUT_TRANSMISSION_FM)
         strlcat(mixer_path, " transmission-fm", MIXER_PATH_MAX_LENGTH);
+    else if (snd_device == SND_DEVICE_OUT_SPDIF)
+        strlcat(mixer_path, " spdif", MIXER_PATH_MAX_LENGTH);
 }
 
 int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type)
@@ -897,6 +901,8 @@
         snd_device = SND_DEVICE_OUT_TRANSMISSION_FM;
     } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) {
         snd_device = SND_DEVICE_OUT_HANDSET;
+    } else if (devices & AUDIO_DEVICE_OUT_SPDIF) {
+        snd_device = SND_DEVICE_OUT_SPDIF;
     } else {
         ALOGE("%s: Unknown device(s) %#x", __func__, devices);
     }
diff --git a/hal_mpq/mpq8092/platform.h b/hal_mpq/mpq8092/platform.h
index 2a81df5..562f979 100644
--- a/hal_mpq/mpq8092/platform.h
+++ b/hal_mpq/mpq8092/platform.h
@@ -74,6 +74,7 @@
     SND_DEVICE_OUT_SPEAKER_AND_ANC_HEADSET,
     SND_DEVICE_OUT_ANC_HANDSET,
     SND_DEVICE_OUT_SPEAKER_PROTECTED,
+    SND_DEVICE_OUT_SPDIF,
     SND_DEVICE_OUT_END,
 
     /*
diff --git a/policy_hal/Android.mk b/policy_hal/Android.mk
index b6a06e4..c68ab6e 100644
--- a/policy_hal/Android.mk
+++ b/policy_hal/Android.mk
@@ -30,6 +30,14 @@
 LOCAL_CFLAGS += -DAUDIO_EXTN_INCALL_MUSIC_ENABLED
 endif
 
+
+ifeq ($(strip $(TARGET_BOARD_PLATFORM)),msm8916)
+LOCAL_CFLAGS += -DVOICE_CONCURRENCY
+LOCAL_CFLAGS += -DWFD_CONCURRENCY
+endif
+
+
+
 include $(BUILD_SHARED_LIBRARY)
 
 endif
diff --git a/policy_hal/AudioPolicyManager.cpp b/policy_hal/AudioPolicyManager.cpp
index f64bbfe..5142353 100644
--- a/policy_hal/AudioPolicyManager.cpp
+++ b/policy_hal/AudioPolicyManager.cpp
@@ -418,12 +418,36 @@
 
 AudioPolicyManager::routing_strategy AudioPolicyManager::getStrategy(AudioSystem::stream_type stream)
 {
-#ifdef QCOM_INCALL_MUSIC_ENABLED
-    if (stream == AudioSystem::INCALL_MUSIC)
-        return STRATEGY_MEDIA;
+       // stream to strategy mapping
+        switch (stream) {
+        case AudioSystem::VOICE_CALL:
+        case AudioSystem::BLUETOOTH_SCO:
+            return STRATEGY_PHONE;
+        case AudioSystem::RING:
+        case AudioSystem::ALARM:
+            return STRATEGY_SONIFICATION;
+        case AudioSystem::NOTIFICATION:
+            return STRATEGY_SONIFICATION_RESPECTFUL;
+        case AudioSystem::DTMF:
+            return STRATEGY_DTMF;
+        default:
+            ALOGE("unknown stream type");
+        case AudioSystem::SYSTEM:
+            // NOTE: SYSTEM stream uses MEDIA strategy because muting music and switching outputs
+            // while key clicks are played produces a poor result
+        case AudioSystem::TTS:
+        case AudioSystem::MUSIC:
+#ifdef AUDIO_EXTN_INCALL_MUSIC_ENABLED
+        case AudioSystem::INCALL_MUSIC:
 #endif
+#ifdef QCOM_INCALL_MUSIC_ENABLED
+        case AudioSystem::INCALL_MUSIC:
+#endif
+             return STRATEGY_MEDIA;
+        case AudioSystem::ENFORCED_AUDIBLE:
+            return STRATEGY_ENFORCED_AUDIBLE;
+    }
 
-    return getStrategy(stream);
 }
 
 audio_devices_t AudioPolicyManager::getDeviceForStrategy(routing_strategy strategy,
@@ -632,7 +656,8 @@
         if (device2 == AUDIO_DEVICE_NONE) {
             device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET;
         }
-        if ((device2 == AUDIO_DEVICE_NONE) && (strategy != STRATEGY_SONIFICATION)) {
+        if ((strategy != STRATEGY_SONIFICATION) && (device == AUDIO_DEVICE_NONE)
+             && (device2 == AUDIO_DEVICE_NONE)) {
             // no sonification on aux digital (e.g. HDMI)
             device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_AUX_DIGITAL;
         }
@@ -642,12 +667,14 @@
             device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET;
         }
 #ifdef AUDIO_EXTN_FM_ENABLED
-            if ((strategy != STRATEGY_SONIFICATION) && (device2 == AUDIO_DEVICE_NONE)) {
+            if ((strategy != STRATEGY_SONIFICATION) && (device == AUDIO_DEVICE_NONE)
+                 && (device2 == AUDIO_DEVICE_NONE)) {
                 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_FM_TX;
             }
 #endif
 #ifdef AUDIO_EXTN_AFE_PROXY_ENABLED
-            if ((strategy != STRATEGY_SONIFICATION) && (device2 == AUDIO_DEVICE_NONE)) {
+            if ((strategy != STRATEGY_SONIFICATION) && (device == AUDIO_DEVICE_NONE)
+                 && (device2 == AUDIO_DEVICE_NONE)) {
                 // no sonification on WFD sink
                 device2 = mAvailableOutputDevices & AUDIO_DEVICE_OUT_PROXY;
             }
@@ -878,6 +905,422 @@
 #endif
     return AudioPolicyManagerBase::computeVolume(stream, index, output, device);
 }
+
+
+audio_io_handle_t AudioPolicyManager::getOutput(AudioSystem::stream_type stream,
+                                    uint32_t samplingRate,
+                                    uint32_t format,
+                                    uint32_t channelMask,
+                                    AudioSystem::output_flags flags,
+                                    const audio_offload_info_t *offloadInfo)
+{
+    audio_io_handle_t output = 0;
+    uint32_t latency = 0;
+    routing_strategy strategy = getStrategy((AudioSystem::stream_type)stream);
+    audio_devices_t device = getDeviceForStrategy(strategy, false /*fromCache*/);
+    IOProfile *profile = NULL;
+
+#ifdef VOICE_CONCURRENCY
+    if (isInCall()) {
+        ALOGV(" IN call mode adding ULL flags .. flags: %x ", flags );
+        //For voip paths
+        if(flags & AudioSystem::OUTPUT_FLAG_DIRECT)
+            flags = AudioSystem::OUTPUT_FLAG_DIRECT;
+        else //route every thing else to ULL path
+            flags = (AudioSystem::output_flags)AUDIO_OUTPUT_FLAG_FAST;
+    }
+#endif
+
+#ifdef WFD_CONCURRENCY
+    if ((mAvailableOutputDevices & AUDIO_DEVICE_OUT_PROXY)
+          && (stream != AudioSystem::MUSIC)) {
+        ALOGV(" WFD mode adding ULL flags for non music stream.. flags: %x ", flags );
+        //For voip paths
+        if(flags & AudioSystem::OUTPUT_FLAG_DIRECT)
+            flags = AudioSystem::OUTPUT_FLAG_DIRECT;
+        else //route every thing else to ULL path
+            flags = (AudioSystem::output_flags)AUDIO_OUTPUT_FLAG_FAST;
+    }
+#endif
+
+    ALOGV(" getOutput() device %d, stream %d, samplingRate %d, format %x, channelMask %x, flags %x ",
+          device, stream, samplingRate, format, channelMask, flags);
+
+
+
+#ifdef AUDIO_POLICY_TEST
+    if (mCurOutput != 0) {
+        ALOGV("getOutput() test output mCurOutput %d, samplingRate %d, format %d, channelMask %x, mDirectOutput %d",
+                mCurOutput, mTestSamplingRate, mTestFormat, mTestChannels, mDirectOutput);
+
+        if (mTestOutputs[mCurOutput] == 0) {
+            ALOGV("getOutput() opening test output");
+            AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor(NULL);
+            outputDesc->mDevice = mTestDevice;
+            outputDesc->mSamplingRate = mTestSamplingRate;
+            outputDesc->mFormat = mTestFormat;
+            outputDesc->mChannelMask = mTestChannels;
+            outputDesc->mLatency = mTestLatencyMs;
+            outputDesc->mFlags = (audio_output_flags_t)(mDirectOutput ? AudioSystem::OUTPUT_FLAG_DIRECT : 0);
+            outputDesc->mRefCount[stream] = 0;
+            mTestOutputs[mCurOutput] = mpClientInterface->openOutput(0, &outputDesc->mDevice,
+                                            &outputDesc->mSamplingRate,
+                                            &outputDesc->mFormat,
+                                            &outputDesc->mChannelMask,
+                                            &outputDesc->mLatency,
+                                            outputDesc->mFlags,
+                                            offloadInfo);
+            if (mTestOutputs[mCurOutput]) {
+                AudioParameter outputCmd = AudioParameter();
+                outputCmd.addInt(String8("set_id"),mCurOutput);
+                mpClientInterface->setParameters(mTestOutputs[mCurOutput],outputCmd.toString());
+                addOutput(mTestOutputs[mCurOutput], outputDesc);
+            }
+        }
+        return mTestOutputs[mCurOutput];
+    }
+#endif //AUDIO_POLICY_TEST
+
+    // open a direct output if required by specified parameters
+    //force direct flag if offload flag is set: offloading implies a direct output stream
+    // and all common behaviors are driven by checking only the direct flag
+    // this should normally be set appropriately in the policy configuration file
+    if ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0) {
+        flags = (AudioSystem::output_flags)(flags | AUDIO_OUTPUT_FLAG_DIRECT);
+    }
+
+    if ((format == AudioSystem::PCM_16_BIT) &&(AudioSystem::popCount(channelMask) > 2)) {
+        ALOGV("owerwrite flag(%x) for PCM16 multi-channel(CM:%x) playback", flags ,channelMask);
+        flags = (AudioSystem::output_flags)AUDIO_OUTPUT_FLAG_DIRECT;
+    }
+
+    // Do not allow offloading if one non offloadable effect is enabled. This prevents from
+    // creating an offloaded track and tearing it down immediately after start when audioflinger
+    // detects there is an active non offloadable effect.
+    // FIXME: We should check the audio session here but we do not have it in this context.
+    // This may prevent offloading in rare situations where effects are left active by apps
+    // in the background.
+    if ((((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) == 0) ||
+            !isNonOffloadableEffectEnabled()) &&
+            flags & AUDIO_OUTPUT_FLAG_DIRECT) {
+        profile = getProfileForDirectOutput(device,
+                                           samplingRate,
+                                           format,
+                                           channelMask,
+                                           (audio_output_flags_t)flags);
+    }
+
+    if (profile != NULL) {
+        AudioOutputDescriptor *outputDesc = NULL;
+
+        for (size_t i = 0; i < mOutputs.size(); i++) {
+            AudioOutputDescriptor *desc = mOutputs.valueAt(i);
+            if (!desc->isDuplicated() && (profile == desc->mProfile)) {
+                outputDesc = desc;
+                // reuse direct output if currently open and configured with same parameters
+                if ((samplingRate == outputDesc->mSamplingRate) &&
+                        (format == outputDesc->mFormat) &&
+                        (channelMask == outputDesc->mChannelMask)) {
+                    outputDesc->mDirectOpenCount++;
+                    ALOGV("getOutput() reusing direct output %d", mOutputs.keyAt(i));
+                    return mOutputs.keyAt(i);
+                }
+            }
+        }
+        // close direct output if currently open and configured with different parameters
+        if (outputDesc != NULL) {
+            closeOutput(outputDesc->mId);
+        }
+        outputDesc = new AudioOutputDescriptor(profile);
+        outputDesc->mDevice = device;
+        outputDesc->mSamplingRate = samplingRate;
+        outputDesc->mFormat = (audio_format_t)format;
+        outputDesc->mChannelMask = (audio_channel_mask_t)channelMask;
+        outputDesc->mLatency = 0;
+        outputDesc->mFlags =(audio_output_flags_t) (outputDesc->mFlags | flags);
+        outputDesc->mRefCount[stream] = 0;
+        outputDesc->mStopTime[stream] = 0;
+        outputDesc->mDirectOpenCount = 1;
+        output = mpClientInterface->openOutput(profile->mModule->mHandle,
+                                        &outputDesc->mDevice,
+                                        &outputDesc->mSamplingRate,
+                                        &outputDesc->mFormat,
+                                        &outputDesc->mChannelMask,
+                                        &outputDesc->mLatency,
+                                        outputDesc->mFlags,
+                                        offloadInfo);
+
+        // only accept an output with the requested parameters
+        if (output == 0 ||
+            (samplingRate != 0 && samplingRate != outputDesc->mSamplingRate) ||
+            (format != 0 && format != outputDesc->mFormat) ||
+            (channelMask != 0 && channelMask != outputDesc->mChannelMask)) {
+            ALOGV("getOutput() failed opening direct output: output %d samplingRate %d %d,"
+                    "format %d %d, channelMask %04x %04x", output, samplingRate,
+                    outputDesc->mSamplingRate, format, outputDesc->mFormat, channelMask,
+                    outputDesc->mChannelMask);
+            if (output != 0) {
+                mpClientInterface->closeOutput(output);
+            }
+            delete outputDesc;
+            return 0;
+        }
+        audio_io_handle_t srcOutput = getOutputForEffect();
+        addOutput(output, outputDesc);
+        audio_io_handle_t dstOutput = getOutputForEffect();
+        if (dstOutput == output) {
+            mpClientInterface->moveEffects(AUDIO_SESSION_OUTPUT_MIX, srcOutput, dstOutput);
+        }
+        mPreviousOutputs = mOutputs;
+        ALOGV("getOutput() returns new direct output %d", output);
+        return output;
+    }
+
+    // ignoring channel mask due to downmix capability in mixer
+
+    // open a non direct output
+
+    // for non direct outputs, only PCM is supported
+    if (audio_is_linear_pcm((audio_format_t)format)) {
+        // get which output is suitable for the specified stream. The actual
+        // routing change will happen when startOutput() will be called
+        SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(device, mOutputs);
+
+        output = selectOutput(outputs, flags);
+    }
+    ALOGW_IF((output == 0), "getOutput() could not find output for stream %d, samplingRate %d,"
+            "format %d, channels %x, flags %x", stream, samplingRate, format, channelMask, flags);
+
+    ALOGV("getOutput() returns output %d", output);
+
+    return output;
+}
+
+
+// This function checks for the parameters which can be offloaded.
+// This can be enhanced depending on the capability of the DSP and policy
+// of the system.
+bool AudioPolicyManager::isOffloadSupported(const audio_offload_info_t& offloadInfo)
+{
+    ALOGV(" isOffloadSupported: SR=%u, CM=0x%x, Format=0x%x, StreamType=%d,"
+     " BitRate=%u, duration=%lld us, has_video=%d",
+     offloadInfo.sample_rate, offloadInfo.channel_mask,
+     offloadInfo.format,
+     offloadInfo.stream_type, offloadInfo.bit_rate, offloadInfo.duration_us,
+     offloadInfo.has_video);
+
+#ifdef VOICE_CONCURRENCY
+    if(isInCall())
+    {
+        ALOGD("\n  blocking  compress offload on call mode\n");
+        return false;
+    }
+#endif
+
+    // Check if offload has been disabled
+    char propValue[PROPERTY_VALUE_MAX];
+    if (property_get("audio.offload.disable", propValue, "0")) {
+        if (atoi(propValue) != 0) {
+            ALOGV("offload disabled by audio.offload.disable=%s", propValue );
+            return false;
+        }
+    }
+
+    // Check if stream type is music, then only allow offload as of now.
+    if (offloadInfo.stream_type != AUDIO_STREAM_MUSIC)
+    {
+        ALOGV("isOffloadSupported: stream_type != MUSIC, returning false");
+        return false;
+    }
+
+    //TODO: enable audio offloading with video when ready
+    if (offloadInfo.has_video)
+    {
+        if(property_get("av.offload.enable", propValue, NULL)) {
+            bool prop_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
+            if (!prop_enabled) {
+               ALOGW("offload disabled by av.offload.enable = %s ", propValue );
+               return false;
+            }
+        }
+        if(offloadInfo.is_streaming &&
+           property_get("av.streaming.offload.enable", propValue, NULL)) {
+            bool prop_enabled = atoi(propValue) || !strncmp("true", propValue, 4);
+            if (!prop_enabled) {
+               ALOGW("offload disabled by av.streaming.offload.enable = %s ", propValue );
+               return false;
+            }
+        }
+        ALOGV("isOffloadSupported: has_video == true, property\
+                set to enable offload");
+    }
+
+    //If duration is less than minimum value defined in property, return false
+    if (property_get("audio.offload.min.duration.secs", propValue, NULL)) {
+        if (offloadInfo.duration_us < (atoi(propValue) * 1000000 )) {
+            ALOGV("Offload denied by duration < audio.offload.min.duration.secs(=%s)", propValue);
+            return false;
+        }
+    } else if (offloadInfo.duration_us < OFFLOAD_DEFAULT_MIN_DURATION_SECS * 1000000) {
+        ALOGV("Offload denied by duration < default min(=%u)", OFFLOAD_DEFAULT_MIN_DURATION_SECS);
+        //duration checks only valid for MP3/AAC formats,
+        //do not check duration for other audio formats, e.g. dolby AAC/AC3 and amrwb+ formats
+        if (offloadInfo.format == AUDIO_FORMAT_MP3 || offloadInfo.format == AUDIO_FORMAT_AAC)
+            return false;
+    }
+
+    // Do not allow offloading if one non offloadable effect is enabled. This prevents from
+    // creating an offloaded track and tearing it down immediately after start when audioflinger
+    // detects there is an active non offloadable effect.
+    // FIXME: We should check the audio session here but we do not have it in this context.
+    // This may prevent offloading in rare situations where effects are left active by apps
+    // in the background.
+    if (isNonOffloadableEffectEnabled()) {
+        return false;
+    }
+
+    // See if there is a profile to support this.
+    // AUDIO_DEVICE_NONE
+    IOProfile *profile = getProfileForDirectOutput(AUDIO_DEVICE_NONE /*ignore device */,
+                                            offloadInfo.sample_rate,
+                                            offloadInfo.format,
+                                            offloadInfo.channel_mask,
+                                            AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD);
+    ALOGV("isOffloadSupported() profile %sfound", profile != NULL ? "" : "NOT ");
+    return (profile != NULL);
+}
+
+void AudioPolicyManager::setPhoneState(int state)
+
+{
+    ALOGV("setPhoneState() state %d", state);
+    audio_devices_t newDevice = AUDIO_DEVICE_NONE;
+    if (state < 0 || state >= AudioSystem::NUM_MODES) {
+        ALOGW("setPhoneState() invalid state %d", state);
+        return;
+    }
+
+    if (state == mPhoneState ) {
+        ALOGW("setPhoneState() setting same state %d", state);
+        return;
+    }
+
+    // if leaving call state, handle special case of active streams
+    // pertaining to sonification strategy see handleIncallSonification()
+    if (isInCall()) {
+        ALOGV("setPhoneState() in call state management: new state is %d", state);
+        for (int stream = 0; stream < AudioSystem::NUM_STREAM_TYPES; stream++) {
+            handleIncallSonification(stream, false, true);
+        }
+    }
+
+    // store previous phone state for management of sonification strategy below
+    int oldState = mPhoneState;
+    mPhoneState = state;
+    bool force = false;
+
+    // are we entering or starting a call
+    if (!isStateInCall(oldState) && isStateInCall(state)) {
+        ALOGV("  Entering call in setPhoneState()");
+        // force routing command to audio hardware when starting a call
+        // even if no device change is needed
+        force = true;
+        for (int j = 0; j < DEVICE_CATEGORY_CNT; j++) {
+            mStreams[AUDIO_STREAM_DTMF].mVolumeCurve[j] =
+                    sVolumeProfiles[AUDIO_STREAM_VOICE_CALL][j];
+        }
+    } else if (isStateInCall(oldState) && !isStateInCall(state)) {
+        ALOGV("  Exiting call in setPhoneState()");
+        // force routing command to audio hardware when exiting a call
+        // even if no device change is needed
+        force = true;
+        for (int j = 0; j < DEVICE_CATEGORY_CNT; j++) {
+            mStreams[AUDIO_STREAM_DTMF].mVolumeCurve[j] =
+                    sVolumeProfiles[AUDIO_STREAM_DTMF][j];
+        }
+    } else if (isStateInCall(state) && (state != oldState)) {
+        ALOGV("  Switching between telephony and VoIP in setPhoneState()");
+        // force routing command to audio hardware when switching between telephony and VoIP
+        // even if no device change is needed
+        force = true;
+    }
+
+    // check for device and output changes triggered by new phone state
+    newDevice = getNewDevice(mPrimaryOutput, false /*fromCache*/);
+    checkA2dpSuspend();
+    checkOutputForAllStrategies();
+    updateDevicesAndOutputs();
+
+    AudioOutputDescriptor *hwOutputDesc = mOutputs.valueFor(mPrimaryOutput);
+
+    // force routing command to audio hardware when ending call
+    // even if no device change is needed
+    if (isStateInCall(oldState) && newDevice == AUDIO_DEVICE_NONE) {
+        newDevice = hwOutputDesc->device();
+    }
+
+    int delayMs = 0;
+    if (isStateInCall(state)) {
+        nsecs_t sysTime = systemTime();
+        for (size_t i = 0; i < mOutputs.size(); i++) {
+            AudioOutputDescriptor *desc = mOutputs.valueAt(i);
+            // mute media and sonification strategies and delay device switch by the largest
+            // latency of any output where either strategy is active.
+            // This avoid sending the ring tone or music tail into the earpiece or headset.
+            if ((desc->isStrategyActive(STRATEGY_MEDIA,
+                                     SONIFICATION_HEADSET_MUSIC_DELAY,
+                                     sysTime) ||
+                    desc->isStrategyActive(STRATEGY_SONIFICATION,
+                                         SONIFICATION_HEADSET_MUSIC_DELAY,
+                                         sysTime)) &&
+                    (delayMs < (int)desc->mLatency*2)) {
+                delayMs = desc->mLatency*2;
+            }
+            setStrategyMute(STRATEGY_MEDIA, true, mOutputs.keyAt(i));
+            setStrategyMute(STRATEGY_MEDIA, false, mOutputs.keyAt(i), MUTE_TIME_MS,
+                getDeviceForStrategy(STRATEGY_MEDIA, true /*fromCache*/));
+            setStrategyMute(STRATEGY_SONIFICATION, true, mOutputs.keyAt(i));
+            setStrategyMute(STRATEGY_SONIFICATION, false, mOutputs.keyAt(i), MUTE_TIME_MS,
+                getDeviceForStrategy(STRATEGY_SONIFICATION, true /*fromCache*/));
+        }
+    }
+
+    // change routing is necessary
+    setOutputDevice(mPrimaryOutput, newDevice, force, delayMs);
+
+    // if entering in call state, handle special case of active streams
+    // pertaining to sonification strategy see handleIncallSonification()
+    if (isStateInCall(state)) {
+        ALOGV("setPhoneState() in call state management: new state is %d", state);
+        for (int stream = 0; stream < AudioSystem::NUM_STREAM_TYPES; stream++) {
+            handleIncallSonification(stream, true, true);
+        }
+    }
+
+    // Flag that ringtone volume must be limited to music volume until we exit MODE_RINGTONE
+    if (state == AudioSystem::MODE_RINGTONE &&
+        isStreamActive(AudioSystem::MUSIC, SONIFICATION_HEADSET_MUSIC_DELAY)) {
+        mLimitRingtoneVolume = true;
+    } else {
+        mLimitRingtoneVolume = false;
+    }
+
+#ifdef VOICE_CONCURRENCY
+    //Call invalidate to reset all opened non ULL audio tracks
+    if(isInCall())
+    {
+        // Move tracks associated to this strategy from previous output to new output
+        for (int i = AudioSystem::SYSTEM; i < (int)AudioSystem::NUM_STREAM_TYPES; i++) {
+                ALOGV("\n Invalidate on call mode for stream :: %d  \n", i);
+                //FIXME see fixme on name change
+                mpClientInterface->setStreamOutput((AudioSystem::stream_type)i,
+                                                  0 /* ignored */);
+        }
+    }
+#endif
+
+}
+
 extern "C" AudioPolicyInterface* createAudioPolicyManager(AudioPolicyClientInterface *clientInterface)
 {
     return new AudioPolicyManager(clientInterface);
diff --git a/policy_hal/AudioPolicyManager.h b/policy_hal/AudioPolicyManager.h
index 7a8cfa9..34ca701 100644
--- a/policy_hal/AudioPolicyManager.h
+++ b/policy_hal/AudioPolicyManager.h
@@ -48,6 +48,17 @@
                                             uint32_t format,
                                             uint32_t channels,
                                             AudioSystem::audio_in_acoustics acoustics);
+        virtual audio_io_handle_t getOutput(AudioSystem::stream_type stream,
+                                            uint32_t samplingRate = 0,
+                                            uint32_t format = AudioSystem::FORMAT_DEFAULT,
+                                            uint32_t channels = 0,
+                                            AudioSystem::output_flags flags =
+                                                    AudioSystem::OUTPUT_FLAG_INDIRECT,
+                                            const audio_offload_info_t *offloadInfo = NULL);
+
+        virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
+
+        virtual void setPhoneState(int state);
 protected:
         // return the strategy corresponding to a given stream type
         static routing_strategy getStrategy(AudioSystem::stream_type stream);
diff --git a/post_proc/bass_boost.c b/post_proc/bass_boost.c
index c64ba6b..c724b58 100644
--- a/post_proc/bass_boost.c
+++ b/post_proc/bass_boost.c
@@ -239,6 +239,11 @@
     ALOGV("%s", __func__);
     bass_ctxt->ctl = output->ctl;
     ALOGV("output->ctl: %p", output->ctl);
+    if (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass)))
+        if (bass_ctxt->ctl)
+            offload_bassboost_send_params(bass_ctxt->ctl, bass_ctxt->offload_bass,
+                                          OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG |
+                                          OFFLOAD_SEND_BASSBOOST_STRENGTH);
     return 0;
 }
 
diff --git a/post_proc/equalizer.c b/post_proc/equalizer.c
index e31d2b9..7c7ced2 100644
--- a/post_proc/equalizer.c
+++ b/post_proc/equalizer.c
@@ -491,6 +491,11 @@
 
     ALOGV("%s: %p", __func__, output->ctl);
     eq_ctxt->ctl = output->ctl;
+    if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq)))
+        if (eq_ctxt->ctl)
+            offload_eq_send_params(eq_ctxt->ctl, eq_ctxt->offload_eq,
+                                   OFFLOAD_SEND_EQ_ENABLE_FLAG |
+                                   OFFLOAD_SEND_EQ_BANDS_LEVEL);
     return 0;
 }
 
diff --git a/post_proc/reverb.c b/post_proc/reverb.c
index 4fc8c83..d104073 100644
--- a/post_proc/reverb.c
+++ b/post_proc/reverb.c
@@ -236,9 +236,14 @@
 
 void reverb_set_preset(reverb_context_t *context, int16_t preset)
 {
+    bool enable;
     ALOGV("%s: preset: %d", __func__, preset);
     context->next_preset = preset;
     offload_reverb_set_preset(&(context->offload_reverb), preset);
+
+    enable = (preset == REVERB_PRESET_NONE) ? false: true;
+    offload_reverb_set_enable_flag(&(context->offload_reverb), enable);
+
     if (context->ctl)
         offload_reverb_send_params(context->ctl, context->offload_reverb,
                                    OFFLOAD_SEND_REVERB_ENABLE_FLAG |
diff --git a/post_proc/virtualizer.c b/post_proc/virtualizer.c
index 2f0ca6b..e9eb728 100644
--- a/post_proc/virtualizer.c
+++ b/post_proc/virtualizer.c
@@ -237,6 +237,11 @@
 
     ALOGV("%s", __func__);
     virt_ctxt->ctl = output->ctl;
+    if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)))
+        if (virt_ctxt->ctl)
+            offload_virtualizer_send_params(virt_ctxt->ctl, virt_ctxt->offload_virt,
+                                          OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG |
+                                          OFFLOAD_SEND_VIRTUALIZER_STRENGTH);
     return 0;
 }