Loading policy_hal/Android.mk +12 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,18 @@ LOCAL_SHARED_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \ libmedia_helper \ ifeq ($(strip $(AUDIO_FEATURE_ENABLED_EXTN_FORMATS)),true) LOCAL_CFLAGS += -DAUDIO_EXTN_FORMATS_ENABLED endif ifeq ($(strip $(AUDIO_FEATURE_ENABLED_HDMI_SPK)),true) LOCAL_CFLAGS += -DAUDIO_EXTN_HDMI_SPK_ENABLED endif ifeq ($(strip $(AUDIO_FEATURE_ENABLED_PROXY_DEVICE)),true) LOCAL_CFLAGS += -DAUDIO_EXTN_AFE_PROXY_ENABLED endif LOCAL_MODULE := libaudiopolicymanager include $(BUILD_SHARED_LIBRARY) Loading policy_hal/AudioPolicyManager.cpp +59 −33 Original line number Diff line number Diff line Loading @@ -96,6 +96,15 @@ status_t AudioPolicyManagerCustom::setDeviceConnectionStateInt(audio_devices_t d // handle output device connection case AUDIO_POLICY_DEVICE_STATE_AVAILABLE: { if (index >= 0) { #ifdef AUDIO_EXTN_HDMI_SPK_ENABLED if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { if (!strncmp(device_address, "hdmi_spkr", 9)) { mHdmiAudioDisabled = false; } else { mHdmiAudioEvent = true; } } #endif ALOGW("setDeviceConnectionState() device already connected: %x", device); return INVALID_OPERATION; } Loading @@ -103,6 +112,20 @@ status_t AudioPolicyManagerCustom::setDeviceConnectionStateInt(audio_devices_t d // register new device as available index = mAvailableOutputDevices.add(devDesc); #ifdef AUDIO_EXTN_HDMI_SPK_ENABLED if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { if (!strncmp(device_address, "hdmi_spkr", 9)) { mHdmiAudioDisabled = false; } else { mHdmiAudioEvent = true; } if (mHdmiAudioDisabled || !mHdmiAudioEvent) { mAvailableOutputDevices.remove(devDesc); ALOGW("HDMI sink not connected, do not route audio to HDMI out"); return INVALID_OPERATION; } } #endif if (index >= 0) { sp<HwModule> module = mHwModules.getModuleForDevice(device); if (module == 0) { Loading Loading @@ -138,6 +161,15 @@ status_t AudioPolicyManagerCustom::setDeviceConnectionStateInt(audio_devices_t d // handle output device disconnection case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE: { if (index < 0) { #ifdef AUDIO_EXTN_HDMI_SPK_ENABLED if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { if (!strncmp(device_address, "hdmi_spkr", 9)) { mHdmiAudioDisabled = true; } else { mHdmiAudioEvent = false; } } #endif ALOGW("setDeviceConnectionState() device not connected: %x", device); return INVALID_OPERATION; } Loading @@ -151,7 +183,15 @@ status_t AudioPolicyManagerCustom::setDeviceConnectionStateInt(audio_devices_t d // remove device from available output devices mAvailableOutputDevices.remove(devDesc); #ifdef AUDIO_EXTN_HDMI_SPK_ENABLED if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { if (!strncmp(device_address, "hdmi_spkr", 9)) { mHdmiAudioDisabled = true; } else { mHdmiAudioEvent = false; } } #endif checkOutputsForDevice(devDesc, state, outputs, devDesc->mAddress); // Propagate device availability to Engine Loading Loading @@ -451,6 +491,7 @@ void AudioPolicyManagerCustom::setPhoneState(audio_mode_t state) { ALOGV("setPhoneState() state %d", state); // store previous phone state for management of sonification strategy below audio_devices_t newDevice = AUDIO_DEVICE_NONE; int oldState = mEngine->getPhoneState(); if (mEngine->setPhoneState(state) != NO_ERROR) { Loading Loading @@ -546,7 +587,14 @@ void AudioPolicyManagerCustom::setPhoneState(audio_mode_t state) setOutputDevice(mPrimaryOutput, rxDevice, force, 0); } } //update device for all non-primary outputs for (size_t i = 0; i < mOutputs.size(); i++) { audio_io_handle_t output = mOutputs.keyAt(i); if (output != mPrimaryOutput->mIoHandle) { newDevice = getNewOutputDevice(mOutputs.valueFor(output), false /*fromCache*/); setOutputDevice(mOutputs.valueFor(output), newDevice, (newDevice != AUDIO_DEVICE_NONE)); } } // if entering in call state, handle special case of active streams // pertaining to sonification strategy see handleIncallSonification() if (isStateInCall(state)) { Loading Loading @@ -578,10 +626,10 @@ status_t AudioPolicyManagerCustom::stopSource(sp<SwAudioOutputDescriptor> output handleEventForBeacon(stream == AUDIO_STREAM_TTS ? STOPPING_BEACON : STOPPING_OUTPUT); // handle special case for sonification while in call if (isInCall()) { if (isInCall() && (outputDesc->mRefCount[stream] == 1)) { if (outputDesc->isDuplicated()) { handleIncallSonification(stream, false, false, outputDesc->mIoHandle); handleIncallSonification(stream, false, false, outputDesc->mIoHandle); handleIncallSonification(stream, false, false, outputDesc->mOutput1->mIoHandle); handleIncallSonification(stream, false, false, outputDesc->mOutput2->mIoHandle); } handleIncallSonification(stream, false, false, outputDesc->mIoHandle); } Loading Loading @@ -610,8 +658,10 @@ status_t AudioPolicyManagerCustom::stopSource(sp<SwAudioOutputDescriptor> output desc->isActive() && outputDesc->sharesHwModuleWith(desc) && (newDevice != desc->device())) { audio_devices_t dev = getNewOutputDevice(mOutputs.valueFor(curOutput), false /*fromCache*/); setOutputDevice(desc, getNewOutputDevice(desc, false /*fromCache*/), dev, true, outputDesc->latency()*2); } Loading Loading @@ -897,6 +947,7 @@ audio_io_handle_t AudioPolicyManagerCustom::getOutputForDevice( ALOGE("Offloading only allowed with music stream"); return 0; } #ifdef AUDIO_EXTN_AFE_PROXY_ENABLED /* * WFD audio routes back to target speaker when starting a ringtone playback. * This is because primary output is reused for ringtone, so output device is Loading @@ -916,6 +967,7 @@ audio_io_handle_t AudioPolicyManagerCustom::getOutputForDevice( else //route every thing else to ULL path flags = AUDIO_OUTPUT_FLAG_FAST; } #endif // open a direct output if required by specified parameters //force direct flag if offload flag is set: offloading implies a direct output stream // and all common behaviors are driven by checking only the direct flag Loading Loading @@ -1077,30 +1129,4 @@ non_direct_output: return output; } audio_devices_t AudioPolicyManagerCustom::getDeviceForStrategy(routing_strategy strategy, bool fromCache) { audio_devices_t availableOutputDeviceTypes = mAvailableOutputDevices.types(); audio_devices_t device = AUDIO_DEVICE_NONE; switch (strategy) { case STRATEGY_SONIFICATION: case STRATEGY_ENFORCED_AUDIBLE: case STRATEGY_ACCESSIBILITY: case STRATEGY_REROUTING: case STRATEGY_MEDIA: if (strategy != STRATEGY_SONIFICATION){ // no sonification on WFD sink device |= availableOutputDeviceTypes & AUDIO_DEVICE_OUT_PROXY; if (device != AUDIO_DEVICE_NONE) { ALOGV("Found proxy for strategy %d", strategy); return device; } } break; default: ALOGV("getDeviceForStrategy() unknown strategy: %d", strategy); break; } device = AudioPolicyManager::getDeviceForStrategy(strategy, fromCache); return device; } } policy_hal/AudioPolicyManager.h +1 −4 Original line number Diff line number Diff line Loading @@ -40,8 +40,7 @@ namespace android { #ifndef APE_OFFLOAD_ENABLED #define AUDIO_FORMAT_APE 0x20000000UL #endif #ifndef AFE_PROXY_ENABLED #ifndef AUDIO_EXTN_AFE_PROXY_ENABLED #define AUDIO_DEVICE_OUT_PROXY 0x1000000 #endif // ---------------------------------------------------------------------------- Loading @@ -63,12 +62,10 @@ public: const char *device_name); virtual void setPhoneState(audio_mode_t state); virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo); // true if given state represents a device in a telephony or VoIP call virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy, bool fromCache); protected: status_t checkAndSetVolume(audio_stream_type_t stream, Loading Loading
policy_hal/Android.mk +12 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,18 @@ LOCAL_SHARED_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \ libmedia_helper \ ifeq ($(strip $(AUDIO_FEATURE_ENABLED_EXTN_FORMATS)),true) LOCAL_CFLAGS += -DAUDIO_EXTN_FORMATS_ENABLED endif ifeq ($(strip $(AUDIO_FEATURE_ENABLED_HDMI_SPK)),true) LOCAL_CFLAGS += -DAUDIO_EXTN_HDMI_SPK_ENABLED endif ifeq ($(strip $(AUDIO_FEATURE_ENABLED_PROXY_DEVICE)),true) LOCAL_CFLAGS += -DAUDIO_EXTN_AFE_PROXY_ENABLED endif LOCAL_MODULE := libaudiopolicymanager include $(BUILD_SHARED_LIBRARY) Loading
policy_hal/AudioPolicyManager.cpp +59 −33 Original line number Diff line number Diff line Loading @@ -96,6 +96,15 @@ status_t AudioPolicyManagerCustom::setDeviceConnectionStateInt(audio_devices_t d // handle output device connection case AUDIO_POLICY_DEVICE_STATE_AVAILABLE: { if (index >= 0) { #ifdef AUDIO_EXTN_HDMI_SPK_ENABLED if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { if (!strncmp(device_address, "hdmi_spkr", 9)) { mHdmiAudioDisabled = false; } else { mHdmiAudioEvent = true; } } #endif ALOGW("setDeviceConnectionState() device already connected: %x", device); return INVALID_OPERATION; } Loading @@ -103,6 +112,20 @@ status_t AudioPolicyManagerCustom::setDeviceConnectionStateInt(audio_devices_t d // register new device as available index = mAvailableOutputDevices.add(devDesc); #ifdef AUDIO_EXTN_HDMI_SPK_ENABLED if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { if (!strncmp(device_address, "hdmi_spkr", 9)) { mHdmiAudioDisabled = false; } else { mHdmiAudioEvent = true; } if (mHdmiAudioDisabled || !mHdmiAudioEvent) { mAvailableOutputDevices.remove(devDesc); ALOGW("HDMI sink not connected, do not route audio to HDMI out"); return INVALID_OPERATION; } } #endif if (index >= 0) { sp<HwModule> module = mHwModules.getModuleForDevice(device); if (module == 0) { Loading Loading @@ -138,6 +161,15 @@ status_t AudioPolicyManagerCustom::setDeviceConnectionStateInt(audio_devices_t d // handle output device disconnection case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE: { if (index < 0) { #ifdef AUDIO_EXTN_HDMI_SPK_ENABLED if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { if (!strncmp(device_address, "hdmi_spkr", 9)) { mHdmiAudioDisabled = true; } else { mHdmiAudioEvent = false; } } #endif ALOGW("setDeviceConnectionState() device not connected: %x", device); return INVALID_OPERATION; } Loading @@ -151,7 +183,15 @@ status_t AudioPolicyManagerCustom::setDeviceConnectionStateInt(audio_devices_t d // remove device from available output devices mAvailableOutputDevices.remove(devDesc); #ifdef AUDIO_EXTN_HDMI_SPK_ENABLED if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { if (!strncmp(device_address, "hdmi_spkr", 9)) { mHdmiAudioDisabled = true; } else { mHdmiAudioEvent = false; } } #endif checkOutputsForDevice(devDesc, state, outputs, devDesc->mAddress); // Propagate device availability to Engine Loading Loading @@ -451,6 +491,7 @@ void AudioPolicyManagerCustom::setPhoneState(audio_mode_t state) { ALOGV("setPhoneState() state %d", state); // store previous phone state for management of sonification strategy below audio_devices_t newDevice = AUDIO_DEVICE_NONE; int oldState = mEngine->getPhoneState(); if (mEngine->setPhoneState(state) != NO_ERROR) { Loading Loading @@ -546,7 +587,14 @@ void AudioPolicyManagerCustom::setPhoneState(audio_mode_t state) setOutputDevice(mPrimaryOutput, rxDevice, force, 0); } } //update device for all non-primary outputs for (size_t i = 0; i < mOutputs.size(); i++) { audio_io_handle_t output = mOutputs.keyAt(i); if (output != mPrimaryOutput->mIoHandle) { newDevice = getNewOutputDevice(mOutputs.valueFor(output), false /*fromCache*/); setOutputDevice(mOutputs.valueFor(output), newDevice, (newDevice != AUDIO_DEVICE_NONE)); } } // if entering in call state, handle special case of active streams // pertaining to sonification strategy see handleIncallSonification() if (isStateInCall(state)) { Loading Loading @@ -578,10 +626,10 @@ status_t AudioPolicyManagerCustom::stopSource(sp<SwAudioOutputDescriptor> output handleEventForBeacon(stream == AUDIO_STREAM_TTS ? STOPPING_BEACON : STOPPING_OUTPUT); // handle special case for sonification while in call if (isInCall()) { if (isInCall() && (outputDesc->mRefCount[stream] == 1)) { if (outputDesc->isDuplicated()) { handleIncallSonification(stream, false, false, outputDesc->mIoHandle); handleIncallSonification(stream, false, false, outputDesc->mIoHandle); handleIncallSonification(stream, false, false, outputDesc->mOutput1->mIoHandle); handleIncallSonification(stream, false, false, outputDesc->mOutput2->mIoHandle); } handleIncallSonification(stream, false, false, outputDesc->mIoHandle); } Loading Loading @@ -610,8 +658,10 @@ status_t AudioPolicyManagerCustom::stopSource(sp<SwAudioOutputDescriptor> output desc->isActive() && outputDesc->sharesHwModuleWith(desc) && (newDevice != desc->device())) { audio_devices_t dev = getNewOutputDevice(mOutputs.valueFor(curOutput), false /*fromCache*/); setOutputDevice(desc, getNewOutputDevice(desc, false /*fromCache*/), dev, true, outputDesc->latency()*2); } Loading Loading @@ -897,6 +947,7 @@ audio_io_handle_t AudioPolicyManagerCustom::getOutputForDevice( ALOGE("Offloading only allowed with music stream"); return 0; } #ifdef AUDIO_EXTN_AFE_PROXY_ENABLED /* * WFD audio routes back to target speaker when starting a ringtone playback. * This is because primary output is reused for ringtone, so output device is Loading @@ -916,6 +967,7 @@ audio_io_handle_t AudioPolicyManagerCustom::getOutputForDevice( else //route every thing else to ULL path flags = AUDIO_OUTPUT_FLAG_FAST; } #endif // open a direct output if required by specified parameters //force direct flag if offload flag is set: offloading implies a direct output stream // and all common behaviors are driven by checking only the direct flag Loading Loading @@ -1077,30 +1129,4 @@ non_direct_output: return output; } audio_devices_t AudioPolicyManagerCustom::getDeviceForStrategy(routing_strategy strategy, bool fromCache) { audio_devices_t availableOutputDeviceTypes = mAvailableOutputDevices.types(); audio_devices_t device = AUDIO_DEVICE_NONE; switch (strategy) { case STRATEGY_SONIFICATION: case STRATEGY_ENFORCED_AUDIBLE: case STRATEGY_ACCESSIBILITY: case STRATEGY_REROUTING: case STRATEGY_MEDIA: if (strategy != STRATEGY_SONIFICATION){ // no sonification on WFD sink device |= availableOutputDeviceTypes & AUDIO_DEVICE_OUT_PROXY; if (device != AUDIO_DEVICE_NONE) { ALOGV("Found proxy for strategy %d", strategy); return device; } } break; default: ALOGV("getDeviceForStrategy() unknown strategy: %d", strategy); break; } device = AudioPolicyManager::getDeviceForStrategy(strategy, fromCache); return device; } }
policy_hal/AudioPolicyManager.h +1 −4 Original line number Diff line number Diff line Loading @@ -40,8 +40,7 @@ namespace android { #ifndef APE_OFFLOAD_ENABLED #define AUDIO_FORMAT_APE 0x20000000UL #endif #ifndef AFE_PROXY_ENABLED #ifndef AUDIO_EXTN_AFE_PROXY_ENABLED #define AUDIO_DEVICE_OUT_PROXY 0x1000000 #endif // ---------------------------------------------------------------------------- Loading @@ -63,12 +62,10 @@ public: const char *device_name); virtual void setPhoneState(audio_mode_t state); virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo); // true if given state represents a device in a telephony or VoIP call virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy, bool fromCache); protected: status_t checkAndSetVolume(audio_stream_type_t stream, Loading