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

Commit 708e038f authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

audiopolicy: Brush up DeviceVector::getDevice... methods

The semantics of these methods wasn't consistent and wasn't clear
from their names (and aggravated by the fact that audio_devices_t can
be used either as a single device, or as a mask):

 * sp<DeviceDescriptor> getDevice(type, address) -- 'type' is a single
   device; if 'address' is an empty string, and no matching device
   with an empty address is found, returns any device of this type;

 * DeviceVector getDevicesFromType(type) -- 'type' is a mask,
   device addresses get ignored;

 * DeviceVector getDevicesFromTypeAddr(type, address) -- 'type' is
   a single device, address is matched exactly. So in practice, only
   1 device could be returned.

Changes:

 * 'getDevicesFromType' renamed to 'getDevicesFromTypeMask' --
   emhpasizes the fact that 'type' can be a mask;

 * 'getDevicesFromTypeAddr' removed, usages replaced with a call to
   'getDevice'. There were just 2 usages, and their intent seem
   to be covered by the semantics of 'getDevice'.

Test: verified basic audio functionality and Auto with simulator
Change-Id: If3e42e4c06f42573fd33ba1303febe0625e079e6
parent f4d3741b
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -76,11 +76,12 @@ public:

    audio_devices_t types() const { return mDeviceTypes; }

    // If 'address' is empty, a device with a non-empty address may be returned
    // if there is no device with the specified 'type' and empty address.
    sp<DeviceDescriptor> getDevice(audio_devices_t type, const String8 &address) const;
    DeviceVector getDevicesFromType(audio_devices_t types) const;
    DeviceVector getDevicesFromTypeMask(audio_devices_t types) const;
    sp<DeviceDescriptor> getDeviceFromId(audio_port_handle_t id) const;
    sp<DeviceDescriptor> getDeviceFromTagName(const String8 &tagName) const;
    DeviceVector getDevicesFromTypeAddr(audio_devices_t type, const String8& address) const;

    audio_devices_t getDevicesFromHwModule(audio_module_handle_t moduleHandle) const;

+1 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ public:
    sp<DeviceDescriptor> getDeviceDescriptor(const audio_devices_t device,
                                             const char *device_address,
                                             const char *device_name,
                                             bool matchAdress = true) const;
                                             bool matchAddress = true) const;

    status_t dump(int fd) const;
};
+7 −19
Original line number Diff line number Diff line
@@ -145,8 +145,8 @@ sp<DeviceDescriptor> DeviceVector::getDevice(audio_devices_t type, const String8
            }
        }
    }
    ALOGV("DeviceVector::getDevice() for type %08x address %s found %p",
          type, address.string(), device.get());
    ALOGV("DeviceVector::%s() for type %08x address \"%s\" found %p",
            __func__, type, address.string(), device.get());
    return device;
}

@@ -160,7 +160,7 @@ sp<DeviceDescriptor> DeviceVector::getDeviceFromId(audio_port_handle_t id) const
    return nullptr;
}

DeviceVector DeviceVector::getDevicesFromType(audio_devices_t type) const
DeviceVector DeviceVector::getDevicesFromTypeMask(audio_devices_t type) const
{
    DeviceVector devices;
    bool isOutput = audio_is_output_devices(type);
@@ -171,20 +171,8 @@ DeviceVector DeviceVector::getDevicesFromType(audio_devices_t type) const
        if ((isOutput == curIsOutput) && ((type & curType) != 0)) {
            devices.add(itemAt(i));
            type &= ~curType;
            ALOGV("DeviceVector::getDevicesFromType() for type %x found %p",
                  itemAt(i)->type(), itemAt(i).get());
        }
    }
    return devices;
}

DeviceVector DeviceVector::getDevicesFromTypeAddr(
        audio_devices_t type, const String8& address) const
{
    DeviceVector devices;
    for (const auto& device : *this) {
        if (device->type() == type && device->mAddress == address) {
            devices.add(device);
            ALOGV("DeviceVector::%s() for type %08x found %p",
                    __func__, itemAt(i)->type(), itemAt(i).get());
        }
    }
    return devices;
@@ -253,7 +241,7 @@ void DeviceDescriptor::toAudioPortConfig(struct audio_port_config *dstConfig,

void DeviceDescriptor::toAudioPort(struct audio_port *port) const
{
    ALOGV("DeviceDescriptor::toAudioPort() handle %d type %x", mId, mDeviceType);
    ALOGV("DeviceDescriptor::toAudioPort() handle %d type %08x", mId, mDeviceType);
    AudioPort::toAudioPort(port);
    port->id = mId;
    toAudioPortConfig(&port->active_config);
@@ -305,7 +293,7 @@ void DeviceDescriptor::log() const
{
    std::string device;
    deviceToString(mDeviceType, device);
    ALOGI("Device id:%d type:0x%X:%s, addr:%s", mId,  mDeviceType, device.c_str(),
    ALOGI("Device id:%d type:0x%08X:%s, addr:%s", mId,  mDeviceType, device.c_str(),
          mAddress.string());

    AudioPort::log("  ");
+6 −11
Original line number Diff line number Diff line
@@ -278,9 +278,10 @@ sp <HwModule> HwModuleCollection::getModuleForDevice(audio_devices_t device) con
sp<DeviceDescriptor> HwModuleCollection::getDeviceDescriptor(const audio_devices_t device,
                                                             const char *device_address,
                                                             const char *device_name,
                                                             bool matchAdress) const
                                                             bool matchAddress) const
{
    String8 address = (device_address == nullptr) ? String8("") : String8(device_address);
    String8 address = (device_address == nullptr || !matchAddress) ?
            String8("") : String8(device_address);
    // handle legacy remote submix case where the address was not always specified
    if (device_distinguishes_on_address(device) && (address.length() == 0)) {
        address = String8("0");
@@ -288,15 +289,9 @@ sp<DeviceDescriptor> HwModuleCollection::getDeviceDescriptor(const audio_devices

    for (const auto& hwModule : *this) {
        DeviceVector declaredDevices = hwModule->getDeclaredDevices();
        DeviceVector deviceList = declaredDevices.getDevicesFromTypeAddr(device, address);
        if (!deviceList.isEmpty()) {
            return deviceList.itemAt(0);
        }
        if (!matchAdress) {
            deviceList = declaredDevices.getDevicesFromType(device);
            if (!deviceList.isEmpty()) {
                return deviceList.itemAt(0);
            }
        sp<DeviceDescriptor> deviceDesc = declaredDevices.getDevice(device, address);
        if (deviceDesc) {
            return deviceDesc;
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ audio_devices_t SessionRouteMap::getActiveDeviceForStream(audio_stream_type_t st
        if (streamType == route->mStreamType && route->isActiveOrChanged()
                && route->mDeviceDescriptor != 0) {
            device = route->mDeviceDescriptor->type();
            if (!availableDevices.getDevicesFromType(device).isEmpty()) {
            if (!availableDevices.getDevicesFromTypeMask(device).isEmpty()) {
                break;
            }
        }
Loading