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

Commit 6cb004ae authored by jiabin's avatar jiabin
Browse files

Return DeviceDescriptor or DeviceVector in Engine.

To remove the limit on the number of audio device types, there is a
need to remove the return value as a combination of audio_devices_t.
Using DeviceDescriptor or DeviceVector in Engine is a starting point.

Test: audiopolicy_tests, smoke test
Test: CTS for AudioTrack, AudioRecord, AudioManager
Bug: 135621476
Change-Id: I7603481d92184549a5fed6b1166cb0044c965570
parent e6138376
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -116,6 +116,13 @@ public:
    DeviceVector getDevicesFromHwModule(audio_module_handle_t moduleHandle) const;
    audio_devices_t getDeviceTypesFromHwModule(audio_module_handle_t moduleHandle) const;

    DeviceVector getFirstDevicesFromTypes(std::vector<audio_devices_t> orderedTypes) const;
    sp<DeviceDescriptor> getFirstExistingDevice(std::vector<audio_devices_t> orderedTypes) const;

    // If there are devices with the given type and the devices to add is not empty,
    // remove all the devices with the given type and add all the devices to add.
    void replaceDevicesByType(audio_devices_t typeToRemove, const DeviceVector &devicesToAdd);

    bool contains(const sp<DeviceDescriptor>& item) const { return indexOf(item) >= 0; }

    /**
+32 −1
Original line number Diff line number Diff line
@@ -256,7 +256,6 @@ DeviceVector DeviceVector::getDevicesFromTypeMask(audio_devices_t type) const
        audio_devices_t curType = itemAt(i)->type() & ~AUDIO_DEVICE_BIT_IN;
        if ((isOutput == curIsOutput) && ((type & curType) != 0)) {
            devices.add(itemAt(i));
            type &= ~curType;
            ALOGV("DeviceVector::%s() for type %08x found %p",
                    __func__, itemAt(i)->type(), itemAt(i).get());
        }
@@ -274,6 +273,38 @@ sp<DeviceDescriptor> DeviceVector::getDeviceFromTagName(const String8 &tagName)
    return nullptr;
}

DeviceVector DeviceVector::getFirstDevicesFromTypes(
        std::vector<audio_devices_t> orderedTypes) const
{
    DeviceVector devices;
    for (auto deviceType : orderedTypes) {
        if (!(devices = getDevicesFromTypeMask(deviceType)).isEmpty()) {
            break;
        }
    }
    return devices;
}

sp<DeviceDescriptor> DeviceVector::getFirstExistingDevice(
        std::vector<audio_devices_t> orderedTypes) const {
    sp<DeviceDescriptor> device;
    for (auto deviceType : orderedTypes) {
        if ((device = getDevice(deviceType, String8(""), AUDIO_FORMAT_DEFAULT)) != nullptr) {
            break;
        }
    }
    return device;
}

void DeviceVector::replaceDevicesByType(
        audio_devices_t typeToRemove, const DeviceVector &devicesToAdd) {
    DeviceVector devicesToRemove = getDevicesFromTypeMask(typeToRemove);
    if (!devicesToRemove.isEmpty() && !devicesToAdd.isEmpty()) {
        remove(devicesToRemove);
        add(devicesToAdd);
    }
}

void DeviceVector::dump(String8 *dst, const String8 &tag, int spaces, bool verbose) const
{
    if (isEmpty()) {
+217 −279

File changed.

Preview size limit exceeded, changes collapsed.

+5 −6
Original line number Diff line number Diff line
@@ -74,15 +74,14 @@ private:

    status_t setDefaultDevice(audio_devices_t device);

    audio_devices_t getDeviceForStrategyInt(legacy_strategy strategy,
    DeviceVector getDevicesForStrategyInt(legacy_strategy strategy,
                                          DeviceVector availableOutputDevices,
                                          DeviceVector availableInputDevices,
                                            const SwAudioOutputCollection &outputs,
                                            uint32_t outputDeviceTypesToIgnore) const;
                                          const SwAudioOutputCollection &outputs) const;

    DeviceVector getDevicesForProductStrategy(product_strategy_t strategy) const;

    audio_devices_t getDeviceForInputSource(audio_source_t inputSource) const;
    sp<DeviceDescriptor> getDeviceForInputSource(audio_source_t inputSource) const;

    DeviceStrategyMap mDevicesForStrategies;