Audio mixer fix for number of frames not being a multipler of blocksize
When the desired number of frames is not a multipler of blocksize,
process__genericNoResampling will ask for 0 frames and crash.
Fix it.
BUG: 70902559
Test: cts-tradefed run cts -m CtsMediaTestCases -t
android.media.cts.AudioTrackLatencyTest#testOutputLowLatency
Change-Id: Id2ce771ee8a4e49fe6ea82e500017324c8918a73
(cherry picked from commit e38b72e410def6c44f090d149879cb620fcc7955)
diff --git a/media/libaudioprocessing/AudioMixer.cpp b/media/libaudioprocessing/AudioMixer.cpp
index f8e05e7..5fafb8a 100644
--- a/media/libaudioprocessing/AudioMixer.cpp
+++ b/media/libaudioprocessing/AudioMixer.cpp
@@ -1469,13 +1469,14 @@
int32_t *out = t1.mainBuffer;
size_t numFrames = 0;
do {
+ const size_t frameCount = min((size_t)BLOCKSIZE, state->frameCount - numFrames);
memset(outTemp, 0, sizeof(outTemp));
e2 = e1;
while (e2) {
const int i = 31 - __builtin_clz(e2);
e2 &= ~(1<<i);
track_t& t = state->tracks[i];
- size_t outFrames = BLOCKSIZE;
+ size_t outFrames = frameCount;
int32_t *aux = NULL;
if (CC_UNLIKELY(t.needs & NEEDS_AUX)) {
aux = t.auxBuffer + numFrames;
@@ -1490,7 +1491,7 @@
}
size_t inFrames = (t.frameCount > outFrames)?outFrames:t.frameCount;
if (inFrames > 0) {
- t.hook(&t, outTemp + (BLOCKSIZE - outFrames) * t.mMixerChannelCount,
+ t.hook(&t, outTemp + (frameCount - outFrames) * t.mMixerChannelCount,
inFrames, state->resampleTemp, aux);
t.frameCount -= inFrames;
outFrames -= inFrames;
@@ -1501,7 +1502,7 @@
if (t.frameCount == 0 && outFrames) {
t.bufferProvider->releaseBuffer(&t.buffer);
t.buffer.frameCount = (state->frameCount - numFrames) -
- (BLOCKSIZE - outFrames);
+ (frameCount - outFrames);
t.bufferProvider->getNextBuffer(&t.buffer);
t.in = t.buffer.raw;
if (t.in == NULL) {
@@ -1515,12 +1516,12 @@
}
convertMixerFormat(out, t1.mMixerFormat, outTemp, t1.mMixerInFormat,
- BLOCKSIZE * t1.mMixerChannelCount);
+ frameCount * t1.mMixerChannelCount);
// TODO: fix ugly casting due to choice of out pointer type
out = reinterpret_cast<int32_t*>((uint8_t*)out
- + BLOCKSIZE * t1.mMixerChannelCount
+ + frameCount * t1.mMixerChannelCount
* audio_bytes_per_sample(t1.mMixerFormat));
- numFrames += BLOCKSIZE;
+ numFrames += frameCount;
} while (numFrames < state->frameCount);
}