Merge "mm-audio: aenc: timestamp fixes"
diff --git a/audiod/AudioDaemon.cpp b/audiod/AudioDaemon.cpp
index 6c8d991..6105635 100644
--- a/audiod/AudioDaemon.cpp
+++ b/audiod/AudioDaemon.cpp
@@ -48,7 +48,7 @@
 
     void AudioDaemon::onFirstRef() {
         ALOGV("Start audiod daemon");
-        run("AudioDaemon", PRIORITY_AUDIO);
+        run("AudioDaemon", PRIORITY_URGENT_AUDIO);
     }
 
     void AudioDaemon::binderDied(const wp<IBinder>& who)
diff --git a/hal/Android.mk b/hal/Android.mk
index c4534b6..d4862f2 100644
--- a/hal/Android.mk
+++ b/hal/Android.mk
@@ -129,6 +129,12 @@
 	$(LOCAL_PATH)/audio_extn \
 	$(LOCAL_PATH)/voice_extn
 
+ifneq ($(filter msm8974,$(AUDIO_PLATFORM)),)
+    LOCAL_C_INCLUDES += external/expat/lib
+    LOCAL_SHARED_LIBRARIES += libexpat
+    LOCAL_SRC_FILES += $(AUDIO_PLATFORM)/platform_parser.c
+endif
+
 ifeq ($(strip $(AUDIO_FEATURE_ENABLED_LISTEN)),true)
     LOCAL_CFLAGS += -DAUDIO_LISTEN_ENABLED
     LOCAL_C_INCLUDES += $(TARGET_OUT_HEADERS)/mm-audio/audio-listen
diff --git a/hal/audio_extn/audio_extn.c b/hal/audio_extn/audio_extn.c
index b641bdb..06bcac8 100644
--- a/hal/audio_extn/audio_extn.c
+++ b/hal/audio_extn/audio_extn.c
@@ -56,7 +56,7 @@
                                    struct str_parms *parms);
 #endif
 #ifndef HFP_ENABLED
-void audio_extn_hfp_set_parameters(adev, parms) (0)
+#define audio_extn_hfp_set_parameters(adev, parms) (0)
 #else
 void audio_extn_hfp_set_parameters(struct audio_device *adev,
                                            struct str_parms *parms);
diff --git a/hal/audio_extn/fm.c b/hal/audio_extn/fm.c
index a4157f8..8a420bd 100644
--- a/hal/audio_extn/fm.c
+++ b/hal/audio_extn/fm.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
@@ -123,11 +123,11 @@
     }
 
     /* 2. Get and set stream specific mixer controls */
-    disable_audio_route(adev, uc_info, true);
+    disable_audio_route(adev, uc_info);
 
     /* 3. Disable the rx and tx devices */
-    disable_snd_device(adev, uc_info->out_snd_device, false);
-    disable_snd_device(adev, uc_info->in_snd_device, true);
+    disable_snd_device(adev, uc_info->out_snd_device);
+    disable_snd_device(adev, uc_info->in_snd_device);
 
     list_remove(&uc_info->list);
     free(uc_info);
@@ -230,9 +230,10 @@
         ALOGD("%s: FM usecase", __func__);
         if (val != 0) {
             if(val & AUDIO_DEVICE_OUT_FM
-               && fmmod.is_fm_running == false)
+               && fmmod.is_fm_running == false) {
+                adev->primary_output->devices = val & ~AUDIO_DEVICE_OUT_FM;
                 fm_start(adev);
-            else if (!(val & AUDIO_DEVICE_OUT_FM)
+            } else if (!(val & AUDIO_DEVICE_OUT_FM)
                      && fmmod.is_fm_running == true)
                 fm_stop(adev);
        }
diff --git a/hal/audio_extn/hfp.c b/hal/audio_extn/hfp.c
index 57d1f0c..add4a7c 100644
--- a/hal/audio_extn/hfp.c
+++ b/hal/audio_extn/hfp.c
@@ -245,11 +245,11 @@
     }
 
     /* 2. Get and set stream specific mixer controls */
-    disable_audio_route(adev, uc_info, true);
+    disable_audio_route(adev, uc_info);
 
     /* 3. Disable the rx and tx devices */
-    disable_snd_device(adev, uc_info->out_snd_device, false);
-    disable_snd_device(adev, uc_info->in_snd_device, true);
+    disable_snd_device(adev, uc_info->out_snd_device);
+    disable_snd_device(adev, uc_info->in_snd_device);
 
     list_remove(&uc_info->list);
     free(uc_info);
diff --git a/hal/audio_extn/spkr_protection.c b/hal/audio_extn/spkr_protection.c
index 6c0eec0..0c131cd 100644
--- a/hal/audio_extn/spkr_protection.c
+++ b/hal/audio_extn/spkr_protection.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-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
@@ -227,8 +227,8 @@
     uc_info_rx->out_snd_device = SND_DEVICE_OUT_SPEAKER_PROTECTED;
     pthread_mutex_lock(&adev->lock);
     disable_rx = true;
-    enable_snd_device(adev, SND_DEVICE_OUT_SPEAKER_PROTECTED, true);
-    enable_audio_route(adev, uc_info_rx, true);
+    enable_snd_device(adev, SND_DEVICE_OUT_SPEAKER_PROTECTED);
+    enable_audio_route(adev, uc_info_rx);
     pthread_mutex_unlock(&adev->lock);
 
     pcm_dev_rx_id = platform_get_pcm_device_id(uc_info_rx->id, PCM_PLAYBACK);
@@ -257,8 +257,8 @@
 
     pthread_mutex_lock(&adev->lock);
     disable_tx = true;
-    enable_snd_device(adev, SND_DEVICE_IN_CAPTURE_VI_FEEDBACK, true);
-    enable_audio_route(adev, uc_info_tx, true);
+    enable_snd_device(adev, SND_DEVICE_IN_CAPTURE_VI_FEEDBACK);
+    enable_audio_route(adev, uc_info_tx);
     pthread_mutex_unlock(&adev->lock);
 
     pcm_dev_tx_id = platform_get_pcm_device_id(uc_info_tx->id, PCM_CAPTURE);
@@ -336,12 +336,12 @@
         handle.pcm_tx = NULL;
         pthread_mutex_lock(&adev->lock);
         if (disable_rx) {
-            disable_snd_device(adev, SND_DEVICE_OUT_SPEAKER_PROTECTED, true);
-            disable_audio_route(adev, uc_info_rx, true);
+            disable_snd_device(adev, SND_DEVICE_OUT_SPEAKER_PROTECTED);
+            disable_audio_route(adev, uc_info_rx);
         }
         if (disable_tx) {
-            disable_snd_device(adev, SND_DEVICE_IN_CAPTURE_VI_FEEDBACK, true);
-            disable_audio_route(adev, uc_info_tx, true);
+            disable_snd_device(adev, SND_DEVICE_IN_CAPTURE_VI_FEEDBACK);
+            disable_audio_route(adev, uc_info_tx);
         }
         pthread_mutex_unlock(&adev->lock);
 
@@ -468,8 +468,11 @@
             }
             goahead = true;
         }
-        if (!list_empty(&adev->usecase_list))
+        if (!list_empty(&adev->usecase_list)) {
+            ALOGD("%s: Usecase active re-try calibration", __func__);
             goahead = false;
+            pthread_mutex_unlock(&handle.mutex_spkr_prot);
+        }
         if (goahead) {
                 int status;
                 status = spkr_calibrate(t0);
@@ -598,7 +601,7 @@
     }
     ALOGV("%s: snd_device(%d: %s)", __func__, snd_device,
          platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_PROTECTED));
-    audio_route_apply_path(adev->audio_route,
+    audio_route_apply_and_update_path(adev->audio_route,
         platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_PROTECTED));
 
     pthread_mutex_lock(&handle.mutex_spkr_prot);
@@ -610,8 +613,8 @@
         uc_info_tx.out_snd_device = SND_DEVICE_NONE;
         handle.pcm_tx = NULL;
 
-        enable_snd_device(adev, SND_DEVICE_IN_CAPTURE_VI_FEEDBACK, true);
-        enable_audio_route(adev, &uc_info_tx, true);
+        enable_snd_device(adev, SND_DEVICE_IN_CAPTURE_VI_FEEDBACK);
+        enable_audio_route(adev, &uc_info_tx);
 
         pcm_dev_tx_id = platform_get_pcm_device_id(uc_info_tx.id, PCM_CAPTURE);
         if (pcm_dev_tx_id < 0) {
@@ -642,8 +645,8 @@
         if (handle.pcm_tx)
             pcm_close(handle.pcm_tx);
         handle.pcm_tx = NULL;
-        disable_snd_device(adev, SND_DEVICE_IN_CAPTURE_VI_FEEDBACK, true);
-        disable_audio_route(adev, &uc_info_tx, true);
+        disable_snd_device(adev, SND_DEVICE_IN_CAPTURE_VI_FEEDBACK);
+        disable_audio_route(adev, &uc_info_tx);
     } else
         handle.spkr_processing_state = SPKR_PROCESSING_IN_PROGRESS;
     pthread_mutex_unlock(&handle.mutex_spkr_prot);
@@ -667,12 +670,12 @@
         if (handle.pcm_tx)
             pcm_close(handle.pcm_tx);
         handle.pcm_tx = NULL;
-        disable_snd_device(adev, SND_DEVICE_IN_CAPTURE_VI_FEEDBACK, true);
-        disable_audio_route(adev, &uc_info_tx, true);
+        disable_snd_device(adev, SND_DEVICE_IN_CAPTURE_VI_FEEDBACK);
+        disable_audio_route(adev, &uc_info_tx);
     }
     handle.spkr_processing_state = SPKR_PROCESSING_IN_IDLE;
     pthread_mutex_unlock(&handle.mutex_spkr_prot);
-    audio_route_reset_path(adev->audio_route,
+    audio_route_reset_and_update_path(adev->audio_route,
       platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_PROTECTED));
     ALOGV("%s: Exit", __func__);
 }
diff --git a/hal/audio_extn/usb.c b/hal/audio_extn/usb.c
index 281b445..0240d7c 100644
--- a/hal/audio_extn/usb.c
+++ b/hal/audio_extn/usb.c
@@ -580,6 +580,11 @@
     usbmod->proxy_card = 0;
     usbmod->proxy_device_id = AFE_PROXY_PLAYBACK_DEVICE;
     usbmod->adev = (struct audio_device*)adev;
+
+     pthread_mutex_init(&usbmod->usb_playback_lock,
+                        (const pthread_mutexattr_t *) NULL);
+     pthread_mutex_init(&usbmod->usb_record_lock,
+                        (const pthread_mutexattr_t *) NULL);
 }
 
 void audio_extn_usb_deinit()
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index c0d47d9..93db127 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -215,8 +215,7 @@
 }
 
 int enable_audio_route(struct audio_device *adev,
-                              struct audio_usecase *usecase,
-                              bool update_mixer)
+                       struct audio_usecase *usecase)
 {
     snd_device_t snd_device;
     char mixer_path[MIXER_PATH_MAX_LENGTH];
@@ -237,18 +236,14 @@
 #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);
-    audio_route_apply_path(adev->audio_route, mixer_path);
-    if (update_mixer)
-        audio_route_update_mixer(adev->audio_route);
-
+    ALOGV("%s: apply mixer and update path: %s", __func__, mixer_path);
+    audio_route_apply_and_update_path(adev->audio_route, mixer_path);
     ALOGV("%s: exit", __func__);
     return 0;
 }
 
 int disable_audio_route(struct audio_device *adev,
-                        struct audio_usecase *usecase,
-                        bool update_mixer)
+                        struct audio_usecase *usecase)
 {
     snd_device_t snd_device;
     char mixer_path[MIXER_PATH_MAX_LENGTH];
@@ -263,18 +258,14 @@
         snd_device = usecase->out_snd_device;
     strcpy(mixer_path, use_case_table[usecase->id]);
     platform_add_backend_name(mixer_path, snd_device);
-    ALOGV("%s: reset mixer path: %s", __func__, mixer_path);
-    audio_route_reset_path(adev->audio_route, mixer_path);
-    if (update_mixer)
-        audio_route_update_mixer(adev->audio_route);
-
+    ALOGV("%s: reset and update mixer path: %s", __func__, mixer_path);
+    audio_route_reset_and_update_path(adev->audio_route, mixer_path);
     ALOGV("%s: exit", __func__);
     return 0;
 }
 
 int enable_snd_device(struct audio_device *adev,
-                             snd_device_t snd_device,
-                             bool update_mixer)
+                      snd_device_t snd_device)
 {
     char device_name[DEVICE_NAME_MAX_SIZE] = {0};
 
@@ -321,17 +312,13 @@
         audio_extn_listen_update_status(snd_device,
                 LISTEN_EVENT_SND_DEVICE_BUSY);
 
-        audio_route_apply_path(adev->audio_route, device_name);
+        audio_route_apply_and_update_path(adev->audio_route, device_name);
     }
-    if (update_mixer)
-        audio_route_update_mixer(adev->audio_route);
-
     return 0;
 }
 
 int disable_snd_device(struct audio_device *adev,
-                       snd_device_t snd_device,
-                       bool update_mixer)
+                       snd_device_t snd_device)
 {
     char device_name[DEVICE_NAME_MAX_SIZE] = {0};
 
@@ -368,10 +355,7 @@
             audio_extn_spkr_prot_is_enabled()) {
             audio_extn_spkr_prot_stop_processing();
         } else
-            audio_route_reset_path(adev->audio_route, device_name);
-
-        if (update_mixer)
-            audio_route_update_mixer(adev->audio_route);
+            audio_route_reset_and_update_path(adev->audio_route, device_name);
 
         audio_extn_listen_update_status(snd_device,
                                         LISTEN_EVENT_SND_DEVICE_FREE);
@@ -413,33 +397,29 @@
             ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..",
                   __func__, use_case_table[usecase->id],
                   platform_get_snd_device_name(usecase->out_snd_device));
-            disable_audio_route(adev, usecase, false);
+            disable_audio_route(adev, usecase);
             switch_device[usecase->id] = true;
             num_uc_to_switch++;
         }
     }
 
     if (num_uc_to_switch) {
-        /* Make sure all the streams are de-routed before disabling the device */
-        audio_route_update_mixer(adev->audio_route);
+        /* All streams have been de-routed. Disable the device */
 
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
             if (switch_device[usecase->id]) {
-                disable_snd_device(adev, usecase->out_snd_device, false);
+                disable_snd_device(adev, usecase->out_snd_device);
             }
         }
 
         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, false);
+                enable_snd_device(adev, snd_device);
             }
         }
 
-        /* Make sure new snd device is enabled before re-routing the streams */
-        audio_route_update_mixer(adev->audio_route);
-
         /* Re-route all the usecases on the shared backend other than the
            specified usecase to new snd devices */
         list_for_each(node, &adev->usecase_list) {
@@ -447,7 +427,7 @@
             /* Update the out_snd_device only before enabling the audio route */
             if (switch_device[usecase->id] ) {
                 usecase->out_snd_device = snd_device;
-                enable_audio_route(adev, usecase, false);
+                enable_audio_route(adev, usecase);
             }
         }
     }
@@ -483,33 +463,29 @@
             ALOGV("%s: Usecase (%s) is active on (%s) - disabling ..",
                   __func__, use_case_table[usecase->id],
                   platform_get_snd_device_name(usecase->in_snd_device));
-            disable_audio_route(adev, usecase, false);
+            disable_audio_route(adev, usecase);
             switch_device[usecase->id] = true;
             num_uc_to_switch++;
         }
     }
 
     if (num_uc_to_switch) {
-        /* Make sure all the streams are de-routed before disabling the device */
-        audio_route_update_mixer(adev->audio_route);
+        /* All streams have been de-routed. Disable the device */
 
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
             if (switch_device[usecase->id]) {
-                disable_snd_device(adev, usecase->in_snd_device, false);
+                disable_snd_device(adev, usecase->in_snd_device);
             }
         }
 
         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, false);
+                enable_snd_device(adev, snd_device);
             }
         }
 
-        /* Make sure new snd device is enabled before re-routing the streams */
-        audio_route_update_mixer(adev->audio_route);
-
         /* Re-route all the usecases on the shared backend other than the
            specified usecase to new snd devices */
         list_for_each(node, &adev->usecase_list) {
@@ -517,7 +493,7 @@
             /* Update the in_snd_device only before enabling the audio route */
             if (switch_device[usecase->id] ) {
                 usecase->in_snd_device = snd_device;
-                enable_audio_route(adev, usecase, false);
+                enable_audio_route(adev, usecase);
             }
         }
     }
@@ -623,7 +599,8 @@
             }
         } else if (voice_extn_compress_voip_is_active(adev)) {
             voip_usecase = get_usecase_from_list(adev, USECASE_COMPRESS_VOIP_CALL);
-            if (voip_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) {
+            if ((voip_usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND) &&
+                (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND)) {
                     in_snd_device = voip_usecase->in_snd_device;
                     out_snd_device = voip_usecase->out_snd_device;
             }
@@ -689,25 +666,25 @@
 
     /* Disable current sound devices */
     if (usecase->out_snd_device != SND_DEVICE_NONE) {
-        disable_audio_route(adev, usecase, true);
-        disable_snd_device(adev, usecase->out_snd_device, false);
+        disable_audio_route(adev, usecase);
+        disable_snd_device(adev, usecase->out_snd_device);
     }
 
     if (usecase->in_snd_device != SND_DEVICE_NONE) {
-        disable_audio_route(adev, usecase, true);
-        disable_snd_device(adev, usecase->in_snd_device, false);
+        disable_audio_route(adev, usecase);
+        disable_snd_device(adev, usecase->in_snd_device);
     }
 
     /* Enable new sound devices */
     if (out_snd_device != SND_DEVICE_NONE) {
         if (usecase->devices & AUDIO_DEVICE_OUT_ALL_CODEC_BACKEND)
             check_usecases_codec_backend(adev, usecase, out_snd_device);
-        enable_snd_device(adev, out_snd_device, false);
+        enable_snd_device(adev, out_snd_device);
     }
 
     if (in_snd_device != SND_DEVICE_NONE) {
         check_and_route_capture_usecases(adev, usecase, in_snd_device);
-        enable_snd_device(adev, in_snd_device, false);
+        enable_snd_device(adev, in_snd_device);
     }
 
     if (usecase->type == VOICE_CALL || usecase->type == VOIP_CALL)
@@ -715,12 +692,10 @@
                                                         out_snd_device,
                                                         in_snd_device);
 
-    audio_route_update_mixer(adev->audio_route);
-
     usecase->in_snd_device = in_snd_device;
     usecase->out_snd_device = out_snd_device;
 
-    enable_audio_route(adev, usecase, true);
+    enable_audio_route(adev, usecase);
 
     /* Applicable only on the targets that has external modem.
      * Enable device command should be sent to modem only after
@@ -731,6 +706,8 @@
                                                                out_snd_device,
                                                                in_snd_device);
 
+    ALOGD("%s: done",__func__);
+
     return status;
 }
 
@@ -755,10 +732,10 @@
     voice_check_and_stop_incall_rec_usecase(adev, in);
 
     /* 1. Disable stream specific mixer controls */
-    disable_audio_route(adev, uc_info, true);
+    disable_audio_route(adev, uc_info);
 
     /* 2. Disable the tx device */
-    disable_snd_device(adev, uc_info->in_snd_device, true);
+    disable_snd_device(adev, uc_info->in_snd_device);
 
     list_remove(&uc_info->list);
     free(uc_info);
@@ -775,7 +752,8 @@
     struct audio_device *adev = in->dev;
 
     in->usecase = platform_update_usecase_from_source(in->source,in->usecase);
-    ALOGV("%s: enter: usecase(%d)", __func__, in->usecase);
+    ALOGD("%s: enter: stream(%p)usecase(%d: %s)",
+          __func__, &in->stream, in->usecase, use_case_table[in->usecase]);
 
     /* Check if source matches incall recording usecase criteria */
     ret = voice_check_and_set_incall_rec_usecase(adev, in);
@@ -1036,7 +1014,7 @@
         usecase = node_to_item(node, struct audio_usecase, list);
         if (usecase->type == PCM_PLAYBACK &&
                 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
-            disable_audio_route(adev, usecase, true);
+            disable_audio_route(adev, usecase);
         }
     }
 
@@ -1048,7 +1026,7 @@
         usecase = node_to_item(node, struct audio_usecase, list);
         if (usecase->type == PCM_PLAYBACK &&
                 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
-            enable_audio_route(adev, usecase, true);
+            enable_audio_route(adev, usecase);
         }
     }
 
@@ -1078,10 +1056,10 @@
     }
 
     /* 1. Get and set stream specific mixer controls */
-    disable_audio_route(adev, uc_info, true);
+    disable_audio_route(adev, uc_info);
 
     /* 2. Disable the rx device */
-    disable_snd_device(adev, uc_info->out_snd_device, true);
+    disable_snd_device(adev, uc_info->out_snd_device);
 
     list_remove(&uc_info->list);
     free(uc_info);
@@ -1097,11 +1075,14 @@
 int start_output_stream(struct stream_out *out)
 {
     int ret = 0;
+    int sink_channels = 0;
+    char prop_value[PROPERTY_VALUE_MAX] = {0};
     struct audio_usecase *uc_info;
     struct audio_device *adev = out->dev;
 
-    ALOGV("%s: enter: usecase(%d: %s) devices(%#x)",
-          __func__, out->usecase, use_case_table[out->usecase], out->devices);
+    ALOGD("%s: enter: stream(%p)usecase(%d: %s) devices(%#x)",
+          __func__, &out->stream, out->usecase, use_case_table[out->usecase],
+          out->devices);
     out->pcm_device_id = platform_get_pcm_device_id(out->usecase, PCM_PLAYBACK);
     if (out->pcm_device_id < 0) {
         ALOGE("%s: Invalid PCM device id(%d) for the usecase(%d)",
@@ -1120,10 +1101,17 @@
 
     /* This must be called before adding this usecase to the list */
     if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
-        if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD)
-            check_and_set_hdmi_channels(adev, out->compr_config.codec->ch_in);
-        else
-            check_and_set_hdmi_channels(adev, out->config.channels);
+        property_get("audio.use.hdmi.sink.cap", prop_value, NULL);
+        if (!strncmp("true", prop_value, 4)) {
+            sink_channels = platform_edid_get_max_channels(out->dev->platform);
+            ALOGD("%s: set HDMI channel count[%d] based on sink capability", __func__, sink_channels);
+            check_and_set_hdmi_channels(adev, sink_channels);
+        } else {
+            if (out->usecase == USECASE_AUDIO_PLAYBACK_OFFLOAD)
+                check_and_set_hdmi_channels(adev, out->compr_config.codec->ch_in);
+            else
+                check_and_set_hdmi_channels(adev, out->config.channels);
+        }
     }
 
     list_add_tail(&adev->usecase_list, &uc_info->list);
@@ -1282,13 +1270,13 @@
     struct stream_out *out = (struct stream_out *)stream;
     struct audio_device *adev = out->dev;
 
-    ALOGV("%s: enter: usecase(%d: %s)", __func__,
-          out->usecase, use_case_table[out->usecase]);
+    ALOGD("%s: enter: stream (%p) usecase(%d: %s)", __func__,
+          stream, out->usecase, use_case_table[out->usecase]);
     if (out->usecase == USECASE_COMPRESS_VOIP_CALL) {
         /* Ignore standby in case of voip call because the voip output
          * stream is closed in adev_close_output_stream()
          */
-        ALOGV("%s: Ignore Standby in VOIP call", __func__);
+        ALOGD("%s: Ignore Standby in VOIP call", __func__);
         return 0;
     }
 
@@ -1400,13 +1388,14 @@
         pthread_mutex_lock(&adev->lock);
 
         /*
-         * When HDMI cable is unplugged the music playback is paused and
-         * the policy manager sends routing=0. But the audioflinger
-         * continues to write data until standby time (3sec).
-         * As the HDMI core is turned off, the write gets blocked.
+         * When HDMI cable is unplugged/usb hs is disconnected the
+         * music playback is paused and the policy manager sends routing=0
+         * But the audioflingercontinues to write data until standby time
+         * (3sec). As the HDMI core is turned off, the write gets blocked.
          * Avoid this by routing audio to speaker until standby.
          */
-        if (out->devices == AUDIO_DEVICE_OUT_AUX_DIGITAL &&
+        if ((out->devices == AUDIO_DEVICE_OUT_AUX_DIGITAL ||
+                out->devices == AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET) &&
                 val == AUDIO_DEVICE_NONE) {
             val = AUDIO_DEVICE_OUT_SPEAKER;
         }
@@ -1832,7 +1821,9 @@
     struct stream_in *in = (struct stream_in *)stream;
     struct audio_device *adev = in->dev;
     int status = 0;
-    ALOGV("%s: enter", __func__);
+    ALOGD("%s: enter: stream (%p) usecase(%d: %s)", __func__,
+          stream, in->usecase, use_case_table[in->usecase]);
+
 
     if (in->usecase == USECASE_COMPRESS_VOIP_CALL) {
         /* Ignore standby in case of voip call because the voip input
@@ -1872,7 +1863,7 @@
     char value[32];
     int ret = 0, val = 0, err;
 
-    ALOGV("%s: enter: kvpairs=%s", __func__, kvpairs);
+    ALOGD("%s: enter: kvpairs=%s", __func__, kvpairs);
     parms = str_parms_create_str(kvpairs);
 
     pthread_mutex_lock(&in->lock);
@@ -1977,7 +1968,7 @@
      * Instead of writing zeroes here, we could trust the hardware
      * to always provide zeroes when muted.
      */
-    if (ret == 0 && voice_get_mic_mute(adev) && !voice_is_in_call(adev))
+    if (ret == 0 && voice_get_mic_mute(adev) && !voice_is_in_call_rec_stream(in))
         memset(buffer, 0, bytes);
 
 exit:
@@ -2055,11 +2046,14 @@
     struct stream_out *out;
     int i, ret = 0;
 
-    ALOGV("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)",
-          __func__, config->sample_rate, config->channel_mask, devices, flags);
     *stream_out = NULL;
     out = (struct stream_out *)calloc(1, sizeof(struct stream_out));
 
+    ALOGD("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x) flags(%#x)\
+        stream_handle(%p)",__func__, config->sample_rate, config->channel_mask,
+        devices, flags, &out->stream);
+
+
     if (!out) {
         return -ENOMEM;
     }
@@ -2224,7 +2218,8 @@
 
     /* Check if this usecase is already existing */
     pthread_mutex_lock(&adev->lock);
-    if (get_usecase_from_list(adev, out->usecase) != NULL) {
+    if ((get_usecase_from_list(adev, out->usecase) != NULL) &&
+        (out->usecase != USECASE_COMPRESS_VOIP_CALL)) {
         ALOGE("%s: Usecase (%d) is already present", __func__, out->usecase);
         pthread_mutex_unlock(&adev->lock);
         ret = -EEXIST;
@@ -2260,6 +2255,8 @@
     config->sample_rate = out->stream.common.get_sample_rate(&out->stream.common);
 
     *stream_out = &out->stream;
+    ALOGD("%s: Stream (%p) picks up usecase (%s)", __func__, &out->stream,
+        use_case_table[out->usecase]);
     ALOGV("%s: exit", __func__);
     return 0;
 
@@ -2277,7 +2274,8 @@
     struct audio_device *adev = out->dev;
     int ret = 0;
 
-    ALOGV("%s: enter", __func__);
+    ALOGD("%s: enter:stream_handle(%p)",__func__, out);
+
     if (out->usecase == USECASE_COMPRESS_VOIP_CALL) {
         ret = voice_extn_compress_voip_close_output_stream(&stream->common);
         if(ret != 0)
@@ -2489,12 +2487,17 @@
     int ret = 0, buffer_size, frame_size;
     int channel_count = popcount(config->channel_mask);
 
-    ALOGV("%s: enter", __func__);
+
     *stream_in = NULL;
     if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0)
         return -EINVAL;
 
     in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
+    ALOGD("%s: enter: sample_rate(%d) channel_mask(%#x) devices(%#x)\
+        stream_handle(%p)",__func__, config->sample_rate, config->channel_mask,
+        devices, &in->stream);
+
+    pthread_mutex_init(&in->lock, (const pthread_mutexattr_t *) NULL);
 
     in->stream.common.get_sample_rate = in_get_sample_rate;
     in->stream.common.set_sample_rate = in_set_sample_rate;
@@ -2563,7 +2566,7 @@
 {
     int ret;
     struct stream_in *in = (struct stream_in *)stream;
-    ALOGV("%s", __func__);
+    ALOGD("%s: enter:stream_handle(%p)",__func__, in);
 
     if (in->usecase == USECASE_COMPRESS_VOIP_CALL) {
         ret = voice_extn_compress_voip_close_input_stream(&stream->common);
@@ -2630,6 +2633,8 @@
 
     adev = calloc(1, sizeof(struct audio_device));
 
+    pthread_mutex_init(&adev->lock, (const pthread_mutexattr_t *) NULL);
+
     adev->device.common.tag = HARDWARE_DEVICE_TAG;
     adev->device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
     adev->device.common.module = (struct hw_module_t *)module;
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index e1172ef..e6ec012 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -242,17 +242,15 @@
 int select_devices(struct audio_device *adev,
                           audio_usecase_t uc_id);
 int disable_audio_route(struct audio_device *adev,
-                               struct audio_usecase *usecase,
-                               bool update_mixer);
+                        struct audio_usecase *usecase);
 int disable_snd_device(struct audio_device *adev,
-                              snd_device_t snd_device,
-                              bool update_mixer);
+                       snd_device_t snd_device);
 int enable_snd_device(struct audio_device *adev,
-                             snd_device_t snd_device,
-                             bool update_mixer);
+                      snd_device_t snd_device);
+
 int enable_audio_route(struct audio_device *adev,
-                              struct audio_usecase *usecase,
-                              bool update_mixer);
+                       struct audio_usecase *usecase);
+
 struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
                                                    audio_usecase_t uc_id);
 
diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c
index dacf68e..bbf85b0 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
@@ -193,20 +193,14 @@
 #define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
 #define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
 
-static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
+static void set_echo_reference(struct audio_device *adev, bool enable)
 {
-    struct mixer_ctl *ctl;
-    const char *mixer_ctl_name = "EC_REF_RX";
+    if (enable)
+        audio_route_apply_and_update_path(adev->audio_route, "echo-reference");
+    else
+        audio_route_reset_and_update_path(adev->audio_route, "echo-reference");
 
-    ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
-    if (!ctl) {
-        ALOGE("%s: Could not get ctl for mixer cmd - %s",
-              __func__, mixer_ctl_name);
-        return -EINVAL;
-    }
-    ALOGV("Setting EC Reference: %s", ec_ref);
-    mixer_ctl_set_enum_by_string(ctl, ec_ref);
-    return 0;
+    ALOGV("Setting EC Reference: %d", enable);
 }
 
 void *platform_init(struct audio_device *adev)
@@ -391,6 +385,11 @@
     return device_id;
 }
 
+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;
@@ -738,9 +737,9 @@
                 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
                     snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
                 }
-                set_echo_reference(adev->mixer, "SLIM_RX");
+                set_echo_reference(adev, true);
             } else
-                set_echo_reference(adev->mixer, "NONE");
+                set_echo_reference(adev, false);
         }
     } else if (source == AUDIO_SOURCE_DEFAULT) {
         goto exit;
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 3ade91f..629bd8c 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -32,6 +32,7 @@
 #include "audio_extn.h"
 #include "voice_extn.h"
 #include "sound/compress_params.h"
+#include "platform_parser.h"
 
 #define MIXER_XML_PATH "/system/etc/mixer_paths.xml"
 #define MIXER_XML_PATH_AUXPCM "/system/etc/mixer_paths_auxpcm.xml"
@@ -44,15 +45,15 @@
 #define COMPRESS_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
 
 /* Used in calculating fragment size for pcm offload */
-#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV 2000 /* 2 secs */
-#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING 100 /* 100 millisecs */
+#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV 1000 /* 1 sec */
+#define PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING 80 /* 80 millisecs */
 
 /* MAX PCM fragment size cannot be increased  further due
  * to flinger's cblk size of 1mb,and it has to be a multiple of
  * 24 - lcm of channels supported by DSP
  */
 #define MAX_PCM_OFFLOAD_FRAGMENT_SIZE (240 * 1024)
-#define MIN_PCM_OFFLOAD_FRAGMENT_SIZE (32 * 1024)
+#define MIN_PCM_OFFLOAD_FRAGMENT_SIZE (4 * 1024)
 
 #define ALIGN( num, to ) (((num) + (to-1)) & (~(to-1)))
 /*
@@ -242,7 +243,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,
@@ -317,20 +318,14 @@
 #define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
 #define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
 
-static int set_echo_reference(struct mixer *mixer, const char* ec_ref)
+static void set_echo_reference(struct audio_device *adev, bool enable)
 {
-    struct mixer_ctl *ctl;
-    const char *mixer_ctl_name = "EC_REF_RX";
+    if (enable)
+        audio_route_apply_and_update_path(adev->audio_route, "echo-reference");
+    else
+        audio_route_reset_and_update_path(adev->audio_route, "echo-reference");
 
-    ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name);
-    if (!ctl) {
-        ALOGE("%s: Could not get ctl for mixer cmd - %s",
-              __func__, mixer_ctl_name);
-        return -EINVAL;
-    }
-    ALOGV("Setting EC Reference: %s", ec_ref);
-    mixer_ctl_set_enum_by_string(ctl, ec_ref);
-    return 0;
+    ALOGV("Setting EC Reference: %d", enable);
 }
 
 static struct csd_data *open_csd_client()
@@ -592,6 +587,9 @@
             my_data->acdb_init();
     }
 
+    /* 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
@@ -729,6 +727,22 @@
     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_get_fluence_type(void *platform, char *value, uint32_t len)
 {
     int ret = 0;
@@ -1131,7 +1145,7 @@
     ALOGV("%s: enter: out_device(%#x) in_device(%#x)",
           __func__, out_device, in_device);
     if ((out_device != AUDIO_DEVICE_NONE) && ((mode == AUDIO_MODE_IN_CALL) ||
-        voice_extn_compress_voip_is_active(adev))) {
+        voice_extn_compress_voip_is_active(adev) || audio_extn_hfp_is_active(adev))) {
         if ((adev->voice.tty_mode != TTY_MODE_OFF) &&
             !voice_extn_compress_voip_is_active(adev)) {
             if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE ||
@@ -1161,13 +1175,14 @@
             } else if (my_data->fluence_type == FLUENCE_NONE ||
                 my_data->fluence_in_voice_call == false) {
                 snd_device = SND_DEVICE_IN_HANDSET_MIC;
-                set_echo_reference(adev->mixer, EC_REF_RX);
+                set_echo_reference(adev, true);
             } else {
                 snd_device = SND_DEVICE_IN_VOICE_DMIC;
                 adev->acdb_settings |= DMIC_FLAG;
             }
         } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
             snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC;
+            set_echo_reference(adev, true);
         } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) {
             if (my_data->btsco_sample_rate == SAMPLE_RATE_16KHZ)
                 snd_device = SND_DEVICE_IN_BT_SCO_MIC_WB;
@@ -1186,6 +1201,7 @@
                 }
             } else {
                 snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC;
+                set_echo_reference(adev, true);
             }
         }
     } else if (source == AUDIO_SOURCE_CAMCORDER) {
@@ -1230,7 +1246,7 @@
                 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
                     snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
                 }
-                set_echo_reference(adev->mixer, EC_REF_RX);
+                set_echo_reference(adev, true);
             } else if (adev->active_input->enable_aec) {
                 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
                     if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
@@ -1247,7 +1263,7 @@
                 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
                     snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
                 }
-                set_echo_reference(adev->mixer, EC_REF_RX);
+                set_echo_reference(adev, true);
             } else if (adev->active_input->enable_ns) {
                 if (in_device & AUDIO_DEVICE_IN_BACK_MIC) {
                     if (my_data->fluence_type & FLUENCE_DUAL_MIC) {
@@ -1264,9 +1280,9 @@
                 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
                     snd_device = SND_DEVICE_IN_HEADSET_MIC_FLUENCE;
                 }
-                set_echo_reference(adev->mixer, "NONE");
+                set_echo_reference(adev, false);
             } else
-                set_echo_reference(adev->mixer, "NONE");
+                set_echo_reference(adev, false);
         }
     } else if (source == AUDIO_SOURCE_MIC) {
         if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC &&
@@ -1274,7 +1290,7 @@
             if(my_data->fluence_type & FLUENCE_DUAL_MIC &&
                     my_data->fluence_in_audio_rec) {
                 snd_device = SND_DEVICE_IN_HANDSET_DMIC;
-                set_echo_reference(adev->mixer, EC_REF_RX);
+                set_echo_reference(adev, true);
             }
         }
     } else if (source == AUDIO_SOURCE_FM_RX ||
@@ -1728,16 +1744,23 @@
     } else if (info->has_video && info->is_streaming) {
         fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV_STREAMING
                                      * info->sample_rate
-                                     * bits_per_sample
+                                     * (bits_per_sample >> 3)
                                      * popcount(info->channel_mask))/1000;
 
     } else if (info->has_video) {
         fragment_size = (PCM_OFFLOAD_BUFFER_DURATION_FOR_AV
                                      * info->sample_rate
-                                     * bits_per_sample
+                                     * (bits_per_sample >> 3)
                                      * popcount(info->channel_mask))/1000;
     }
 
+    char value[PROPERTY_VALUE_MAX] = {0};
+    if((property_get("audio.offload.pcm.buffer.size", value, "")) &&
+            atoi(value)) {
+        fragment_size =  atoi(value) * 1024;
+        ALOGV("Using buffer size from sys prop %d", fragment_size);
+    }
+
     fragment_size = ALIGN( fragment_size, 1024);
 
     if(fragment_size < MIN_PCM_OFFLOAD_FRAGMENT_SIZE)
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index f119fcd..2d6f854 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -186,7 +186,7 @@
 
 #ifdef PLATFORM_MSM8610
 #define LOWLATENCY_PCM_DEVICE 12
-#define EC_REF_RX "I2S_RX"
+#define EC_REF_RX "SEC_I2S_RX"
 #else
 #define LOWLATENCY_PCM_DEVICE 15
 #define EC_REF_RX "SLIM_RX"
@@ -220,7 +220,7 @@
 #define VOICE2_CALL_PCM_DEVICE 22
 #define VOLTE_CALL_PCM_DEVICE 14
 #define QCHAT_CALL_PCM_DEVICE 20
-#define VOWLAN_CALL_PCM_DEVICE -1
+#define VOWLAN_CALL_PCM_DEVICE 36
 #endif
 
 #ifdef PLATFORM_MSM8x26
diff --git a/hal/msm8974/platform_parser.c b/hal/msm8974/platform_parser.c
new file mode 100644
index 0000000..8f86d97
--- /dev/null
+++ b/hal/msm8974/platform_parser.c
@@ -0,0 +1,161 @@
+/*
+ * 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_parser"
+#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"
+#include "platform_parser.h"
+
+#define PLATFORM_XML_PATH        "/system/etc/platform_info.xml"
+#define BUF_SIZE                    1024
+
+static void process_device(void *userdata, const XML_Char **attr)
+{
+    unsigned int    *snd_device_index = userdata;
+
+    if (strcmp(attr[0], "name") != 0)
+        goto done;
+
+    if (platform_get_snd_device_name(*snd_device_index) == NULL)
+        goto next;
+    if (strcmp(attr[1], platform_get_snd_device_name(*snd_device_index)) != 0) {
+        ALOGE("%s: %s in platform.h at index %d does not match %s, from %s no ACDB ID set!",
+            __func__, platform_get_snd_device_name(*snd_device_index),
+            *snd_device_index, attr[1], PLATFORM_XML_PATH);
+        goto done;
+    }
+
+    if (strcmp(attr[2], "acdb_id") != 0) {
+        ALOGE("%s: Device %s at index %d in %s has no acdb_id, no ACDB ID set!",
+              __func__, attr[1], *snd_device_index, PLATFORM_XML_PATH);
+        goto done;
+    }
+
+    if(platform_set_snd_device_acdb_id(*snd_device_index,
+                                atoi((char *)attr[3])) != 0)
+        goto done;
+
+next:
+     (*snd_device_index)++;
+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(userdata, 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;
+    unsigned int    snd_device_index = SND_DEVICE_MIN;
+    void            *buf;
+
+    file = fopen(PLATFORM_XML_PATH, "r");
+    if (!file) {
+        ALOGD("%s: Failed to open %s, using defaults.",
+            __func__, PLATFORM_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_SetUserData(parser, &snd_device_index);
+    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_XML_PATH);
+            ret = -EINVAL;
+            goto err_free_parser;
+        }
+
+        if (bytes_read == 0)
+            break;
+    }
+
+    if (snd_device_index != SND_DEVICE_MAX) {
+        ALOGE("%s: Only %d/%d ACDB ID's set! Fix %s!",
+            __func__, snd_device_index, SND_DEVICE_MAX, PLATFORM_XML_PATH);
+        ret = -EINVAL;
+    }
+
+err_free_parser:
+    XML_ParserFree(parser);
+err_close_file:
+    fclose(file);
+done:
+    return ret;
+}
diff --git a/hal/msm8974/platform_parser.h b/hal/msm8974/platform_parser.h
new file mode 100644
index 0000000..3e91934
--- /dev/null
+++ b/hal/msm8974/platform_parser.h
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+#ifndef AUDIO_PLATFORM_PARSER_H
+#define AUDIO_PLATFORM_PARSER_H
+
+int platform_info_init(void);
+
+#endif // AUDIO_PLATFORM_PARSER_H
diff --git a/hal/platform_api.h b/hal/platform_api.h
index 7c4171d..913fd82 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);
@@ -29,6 +29,7 @@
 int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type);
 int platform_set_fluence_type(void *platform, char *value);
 int platform_get_fluence_type(void *platform, char *value, uint32_t len);
+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,
diff --git a/hal/voice.c b/hal/voice.c
index 82813f6..7cb448e 100644
--- a/hal/voice.c
+++ b/hal/voice.c
@@ -88,11 +88,11 @@
     }
 
     /* 2. Get and set stream specific mixer controls */
-    disable_audio_route(adev, uc_info, true);
+    disable_audio_route(adev, uc_info);
 
     /* 3. Disable the rx and tx devices */
-    disable_snd_device(adev, uc_info->out_snd_device, false);
-    disable_snd_device(adev, uc_info->in_snd_device, true);
+    disable_snd_device(adev, uc_info->out_snd_device);
+    disable_snd_device(adev, uc_info->in_snd_device);
 
     list_remove(&uc_info->list);
     free(uc_info);
@@ -189,6 +189,19 @@
     return in_call;
 }
 
+bool voice_is_in_call_rec_stream(struct stream_in *in)
+{
+    bool in_call_rec = false;
+    int ret = 0;
+
+    ret = voice_extn_is_in_call_rec_stream(in, &in_call_rec);
+    if (ret == -ENOSYS) {
+        in_call_rec = false;
+    }
+
+    return in_call_rec;
+}
+
 uint32_t voice_get_active_session_id(struct audio_device *adev)
 {
     int ret = 0;
diff --git a/hal/voice.h b/hal/voice.h
index d160569..0098f94 100644
--- a/hal/voice.h
+++ b/hal/voice.h
@@ -77,6 +77,7 @@
                           struct str_parms *reply);
 void voice_init(struct audio_device *adev);
 bool voice_is_in_call(struct audio_device *adev);
+bool voice_is_in_call_rec_stream(struct stream_in *in);
 int voice_set_mic_mute(struct audio_device *dev, bool state);
 bool voice_get_mic_mute(struct audio_device *dev);
 int voice_set_volume(struct audio_device *adev, float volume);
diff --git a/hal/voice_extn/compress_voip.c b/hal/voice_extn/compress_voip.c
index 47ac2c8..deb3172 100644
--- a/hal/voice_extn/compress_voip.c
+++ b/hal/voice_extn/compress_voip.c
@@ -305,11 +305,11 @@
         }
 
         /* 2. Get and set stream specific mixer controls */
-        disable_audio_route(adev, uc_info, true);
+        disable_audio_route(adev, uc_info);
 
         /* 3. Disable the rx and tx devices */
-        disable_snd_device(adev, uc_info->out_snd_device, false);
-        disable_snd_device(adev, uc_info->in_snd_device, true);
+        disable_snd_device(adev, uc_info->out_snd_device);
+        disable_snd_device(adev, uc_info->in_snd_device);
 
         list_remove(&uc_info->list);
         free(uc_info);
diff --git a/hal/voice_extn/voice_extn.c b/hal/voice_extn/voice_extn.c
index f6083f3..58a1f8b 100644
--- a/hal/voice_extn/voice_extn.c
+++ b/hal/voice_extn/voice_extn.c
@@ -356,6 +356,19 @@
     return 0;
 }
 
+int voice_extn_is_in_call_rec_stream(struct stream_in *in, bool *in_call_rec)
+{
+    *in_call_rec = false;
+
+    if(in->source == AUDIO_SOURCE_VOICE_DOWNLINK ||
+       in->source == AUDIO_SOURCE_VOICE_UPLINK ||
+       in->source == AUDIO_SOURCE_VOICE_CALL) {
+       *in_call_rec = true;
+    }
+
+    return 0;
+}
+
 void voice_extn_init(struct audio_device *adev)
 {
     adev->voice.session[VOICE_SESS_IDX].vsid =  VOICE_VSID;
diff --git a/hal/voice_extn/voice_extn.h b/hal/voice_extn/voice_extn.h
index f7d20e4..4a9c610 100644
--- a/hal/voice_extn/voice_extn.h
+++ b/hal/voice_extn/voice_extn.h
@@ -33,6 +33,7 @@
                                struct str_parms *query,
                                struct str_parms *reply);
 int voice_extn_is_in_call(struct audio_device *adev, bool *in_call);
+int voice_extn_is_in_call_rec_stream(struct stream_in *in, bool *in_call_rec);
 int voice_extn_get_active_session_id(struct audio_device *adev,
                                      uint32_t *session_id);
 void voice_extn_in_get_parameters(struct stream_in *in,
@@ -80,6 +81,11 @@
     return -ENOSYS;
 }
 
+static int voice_extn_is_in_call_rec_stream(struct stream_in *in, bool *in_call_rec)
+{
+    return -ENOSYS;
+}
+
 static int voice_extn_get_active_session_id(struct audio_device *adev,
                                             uint32_t *session_id)
 {
diff --git a/policy_hal/AudioPolicyManager.cpp b/policy_hal/AudioPolicyManager.cpp
index 0722aed..13dd21c 100644
--- a/policy_hal/AudioPolicyManager.cpp
+++ b/policy_hal/AudioPolicyManager.cpp
@@ -51,7 +51,7 @@
 {
     SortedVector <audio_io_handle_t> outputs;
 
-    ALOGV("setDeviceConnectionState() device: %x, state %d, address %s", device, state, device_address);
+    ALOGD("setDeviceConnectionState() device: %x, state %d, address %s", device, state, device_address);
 
     // connect/disconnect only 1 device at a time
     if (!audio_is_output_device(device) && !audio_is_input_device(device)) return BAD_VALUE;
@@ -193,8 +193,16 @@
             // do not force device change on duplicated output because if device is 0, it will
             // also force a device 0 for the two outputs it is duplicated to which may override
             // a valid device selection on those outputs.
+            audio_devices_t cachedDevice = getNewDevice(mOutputs.keyAt(i), true /*fromCache*/);
+            AudioOutputDescriptor *desc = mOutputs.valueFor(mOutputs.keyAt(i));
+            if (cachedDevice == AUDIO_DEVICE_OUT_SPEAKER &&
+                device == AUDIO_DEVICE_OUT_PROXY &&
+                (desc->mFlags & AUDIO_OUTPUT_FLAG_FAST)) {
+                    ALOGI("Avoid routing touch tone to spkr as proxy is being disconnected");
+                    break;
+            }
             setOutputDevice(mOutputs.keyAt(i),
-                            getNewDevice(mOutputs.keyAt(i), true /*fromCache*/),
+                            cachedDevice,
                             !mOutputs.valueAt(i)->isDuplicated(),
                             0);
         }
@@ -387,7 +395,7 @@
 
 void AudioPolicyManager::setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config)
 {
-    ALOGV("setForceUse() usage %d, config %d, mPhoneState %d", usage, config, mPhoneState);
+    ALOGD("setForceUse() usage %d, config %d, mPhoneState %d", usage, config, mPhoneState);
 
     bool forceVolumeReeval = false;
     switch(usage) {
@@ -450,7 +458,7 @@
     checkA2dpSuspend();
     checkOutputForAllStrategies();
     updateDevicesAndOutputs();
-    for (int i = mOutputs.size() -1; i >= 0; i--) {
+    for (int i = 0; i < mOutputs.size(); i++) {
         audio_io_handle_t output = mOutputs.keyAt(i);
         audio_devices_t newDevice = getNewDevice(output, true /*fromCache*/);
         setOutputDevice(output, newDevice, (newDevice != AUDIO_DEVICE_NONE));
@@ -475,193 +483,6 @@
 
 }
 
-status_t AudioPolicyManager::startOutput(audio_io_handle_t output,
-                                             AudioSystem::stream_type stream,
-                                             int session)
-{
-    ALOGV("startOutput() output %d, stream %d, session %d", output, stream, session);
-    ssize_t index = mOutputs.indexOfKey(output);
-    if (index < 0) {
-        ALOGW("startOutput() unknow output %d", output);
-        return BAD_VALUE;
-    }
-
-    AudioOutputDescriptor *outputDesc = mOutputs.valueAt(index);
-
-    // increment usage count for this stream on the requested output:
-    // NOTE that the usage count is the same for duplicated output and hardware output which is
-    // necessary for a correct control of hardware output routing by startOutput() and stopOutput()
-    outputDesc->changeRefCount(stream, 1);
-
-    if (outputDesc->mRefCount[stream] == 1) {
-        audio_devices_t newDevice = getNewDevice(output, false /*fromCache*/);
-        routing_strategy strategy = getStrategy(stream);
-        bool shouldWait = (strategy == STRATEGY_SONIFICATION) ||
-                            (strategy == STRATEGY_SONIFICATION_RESPECTFUL);
-        uint32_t waitMs = 0;
-        bool force = false;
-        for (size_t i = 0; i < mOutputs.size(); i++) {
-            AudioOutputDescriptor *desc = mOutputs.valueAt(i);
-            if (desc != outputDesc) {
-                // force a device change if any other output is managed by the same hw
-                // module and has a current device selection that differs from selected device.
-                // In this case, the audio HAL must receive the new device selection so that it can
-                // change the device currently selected by the other active output.
-                if (outputDesc->sharesHwModuleWith(desc) &&
-                    desc->device() != newDevice) {
-                    force = true;
-                }
-                // wait for audio on other active outputs to be presented when starting
-                // a notification so that audio focus effect can propagate.
-                uint32_t latency = desc->latency();
-                if (shouldWait && desc->isActive(latency * 2) && (waitMs < latency)) {
-                    waitMs = latency;
-                }
-            }
-        }
-        uint32_t muteWaitMs = setOutputDevice(output, newDevice, force);
-
-        // handle special case for sonification while in call
-        if (isInCall()) {
-            handleIncallSonification(stream, true, false);
-        }
-
-        // apply volume rules for current stream and device if necessary
-        checkAndSetVolume(stream,
-                          mStreams[stream].getVolumeIndex(newDevice),
-                          output,
-                          newDevice);
-
-        // update the outputs if starting an output with a stream that can affect notification
-        // routing
-        handleNotificationRoutingForStream(stream);
-        if (waitMs > muteWaitMs) {
-            usleep((waitMs - muteWaitMs) * 2 * 1000);
-        }
-    }
-#ifdef DOLBY_UDC
-    // It is observed that in some use-cases where both outputs are present eg. bluetooth and headphone,
-    // the output for particular stream type is decided in this routine. Hence we must call
-    // getDeviceForStrategy in order to get the current active output for this stream type and update
-    // the dolby system property.
-    if (stream == AudioSystem::MUSIC)
-    {
-        audio_devices_t audioOutputDevice = getDeviceForStrategy(getStrategy(AudioSystem::MUSIC), true);
-        DolbySystemProperty::set(audioOutputDevice);
-    }
-#endif // DOLBY_END
-    return NO_ERROR;
-}
-
-
-status_t AudioPolicyManager::stopOutput(audio_io_handle_t output,
-                                            AudioSystem::stream_type stream,
-                                            int session)
-{
-    ALOGV("stopOutput() output %d, stream %d, session %d", output, stream, session);
-    ssize_t index = mOutputs.indexOfKey(output);
-    if (index < 0) {
-        ALOGW("stopOutput() unknow output %d", output);
-        return BAD_VALUE;
-    }
-
-    AudioOutputDescriptor *outputDesc = mOutputs.valueAt(index);
-
-    // handle special case for sonification while in call
-    if (isInCall()) {
-        handleIncallSonification(stream, false, false);
-    }
-
-    if (outputDesc->mRefCount[stream] > 0) {
-        // decrement usage count of this stream on the output
-        outputDesc->changeRefCount(stream, -1);
-        // store time at which the stream was stopped - see isStreamActive()
-        if (outputDesc->mRefCount[stream] == 0) {
-            outputDesc->mStopTime[stream] = systemTime();
-            audio_devices_t newDevice = getNewDevice(output, false /*fromCache*/);
-            // delay the device switch by twice the latency because stopOutput() is executed when
-            // the track stop() command is received and at that time the audio track buffer can
-            // still contain data that needs to be drained. The latency only covers the audio HAL
-            // and kernel buffers. Also the latency does not always include additional delay in the
-            // audio path (audio DSP, CODEC ...)
-            setOutputDevice(output, newDevice, false, outputDesc->mLatency*2);
-
-            // force restoring the device selection on other active outputs if it differs from the
-            // one being selected for this output
-            for (size_t i = 0; i < mOutputs.size(); i++) {
-                audio_io_handle_t curOutput = mOutputs.keyAt(i);
-                AudioOutputDescriptor *desc = mOutputs.valueAt(i);
-                if (curOutput != output &&
-                        desc->isActive() &&
-                        outputDesc->sharesHwModuleWith(desc) &&
-                        (newDevice != desc->device())) {
-                    setOutputDevice(curOutput,
-                                    getNewDevice(curOutput, false /*fromCache*/),
-                                    true,
-                                    outputDesc->mLatency*2);
-                }
-            }
-            // update the outputs if stopping one with a stream that can affect notification routing
-            handleNotificationRoutingForStream(stream);
-        }
-        return NO_ERROR;
-    } else {
-        ALOGW("stopOutput() refcount is already 0 for output %d", output);
-        return INVALID_OPERATION;
-    }
-}
-
-audio_devices_t AudioPolicyManager::getNewDevice(audio_io_handle_t output, bool fromCache)
-{
-    audio_devices_t device = AUDIO_DEVICE_NONE;
-
-    AudioOutputDescriptor *outputDesc = mOutputs.valueFor(output);
-    AudioOutputDescriptor *primaryOutputDesc = mOutputs.valueFor(mPrimaryOutput);
-    // check the following by order of priority to request a routing change if necessary:
-    // 1: the strategy enforced audible is active on the output:
-    //      use device for strategy enforced audible
-    // 2: we are in call or the strategy phone is active on the output:
-    //      use device for strategy phone
-    // 3: the strategy sonification is active on the output:
-    //      use device for strategy sonification
-    // 4: the strategy "respectful" sonification is active on the output:
-    //      use device for strategy "respectful" sonification
-    // 5: the strategy media is active on the output:
-    //      use device for strategy media
-    // 6: the strategy DTMF is active on the output:
-    //      use device for strategy DTMF
-    if (outputDesc->isStrategyActive(STRATEGY_ENFORCED_AUDIBLE)) {
-        device = getDeviceForStrategy(STRATEGY_ENFORCED_AUDIBLE, fromCache);
-    } else if (isInCall() ||
-                    outputDesc->isStrategyActive(STRATEGY_PHONE)) {
-        device = getDeviceForStrategy(STRATEGY_PHONE, fromCache);
-    } else if (outputDesc->isStrategyActive(STRATEGY_SONIFICATION)||
-                (primaryOutputDesc->isStrategyActive(STRATEGY_SONIFICATION)&& !primaryOutputDesc->isStrategyActive(STRATEGY_MEDIA))){
-        device = getDeviceForStrategy(STRATEGY_SONIFICATION, fromCache);
-    } else if (outputDesc->isStrategyActive(STRATEGY_SONIFICATION_RESPECTFUL)) {
-        device = getDeviceForStrategy(STRATEGY_SONIFICATION_RESPECTFUL, fromCache);
-    } else if (outputDesc->isStrategyActive(STRATEGY_MEDIA)) {
-        device = getDeviceForStrategy(STRATEGY_MEDIA, fromCache);
-    } else if (outputDesc->isStrategyActive(STRATEGY_DTMF)) {
-        device = getDeviceForStrategy(STRATEGY_DTMF, fromCache);
-    }
-
-    ALOGV("getNewDevice() selected device %x", device);
-    return device;
-}
-
-//private function, no changes from AudioPolicyManagerBase
-void AudioPolicyManager::handleNotificationRoutingForStream(AudioSystem::stream_type stream) {
-    switch(stream) {
-    case AudioSystem::MUSIC:
-        checkOutputForStrategy(STRATEGY_SONIFICATION_RESPECTFUL);
-        updateDevicesAndOutputs();
-        break;
-    default:
-        break;
-    }
-}
-
 audio_io_handle_t AudioPolicyManager::getInput(int inputSource,
                                     uint32_t samplingRate,
                                     uint32_t format,
@@ -671,7 +492,7 @@
     audio_io_handle_t input = 0;
     audio_devices_t device = getDeviceForInputSource(inputSource);
 
-    ALOGV("getInput() inputSource %d, samplingRate %d, format %d, channelMask %x, acoustics %x",
+    ALOGD("getInput() inputSource %d, samplingRate %d, format %d, channelMask %x, acoustics %x",
           inputSource, samplingRate, format, channelMask, acoustics);
 
     if (device == AUDIO_DEVICE_NONE) {
@@ -724,6 +545,8 @@
         return 0;
     }
     mInputs.add(input, inputDesc);
+    ALOGD("getInput() returns input %d", input);
+
     return input;
 }
 
@@ -1101,6 +924,17 @@
     }
 }
 
+bool AudioPolicyManager::isDirectOutput(audio_io_handle_t output) {
+    for (size_t i = 0; i < mOutputs.size(); i++) {
+        audio_io_handle_t curOutput = mOutputs.keyAt(i);
+        AudioOutputDescriptor *desc = mOutputs.valueAt(i);
+        if ((curOutput == output) && (desc->mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) {
+            return true;
+        }
+    }
+    return false;
+}
+
 status_t AudioPolicyManager::checkAndSetVolume(int stream,
                                                int index,
                                                audio_io_handle_t output,
@@ -1157,21 +991,14 @@
         stream == AudioSystem::BLUETOOTH_SCO) {
         float voiceVolume;
 
-        voiceVolume = (float)index/(float)mStreams[stream].mIndexMax;
+        if (stream == AudioSystem::VOICE_CALL)
+            voiceVolume = (float)index/(float)mStreams[stream].mIndexMax;
+        else
+            // Force voice volume to max for bluetooth SCO as volume is managed by the headset
+            voiceVolume = 1.0;
 
-        // Force voice volume to max when Vgs is set for bluetooth SCO as volume is managed by the headset
-        if (stream == AudioSystem::BLUETOOTH_SCO) {
-            String8 key ("bt_headset_vgs");
-            mpClientInterface->getParameters(output,key);
-            AudioParameter result(mpClientInterface->getParameters(0,key));
-            int value;
-            if (result.getInt(String8("isVGS"),value) == NO_ERROR) {
-                ALOGV("Use BT-SCO Voice Volume");
-                voiceVolume = 1.0;
-            }
-        }
-
-        if (voiceVolume != mLastVoiceVolume && output == mPrimaryOutput) {
+        if (voiceVolume != mLastVoiceVolume && ((output == mPrimaryOutput) ||
+            isDirectOutput(output))) {
             mpClientInterface->setVoiceVolume(voiceVolume, delayMs);
             mLastVoiceVolume = voiceVolume;
         }
diff --git a/policy_hal/AudioPolicyManager.h b/policy_hal/AudioPolicyManager.h
index 8ef1cab..3b80977 100644
--- a/policy_hal/AudioPolicyManager.h
+++ b/policy_hal/AudioPolicyManager.h
@@ -50,13 +50,6 @@
                                             AudioSystem::audio_in_acoustics acoustics);
         virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
         virtual void setPhoneState(int state);
-        virtual status_t startOutput(audio_io_handle_t output,
-                                     AudioSystem::stream_type stream,
-                                     int session = 0);
-        virtual status_t stopOutput(audio_io_handle_t output,
-                                    AudioSystem::stream_type stream,
-                                    int session = 0);
-
 protected:
         // return the strategy corresponding to a given stream type
         static routing_strategy getStrategy(AudioSystem::stream_type stream);
@@ -84,12 +77,23 @@
         // check that volume change is permitted, compute and send new volume to audio hardware
         status_t checkAndSetVolume(int stream, int index, audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false);
 
-        audio_devices_t getNewDevice(audio_io_handle_t output, bool fromCache);
         // returns the category the device belongs to with regard to volume curve management
         static device_category getDeviceCategory(audio_devices_t device);
 
+        // returns true if give output is direct output
+        bool isDirectOutput(audio_io_handle_t output);
+
+        static const char* HDMI_SPKR_STR;
+
+        //parameter indicates of HDMI speakers disabled from the Qualcomm settings
+        bool mHdmiAudioDisabled;
+
+        //parameter indicates if HDMI plug in/out detected
+        bool mHdmiAudioEvent;
+
 private:
-        void handleNotificationRoutingForStream(AudioSystem::stream_type stream);
+        // Used for voip + voice concurrency usecase
+        int mPrevPhoneState;
 
 };
 };
diff --git a/post_proc/bass_boost.c b/post_proc/bass_boost.c
index 2061cd0..4edd9af 100644
--- a/post_proc/bass_boost.c
+++ b/post_proc/bass_boost.c
@@ -47,13 +47,14 @@
 
 int bassboost_get_strength(bassboost_context_t *context)
 {
-    ALOGV("%s: strength: %d", __func__, context->strength);
+    ALOGV("%s: ctxt %p, strength: %d", __func__,
+                      context,  context->strength);
     return context->strength;
 }
 
 int bassboost_set_strength(bassboost_context_t *context, uint32_t strength)
 {
-    ALOGV("%s: strength: %d", __func__, strength);
+    ALOGV("%s: ctxt %p, strength: %d", __func__, context, strength);
     context->strength = strength;
 
     offload_bassboost_set_strength(&(context->offload_bass), strength);
@@ -74,7 +75,7 @@
     void *value = p->data + voffset;
     int i;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p, param %d", __func__, bass_ctxt, param);
 
     p->status = 0;
 
@@ -100,12 +101,10 @@
 
     switch (param) {
     case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
-	ALOGV("%s: BASSBOOST_PARAM_STRENGTH_SUPPORTED", __func__);
         *(uint32_t *)value = 1;
         break;
 
     case BASSBOOST_PARAM_STRENGTH:
-	ALOGV("%s: BASSBOOST_PARAM_STRENGTH", __func__);
         *(int16_t *)value = bassboost_get_strength(bass_ctxt);
         break;
 
@@ -127,13 +126,12 @@
     int32_t param = *param_tmp++;
     uint32_t strength;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p, param %d", __func__, bass_ctxt, param);
 
     p->status = 0;
 
     switch (param) {
     case BASSBOOST_PARAM_STRENGTH:
-	ALOGV("%s BASSBOOST_PARAM_STRENGTH", __func__);
         strength = (uint32_t)(*(int16_t *)value);
         bassboost_set_strength(bass_ctxt, strength);
         break;
@@ -149,13 +147,14 @@
 {
     bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
 
-    ALOGV("%s: device: %d", __func__, device);
+    ALOGV("%s: ctxt %p, device 0x%x", __func__, bass_ctxt, device);
     bass_ctxt->device = device;
     if((device == AUDIO_DEVICE_OUT_SPEAKER) ||
        (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT) ||
        (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER) ||
        (device == AUDIO_DEVICE_OUT_PROXY) ||
        (device == AUDIO_DEVICE_OUT_AUX_DIGITAL) ||
+       (device == AUDIO_DEVICE_OUT_USB_ACCESSORY) ||
        (device == AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET)) {
         if (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass))) {
             offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), false);
@@ -164,6 +163,7 @@
                 offload_bassboost_send_params(bass_ctxt->ctl,
                                               bass_ctxt->offload_bass,
                                               OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG);
+            ALOGI("%s: ctxt %p, disabled based on device", __func__, bass_ctxt);
         }
     } else {
         if (!offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass)) &&
@@ -191,7 +191,7 @@
 {
     bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p", __func__, bass_ctxt);
     context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
     context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
     context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
@@ -221,7 +221,7 @@
 {
     bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p, strength %d", __func__, bass_ctxt, bass_ctxt->strength);
 
     if (!offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass)) &&
         !(bass_ctxt->temp_disabled)) {
@@ -239,7 +239,7 @@
 {
     bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p", __func__, bass_ctxt);
     if (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass))) {
         offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), false);
         if (bass_ctxt->ctl)
@@ -254,9 +254,9 @@
 {
     bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p, ctl %p, strength %d", __func__, bass_ctxt,
+                                   output->ctl, bass_ctxt->strength);
     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,
@@ -269,7 +269,7 @@
 {
     bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p", __func__, bass_ctxt);
     bass_ctxt->ctl = NULL;
     return 0;
 }
diff --git a/post_proc/bundle.c b/post_proc/bundle.c
index 8e2bce8..a0d9fcb 100644
--- a/post_proc/bundle.c
+++ b/post_proc/bundle.c
@@ -121,6 +121,7 @@
 {
     struct listnode *fx_node;
 
+    ALOGV("%s: e_ctxt %p, o_ctxt %p", __func__, context, output);
     list_for_each(fx_node, &output->effects_list) {
         effect_context_t *fx_ctxt = node_to_item(fx_node,
                                                  effect_context_t,
@@ -139,6 +140,7 @@
 {
     struct listnode *fx_node;
 
+    ALOGV("%s: e_ctxt %p, o_ctxt %p", __func__, context, output);
     list_for_each(fx_node, &output->effects_list) {
         effect_context_t *fx_ctxt = node_to_item(fx_node,
                                                  effect_context_t,
@@ -199,6 +201,11 @@
 
     output_context_t *out_ctxt = (output_context_t *)
                                  malloc(sizeof(output_context_t));
+    if (!out_ctxt) {
+        ALOGE("%s fail to allocate for output context", __func__);
+        ret = -ENOMEM;
+        goto exit;
+    }
     out_ctxt->handle = output;
     out_ctxt->pcm_device_id = pcm_id;
 
@@ -332,6 +339,9 @@
         sizeof(effect_uuid_t)) == 0) {
         equalizer_context_t *eq_ctxt = (equalizer_context_t *)
                                        calloc(1, sizeof(equalizer_context_t));
+        if (eq_ctxt == NULL) {
+            return -ENOMEM;
+        }
         context = (effect_context_t *)eq_ctxt;
         context->ops.init = equalizer_init;
         context->ops.reset = equalizer_reset;
@@ -349,6 +359,9 @@
                sizeof(effect_uuid_t)) == 0) {
         bassboost_context_t *bass_ctxt = (bassboost_context_t *)
                                          calloc(1, sizeof(bassboost_context_t));
+        if (bass_ctxt == NULL) {
+            return -ENOMEM;
+        }
         context = (effect_context_t *)bass_ctxt;
         context->ops.init = bassboost_init;
         context->ops.reset = bassboost_reset;
@@ -366,6 +379,9 @@
                sizeof(effect_uuid_t)) == 0) {
         virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)
                                            calloc(1, sizeof(virtualizer_context_t));
+        if (virt_ctxt == NULL) {
+            return -ENOMEM;
+        }
         context = (effect_context_t *)virt_ctxt;
         context->ops.init = virtualizer_init;
         context->ops.reset = virtualizer_reset;
@@ -389,6 +405,9 @@
                 sizeof(effect_uuid_t)) == 0)) {
         reverb_context_t *reverb_ctxt = (reverb_context_t *)
                                         calloc(1, sizeof(reverb_context_t));
+        if (reverb_ctxt == NULL) {
+            return -ENOMEM;
+        }
         context = (effect_context_t *)reverb_ctxt;
         context->ops.init = reverb_init;
         context->ops.reset = reverb_reset;
@@ -512,7 +531,7 @@
     effect_context_t * context = (effect_context_t *)self;
     int status = 0;
 
-    ALOGW("%s Called ?????", __func__);
+    ALOGW("%s: ctxt %p, Called ?????", __func__, context);
 
     pthread_mutex_lock(&lock);
     if (!effect_exists(context)) {
@@ -545,6 +564,7 @@
         goto exit;
     }
 
+    ALOGV("%s: ctxt %p, cmd %d", __func__, context, cmdCode);
     if (context == NULL || context->state == EFFECT_STATE_UNINITIALIZED) {
         status = -EINVAL;
         goto exit;
@@ -598,7 +618,6 @@
         context->state = EFFECT_STATE_ACTIVE;
         if (context->ops.enable)
             context->ops.enable(context);
-        ALOGV("%s EFFECT_CMD_ENABLE", __func__);
         *(int *)pReplyData = 0;
         break;
     case EFFECT_CMD_DISABLE:
@@ -613,7 +632,6 @@
         context->state = EFFECT_STATE_INITIALIZED;
         if (context->ops.disable)
             context->ops.disable(context);
-        ALOGV("%s EFFECT_CMD_DISABLE", __func__);
         *(int *)pReplyData = 0;
         break;
     case EFFECT_CMD_GET_PARAM: {
@@ -623,7 +641,7 @@
             *replySize < (int)(sizeof(effect_param_t) + sizeof(uint32_t) +
                                sizeof(uint16_t))) {
             status = -EINVAL;
-            ALOGV("EFFECT_CMD_GET_PARAM invalid command cmdSize %d *replySize %d",
+            ALOGW("EFFECT_CMD_GET_PARAM invalid command cmdSize %d *replySize %d",
                   cmdSize, *replySize);
             goto exit;
         }
@@ -643,7 +661,7 @@
                             sizeof(uint16_t)) ||
             pReplyData == NULL || *replySize != sizeof(int32_t)) {
             status = -EINVAL;
-            ALOGV("EFFECT_CMD_SET_PARAM invalid command cmdSize %d *replySize %d",
+            ALOGW("EFFECT_CMD_SET_PARAM invalid command cmdSize %d *replySize %d",
                   cmdSize, *replySize);
             goto exit;
         }
@@ -659,7 +677,7 @@
         ALOGV("\t EFFECT_CMD_SET_DEVICE start");
         if (pCmdData == NULL || cmdSize < sizeof(uint32_t)) {
             status = -EINVAL;
-            ALOGV("EFFECT_CMD_SET_DEVICE invalid command cmdSize %d", cmdSize);
+            ALOGW("EFFECT_CMD_SET_DEVICE invalid command cmdSize %d", cmdSize);
             goto exit;
         }
         device = *(uint32_t *)pCmdData;
@@ -675,7 +693,7 @@
 
         if (cmdSize != sizeof(effect_offload_param_t) || pCmdData == NULL
                 || pReplyData == NULL || *replySize != sizeof(int)) {
-            ALOGV("%s EFFECT_CMD_OFFLOAD bad format", __func__);
+            ALOGW("%s EFFECT_CMD_OFFLOAD bad format", __func__);
             status = -EINVAL;
             break;
         }
diff --git a/post_proc/effect_api.c b/post_proc/effect_api.c
index 570ca8b..2acf18e 100644
--- a/post_proc/effect_api.c
+++ b/post_proc/effect_api.c
@@ -29,6 +29,12 @@
 
 #define LOG_TAG "offload_effect_api"
 #define LOG_NDEBUG 0
+//#define VERY_VERY_VERBOSE_LOGGING
+#ifdef VERY_VERY_VERBOSE_LOGGING
+#define ALOGVV ALOGV
+#else
+#define ALOGVV(a...) do { } while(0)
+#endif
 
 #include <stdbool.h>
 #include <cutils/log.h>
@@ -99,34 +105,34 @@
 void offload_bassboost_set_device(struct bass_boost_params *bassboost,
                                   uint32_t device)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: device 0x%x", __func__, device);
     bassboost->device = device;
 }
 
 void offload_bassboost_set_enable_flag(struct bass_boost_params *bassboost,
                                        bool enable)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: enable=%d", __func__, (int)enable);
     bassboost->enable_flag = enable;
 }
 
 int offload_bassboost_get_enable_flag(struct bass_boost_params *bassboost)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: enable=%d", __func__, (int)bassboost->enable_flag);
     return bassboost->enable_flag;
 }
 
 void offload_bassboost_set_strength(struct bass_boost_params *bassboost,
                                     int strength)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: strength %d", __func__, strength);
     bassboost->strength = strength;
 }
 
 void offload_bassboost_set_mode(struct bass_boost_params *bassboost,
                                 int mode)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: mode %d", __func__, mode);
     bassboost->mode = mode;
 }
 
@@ -137,7 +143,7 @@
     int param_values[128] = {0};
     int *p_param_values = param_values;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: flags 0x%x", __func__, param_send_flags);
     *p_param_values++ = BASS_BOOST_MODULE;
     *p_param_values++ = bassboost.device;
     *p_param_values++ = 0; /* num of commands*/
@@ -175,41 +181,41 @@
 void offload_virtualizer_set_device(struct virtualizer_params *virtualizer,
                                     uint32_t device)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: device=0x%x", __func__, device);
     virtualizer->device = device;
 }
 
 void offload_virtualizer_set_enable_flag(struct virtualizer_params *virtualizer,
                                          bool enable)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: enable=%d", __func__, (int)enable);
     virtualizer->enable_flag = enable;
 }
 
 int offload_virtualizer_get_enable_flag(struct virtualizer_params *virtualizer)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: enabled %d", __func__, (int)virtualizer->enable_flag);
     return virtualizer->enable_flag;
 }
 
 void offload_virtualizer_set_strength(struct virtualizer_params *virtualizer,
                                       int strength)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: strength %d", __func__, strength);
     virtualizer->strength = strength;
 }
 
 void offload_virtualizer_set_out_type(struct virtualizer_params *virtualizer,
                                       int out_type)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: out_type %d", __func__, out_type);
     virtualizer->out_type = out_type;
 }
 
 void offload_virtualizer_set_gain_adjust(struct virtualizer_params *virtualizer,
                                          int gain_adjust)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: gain %d", __func__, gain_adjust);
     virtualizer->gain_adjust = gain_adjust;
 }
 
@@ -220,7 +226,7 @@
     int param_values[128] = {0};
     int *p_param_values = param_values;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: flags 0x%x", __func__, param_send_flags);
     *p_param_values++ = VIRTUALIZER_MODULE;
     *p_param_values++ = virtualizer.device;
     *p_param_values++ = 0; /* num of commands*/
@@ -265,25 +271,25 @@
 
 void offload_eq_set_device(struct eq_params *eq, uint32_t device)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: device 0x%x", __func__, device);
     eq->device = device;
 }
 
 void offload_eq_set_enable_flag(struct eq_params *eq, bool enable)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: enable=%d", __func__, (int)enable);
     eq->enable_flag = enable;
 }
 
 int offload_eq_get_enable_flag(struct eq_params *eq)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: enabled=%d", __func__, (int)eq->enable_flag);
     return eq->enable_flag;
 }
 
 void offload_eq_set_preset(struct eq_params *eq, int preset)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: preset %d", __func__, preset);
     eq->config.preset_id = preset;
     eq->config.eq_pregain = Q27_UNITY;
 }
@@ -293,7 +299,7 @@
                                 int *band_gain_list)
 {
     int i;
-    ALOGV("%s", __func__);
+    ALOGVV("%s", __func__);
     eq->config.num_bands = num_bands;
     for (i=0; i<num_bands; i++) {
         eq->per_band_cfg[i].band_idx = i;
@@ -311,8 +317,9 @@
     int *p_param_values = param_values;
     uint32_t i;
 
-    ALOGV("%s", __func__);
-    if (eq.config.preset_id < -1 ) {
+    ALOGV("%s: flags 0x%x", __func__, param_send_flags);
+    if ((eq.config.preset_id < -1) ||
+            ((param_send_flags & OFFLOAD_SEND_EQ_PRESET) && (eq.config.preset_id == -1))) {
         ALOGV("No Valid preset to set");
         return 0;
     }
@@ -365,110 +372,110 @@
 
 void offload_reverb_set_device(struct reverb_params *reverb, uint32_t device)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: device 0x%x", __func__, device);
     reverb->device = device;
 }
 
 void offload_reverb_set_enable_flag(struct reverb_params *reverb, bool enable)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: enable=%d", __func__, (int)enable);
     reverb->enable_flag = enable;
 }
 
 int offload_reverb_get_enable_flag(struct reverb_params *reverb)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: enabled=%d", __func__, reverb->enable_flag);
     return reverb->enable_flag;
 }
 
 void offload_reverb_set_mode(struct reverb_params *reverb, int mode)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s", __func__);
     reverb->mode = mode;
 }
 
 void offload_reverb_set_preset(struct reverb_params *reverb, int preset)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: preset %d", __func__, preset);
     if (preset && (preset <= NUM_OSL_REVERB_PRESETS_SUPPORTED))
         reverb->preset = map_reverb_opensl_preset_2_offload_preset[preset-1][1];
 }
 
 void offload_reverb_set_wet_mix(struct reverb_params *reverb, int wet_mix)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: wet_mix %d", __func__, wet_mix);
     reverb->wet_mix = wet_mix;
 }
 
 void offload_reverb_set_gain_adjust(struct reverb_params *reverb,
                                     int gain_adjust)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: gain %d", __func__, gain_adjust);
     reverb->gain_adjust = gain_adjust;
 }
 
 void offload_reverb_set_room_level(struct reverb_params *reverb, int room_level)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: level %d", __func__, room_level);
     reverb->room_level = room_level;
 }
 
 void offload_reverb_set_room_hf_level(struct reverb_params *reverb,
                                       int room_hf_level)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: level %d", __func__, room_hf_level);
     reverb->room_hf_level = room_hf_level;
 }
 
 void offload_reverb_set_decay_time(struct reverb_params *reverb, int decay_time)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: decay time %d", __func__, decay_time);
     reverb->decay_time = decay_time;
 }
 
 void offload_reverb_set_decay_hf_ratio(struct reverb_params *reverb,
                                        int decay_hf_ratio)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: decay_hf_ratio %d", __func__, decay_hf_ratio);
     reverb->decay_hf_ratio = decay_hf_ratio;
 }
 
 void offload_reverb_set_reflections_level(struct reverb_params *reverb,
                                           int reflections_level)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: ref level %d", __func__, reflections_level);
     reverb->reflections_level = reflections_level;
 }
 
 void offload_reverb_set_reflections_delay(struct reverb_params *reverb,
                                           int reflections_delay)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: ref delay", __func__, reflections_delay);
     reverb->reflections_delay = reflections_delay;
 }
 
 void offload_reverb_set_reverb_level(struct reverb_params *reverb,
                                      int reverb_level)
 {
-    ALOGV("%s", __func__);
+    ALOGD("%s: reverb level %d", __func__, reverb_level);
     reverb->level = reverb_level;
 }
 
 void offload_reverb_set_delay(struct reverb_params *reverb, int delay)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: delay %d", __func__, delay);
     reverb->delay = delay;
 }
 
 void offload_reverb_set_diffusion(struct reverb_params *reverb, int diffusion)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: diffusion %d", __func__, diffusion);
     reverb->diffusion = diffusion;
 }
 
 void offload_reverb_set_density(struct reverb_params *reverb, int density)
 {
-    ALOGV("%s", __func__);
+    ALOGVV("%s: density %d", __func__, density);
     reverb->density = density;
 }
 
@@ -479,7 +486,7 @@
     int param_values[128] = {0};
     int *p_param_values = param_values;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: flags 0x%x", __func__, param_send_flags);
     *p_param_values++ = REVERB_MODULE;
     *p_param_values++ = reverb.device;
     *p_param_values++ = 0; /* num of commands*/
diff --git a/post_proc/equalizer.c b/post_proc/equalizer.c
index 7c7ced2..c635251 100644
--- a/post_proc/equalizer.c
+++ b/post_proc/equalizer.c
@@ -87,7 +87,7 @@
 
 int equalizer_get_band_level(equalizer_context_t *context, int32_t band)
 {
-    ALOGV("%s: band: %d level: %d", __func__, band,
+    ALOGV("%s: ctxt %p, band: %d level: %d", __func__, context, band,
            context->band_levels[band] * 100);
     return context->band_levels[band] * 100;
 }
@@ -95,7 +95,7 @@
 int equalizer_set_band_level(equalizer_context_t *context, int32_t band,
                              int32_t level)
 {
-    ALOGV("%s: band: %d, level: %d", __func__, band, level);
+    ALOGV("%s: ctxt %p, band: %d, level: %d", __func__, context, band, level);
     if (level > 0) {
         level = (int)((level+50)/100);
     } else {
@@ -118,7 +118,7 @@
 
 int equalizer_get_center_frequency(equalizer_context_t *context, int32_t band)
 {
-    ALOGV("%s: band: %d", __func__, band);
+    ALOGV("%s: ctxt %p, band: %d", __func__, context, band);
     return (equalizer_band_freq_range[band][0] +
             equalizer_band_freq_range[band][1]) / 2;
 }
@@ -126,7 +126,7 @@
 int equalizer_get_band_freq_range(equalizer_context_t *context, int32_t band,
                                   uint32_t *low, uint32_t *high)
 {
-    ALOGV("%s: band: %d", __func__, band);
+    ALOGV("%s: ctxt %p, band: %d", __func__, context, band);
     *low = equalizer_band_freq_range[band][0];
     *high = equalizer_band_freq_range[band][1];
    return 0;
@@ -136,7 +136,7 @@
 {
     int i;
 
-    ALOGV("%s: freq: %d", __func__, freq);
+    ALOGV("%s: ctxt %p, freq: %d", __func__, context, freq);
     for(i = 0; i < NUM_EQ_BANDS; i++) {
         if (freq <= equalizer_band_freq_range[i][1]) {
             return i;
@@ -147,7 +147,7 @@
 
 int equalizer_get_preset(equalizer_context_t *context)
 {
-    ALOGV("%s: preset: %d", __func__, context->preset);
+    ALOGV("%s: ctxt %p, preset: %d", __func__, context, context->preset);
     return context->preset;
 }
 
@@ -155,7 +155,7 @@
 {
     int i;
 
-    ALOGV("%s: preset: %d", __func__, preset);
+    ALOGV("%s: ctxt %p, preset: %d", __func__, context, preset);
     context->preset = preset;
     for (i=0; i<NUM_EQ_BANDS; i++)
         context->band_levels[i] =
@@ -176,7 +176,8 @@
 const char * equalizer_get_preset_name(equalizer_context_t *context,
                                        int32_t preset)
 {
-    ALOGV("%s: preset: %s", __func__, equalizer_preset_names[preset]);
+    ALOGV("%s: ctxt %p, preset: %s", __func__, context,
+                        equalizer_preset_names[preset]);
     if (preset == PRESET_CUSTOM) {
         return "Custom";
     } else {
@@ -186,7 +187,7 @@
 
 int equalizer_get_num_presets(equalizer_context_t *context)
 {
-    ALOGV("%s: presets_num: %d", __func__,
+    ALOGV("%s: ctxt %p, presets_num: %d", __func__, context,
            sizeof(equalizer_preset_names)/sizeof(char *));
     return sizeof(equalizer_preset_names)/sizeof(char *);
 }
@@ -203,7 +204,7 @@
     void *value = p->data + voffset;
     int i;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p, param %d", __func__, eq_ctxt, param);
 
     p->status = 0;
 
@@ -255,18 +256,15 @@
 
     switch (param) {
     case EQ_PARAM_NUM_BANDS:
-	ALOGV("%s: EQ_PARAM_NUM_BANDS", __func__);
         *(uint16_t *)value = (uint16_t)NUM_EQ_BANDS;
         break;
 
     case EQ_PARAM_LEVEL_RANGE:
-	ALOGV("%s: EQ_PARAM_LEVEL_RANGE", __func__);
         *(int16_t *)value = -1500;
         *((int16_t *)value + 1) = 1500;
         break;
 
     case EQ_PARAM_BAND_LEVEL:
-	ALOGV("%s: EQ_PARAM_BAND_LEVEL", __func__);
         param2 = *param_tmp;
         if (param2 >= NUM_EQ_BANDS) {
             p->status = -EINVAL;
@@ -276,7 +274,6 @@
         break;
 
     case EQ_PARAM_CENTER_FREQ:
-	ALOGV("%s: EQ_PARAM_CENTER_FREQ", __func__);
         param2 = *param_tmp;
         if (param2 >= NUM_EQ_BANDS) {
            p->status = -EINVAL;
@@ -286,7 +283,6 @@
         break;
 
     case EQ_PARAM_BAND_FREQ_RANGE:
-	ALOGV("%s: EQ_PARAM_BAND_FREQ_RANGE", __func__);
         param2 = *param_tmp;
         if (param2 >= NUM_EQ_BANDS) {
             p->status = -EINVAL;
@@ -297,25 +293,21 @@
         break;
 
     case EQ_PARAM_GET_BAND:
-	ALOGV("%s: EQ_PARAM_GET_BAND", __func__);
         param2 = *param_tmp;
         *(uint16_t *)value = (uint16_t)equalizer_get_band(eq_ctxt, param2);
         break;
 
     case EQ_PARAM_CUR_PRESET:
-	ALOGV("%s: EQ_PARAM_CUR_PRESET", __func__);
         *(uint16_t *)value = (uint16_t)equalizer_get_preset(eq_ctxt);
         break;
 
     case EQ_PARAM_GET_NUM_OF_PRESETS:
-	ALOGV("%s: EQ_PARAM_GET_NUM_OF_PRESETS", __func__);
         *(uint16_t *)value = (uint16_t)equalizer_get_num_presets(eq_ctxt);
         break;
 
     case EQ_PARAM_GET_PRESET_NAME:
-	ALOGV("%s: EQ_PARAM_GET_PRESET_NAME", __func__);
         param2 = *param_tmp;
-	ALOGV("param2: %d", param2);
+        ALOGV("%s: EQ_PARAM_GET_PRESET_NAME: param2: %d", __func__, param2);
         if (param2 >= equalizer_get_num_presets(eq_ctxt)) {
             p->status = -EINVAL;
             break;
@@ -327,7 +319,6 @@
         break;
 
     case EQ_PARAM_PROPERTIES: {
-	ALOGV("%s: EQ_PARAM_PROPERTIES", __func__);
         int16_t *prop = (int16_t *)value;
         prop[0] = (int16_t)equalizer_get_preset(eq_ctxt);
         prop[1] = (int16_t)NUM_EQ_BANDS;
@@ -357,13 +348,12 @@
     int32_t level;
     int i;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p, param %d", __func__, eq_ctxt, param);
 
     p->status = 0;
 
     switch (param) {
     case EQ_PARAM_CUR_PRESET:
-	ALOGV("EQ_PARAM_CUR_PRESET");
         preset = (int32_t)(*(uint16_t *)value);
 
         if ((preset >= equalizer_get_num_presets(eq_ctxt)) || (preset < 0)) {
@@ -373,7 +363,6 @@
         equalizer_set_preset(eq_ctxt, preset);
         break;
     case EQ_PARAM_BAND_LEVEL:
-	ALOGV("EQ_PARAM_BAND_LEVEL");
         band =  *param_tmp;
         level = (int32_t)(*(int16_t *)value);
         if (band >= NUM_EQ_BANDS) {
@@ -383,7 +372,6 @@
         equalizer_set_band_level(eq_ctxt, band, level);
         break;
     case EQ_PARAM_PROPERTIES: {
-	ALOGV("EQ_PARAM_PROPERTIES");
         int16_t *prop = (int16_t *)value;
         if ((int)prop[0] >= equalizer_get_num_presets(eq_ctxt)) {
             p->status = -EINVAL;
@@ -411,7 +399,7 @@
 
 int equalizer_set_device(effect_context_t *context,  uint32_t device)
 {
-    ALOGV("%s: device: %d", __func__, device);
+    ALOGV("%s: ctxt %p, device: 0x%x", __func__, context, device);
     equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
     eq_ctxt->device = device;
     offload_eq_set_device(&(eq_ctxt->offload_eq), device);
@@ -427,7 +415,7 @@
 
 int equalizer_init(effect_context_t *context)
 {
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p", __func__, context);
     equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
 
     context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
@@ -459,7 +447,7 @@
 {
     equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p", __func__, context);
 
     if (!offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
         offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), true);
@@ -475,7 +463,7 @@
 {
     equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s:ctxt %p", __func__, eq_ctxt);
     if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
         offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), false);
         if (eq_ctxt->ctl)
@@ -489,7 +477,7 @@
 {
     equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
 
-    ALOGV("%s: %p", __func__, output->ctl);
+    ALOGV("%s: ctxt %p, ctl %p", __func__, eq_ctxt, output->ctl);
     eq_ctxt->ctl = output->ctl;
     if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq)))
         if (eq_ctxt->ctl)
@@ -503,7 +491,7 @@
 {
     equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p", __func__, eq_ctxt);
     eq_ctxt->ctl = NULL;
     return 0;
 }
diff --git a/post_proc/reverb.c b/post_proc/reverb.c
index 60750b0..078c584 100644
--- a/post_proc/reverb.c
+++ b/post_proc/reverb.c
@@ -115,13 +115,13 @@
  */
 int16_t reverb_get_room_level(reverb_context_t *context)
 {
-    ALOGV("%s: room level: %d", __func__, context->reverb_settings.roomLevel);
+    ALOGV("%s: ctxt %p, room level: %d", __func__, context, context->reverb_settings.roomLevel);
     return context->reverb_settings.roomLevel;
 }
 
 void reverb_set_room_level(reverb_context_t *context, int16_t room_level)
 {
-    ALOGV("%s: room level: %d", __func__, room_level);
+    ALOGV("%s: ctxt %p, room level: %d", __func__, context, room_level);
     context->reverb_settings.roomLevel = room_level;
     offload_reverb_set_room_level(&(context->offload_reverb), room_level);
     if (context->ctl)
@@ -132,14 +132,14 @@
 
 int16_t reverb_get_room_hf_level(reverb_context_t *context)
 {
-    ALOGV("%s: room hf level: %d", __func__,
+    ALOGV("%s: ctxt %p, room hf level: %d", __func__, context,
           context->reverb_settings.roomHFLevel);
     return context->reverb_settings.roomHFLevel;
 }
 
 void reverb_set_room_hf_level(reverb_context_t *context, int16_t room_hf_level)
 {
-    ALOGV("%s: room hf level: %d", __func__, room_hf_level);
+    ALOGV("%s: ctxt %p, room hf level: %d", __func__, context, room_hf_level);
     context->reverb_settings.roomHFLevel = room_hf_level;
     offload_reverb_set_room_hf_level(&(context->offload_reverb), room_hf_level);
     if (context->ctl)
@@ -150,13 +150,14 @@
 
 uint32_t reverb_get_decay_time(reverb_context_t *context)
 {
-    ALOGV("%s: decay time: %d", __func__, context->reverb_settings.decayTime);
+    ALOGV("%s: ctxt %p, decay time: %d", __func__, context,
+                         context->reverb_settings.decayTime);
     return context->reverb_settings.decayTime;
 }
 
 void reverb_set_decay_time(reverb_context_t *context, uint32_t decay_time)
 {
-    ALOGV("%s: decay_time: %d", __func__, decay_time);
+    ALOGV("%s: ctxt %p, decay_time: %d", __func__, context, decay_time);
     context->reverb_settings.decayTime = decay_time;
     offload_reverb_set_decay_time(&(context->offload_reverb), decay_time);
     if (context->ctl)
@@ -167,14 +168,14 @@
 
 int16_t reverb_get_decay_hf_ratio(reverb_context_t *context)
 {
-    ALOGV("%s: decay hf ratio: %d", __func__,
+    ALOGV("%s: ctxt %p, decay hf ratio: %d", __func__, context,
           context->reverb_settings.decayHFRatio);
     return context->reverb_settings.decayHFRatio;
 }
 
 void reverb_set_decay_hf_ratio(reverb_context_t *context, int16_t decay_hf_ratio)
 {
-    ALOGV("%s: decay_hf_ratio: %d", __func__, decay_hf_ratio);
+    ALOGV("%s: ctxt %p, decay_hf_ratio: %d", __func__, context, decay_hf_ratio);
     context->reverb_settings.decayHFRatio = decay_hf_ratio;
     offload_reverb_set_decay_hf_ratio(&(context->offload_reverb), decay_hf_ratio);
     if (context->ctl)
@@ -185,13 +186,14 @@
 
 int16_t reverb_get_reverb_level(reverb_context_t *context)
 {
-    ALOGV("%s: reverb level: %d", __func__, context->reverb_settings.reverbLevel);
+    ALOGV("%s: ctxt %p, reverb level: %d", __func__, context,
+                         context->reverb_settings.reverbLevel);
     return context->reverb_settings.reverbLevel;
 }
 
 void reverb_set_reverb_level(reverb_context_t *context, int16_t reverb_level)
 {
-    ALOGV("%s: reverb level: %d", __func__, reverb_level);
+    ALOGV("%s: ctxt %p, reverb level: %d", __func__, context, reverb_level);
     context->reverb_settings.reverbLevel = reverb_level;
     offload_reverb_set_reverb_level(&(context->offload_reverb), reverb_level);
     if (context->ctl)
@@ -202,13 +204,14 @@
 
 int16_t reverb_get_diffusion(reverb_context_t *context)
 {
-    ALOGV("%s: diffusion: %d", __func__, context->reverb_settings.diffusion);
+    ALOGV("%s: ctxt %p, diffusion: %d", __func__, context,
+                        context->reverb_settings.diffusion);
     return context->reverb_settings.diffusion;
 }
 
 void reverb_set_diffusion(reverb_context_t *context, int16_t diffusion)
 {
-    ALOGV("%s: diffusion: %d", __func__, diffusion);
+    ALOGV("%s: ctxt %p, diffusion: %d", __func__, context, diffusion);
     context->reverb_settings.diffusion = diffusion;
     offload_reverb_set_diffusion(&(context->offload_reverb), diffusion);
     if (context->ctl)
@@ -219,13 +222,14 @@
 
 int16_t reverb_get_density(reverb_context_t *context)
 {
-    ALOGV("%s: density: %d", __func__, context->reverb_settings.density);
+    ALOGV("%s: ctxt %p, density: %d", __func__, context,
+                          context->reverb_settings.density);
     return context->reverb_settings.density;
 }
 
 void reverb_set_density(reverb_context_t *context, int16_t density)
 {
-    ALOGV("%s: density: %d", __func__, density);
+    ALOGV("%s: ctxt %p, density: %d", __func__, density, density);
     context->reverb_settings.density = density;
     offload_reverb_set_density(&(context->offload_reverb), density);
     if (context->ctl)
@@ -237,7 +241,7 @@
 void reverb_set_preset(reverb_context_t *context, int16_t preset)
 {
     bool enable;
-    ALOGV("%s: preset: %d", __func__, preset);
+    ALOGV("%s: ctxt %p, preset: %d", __func__, context, preset);
     context->next_preset = preset;
     offload_reverb_set_preset(&(context->offload_reverb), preset);
 
@@ -253,7 +257,7 @@
 void reverb_set_all_properties(reverb_context_t *context,
                                reverb_settings_t *reverb_settings)
 {
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p", __func__, context);
     context->reverb_settings.roomLevel = reverb_settings->roomLevel;
     context->reverb_settings.roomHFLevel = reverb_settings->roomHFLevel;
     context->reverb_settings.decayTime = reverb_settings->decayTime;
@@ -300,7 +304,7 @@
     reverb_settings_t *reverb_settings;
     int i;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p, param %d", __func__, reverb_ctxt, param);
 
     p->status = 0;
 
@@ -378,7 +382,6 @@
 
     switch (param) {
     case REVERB_PARAM_PROPERTIES:
-	ALOGV("%s: REVERB_PARAM_PROPERTIES", __func__);
         reverb_settings = (reverb_settings_t *)value;
         reverb_settings->roomLevel = reverb_get_room_level(reverb_ctxt);
         reverb_settings->roomHFLevel = reverb_get_room_hf_level(reverb_ctxt);
@@ -392,43 +395,33 @@
         reverb_settings->density = reverb_get_density(reverb_ctxt);
         break;
     case REVERB_PARAM_ROOM_LEVEL:
-	ALOGV("%s: REVERB_PARAM_ROOM_LEVEL", __func__);
         *(int16_t *)value = reverb_get_room_level(reverb_ctxt);
         break;
     case REVERB_PARAM_ROOM_HF_LEVEL:
-	ALOGV("%s: REVERB_PARAM_ROOM_HF_LEVEL", __func__);
         *(int16_t *)value = reverb_get_room_hf_level(reverb_ctxt);
         break;
     case REVERB_PARAM_DECAY_TIME:
-	ALOGV("%s: REVERB_PARAM_DECAY_TIME", __func__);
         *(uint32_t *)value = reverb_get_decay_time(reverb_ctxt);
         break;
     case REVERB_PARAM_DECAY_HF_RATIO:
-	ALOGV("%s: REVERB_PARAM_DECAY_HF_RATIO", __func__);
         *(int16_t *)value = reverb_get_decay_hf_ratio(reverb_ctxt);
         break;
     case REVERB_PARAM_REVERB_LEVEL:
-	ALOGV("%s: REVERB_PARAM_REVERB_LEVEL", __func__);
         *(int16_t *)value = reverb_get_reverb_level(reverb_ctxt);
         break;
     case REVERB_PARAM_DIFFUSION:
-	ALOGV("%s: REVERB_PARAM_DIFFUSION", __func__);
         *(int16_t *)value = reverb_get_diffusion(reverb_ctxt);
         break;
     case REVERB_PARAM_DENSITY:
-	ALOGV("%s: REVERB_PARAM_DENSITY", __func__);
         *(int16_t *)value = reverb_get_density(reverb_ctxt);
         break;
     case REVERB_PARAM_REFLECTIONS_LEVEL:
-	ALOGV("%s: REVERB_PARAM_REFLECTIONS_LEVEL", __func__);
         *(uint16_t *)value = 0;
         break;
     case REVERB_PARAM_REFLECTIONS_DELAY:
-	ALOGV("%s: REVERB_PARAM_REFLECTIONS_DELAY", __func__);
         *(uint32_t *)value = 0;
         break;
     case REVERB_PARAM_REVERB_DELAY:
-	ALOGV("%s: REVERB_PARAM_REVERB_DELAY", __func__);
         *(uint32_t *)value = 0;
         break;
     default:
@@ -452,7 +445,7 @@
     int16_t ratio;
     uint32_t time;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p, param %d", __func__, reverb_ctxt, param);
 
     p->status = 0;
 
@@ -469,41 +462,33 @@
     }
     switch (param) {
     case REVERB_PARAM_PROPERTIES:
-	ALOGV("%s: REVERB_PARAM_PROPERTIES", __func__);
         reverb_settings = (reverb_settings_t *)value;
         break;
     case REVERB_PARAM_ROOM_LEVEL:
-	ALOGV("%s: REVERB_PARAM_ROOM_LEVEL", __func__);
         level = *(int16_t *)value;
         reverb_set_room_level(reverb_ctxt, level);
         break;
     case REVERB_PARAM_ROOM_HF_LEVEL:
-	ALOGV("%s: REVERB_PARAM_ROOM_HF_LEVEL", __func__);
         level = *(int16_t *)value;
         reverb_set_room_hf_level(reverb_ctxt, level);
         break;
     case REVERB_PARAM_DECAY_TIME:
-	ALOGV("%s: REVERB_PARAM_DECAY_TIME", __func__);
         time = *(uint32_t *)value;
         reverb_set_decay_time(reverb_ctxt, time);
         break;
     case REVERB_PARAM_DECAY_HF_RATIO:
-	ALOGV("%s: REVERB_PARAM_DECAY_HF_RATIO", __func__);
         ratio = *(int16_t *)value;
         reverb_set_decay_hf_ratio(reverb_ctxt, ratio);
         break;
     case REVERB_PARAM_REVERB_LEVEL:
-	ALOGV("%s: REVERB_PARAM_REVERB_LEVEL", __func__);
         level = *(int16_t *)value;
         reverb_set_reverb_level(reverb_ctxt, level);
         break;
     case REVERB_PARAM_DIFFUSION:
-	ALOGV("%s: REVERB_PARAM_DIFFUSION", __func__);
         ratio = *(int16_t *)value;
         reverb_set_diffusion(reverb_ctxt, ratio);
         break;
     case REVERB_PARAM_DENSITY:
-	ALOGV("%s: REVERB_PARAM_DENSITY", __func__);
         ratio = *(int16_t *)value;
         reverb_set_density(reverb_ctxt, ratio);
         break;
@@ -523,7 +508,7 @@
 {
     reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
 
-    ALOGV("%s: device: %d", __func__, device);
+    ALOGV("%s: ctxt %p, device: 0x%x", __func__, reverb_ctxt, device);
     reverb_ctxt->device = device;
     offload_reverb_set_device(&(reverb_ctxt->offload_reverb), device);
     return 0;
@@ -540,6 +525,7 @@
 {
     reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
 
+    ALOGV("%s: ctxt %p", __func__, reverb_ctxt);
     context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
     /*
        FIXME: channel mode is mono for auxiliary. is it needed for offload ?
@@ -577,7 +563,7 @@
 {
     reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p", __func__, reverb_ctxt);
 
     if (!offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb)))
         offload_reverb_set_enable_flag(&(reverb_ctxt->offload_reverb), true);
@@ -588,7 +574,7 @@
 {
     reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p", __func__, reverb_ctxt);
     if (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb))) {
         offload_reverb_set_enable_flag(&(reverb_ctxt->offload_reverb), false);
         if (reverb_ctxt->ctl)
@@ -603,7 +589,7 @@
 {
     reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p, ctl %p", __func__, reverb_ctxt, output->ctl);
     reverb_ctxt->ctl = output->ctl;
     if (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb))) {
         if (reverb_ctxt->ctl && reverb_ctxt->preset) {
@@ -620,7 +606,7 @@
 {
     reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p", __func__, reverb_ctxt);
     reverb_ctxt->ctl = NULL;
     return 0;
 }
diff --git a/post_proc/virtualizer.c b/post_proc/virtualizer.c
index 8f6d000..6afbdfb 100644
--- a/post_proc/virtualizer.c
+++ b/post_proc/virtualizer.c
@@ -47,13 +47,13 @@
 
 int virtualizer_get_strength(virtualizer_context_t *context)
 {
-    ALOGV("%s: strength: %d", __func__, context->strength);
+    ALOGV("%s: ctxt %p, strength: %d", __func__, context, context->strength);
     return context->strength;
 }
 
 int virtualizer_set_strength(virtualizer_context_t *context, uint32_t strength)
 {
-    ALOGV("%s: strength: %d", __func__, strength);
+    ALOGV("%s: ctxt %p, strength: %d", __func__, context, strength);
     context->strength = strength;
 
     offload_virtualizer_set_strength(&(context->offload_virt), strength);
@@ -74,7 +74,7 @@
     void *value = p->data + voffset;
     int i;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p, param %d", __func__, virt_ctxt, param);
 
     p->status = 0;
 
@@ -100,12 +100,10 @@
 
     switch (param) {
     case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
-	ALOGV("%s: VIRTUALIZER_PARAM_STRENGTH_SUPPORTED", __func__);
         *(uint32_t *)value = 1;
         break;
 
     case VIRTUALIZER_PARAM_STRENGTH:
-	ALOGV("%s: VIRTUALIZER_PARAM_STRENGTH", __func__);
         *(int16_t *)value = virtualizer_get_strength(virt_ctxt);
         break;
 
@@ -127,13 +125,12 @@
     int32_t param = *param_tmp++;
     uint32_t strength;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p, param %d", __func__, virt_ctxt, param);
 
     p->status = 0;
 
     switch (param) {
     case VIRTUALIZER_PARAM_STRENGTH:
-	ALOGV("%s VIRTUALIZER_PARAM_STRENGTH", __func__);
         strength = (uint32_t)(*(int16_t *)value);
         virtualizer_set_strength(virt_ctxt, strength);
         break;
@@ -149,13 +146,14 @@
 {
     virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
 
-    ALOGV("%s: device: %d", __func__, device);
+    ALOGV("%s: ctxt %p, device: 0x%x", __func__, virt_ctxt, device);
     virt_ctxt->device = device;
     if((device == AUDIO_DEVICE_OUT_SPEAKER) ||
        (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT) ||
        (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER) ||
        (device == AUDIO_DEVICE_OUT_PROXY) ||
        (device == AUDIO_DEVICE_OUT_AUX_DIGITAL) ||
+       (device == AUDIO_DEVICE_OUT_USB_ACCESSORY) ||
        (device == AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET)) {
         if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) {
             offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
@@ -164,6 +162,7 @@
                 offload_virtualizer_send_params(virt_ctxt->ctl,
                                               virt_ctxt->offload_virt,
                                               OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG);
+            ALOGI("%s: ctxt %p, disabled based on device", __func__, virt_ctxt);
         }
     } else {
         if (!offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) &&
@@ -189,7 +188,7 @@
 
 int virtualizer_init(effect_context_t *context)
 {
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p", __func__, context);
     virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
 
     context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
@@ -220,7 +219,7 @@
 {
     virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p, strength %d", __func__, virt_ctxt, virt_ctxt->strength);
 
     if (!offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)) &&
         !(virt_ctxt->temp_disabled)) {
@@ -238,7 +237,7 @@
 {
     virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p", __func__, virt_ctxt);
     if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt))) {
         offload_virtualizer_set_enable_flag(&(virt_ctxt->offload_virt), false);
         if (virt_ctxt->ctl)
@@ -253,7 +252,7 @@
 {
     virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p, ctl %p", __func__, virt_ctxt, output->ctl);
     virt_ctxt->ctl = output->ctl;
     if (offload_virtualizer_get_enable_flag(&(virt_ctxt->offload_virt)))
         if (virt_ctxt->ctl)
@@ -267,7 +266,7 @@
 {
     virtualizer_context_t *virt_ctxt = (virtualizer_context_t *)context;
 
-    ALOGV("%s", __func__);
+    ALOGV("%s: ctxt %p", __func__, virt_ctxt);
     virt_ctxt->ctl = NULL;
     return 0;
 }
diff --git a/visualizer/offload_visualizer.c b/visualizer/offload_visualizer.c
index 95b4687..94c44a5 100644
--- a/visualizer/offload_visualizer.c
+++ b/visualizer/offload_visualizer.c
@@ -431,6 +431,11 @@
     }
 
     output_context_t *out_ctxt = (output_context_t *)malloc(sizeof(output_context_t));
+    if (out_ctxt == NULL) {
+        ALOGE("%s fail to allocate memory", __func__);
+        ret = -ENOMEM;
+        goto exit;
+    }
     out_ctxt->handle = output;
     list_init(&out_ctxt->effects_list);
 
@@ -927,6 +932,10 @@
     if (memcmp(uuid, &visualizer_descriptor.uuid, sizeof(effect_uuid_t)) == 0) {
         visualizer_context_t *visu_ctxt = (visualizer_context_t *)calloc(1,
                                                                      sizeof(visualizer_context_t));
+        if (visu_ctxt == NULL) {
+            ALOGE("%s fail to allocate memory", __func__);
+            return -ENOMEM;
+        }
         context = (effect_context_t *)visu_ctxt;
         context->ops.init = visualizer_init;
         context->ops.reset = visualizer_reset;
diff --git a/voice_processing/voice_processing.c b/voice_processing/voice_processing.c
index b8b1e1b..1d18a3d 100644
--- a/voice_processing/voice_processing.c
+++ b/voice_processing/voice_processing.c
@@ -408,6 +408,10 @@
     }
 
     session = (struct session_s *)calloc(1, sizeof(struct session_s));
+    if (session == NULL) {
+        ALOGE("get_session() fail to allocate memory");
+        return NULL;
+    }
     session_init(session);
     session->id = sessionId;
     session->io = ioId;
@@ -682,6 +686,10 @@
         return -EINVAL;
     }
     id = uuid_to_id(&desc->type);
+    if (id >= NUM_ID) {
+        ALOGW("lib_create: fx not found type: %08x", desc->type.timeLow);
+        return -EINVAL;
+    }
 
     session = get_session(id, sessionId, ioId);