hal: Limit multichannel clips >48khz to 48Khz

-Configuring copp and backend at 48Khz for multichannel
clips > 48khz
-This is to address ADSP MIPS concern for playback of multichannel
 clip with sample rate > 48khz with pp (SA+ or SA+_HPX)

Change-Id: Ic010ce212011519e729601d067f8ddb6737c6b28
diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h
index 98b2672..e7e2418 100644
--- a/hal/audio_extn/audio_extn.h
+++ b/hal/audio_extn/audio_extn.h
@@ -421,6 +421,7 @@
                                   audio_format_t format,
                                   uint32_t sample_rate,
                                   uint32_t bit_width,
+                                  audio_channel_mask_t channel_mask,
                                   struct stream_app_type_cfg *app_type_cfg);
 int audio_extn_utils_send_app_type_cfg(struct audio_usecase *usecase);
 void audio_extn_utils_send_audio_calibration(struct audio_device *adev,
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c
index 82b596f..3a0b6fd 100644
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.c
@@ -452,12 +452,14 @@
                                   audio_format_t format,
                                   uint32_t sample_rate,
                                   uint32_t bit_width,
+                                  audio_channel_mask_t channel_mask,
                                   struct stream_app_type_cfg *app_type_cfg)
 {
     struct listnode *node_i, *node_j, *node_k;
     struct streams_output_cfg *so_info;
     struct stream_format *sf_info;
     struct stream_sample_rate *ss_info;
+    char value[PROPERTY_VALUE_MAX] = {0};
 
     if ((24 == bit_width) &&
         (devices & AUDIO_DEVICE_OUT_SPEAKER)) {
@@ -468,6 +470,16 @@
         ALOGI("%s Allowing 24-bit playback on speaker ONLY at default sampling rate", __func__);
     }
 
+    property_get("audio.playback.mch.downsample",value,"");
+    if (!strncmp("true", value, sizeof("true"))) {
+        if ((popcount(channel_mask) > 2) &&
+                (sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
+                !(flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH))  {
+                    sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
+                    ALOGD("%s: MCH session defaulting sample rate to %d",
+                               __func__, sample_rate);
+        }
+    }
     ALOGV("%s: flags: %x, format: %x sample_rate %d",
            __func__, flags, format, sample_rate);
     list_for_each(node_i, streams_output_cfg_list) {
@@ -509,6 +521,7 @@
     struct mixer_ctl *ctl;
     int pcm_device_id, acdb_dev_id, snd_device = usecase->out_snd_device;
     int32_t sample_rate = DEFAULT_OUTPUT_SAMPLING_RATE;
+    char value[PROPERTY_VALUE_MAX] = {0};
 
     ALOGV("%s", __func__);
 
@@ -558,6 +571,14 @@
         sample_rate = out->app_type_cfg.sample_rate;
     }
 
+    property_get("audio.playback.mch.downsample",value,"");
+    if (!strncmp("true", value, sizeof("true"))) {
+        if ((popcount(out->channel_mask) > 2) &&
+               (out->sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
+               !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH))
+           sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
+    }
+
     app_type_cfg[len++] = out->app_type_cfg.app_type;
     app_type_cfg[len++] = acdb_dev_id;
     if (((out->format == AUDIO_FORMAT_E_AC3) ||
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index b3812a8..435d5ba 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -954,6 +954,7 @@
                                                 usecase->stream.out->format,
                                                 usecase->stream.out->sample_rate,
                                                 usecase->stream.out->bit_width,
+                                                usecase->stream.out->channel_mask,
                                                 &usecase->stream.out->app_type_cfg);
         ALOGI("%s Selected apptype: %d", __func__, usecase->stream.out->app_type_cfg.app_type);
     }
@@ -2978,7 +2979,8 @@
     audio_extn_utils_update_stream_app_type_cfg(adev->platform,
                                                 &adev->streams_output_cfg_list,
                                                 devices, flags, format, out->sample_rate,
-                                                out->bit_width, &out->app_type_cfg);
+                                                out->bit_width, out->channel_mask,
+                                                &out->app_type_cfg);
     if ((out->usecase == USECASE_AUDIO_PLAYBACK_PRIMARY) ||
         (flags & AUDIO_OUTPUT_FLAG_PRIMARY)) {
         /* Ensure the default output is not selected twice */
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index 8acfa43..3fd8ad3 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -3441,6 +3441,7 @@
     struct stream_out *out = NULL;
     unsigned int bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
     unsigned int sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
+    char value[PROPERTY_VALUE_MAX] = {0};
 
     // For voice calls use default configuration
     // force routing is not required here, caller will do it anyway
@@ -3480,6 +3481,22 @@
     if (16 == bit_width) {
         sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
     }
+
+    //check if mulitchannel clip needs to be down sampled to 48k
+    property_get("audio.playback.mch.downsample",value,"");
+    if (!strncmp("true", value, sizeof("true"))) {
+        out = usecase->stream.out;
+        if ((popcount(out->channel_mask) > 2) &&
+                      (out->sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
+                      !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) {
+           sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
+          /* update out sample rate to reflect current backend sample rate  */
+           out->sample_rate = sample_rate;
+           ALOGD("%s: MCH session defaulting sample rate to %d",
+                        __func__, sample_rate);
+         }
+    }
+
     // 24 bit playback on speakers is allowed through 48 khz backend only
     // bit width re-configured based on platform info
     if ((24 == bit_width) &&
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 9c1115c..a99eea1 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -3133,6 +3133,7 @@
     struct stream_out *out = NULL;
     unsigned int bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
     unsigned int sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
+    char value[PROPERTY_VALUE_MAX] = {0};
 
     // For voice calls use default configuration
     // force routing is not required here, caller will do it anyway
@@ -3172,6 +3173,21 @@
     if (16 == bit_width) {
         sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
     }
+
+    //check if mulitchannel clip needs to be down sampled  to 48k
+    property_get("audio.playback.mch.downsample",value,"");
+    if (!strncmp("true", value, sizeof("true"))) {
+        out = usecase->stream.out;
+        if ((popcount(out->channel_mask) > 2) &&
+                      (out->sample_rate > CODEC_BACKEND_DEFAULT_SAMPLE_RATE) &&
+                      !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)) {
+            /* update out sample rate to reflect current backend sample rate  */
+            sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
+            ALOGD("%s: MCH session defaulting sample rate to %d",
+                 __func__, sample_rate);
+        }
+    }
+
     // 24 bit playback on speakers is allowed through 48 khz backend only
     // bit width re-configured based on platform info
     if ((24 == bit_width) &&