audio: Add dedicated streams for VoIP call

Add dedicated streams for VoIP usecase. This includes adding
a new direct output and input types that use audio playback
and record paths respectively. It falls back to compress VoIP
wherever this feature is not applicable.

Change-Id: I9b7654819b9d8deb00f8888fbfc31f0fbbae5266
diff --git a/configs/sdm845/audio_output_policy.conf b/configs/sdm845/audio_output_policy.conf
index 76039c7..877b6a5 100644
--- a/configs/sdm845/audio_output_policy.conf
+++ b/configs/sdm845/audio_output_policy.conf
@@ -25,6 +25,13 @@
     bit_width 16
     app_type 69943
   }
+  voip_rx {
+    flags AUDIO_OUTPUT_FLAG_VOIP_RX|AUDIO_OUTPUT_FLAG_DIRECT
+    formats AUDIO_FORMAT_PCM_16_BIT
+    sampling_rates 8000|16000|32000|48000
+    bit_width 16
+    app_type 69946
+  }
   deep_buffer {
     flags AUDIO_OUTPUT_FLAG_DEEP_BUFFER
     formats AUDIO_FORMAT_PCM_16_BIT
diff --git a/configs/sdm845/audio_platform_info.xml b/configs/sdm845/audio_platform_info.xml
index 52fcb1f..abbb294 100644
--- a/configs/sdm845/audio_platform_info.xml
+++ b/configs/sdm845/audio_platform_info.xml
@@ -65,6 +65,8 @@
         <usecase name="USECASE_AUDIO_RECORD_LOW_LATENCY" type="in" id="17" />
         <usecase name="USECASE_AUDIO_PLAYBACK_ULL" type="out" id="17" />
         <usecase name="USECASE_AUDIO_PLAYBACK_EXT_DISP_SILENCE" type="out" id="27" />
+        <usecase name="USECASE_AUDIO_PLAYBACK_VOIP" type="out" id="16" />
+        <usecase name="USECASE_AUDIO_RECORD_VOIP" type="in" id="16" />
     </pcm_ids>
     <config_params>
         <param key="spkr_1_tz_name" value="wsatz.13"/>
diff --git a/configs/sdm845/mixer_paths_tavil.xml b/configs/sdm845/mixer_paths_tavil.xml
index decaa1f..8df0cbb 100644
--- a/configs/sdm845/mixer_paths_tavil.xml
+++ b/configs/sdm845/mixer_paths_tavil.xml
@@ -72,6 +72,9 @@
     <ctl name="MultiMedia8 Mixer SLIM_0_TX" value="0" />
     <ctl name="MultiMedia8 Mixer SLIM_4_TX" value="0" />
     <ctl name="MultiMedia8 Mixer SLIM_7_TX" value="0" />
+    <ctl name="MultiMedia10 Mixer SLIM_0_TX" value="0" />
+    <ctl name="MultiMedia10 Mixer SLIM_7_TX" value="0" />
+    <ctl name="MultiMedia10 Mixer AFE_PCM_TX" value="0" />
     <ctl name="DISPLAY_PORT Mixer MultiMedia1" value="0" />
     <ctl name="DISPLAY_PORT Mixer MultiMedia2" value="0" />
     <ctl name="DISPLAY_PORT Mixer MultiMedia3" value="0" />
@@ -153,6 +156,7 @@
     <ctl name="MultiMedia1 Mixer USB_AUDIO_TX" value="0" />
     <ctl name="MultiMedia5 Mixer USB_AUDIO_TX" value="0" />
     <ctl name="MultiMedia8 Mixer USB_AUDIO_TX" value="0" />
+    <ctl name="MultiMedia10 Mixer USB_AUDIO_TX" value="0" />
     <ctl name="MultiMedia6 Mixer SLIM_0_TX" value="0" />
     <ctl name="SLIM_2_RX Format" value="UNPACKED" />
     <ctl name="SLIM_2_RX SampleRate" value="KHZ_48" />
@@ -1517,6 +1521,62 @@
         <ctl name="VoiceMMode2_Tx Mixer USB_AUDIO_TX_MMode2" value="1" />
     </path>
 
+    <!-- VoIP Rx settings -->
+    <path name="audio-playback-voip">
+        <ctl name="SLIMBUS_0_RX Audio Mixer MultiMedia10" value="1" />
+    </path>
+
+    <path name="audio-playback-voip headphones">
+        <ctl name="SLIMBUS_6_RX Audio Mixer MultiMedia10" value="1" />
+    </path>
+
+    <path name="audio-playback-voip bt-sco">
+        <ctl name="SLIMBUS_7_RX Mixer MultiMedia10" value="1" />
+    </path>
+
+    <path name="audio-playback-voip bt-sco-wb">
+        <ctl name="BT SampleRate" value="KHZ_16" />
+        <path name="audio-playback-voip bt-sco" />
+    </path>
+
+    <path name="audio-playback-voip afe-proxy">
+        <ctl name="AFE_PCM_RX Mixer MultiMedia10" value="1" />
+    </path>
+
+    <path name="audio-playback-voip usb-headphones">
+        <ctl name="USB_AUDIO_RX Mixer MultiMedia10" value="1" />
+    </path>
+
+    <path name="audio-playback-voip usb-headset">
+        <ctl name="USB_AUDIO_RX Mixer MultiMedia10" value="1" />
+    </path>
+
+    <path name="audio-playback-voip display-port">
+        <ctl name="DISPLAY_PORT Mixer MultiMedia10" value="1" />
+    </path>
+
+    <path name="audio-playback-voip speaker-and-display-port">
+        <path name="audio-playback-voip display-port" />
+        <path name="audio-playback-voip" />
+    </path>
+
+    <!-- VoIP Tx settings -->
+    <path name="audio-record-voip">
+        <ctl name="MultiMedia10 Mixer SLIM_0_TX" value="1" />
+    </path>
+
+    <path name="audio-record-voip usb-headset-mic">
+        <ctl name="MultiMedia10 Mixer USB_AUDIO_TX" value="1" />
+    </path>
+
+    <path name="audio-record-voip bt-sco">
+        <ctl name="MultiMedia10 Mixer SLIM_7_TX" value="1" />
+    </path>
+
+    <path name="audio-record-voip bt-sco-wb">
+        <ctl name="BT SampleRate" value="KHZ_16" />
+        <path name="audio-record-voip bt-sco" />
+    </path>
    <path name="spkr-rx-calib">
         <ctl name="SLIMBUS_DL_HL Switch"  value="1" />
     </path>
diff --git a/configs/sdm845/sdm845.mk b/configs/sdm845/sdm845.mk
index 5cdc6f0..56f248b 100644
--- a/configs/sdm845/sdm845.mk
+++ b/configs/sdm845/sdm845.mk
@@ -6,7 +6,7 @@
 ifneq ($(TARGET_USES_AOSP_FOR_AUDIO), true)
 USE_CUSTOM_AUDIO_POLICY := 1
 AUDIO_FEATURE_ENABLED_COMPRESS_CAPTURE := false
-AUDIO_FEATURE_ENABLED_COMPRESS_VOIP := true
+AUDIO_FEATURE_ENABLED_COMPRESS_VOIP := false
 AUDIO_FEATURE_ENABLED_EXTN_FORMATS := true
 AUDIO_FEATURE_ENABLED_EXTN_FLAC_DECODER := true
 AUDIO_FEATURE_ENABLED_EXTN_RESAMPLER := true
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c
index 9b0df8e..9f78a0c 100644
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.c
@@ -81,6 +81,8 @@
 #define SND_AUDIOCODEC_TRUEHD 0x00000023
 #endif
 
+#define APP_TYPE_VOIP_AUDIO 0x1113A
+
 #ifdef AUDIO_EXTERNAL_HDMI_ENABLED
 #define PROFESSIONAL        (1<<0)      /* 0 = consumer, 1 = professional */
 #define NON_LPCM            (1<<1)      /* 0 = audio, 1 = non-audio */
@@ -119,6 +121,7 @@
 #endif
     STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH),
     STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_TIMESTAMP),
+    STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_VOIP_RX),
     STRING_TO_ENUM(AUDIO_INPUT_FLAG_NONE),
     STRING_TO_ENUM(AUDIO_INPUT_FLAG_FAST),
     STRING_TO_ENUM(AUDIO_INPUT_FLAG_HW_HOTWORD),
@@ -786,7 +789,10 @@
         ALOGV("%s Selected apptype: %d", __func__, usecase->stream.out->app_type_cfg.app_type);
         break;
     case PCM_CAPTURE:
-        audio_extn_utils_update_stream_input_app_type_cfg(adev->platform,
+        if (usecase->id == USECASE_AUDIO_RECORD_VOIP)
+            usecase->stream.in->app_type_cfg.app_type = APP_TYPE_VOIP_AUDIO;
+        else
+            audio_extn_utils_update_stream_input_app_type_cfg(adev->platform,
                                                 &adev->streams_input_cfg_list,
                                                 usecase->stream.in->device,
                                                 usecase->stream.in->flags,
@@ -830,6 +836,7 @@
         (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY) &&
         (usecase->id != USECASE_AUDIO_PLAYBACK_MULTI_CH) &&
         (usecase->id != USECASE_AUDIO_PLAYBACK_ULL) &&
+        (usecase->id != USECASE_AUDIO_PLAYBACK_VOIP) &&
         (!is_offload_usecase(usecase->id)) &&
         (usecase->type != PCM_CAPTURE)) {
         ALOGV("%s: a rx/tx/loopback path where app type cfg is not required %d", __func__, usecase->id);
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 9bee430..af3a6c5 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -86,6 +86,7 @@
 /*DIRECT PCM has same buffer sizes as DEEP Buffer*/
 #define DIRECT_PCM_NUM_FRAGMENTS 2
 #define COMPRESS_PLAYBACK_VOLUME_MAX 0x2000
+#define VOIP_PLAYBACK_VOLUME_MAX 0x2000
 #define DSD_VOLUME_MIN_DB (-110)
 
 #define PROXY_OPEN_RETRY_COUNT           100
@@ -100,6 +101,19 @@
 #endif
 
 #define ULL_PERIOD_SIZE (DEFAULT_OUTPUT_SAMPLING_RATE/1000)
+#define DEFAULT_VOIP_BUF_DURATION_MS 20
+#define DEFAULT_VOIP_BIT_DEPTH_BYTE sizeof(int16_t)
+#define DEFAULT_VOIP_SAMP_RATE 48000
+
+#define VOIP_IO_BUF_SIZE(SR, DURATION_MS, BIT_DEPTH) (SR)/1000 * DURATION_MS * BIT_DEPTH
+
+struct pcm_config default_pcm_config_voip_copp = {
+    .channels = 1,
+    .rate = DEFAULT_VOIP_SAMP_RATE, /* changed when the stream is opened */
+    .period_size = VOIP_IO_BUF_SIZE(DEFAULT_VOIP_SAMP_RATE, DEFAULT_VOIP_BUF_DURATION_MS, DEFAULT_VOIP_BIT_DEPTH_BYTE)/2,
+    .period_count = 2,
+    .format = PCM_FORMAT_S16_LE,
+};
 
 static unsigned int configured_low_latency_capture_period_size =
         LOW_LATENCY_CAPTURE_PERIOD_SIZE;
@@ -263,8 +277,12 @@
     [USECASE_AUDIO_PLAYBACK_AFE_PROXY] = "afe-proxy-playback",
     [USECASE_AUDIO_RECORD_AFE_PROXY] = "afe-proxy-record",
     [USECASE_AUDIO_PLAYBACK_EXT_DISP_SILENCE] = "silence-playback",
+
     /* Transcode loopback cases */
     [USECASE_AUDIO_TRANSCODE_LOOPBACK] = "audio-transcode-loopback",
+
+    [USECASE_AUDIO_PLAYBACK_VOIP] = "audio-playback-voip",
+    [USECASE_AUDIO_RECORD_VOIP] = "audio-record-voip",
 };
 
 static const audio_usecase_t offload_usecases[] = {
@@ -2714,6 +2732,8 @@
             return out->compr_config.fragment_size;
     } else if(out->usecase == USECASE_COMPRESS_VOIP_CALL)
         return voice_extn_compress_voip_out_get_buffer_size(out);
+    else if(out->usecase == USECASE_AUDIO_PLAYBACK_VOIP)
+        return VOIP_IO_BUF_SIZE(out->config.rate, DEFAULT_VOIP_BUF_DURATION_MS, DEFAULT_VOIP_BIT_DEPTH_BYTE);
     else if (is_offload_usecase(out->usecase) &&
              out->flags == AUDIO_OUTPUT_FLAG_DIRECT)
         return out->hal_fragment_size;
@@ -3305,6 +3325,26 @@
             mixer_ctl_set_array(ctl, volume, sizeof(volume)/sizeof(volume[0]));
             return 0;
         }
+    } else if (out->usecase == USECASE_AUDIO_PLAYBACK_VOIP) {
+        char mixer_ctl_name[] = "App Type Gain";
+        struct audio_device *adev = out->dev;
+        struct mixer_ctl *ctl;
+        uint32_t set_values[4];
+
+        ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
+        if (!ctl) {
+            ALOGE("%s: Could not get ctl for mixer cmd - %s",
+                   __func__, mixer_ctl_name);
+            return -EINVAL;
+        }
+
+        set_values[0] = 0; //0: Rx Session 1:Tx Session
+        set_values[1] = out->app_type_cfg.app_type;
+        set_values[2] = (int)(left * VOIP_PLAYBACK_VOLUME_MAX);
+        set_values[3] = (int)(right * VOIP_PLAYBACK_VOLUME_MAX);
+
+        mixer_ctl_set_array(ctl, set_values, ARRAY_SIZE(set_values));
+        return 0;
     }
 
     return -ENOSYS;
@@ -3826,6 +3866,8 @@
 
     if(in->usecase == USECASE_COMPRESS_VOIP_CALL)
         return voice_extn_compress_voip_in_get_buffer_size(in);
+    else if(in->usecase == USECASE_AUDIO_RECORD_VOIP)
+        return VOIP_IO_BUF_SIZE(in->config.rate, DEFAULT_VOIP_BUF_DURATION_MS, DEFAULT_VOIP_BIT_DEPTH_BYTE);
     else if(audio_extn_compr_cap_usecase_supported(in->usecase))
         return audio_extn_compr_cap_get_buffer_size(in->config.format);
     else if(audio_extn_cin_attached_usecase(in->usecase))
@@ -4266,6 +4308,19 @@
     }
 
     /* Init use case and pcm_config */
+#ifndef COMPRESS_VOIP_ENABLED
+    if (out->flags == (AUDIO_OUTPUT_FLAG_DIRECT | AUDIO_OUTPUT_FLAG_VOIP_RX) &&
+        (out->sample_rate == 8000 || out->sample_rate == 16000 ||
+         out->sample_rate == 32000 || out->sample_rate == 48000)) {
+        out->supported_channel_masks[0] = AUDIO_CHANNEL_OUT_MONO;
+        out->channel_mask = AUDIO_CHANNEL_OUT_MONO;
+        out->usecase = USECASE_AUDIO_PLAYBACK_VOIP;
+
+        out->config = default_pcm_config_voip_copp;
+        out->config.period_size = VOIP_IO_BUF_SIZE(out->sample_rate, DEFAULT_VOIP_BUF_DURATION_MS, DEFAULT_VOIP_BIT_DEPTH_BYTE)/2;
+        out->config.rate = out->sample_rate;
+
+#else
     if ((out->dev->mode == AUDIO_MODE_IN_COMMUNICATION || voice_extn_compress_voip_is_active(out->dev)) &&
                (out->flags == (AUDIO_OUTPUT_FLAG_DIRECT | AUDIO_OUTPUT_FLAG_VOIP_RX)) &&
                (voice_extn_compress_voip_is_config_supported(config))) {
@@ -4275,6 +4330,7 @@
                   __func__, ret);
             goto error_open;
         }
+#endif
     } else if ((out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) ||
                (out->flags == AUDIO_OUTPUT_FLAG_DIRECT)) {
         pthread_mutex_lock(&adev->lock);
@@ -5313,6 +5369,17 @@
             in->config.period_size = buffer_size / frame_size;
         }
 
+#ifndef COMPRESS_VOIP_ENABLED
+        if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) &&
+            (in->config.rate == 8000 || in->config.rate == 16000 ||
+             in->config.rate == 32000 || in->config.rate == 48000) &&
+            (audio_channel_count_from_in_mask(in->channel_mask) == 1)) {
+
+            in->usecase = USECASE_AUDIO_RECORD_VOIP;
+            in->config = default_pcm_config_voip_copp;
+            in->config.period_size = VOIP_IO_BUF_SIZE(in->sample_rate, DEFAULT_VOIP_BUF_DURATION_MS, DEFAULT_VOIP_BIT_DEPTH_BYTE)/2;
+            in->config.rate = in->sample_rate;
+#else
         if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) &&
                (in->dev->mode == AUDIO_MODE_IN_COMMUNICATION || voice_extn_compress_voip_is_active(in->dev)) &&
                (voice_extn_compress_voip_is_format_supported(in->format)) &&
@@ -5320,6 +5387,7 @@
                 in->config.rate == 32000 || in->config.rate == 48000) &&
                (audio_channel_count_from_in_mask(in->channel_mask) == 1)) {
             voice_extn_compress_voip_open_input_stream(in);
+#endif
         }
     }
 
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index 9c13d99..4c9f83f 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -133,6 +133,8 @@
     USECASE_AUDIO_RECORD_LOW_LATENCY,
     USECASE_AUDIO_RECORD_FM_VIRTUAL,
 
+    USECASE_AUDIO_PLAYBACK_VOIP,
+    USECASE_AUDIO_RECORD_VOIP,
     /* Voice usecase */
     USECASE_VOICE_CALL,
 
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 2836974..b0a4f85 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -365,6 +365,8 @@
                                         AFE_PROXY_RECORD_PCM_DEVICE},
     [USECASE_AUDIO_PLAYBACK_EXT_DISP_SILENCE] = {MULTIMEDIA9_PCM_DEVICE, -1},
     [USECASE_AUDIO_TRANSCODE_LOOPBACK] = {TRANSCODE_LOOPBACK_RX_DEV_ID, TRANSCODE_LOOPBACK_TX_DEV_ID},
+    [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE, AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
+    [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE, AUDIO_RECORD_VOIP_PCM_DEVICE},
 
 };
 
@@ -6736,9 +6738,7 @@
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
 
-            if (usecase != NULL &&
-                usecase->type == PCM_PLAYBACK &&
-                usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
+            if (usecase != NULL && usecase->type == PCM_PLAYBACK) {
                 int new_snd_device[2] = {0};
                 int i, num_devices = 1;
 
diff --git a/hal/msm8916/platform.h b/hal/msm8916/platform.h
index f8c7280..17bd8f2 100644
--- a/hal/msm8916/platform.h
+++ b/hal/msm8916/platform.h
@@ -330,6 +330,8 @@
 #define PLAYBACK_OFFLOAD_DEVICE 9
 #define PLAYBACK_OFFLOAD_DEVICE2 24
 #define COMPRESS_VOIP_CALL_PCM_DEVICE 3
+#define AUDIO_PLAYBACK_VOIP_PCM_DEVICE 16
+#define AUDIO_RECORD_VOIP_PCM_DEVICE 16
 
 /* Define macro for Internal FM volume mixer */
 #ifdef PLATFORM_MSMFALCON
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index d423919..3ffacb8 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -345,6 +345,9 @@
     [USECASE_AUDIO_PLAYBACK_EXT_DISP_SILENCE] = {MULTIMEDIA9_PCM_DEVICE, -1},
     [USECASE_AUDIO_TRANSCODE_LOOPBACK] = {TRANSCODE_LOOPBACK_RX_DEV_ID, TRANSCODE_LOOPBACK_TX_DEV_ID},
 
+    [USECASE_AUDIO_PLAYBACK_VOIP] = {AUDIO_PLAYBACK_VOIP_PCM_DEVICE, AUDIO_PLAYBACK_VOIP_PCM_DEVICE},
+    [USECASE_AUDIO_RECORD_VOIP] = {AUDIO_RECORD_VOIP_PCM_DEVICE, AUDIO_RECORD_VOIP_PCM_DEVICE},
+
 };
 
 /* Array to store sound devices */
@@ -984,9 +987,7 @@
         list_for_each(node, &adev->usecase_list) {
             usecase = node_to_item(node, struct audio_usecase, list);
 
-            if (usecase != NULL &&
-                usecase->type == PCM_PLAYBACK &&
-                usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
+            if (usecase != NULL && usecase->type == PCM_PLAYBACK) {
                 int new_snd_device[2] = {0};
                 int i, num_devices = 1;
 
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index fca940f..9695e36 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -374,6 +374,8 @@
 #endif
 
 #define COMPRESS_VOIP_CALL_PCM_DEVICE 3
+#define AUDIO_PLAYBACK_VOIP_PCM_DEVICE 16
+#define AUDIO_RECORD_VOIP_PCM_DEVICE 16
 
 #ifdef PLATFORM_MSM8610
 #define LOWLATENCY_PCM_DEVICE 12
diff --git a/hal/voice_extn/voice_extn.h b/hal/voice_extn/voice_extn.h
index 2f879bd..7f10d0c 100644
--- a/hal/voice_extn/voice_extn.h
+++ b/hal/voice_extn/voice_extn.h
@@ -289,7 +289,6 @@
     return false;
 }
 
-#define AUDIO_OUTPUT_FLAG_VOIP_RX 0x800
 #endif
 
 #endif //VOICE_EXTN_H
diff --git a/post_proc/volume_listener.c b/post_proc/volume_listener.c
index b8aa893..635fe23 100644
--- a/post_proc/volume_listener.c
+++ b/post_proc/volume_listener.c
@@ -45,7 +45,8 @@
 #define VOL_FLAG ( EFFECT_FLAG_TYPE_INSERT | \
                    EFFECT_FLAG_VOLUME_IND | \
                    EFFECT_FLAG_DEVICE_IND | \
-                   EFFECT_FLAG_OFFLOAD_SUPPORTED)
+                   EFFECT_FLAG_OFFLOAD_SUPPORTED | \
+                   EFFECT_FLAG_NO_PROCESS)
 
 #define PRINT_STREAM_TYPE(i) ALOGV("descriptor found and is of stream type %s ",\
                                                             i == MUSIC?"MUSIC": \
@@ -212,6 +213,18 @@
 /*
  *  Local functions
  */
+static bool verify_context(vol_listener_context_t *context)
+{
+    if (context->stream_type == VC_CALL)
+        return true;
+    else {
+        if (context->dev_id & AUDIO_DEVICE_OUT_SPEAKER)
+            return true;
+        else
+            return false;
+    }
+}
+
 static void dump_list_l()
 {
     struct listnode *node;
@@ -257,7 +270,7 @@
     list_for_each(node, &vol_effect_list) {
         context = node_to_item(node, struct vol_listener_context_s, effect_list_node);
         if ((context->state == VOL_LISTENER_STATE_ACTIVE) &&
-            (context->dev_id & AUDIO_DEVICE_OUT_SPEAKER) &&
+            verify_context(context) &&
             (new_vol < (context->left_vol + context->right_vol) / 2)) {
             new_vol = (context->left_vol + context->right_vol) / 2;
         }
@@ -462,8 +475,8 @@
 
         // After changing the state and if device is speaker
         // recalculate gain dep cal level
-        if (context->dev_id & AUDIO_DEVICE_OUT_SPEAKER) {
-                check_and_set_gain_dep_cal();
+        if (verify_context(context)) {
+            check_and_set_gain_dep_cal();
         }
 
         break;
@@ -489,7 +502,7 @@
 
         // After changing the state and if device is speaker
         // recalculate gain dep cal level
-        if (context->dev_id & AUDIO_DEVICE_OUT_SPEAKER) {
+        if (verify_context(context)) {
             check_and_set_gain_dep_cal();
         }
 
@@ -519,10 +532,13 @@
             ALOGV("%s :: EFFECT_CMD_SET_DEVICE: (current/new) device (0x%x / 0x%x)",
                    __func__, context->dev_id, new_device);
 
-            // check if old or new device is speaker
-            if ((context->dev_id & AUDIO_DEVICE_OUT_SPEAKER) ||
-                (new_device & AUDIO_DEVICE_OUT_SPEAKER)) {
+            // check if old or new device is speaker for playback usecase
+            if (context->stream_type == VC_CALL)
                 recompute_gain_dep_cal_Level = true;
+            else {
+                if (context->dev_id & AUDIO_DEVICE_OUT_SPEAKER ||
+                    new_device & AUDIO_DEVICE_OUT_SPEAKER)
+                    recompute_gain_dep_cal_Level = true;
             }
 
             context->dev_id = new_device;
@@ -546,7 +562,7 @@
                 goto exit;
             }
 
-            if (context->dev_id & AUDIO_DEVICE_OUT_SPEAKER) {
+            if (verify_context(context)) {
                 recompute_gain_dep_cal_Level = true;
             }
 
@@ -771,7 +787,7 @@
             ALOGV("--- Found something to remove ---");
             list_remove(node);
             PRINT_STREAM_TYPE(context->stream_type);
-            if (context->dev_id & AUDIO_DEVICE_OUT_SPEAKER) {
+            if (verify_context(context)) {
                 recompute_flag = true;
             }
             list_remove(&context->effect_list_node);
diff --git a/voice_processing/voice_processing.c b/voice_processing/voice_processing.c
index e23cfe1..2d5d93d 100644
--- a/voice_processing/voice_processing.c
+++ b/voice_processing/voice_processing.c
@@ -91,7 +91,8 @@
         { 0x7b491460, 0x8d4d, 0x11e0, 0xbd61, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, // type
         { 0x0f8d0d2a, 0x59e5, 0x45fe, 0xb6e4, { 0x24, 0x8c, 0x8a, 0x79, 0x91, 0x09 } }, // uuid
         EFFECT_CONTROL_API_VERSION,
-        (EFFECT_FLAG_TYPE_PRE_PROC|EFFECT_FLAG_DEVICE_IND|EFFECT_FLAG_HW_ACC_TUNNEL),
+        (EFFECT_FLAG_TYPE_PRE_PROC|EFFECT_FLAG_DEVICE_IND|EFFECT_FLAG_HW_ACC_TUNNEL|
+         EFFECT_FLAG_OFFLOAD_SUPPORTED),
         0,
         0,
         "Acoustic Echo Canceler",
@@ -103,7 +104,8 @@
         { 0x58b4b260, 0x8e06, 0x11e0, 0xaa8e, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, // type
         { 0x1d97bb0b, 0x9e2f, 0x4403, 0x9ae3, { 0x58, 0xc2, 0x55, 0x43, 0x06, 0xf8 } }, // uuid
         EFFECT_CONTROL_API_VERSION,
-        (EFFECT_FLAG_TYPE_PRE_PROC|EFFECT_FLAG_DEVICE_IND|EFFECT_FLAG_HW_ACC_TUNNEL),
+        (EFFECT_FLAG_TYPE_PRE_PROC|EFFECT_FLAG_DEVICE_IND|EFFECT_FLAG_HW_ACC_TUNNEL|
+         EFFECT_FLAG_OFFLOAD_SUPPORTED),
         0,
         0,
         "Noise Suppression",