hal: Add support for buffer duration in offload usecase

Add support for buffer duration in offload usecase.
HAL configures the buffer size corresponding to the
duration specified by the client.

Change-Id: I73faf8ddd633ba8a889f3189fcc6d4392a0e1a42
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c
index 171f69e..8d9cd33 100644
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.c
@@ -1525,11 +1525,15 @@
 
 uint32_t get_alsa_fragment_size(uint32_t bytes_per_sample,
                                   uint32_t sample_rate,
-                                  uint32_t noOfChannels)
+                                  uint32_t noOfChannels,
+                                  int64_t duration_ms)
 {
     uint32_t fragment_size = 0;
     uint32_t pcm_offload_time = PCM_OFFLOAD_BUFFER_DURATION;
 
+    if (duration_ms >= MIN_OFFLOAD_BUFFER_DURATION_MS && duration_ms <= MAX_OFFLOAD_BUFFER_DURATION_MS)
+        pcm_offload_time = duration_ms;
+
     fragment_size = (pcm_offload_time
                      * sample_rate
                      * bytes_per_sample
@@ -1564,7 +1568,8 @@
     out->compr_config.fragment_size =
              get_alsa_fragment_size(hal_op_bytes_per_sample,
                                       out->sample_rate,
-                                      popcount(out->channel_mask));
+                                      popcount(out->channel_mask),
+                                      out->info.duration_us / 1000);
 
     if ((src_format != dst_format) &&
          hal_op_bytes_per_sample != hal_ip_bytes_per_sample) {