Loading services/audiopolicy/managerdefault/AudioPolicyManager.cpp +43 −15 Original line number Diff line number Diff line Loading @@ -49,6 +49,9 @@ namespace android { //FIXME: workaround for truncated touch sounds // to be removed when the problem is handled by system UI #define TOUCH_SOUND_FIXED_DELAY_MS 100 // ---------------------------------------------------------------------------- // AudioPolicyInterface implementation // ---------------------------------------------------------------------------- Loading Loading @@ -327,15 +330,16 @@ audio_policy_dev_state_t AudioPolicyManager::getDeviceConnectionState(audio_devi AUDIO_POLICY_DEVICE_STATE_AVAILABLE : AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; } void AudioPolicyManager::updateCallRouting(audio_devices_t rxDevice, int delayMs) uint32_t AudioPolicyManager::updateCallRouting(audio_devices_t rxDevice, uint32_t delayMs) { bool createTxPatch = false; status_t status; audio_patch_handle_t afPatchHandle; DeviceVector deviceList; uint32_t muteWaitMs = 0; if(!hasPrimaryOutput()) { return; return muteWaitMs; } audio_devices_t txDevice = getDeviceAndMixForInputSource(AUDIO_SOURCE_VOICE_COMMUNICATION); ALOGV("updateCallRouting device rxDevice %08x txDevice %08x", rxDevice, txDevice); Loading @@ -355,7 +359,7 @@ void AudioPolicyManager::updateCallRouting(audio_devices_t rxDevice, int delayMs // via setOutputDevice() on primary output. // Otherwise, create two audio patches for TX and RX path. if (availablePrimaryOutputDevices() & rxDevice) { setOutputDevice(mPrimaryOutput, rxDevice, true, delayMs); muteWaitMs = setOutputDevice(mPrimaryOutput, rxDevice, true, delayMs); // If the TX device is also on the primary HW module, setOutputDevice() will take care // of it due to legacy implementation. If not, create a patch. if ((availablePrimaryInputDevices() & txDevice & ~AUDIO_DEVICE_BIT_IN) Loading Loading @@ -395,7 +399,7 @@ void AudioPolicyManager::updateCallRouting(audio_devices_t rxDevice, int delayMs } afPatchHandle = AUDIO_PATCH_HANDLE_NONE; status = mpClientInterface->createAudioPatch(&patch, &afPatchHandle, 0); status = mpClientInterface->createAudioPatch(&patch, &afPatchHandle, delayMs); ALOGW_IF(status != NO_ERROR, "updateCallRouting() error %d creating RX audio patch", status); if (status == NO_ERROR) { Loading Loading @@ -456,7 +460,7 @@ void AudioPolicyManager::updateCallRouting(audio_devices_t rxDevice, int delayMs } afPatchHandle = AUDIO_PATCH_HANDLE_NONE; status = mpClientInterface->createAudioPatch(&patch, &afPatchHandle, 0); status = mpClientInterface->createAudioPatch(&patch, &afPatchHandle, delayMs); ALOGW_IF(status != NO_ERROR, "setPhoneState() error %d creating TX audio patch", status); if (status == NO_ERROR) { Loading @@ -465,6 +469,8 @@ void AudioPolicyManager::updateCallRouting(audio_devices_t rxDevice, int delayMs mCallTxPatch->mUid = mUidCached; } } return muteWaitMs; } void AudioPolicyManager::setPhoneState(audio_mode_t state) Loading Loading @@ -597,18 +603,26 @@ void AudioPolicyManager::setForceUse(audio_policy_force_use_t usage, checkOutputForAllStrategies(); updateDevicesAndOutputs(); //FIXME: workaround for truncated touch sounds // to be removed when the problem is handled by system UI uint32_t delayMs = 0; uint32_t waitMs = 0; if (usage == AUDIO_POLICY_FORCE_FOR_COMMUNICATION) { delayMs = TOUCH_SOUND_FIXED_DELAY_MS; } if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) { audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, true /*fromCache*/); updateCallRouting(newDevice); waitMs = updateCallRouting(newDevice, delayMs); } for (size_t i = 0; i < mOutputs.size(); i++) { sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i); audio_devices_t newDevice = getNewOutputDevice(outputDesc, true /*fromCache*/); if ((mEngine->getPhoneState() != AUDIO_MODE_IN_CALL) || (outputDesc != mPrimaryOutput)) { setOutputDevice(outputDesc, newDevice, (newDevice != AUDIO_DEVICE_NONE)); waitMs = setOutputDevice(outputDesc, newDevice, (newDevice != AUDIO_DEVICE_NONE), delayMs); } if (forceVolumeReeval && (newDevice != AUDIO_DEVICE_NONE)) { applyStreamVolumes(outputDesc, newDevice, 0, true); applyStreamVolumes(outputDesc, newDevice, waitMs, true); } } Loading Loading @@ -1205,7 +1219,7 @@ status_t AudioPolicyManager::startSource(sp<AudioOutputDescriptor> outputDesc, } } } (void) /*uint32_t muteWaitMs*/ setOutputDevice(outputDesc, device, force, 0, NULL, address); uint32_t muteWaitMs = setOutputDevice(outputDesc, device, force, 0, NULL, address); // handle special case for sonification while in call if (isInCall()) { Loading @@ -1226,7 +1240,12 @@ status_t AudioPolicyManager::startSource(sp<AudioOutputDescriptor> outputDesc, if (strategy == STRATEGY_SONIFICATION) { mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY); } if (waitMs > muteWaitMs) { *delayMs = waitMs - muteWaitMs; } } return NO_ERROR; } Loading Loading @@ -1951,8 +1970,12 @@ status_t AudioPolicyManager::setStreamVolumeIndex(audio_stream_type_t stream, } if (applyDefault || ((curDevice & curStreamDevice) != 0)) { //FIXME: workaround for truncated touch sounds // delayed volume change for system stream to be removed when the problem is // handled by system UI status_t volStatus = checkAndSetVolume((audio_stream_type_t)curStream, index, desc, curDevice); checkAndSetVolume((audio_stream_type_t)curStream, index, desc, curDevice, (stream == AUDIO_STREAM_SYSTEM) ? TOUCH_SOUND_FIXED_DELAY_MS : 0); if (volStatus != NO_ERROR) { status = volStatus; } Loading Loading @@ -4646,15 +4669,20 @@ uint32_t AudioPolicyManager::checkDeviceMuteStrategies(sp<AudioOutputDescriptor> // temporary mute output if device selection changes to avoid volume bursts due to // different per device volumes if (outputDesc->isActive() && (device != prevDevice)) { if (muteWaitMs < outputDesc->latency() * 2) { muteWaitMs = outputDesc->latency() * 2; uint32_t tempMuteWaitMs = outputDesc->latency() * 2; // temporary mute duration is conservatively set to 4 times the reported latency uint32_t tempMuteDurationMs = outputDesc->latency() * 4; if (muteWaitMs < tempMuteWaitMs) { muteWaitMs = tempMuteWaitMs; } for (size_t i = 0; i < NUM_STRATEGIES; i++) { if (isStrategyActive(outputDesc, (routing_strategy)i)) { setStrategyMute((routing_strategy)i, true, outputDesc); // do tempMute unmute after twice the mute wait time // make sure that we do not start the temporary mute period too early in case of // delayed device change setStrategyMute((routing_strategy)i, true, outputDesc, delayMs); setStrategyMute((routing_strategy)i, false, outputDesc, muteWaitMs *2, device); delayMs + tempMuteDurationMs, device); } } } Loading services/audiopolicy/managerdefault/AudioPolicyManager.h +1 −1 Original line number Diff line number Diff line Loading @@ -478,7 +478,7 @@ protected: return mAvailableInputDevices.getDevicesFromHwModule(mPrimaryOutput->getModuleHandle()); } void updateCallRouting(audio_devices_t rxDevice, int delayMs = 0); uint32_t updateCallRouting(audio_devices_t rxDevice, uint32_t delayMs = 0); // if argument "device" is different from AUDIO_DEVICE_NONE, startSource() will force // the re-evaluation of the output device. Loading Loading
services/audiopolicy/managerdefault/AudioPolicyManager.cpp +43 −15 Original line number Diff line number Diff line Loading @@ -49,6 +49,9 @@ namespace android { //FIXME: workaround for truncated touch sounds // to be removed when the problem is handled by system UI #define TOUCH_SOUND_FIXED_DELAY_MS 100 // ---------------------------------------------------------------------------- // AudioPolicyInterface implementation // ---------------------------------------------------------------------------- Loading Loading @@ -327,15 +330,16 @@ audio_policy_dev_state_t AudioPolicyManager::getDeviceConnectionState(audio_devi AUDIO_POLICY_DEVICE_STATE_AVAILABLE : AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; } void AudioPolicyManager::updateCallRouting(audio_devices_t rxDevice, int delayMs) uint32_t AudioPolicyManager::updateCallRouting(audio_devices_t rxDevice, uint32_t delayMs) { bool createTxPatch = false; status_t status; audio_patch_handle_t afPatchHandle; DeviceVector deviceList; uint32_t muteWaitMs = 0; if(!hasPrimaryOutput()) { return; return muteWaitMs; } audio_devices_t txDevice = getDeviceAndMixForInputSource(AUDIO_SOURCE_VOICE_COMMUNICATION); ALOGV("updateCallRouting device rxDevice %08x txDevice %08x", rxDevice, txDevice); Loading @@ -355,7 +359,7 @@ void AudioPolicyManager::updateCallRouting(audio_devices_t rxDevice, int delayMs // via setOutputDevice() on primary output. // Otherwise, create two audio patches for TX and RX path. if (availablePrimaryOutputDevices() & rxDevice) { setOutputDevice(mPrimaryOutput, rxDevice, true, delayMs); muteWaitMs = setOutputDevice(mPrimaryOutput, rxDevice, true, delayMs); // If the TX device is also on the primary HW module, setOutputDevice() will take care // of it due to legacy implementation. If not, create a patch. if ((availablePrimaryInputDevices() & txDevice & ~AUDIO_DEVICE_BIT_IN) Loading Loading @@ -395,7 +399,7 @@ void AudioPolicyManager::updateCallRouting(audio_devices_t rxDevice, int delayMs } afPatchHandle = AUDIO_PATCH_HANDLE_NONE; status = mpClientInterface->createAudioPatch(&patch, &afPatchHandle, 0); status = mpClientInterface->createAudioPatch(&patch, &afPatchHandle, delayMs); ALOGW_IF(status != NO_ERROR, "updateCallRouting() error %d creating RX audio patch", status); if (status == NO_ERROR) { Loading Loading @@ -456,7 +460,7 @@ void AudioPolicyManager::updateCallRouting(audio_devices_t rxDevice, int delayMs } afPatchHandle = AUDIO_PATCH_HANDLE_NONE; status = mpClientInterface->createAudioPatch(&patch, &afPatchHandle, 0); status = mpClientInterface->createAudioPatch(&patch, &afPatchHandle, delayMs); ALOGW_IF(status != NO_ERROR, "setPhoneState() error %d creating TX audio patch", status); if (status == NO_ERROR) { Loading @@ -465,6 +469,8 @@ void AudioPolicyManager::updateCallRouting(audio_devices_t rxDevice, int delayMs mCallTxPatch->mUid = mUidCached; } } return muteWaitMs; } void AudioPolicyManager::setPhoneState(audio_mode_t state) Loading Loading @@ -597,18 +603,26 @@ void AudioPolicyManager::setForceUse(audio_policy_force_use_t usage, checkOutputForAllStrategies(); updateDevicesAndOutputs(); //FIXME: workaround for truncated touch sounds // to be removed when the problem is handled by system UI uint32_t delayMs = 0; uint32_t waitMs = 0; if (usage == AUDIO_POLICY_FORCE_FOR_COMMUNICATION) { delayMs = TOUCH_SOUND_FIXED_DELAY_MS; } if (mEngine->getPhoneState() == AUDIO_MODE_IN_CALL && hasPrimaryOutput()) { audio_devices_t newDevice = getNewOutputDevice(mPrimaryOutput, true /*fromCache*/); updateCallRouting(newDevice); waitMs = updateCallRouting(newDevice, delayMs); } for (size_t i = 0; i < mOutputs.size(); i++) { sp<SwAudioOutputDescriptor> outputDesc = mOutputs.valueAt(i); audio_devices_t newDevice = getNewOutputDevice(outputDesc, true /*fromCache*/); if ((mEngine->getPhoneState() != AUDIO_MODE_IN_CALL) || (outputDesc != mPrimaryOutput)) { setOutputDevice(outputDesc, newDevice, (newDevice != AUDIO_DEVICE_NONE)); waitMs = setOutputDevice(outputDesc, newDevice, (newDevice != AUDIO_DEVICE_NONE), delayMs); } if (forceVolumeReeval && (newDevice != AUDIO_DEVICE_NONE)) { applyStreamVolumes(outputDesc, newDevice, 0, true); applyStreamVolumes(outputDesc, newDevice, waitMs, true); } } Loading Loading @@ -1205,7 +1219,7 @@ status_t AudioPolicyManager::startSource(sp<AudioOutputDescriptor> outputDesc, } } } (void) /*uint32_t muteWaitMs*/ setOutputDevice(outputDesc, device, force, 0, NULL, address); uint32_t muteWaitMs = setOutputDevice(outputDesc, device, force, 0, NULL, address); // handle special case for sonification while in call if (isInCall()) { Loading @@ -1226,7 +1240,12 @@ status_t AudioPolicyManager::startSource(sp<AudioOutputDescriptor> outputDesc, if (strategy == STRATEGY_SONIFICATION) { mpClientInterface->invalidateStream(AUDIO_STREAM_ACCESSIBILITY); } if (waitMs > muteWaitMs) { *delayMs = waitMs - muteWaitMs; } } return NO_ERROR; } Loading Loading @@ -1951,8 +1970,12 @@ status_t AudioPolicyManager::setStreamVolumeIndex(audio_stream_type_t stream, } if (applyDefault || ((curDevice & curStreamDevice) != 0)) { //FIXME: workaround for truncated touch sounds // delayed volume change for system stream to be removed when the problem is // handled by system UI status_t volStatus = checkAndSetVolume((audio_stream_type_t)curStream, index, desc, curDevice); checkAndSetVolume((audio_stream_type_t)curStream, index, desc, curDevice, (stream == AUDIO_STREAM_SYSTEM) ? TOUCH_SOUND_FIXED_DELAY_MS : 0); if (volStatus != NO_ERROR) { status = volStatus; } Loading Loading @@ -4646,15 +4669,20 @@ uint32_t AudioPolicyManager::checkDeviceMuteStrategies(sp<AudioOutputDescriptor> // temporary mute output if device selection changes to avoid volume bursts due to // different per device volumes if (outputDesc->isActive() && (device != prevDevice)) { if (muteWaitMs < outputDesc->latency() * 2) { muteWaitMs = outputDesc->latency() * 2; uint32_t tempMuteWaitMs = outputDesc->latency() * 2; // temporary mute duration is conservatively set to 4 times the reported latency uint32_t tempMuteDurationMs = outputDesc->latency() * 4; if (muteWaitMs < tempMuteWaitMs) { muteWaitMs = tempMuteWaitMs; } for (size_t i = 0; i < NUM_STRATEGIES; i++) { if (isStrategyActive(outputDesc, (routing_strategy)i)) { setStrategyMute((routing_strategy)i, true, outputDesc); // do tempMute unmute after twice the mute wait time // make sure that we do not start the temporary mute period too early in case of // delayed device change setStrategyMute((routing_strategy)i, true, outputDesc, delayMs); setStrategyMute((routing_strategy)i, false, outputDesc, muteWaitMs *2, device); delayMs + tempMuteDurationMs, device); } } } Loading
services/audiopolicy/managerdefault/AudioPolicyManager.h +1 −1 Original line number Diff line number Diff line Loading @@ -478,7 +478,7 @@ protected: return mAvailableInputDevices.getDevicesFromHwModule(mPrimaryOutput->getModuleHandle()); } void updateCallRouting(audio_devices_t rxDevice, int delayMs = 0); uint32_t updateCallRouting(audio_devices_t rxDevice, uint32_t delayMs = 0); // if argument "device" is different from AUDIO_DEVICE_NONE, startSource() will force // the re-evaluation of the output device. Loading