hal: reset echo reference at the end of recording/VoIP sessions

Echo reference is not being reset currently at the end of
recording/VoIP session causing the echo reference not to
work in the further instances of recording/VoIP sessions.
Fix this by resetting echo reference while closing the input
stream used for recording/VoIP usecases.

CRs-Fixed: 717973
Change-Id: I761ba112952951777525b1bf102c9d6ccaad3269
diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c
index 3274888..e2c30f4 100644
--- a/hal/msm8960/platform.c
+++ b/hal/msm8960/platform.c
@@ -80,6 +80,7 @@
     bool fluence_in_voice_rec;
     int  fluence_type;
     int  dualmic_config;
+    bool ec_ref_enabled;
 
     /* Audio calibration related functions */
     void *acdb_handle;
@@ -201,12 +202,22 @@
 #define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
 #define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
 
-static void set_echo_reference(struct audio_device *adev, bool enable)
+void platform_set_echo_reference(void *platform, bool enable)
 {
-    if (enable)
+    struct platform_data *my_data = (struct platform_data *)platform;
+    struct audio_device *adev = my_data->adev;
+
+    if (enable) {
+        my_data->ec_ref_enabled = enable;
         audio_route_apply_and_update_path(adev->audio_route, "echo-reference");
-    else
-        audio_route_reset_and_update_path(adev->audio_route, "echo-reference");
+    } else {
+        if (my_data->ec_ref_enabled) {
+            audio_route_reset_and_update_path(adev->audio_route, "echo-reference");
+            my_data->ec_ref_enabled = enable;
+        } else {
+            ALOGV("EC Reference is already disabled: %d", my_data->ec_ref_enabled);
+        }
+    }
 
     ALOGV("Setting EC Reference: %d", enable);
 }
@@ -809,9 +820,9 @@
                 } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) {
                     snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC;
                 }
-                set_echo_reference(adev, true);
+                platform_set_echo_reference(adev->platform, true);
             } else
-                set_echo_reference(adev, false);
+                platform_set_echo_reference(adev->platform, false);
         }
     } else if (source == AUDIO_SOURCE_DEFAULT) {
         goto exit;