Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opensles: scale buffer size by sample rate #762

Merged
merged 1 commit into from
Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/opensles/AudioInputStreamOpenSLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Result AudioInputStreamOpenSLES::open() {
goto error;
}

oboeResult = configureBufferSizes();
oboeResult = configureBufferSizes(mSampleRate);
if (Result::OK != oboeResult) {
goto error;
}
Expand Down
2 changes: 1 addition & 1 deletion src/opensles/AudioOutputStreamOpenSLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Result AudioOutputStreamOpenSLES::open() {
goto error;
}

oboeResult = configureBufferSizes();
oboeResult = configureBufferSizes(mSampleRate);
if (Result::OK != oboeResult) {
goto error;
}
Expand Down
13 changes: 9 additions & 4 deletions src/opensles/AudioStreamOpenSLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ AudioStreamOpenSLES::AudioStreamOpenSLES(const AudioStreamBuilder &builder)
mSessionId = SessionId::None;
}

static constexpr int32_t kFramesPerHighLatencyBurst = 960; // typical, 20 msec at 48000
static constexpr int32_t kHighLatencyBufferSizeMillis = 20; // typical Android period
static constexpr SLuint32 kAudioChannelCountMax = 30; // TODO Why 30?
static constexpr SLuint32 SL_ANDROID_UNKNOWN_CHANNELMASK = 0; // Matches name used internally.

Expand Down Expand Up @@ -94,19 +94,24 @@ Result AudioStreamOpenSLES::open() {
return Result::OK;
}

Result AudioStreamOpenSLES::configureBufferSizes() {
Result AudioStreamOpenSLES::configureBufferSizes(int32_t sampleRate) {
// Decide frames per burst based on hints from caller.
mFramesPerBurst = mFramesPerCallback;
if (mFramesPerBurst == kUnspecified) {
mFramesPerBurst = DefaultStreamValues::FramesPerBurst;
}

// Calculate the size of a fixed duration buffer based on sample rate.
int32_t framesPerHighLatencyBuffer =
(kHighLatencyBufferSizeMillis * sampleRate) / kMillisPerSecond;

// For high latency streams, use a larger buffer size.
// Performance Mode support was added in N_MR1 (7.1)
if (getSdkVersion() >= __ANDROID_API_N_MR1__
&& mPerformanceMode != PerformanceMode::LowLatency
&& mFramesPerBurst < kFramesPerHighLatencyBurst) {
&& mFramesPerBurst < framesPerHighLatencyBuffer) {
// Find a multiple of framesPerBurst >= kFramesPerHighLatencyBurst.
int32_t numBursts = (kFramesPerHighLatencyBurst + mFramesPerBurst - 1) / mFramesPerBurst;
int32_t numBursts = (framesPerHighLatencyBuffer + mFramesPerBurst - 1) / mFramesPerBurst;
mFramesPerBurst *= numBursts;
LOGD("AudioStreamOpenSLES:%s() NOT low latency, set mFramesPerBurst = %d",
__func__, mFramesPerBurst);
Expand Down
2 changes: 1 addition & 1 deletion src/opensles/AudioStreamOpenSLES.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class AudioStreamOpenSLES : public AudioStreamBuffered {
PerformanceMode convertPerformanceMode(SLuint32 openslMode) const;
SLuint32 convertPerformanceMode(PerformanceMode oboeMode) const;

Result configureBufferSizes();
Result configureBufferSizes(int32_t sampleRate);

void logUnsupportedAttributes();

Expand Down