hal: add a single mixer control MIXER_SAMPLE_RATE_DEFAULT for a2dp

Audio not heard on a2dp playback in older devices
where different sampling rates for rx and tx is not supported

Add a single mixer control to update the sample rate irrespective of tx or rx,
update this when the tx and rx specific controls are not available

Change-Id: I9d365c9ab464a26ba6bef52ab2a1f6b4e10fe3dd
diff --git a/hal/audio_extn/a2dp.c b/hal/audio_extn/a2dp.c
index 858ade3..d228123 100644
--- a/hal/audio_extn/a2dp.c
+++ b/hal/audio_extn/a2dp.c
@@ -76,6 +76,7 @@
 #define MIXER_SCRAMBLER_MODE       "AFE Scrambler Mode"
 #define MIXER_SAMPLE_RATE_RX       "BT SampleRate RX"
 #define MIXER_SAMPLE_RATE_TX       "BT SampleRate TX"
+#define MIXER_SAMPLE_RATE_DEFAULT  "BT SampleRate"
 #define MIXER_AFE_IN_CHANNELS      "AFE Input Channels"
 #define MIXER_ABR_TX_FEEDBACK_PATH "A2DP_SLIM7_UL_HL Switch"
 #define MIXER_SET_FEEDBACK_CHANNEL "BT set feedback channel"
@@ -787,30 +788,43 @@
     ALOGD("%s: set backend rx sample rate = %s", __func__, rate_str);
     ctl_sample_rate = mixer_get_ctl_by_name(a2dp.adev->mixer,
                                         MIXER_SAMPLE_RATE_RX);
-    if (!ctl_sample_rate) {
-        ALOGE("%s: ERROR backend sample rate mixer control not identifed", __func__);
-        return -ENOSYS;
-    }
-    if (mixer_ctl_set_enum_by_string(ctl_sample_rate, rate_str) != 0) {
-        ALOGE("%s: Failed to set backend sample rate = %s", __func__, rate_str);
-        return -ENOSYS;
-    }
+    if (ctl_sample_rate) {
 
-    // Set Tx backend sample rate
-    if (a2dp.abr_config.is_abr_enabled)
+        if (mixer_ctl_set_enum_by_string(ctl_sample_rate, rate_str) != 0) {
+            ALOGE("%s: Failed to set backend sample rate = %s", __func__, rate_str);
+            return -ENOSYS;
+        }
+
+        /* Set Tx backend sample rate */
+        if (a2dp.abr_config.is_abr_enabled)
         rate_str = ABR_TX_SAMPLE_RATE;
 
-    ALOGD("%s: set backend tx sample rate = %s", __func__, rate_str);
-    ctl_sample_rate = mixer_get_ctl_by_name(a2dp.adev->mixer,
-                                        MIXER_SAMPLE_RATE_TX);
-    if (!ctl_sample_rate) {
-        ALOGE("%s: ERROR backend sample rate mixer control not identifed", __func__);
-        return -ENOSYS;
-    }
-    if (mixer_ctl_set_enum_by_string(ctl_sample_rate, rate_str) != 0) {
-        ALOGE("%s: Failed to set backend sample rate = %s",
-                                    __func__, rate_str);
-        return -ENOSYS;
+        ALOGD("%s: set backend tx sample rate = %s", __func__, rate_str);
+        ctl_sample_rate = mixer_get_ctl_by_name(a2dp.adev->mixer,
+                                            MIXER_SAMPLE_RATE_TX);
+        if (!ctl_sample_rate) {
+                ALOGE("%s: ERROR backend sample rate mixer control not identifed", __func__);
+                return -ENOSYS;
+        }
+
+        if (mixer_ctl_set_enum_by_string(ctl_sample_rate, rate_str) != 0) {
+            ALOGE("%s: Failed to set backend sample rate = %s", __func__, rate_str);
+            return -ENOSYS;
+        }
+    } else {
+        /* Fallback to legacy approch if MIXER_SAMPLE_RATE_RX and
+        MIXER_SAMPLE_RATE_TX is not supported */
+        ctl_sample_rate = mixer_get_ctl_by_name(a2dp.adev->mixer,
+                                        MIXER_SAMPLE_RATE_DEFAULT);
+        if (!ctl_sample_rate) {
+            ALOGE("%s: ERROR backend sample rate mixer control not identifed", __func__);
+            return -ENOSYS;
+        }
+
+        if (mixer_ctl_set_enum_by_string(ctl_sample_rate, rate_str) != 0) {
+            ALOGE("%s: Failed to set backend sample rate = %s", __func__, rate_str);
+            return -ENOSYS;
+        }
     }
 
     //Configure AFE input channels
@@ -849,24 +863,37 @@
     ALOGD("%s: reset backend sample rate = %s", __func__, rate_str);
     ctl_sample_rate_rx = mixer_get_ctl_by_name(a2dp.adev->mixer,
                                         MIXER_SAMPLE_RATE_RX);
-    if (!ctl_sample_rate_rx) {
-        ALOGE("%s: ERROR Rx backend sample rate mixer control not identifed", __func__);
-        return -ENOSYS;
-    }
-    if (mixer_ctl_set_enum_by_string(ctl_sample_rate_rx, rate_str) != 0) {
-        ALOGE("%s: Failed to reset Rx backend sample rate = %s", __func__, rate_str);
-        return -ENOSYS;
-    }
+    if (ctl_sample_rate_rx) {
 
-    ctl_sample_rate_tx = mixer_get_ctl_by_name(a2dp.adev->mixer,
+        if (mixer_ctl_set_enum_by_string(ctl_sample_rate_rx, rate_str) != 0) {
+            ALOGE("%s: Failed to reset Rx backend sample rate = %s", __func__, rate_str);
+            return -ENOSYS;
+        }
+
+        ctl_sample_rate_tx = mixer_get_ctl_by_name(a2dp.adev->mixer,
                                         MIXER_SAMPLE_RATE_TX);
-    if (!ctl_sample_rate_tx) {
-        ALOGE("%s: ERROR Tx backend sample rate mixer control not identifed", __func__);
-        return -ENOSYS;
-    }
-    if (mixer_ctl_set_enum_by_string(ctl_sample_rate_tx, rate_str) != 0) {
-        ALOGE("%s: Failed to reset Tx backend sample rate = %s", __func__, rate_str);
-        return -ENOSYS;
+        if (!ctl_sample_rate_tx) {
+                ALOGE("%s: ERROR Tx backend sample rate mixer control not identifed", __func__);
+                return -ENOSYS;
+        }
+
+        if (mixer_ctl_set_enum_by_string(ctl_sample_rate_tx, rate_str) != 0) {
+            ALOGE("%s: Failed to reset Tx backend sample rate = %s", __func__, rate_str);
+            return -ENOSYS;
+        }
+    } else {
+
+        ctl_sample_rate_rx = mixer_get_ctl_by_name(a2dp.adev->mixer,
+                                        MIXER_SAMPLE_RATE_DEFAULT);
+        if (!ctl_sample_rate_rx) {
+            ALOGE("%s: ERROR backend sample rate mixer control not identifed", __func__);
+            return -ENOSYS;
+        }
+
+        if (mixer_ctl_set_enum_by_string(ctl_sample_rate_rx, rate_str) != 0) {
+            ALOGE("%s: Failed to reset backend sample rate = %s", __func__, rate_str);
+            return -ENOSYS;
+        }
     }
 
     // Reset AFE input channels