From de496d8d5fdc1070348b6ac14aebb4b9802ddc5d Mon Sep 17 00:00:00 2001 From: Tanya Finkel Date: Wed, 5 Mar 2014 23:59:45 +0200 Subject: [PATCH] Audio: Add routing option between HDMI speakers and device speakers Add option that routing between HDMI audio output and device audio output, when HDMI is connected. Change-Id: I9bbe9b1cbee5b6659502dae386c086f37bef2120 --- policy_hal/Android.mk | 3 +++ policy_hal/AudioPolicyManager.cpp | 40 +++++++++++++++++++++++++++++++ policy_hal/AudioPolicyManager.h | 12 +++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/policy_hal/Android.mk b/policy_hal/Android.mk index c68ab6ea..4f3a737e 100644 --- a/policy_hal/Android.mk +++ b/policy_hal/Android.mk @@ -29,6 +29,9 @@ endif ifneq ($(strip $(AUDIO_FEATURE_DISABLED_INCALL_MUSIC)),true) LOCAL_CFLAGS += -DAUDIO_EXTN_INCALL_MUSIC_ENABLED endif +ifneq ($(strip $(AUDIO_FEATURE_DISABLED_HDMI_SPK)),true) +LOCAL_CFLAGS += -DAUDIO_EXTN_HDMI_SPK_ENABLED +endif ifeq ($(strip $(TARGET_BOARD_PLATFORM)),msm8916) diff --git a/policy_hal/AudioPolicyManager.cpp b/policy_hal/AudioPolicyManager.cpp index a774c9e2..89474564 100644 --- a/policy_hal/AudioPolicyManager.cpp +++ b/policy_hal/AudioPolicyManager.cpp @@ -44,6 +44,7 @@ namespace android_audio_legacy { // ---------------------------------------------------------------------------- // AudioPolicyInterface implementation // ---------------------------------------------------------------------------- +const char* AudioPolicyManager::HDMI_SPKR_STR = "hdmi_spkr"; status_t AudioPolicyManager::setDeviceConnectionState(audio_devices_t device, AudioSystem::device_connection_state state, @@ -85,6 +86,15 @@ status_t AudioPolicyManager::setDeviceConnectionState(audio_devices_t device, // handle output device connection case AudioSystem::DEVICE_STATE_AVAILABLE: if (mAvailableOutputDevices & device) { +#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED + if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { + if (!strncmp(device_address, HDMI_SPKR_STR, MAX_DEVICE_ADDRESS_LEN)) { + mHdmiAudioDisabled = false; + } else { + mHdmiAudioEvent = true; + } + } +#endif ALOGW("setDeviceConnectionState() device already connected: %x", device); return INVALID_OPERATION; } @@ -98,6 +108,18 @@ status_t AudioPolicyManager::setDeviceConnectionState(audio_devices_t device, // register new device as available mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices | device); +#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED + if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { + if (!strncmp(device_address, HDMI_SPKR_STR, MAX_DEVICE_ADDRESS_LEN)) { + mHdmiAudioDisabled = false; + } else { + mHdmiAudioEvent = true; + } + if (mHdmiAudioDisabled || !mHdmiAudioEvent) { + mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices & ~device); + } + } +#endif if (!outputs.isEmpty()) { String8 paramStr; if (mHasA2dp && audio_is_a2dp_device(device)) { @@ -127,6 +149,15 @@ status_t AudioPolicyManager::setDeviceConnectionState(audio_devices_t device, // handle output device disconnection case AudioSystem::DEVICE_STATE_UNAVAILABLE: { if (!(mAvailableOutputDevices & device)) { +#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED + if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { + if (!strncmp(device_address, HDMI_SPKR_STR, MAX_DEVICE_ADDRESS_LEN)) { + mHdmiAudioDisabled = true; + } else { + mHdmiAudioEvent = false; + } + } +#endif ALOGW("setDeviceConnectionState() device not connected: %x", device); return INVALID_OPERATION; } @@ -135,6 +166,15 @@ status_t AudioPolicyManager::setDeviceConnectionState(audio_devices_t device, // remove device from available output devices mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices & ~device); +#ifdef AUDIO_EXTN_HDMI_SPK_ENABLED + if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) { + if (!strncmp(device_address, HDMI_SPKR_STR, MAX_DEVICE_ADDRESS_LEN)) { + mHdmiAudioDisabled = true; + } else { + mHdmiAudioEvent = false; + } + } +#endif checkOutputsForDevice(device, state, outputs); if (mHasA2dp && audio_is_a2dp_device(device)) { // handle A2DP device disconnection diff --git a/policy_hal/AudioPolicyManager.h b/policy_hal/AudioPolicyManager.h index 34ca701c..188488a4 100644 --- a/policy_hal/AudioPolicyManager.h +++ b/policy_hal/AudioPolicyManager.h @@ -35,7 +35,9 @@ class AudioPolicyManager: public AudioPolicyManagerBase public: AudioPolicyManager(AudioPolicyClientInterface *clientInterface) - : AudioPolicyManagerBase(clientInterface) {} + : AudioPolicyManagerBase(clientInterface) { + mHdmiAudioDisabled = false; + mHdmiAudioEvent = false; } virtual ~AudioPolicyManager() {} @@ -89,5 +91,13 @@ protected: // returns the category the device belongs to with regard to volume curve management static device_category getDeviceCategory(audio_devices_t device); + static const char* HDMI_SPKR_STR; + + //parameter indicates of HDMI speakers disabled from the Qualcomm settings + bool mHdmiAudioDisabled; + + //parameter indicates if HDMI plug in/out detected + bool mHdmiAudioEvent; + }; };