I looked at the implementation of the openStream() function:
AudioStream *AudioStreamBuilder::build() {
AudioStream *stream = nullptr;
if (mAudioApi == AudioApi::AAudio && isAAudioSupported()) {
stream = new AudioStreamAAudio(*this);
// If unspecified, only use AAudio if recommended.
} else if (mAudioApi == AudioApi::Unspecified && isAAudioRecommended()) {
stream = new AudioStreamAAudio(*this);
} else {
if (getDirection() == oboe::Direction::Output) {
stream = new AudioOutputStreamOpenSLES(*this);
} else if (getDirection() == oboe::Direction::Input) {
stream = new AudioInputStreamOpenSLES(*this);
}
}
return stream;
}
Result AudioStreamBuilder::openStream(AudioStream **streamPP) {
if (streamPP == nullptr) {
return Result::ErrorNull;
}
*streamPP = nullptr;
AudioStream *streamP = build();
if (streamP == nullptr) {
return Result::ErrorNull;
}
Result result = streamP->open(); // TODO review API
if (result == Result::OK) {
*streamPP = streamP;
}
return result;
}
Doesn't this leak memory if streamP->open() fails? I'm also surprised they are using new instead of unique_ptr, especially since one of their listed benefits is "Convenient C++ API (uses the C++11 standard) ".