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

Commit 07c99014 authored by Jaideep Sharma's avatar Jaideep Sharma Committed by Eric Laurent
Browse files

audiopolicy: Add support for multiple display ports.

Sort devices added to policy manager based on device type.
For devices of same type sort based on id, which places the
latest devices in the front of the list.
For devices of same type, no id, fallback to default
sort using pointer address.
This is needed when same type of different devices can be connected.

Bug: 111196161
Test: manual audio smoke tests.

Change-Id: I428e9f0cb5d8e9700be7b96cea665bc2e0d2805e
parent e4d123ad
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -278,6 +278,8 @@ public:

    void dump(String8 *dst, const String8 &tag, int spaces = 0, bool verbose = true) const;

protected:
    int     do_compare(const void* lhs, const void* rhs) const;
private:
    void refreshTypes();
    void refreshAudioProfiles();
+17 −0
Original line number Diff line number Diff line
@@ -279,6 +279,23 @@ ssize_t DeviceVector::add(const sp<DeviceDescriptor>& item)
    return ret;
}

int DeviceVector::do_compare(const void* lhs, const void* rhs) const {
    const auto ldevice = *reinterpret_cast<const sp<DeviceDescriptor>*>(lhs);
    const auto rdevice = *reinterpret_cast<const sp<DeviceDescriptor>*>(rhs);
    int ret = 0;

    // sort by type.
    ret = compare_type(ldevice->type(), rdevice->type());
    if (ret != 0)
        return ret;
    // for same type higher priority for latest device.
    ret = compare_type(rdevice->getId(), ldevice->getId());
    if (ret != 0)
        return ret;
    // fallback to default sort using pointer address
    return SortedVector::do_compare(lhs, rhs);
}

ssize_t DeviceVector::remove(const sp<DeviceDescriptor>& item)
{
    ssize_t ret = indexOf(item);