aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Burk <philburk@mobileer.com>2023-02-03 14:20:15 -0800
committerGitHub <noreply@github.com>2023-02-03 14:20:15 -0800
commit962ee701d2f41e0794ee8516a14f44657609012c (patch)
tree22a75cc701480e579c4e410f804f9c313ac8e112
parentf2fc1c8aab8418ade9917793db6fd166e8de8ec4 (diff)
downloadoboe-962ee701d2f41e0794ee8516a14f44657609012c.tar.gz
oboe: clip waitForAvailableFrames (#1702)
Clip against BufferCapacity minus BurstSize. Also bump Oboe to 1.7.1 and OboeTester to 2.3.6. Fixes #1701
-rw-r--r--apps/OboeTester/app/build.gradle4
-rw-r--r--include/oboe/AudioStream.h7
-rw-r--r--include/oboe/Version.h2
-rw-r--r--src/common/AudioStream.cpp8
4 files changed, 17 insertions, 4 deletions
diff --git a/apps/OboeTester/app/build.gradle b/apps/OboeTester/app/build.gradle
index 3449c314..91c62a80 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 64
- versionName "2.3.5"
+ versionCode 65
+ versionName "2.3.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
diff --git a/include/oboe/AudioStream.h b/include/oboe/AudioStream.h
index c349d628..cbec76e0 100644
--- a/include/oboe/AudioStream.h
+++ b/include/oboe/AudioStream.h
@@ -435,7 +435,12 @@ public:
* This can be used with an EXCLUSIVE MMAP input stream to avoid reading data too close to
* the DSP write position, which may cause glitches.
*
- * @param numFrames minimum frames available
+ * Starting with Oboe 1.7.1, the numFrames will be clipped internally against the
+ * BufferCapacity minus BurstSize. This is to prevent trying to wait for more frames
+ * than could possibly be available. In this case, the return value may be less than numFrames.
+ * Note that there may still be glitching if numFrames is too high.
+ *
+ * @param numFrames requested minimum frames available
* @param timeoutNanoseconds
* @return number of frames available, ErrorTimeout
*/
diff --git a/include/oboe/Version.h b/include/oboe/Version.h
index 68c3fe91..6bcc045d 100644
--- a/include/oboe/Version.h
+++ b/include/oboe/Version.h
@@ -37,7 +37,7 @@
#define OBOE_VERSION_MINOR 7
// Type: 16-bit unsigned int. Min value: 0 Max value: 65535. See below for description.
-#define OBOE_VERSION_PATCH 0
+#define OBOE_VERSION_PATCH 1
#define OBOE_STRINGIFY(x) #x
#define OBOE_TOSTRING(x) OBOE_STRINGIFY(x)
diff --git a/src/common/AudioStream.cpp b/src/common/AudioStream.cpp
index 9065e2d7..7f9ed4d5 100644
--- a/src/common/AudioStream.cpp
+++ b/src/common/AudioStream.cpp
@@ -166,6 +166,14 @@ ResultWithValue<int32_t> AudioStream::waitForAvailableFrames(int32_t numFrames,
if (numFrames == 0) return Result::OK;
if (numFrames < 0) return Result::ErrorOutOfRange;
+ // Make sure we don't try to wait for more frames than the buffer can hold.
+ // Subtract framesPerBurst because this is often called from a callback
+ // and we don't want to be sleeping if the buffer is close to overflowing.
+ const int32_t maxAvailableFrames = getBufferCapacityInFrames() - getFramesPerBurst();
+ numFrames = std::min(numFrames, maxAvailableFrames);
+ // The capacity should never be less than one burst. But clip to zero just in case.
+ numFrames = std::max(0, numFrames);
+
int64_t framesAvailable = 0;
int64_t burstInNanos = getFramesPerBurst() * kNanosPerSecond / getSampleRate();
bool ready = false;