aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Burk <philburk@mobileer.com>2022-12-01 09:08:25 -0800
committerGitHub <noreply@github.com>2022-12-01 09:08:25 -0800
commit3ad855135b360697e581239fcf4843db00bb13f7 (patch)
tree4ca813e39680d5c79c93c667fa444473949199d9
parent34e89ecf41f55aad6d4375c7be4a287cb969117a (diff)
downloadoboe-3ad855135b360697e581239fcf4843db00bb13f7.tar.gz
OboeTester: fix overflow in array of PeakDetectors. (#1665)
This caused crashes or other undefined behavior when trying to record more than 8 channels in the RECORD AND PLAY test. Check for valid index in getPeakLevel(). For b/260169236 related to unexpected behavior when testing 9 channels.
-rw-r--r--apps/OboeTester/app/build.gradle4
-rw-r--r--apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.cpp11
-rw-r--r--apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.h20
-rw-r--r--apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp3
-rw-r--r--apps/OboeTester/app/src/main/res/values/strings.xml4
5 files changed, 27 insertions, 15 deletions
diff --git a/apps/OboeTester/app/build.gradle b/apps/OboeTester/app/build.gradle
index 0568c666..7e6efd81 100644
--- a/apps/OboeTester/app/build.gradle
+++ b/apps/OboeTester/app/build.gradle
@@ -6,8 +6,8 @@ android {
applicationId = "com.mobileer.oboetester"
minSdkVersion 23
targetSdkVersion 33
- versionCode 59
- versionName "2.3.0"
+ versionCode 60
+ versionName "2.3.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
diff --git a/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.cpp b/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.cpp
index b16b4666..6ac37599 100644
--- a/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.cpp
+++ b/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.cpp
@@ -17,6 +17,17 @@
#include "common/OboeDebug.h"
#include "InputStreamCallbackAnalyzer.h"
+double InputStreamCallbackAnalyzer::getPeakLevel(int index) {
+ if (mPeakDetectors == nullptr) {
+ LOGE("%s() called before setup()", __func__);
+ return -1.0;
+ } else if (index < 0 || index >= mNumChannels) {
+ LOGE("%s(), index out of range, 0 <= %d < %d", __func__, index, mNumChannels);
+ return -2.0;
+ }
+ return mPeakDetectors[index].getLevel();
+}
+
oboe::DataCallbackResult InputStreamCallbackAnalyzer::onAudioReady(
oboe::AudioStream *audioStream,
void *audioData,
diff --git a/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.h b/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.h
index 7dda1d6c..07c4f979 100644
--- a/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.h
+++ b/apps/OboeTester/app/src/main/cpp/InputStreamCallbackAnalyzer.h
@@ -29,14 +29,12 @@
#include "MultiChannelRecording.h"
#include "OboeTesterStreamCallback.h"
-constexpr int kMaxInputChannels = 8;
-
class InputStreamCallbackAnalyzer : public OboeTesterStreamCallback {
public:
void reset() {
- for (auto detector : mPeakDetectors) {
- detector.reset();
+ for (int iChannel = 0; iChannel < mNumChannels; iChannel++) {
+ mPeakDetectors[iChannel].reset();
}
OboeTesterStreamCallback::reset();
}
@@ -44,6 +42,8 @@ public:
void setup(int32_t maxFramesPerCallback,
int32_t channelCount,
oboe::AudioFormat inputFormat) {
+ mNumChannels = channelCount;
+ mPeakDetectors = std::make_unique<PeakDetector[]>(channelCount);
int32_t bufferSize = maxFramesPerCallback * channelCount;
mInputConverter = std::make_unique<FormatConverterBox>(bufferSize,
inputFormat,
@@ -62,9 +62,7 @@ public:
mRecording = recording;
}
- double getPeakLevel(int index) {
- return mPeakDetectors[index].getLevel();
- }
+ double getPeakLevel(int index);
void setMinimumFramesBeforeRead(int32_t numFrames) {
mMinimumFramesBeforeRead = numFrames;
@@ -75,13 +73,13 @@ public:
}
public:
- PeakDetector mPeakDetectors[kMaxInputChannels];
- MultiChannelRecording *mRecording = nullptr;
+ int32_t mNumChannels = 0;
+ std::unique_ptr<PeakDetector[]> mPeakDetectors;
+ MultiChannelRecording *mRecording = nullptr;
private:
-
std::unique_ptr<FormatConverterBox> mInputConverter;
- int32_t mMinimumFramesBeforeRead = 0;
+ int32_t mMinimumFramesBeforeRead = 0;
};
#endif //NATIVEOBOE_INPUTSTREAMCALLBACKANALYZER_H
diff --git a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp
index 31bfa6ac..08e10c15 100644
--- a/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp
+++ b/apps/OboeTester/app/src/main/cpp/NativeAudioContext.cpp
@@ -539,8 +539,7 @@ oboe::Result ActivityRecording::startPlayback() {
builder.setChannelCount(mChannelCount)
->setSampleRate(mSampleRate)
->setFormat(oboe::AudioFormat::Float)
- ->setCallback(&mPlayRecordingCallback)
- ->setAudioApi(oboe::AudioApi::OpenSLES);
+ ->setCallback(&mPlayRecordingCallback);
oboe::Result result = builder.openStream(&playbackStream);
if (result != oboe::Result::OK) {
delete playbackStream;
diff --git a/apps/OboeTester/app/src/main/res/values/strings.xml b/apps/OboeTester/app/src/main/res/values/strings.xml
index bf1a6768..44411d16 100644
--- a/apps/OboeTester/app/src/main/res/values/strings.xml
+++ b/apps/OboeTester/app/src/main/res/values/strings.xml
@@ -136,6 +136,10 @@
<item>7</item>
<item>8</item>
<item>9</item>
+ <item>10</item>
+ <item>11</item>
+ <item>12</item>
+ <item>13</item>
</string-array>
<string-array name="glitch_times">