Skip to content

Commit f50edfa

Browse files
committed
internal/oboe: update Oboe to v1.9.0
1 parent 70140b2 commit f50edfa

24 files changed

+229
-96
lines changed

internal/oboe/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"strings"
3030
)
3131

32-
const oboeVersion = "1.8.1"
32+
const oboeVersion = "1.9.0"
3333

3434
func main() {
3535
if err := run(); err != nil {

internal/oboe/oboe_aaudio_AAudioExtensions_android.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class AAudioExtensions {
8989
if (loadSymbols()) return false;
9090
if (mAAudio_getMMapPolicy == nullptr) return false;
9191
int32_t policy = mAAudio_getMMapPolicy();
92-
return isPolicyEnabled(policy);
92+
return (policy == Unspecified) ? mMMapSupported : isPolicyEnabled(policy);
9393
}
9494

9595
bool isMMapSupported() {

internal/oboe/oboe_aaudio_AudioStreamAAudio_android.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ static aaudio_data_callback_result_t oboe_aaudio_data_callback_proc(
6060
// This runs in its own thread.
6161
// Only one of these threads will be launched from internalErrorCallback().
6262
// It calls app error callbacks from a static function in case the stream gets deleted.
63-
static void oboe_aaudio_error_thread_proc(AudioStreamAAudio *oboeStream,
63+
static void oboe_aaudio_error_thread_proc_common(AudioStreamAAudio *oboeStream,
6464
Result error) {
65-
LOGD("%s(,%d) - entering >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", __func__, error);
65+
#if 0
66+
LOGE("%s() sleep for 5 seconds", __func__);
67+
usleep(5*1000*1000);
68+
LOGD("%s() - woke up -------------------------", __func__);
69+
#endif
6670
AudioStreamErrorCallback *errorCallback = oboeStream->getErrorCallback();
6771
if (errorCallback == nullptr) return; // should be impossible
6872
bool isErrorHandled = errorCallback->onError(oboeStream, error);
@@ -74,16 +78,24 @@ static void oboe_aaudio_error_thread_proc(AudioStreamAAudio *oboeStream,
7478
// Warning, oboeStream may get deleted by this callback.
7579
errorCallback->onErrorAfterClose(oboeStream, error);
7680
}
81+
}
82+
83+
// Callback thread for raw pointers.
84+
static void oboe_aaudio_error_thread_proc(AudioStreamAAudio *oboeStream,
85+
Result error) {
86+
LOGD("%s(,%d) - entering >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", __func__, error);
87+
oboe_aaudio_error_thread_proc_common(oboeStream, error);
7788
LOGD("%s() - exiting <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", __func__);
7889
}
7990

80-
// This runs in its own thread.
81-
// Only one of these threads will be launched from internalErrorCallback().
82-
// Prevents deletion of the stream if the app is using AudioStreamBuilder::openSharedStream()
91+
// Callback thread for shared pointers.
8392
static void oboe_aaudio_error_thread_proc_shared(std::shared_ptr<AudioStream> sharedStream,
8493
Result error) {
94+
LOGD("%s(,%d) - entering >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", __func__, error);
95+
// Hold the shared pointer while we use the raw pointer.
8596
AudioStreamAAudio *oboeStream = reinterpret_cast<AudioStreamAAudio*>(sharedStream.get());
86-
oboe_aaudio_error_thread_proc(oboeStream, error);
97+
oboe_aaudio_error_thread_proc_common(oboeStream, error);
98+
LOGD("%s() - exiting <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", __func__);
8799
}
88100

89101
namespace oboe {
@@ -528,7 +540,7 @@ DataCallbackResult AudioStreamAAudio::callOnAudioReady(AAudioStream * /*stream*/
528540
if (result == DataCallbackResult::Stop) {
529541
LOGD("Oboe callback returned DataCallbackResult::Stop");
530542
} else {
531-
LOGE("Oboe callback returned unexpected value = %d", result);
543+
LOGE("Oboe callback returned unexpected value. Error: %d", static_cast<int>(result));
532544
}
533545

534546
// Returning Stop caused various problems before S. See #1230

internal/oboe/oboe_common_AudioStreamBuilder_android.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Result AudioStreamBuilder::openStream(AudioStream **streamPP) {
9696
Result AudioStreamBuilder::openStreamInternal(AudioStream **streamPP) {
9797
auto result = isValidConfig();
9898
if (result != Result::OK) {
99-
LOGW("%s() invalid config %d", __func__, result);
99+
LOGW("%s() invalid config. Error %s", __func__, oboe::convertToText(result));
100100
return result;
101101
}
102102

@@ -117,7 +117,7 @@ Result AudioStreamBuilder::openStreamInternal(AudioStream **streamPP) {
117117
// Do we need to make a child stream and convert.
118118
if (conversionNeeded) {
119119
AudioStream *tempStream;
120-
result = childBuilder.openStream(&tempStream);
120+
result = childBuilder.openStreamInternal(&tempStream);
121121
if (result != Result::OK) {
122122
return result;
123123
}
@@ -144,7 +144,9 @@ Result AudioStreamBuilder::openStreamInternal(AudioStream **streamPP) {
144144

145145
// Use childStream in a FilterAudioStream.
146146
LOGI("%s() create a FilterAudioStream for data conversion.", __func__);
147-
FilterAudioStream *filterStream = new FilterAudioStream(parentBuilder, tempStream);
147+
std::shared_ptr<AudioStream> childStream(tempStream);
148+
FilterAudioStream *filterStream = new FilterAudioStream(parentBuilder, childStream);
149+
childStream->setWeakThis(childStream);
148150
result = filterStream->configureFlowGraph();
149151
if (result != Result::OK) {
150152
filterStream->close();

internal/oboe/oboe_common_AudioStream_android.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ namespace oboe {
3030
*/
3131
AudioStream::AudioStream(const AudioStreamBuilder &builder)
3232
: AudioStreamBase(builder) {
33+
LOGD("Constructor for AudioStream at %p", this);
34+
}
35+
36+
AudioStream::~AudioStream() {
37+
// This is to help debug use after free bugs.
38+
LOGD("Destructor for AudioStream at %p", this);
3339
}
3440

3541
Result AudioStream::close() {
@@ -113,8 +119,12 @@ Result AudioStream::start(int64_t timeoutNanoseconds)
113119
Result result = requestStart();
114120
if (result != Result::OK) return result;
115121
if (timeoutNanoseconds <= 0) return result;
116-
return waitForStateTransition(StreamState::Starting,
122+
result = waitForStateTransition(StreamState::Starting,
117123
StreamState::Started, timeoutNanoseconds);
124+
if (result != Result::OK) {
125+
LOGE("AudioStream::%s() timed out before moving from STARTING to STARTED", __func__);
126+
}
127+
return result;
118128
}
119129

120130
Result AudioStream::pause(int64_t timeoutNanoseconds)

internal/oboe/oboe_common_DataConversionFlowGraph_android.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ Result DataConversionFlowGraph::configure(AudioStream *sourceStream, AudioStream
9292
int32_t sinkSampleRate = sinkStream->getSampleRate();
9393
int32_t sinkFramesPerCallback = sinkStream->getFramesPerDataCallback();
9494

95-
LOGI("%s() flowgraph converts channels: %d to %d, format: %d to %d"
96-
", rate: %d to %d, cbsize: %d to %d, qual = %d",
95+
LOGI("%s() flowgraph converts channels: %d to %d, format: %s to %s"
96+
", rate: %d to %d, cbsize: %d to %d, qual = %s",
9797
__func__,
9898
sourceChannelCount, sinkChannelCount,
99-
sourceFormat, sinkFormat,
99+
oboe::convertToText(sourceFormat), oboe::convertToText(sinkFormat),
100100
sourceSampleRate, sinkSampleRate,
101101
sourceFramesPerCallback, sinkFramesPerCallback,
102-
sourceStream->getSampleRateConversionQuality());
102+
oboe::convertToText(sourceStream->getSampleRateConversionQuality()));
103103

104104
// Source
105105
// IF OUTPUT and using a callback then call back to the app using a SourceCaller.
@@ -128,7 +128,7 @@ Result DataConversionFlowGraph::configure(AudioStream *sourceStream, AudioStream
128128
actualSourceFramesPerCallback);
129129
break;
130130
default:
131-
LOGE("%s() Unsupported source caller format = %d", __func__, sourceFormat);
131+
LOGE("%s() Unsupported source caller format = %d", __func__, static_cast<int>(sourceFormat));
132132
return Result::ErrorIllegalArgument;
133133
}
134134
mSourceCaller->setStream(sourceStream);
@@ -150,7 +150,7 @@ Result DataConversionFlowGraph::configure(AudioStream *sourceStream, AudioStream
150150
mSource = std::make_unique<SourceI32>(sourceChannelCount);
151151
break;
152152
default:
153-
LOGE("%s() Unsupported source format = %d", __func__, sourceFormat);
153+
LOGE("%s() Unsupported source format = %d", __func__, static_cast<int>(sourceFormat));
154154
return Result::ErrorIllegalArgument;
155155
}
156156
if (isInput) {
@@ -226,7 +226,7 @@ Result DataConversionFlowGraph::configure(AudioStream *sourceStream, AudioStream
226226
mSink = std::make_unique<SinkI32>(sinkChannelCount);
227227
break;
228228
default:
229-
LOGE("%s() Unsupported sink format = %d", __func__, sinkFormat);
229+
LOGE("%s() Unsupported sink format = %d", __func__, static_cast<int>(sinkFormat));
230230
return Result::ErrorIllegalArgument;;
231231
}
232232
lastOutput->connect(&mSink->input);

internal/oboe/oboe_common_FilterAudioStream_android.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ class FilterAudioStream : public AudioStream, AudioStreamCallback {
3838
*
3939
* @param builder containing all the stream's attributes
4040
*/
41-
FilterAudioStream(const AudioStreamBuilder &builder, AudioStream *childStream)
41+
FilterAudioStream(const AudioStreamBuilder &builder, std::shared_ptr<AudioStream> childStream)
4242
: AudioStream(builder)
43-
, mChildStream(childStream) {
43+
, mChildStream(childStream) {
4444
// Intercept the callback if used.
4545
if (builder.isErrorCallbackSpecified()) {
4646
mErrorCallback = mChildStream->swapErrorCallback(this);
@@ -66,10 +66,6 @@ class FilterAudioStream : public AudioStream, AudioStreamCallback {
6666

6767
virtual ~FilterAudioStream() = default;
6868

69-
AudioStream *getChildStream() const {
70-
return mChildStream.get();
71-
}
72-
7369
Result configureFlowGraph();
7470

7571
// Close child and parent.
@@ -216,7 +212,7 @@ class FilterAudioStream : public AudioStream, AudioStreamCallback {
216212

217213
private:
218214

219-
std::unique_ptr<AudioStream> mChildStream; // this stream wraps the child stream
215+
std::shared_ptr<AudioStream> mChildStream; // this stream wraps the child stream
220216
std::unique_ptr<DataConversionFlowGraph> mFlowGraph; // for converting data
221217
std::unique_ptr<uint8_t[]> mBlockingBuffer; // temp buffer for write()
222218
double mRateScaler = 1.0; // ratio parent/child sample rates

internal/oboe/oboe_common_Utilities_android.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,20 @@ const char *convertToText<ChannelCount>(ChannelCount channelCount) {
278278
}
279279
}
280280

281+
template<>
282+
const char *convertToText<SampleRateConversionQuality>(SampleRateConversionQuality sampleRateConversionQuality) {
283+
284+
switch (sampleRateConversionQuality) {
285+
case SampleRateConversionQuality::None: return "None";
286+
case SampleRateConversionQuality::Fastest: return "Fastest";
287+
case SampleRateConversionQuality::Low: return "Low";
288+
case SampleRateConversionQuality::Medium: return "Medium";
289+
case SampleRateConversionQuality::High: return "High";
290+
case SampleRateConversionQuality::Best: return "Best";
291+
default: return "Unrecognized sample rate conversion quality";
292+
}
293+
}
294+
281295
std::string getPropertyString(const char * name) {
282296
std::string result;
283297
#ifdef __ANDROID__

internal/oboe/oboe_flowgraph_SampleRateConverter_android.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ SampleRateConverter::SampleRateConverter(int32_t channelCount,
2828

2929
void SampleRateConverter::reset() {
3030
FlowGraphNode::reset();
31-
mInputCursor = kInitialCallCount;
31+
mInputCallCount = kInitialCallCount;
32+
mInputCursor = 0;
3233
}
3334

3435
// Return true if there is a sample available.

internal/oboe/oboe_flowgraph_SampleRateConverter_android.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class SampleRateConverter : public FlowGraphFilter {
5454
int32_t mNumValidInputFrames = 0; // number of valid frames currently in the input port buffer
5555
// We need our own callCount for upstream calls because calls occur at a different rate.
5656
// This means we cannot have cyclic graphs or merges that contain an SRC.
57-
int64_t mInputCallCount = 0;
57+
int64_t mInputCallCount = kInitialCallCount;
5858

5959
};
6060

0 commit comments

Comments
 (0)