diff options
author | Phil Burk <philburk@mobileer.com> | 2020-04-22 12:10:40 -0700 |
---|---|---|
committer | Phil Burk <philburk@mobileer.com> | 2020-04-22 12:10:40 -0700 |
commit | df6d638ffc5afafbfa40c6c6ba58322e5adc14ef (patch) | |
tree | e482fac4b23cd81d92cc1e152e407e6e26f179eb /src | |
parent | c4556cc6fa309ae622817d7e0e17fbb81fc40fdc (diff) | |
download | oboe-df6d638ffc5afafbfa40c6c6ba58322e5adc14ef.tar.gz |
Oboe: openSharedStream uses ResultWithView
Also use a friend class to hide ssetWeakThis().
Diffstat (limited to 'src')
-rw-r--r-- | src/common/AudioStreamBuilder.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/common/AudioStreamBuilder.cpp b/src/common/AudioStreamBuilder.cpp index 3ca3e103..a5fc2ee6 100644 --- a/src/common/AudioStreamBuilder.cpp +++ b/src/common/AudioStreamBuilder.cpp @@ -186,14 +186,31 @@ Result AudioStreamBuilder::openManagedStream(oboe::ManagedStream &stream) { return result; } -Result AudioStreamBuilder::openSharedStream(std::shared_ptr<oboe::AudioStream> &sharedStream) { +// FIXME Remove this before release. Just for comparison with next method. +Result AudioStreamBuilder::openSharedStream(std::shared_ptr<AudioStream> &sharedStream) { sharedStream.reset(); AudioStream *streamptr; auto result = openStream(&streamptr); - sharedStream.reset(streamptr); - // Save a weak_ptr in the stream for use with callbacks. - streamptr->setWeakThis(sharedStream); + if (result == Result::OK) { + sharedStream.reset(streamptr); + // Save a weak_ptr in the stream for use with callbacks. + streamptr->setWeakThis(sharedStream); + } return result; } -} // namespace oboe
\ No newline at end of file +ResultWithValue<std::shared_ptr<AudioStream>> AudioStreamBuilder::openSharedStream() { + std::shared_ptr<AudioStream> sharedStream; + AudioStream *streamptr; + auto result = openStream(&streamptr); + if (result == Result::OK) { + sharedStream.reset(streamptr); + // Save a weak_ptr in the stream for use with callbacks. + streamptr->setWeakThis(sharedStream); + return ResultWithValue<std::shared_ptr<AudioStream>>(sharedStream); + } else { + return ResultWithValue<std::shared_ptr<AudioStream>>(result); + } +} + +} // namespace oboe |