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

Commit f34c00f5 authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "AudioPolicyManager: update getDevicesForAttributes" into tm-dev

parents dfc054f6 6d23c0f5
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1270,7 +1270,8 @@ DeviceTypeSet AudioSystem::getDevicesForStream(audio_stream_type_t stream) {
}

status_t AudioSystem::getDevicesForAttributes(const AudioAttributes& aa,
                                              AudioDeviceTypeAddrVector* devices) {
                                              AudioDeviceTypeAddrVector* devices,
                                              bool forVolume) {
    if (devices == nullptr) {
        return BAD_VALUE;
    }
@@ -1281,7 +1282,7 @@ status_t AudioSystem::getDevicesForAttributes(const AudioAttributes& aa,
            legacy2aidl_AudioAttributes_AudioAttributesEx(aa));
    std::vector<AudioDevice> retAidl;
    RETURN_STATUS_IF_ERROR(
            statusTFromBinderStatus(aps->getDevicesForAttributes(aaAidl, &retAidl)));
            statusTFromBinderStatus(aps->getDevicesForAttributes(aaAidl, forVolume, &retAidl)));
    *devices = VALUE_OR_RETURN_STATUS(
            convertContainer<AudioDeviceTypeAddrVector>(
                    retAidl,
+1 −1
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ interface IAudioPolicyService {

    AudioDeviceDescription[] getDevicesForStream(AudioStreamType stream);

    AudioDevice[] getDevicesForAttributes(in AudioAttributesEx attr);
    AudioDevice[] getDevicesForAttributes(in AudioAttributesEx attr, boolean forVolume);

    int /* audio_io_handle_t */ getOutputForEffect(in EffectDescriptor desc);

+2 −1
Original line number Diff line number Diff line
@@ -330,7 +330,8 @@ public:
    static product_strategy_t getStrategyForStream(audio_stream_type_t stream);
    static DeviceTypeSet getDevicesForStream(audio_stream_type_t stream);
    static status_t getDevicesForAttributes(const AudioAttributes &aa,
                                            AudioDeviceTypeAddrVector *devices);
                                            AudioDeviceTypeAddrVector *devices,
                                            bool forVolume);

    static audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc);
    static status_t registerEffect(const effect_descriptor_t *desc,
+2 −1
Original line number Diff line number Diff line
@@ -215,7 +215,8 @@ public:

    // retrieves the list of enabled output devices for the given audio attributes
    virtual status_t getDevicesForAttributes(const audio_attributes_t &attr,
                                             AudioDeviceTypeAddrVector *devices) = 0;
                                             AudioDeviceTypeAddrVector *devices,
                                             bool forVolume) = 0;

    // Audio effect management
    virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc) = 0;
+53 −8
Original line number Diff line number Diff line
@@ -3919,7 +3919,7 @@ audio_direct_mode_t AudioPolicyManager::getDirectPlaybackSupport(const audio_att
status_t AudioPolicyManager::getDirectProfilesForAttributes(const audio_attributes_t* attr,
                                                AudioProfileVector& audioProfilesVector) {
    AudioDeviceTypeAddrVector devices;
    status_t status = getDevicesForAttributes(*attr, &devices);
    status_t status = getDevicesForAttributes(*attr, &devices, false /* forVolume */);
    if (status != OK) {
        return status;
    }
@@ -6472,24 +6472,69 @@ DeviceTypeSet AudioPolicyManager::getDevicesForStream(audio_stream_type_t stream

// TODO - consider MSD routes b/214971780
status_t AudioPolicyManager::getDevicesForAttributes(
        const audio_attributes_t &attr, AudioDeviceTypeAddrVector *devices) {
        const audio_attributes_t &attr, AudioDeviceTypeAddrVector *devices, bool forVolume) {
    if (devices == nullptr) {
        return BAD_VALUE;
    }

    // Devices are determined in the following precedence:
    //
    // 1) Devices associated with a dynamic policy matching the attributes.  This is often
    //    a remote submix from MIX_ROUTE_FLAG_LOOP_BACK.
    //
    // If no such dynamic policy then
    // 2) Devices containing an active client using setPreferredDevice
    //    with same strategy as the attributes.
    //    (from the default Engine::getOutputDevicesForAttributes() implementation).
    //
    // If no corresponding active client with setPreferredDevice then
    // 3) Devices associated with the strategy determined by the attributes
    //    (from the default Engine::getOutputDevicesForAttributes() implementation).
    //
    // See related getOutputForAttrInt().

    // check dynamic policies but only for primary descriptors (secondary not used for audible
    // audio routing, only used for duplication for playback capture)
    sp<AudioPolicyMix> policyMix;
    status_t status = mPolicyMixes.getOutputForAttr(attr, 0 /*uid unknown here*/,
            AUDIO_OUTPUT_FLAG_NONE, policyMix, nullptr);
            AUDIO_OUTPUT_FLAG_NONE, policyMix, nullptr /* secondaryMixes */);
    if (status != OK) {
        return status;
    }
    if (policyMix != nullptr && policyMix->getOutput() != nullptr) {
        AudioDeviceTypeAddr device(policyMix->mDeviceType, policyMix->mDeviceAddress.c_str());
        devices->push_back(device);
        return NO_ERROR;

    DeviceVector curDevices;
    if (policyMix != nullptr && policyMix->getOutput() != nullptr &&
            // For volume control, skip LOOPBACK mixes which use AUDIO_DEVICE_OUT_REMOTE_SUBMIX
            // as they are unaffected by device/stream volume
            // (per SwAudioOutputDescriptor::isFixedVolume()).
            (!forVolume || policyMix->mDeviceType != AUDIO_DEVICE_OUT_REMOTE_SUBMIX)
            ) {
        sp<DeviceDescriptor> deviceDesc = mAvailableOutputDevices.getDevice(
                policyMix->mDeviceType, policyMix->mDeviceAddress, AUDIO_FORMAT_DEFAULT);
        curDevices.add(deviceDesc);
    } else {
        // The default Engine::getOutputDevicesForAttributes() uses findPreferredDevice()
        // which selects setPreferredDevice if active.  This means forVolume call
        // will take an active setPreferredDevice, if such exists.

        curDevices = mEngine->getOutputDevicesForAttributes(
                attr, nullptr /* preferredDevice */, false /* fromCache */);
    }

    if (forVolume) {
        // We alias the device AUDIO_DEVICE_OUT_SPEAKER_SAFE to AUDIO_DEVICE_OUT_SPEAKER
        // for single volume control in AudioService (such relationship should exist if
        // SPEAKER_SAFE is present).
        //
        // (This is unrelated to a different device grouping as Volume::getDeviceCategory)
        DeviceVector speakerSafeDevices =
                curDevices.getDevicesFromType(AUDIO_DEVICE_OUT_SPEAKER_SAFE);
        if (!speakerSafeDevices.isEmpty()) {
            curDevices.merge(
                    mAvailableOutputDevices.getDevicesFromType(AUDIO_DEVICE_OUT_SPEAKER));
            curDevices.remove(speakerSafeDevices);
        }
    }
    DeviceVector curDevices = mEngine->getOutputDevicesForAttributes(attr, nullptr, false);
    for (const auto& device : curDevices) {
        devices->push_back(device->getDeviceTypeAddr());
    }
Loading