hal: align adm sample rate and channel count for a2dp capture

Add support to set adm sample rate and channel count according
to decoder configuration for a2dp capture.

Change-Id: I2906fcc3457064d8a65f7dd895f9b2caff7aae13
diff --git a/hal/audio_extn/a2dp.c b/hal/audio_extn/a2dp.c
index 4a0f964..23c278e 100644
--- a/hal/audio_extn/a2dp.c
+++ b/hal/audio_extn/a2dp.c
@@ -94,6 +94,7 @@
 #define MIXER_AFE_SINK_CHANNELS_SLIM7    "AFE Output Channels SLIM7"
 #define MIXER_FMT_TWS_CHANNEL_MODE "TWS Channel Mode"
 #define MIXER_FMT_LC3_CHANNEL_MODE "LC3 Channel Mode"
+#define MIXER_SLIM7_TX_ADM_CHANNEL "SLIM7_TX ADM Channels"
 #define ENCODER_LATENCY_SBC        10
 #define ENCODER_LATENCY_APTX       40
 #define ENCODER_LATENCY_APTX_HD    20
@@ -1326,6 +1327,7 @@
     char *rate_str = NULL, *channels = NULL;
     uint32_t sampling_rate;
     struct mixer_ctl *ctl_sample_rate = NULL, *ctrl_channels = NULL;
+    struct mixer_ctl *adm_ctrl_channels = NULL;
     bool is_configured = false;
 
     if (direction == SINK) {
@@ -1466,12 +1468,15 @@
         }
 
         ALOGD("%s: set afe dec channels =%s", __func__, channels);
-        if (a2dp.bt_decoder_format == CODEC_TYPE_LC3)
+        if (a2dp.bt_decoder_format == CODEC_TYPE_LC3) {
             ctrl_channels = mixer_get_ctl_by_name(a2dp.adev->mixer,
                                                 MIXER_AFE_SINK_CHANNELS_SLIM7);
-        else
+            adm_ctrl_channels = mixer_get_ctl_by_name(a2dp.adev->mixer,
+                                                MIXER_SLIM7_TX_ADM_CHANNEL);
+        } else {
             ctrl_channels = mixer_get_ctl_by_name(a2dp.adev->mixer,
                                                 MIXER_AFE_SINK_CHANNELS);
+        }
     } else {
         //Configure AFE enc channels
         switch (a2dp.enc_channels) {
@@ -1498,6 +1503,19 @@
             goto fail;
         }
     }
+    // need to set adm channel for LC3 decoder
+    if (a2dp.bt_decoder_format == CODEC_TYPE_LC3) {
+        if (!adm_ctrl_channels) {
+            ALOGE(" ERROR ADM channels mixer control not identified");
+        } else {
+            if (mixer_ctl_set_enum_by_string(adm_ctrl_channels, channels) != 0) {
+                ALOGE("%s: Failed to set ADM channels =%s", __func__, channels);
+                is_configured = false;
+                goto fail;
+            }
+        }
+    }
+
     is_configured = true;
 fail:
     return is_configured;
@@ -1615,7 +1633,7 @@
 {
     const char *rate_str = "KHZ_8", *channels = "Zero";
     struct mixer_ctl *ctl_sample_rate = NULL, *ctl_sample_rate_tx = NULL;
-    struct mixer_ctl *ctrl_channels = NULL;
+    struct mixer_ctl *ctrl_channels = NULL, *adm_ctrl_channels = NULL;
 
     // Reset backend sampling rate
     if (direction == SINK) {
@@ -1647,7 +1665,6 @@
             }
         }
     } else {
-
         ctl_sample_rate = mixer_get_ctl_by_name(a2dp.adev->mixer,
                                         MIXER_SAMPLE_RATE_DEFAULT);
         if (!ctl_sample_rate) {
@@ -1679,6 +1696,13 @@
         ALOGE("%s: Failed to reset AFE in channels = %d", __func__, a2dp.enc_channels);
         return -ENOSYS;
     }
+    // Reset adm channels for slim7 tx if available
+    adm_ctrl_channels = mixer_get_ctl_by_name(a2dp.adev->mixer,
+                                            MIXER_SLIM7_TX_ADM_CHANNEL);
+    if (adm_ctrl_channels) {
+        if (mixer_ctl_set_enum_by_string(adm_ctrl_channels, channels) != 0)
+            ALOGE("%s: Failed to reset ADM in channels = %d", __func__, a2dp.dec_channels);
+    }
 
     return 0;
 }
@@ -1953,6 +1977,8 @@
     is_configured = true;
     a2dp.bt_decoder_format = CODEC_TYPE_LC3;
     a2dp.dec_channels = CH_STEREO;
+    a2dp.dec_sampling_rate =
+        lc3_dsp_cfg.dec_codec.from_Air_cfg.fromAirConfig.sampling_freq;
 
 fail:
     return is_configured;