diff options
author | Nikolay Martyanov <nikolay.martyanov@opensynergy.com> | 2020-09-14 12:09:07 +0200 |
---|---|---|
committer | Nikolay Martyanov <nikolay.martyanov@opensynergy.com> | 2020-09-17 14:54:55 +0200 |
commit | c330f6e26466b470e6ce6d4776a30fabdf849827 (patch) | |
tree | afffeab9261dacc1749c15913af1ebf07656c4ee /hal | |
parent | 11dfa08a25c7a506257ea39e75e38fc5b180bf4f (diff) | |
download | device_google_trout-c330f6e26466b470e6ce6d4776a30fabdf849827.tar.gz device_google_trout-c330f6e26466b470e6ce6d4776a30fabdf849827.tar.bz2 device_google_trout-c330f6e26466b470e6ce6d4776a30fabdf849827.zip |
Audio HAL: Adjust default buffer size.
The audio HAL works through tinyalsa, that doesn't provide way to query
supported parameters from the device. For this reason, all audio HALs in
Android use hardcoded audio parameters. In turn, default buffer size
that is allocated by the CF HAL does not match supported by the virtual
sound card. It leads to a lot of underruns and so on.
Bug: 167390806
Test: Build and boot
Change-Id: I6feda36b4e961539555e082e2e6b2d59c73d8f7f
Diffstat (limited to 'hal')
-rw-r--r-- | hal/audio/6.0/audio_hw.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/hal/audio/6.0/audio_hw.c b/hal/audio/6.0/audio_hw.c index a401dc1..09ed827 100644 --- a/hal/audio/6.0/audio_hw.c +++ b/hal/audio/6.0/audio_hw.c @@ -45,10 +45,10 @@ #define PCM_CARD 0 #define PCM_DEVICE 0 -#define OUT_PERIOD_MS 15 +#define OUT_PERIOD_MS 40 #define OUT_PERIOD_COUNT 4 -#define IN_PERIOD_MS 15 +#define IN_PERIOD_MS 40 #define IN_PERIOD_COUNT 4 #define PI 3.14159265 @@ -1079,8 +1079,17 @@ static int adev_open_output_stream(struct audio_hw_device *dev, out->frames_written = 0; out->frames_rendered = 0; + /* Init a buffer, twice the size of the period count. + * It is not enough to make the buffer of the exactly size, as the + * processes of writing to and reading from the buffer are not synchronized. + * Hence, it is possible that the reader hasn't read all the frames from + * the buffer by the moment, the writer put a new chunk of frames there. + * Taking into account, that this code does not handle the situation of + * generic frames overflows (as it is handled in another place), doubling + * the size of the buffer solves this problem. + */ ret = audio_vbuffer_init(&out->buffer, - out->pcm_config.period_size*out->pcm_config.period_count, + out->pcm_config.period_size*out->pcm_config.period_count*2, out->pcm_config.channels * pcm_format_to_bits(out->pcm_config.format) >> 3); if (ret == 0) { |