audio: Fix realtime stream routing behavior am: 104fdfd768
am: f122d53760

Change-Id: I2ed06dff9af071c1e0d34c39ee9f22eba3a5464c
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 322c1b0..fa60668 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -361,12 +361,6 @@
 {
     struct audio_device *adev = out->dev;
 
-    if (out->routing_change) {
-        out->routing_change = false;
-        if (adev->adm_on_routing_change)
-            adev->adm_on_routing_change(adev->adm_data, out->handle);
-    }
-
     if (adev->adm_request_focus_v2) {
         adev->adm_request_focus_v2(adev->adm_data, out->handle, ns);
     } else if (adev->adm_request_focus) {
@@ -378,12 +372,6 @@
 {
     struct audio_device *adev = in->dev;
 
-    if (in->routing_change) {
-        in->routing_change = false;
-        if (adev->adm_on_routing_change)
-            adev->adm_on_routing_change(adev->adm_data, in->capture_handle);
-    }
-
     if (adev->adm_request_focus_v2) {
         adev->adm_request_focus_v2(adev->adm_data, in->capture_handle, ns);
     } else if (adev->adm_request_focus) {
@@ -2110,7 +2098,11 @@
             if (!out->standby) {
                 if (!same_dev) {
                     ALOGV("update routing change");
-                    out->routing_change = true;
+                    // inform adm before actual routing to prevent glitches.
+                    if (adev->adm_on_routing_change) {
+                        adev->adm_on_routing_change(adev->adm_data,
+                                                    out->handle);
+                    }
                 }
                 select_devices(adev, out->usecase);
                 audio_extn_tfa_98xx_update();
@@ -2919,7 +2911,11 @@
             /* If recording is in progress, change the tx device to new device */
             if (!in->standby) {
                 ALOGV("update input routing change");
-                in->routing_change = true;
+                // inform adm before actual routing to prevent glitches.
+                if (adev->adm_on_routing_change) {
+                    adev->adm_on_routing_change(adev->adm_data,
+                                                in->capture_handle);
+                }
                 select_devices(adev, in->usecase);
             }
         }
diff --git a/hal/audio_hw.h b/hal/audio_hw.h
index 187bec4..e410d64 100644
--- a/hal/audio_hw.h
+++ b/hal/audio_hw.h
@@ -213,7 +213,6 @@
     int send_new_metadata;
     bool realtime;
     int af_period_multiplier;
-    bool routing_change;
     struct audio_device *dev;
     card_status_t card_status;
 
@@ -243,7 +242,6 @@
     bool is_st_session_active;
     bool realtime;
     int af_period_multiplier;
-    bool routing_change;
     struct audio_device *dev;
     audio_format_t format;
     card_status_t card_status;