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

Commit 99896dab authored by Francois Gaffie's avatar Francois Gaffie Committed by Eric Laurent
Browse files

audiopolicy: Fix sofware bridge creation for AudioHAL supporting routing APIs



AudioPolicy roughly checks if HAL supports routing APIs 3.0 to enable or
not software bridge in case of device to device patch requests.

However, Audio HAL declares in XML file routes supported. AudioPolicy
shall refine its decision upon information available in the policy configuration
file.

Test: Audio smoke tests.
Test: CTS tests for AudioRecord, AudioTrack and AudioEffect

Change-Id: Idc2e1ccd7d9fb6385f9a05ee002bec045e608232
Signed-off-by: default avatarFrancois Gaffie <francois.gaffie@renault.com>
parent d00c4607
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -46,6 +46,19 @@ public:

    audio_route_type_t getType() const { return mType; }

    /**
     * @brief supportsPatch checks if an audio patch is supported by a Route declared in
     * the audio_policy_configuration.xml file.
     * If the patch is supported natively by an AudioHAL (which supports of course Routing API 3.0),
     * audiopolicy will not request AudioFlinger to use a software bridge to realize a patch
     * between 2 ports.
     * @param srcPort (aka the source) to be considered
     * @param dstPort (aka the sink) to be considered
     * @return true if the audio route supports the connection between the sink and the source,
     * false otherwise
     */
    bool supportsPatch(const sp<AudioPort> &srcPort, const sp<AudioPort> &dstPort) const;

    void dump(String8 *dst, int spaces) const;

private:
+11 −0
Original line number Diff line number Diff line
@@ -81,6 +81,17 @@ public:
        return mPorts.findByTagName(tagName);
    }

    /**
     * @brief supportsPatch checks if an audio patch between 2 ports beloging to this HwModule
     * is supported by a HwModule. The ports and the route shall be declared in the
     * audio_policy_configuration.xml file.
     * @param srcPort (aka the source) to be considered
     * @param dstPort (aka the sink) to be considered
     * @return true if the HwModule supports the connection between the sink and the source,
     * false otherwise
     */
    bool supportsPatch(const sp<AudioPort> &srcPort, const sp<AudioPort> &dstPort) const;

    // TODO remove from here (split serialization)
    void dump(String8 *dst) const;

+15 −0
Original line number Diff line number Diff line
@@ -37,4 +37,19 @@ void AudioRoute::dump(String8 *dst, int spaces) const
    dst->append("\n");
}

bool AudioRoute::supportsPatch(const sp<AudioPort> &srcPort, const sp<AudioPort> &dstPort) const
{
    if (mSink == 0 || dstPort == 0 || dstPort != mSink) {
        return false;
    }
    ALOGV("%s: sinks %s matching", __FUNCTION__, mSink->getTagName().string());
    for (const auto &sourcePort : mSources) {
        if (sourcePort == srcPort) {
            ALOGV("%s: sources %s matching", __FUNCTION__, sourcePort->getTagName().string());
            return true;
        }
    }
    return false;
}

}
+9 −0
Original line number Diff line number Diff line
@@ -218,6 +218,15 @@ void HwModule::setHandle(audio_module_handle_t handle) {
    mHandle = handle;
}

bool HwModule::supportsPatch(const sp<AudioPort> &srcPort, const sp<AudioPort> &dstPort) const {
    for (const auto &route : mRoutes) {
        if (route->supportsPatch(srcPort, dstPort)) {
            return true;
        }
    }
    return false;
}

void HwModule::dump(String8 *dst) const
{
    dst->appendFormat("  - name: %s\n", getName());
+3 −1
Original line number Diff line number Diff line
@@ -3083,8 +3083,10 @@ status_t AudioPolicyManager::createAudioPatch(const struct audio_patch *patch,
                // create a software bridge in PatchPanel if:
                // - source and sink devices are on different HW modules OR
                // - audio HAL version is < 3.0
                // - audio HAL version is >= 3.0 but no route has been declared between devices
                if (!srcDeviceDesc->hasSameHwModuleAs(sinkDeviceDesc) ||
                        (srcDeviceDesc->mModule->getHalVersionMajor() < 3)) {
                        (srcDeviceDesc->mModule->getHalVersionMajor() < 3) ||
                        !srcDeviceDesc->mModule->supportsPatch(srcDeviceDesc, sinkDeviceDesc)) {
                    // support only one sink device for now to simplify output selection logic
                    if (patch->num_sinks > 1) {
                        return INVALID_OPERATION;