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

Commit 4c34434a authored by Francois Gaffie's avatar Francois Gaffie Committed by Eric Laurent
Browse files

audiopolicy: HW Bridge Sink matching rule



In order to use an HW Bridge, audio policy configuration file
must declare that a given sink may be reacheable from a given source
device.
The declaration is made using the "Tag Name", which is a human readable
name given to a device / mix Port.

This CL adds an equality operator based only on this tag name, which
identify uniquely the device port.

This CL manages also dynamic device cases, the tagName shall be assigned
to all dynamically created device.

Test: adb shell ./data/AudioPolicyEmulatorTests/AudioPolicyEmulatorTests --gtest_filter=*VoiceCallBridgingTest*

Signed-off-by: default avatarFrancois Gaffie <francois.gaffie@renault.com>
Change-Id: I0fc6435dcc5f40634be5392dd92dcd2f377809c2
parent adec76d0
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ public:

    bool supportsFormat(audio_format_t format);

    void setDynamic() { mIsDynamic = true; }
    bool isDynamic() const { return mIsDynamic; }

    // PolicyAudioPortConfig
    virtual sp<PolicyAudioPort> getPolicyAudioPort() const {
        return static_cast<PolicyAudioPort*>(const_cast<DeviceDescriptor*>(this));
@@ -97,6 +100,8 @@ private:
    std::string mTagName; // Unique human readable identifier for a device port found in conf file.
    FormatVector        mEncodedFormats;
    audio_format_t      mCurrentEncodedFormat;
    bool                mIsDynamic = false;
    const std::string   mDeclaredAddress; // Original device address
};

class DeviceVector : public SortedVector<sp<DeviceDescriptor> >
+10 −1
Original line number Diff line number Diff line
@@ -131,8 +131,17 @@ class HwModuleCollection : public Vector<sp<HwModule> >
public:
    sp<HwModule> getModuleFromName(const char *name) const;

    /**
     * @brief getModuleForDeviceType try to get a device from type / format on all modules
     * @param device type to consider
     * @param encodedFormat to consider
     * @param[out] tagName if not null, if a matching device is found, will return the tagName
     * of original device from XML file so that audio routes matchin rules work.
     * @return valid module if considered device found, nullptr otherwise.
     */
    sp<HwModule> getModuleForDeviceType(audio_devices_t device,
                                        audio_format_t encodedFormat) const;
                                        audio_format_t encodedFormat,
                                        std::string *tagName = nullptr) const;

    sp<HwModule> getModuleForDevice(const sp<DeviceDescriptor> &device,
                                    audio_format_t encodedFormat) const;
+19 −0
Original line number Diff line number Diff line
@@ -111,6 +111,19 @@ public:
               (!areOutputDevices || devicesSupportEncodedFormats(deviceTypes));
    }

    /**
     * @brief getTag
     * @param deviceTypes to be considered
     * @return tagName of first matching device for the considered types, empty string otherwise.
     */
    std::string getTag(const DeviceTypeSet& deviceTypes) const
    {
        if (supportsDeviceTypes(deviceTypes)) {
            return mSupportedDevices.getDevicesFromTypes(deviceTypes).itemAt(0)->getTagName();
        }
        return {};
    }

    /**
     * @brief supportsDevice
     * @param device to be checked against
@@ -150,6 +163,12 @@ public:
    }
    void removeSupportedDevice(const sp<DeviceDescriptor> &device)
    {
        ssize_t ret = mSupportedDevices.indexOf(device);
        if (ret >= 0 && !mSupportedDevices.itemAt(ret)->isDynamic()) {
            // devices equality checks only type, address, name and format
            // Prevents from removing non dynamically added devices
            return;
        }
        mSupportedDevices.remove(device);
    }
    void setSupportedDevices(const DeviceVector &devices)
+5 −0
Original line number Diff line number Diff line
@@ -42,6 +42,11 @@ public:

    virtual const std::string getTagName() const = 0;

    bool equals(const sp<PolicyAudioPort> &right) const
    {
        return getTagName() == right->getTagName();
    }

    virtual sp<AudioPort> asAudioPort() const = 0;

    virtual void setFlags(uint32_t flags)
+2 −2
Original line number Diff line number Diff line
@@ -39,12 +39,12 @@ void AudioRoute::dump(String8 *dst, int spaces) const
bool AudioRoute::supportsPatch(const sp<PolicyAudioPort> &srcPort,
                               const sp<PolicyAudioPort> &dstPort) const
{
    if (mSink == 0 || dstPort == 0 || dstPort != mSink) {
    if (mSink == 0 || dstPort == 0 || !dstPort->equals(mSink)) {
        return false;
    }
    ALOGV("%s: sinks %s matching", __FUNCTION__, mSink->getTagName().c_str());
    for (const auto &sourcePort : mSources) {
        if (sourcePort == srcPort) {
        if (sourcePort->equals(srcPort)) {
            ALOGV("%s: sources %s matching", __FUNCTION__, sourcePort->getTagName().c_str());
            return true;
        }
Loading