hal: Set sampling rate for stream_out

Propagate sampling rate to platform_get_output_snd_device to
properly detect 44.1 kHz usecases. Also remove usage of
audio_devices_t in platform_set_echo reference as it does not
contain the sampling rate necessary for
platform_get_output_snd_device. Check device ref counts instead.

CRs-Fixed: 955740
Change-Id: Iaeb53fb362852416603cd57ba15da37b30973c0f
diff --git a/hal/msm8916/platform.c b/hal/msm8916/platform.c
index f630270..82aa696 100644
--- a/hal/msm8916/platform.c
+++ b/hal/msm8916/platform.c
@@ -1077,10 +1077,6 @@
     audio_devices_t out_device)
 {
     struct platform_data *my_data = (struct platform_data *)adev->platform;
-    snd_device_t snd_device = SND_DEVICE_NONE;
-    struct stream_out out;
-
-    out.devices = out_device;
 
     if (strcmp(my_data->ec_ref_mixer_path, "")) {
         ALOGV("%s: disabling %s", __func__, my_data->ec_ref_mixer_path);
@@ -1089,13 +1085,10 @@
     }
 
     if (enable) {
-        snd_device = platform_get_output_snd_device(adev->platform, &out);
-
         if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_HEADPHONES_44_1] > 0)
             strlcpy(my_data->ec_ref_mixer_path, "echo-reference headphones-44.1",
                 sizeof(my_data->ec_ref_mixer_path));
-        else if ((snd_device == SND_DEVICE_OUT_SPEAKER_VBAT) ||
-                 (snd_device == SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT))
+        else if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_SPEAKER_VBAT] > 0)
             strlcpy(my_data->ec_ref_mixer_path, "vbat-speaker echo-reference",
                 sizeof(my_data->ec_ref_mixer_path));
         else
@@ -3463,6 +3456,7 @@
               cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
           } else {
               out.devices = cal.dev_id;
+              out.sample_rate = cal.sampling_rate;
               cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
           }
         }
@@ -3697,6 +3691,7 @@
         cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
     } else if(cal.dev_id) {
         out.devices = cal.dev_id;
+        out.sample_rate = cal.sampling_rate;
         cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
     }
     cal.acdb_dev_id =  platform_get_snd_device_acdb_id(cal.snd_dev_id);
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 8822339..545df30 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -830,10 +830,6 @@
                                  audio_devices_t out_device)
 {
     struct platform_data *my_data = (struct platform_data *)adev->platform;
-    snd_device_t snd_device = SND_DEVICE_NONE;
-    struct stream_out out;
-
-    out.devices = out_device;
 
     if (strcmp(my_data->ec_ref_mixer_path, "")) {
         ALOGV("%s: disabling %s", __func__, my_data->ec_ref_mixer_path);
@@ -842,8 +838,6 @@
     }
 
     if (enable) {
-        snd_device = platform_get_output_snd_device(adev->platform, &out);
-
         /*
          * If native audio device reference count > 0, then apply codec EC otherwise
          * fallback to Speakers with VBat if enabled or default
@@ -851,8 +845,7 @@
         if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_HEADPHONES_44_1] > 0)
             strlcpy(my_data->ec_ref_mixer_path, "echo-reference headphones-44.1",
                     sizeof(my_data->ec_ref_mixer_path));
-        else if ((snd_device == SND_DEVICE_OUT_SPEAKER_VBAT) ||
-                 (snd_device == SND_DEVICE_OUT_SPEAKER_PROTECTED_VBAT))
+        else if (adev->snd_dev_ref_cnt[SND_DEVICE_OUT_SPEAKER_VBAT] > 0)
             strlcpy(my_data->ec_ref_mixer_path, "echo-reference speaker-vbat",
                     sizeof(my_data->ec_ref_mixer_path));
         else
@@ -3109,6 +3102,7 @@
               cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
           } else {
               out.devices = cal.dev_id;
+              out.sample_rate = cal.sampling_rate;
               cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
           }
         }
@@ -3409,6 +3403,7 @@
         cal.snd_dev_id = platform_get_input_snd_device(platform, cal.dev_id);
     } else if(cal.dev_id) {
         out.devices = cal.dev_id;
+        out.sample_rate = cal.sampling_rate;
         cal.snd_dev_id = platform_get_output_snd_device(platform, &out);
     }
     cal.acdb_dev_id =  platform_get_snd_device_acdb_id(cal.snd_dev_id);