diff options
Diffstat (limited to 'libs/audioflinger/AudioPolicyManagerBase.cpp')
| -rw-r--r-- | libs/audioflinger/AudioPolicyManagerBase.cpp | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/libs/audioflinger/AudioPolicyManagerBase.cpp b/libs/audioflinger/AudioPolicyManagerBase.cpp index 096aa73..7b866c7 100644 --- a/libs/audioflinger/AudioPolicyManagerBase.cpp +++ b/libs/audioflinger/AudioPolicyManagerBase.cpp @@ -82,8 +82,8 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(AudioSystem::audio_dev // keep track of SCO device address mScoDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN); #ifdef WITH_A2DP - if ((mA2dpDeviceAddress == mScoDeviceAddress) && - (mPhoneState != AudioSystem::MODE_NORMAL)) { + if (mA2dpOutput != 0 && + mPhoneState != AudioSystem::MODE_NORMAL) { mpClientInterface->suspendOutput(mA2dpOutput); } #endif @@ -116,8 +116,8 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(AudioSystem::audio_dev if (AudioSystem::isBluetoothScoDevice(device)) { mScoDeviceAddress = ""; #ifdef WITH_A2DP - if ((mA2dpDeviceAddress == mScoDeviceAddress) && - (mPhoneState != AudioSystem::MODE_NORMAL)) { + if (mA2dpOutput != 0 && + mPhoneState != AudioSystem::MODE_NORMAL) { mpClientInterface->restoreOutput(mA2dpOutput); } #endif @@ -275,10 +275,8 @@ void AudioPolicyManagerBase::setPhoneState(int state) newDevice = getNewDevice(mHardwareOutput, false); #ifdef WITH_A2DP checkOutputForAllStrategies(newDevice); - // suspend A2DP output if SCO device address is the same as A2DP device address. - // no need to check that a SCO device is actually connected as mScoDeviceAddress == "" - // if none is connected and the test below will fail. - if (mA2dpDeviceAddress == mScoDeviceAddress) { + // suspend A2DP output if a SCO device is present. + if (mA2dpOutput != 0 && mScoDeviceAddress != "") { if (oldState == AudioSystem::MODE_NORMAL) { mpClientInterface->suspendOutput(mA2dpOutput); } else if (state == AudioSystem::MODE_NORMAL) { @@ -295,13 +293,31 @@ void AudioPolicyManagerBase::setPhoneState(int state) if (oldState == AudioSystem::MODE_IN_CALL && newDevice == 0) { newDevice = hwOutputDesc->device(); } + + // when changing from ring tone to in call mode, mute the ringing tone + // immediately and delay the route change to avoid sending the ring tone + // tail into the earpiece or headset. + int delayMs = 0; + if (state == AudioSystem::MODE_IN_CALL && oldState == AudioSystem::MODE_RINGTONE) { + // delay the device change command by twice the output latency to have some margin + // and be sure that audio buffers not yet affected by the mute are out when + // we actually apply the route change + delayMs = hwOutputDesc->mLatency*2; + setStreamMute(AudioSystem::RING, true, mHardwareOutput); + } + // change routing is necessary - setOutputDevice(mHardwareOutput, newDevice, force); + setOutputDevice(mHardwareOutput, newDevice, force, delayMs); // if entering in call state, handle special case of active streams // pertaining to sonification strategy see handleIncallSonification() if (state == AudioSystem::MODE_IN_CALL) { LOGV("setPhoneState() in call state management: new state is %d", state); + // unmute the ringing tone after a sufficient delay if it was muted before + // setting output device above + if (oldState == AudioSystem::MODE_RINGTONE) { + setStreamMute(AudioSystem::RING, false, mHardwareOutput, MUTE_TIME_MS); + } for (int stream = 0; stream < AudioSystem::NUM_STREAM_TYPES; stream++) { handleIncallSonification(stream, true, true); } @@ -1173,7 +1189,7 @@ status_t AudioPolicyManagerBase::handleA2dpConnection(AudioSystem::audio_devices } AudioOutputDescriptor *hwOutputDesc = mOutputs.valueFor(mHardwareOutput); - if (mA2dpDeviceAddress == mScoDeviceAddress) { + if (mScoDeviceAddress != "") { // It is normal to suspend twice if we are both in call, // and have the hardware audio output routed to BT SCO if (mPhoneState != AudioSystem::MODE_NORMAL) { @@ -1207,10 +1223,10 @@ status_t AudioPolicyManagerBase::handleA2dpDisconnection(AudioSystem::audio_devi return INVALID_OPERATION; } - // mute media during 2 seconds to avoid outputing sound on hardware output while music stream + // mute media strategy to avoid outputting sound on hardware output while music stream // is switched from A2DP output and before music is paused by music application setStrategyMute(STRATEGY_MEDIA, true, mHardwareOutput); - setStrategyMute(STRATEGY_MEDIA, false, mHardwareOutput, 2000); + setStrategyMute(STRATEGY_MEDIA, false, mHardwareOutput, MUTE_TIME_MS); if (!a2dpUsedForSonification()) { // unmute music on A2DP output if a notification or ringtone is playing @@ -1538,9 +1554,9 @@ void AudioPolicyManagerBase::setOutputDevice(audio_io_handle_t output, uint32_t usleep(outputDesc->mLatency*2*1000); } #ifdef WITH_A2DP - // suspend A2D output if SCO device is selected + // suspend A2DP output if SCO device is selected if (AudioSystem::isBluetoothScoDevice((AudioSystem::audio_devices)device)) { - if (mA2dpOutput && mScoDeviceAddress == mA2dpDeviceAddress) { + if (mA2dpOutput != 0) { mpClientInterface->suspendOutput(mA2dpOutput); } } @@ -1555,7 +1571,7 @@ void AudioPolicyManagerBase::setOutputDevice(audio_io_handle_t output, uint32_t #ifdef WITH_A2DP // if disconnecting SCO device, restore A2DP output if (AudioSystem::isBluetoothScoDevice((AudioSystem::audio_devices)prevDevice)) { - if (mA2dpOutput && mScoDeviceAddress == mA2dpDeviceAddress) { + if (mA2dpOutput != 0) { LOGV("restore A2DP output"); mpClientInterface->restoreOutput(mA2dpOutput); } |
