hal: Fix underrun in Compress VOIP path
Underrun occurs in compress VOIP path when the application
passes less bytes than the actual buffer size allocated on
the basis of period size and no of channels. Fix underrun by
ignoring the pcm_write for such buffers.
CRs-Fixed: 2052745
Change-Id: I74269ffe15ef021bf57f5bea4eada44f67c51981
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 1b818b1..68f5978 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -3275,7 +3275,26 @@
out->config.channels *
format_to_bitwidth_table[out->hal_op_format]));
} else {
- ret = pcm_write(out->pcm, (void *)buffer, bytes);
+ /*
+ * To avoid underrun in DSP when the application is not pumping
+ * data at required rate, check for the no. of bytes and ignore
+ * pcm_write if it is less than actual buffer size.
+ * It is a work around to a change in compress VOIP driver.
+ */
+ if ((out->flags & AUDIO_OUTPUT_FLAG_VOIP_RX) &&
+ bytes < (out->config.period_size * out->config.channels *
+ audio_bytes_per_sample(out->format))) {
+ size_t voip_buf_size =
+ out->config.period_size * out->config.channels *
+ audio_bytes_per_sample(out->format);
+ ALOGE("%s:VOIP underrun: bytes received %zu, required:%zu\n",
+ __func__, bytes, voip_buf_size);
+ usleep(((uint64_t)voip_buf_size - bytes) *
+ 1000000 / audio_stream_out_frame_size(stream) /
+ out_get_sample_rate(&out->stream.common));
+ ret = 0;
+ } else
+ ret = pcm_write(out->pcm, (void *)buffer, bytes);
}
release_out_focus(out);