summaryrefslogtreecommitdiffstats
path: root/services/audioflinger/Threads.cpp
diff options
context:
space:
mode:
authorHongwei Wang <hwwang@google.com>2019-04-16 19:07:03 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-04-16 19:07:03 +0000
commit654438952d760d80986270db81d498f1b6e110b4 (patch)
tree3b3da8dedee329a89f54804513fc39aad0d92061 /services/audioflinger/Threads.cpp
parente46a14777671ec310b35aa1b0a90510f29bf8085 (diff)
parent95e3768e1936673cacf185c721f9b2c117a94a0a (diff)
downloadframeworks_av-654438952d760d80986270db81d498f1b6e110b4.tar.gz
frameworks_av-654438952d760d80986270db81d498f1b6e110b4.tar.bz2
frameworks_av-654438952d760d80986270db81d498f1b6e110b4.zip
Merge "AudioFlinger::Thread ensure proper add / sub" into qt-dev
Diffstat (limited to 'services/audioflinger/Threads.cpp')
-rw-r--r--services/audioflinger/Threads.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 2da098f6c3..6fea8befbf 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -44,6 +44,7 @@
#include <audio_utils/primitives.h>
#include <audio_utils/format.h>
#include <audio_utils/minifloat.h>
+#include <audio_utils/safe_math.h>
#include <system/audio_effects/effect_ns.h>
#include <system/audio_effects/effect_aec.h>
#include <system/audio.h>
@@ -7904,7 +7905,7 @@ void AudioFlinger::RecordThread::ResamplerBufferProvider::sync(
RecordThread *recordThread = (RecordThread *) threadBase.get();
const int32_t rear = recordThread->mRsmpInRear;
const int32_t front = mRsmpInFront;
- const ssize_t filled = rear - front;
+ const ssize_t filled = audio_utils::safe_sub_overflow(rear, front);
size_t framesIn;
bool overrun = false;
@@ -7918,7 +7919,8 @@ void AudioFlinger::RecordThread::ResamplerBufferProvider::sync(
} else {
// client is not keeping up with server, but give it latest data
framesIn = recordThread->mRsmpInFrames;
- mRsmpInFront = /* front = */ rear - framesIn;
+ mRsmpInFront = /* front = */ audio_utils::safe_sub_overflow(
+ rear, static_cast<int32_t>(framesIn));
overrun = true;
}
if (framesAvailable != NULL) {
@@ -7942,7 +7944,7 @@ status_t AudioFlinger::RecordThread::ResamplerBufferProvider::getNextBuffer(
RecordThread *recordThread = (RecordThread *) threadBase.get();
int32_t rear = recordThread->mRsmpInRear;
int32_t front = mRsmpInFront;
- ssize_t filled = rear - front;
+ ssize_t filled = audio_utils::safe_sub_overflow(rear, front);
// FIXME should not be P2 (don't want to increase latency)
// FIXME if client not keeping up, discard
LOG_ALWAYS_FATAL_IF(!(0 <= filled && (size_t) filled <= recordThread->mRsmpInFrames));
@@ -7975,13 +7977,13 @@ status_t AudioFlinger::RecordThread::ResamplerBufferProvider::getNextBuffer(
void AudioFlinger::RecordThread::ResamplerBufferProvider::releaseBuffer(
AudioBufferProvider::Buffer* buffer)
{
- size_t stepCount = buffer->frameCount;
+ int32_t stepCount = static_cast<int32_t>(buffer->frameCount);
if (stepCount == 0) {
return;
}
ALOG_ASSERT(stepCount <= mRsmpInUnrel);
mRsmpInUnrel -= stepCount;
- mRsmpInFront += stepCount;
+ mRsmpInFront = audio_utils::safe_add_overflow(mRsmpInFront, stepCount);
buffer->raw = NULL;
buffer->frameCount = 0;
}