Skip to content

Commit

Permalink
round capacity up to get a FAST input path
Browse files Browse the repository at this point in the history
Workaround for a limitation in AudioFlinger on Legacy AAudio data path.
INPUT stream capacity must be 4096 to get a FAST track.

Fixes #183
  • Loading branch information
Phil Burk committed Sep 18, 2018
1 parent 8330e85 commit dc5ed59
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/aaudio/AudioStreamAAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,28 @@ Result AudioStreamAAudio::open() {
return result;
}

LOGD("AudioStreamAAudio(): AAudio_createStreamBuilder()");
AAudioStreamBuilder *aaudioBuilder;
result = static_cast<Result>(mLibLoader->createStreamBuilder(&aaudioBuilder));
if (result != Result::OK) {
return result;
}

LOGD("AudioStreamAAudio.open() try with deviceId = %d", static_cast<int>(mDeviceId));
mLibLoader->builder_setBufferCapacityInFrames(aaudioBuilder, mBufferCapacityInFrames);
// Do not set INPUT capacity below 4096 because that prevents us from getting a FAST track
// when using the Legacy data path.
// If the app requests > 4096 then we allow it but we are less likely to get LowLatency.
// See internal bug b/80308183 for more details.
int32_t capacity = mBufferCapacityInFrames;
constexpr int kCapacityRequiredForFastLegacyTrack = 4096; // matches value in AudioFinger
if (mDirection == oboe::Direction::Input
&& capacity != oboe::Unspecified
&& capacity < kCapacityRequiredForFastLegacyTrack
&& mPerformanceMode == oboe::PerformanceMode::LowLatency) {
capacity = kCapacityRequiredForFastLegacyTrack;
LOGD("AudioStreamAAudio.open() capacity changed from %d to %d",
static_cast<int>(mBufferCapacityInFrames), capacity);
}
mLibLoader->builder_setBufferCapacityInFrames(aaudioBuilder, capacity);

mLibLoader->builder_setChannelCount(aaudioBuilder, mChannelCount);
mLibLoader->builder_setDeviceId(aaudioBuilder, mDeviceId);
mLibLoader->builder_setDirection(aaudioBuilder, static_cast<aaudio_direction_t>(mDirection));
Expand Down

0 comments on commit dc5ed59

Please sign in to comment.