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

Commit 7288ab87 authored by Eric Laurent's avatar Eric Laurent
Browse files

audio policy: clarify use of mName field for audio devices

The audio port field mName was used for two different purposes
which caused a problem when exposing this information at the SDK API.

Create a new "mTag" field storing the audio_policy.conf device tag
if needed.
Field "mName" is now used to store any additional name associated to
a given device when available (e.g Manufacturer and model name for a USB device).

Change-Id: I17fa872e4a3a2e1b7cbb807c6f72e095a8a2c9c5
parent 464c7e08
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ namespace android {
class DeviceDescriptor : public AudioPort, public AudioPortConfig
{
public:
    DeviceDescriptor(const String8& name, audio_devices_t type);
    DeviceDescriptor(audio_devices_t type);

    virtual ~DeviceDescriptor() {}

@@ -50,10 +50,9 @@ public:
    status_t dump(int fd, int spaces, int index) const;
    void log() const;

    String8 mTag;
    String8 mAddress;

    static String8  emptyNameStr;

private:
    audio_devices_t     mDeviceType;
    audio_port_handle_t mId;
@@ -73,12 +72,12 @@ public:
    audio_devices_t types() const { return mDeviceTypes; }

    void loadDevicesFromType(audio_devices_t types);
    void loadDevicesFromName(char *name, const DeviceVector& declaredDevices);
    void loadDevicesFromTag(char *tag, const DeviceVector& declaredDevices);

    sp<DeviceDescriptor> getDevice(audio_devices_t type, String8 address) const;
    DeviceVector getDevicesFromType(audio_devices_t types) const;
    sp<DeviceDescriptor> getDeviceFromId(audio_port_handle_t id) const;
    sp<DeviceDescriptor> getDeviceFromName(const String8& name) const;
    sp<DeviceDescriptor> getDeviceFromTag(const String8& tag) const;
    DeviceVector getDevicesFromTypeAddr(audio_devices_t type, String8 address) const;

    audio_devices_t getDevicesFromHwModule(audio_module_handle_t moduleHandle) const;
+3 −3
Original line number Diff line number Diff line
@@ -218,7 +218,7 @@ void ConfigParsingUtils::loadGlobalConfig(cnode *root, const sp<HwModule>& modul
    node = node->first_child;
    while (node) {
        if (strcmp(ATTACHED_OUTPUT_DEVICES_TAG, node->name) == 0) {
            availableOutputDevices.loadDevicesFromName((char *)node->value,
            availableOutputDevices.loadDevicesFromTag((char *)node->value,
                                                        declaredDevices);
            ALOGV("loadGlobalConfig() Attached Output Devices %08x",
                  availableOutputDevices.types());
@@ -228,13 +228,13 @@ void ConfigParsingUtils::loadGlobalConfig(cnode *root, const sp<HwModule>& modul
                    ARRAY_SIZE(sDeviceTypeToEnumTable),
                    (char *)node->value);
            if (device != AUDIO_DEVICE_NONE) {
                defaultOutputDevice = new DeviceDescriptor(String8("default-output"), device);
                defaultOutputDevice = new DeviceDescriptor(device);
            } else {
                ALOGW("loadGlobalConfig() default device not specified");
            }
            ALOGV("loadGlobalConfig() mDefaultOutputDevice %08x", defaultOutputDevice->type());
        } else if (strcmp(ATTACHED_INPUT_DEVICES_TAG, node->name) == 0) {
            availableInputDevices.loadDevicesFromName((char *)node->value,
            availableInputDevices.loadDevicesFromTag((char *)node->value,
                                                       declaredDevices);
            ALOGV("loadGlobalConfig() Available InputDevices %08x", availableInputDevices.types());
        } else if (strcmp(SPEAKER_DRC_ENABLED_TAG, node->name) == 0) {
+14 −19
Original line number Diff line number Diff line
@@ -24,13 +24,11 @@

namespace android {

String8 DeviceDescriptor::emptyNameStr = String8("");

DeviceDescriptor::DeviceDescriptor(const String8& name, audio_devices_t type) :
    AudioPort(name, AUDIO_PORT_TYPE_DEVICE,
DeviceDescriptor::DeviceDescriptor(audio_devices_t type) :
    AudioPort(String8(""), AUDIO_PORT_TYPE_DEVICE,
              audio_is_output_device(type) ? AUDIO_PORT_ROLE_SINK :
                                             AUDIO_PORT_ROLE_SOURCE),
    mAddress(""), mDeviceType(type), mId(0)
    mTag(""), mAddress(""), mDeviceType(type), mId(0)
{

}
@@ -142,24 +140,21 @@ void DeviceVector::loadDevicesFromType(audio_devices_t types)
        uint32_t i = 31 - __builtin_clz(types);
        uint32_t type = 1 << i;
        types &= ~type;
        add(new DeviceDescriptor(String8("device_type"), type | role_bit));
        add(new DeviceDescriptor(type | role_bit));
    }
}

void DeviceVector::loadDevicesFromName(char *name,
void DeviceVector::loadDevicesFromTag(char *tag,
                                       const DeviceVector& declaredDevices)
{
    char *devName = strtok(name, "|");
    while (devName != NULL) {
        if (strlen(devName) != 0) {
    char *devTag = strtok(tag, "|");
    while (devTag != NULL) {
        if (strlen(devTag) != 0) {
            audio_devices_t type = ConfigParsingUtils::stringToEnum(sDeviceTypeToEnumTable,
                                 ARRAY_SIZE(sDeviceTypeToEnumTable),
                                 devName);
                                 devTag);
            if (type != AUDIO_DEVICE_NONE) {
                devName = (char *)ConfigParsingUtils::enumToString(sDeviceNameToEnumTable,
                                                           ARRAY_SIZE(sDeviceNameToEnumTable),
                                                           type);
                sp<DeviceDescriptor> dev = new DeviceDescriptor(String8(devName), type);
                sp<DeviceDescriptor> dev = new DeviceDescriptor(type);
                if (type == AUDIO_DEVICE_IN_REMOTE_SUBMIX ||
                        type == AUDIO_DEVICE_OUT_REMOTE_SUBMIX ) {
                    dev->mAddress = String8("0");
@@ -167,13 +162,13 @@ void DeviceVector::loadDevicesFromName(char *name,
                add(dev);
            } else {
                sp<DeviceDescriptor> deviceDesc =
                        declaredDevices.getDeviceFromName(String8(devName));
                        declaredDevices.getDeviceFromTag(String8(devTag));
                if (deviceDesc != 0) {
                    add(deviceDesc);
                }
            }
         }
         devName = strtok(NULL, "|");
         devTag = strtok(NULL, "|");
     }
}

@@ -239,11 +234,11 @@ DeviceVector DeviceVector::getDevicesFromTypeAddr(
    return devices;
}

sp<DeviceDescriptor> DeviceVector::getDeviceFromName(const String8& name) const
sp<DeviceDescriptor> DeviceVector::getDeviceFromTag(const String8& tag) const
{
    sp<DeviceDescriptor> device;
    for (size_t i = 0; i < size(); i++) {
        if (itemAt(i)->mName == name) {
        if (itemAt(i)->mTag == tag) {
            device = itemAt(i);
            break;
        }
+10 −8
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ status_t HwModule::loadInput(cnode *root)
        } else if (strcmp(node->name, CHANNELS_TAG) == 0) {
            profile->loadInChannels((char *)node->value);
        } else if (strcmp(node->name, DEVICES_TAG) == 0) {
            profile->mSupportedDevices.loadDevicesFromName((char *)node->value,
            profile->mSupportedDevices.loadDevicesFromTag((char *)node->value,
                                                           mDeclaredDevices);
        } else if (strcmp(node->name, FLAGS_TAG) == 0) {
            profile->mFlags = ConfigParsingUtils::parseInputFlagNames((char *)node->value);
@@ -105,7 +105,7 @@ status_t HwModule::loadOutput(cnode *root)
        } else if (strcmp(node->name, CHANNELS_TAG) == 0) {
            profile->loadOutChannels((char *)node->value);
        } else if (strcmp(node->name, DEVICES_TAG) == 0) {
            profile->mSupportedDevices.loadDevicesFromName((char *)node->value,
            profile->mSupportedDevices.loadDevicesFromTag((char *)node->value,
                                                           mDeclaredDevices);
        } else if (strcmp(node->name, FLAGS_TAG) == 0) {
            profile->mFlags = ConfigParsingUtils::parseOutputFlagNames((char *)node->value);
@@ -154,7 +154,8 @@ status_t HwModule::loadDevice(cnode *root)
        ALOGW("loadDevice() bad type %08x", type);
        return BAD_VALUE;
    }
    sp<DeviceDescriptor> deviceDesc = new DeviceDescriptor(String8(root->name), type);
    sp<DeviceDescriptor> deviceDesc = new DeviceDescriptor(type);
    deviceDesc->mTag = String8(root->name);

    node = root->first_child;
    while (node) {
@@ -172,8 +173,8 @@ status_t HwModule::loadDevice(cnode *root)
        node = node->next;
    }

    ALOGV("loadDevice() adding device name %s type %08x address %s",
          deviceDesc->mName.string(), type, deviceDesc->mAddress.string());
    ALOGV("loadDevice() adding device tag %s type %08x address %s",
          deviceDesc->mTag.string(), type, deviceDesc->mAddress.string());

    mDeclaredDevices.add(deviceDesc);

@@ -189,7 +190,7 @@ status_t HwModule::addOutputProfile(String8 name, const audio_config_t *config,
    profile->mChannelMasks.add(config->channel_mask);
    profile->mFormats.add(config->format);

    sp<DeviceDescriptor> devDesc = new DeviceDescriptor(name, device);
    sp<DeviceDescriptor> devDesc = new DeviceDescriptor(device);
    devDesc->mAddress = address;
    profile->mSupportedDevices.add(devDesc);

@@ -220,7 +221,7 @@ status_t HwModule::addInputProfile(String8 name, const audio_config_t *config,
    profile->mChannelMasks.add(config->channel_mask);
    profile->mFormats.add(config->format);

    sp<DeviceDescriptor> devDesc = new DeviceDescriptor(name, device);
    sp<DeviceDescriptor> devDesc = new DeviceDescriptor(device);
    devDesc->mAddress = address;
    profile->mSupportedDevices.add(devDesc);

@@ -350,7 +351,8 @@ sp<DeviceDescriptor> HwModuleCollection::getDeviceDescriptor(const audio_device
    }

    sp<DeviceDescriptor> devDesc =
            new DeviceDescriptor(String8(device_name != NULL ? device_name : ""), device);
            new DeviceDescriptor(device);
    devDesc->mName = device_name;
    devDesc->mAddress = address;
    return devDesc;
}
+2 −2
Original line number Diff line number Diff line
@@ -2648,7 +2648,7 @@ AudioPolicyManager::AudioPolicyManager(AudioPolicyClientInterface *clientInterfa
    mUidCached = getuid();
    mpClientInterface = clientInterface;

    mDefaultOutputDevice = new DeviceDescriptor(String8("Speaker"), AUDIO_DEVICE_OUT_SPEAKER);
    mDefaultOutputDevice = new DeviceDescriptor(AUDIO_DEVICE_OUT_SPEAKER);
    if (ConfigParsingUtils::loadAudioPolicyConfig(AUDIO_POLICY_VENDOR_CONFIG_FILE,
                 mHwModules, mAvailableInputDevices, mAvailableOutputDevices,
                 mDefaultOutputDevice, mSpeakerDrcEnabled) != NO_ERROR) {
@@ -4738,7 +4738,7 @@ void AudioPolicyManager::defaultAudioPolicyConfig(void)
    sp<HwModule> module;
    sp<IOProfile> profile;
    sp<DeviceDescriptor> defaultInputDevice =
                    new DeviceDescriptor(String8("builtin-mic"), AUDIO_DEVICE_IN_BUILTIN_MIC);
                    new DeviceDescriptor(AUDIO_DEVICE_IN_BUILTIN_MIC);
    mAvailableOutputDevices.add(mDefaultOutputDevice);
    mAvailableInputDevices.add(defaultInputDevice);