Skip to content

Commit 73d32a0

Browse files
committed
Change audio flinger to user HAL master mute if available: DO NOT MERGE
Replicate the pattern used for HAL master volume support to make use of master mute support if the HAL supports it. This is part of the change needed to address bug 6828363. Because of the divergences between ICS and master, this change will need to be merged by hand. Signed-off-by: John Grossman <johngro@google.com> Change-Id: I6d83be524021d273d093bcb117b8f2fe57c23685
1 parent 194f6bc commit 73d32a0

File tree

2 files changed

+100
-16
lines changed

2 files changed

+100
-16
lines changed

services/audioflinger/AudioFlinger.cpp

Lines changed: 88 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,14 @@ static const char *audio_interfaces[] = {
175175

176176
AudioFlinger::AudioFlinger()
177177
: BnAudioFlinger(),
178-
mPrimaryHardwareDev(0), mMasterVolume(1.0f), mMasterVolumeSW(1.0f),
179-
mMasterVolumeSupportLvl(MVS_NONE), mMasterMute(false), mNextUniqueId(1),
178+
mPrimaryHardwareDev(0),
179+
mMasterVolume(1.0f),
180+
mMasterVolumeSW(1.0f),
181+
mMasterVolumeSupportLvl(MVS_NONE),
182+
mMasterMute(false),
183+
mMasterMuteSW(false),
184+
mMasterMuteSupportLvl(MMS_NONE),
185+
mNextUniqueId(1),
180186
mBtNrecIsOff(false)
181187
{
182188
}
@@ -245,10 +251,13 @@ void AudioFlinger::onFirstRef()
245251
return;
246252
}
247253

248-
// Determine the level of master volume support the primary audio HAL has,
249-
// and set the initial master volume at the same time.
254+
// Determine the level of master volume/master mute support the primary
255+
// audio HAL has, and set the initial master volume/mute state at the same
256+
// time.
250257
float initialVolume = 1.0;
258+
bool initialMute = false;
251259
mMasterVolumeSupportLvl = MVS_NONE;
260+
mMasterMuteSupportLvl = MMS_NONE;
252261
if (0 == mPrimaryHardwareDev->init_check(mPrimaryHardwareDev)) {
253262
AutoMutex lock(mHardwareLock);
254263
audio_hw_device_t *dev = mPrimaryHardwareDev;
@@ -267,11 +276,26 @@ void AudioFlinger::onFirstRef()
267276
(NO_ERROR != dev->set_master_volume(dev, initialVolume))) {
268277
mMasterVolumeSupportLvl = MVS_NONE;
269278
}
279+
280+
mHardwareStatus = AUDIO_HW_GET_MASTER_MUTE;
281+
if ((NULL != dev->get_master_mute) &&
282+
(NO_ERROR == dev->get_master_mute(dev, &initialMute))) {
283+
mMasterMuteSupportLvl = MMS_FULL;
284+
} else {
285+
mMasterMuteSupportLvl = MMS_SETONLY;
286+
initialMute = 0;
287+
}
288+
289+
mHardwareStatus = AUDIO_HW_SET_MASTER_MUTE;
290+
if ((NULL == dev->set_master_mute) ||
291+
(NO_ERROR != dev->set_master_mute(dev, initialMute))) {
292+
mMasterMuteSupportLvl = MMS_NONE;
293+
}
270294
mHardwareStatus = AUDIO_HW_INIT;
271295
}
272296

273-
// Set the mode for each audio HAL, and try to set the initial volume (if
274-
// supported) for all of the non-primary audio HALs.
297+
// Set the mode for each audio HAL, and try to set the initial volume and
298+
// initial mute state (if supported) for all of the non-primary audio HALs.
275299
for (size_t i = 0; i < mAudioHwDevs.size(); i++) {
276300
audio_hw_device_t *dev = mAudioHwDevs[i];
277301

@@ -284,20 +308,26 @@ void AudioFlinger::onFirstRef()
284308
mHardwareStatus = AUDIO_HW_SET_MODE;
285309
dev->set_mode(dev, mMode);
286310

287-
if ((dev != mPrimaryHardwareDev) &&
288-
(NULL != dev->set_master_volume)) {
289-
mHardwareStatus = AUDIO_HW_SET_MASTER_VOLUME;
290-
dev->set_master_volume(dev, initialVolume);
311+
if (dev != mPrimaryHardwareDev) {
312+
if (NULL != dev->set_master_volume) {
313+
mHardwareStatus = AUDIO_HW_SET_MASTER_VOLUME;
314+
dev->set_master_volume(dev, initialVolume);
315+
}
316+
317+
if (NULL != dev->set_master_mute) {
318+
mHardwareStatus = AUDIO_HW_SET_MASTER_MUTE;
319+
dev->set_master_mute(dev, initialMute);
320+
}
291321
}
292322

293323
mHardwareStatus = AUDIO_HW_INIT;
294324
}
295325
}
296326

297-
mMasterVolumeSW = (MVS_NONE == mMasterVolumeSupportLvl)
298-
? initialVolume
299-
: 1.0;
327+
mMasterVolumeSW = initialVolume;
300328
mMasterVolume = initialVolume;
329+
mMasterMuteSW = initialMute;
330+
mMasterMute = initialMute;
301331
mHardwareStatus = AUDIO_HW_IDLE;
302332
}
303333

@@ -724,15 +754,39 @@ bool AudioFlinger::getMicMute() const
724754

725755
status_t AudioFlinger::setMasterMute(bool muted)
726756
{
757+
status_t ret = initCheck();
758+
if (ret != NO_ERROR) {
759+
return ret;
760+
}
761+
727762
// check calling permissions
728763
if (!settingsAllowed()) {
729764
return PERMISSION_DENIED;
730765
}
731766

767+
bool swmm = muted;
768+
769+
// when hw supports master mute, don't mute in sw mixer
770+
if (MMS_NONE != mMasterMuteSupportLvl) {
771+
for (size_t i = 0; i < mAudioHwDevs.size(); i++) {
772+
AutoMutex lock(mHardwareLock);
773+
audio_hw_device_t *dev = mAudioHwDevs[i];
774+
775+
mHardwareStatus = AUDIO_HW_SET_MASTER_MUTE;
776+
if (NULL != dev->set_master_mute) {
777+
dev->set_master_mute(dev, muted);
778+
}
779+
mHardwareStatus = AUDIO_HW_IDLE;
780+
}
781+
782+
swmm = false;
783+
}
784+
732785
Mutex::Autolock _l(mLock);
733-
mMasterMute = muted;
786+
mMasterMute = muted;
787+
mMasterMuteSW = swmm;
734788
for (uint32_t i = 0; i < mPlaybackThreads.size(); i++)
735-
mPlaybackThreads.valueAt(i)->setMasterMute(muted);
789+
mPlaybackThreads.valueAt(i)->setMasterMute(swmm);
736790

737791
return NO_ERROR;
738792
}
@@ -762,9 +816,27 @@ float AudioFlinger::masterVolumeSW() const
762816

763817
bool AudioFlinger::masterMute() const
764818
{
819+
if (MMS_FULL == mMasterMuteSupportLvl) {
820+
bool ret_val;
821+
AutoMutex lock(mHardwareLock);
822+
823+
mHardwareStatus = AUDIO_HW_GET_MASTER_MUTE;
824+
assert(NULL != mPrimaryHardwareDev);
825+
assert(NULL != mPrimaryHardwareDev->get_master_mute);
826+
827+
mPrimaryHardwareDev->get_master_mute(mPrimaryHardwareDev, &ret_val);
828+
mHardwareStatus = AUDIO_HW_IDLE;
829+
return ret_val;
830+
}
831+
765832
return mMasterMute;
766833
}
767834

835+
bool AudioFlinger::masterMuteSW() const
836+
{
837+
return mMasterMuteSW;
838+
}
839+
768840
status_t AudioFlinger::setStreamVolume(int stream, float value, int output)
769841
{
770842
// check calling permissions
@@ -1493,7 +1565,7 @@ AudioFlinger::PlaybackThread::PlaybackThread(const sp<AudioFlinger>& audioFlinge
14931565

14941566
mMasterVolume = mAudioFlinger->masterVolumeSW();
14951567

1496-
mMasterMute = mAudioFlinger->masterMute();
1568+
mMasterMute = mAudioFlinger->masterMuteSW();
14971569

14981570
for (int stream = 0; stream < AUDIO_STREAM_CNT; stream++) {
14991571
mStreamTypes[stream].volume = mAudioFlinger->streamVolumeInternal(stream);

services/audioflinger/AudioFlinger.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class AudioFlinger :
102102
virtual float masterVolume() const;
103103
virtual float masterVolumeSW() const;
104104
virtual bool masterMute() const;
105+
virtual bool masterMuteSW() const;
105106

106107
virtual status_t setStreamVolume(int stream, float value, int output);
107108
virtual status_t setStreamMute(int stream, bool muted);
@@ -193,6 +194,8 @@ class AudioFlinger :
193194
AUDIO_SET_VOICE_VOLUME,
194195
AUDIO_SET_PARAMETER,
195196
AUDIO_HW_GET_MASTER_VOLUME,
197+
AUDIO_HW_SET_MASTER_MUTE,
198+
AUDIO_HW_GET_MASTER_MUTE,
196199
};
197200

198201
// record interface
@@ -1506,6 +1509,12 @@ class AudioFlinger :
15061509
MVS_FULL,
15071510
};
15081511

1512+
enum master_mute_support {
1513+
MMS_NONE,
1514+
MMS_SETONLY,
1515+
MMS_FULL,
1516+
};
1517+
15091518
mutable Mutex mLock;
15101519

15111520
DefaultKeyedVector< pid_t, wp<Client> > mClients;
@@ -1521,7 +1530,10 @@ class AudioFlinger :
15211530
float mMasterVolume;
15221531
float mMasterVolumeSW;
15231532
master_volume_support mMasterVolumeSupportLvl;
1533+
15241534
bool mMasterMute;
1535+
bool mMasterMuteSW;
1536+
master_mute_support mMasterMuteSupportLvl;
15251537

15261538
DefaultKeyedVector< int, sp<RecordThread> > mRecordThreads;
15271539

0 commit comments

Comments
 (0)