hal: add input source check to open compress voip input

Compress voip input requires input source type to be of
AUDIO_SOURCE_VOICE_COMMUNICATION. Move the opening of compress
voip input to in_set_parameters() function which is the first
place in HAL where the source type information is available.

Change-Id: I3758eba6049ccd4f1a4465ef264420d9afb6a795
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 09b9bea..cfcc5a5 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -1835,6 +1835,18 @@
         /* no audio source uses val == 0 */
         if ((in->source != val) && (val != 0)) {
             in->source = val;
+            if ((in->source == AUDIO_SOURCE_VOICE_COMMUNICATION) &&
+                (in->dev->mode == AUDIO_MODE_IN_COMMUNICATION) &&
+                (voice_extn_compress_voip_is_format_supported(in->format)) &&
+                (in->config.rate == 8000 || in->config.rate == 16000) &&
+                (popcount(in->channel_mask) == 1)) {
+                ret = voice_extn_compress_voip_open_input_stream(in);
+                if (ret != 0) {
+                    ALOGE("%s: Compress voip input cannot be opened, error:%d",
+                          __func__, ret);
+                    goto done;
+                }
+            }
         }
     }
 
@@ -1849,6 +1861,7 @@
         }
     }
 
+done:
     pthread_mutex_unlock(&adev->lock);
     pthread_mutex_unlock(&in->lock);
 
@@ -2448,16 +2461,7 @@
     in->config.rate = config->sample_rate;
     in->format = config->format;
 
-    if ((in->dev->mode == AUDIO_MODE_IN_COMMUNICATION) &&
-        (voice_extn_compress_voip_is_config_supported(config))) {
-        ret = voice_extn_compress_voip_open_input_stream(in);
-        if (ret != 0)
-        {
-            ALOGE("%s: Compress voip input cannot be opened, error:%d",
-                  __func__, ret);
-            goto err_open;
-        }
-    } else if (channel_count == 6) {
+    if (channel_count == 6) {
         if(audio_extn_ssr_get_enabled()) {
             if(audio_extn_ssr_init(adev, in)) {
                 ALOGE("%s: audio_extn_ssr_init failed", __func__);
@@ -2469,7 +2473,8 @@
             goto err_open;
         }
     } else if (audio_extn_compr_cap_enabled() &&
-            audio_extn_compr_cap_format_supported(config->format)) {
+            audio_extn_compr_cap_format_supported(config->format) &&
+            (in->dev->mode != AUDIO_MODE_IN_COMMUNICATION)) {
         audio_extn_compr_cap_init(adev, in);
     } else {
         in->config.channels = channel_count;