Skip to content

Commit 1792dcc

Browse files
Eric Laurentandi34
authored andcommitted
DO NOT MERGE - audio flinger: fix fuzz test crash
Clear output stream pointer in duplicating thread when the main output to which it is attached is closed. Also do not forward master mute and volume commands to duplicating threads as this is not applicable. Also fix logic in AudioFlinger::primaryPlaybackThread_l() that could accidentally return a duplicating thread. This never happens because the primary thread is always first in the list. Bug: 20731946. Change-Id: Ic8869699836920351b23d09544c50a258d3fb585
1 parent c0bccf3 commit 1792dcc

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

services/audioflinger/AudioFlinger.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,12 @@ status_t AudioFlinger::setMasterVolume(float value)
646646
// assigned to HALs which do not have master volume support will apply
647647
// master volume during the mix operation. Threads with HALs which do
648648
// support master volume will simply ignore the setting.
649-
for (size_t i = 0; i < mPlaybackThreads.size(); i++)
649+
for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
650+
if (mPlaybackThreads.valueAt(i)->isDuplicating()) {
651+
continue;
652+
}
650653
mPlaybackThreads.valueAt(i)->setMasterVolume(value);
654+
}
651655

652656
return NO_ERROR;
653657
}
@@ -753,8 +757,12 @@ status_t AudioFlinger::setMasterMute(bool muted)
753757
// assigned to HALs which do not have master mute support will apply master
754758
// mute during the mix operation. Threads with HALs which do support master
755759
// mute will simply ignore the setting.
756-
for (size_t i = 0; i < mPlaybackThreads.size(); i++)
760+
for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
761+
if (mPlaybackThreads.valueAt(i)->isDuplicating()) {
762+
continue;
763+
}
757764
mPlaybackThreads.valueAt(i)->setMasterMute(muted);
765+
}
758766

759767
return NO_ERROR;
760768
}
@@ -1596,7 +1604,7 @@ status_t AudioFlinger::closeOutput_nonvirtual(audio_io_handle_t output)
15961604

15971605
if (thread->type() == ThreadBase::MIXER) {
15981606
for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
1599-
if (mPlaybackThreads.valueAt(i)->type() == ThreadBase::DUPLICATING) {
1607+
if (mPlaybackThreads.valueAt(i)->isDuplicating()) {
16001608
DuplicatingThread *dupThread =
16011609
(DuplicatingThread *)mPlaybackThreads.valueAt(i).get();
16021610
dupThread->removeOutputTrack((MixerThread *)thread.get());
@@ -1627,7 +1635,7 @@ status_t AudioFlinger::closeOutput_nonvirtual(audio_io_handle_t output)
16271635
// The thread entity (active unit of execution) is no longer running here,
16281636
// but the ThreadBase container still exists.
16291637

1630-
if (thread->type() != ThreadBase::DUPLICATING) {
1638+
if (!thread->isDuplicating()) {
16311639
AudioStreamOut *out = thread->clearOutput();
16321640
ALOG_ASSERT(out != NULL, "out shouldn't be NULL");
16331641
// from now on thread->mOutput is NULL
@@ -2000,6 +2008,9 @@ AudioFlinger::PlaybackThread *AudioFlinger::primaryPlaybackThread_l() const
20002008
{
20012009
for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
20022010
PlaybackThread *thread = mPlaybackThreads.valueAt(i).get();
2011+
if(thread->isDuplicating()) {
2012+
continue;
2013+
}
20032014
AudioStreamOut *output = thread->getOutput();
20042015
if (output != NULL && output->audioHwDev == mPrimaryHardwareDev) {
20052016
return thread;

services/audioflinger/Threads.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4306,10 +4306,13 @@ void AudioFlinger::DuplicatingThread::removeOutputTrack(MixerThread *thread)
43064306
mOutputTracks[i]->destroy();
43074307
mOutputTracks.removeAt(i);
43084308
updateWaitTime_l();
4309+
if (thread->getOutput() == mOutput) {
4310+
mOutput = NULL;
4311+
}
43094312
return;
43104313
}
43114314
}
4312-
ALOGV("removeOutputTrack(): unkonwn thread: %p", thread);
4315+
ALOGV("removeOutputTrack(): unknown thread: %p", thread);
43134316
}
43144317

43154318
// caller must hold mLock

services/audioflinger/Threads.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ class ThreadBase : public Thread {
118118

119119
// static externally-visible
120120
type_t type() const { return mType; }
121+
bool isDuplicating() const { return (mType == DUPLICATING); }
122+
121123
audio_io_handle_t id() const { return mId;}
122124

123125
// dynamic externally-visible

0 commit comments

Comments
 (0)