audio-hal: Use audio stream to get delay latency

An incremental change on top of Change-Id: Icb9babf7e6a63c1f3d1af73c42ef21fb8b7d211b
This resolved the perf issue of audio playback.

Change-Id: I7f50813147c4568d9e12dd16c486adc3fc4abe90
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index 0be37a4..9d6aae7 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -1611,8 +1611,6 @@
     sizeof(msm_device_to_be_id) / sizeof(msm_device_to_be_id[0]);
 #endif
 
-static int snd_device_delay_ms[SND_DEVICE_MAX] = {0};
-
 #define DEEP_BUFFER_PLATFORM_DELAY (29*1000LL)
 #define PCM_OFFLOAD_PLATFORM_DELAY (30*1000LL)
 #define LOW_LATENCY_PLATFORM_DELAY (13*1000LL)
@@ -2259,7 +2257,6 @@
         hw_interface_table[dev] = NULL;
         operator_specific_device_table[dev] = NULL;
         external_specific_device_table[dev] = NULL;
-        snd_device_delay_ms[dev] = 0;
         /* Init island cfg and power mode */
         my_data->island_cfg[dev].mixer_ctl = NULL;
         my_data->power_mode_cfg[dev].mixer_ctl = NULL;
@@ -8874,26 +8871,6 @@
     return NULL;
 }
 
-void platform_set_snd_device_delay(snd_device_t snd_device, int delay_ms)
-{
-    if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
-        ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
-        return;
-    }
-
-    snd_device_delay_ms[snd_device] = delay_ms;
-}
-
-/* return delay in Us */
-int64_t platform_get_snd_device_delay(snd_device_t snd_device)
-{
-    if ((snd_device < SND_DEVICE_MIN) || (snd_device >= SND_DEVICE_MAX)) {
-        ALOGE("%s: Invalid snd_device = %d", __func__, snd_device);
-        return 0;
-    }
-    return 1000LL * (int64_t)snd_device_delay_ms[snd_device];
-}
-
 void platform_set_audio_source_delay(audio_source_t audio_source, int delay_ms)
 {
     if ((audio_source < AUDIO_SOURCE_DEFAULT) ||
@@ -8917,14 +8894,14 @@
     return 1000LL * audio_source_delay_ms[audio_source];
 }
 
-/* Delay in Us */
 /* Delay in Us, only to be used for PCM formats */
-int64_t platform_render_latency(struct audio_device *adev, audio_usecase_t usecase)
+int64_t platform_render_latency(struct stream_out *out)
 {
     int64_t delay = 0LL;
-    struct audio_usecase *uc_info;
 
-    switch (usecase) {
+    if (!out)
+        return delay;
+    switch (out->usecase) {
         case USECASE_AUDIO_PLAYBACK_DEEP_BUFFER:
         case USECASE_AUDIO_PLAYBACK_MEDIA:
         case USECASE_AUDIO_PLAYBACK_NAV_GUIDANCE:
@@ -8952,32 +8929,20 @@
             break;
     }
 
-    uc_info = get_usecase_from_list(adev, usecase);
-
-    if (uc_info != NULL) {
-        if (uc_info->type == PCM_PLAYBACK)
-            delay += platform_get_snd_device_delay(uc_info->out_snd_device);
-        else
-            ALOGE("%s: Invalid uc_info->type %d", __func__, uc_info->type);
-    }
-
+    /* out->device could be used to add delay time if it's necessary */
     return delay;
 }
 
-int64_t platform_capture_latency(struct audio_device *adev, audio_usecase_t usecase)
+int64_t platform_capture_latency(struct stream_in *in)
 {
     int64_t delay = 0LL;
-    struct audio_usecase *uc_info;
 
-    uc_info = get_usecase_from_list(adev, usecase);
+    if (!in)
+        return delay;
 
-    if (uc_info != NULL) {
-        if (uc_info->type == PCM_CAPTURE)
-            delay += platform_get_snd_device_delay(uc_info->in_snd_device);
-        else
-            ALOGE("%s: Invalid uc_info->type %d", __func__, uc_info->type);
-    }
+    delay = platform_get_audio_source_delay(in->source);
 
+    /* in->device could be used to add delay time if it's necessary */
     return delay;
 }