audio/internal/oboe: Bug fix: Opening a stream might fail when too many streams are opened

openStream might fail when too many streams are opened in a short time.
In this case, sleep 1[ms] and retry to open the stream.

Updates #1549
Closes #1645
This commit is contained in:
Hajime Hoshi 2021-05-16 17:56:57 +09:00
parent 1dd48388b4
commit 58c1ed0e23
2 changed files with 13 additions and 2 deletions

View File

@ -84,6 +84,8 @@ public:
return "bit_depth_in_bytes_ must be 2 but not";
}
int retry_count = 0;
retry:
if (!stream_) {
oboe::AudioStreamBuilder builder;
oboe::Result result =
@ -96,6 +98,16 @@ public:
->setDataCallback(this)
->openStream(stream_);
if (result != oboe::Result::OK) {
// openStream might fail with oboe::Result::ErrorInternal when too many
// streams are opened in a short time (#1645).
if (result == oboe::Result::ErrorInternal && retry_count < 100) {
retry_count++;
// Sleep 10[ms]
timespec ts = {};
ts.tv_nsec = 10000000;
nanosleep(&ts, nullptr);
goto retry;
}
return oboe::convertToText(result);
}
}

View File

@ -24,8 +24,7 @@ import (
)
func IsAvailable() bool {
// Disable the reader driver for Android temporarily (#1645).
return false
return true
}
type context struct {