hal: Fix AudioRecord and AudioTrack timestamps incorrect
Calculate the timestamps with platfrom and snd device delay.
Add delay for snd device from xml and add platform rendor delay
with snd device delay for capture and playback usecases.
Bug: 137325602
Test: manual test
Change-Id: I2a606018cb1fb6678459e3a407dcb02b7db1b074
Signed-off-by: Robert Lee <lerobert@google.com>
(cherry picked from commit 225f7d47ac137746f99b4a436dfc279dc7be7918)
Signed-off-by: Aniket Kumar Lata <alata@codeaurora.org>
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 7a42c1b..b3bd5fb 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -4289,8 +4289,10 @@
/* This adjustment accounts for buffering after app processor.
* It is based on estimated DSP latency per use case, rather than exact.
*/
- int64_t platform_latency = platform_render_latency(out->usecase) *
+ pthread_mutex_lock(&adev->lock);
+ int64_t platform_latency = platform_render_latency(out->dev, out->usecase) *
out->sample_rate / 1000000LL;
+ pthread_mutex_unlock(&adev->lock);
pthread_mutex_lock(&out->position_query_lock);
/* not querying actual state of buffering in kernel as it would involve an ioctl call
@@ -5242,7 +5244,9 @@
1000) / (out->config.rate);
else
period_ms = 0;
- latency = period_ms + platform_render_latency(out->usecase)/1000;
+ pthread_mutex_lock(&adev->lock);
+ latency = period_ms + platform_render_latency(out->dev, out->usecase)/1000;
+ pthread_mutex_unlock(&adev->lock);
} else {
latency = (out->config.period_count * out->config.period_size * 1000) /
(out->config.rate);
@@ -6176,7 +6180,10 @@
// This adjustment accounts for buffering after app processor.
// It is based on estimated DSP latency per use case, rather than exact.
- frames_temp = platform_render_latency(out->usecase) * out->sample_rate / 1000000LL;
+ pthread_mutex_lock(&adev->lock);
+ frames_temp = platform_render_latency(out->dev, out->usecase) *
+ out->sample_rate / 1000000LL;
+ pthread_mutex_unlock(&adev->lock);
if (signed_frames >= frames_temp)
signed_frames -= frames_temp;
@@ -7073,7 +7080,10 @@
unsigned int avail;
if (pcm_get_htimestamp(in->pcm, &avail, ×tamp) == 0) {
*frames = in->frames_read + avail;
- *time = timestamp.tv_sec * 1000000000LL + timestamp.tv_nsec;
+ pthread_mutex_lock(&adev->lock);
+ *time = timestamp.tv_sec * 1000000000LL + timestamp.tv_nsec
+ - platform_capture_latency(in->dev, in->usecase) * 1000LL;
+ pthread_mutex_unlock(&adev->lock);
ret = 0;
}
}