audio: adjust latency for pcm offload stream

Choppy noise is heard when inserting usb headset during pcm offload
playback. That's because muteWaitMs calculated based on output latency
is inaccurate. COMPRESS_OFFLOAD_PLAYBACK_LATENCY a fixed estimation
value is used for both pcm and compress offload. But for pcm offload
use case, this value is not sufficient enough to ensure PCM buffer
completely presented before output/device change happens.

Fix is to introduce accurate latency for pcm offload. This number is
calculated based on real DSP path delay and buffer duration.

Change-Id: Id2b2b13b7aae06fa0ac3896b24fa693b8b1a6de5
CRs-Fixed: 2293194
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c
index a6f17ac..0ea8b56 100644
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2014 The Android Open Source Project
@@ -101,7 +101,10 @@
 #endif
 
 /* ToDo: Check and update a proper value in msec */
-#define COMPRESS_OFFLOAD_PLAYBACK_LATENCY 50
+#define COMPRESS_OFFLOAD_PLAYBACK_LATENCY  50
+#define PCM_OFFLOAD_PLAYBACK_DSP_PATHDELAY 62
+#define PCM_OFFLOAD_PLAYBACK_LATENCY \
+    (PCM_OFFLOAD_BUFFER_DURATION + PCM_OFFLOAD_PLAYBACK_DSP_PATHDELAY)
 
 #ifndef MAX_CHANNELS_SUPPORTED
 #define MAX_CHANNELS_SUPPORTED 8
@@ -1806,6 +1809,12 @@
     struct snd_compr_metadata metadata;
     int delay_ms = COMPRESS_OFFLOAD_PLAYBACK_LATENCY;
 
+    /* override the latency for pcm offload use case */
+    if ((out->flags & AUDIO_OUTPUT_FLAG_DIRECT) &&
+        !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) {
+        delay_ms = PCM_OFFLOAD_PLAYBACK_LATENCY;
+    }
+
     if (property_get_bool("vendor.audio.playback.dsp.pathdelay", false)) {
         ALOGD("%s:: Quering DSP delay %d",__func__, __LINE__);
         if (!(is_offload_usecase(out->usecase))) {