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

Commit 36e2dea7 authored by jiabin's avatar jiabin
Browse files

Add constructor with type and address for DeviceDescriptor.

Type and address are used to distinguish a device, it makes more
sense to set device type and address when creating a DeviceDescriptor.

Bug: 135621476
Test: make, atest audiopolicy_tests
Change-Id: I5f9063bd8c756ace77c162e86a8c0dd685da79b4
parent c76250c8
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -25,12 +25,22 @@
namespace android {

DeviceDescriptorBase::DeviceDescriptorBase(audio_devices_t type) :
        DeviceDescriptorBase(type, "")
{
}

DeviceDescriptorBase::DeviceDescriptorBase(audio_devices_t type, const std::string& address) :
        DeviceDescriptorBase(AudioDeviceTypeAddr(type, address))
{
}

DeviceDescriptorBase::DeviceDescriptorBase(const AudioDeviceTypeAddr &deviceTypeAddr) :
        AudioPort("", AUDIO_PORT_TYPE_DEVICE,
              audio_is_output_device(type) ? AUDIO_PORT_ROLE_SINK :
                                             AUDIO_PORT_ROLE_SOURCE)
                  audio_is_output_device(deviceTypeAddr.mType) ? AUDIO_PORT_ROLE_SINK :
                                         AUDIO_PORT_ROLE_SOURCE),
        mDeviceTypeAddr(deviceTypeAddr)
{
    mDeviceTypeAddr.mType = type;
    if (audio_is_remote_submix_device(type)) {
    if (mDeviceTypeAddr.mAddress.empty() && audio_is_remote_submix_device(mDeviceTypeAddr.mType)) {
        mDeviceTypeAddr.mAddress = "0";
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ class DeviceDescriptorBase : public AudioPort, public AudioPortConfig
public:
     // Note that empty name refers by convention to a generic device.
    explicit DeviceDescriptorBase(audio_devices_t type);
    DeviceDescriptorBase(audio_devices_t type, const std::string& address);
    explicit DeviceDescriptorBase(const AudioDeviceTypeAddr& deviceTypeAddr);

    virtual ~DeviceDescriptorBase() {}

+7 −3
Original line number Diff line number Diff line
@@ -33,9 +33,13 @@ class DeviceDescriptor : public DeviceDescriptorBase,
{
public:
     // Note that empty name refers by convention to a generic device.
    explicit DeviceDescriptor(audio_devices_t type, const std::string &tagName = "");
    DeviceDescriptor(audio_devices_t type, const FormatVector &encodedFormats,
            const std::string &tagName = "");
    explicit DeviceDescriptor(audio_devices_t type);
    DeviceDescriptor(audio_devices_t type, const std::string &tagName,
            const FormatVector &encodedFormats = FormatVector{});
    DeviceDescriptor(audio_devices_t type, const std::string &tagName,
            const std::string &address, const FormatVector &encodedFormats = FormatVector{});
    DeviceDescriptor(const AudioDeviceTypeAddr &deviceTypeAddr, const std::string &tagName = "",
            const FormatVector &encodedFormats = FormatVector{});

    virtual ~DeviceDescriptor() {}

+22 −6
Original line number Diff line number Diff line
@@ -26,14 +26,30 @@

namespace android {

DeviceDescriptor::DeviceDescriptor(audio_devices_t type, const std::string &tagName) :
        DeviceDescriptor(type, FormatVector{}, tagName)
DeviceDescriptor::DeviceDescriptor(audio_devices_t type) :
        DeviceDescriptor(type, "" /*tagName*/)
{
}

DeviceDescriptor::DeviceDescriptor(audio_devices_t type, const FormatVector &encodedFormats,
        const std::string &tagName) :
    DeviceDescriptorBase(type), mTagName(tagName), mEncodedFormats(encodedFormats)
DeviceDescriptor::DeviceDescriptor(audio_devices_t type,
                                   const std::string &tagName,
                                   const FormatVector &encodedFormats) :
        DeviceDescriptor(type, tagName, "" /*address*/, encodedFormats)
{
}

DeviceDescriptor::DeviceDescriptor(audio_devices_t type,
                                   const std::string &tagName,
                                   const std::string &address,
                                   const FormatVector &encodedFormats) :
        DeviceDescriptor(AudioDeviceTypeAddr(type, address), tagName, encodedFormats)
{
}

DeviceDescriptor::DeviceDescriptor(const AudioDeviceTypeAddr &deviceTypeAddr,
                                   const std::string &tagName,
                                   const FormatVector &encodedFormats) :
        DeviceDescriptorBase(deviceTypeAddr), mTagName(tagName), mEncodedFormats(encodedFormats)
{
    mCurrentEncodedFormat = AUDIO_FORMAT_DEFAULT;
    /* If framework runs against a pre 5.0 Audio HAL, encoded formats are absent from the config.
@@ -41,7 +57,7 @@ DeviceDescriptor::DeviceDescriptor(audio_devices_t type, const FormatVector &enc
     * For now, the workaround to remove AC3 and IEC61937 support on HDMI is to declare
     * something like 'encodedFormats="AUDIO_FORMAT_PCM_16_BIT"' on the HDMI devicePort.
     */
    if (type == AUDIO_DEVICE_OUT_HDMI && mEncodedFormats.empty()) {
    if (mDeviceTypeAddr.mType == AUDIO_DEVICE_OUT_HDMI && mEncodedFormats.empty()) {
        mEncodedFormats.push_back(AUDIO_FORMAT_AC3);
        mEncodedFormats.push_back(AUDIO_FORMAT_IEC61937);
    }
+4 −6
Original line number Diff line number Diff line
@@ -49,8 +49,7 @@ status_t HwModule::addOutputProfile(const std::string& name, const audio_config_
    profile->addAudioProfile(new AudioProfile(config->format, config->channel_mask,
                                              config->sample_rate));

    sp<DeviceDescriptor> devDesc = new DeviceDescriptor(device);
    devDesc->setAddress(address.string());
    sp<DeviceDescriptor> devDesc = new DeviceDescriptor(device, "" /*tagName*/, address.string());
    addDynamicDevice(devDesc);
    // Reciprocally attach the device to the module
    devDesc->attach(this);
@@ -117,8 +116,7 @@ status_t HwModule::addInputProfile(const std::string& name, const audio_config_t
    profile->addAudioProfile(new AudioProfile(config->format, config->channel_mask,
                                              config->sample_rate));

    sp<DeviceDescriptor> devDesc = new DeviceDescriptor(device);
    devDesc->setAddress(address.string());
    sp<DeviceDescriptor> devDesc = new DeviceDescriptor(device, "" /*tagName*/, address.string());
    addDynamicDevice(devDesc);
    // Reciprocally attach the device to the module
    devDesc->attach(this);
@@ -360,9 +358,9 @@ sp<DeviceDescriptor> HwModuleCollection::createDevice(const audio_devices_t type
              address);
        return nullptr;
    }
    sp<DeviceDescriptor> device = new DeviceDescriptor(type, name);

    sp<DeviceDescriptor> device = new DeviceDescriptor(type, name, address);
    device->setName(name);
    device->setAddress(address);
    device->setEncodedFormat(encodedFormat);

  // Add the device to the list of dynamic devices
Loading