Merge "aaudio: use minimum of one burst in buffer" into rvc-dev

gugelfrei
TreeHugger Robot 4 years ago committed by Android (Google) Code Review
commit 4023d73e13

@ -714,12 +714,8 @@ void AudioStreamInternal::processTimestamp(uint64_t position, int64_t time) {
aaudio_result_t AudioStreamInternal::setBufferSize(int32_t requestedFrames) { aaudio_result_t AudioStreamInternal::setBufferSize(int32_t requestedFrames) {
int32_t adjustedFrames = requestedFrames; int32_t adjustedFrames = requestedFrames;
const int32_t maximumSize = getBufferCapacity() - mFramesPerBurst; const int32_t maximumSize = getBufferCapacity() - mFramesPerBurst;
// The buffer size can be set to zero. // Minimum size should be a multiple number of bursts.
// This means that the callback may be called when the internal buffer becomes empty. const int32_t minimumSize = 1 * mFramesPerBurst;
// This will be fine on some devices in ideal circumstances and will result in the
// lowest possible latency.
// If there are glitches then they should be detected as XRuns and the size can be increased.
static const int32_t minimumSize = 0;
// Clip to minimum size so that rounding up will work better. // Clip to minimum size so that rounding up will work better.
adjustedFrames = std::max(minimumSize, adjustedFrames); adjustedFrames = std::max(minimumSize, adjustedFrames);
@ -731,12 +727,14 @@ aaudio_result_t AudioStreamInternal::setBufferSize(int32_t requestedFrames) {
// Round to the next highest burst size. // Round to the next highest burst size.
int32_t numBursts = (adjustedFrames + mFramesPerBurst - 1) / mFramesPerBurst; int32_t numBursts = (adjustedFrames + mFramesPerBurst - 1) / mFramesPerBurst;
adjustedFrames = numBursts * mFramesPerBurst; adjustedFrames = numBursts * mFramesPerBurst;
// Clip just in case maximumSize is not a multiple of mFramesPerBurst.
adjustedFrames = std::min(maximumSize, adjustedFrames);
} }
// Clip against the actual size from the endpoint. // Clip against the actual size from the endpoint.
int32_t actualFrames = 0; int32_t actualFrames = 0;
mAudioEndpoint.setBufferSizeInFrames(maximumSize, &actualFrames); mAudioEndpoint.setBufferSizeInFrames(maximumSize, &actualFrames);
// actualFrames should be <= maximumSize // actualFrames should be <= actual maximum size of endpoint
adjustedFrames = std::min(actualFrames, adjustedFrames); adjustedFrames = std::min(actualFrames, adjustedFrames);
mBufferSizeInFrames = adjustedFrames; mBufferSizeInFrames = adjustedFrames;

Loading…
Cancel
Save