summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorllololo <llololo@google.com>2020-08-21 02:38:24 +0000
committerAndy Hung <hunga@google.com>2021-01-05 21:19:07 +0000
commit53fd072329547b00e26b92d0528eda7fa8d7c974 (patch)
tree3c8893506554e5a9047bda358ba9ca9d0eaa1748
parent9e85e402af91048d21e94301dd153c9b681ff96e (diff)
downloadaudio-53fd072329547b00e26b92d0528eda7fa8d7c974.tar.gz
audio_hal: Ensure input buffer size represents an integral number of
frames. Update get input buffer size logic for record use cases such that the size is also a multiple of bytes per sample period. For 1 channel 24 bit recording the computed value was not a multiple of bytes per sample and this mismatches with the computed value by ALSA causing buffer invalid errors because the use case pointers difference was reaching stop threshold. Bug: 152727483 Test: repro steps in the bug. Merged-In: I953366e09d98352d30b82f40c18a261d2355cf2c Change-Id: I953366e09d98352d30b82f40c18a261d2355cf2c
-rw-r--r--hal/audio_hw.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index a3abb8a..28faffc 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -2738,23 +2738,21 @@ static size_t get_stream_buffer_size(size_t duration_ms,
int channel_count,
bool is_low_latency)
{
- size_t size = 0;
+ // Compute target frames based on time or period size.
+ size_t target_frames = is_low_latency
+ ? configured_low_latency_capture_period_size // record only
+ : (sample_rate * duration_ms) / 1000;
- size = (sample_rate * duration_ms) / 1000;
- if (is_low_latency)
- size = configured_low_latency_capture_period_size;
-
- size *= channel_count * audio_bytes_per_sample(format);
+ // Round up to a multiple of 16 frames in case sizing for the MixerThread.
+ if (!is_low_latency) { // low latency flag set for record only
+ target_frames = (target_frames + 0xf) & ~0xf;
+ }
- /* make sure the size is multiple of 32 bytes
- * At 48 kHz mono 16-bit PCM:
- * 5.000 ms = 240 frames = 15*16*1*2 = 480, a whole multiple of 32 (15)
- * 3.333 ms = 160 frames = 10*16*1*2 = 320, a whole multiple of 32 (10)
- */
- size += 0x1f;
- size &= ~0x1f;
+ // Buffer size is the target frames multiplied by the frame size in bytes.
+ const size_t frame_size = channel_count * audio_bytes_per_sample(format);
+ const size_t buffer_size = target_frames * frame_size;
- return size;
+ return buffer_size;
}
static uint32_t out_get_sample_rate(const struct audio_stream *stream)