Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e2bfe7ff authored by Aniket Kumar Lata's avatar Aniket Kumar Lata Committed by android-build-merger
Browse files

Merge changes from topic "bt-a2dp-offload-aosp"

am: 262eb819

Change-Id: I008587282bdad3df2322f7975cf426ccb2e5ab91
parents 7c5acee3 262eb819
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -179,6 +179,16 @@ public:
     */
    audio_io_handle_t getA2dpOutput() const;

    /**
     * returns true if primary HAL supports A2DP Offload
     */
    bool isA2dpOffloadedOnPrimary() const;

    /**
     * returns true if A2DP is supported (either via hardware offload or software encoding)
     */
    bool isA2dpSupported() const;

    sp<SwAudioOutputDescriptor> getOutputFromId(audio_port_handle_t id) const;

    sp<SwAudioOutputDescriptor> getPrimaryOutput() const;
+23 −0
Original line number Diff line number Diff line
@@ -486,6 +486,29 @@ audio_io_handle_t SwAudioOutputCollection::getA2dpOutput() const
    return 0;
}

bool SwAudioOutputCollection::isA2dpOffloadedOnPrimary() const
{
    sp<SwAudioOutputDescriptor> primaryOutput = getPrimaryOutput();

    if ((primaryOutput != NULL) && (primaryOutput->mProfile != NULL)
        && (primaryOutput->mProfile->mModule != NULL)) {
        sp<HwModule> primaryHwModule = primaryOutput->mProfile->mModule;
        Vector <sp<IOProfile>> primaryHwModuleOutputProfiles =
                                   primaryHwModule->getOutputProfiles();
        for (size_t i = 0; i < primaryHwModuleOutputProfiles.size(); i++) {
            if (primaryHwModuleOutputProfiles[i]->supportDevice(AUDIO_DEVICE_OUT_ALL_A2DP)) {
                return true;
            }
        }
    }
    return false;
}

bool SwAudioOutputCollection::isA2dpSupported() const
{
    return (isA2dpOffloadedOnPrimary() || (getA2dpOutput() != 0));
}

sp<SwAudioOutputDescriptor> SwAudioOutputCollection::getPrimaryOutput() const
{
    for (size_t i = 0; i < size(); i++) {
+3 −3
Original line number Diff line number Diff line
@@ -347,7 +347,7 @@ audio_devices_t Engine::getDeviceForStrategyInt(routing_strategy strategy,
            // when not in a phone call, phone strategy should route STREAM_VOICE_CALL to A2DP
            if (!isInCall() &&
                    (mForceUse[AUDIO_POLICY_FORCE_FOR_MEDIA] != AUDIO_POLICY_FORCE_NO_BT_A2DP) &&
                    (outputs.getA2dpOutput() != 0)) {
                     outputs.isA2dpSupported()) {
                device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP;
                if (device) break;
                device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES;
@@ -381,7 +381,7 @@ audio_devices_t Engine::getDeviceForStrategyInt(routing_strategy strategy,
            // A2DP speaker when forcing to speaker output
            if (!isInCall() &&
                    (mForceUse[AUDIO_POLICY_FORCE_FOR_MEDIA] != AUDIO_POLICY_FORCE_NO_BT_A2DP) &&
                    (outputs.getA2dpOutput() != 0)) {
                     outputs.isA2dpSupported()) {
                device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER;
                if (device) break;
            }
@@ -491,7 +491,7 @@ audio_devices_t Engine::getDeviceForStrategyInt(routing_strategy strategy,
        }
        if ((device2 == AUDIO_DEVICE_NONE) &&
                (mForceUse[AUDIO_POLICY_FORCE_FOR_MEDIA] != AUDIO_POLICY_FORCE_NO_BT_A2DP) &&
                (outputs.getA2dpOutput() != 0)) {
                 outputs.isA2dpSupported()) {
            device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP;
            if (device2 == AUDIO_DEVICE_NONE) {
                device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES;
+6 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@

#define AUDIO_POLICY_XML_CONFIG_FILE_PATH_MAX_LENGTH 128
#define AUDIO_POLICY_XML_CONFIG_FILE_NAME "audio_policy_configuration.xml"
#define AUDIO_POLICY_A2DP_OFFLOAD_XML_CONFIG_FILE_NAME "audio_policy_a2dp_offload_configuration.xml"

#include <inttypes.h>
#include <math.h>
@@ -3565,10 +3566,13 @@ static status_t deserializeAudioPolicyXmlConfig(AudioPolicyConfig &config) {

    for (int i = 0; i < kConfigLocationListSize; i++) {
        PolicySerializer serializer;
        bool use_a2dp_offload_config =
                 property_get_bool("persist.bluetooth.a2dp_offload.enable", false);
        snprintf(audioPolicyXmlConfigFile,
                 sizeof(audioPolicyXmlConfigFile),
                 "%s/%s",
                 kConfigLocationList[i],
                 use_a2dp_offload_config ? AUDIO_POLICY_A2DP_OFFLOAD_XML_CONFIG_FILE_NAME :
                     AUDIO_POLICY_XML_CONFIG_FILE_NAME);
        ret = serializer.deserialize(audioPolicyXmlConfigFile, config);
        if (ret == NO_ERROR) {
@@ -4666,7 +4670,7 @@ void AudioPolicyManager::checkOutputForAllStrategies()
void AudioPolicyManager::checkA2dpSuspend()
{
    audio_io_handle_t a2dpOutput = mOutputs.getA2dpOutput();
    if (a2dpOutput == 0) {
    if (a2dpOutput == 0 || mOutputs.isA2dpOffloadedOnPrimary()) {
        mA2dpSuspended = false;
        return;
    }