From 68f7df0d535e8d282cd7bc5feeca9ac5a77fc081 Mon Sep 17 00:00:00 2001 From: Phil Burk Date: Wed, 15 Apr 2020 13:49:11 -0700 Subject: [PATCH 1/4] oboe: add openSharedStream To prevent race conditions with the onError callbacks that were resulting in the use of a deleted stream. For bug #820 --- include/oboe/AudioStream.h | 21 +++++++++++++++++++-- include/oboe/AudioStreamBuilder.h | 3 +++ src/aaudio/AudioStreamAAudio.cpp | 20 ++++++++++++++++++++ src/common/AudioStreamBuilder.cpp | 10 ++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/include/oboe/AudioStream.h b/include/oboe/AudioStream.h index d9b2046a3..f24525854 100644 --- a/include/oboe/AudioStream.h +++ b/include/oboe/AudioStream.h @@ -418,6 +418,22 @@ class AudioStream : public AudioStreamBase { ResultWithValue waitForAvailableFrames(int32_t numFrames, int64_t timeoutNanoseconds); + /* + * INTERNAL USE ONLY + * Set a weak_ptr to this stream from the shared_ptr so that we can + * later use a shared_ptr in the error callback. + */ + void setWeakThis(std::shared_ptr &sharedStream) { + mWeakThis = sharedStream; + } + + /* + * Make a shared_ptr that will prevent this stream from being deleted. + */ + std::shared_ptr lockWeakThis() { + return mWeakThis.lock(); + } + protected: /** @@ -497,17 +513,18 @@ class AudioStream : public AudioStreamBase { std::mutex mLock; // for synchronizing start/stop/close + private: int mPreviousScheduler = -1; std::atomic mDataCallbackEnabled{false}; std::atomic mErrorCallbackCalled{false}; - + std::weak_ptr mWeakThis; }; /** - * This struct is a stateless functor which closes a audiostream prior to its deletion. + * This struct is a stateless functor which closes an AudioStream prior to its deletion. * This means it can be used to safely delete a smart pointer referring to an open stream. */ struct StreamDeleterFunctor { diff --git a/include/oboe/AudioStreamBuilder.h b/include/oboe/AudioStreamBuilder.h index b0f7de8e7..636803a74 100644 --- a/include/oboe/AudioStreamBuilder.h +++ b/include/oboe/AudioStreamBuilder.h @@ -25,6 +25,7 @@ namespace oboe { // This depends on AudioStream, so we use forward declaration, it will close and delete the stream struct StreamDeleterFunctor; using ManagedStream = std::unique_ptr; + /** * Factory class for an audio Stream. */ @@ -399,6 +400,8 @@ class AudioStreamBuilder : public AudioStreamBase { */ Result openManagedStream(ManagedStream &stream); + Result openSharedStream(std::shared_ptr &sharedStream); + private: /** diff --git a/src/aaudio/AudioStreamAAudio.cpp b/src/aaudio/AudioStreamAAudio.cpp index b19ec915d..383e9f60d 100644 --- a/src/aaudio/AudioStreamAAudio.cpp +++ b/src/aaudio/AudioStreamAAudio.cpp @@ -74,6 +74,17 @@ static void oboe_aaudio_error_thread_proc(AudioStreamAAudio *oboeStream, LOGD("%s() - exiting <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", __func__); } +// This runs in its own thread. +// Only one of these threads will be launched from internalErrorCallback(). +// Prevents deletion of the stream if the app is using AudioStreamBuilder::openSharedStream() +static void oboe_aaudio_error_thread_proc_shared(std::shared_ptr sharedStream, + Result error) { + LOGD("%s() - entering >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", __func__); + AudioStreamAAudio *oboeStream = reinterpret_cast(sharedStream.get()); + oboe_aaudio_error_thread_proc(oboeStream, error); + LOGD("%s() - exiting <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", __func__); +} + namespace oboe { /* @@ -101,12 +112,21 @@ void AudioStreamAAudio::internalErrorCallback( void *userData, aaudio_result_t error) { AudioStreamAAudio *oboeStream = reinterpret_cast(userData); + + // Prevents deletion of the stream if the app is using AudioStreamBuilder::openSharedStream() + std::shared_ptr sharedStream = oboeStream->lockWeakThis(); + // These checks should be enough because we assume that the stream close() // will join() any active callback threads and will not allow new callbacks. if (oboeStream->wasErrorCallbackCalled()) { // block extra error callbacks LOGE("%s() multiple error callbacks called!", __func__); } else if (stream != oboeStream->getUnderlyingStream()) { LOGD("%s() stream already closed", __func__); // can happen if there are bugs + } else if (sharedStream) { + // Handle error on a separate thread using shared pointer. + std::thread t(oboe_aaudio_error_thread_proc_shared, sharedStream, + static_cast(error)); + t.detach(); } else { // Handle error on a separate thread. std::thread t(oboe_aaudio_error_thread_proc, oboeStream, diff --git a/src/common/AudioStreamBuilder.cpp b/src/common/AudioStreamBuilder.cpp index 9d446258a..3ca3e1032 100644 --- a/src/common/AudioStreamBuilder.cpp +++ b/src/common/AudioStreamBuilder.cpp @@ -186,4 +186,14 @@ Result AudioStreamBuilder::openManagedStream(oboe::ManagedStream &stream) { return result; } +Result AudioStreamBuilder::openSharedStream(std::shared_ptr &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); + return result; +} + } // namespace oboe \ No newline at end of file From c4556cc6fa309ae622817d7e0e17fbb81fc40fdc Mon Sep 17 00:00:00 2001 From: Phil Burk Date: Wed, 15 Apr 2020 13:50:58 -0700 Subject: [PATCH 2/4] OboeTester: use openSharedStream() Also added a sleep to provoke a race condition. Should be removed. --- .../app/src/main/cpp/NativeAudioContext.cpp | 29 ++++++++++--------- .../app/src/main/cpp/NativeAudioContext.h | 4 +-- .../src/main/cpp/OboeStreamCallbackProxy.cpp | 2 ++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp index 5a145d42a..10e23eab5 100644 --- a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp +++ b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp @@ -59,7 +59,7 @@ int ActivityContext::callbackSize = 0; oboe::AudioStream * ActivityContext::getOutputStream() { for (auto entry : mOboeStreams) { - oboe::AudioStream *oboeStream = entry.second; + oboe::AudioStream *oboeStream = entry.second.get(); if (oboeStream->getDirection() == oboe::Direction::Output) { return oboeStream; } @@ -69,7 +69,7 @@ oboe::AudioStream * ActivityContext::getOutputStream() { oboe::AudioStream * ActivityContext::getInputStream() { for (auto entry : mOboeStreams) { - oboe::AudioStream *oboeStream = entry.second; + oboe::AudioStream *oboeStream = entry.second.get(); if (oboeStream != nullptr) { if (oboeStream->getDirection() == oboe::Direction::Input) { return oboeStream; @@ -80,6 +80,7 @@ oboe::AudioStream * ActivityContext::getInputStream() { } void ActivityContext::freeStreamIndex(int32_t streamIndex) { + mOboeStreams[streamIndex].reset(); mOboeStreams.erase(streamIndex); } @@ -88,13 +89,14 @@ int32_t ActivityContext::allocateStreamIndex() { } void ActivityContext::close(int32_t streamIndex) { + LOGD("ActivityContext::%s() called for stream %d ", __func__, streamIndex); stopBlockingIOThread(); oboe::AudioStream *oboeStream = getStream(streamIndex); + LOGD("ActivityContext::%s() close stream %p ", __func__, oboeStream); if (oboeStream != nullptr) { oboeStream->close(); - freeStreamIndex(streamIndex); LOGD("ActivityContext::%s() delete stream %d ", __func__, streamIndex); - delete oboeStream; + freeStreamIndex(streamIndex); } } @@ -110,7 +112,7 @@ oboe::Result ActivityContext::pause() { oboe::Result result = oboe::Result::OK; stopBlockingIOThread(); for (auto entry : mOboeStreams) { - oboe::AudioStream *oboeStream = entry.second; + oboe::AudioStream *oboeStream = entry.second.get(); result = oboeStream->requestPause(); printScheduler(); } @@ -123,8 +125,8 @@ oboe::Result ActivityContext::stopAllStreams() { LOGD("ActivityContext::stopAllStreams() called"); for (auto entry : mOboeStreams) { LOGD("ActivityContext::stopAllStreams() handle = %d, stream %p", - entry.first, entry.second); - oboe::AudioStream *oboeStream = entry.second; + entry.first, entry.second.get()); + oboe::AudioStream *oboeStream = entry.second.get(); result = oboeStream->requestStop(); printScheduler(); } @@ -204,18 +206,16 @@ int ActivityContext::open(jint nativeApi, AAudioExtensions::getInstance().setMMapEnabled(isMMap); // Open a stream based on the builder settings. - oboe::AudioStream *oboeStream = nullptr; - oboe::Result result = builder.openStream(&oboeStream); + std::shared_ptr oboeStream; + oboe::Result result = builder.openSharedStream(oboeStream); LOGD("ActivityContext::open() builder.openStream() returned %d, oboeStream = %p", - result, oboeStream); + result, oboeStream.get()); AAudioExtensions::getInstance().setMMapEnabled(oldMMapEnabled); if (result != oboe::Result::OK) { - delete oboeStream; - oboeStream = nullptr; freeStreamIndex(streamIndex); streamIndex = -1; } else { - mOboeStreams[streamIndex] = oboeStream; + mOboeStreams[streamIndex] = oboeStream; // save shared_ptr mChannelCount = oboeStream->getChannelCount(); // FIXME store per stream mFramesPerBurst = oboeStream->getFramesPerBurst(); @@ -223,7 +223,7 @@ int ActivityContext::open(jint nativeApi, createRecording(); - finishOpen(isInput, oboeStream); + finishOpen(isInput, oboeStream.get()); } @@ -606,6 +606,7 @@ void ActivityGlitches::finishOpen(bool isInput, oboe::AudioStream *oboeStream) { // =================================================================== ActivityTestDisconnect void ActivityTestDisconnect::close(int32_t streamIndex) { + LOGD("ActivityTestDisconnect::%s() called for stream %d ", __func__, streamIndex); ActivityContext::close(streamIndex); mSinkFloat.reset(); } diff --git a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h index c6965f14d..b86d50a41 100644 --- a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h +++ b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.h @@ -194,7 +194,7 @@ class ActivityContext { oboe::AudioStream *getStream(int32_t streamIndex) { auto it = mOboeStreams.find(streamIndex); if (it != mOboeStreams.end()) { - return it->second; + return it->second.get(); } else { return nullptr; } @@ -329,7 +329,7 @@ class ActivityContext { std::unique_ptr mRecording{}; int32_t mNextStreamHandle = 0; - std::unordered_map mOboeStreams; + std::unordered_map> mOboeStreams; int32_t mFramesPerBurst = 0; // TODO per stream int32_t mChannelCount = 0; // TODO per stream int32_t mSampleRate = 0; // TODO per stream diff --git a/apps/OboeTester/app/src/main/cpp/OboeStreamCallbackProxy.cpp b/apps/OboeTester/app/src/main/cpp/OboeStreamCallbackProxy.cpp index ab8f45b0c..c73daa4c4 100644 --- a/apps/OboeTester/app/src/main/cpp/OboeStreamCallbackProxy.cpp +++ b/apps/OboeTester/app/src/main/cpp/OboeStreamCallbackProxy.cpp @@ -85,6 +85,8 @@ void OboeStreamCallbackProxy::onErrorBeforeClose(oboe::AudioStream *audioStream, if (mCallback != nullptr) { mCallback->onErrorBeforeClose(audioStream, error); } + usleep(2000 * 1000); // FIXME - sleep to provoke a race condition + LOGD("OboeStreamCallbackProxy::%s(%p, %d) returning after sleep", __func__, audioStream, error); } void OboeStreamCallbackProxy::onErrorAfterClose(oboe::AudioStream *audioStream, oboe::Result error) { From df6d638ffc5afafbfa40c6c6ba58322e5adc14ef Mon Sep 17 00:00:00 2001 From: Phil Burk Date: Wed, 22 Apr 2020 12:10:40 -0700 Subject: [PATCH 3/4] Oboe: openSharedStream uses ResultWithView Also use a friend class to hide ssetWeakThis(). --- .../app/src/main/cpp/NativeAudioContext.cpp | 12 +++---- include/oboe/AudioStream.h | 35 ++++++++++--------- include/oboe/AudioStreamBase.h | 1 + include/oboe/AudioStreamBuilder.h | 3 ++ src/common/AudioStreamBuilder.cpp | 27 +++++++++++--- 5 files changed, 50 insertions(+), 28 deletions(-) diff --git a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp index 10e23eab5..451e8b6b4 100644 --- a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp +++ b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp @@ -207,14 +207,16 @@ int ActivityContext::open(jint nativeApi, // Open a stream based on the builder settings. std::shared_ptr oboeStream; - oboe::Result result = builder.openSharedStream(oboeStream); + auto resultWith = builder.openSharedStream(); + Result result = resultWith.error(); LOGD("ActivityContext::open() builder.openStream() returned %d, oboeStream = %p", - result, oboeStream.get()); + resultWith.error(), oboeStream.get()); AAudioExtensions::getInstance().setMMapEnabled(oldMMapEnabled); - if (result != oboe::Result::OK) { + if (!resultWith) { freeStreamIndex(streamIndex); streamIndex = -1; } else { + oboeStream = resultWith.value(); mOboeStreams[streamIndex] = oboeStream; // save shared_ptr mChannelCount = oboeStream->getChannelCount(); // FIXME store per stream @@ -226,14 +228,12 @@ int ActivityContext::open(jint nativeApi, finishOpen(isInput, oboeStream.get()); } - if (!mUseCallback) { int numSamples = getFramesPerBlock() * mChannelCount; dataBuffer = std::make_unique(numSamples); } - - return ((int)result < 0) ? (int)result : streamIndex; + return (result != Result::OK) ? (int)result : streamIndex; } oboe::Result ActivityContext::start() { diff --git a/include/oboe/AudioStream.h b/include/oboe/AudioStream.h index f24525854..faee05b43 100644 --- a/include/oboe/AudioStream.h +++ b/include/oboe/AudioStream.h @@ -42,6 +42,7 @@ constexpr int64_t kDefaultTimeoutNanos = (2000 * kNanosPerMillisecond); * Base class for Oboe C++ audio stream. */ class AudioStream : public AudioStreamBase { + friend class AudioStreamBuilder; // allow access to setWeakThis() and lockWeakThis() public: AudioStream() {} @@ -418,22 +419,6 @@ class AudioStream : public AudioStreamBase { ResultWithValue waitForAvailableFrames(int32_t numFrames, int64_t timeoutNanoseconds); - /* - * INTERNAL USE ONLY - * Set a weak_ptr to this stream from the shared_ptr so that we can - * later use a shared_ptr in the error callback. - */ - void setWeakThis(std::shared_ptr &sharedStream) { - mWeakThis = sharedStream; - } - - /* - * Make a shared_ptr that will prevent this stream from being deleted. - */ - std::shared_ptr lockWeakThis() { - return mWeakThis.lock(); - } - protected: /** @@ -495,6 +480,23 @@ class AudioStream : public AudioStreamBase { mDataCallbackEnabled = enabled; } + /* + * Set a weak_ptr to this stream from the shared_ptr so that we can + * later use a shared_ptr in the error callback. + */ + void setWeakThis(std::shared_ptr &sharedStream) { + mWeakThis = sharedStream; + } + + /* + * Make a shared_ptr that will prevent this stream from being deleted. + */ + std::shared_ptr lockWeakThis() { + return mWeakThis.lock(); + } + + std::weak_ptr mWeakThis; // weak pointer to this object + /** * Number of frames which have been written into the stream * @@ -520,7 +522,6 @@ class AudioStream : public AudioStreamBase { std::atomic mDataCallbackEnabled{false}; std::atomic mErrorCallbackCalled{false}; - std::weak_ptr mWeakThis; }; /** diff --git a/include/oboe/AudioStreamBase.h b/include/oboe/AudioStreamBase.h index fd327e6e8..4a6237dfd 100644 --- a/include/oboe/AudioStreamBase.h +++ b/include/oboe/AudioStreamBase.h @@ -27,6 +27,7 @@ namespace oboe { * Base class containing parameters for audio streams and builders. **/ class AudioStreamBase { + public: AudioStreamBase() {} diff --git a/include/oboe/AudioStreamBuilder.h b/include/oboe/AudioStreamBuilder.h index 636803a74..d93fae359 100644 --- a/include/oboe/AudioStreamBuilder.h +++ b/include/oboe/AudioStreamBuilder.h @@ -19,6 +19,7 @@ #include "oboe/Definitions.h" #include "oboe/AudioStreamBase.h" +#include "ResultWithValue.h" namespace oboe { @@ -402,6 +403,8 @@ class AudioStreamBuilder : public AudioStreamBase { Result openSharedStream(std::shared_ptr &sharedStream); + ResultWithValue> openSharedStream(); + private: /** diff --git a/src/common/AudioStreamBuilder.cpp b/src/common/AudioStreamBuilder.cpp index 3ca3e1032..a5fc2ee65 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 &sharedStream) { +// FIXME Remove this before release. Just for comparison with next method. +Result AudioStreamBuilder::openSharedStream(std::shared_ptr &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> AudioStreamBuilder::openSharedStream() { + std::shared_ptr 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>(sharedStream); + } else { + return ResultWithValue>(result); + } +} + +} // namespace oboe From da7f9cc2a68258cef524886cf5c15ab88554950a Mon Sep 17 00:00:00 2001 From: Phil Burk Date: Fri, 24 Apr 2020 16:45:19 -0700 Subject: [PATCH 4/4] oboe: shared_ptr to stream Changed openSharedStream() to openStream(). Remove version with ResultWithValue Bump oboe version to 1.4.0 Bump oboetester version to 1.5.24 --- apps/OboeTester/app/build.gradle | 4 ++-- .../OboeTester/app/src/main/AndroidManifest.xml | 4 ++-- .../app/src/main/cpp/NativeAudioContext.cpp | 8 +++----- .../src/main/cpp/OboeStreamCallbackProxy.cpp | 2 +- include/oboe/AudioStreamBuilder.h | 16 ++++++++++++---- include/oboe/Version.h | 4 ++-- src/common/AudioStreamBuilder.cpp | 17 +---------------- 7 files changed, 23 insertions(+), 32 deletions(-) diff --git a/apps/OboeTester/app/build.gradle b/apps/OboeTester/app/build.gradle index a57de163a..9784049a1 100644 --- a/apps/OboeTester/app/build.gradle +++ b/apps/OboeTester/app/build.gradle @@ -7,8 +7,8 @@ android { minSdkVersion 23 targetSdkVersion 28 // Also update the version in the AndroidManifest.xml file. - versionCode 31 - versionName "1.5.23" + versionCode 32 + versionName "1.5.24" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { diff --git a/apps/OboeTester/app/src/main/AndroidManifest.xml b/apps/OboeTester/app/src/main/AndroidManifest.xml index d52d3211a..e0cc3d190 100644 --- a/apps/OboeTester/app/src/main/AndroidManifest.xml +++ b/apps/OboeTester/app/src/main/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="32" + android:versionName="1.5.24"> diff --git a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp index 451e8b6b4..ee9813233 100644 --- a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp +++ b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp @@ -207,16 +207,14 @@ int ActivityContext::open(jint nativeApi, // Open a stream based on the builder settings. std::shared_ptr oboeStream; - auto resultWith = builder.openSharedStream(); - Result result = resultWith.error(); + Result result = builder.openStream(oboeStream); LOGD("ActivityContext::open() builder.openStream() returned %d, oboeStream = %p", - resultWith.error(), oboeStream.get()); + result, oboeStream.get()); AAudioExtensions::getInstance().setMMapEnabled(oldMMapEnabled); - if (!resultWith) { + if (result != Result::OK) { freeStreamIndex(streamIndex); streamIndex = -1; } else { - oboeStream = resultWith.value(); mOboeStreams[streamIndex] = oboeStream; // save shared_ptr mChannelCount = oboeStream->getChannelCount(); // FIXME store per stream diff --git a/apps/OboeTester/app/src/main/cpp/OboeStreamCallbackProxy.cpp b/apps/OboeTester/app/src/main/cpp/OboeStreamCallbackProxy.cpp index c73daa4c4..ec25935e9 100644 --- a/apps/OboeTester/app/src/main/cpp/OboeStreamCallbackProxy.cpp +++ b/apps/OboeTester/app/src/main/cpp/OboeStreamCallbackProxy.cpp @@ -85,7 +85,7 @@ void OboeStreamCallbackProxy::onErrorBeforeClose(oboe::AudioStream *audioStream, if (mCallback != nullptr) { mCallback->onErrorBeforeClose(audioStream, error); } - usleep(2000 * 1000); // FIXME - sleep to provoke a race condition + // usleep(2000 * 1000); // FIXME - sleep to provoke a race condition LOGD("OboeStreamCallbackProxy::%s(%p, %d) returning after sleep", __func__, audioStream, error); } diff --git a/include/oboe/AudioStreamBuilder.h b/include/oboe/AudioStreamBuilder.h index d93fae359..a1ea0a851 100644 --- a/include/oboe/AudioStreamBuilder.h +++ b/include/oboe/AudioStreamBuilder.h @@ -384,11 +384,23 @@ class AudioStreamBuilder : public AudioStreamBase { * * The caller owns the pointer to the AudioStream object. * + * @deprecated Use openStream(std::shared_ptr &stream) instead. * @param stream pointer to a variable to receive the stream address * @return OBOE_OK if successful or a negative error code */ Result openStream(AudioStream **stream); + /** + * Create and open a stream object based on the current settings. + * + * The caller shares the pointer to the AudioStream object. + * The shared_ptr is used internally by Oboe to prevent the stream from being + * deleted while it is being used by callbacks. + * + * @param stream reference to a shared_ptr to receive the stream address + * @return OBOE_OK if successful or a negative error code + */ + Result openStream(std::shared_ptr &stream); /** * Create and open a ManagedStream object based on the current builder state. @@ -401,10 +413,6 @@ class AudioStreamBuilder : public AudioStreamBase { */ Result openManagedStream(ManagedStream &stream); - Result openSharedStream(std::shared_ptr &sharedStream); - - ResultWithValue> openSharedStream(); - private: /** diff --git a/include/oboe/Version.h b/include/oboe/Version.h index 69d7f46b9..5aed55b9c 100644 --- a/include/oboe/Version.h +++ b/include/oboe/Version.h @@ -34,10 +34,10 @@ #define OBOE_VERSION_MAJOR 1 // Type: 8-bit unsigned int. Min value: 0 Max value: 255. See below for description. -#define OBOE_VERSION_MINOR 3 +#define OBOE_VERSION_MINOR 4 // Type: 16-bit unsigned int. Min value: 0 Max value: 65535. See below for description. -#define OBOE_VERSION_PATCH 3 +#define OBOE_VERSION_PATCH 0 #define OBOE_STRINGIFY(x) #x #define OBOE_TOSTRING(x) OBOE_STRINGIFY(x) diff --git a/src/common/AudioStreamBuilder.cpp b/src/common/AudioStreamBuilder.cpp index a5fc2ee65..a94e54ebe 100644 --- a/src/common/AudioStreamBuilder.cpp +++ b/src/common/AudioStreamBuilder.cpp @@ -186,8 +186,7 @@ Result AudioStreamBuilder::openManagedStream(oboe::ManagedStream &stream) { return result; } -// FIXME Remove this before release. Just for comparison with next method. -Result AudioStreamBuilder::openSharedStream(std::shared_ptr &sharedStream) { +Result AudioStreamBuilder::openStream(std::shared_ptr &sharedStream) { sharedStream.reset(); AudioStream *streamptr; auto result = openStream(&streamptr); @@ -199,18 +198,4 @@ Result AudioStreamBuilder::openSharedStream(std::shared_ptr &shared return result; } -ResultWithValue> AudioStreamBuilder::openSharedStream() { - std::shared_ptr 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>(sharedStream); - } else { - return ResultWithValue>(result); - } -} - } // namespace oboe