diff --git a/hal/audio_hw.c b/hal/audio_hw.c index af3a6c5e..9e7b1ce7 100644 --- a/hal/audio_hw.c +++ b/hal/audio_hw.c @@ -3254,7 +3254,7 @@ static uint32_t out_get_latency(const struct audio_stream_out *stream) (out->config.rate); } - if ((AUDIO_DEVICE_OUT_BLUETOOTH_A2DP == out->devices) && + if ((AUDIO_DEVICE_OUT_ALL_A2DP & out->devices) && !(out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD)) latency += audio_extn_a2dp_get_encoder_latency(); @@ -3717,6 +3717,13 @@ static int out_get_presentation_position(const struct audio_stream_out *stream, signed_frames -= (platform_render_latency(out->usecase) * out->sample_rate / 1000000LL); + // Adjustment accounts for A2dp encoder latency with non offload usecases + // Note: Encoder latency is returned in ms, while platform_render_latency in us. + if (AUDIO_DEVICE_OUT_ALL_A2DP & out->devices) { + signed_frames -= + (audio_extn_a2dp_get_encoder_latency() * out->sample_rate / 1000); + } + // It would be unusual for this value to be negative, but check just in case ... if (signed_frames >= 0) { *frames = signed_frames;