Merge changes I9eb9de96,Id1e037af
* changes:
audiopolicy: fixup! audiopolicy: HW Bridge Sink matching rule
Revert "Revert "audiopolicy: HW Bridge Sink matching rule""
diff --git a/services/audiopolicy/common/managerdefinitions/include/DeviceDescriptor.h b/services/audiopolicy/common/managerdefinitions/include/DeviceDescriptor.h
index 3d338ea..82cd6cf 100644
--- a/services/audiopolicy/common/managerdefinitions/include/DeviceDescriptor.h
+++ b/services/audiopolicy/common/managerdefinitions/include/DeviceDescriptor.h
@@ -65,6 +65,9 @@
bool supportsFormat(audio_format_t format);
+ void setDynamic() { mIsDynamic = true; }
+ bool isDynamic() const { return mIsDynamic; }
+
// PolicyAudioPortConfig
virtual sp<PolicyAudioPort> getPolicyAudioPort() const {
return static_cast<PolicyAudioPort*>(const_cast<DeviceDescriptor*>(this));
@@ -105,6 +108,8 @@
std::string mTagName; // Unique human readable identifier for a device port found in conf file.
FormatVector mEncodedFormats;
audio_format_t mCurrentEncodedFormat;
+ bool mIsDynamic = false;
+ const std::string mDeclaredAddress; // Original device address
};
class DeviceVector : public SortedVector<sp<DeviceDescriptor> >
diff --git a/services/audiopolicy/common/managerdefinitions/include/HwModule.h b/services/audiopolicy/common/managerdefinitions/include/HwModule.h
index 23f0c9a..9ba745a 100644
--- a/services/audiopolicy/common/managerdefinitions/include/HwModule.h
+++ b/services/audiopolicy/common/managerdefinitions/include/HwModule.h
@@ -52,8 +52,12 @@
devices.merge(mDynamicDevices);
return devices;
}
+ std::string getTagForDevice(audio_devices_t device,
+ const String8 &address = String8(),
+ audio_format_t codec = AUDIO_FORMAT_DEFAULT);
void addDynamicDevice(const sp<DeviceDescriptor> &device)
{
+ device->setDynamic();
mDynamicDevices.add(device);
}
@@ -131,8 +135,17 @@
public:
sp<HwModule> getModuleFromName(const char *name) const;
+ /**
+ * @brief getModuleForDeviceType try to get a device from type / format on all modules
+ * @param device type to consider
+ * @param encodedFormat to consider
+ * @param[out] tagName if not null, if a matching device is found, will return the tagName
+ * of original device from XML file so that audio routes matchin rules work.
+ * @return valid module if considered device found, nullptr otherwise.
+ */
sp<HwModule> getModuleForDeviceType(audio_devices_t device,
- audio_format_t encodedFormat) const;
+ audio_format_t encodedFormat,
+ std::string *tagName = nullptr) const;
sp<HwModule> getModuleForDevice(const sp<DeviceDescriptor> &device,
audio_format_t encodedFormat) const;
diff --git a/services/audiopolicy/common/managerdefinitions/include/IOProfile.h b/services/audiopolicy/common/managerdefinitions/include/IOProfile.h
index a5cd534..a74cefa 100644
--- a/services/audiopolicy/common/managerdefinitions/include/IOProfile.h
+++ b/services/audiopolicy/common/managerdefinitions/include/IOProfile.h
@@ -112,6 +112,19 @@
}
/**
+ * @brief getTag
+ * @param deviceTypes to be considered
+ * @return tagName of first matching device for the considered types, empty string otherwise.
+ */
+ std::string getTag(const DeviceTypeSet& deviceTypes) const
+ {
+ if (supportsDeviceTypes(deviceTypes)) {
+ return mSupportedDevices.getDevicesFromTypes(deviceTypes).itemAt(0)->getTagName();
+ }
+ return {};
+ }
+
+ /**
* @brief supportsDevice
* @param device to be checked against
* forceCheckOnAddress if true, check on type and address whatever the type, otherwise
@@ -152,6 +165,12 @@
}
void removeSupportedDevice(const sp<DeviceDescriptor> &device)
{
+ ssize_t ret = mSupportedDevices.indexOf(device);
+ if (ret >= 0 && !mSupportedDevices.itemAt(ret)->isDynamic()) {
+ // devices equality checks only type, address, name and format
+ // Prevents from removing non dynamically added devices
+ return;
+ }
mSupportedDevices.remove(device);
}
void setSupportedDevices(const DeviceVector &devices)
diff --git a/services/audiopolicy/common/managerdefinitions/include/PolicyAudioPort.h b/services/audiopolicy/common/managerdefinitions/include/PolicyAudioPort.h
index d2f6297..e6eef24 100644
--- a/services/audiopolicy/common/managerdefinitions/include/PolicyAudioPort.h
+++ b/services/audiopolicy/common/managerdefinitions/include/PolicyAudioPort.h
@@ -42,6 +42,11 @@
virtual const std::string getTagName() const = 0;
+ bool equals(const sp<PolicyAudioPort> &right) const
+ {
+ return getTagName() == right->getTagName();
+ }
+
virtual sp<AudioPort> asAudioPort() const = 0;
virtual void setFlags(uint32_t flags)
diff --git a/services/audiopolicy/common/managerdefinitions/src/AudioRoute.cpp b/services/audiopolicy/common/managerdefinitions/src/AudioRoute.cpp
index 2a18f19..c8e4e76 100644
--- a/services/audiopolicy/common/managerdefinitions/src/AudioRoute.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/AudioRoute.cpp
@@ -39,12 +39,12 @@
bool AudioRoute::supportsPatch(const sp<PolicyAudioPort> &srcPort,
const sp<PolicyAudioPort> &dstPort) const
{
- if (mSink == 0 || dstPort == 0 || dstPort != mSink) {
+ if (mSink == 0 || dstPort == 0 || !dstPort->equals(mSink)) {
return false;
}
ALOGV("%s: sinks %s matching", __FUNCTION__, mSink->getTagName().c_str());
for (const auto &sourcePort : mSources) {
- if (sourcePort == srcPort) {
+ if (sourcePort->equals(srcPort)) {
ALOGV("%s: sources %s matching", __FUNCTION__, sourcePort->getTagName().c_str());
return true;
}
diff --git a/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
index 6c31b79..3cfceba 100644
--- a/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
@@ -49,10 +49,13 @@
{
}
+// Let DeviceDescriptorBase initialize the address since it handles specific cases like
+// legacy remote submix where "0" is added as default address.
DeviceDescriptor::DeviceDescriptor(const AudioDeviceTypeAddr &deviceTypeAddr,
const std::string &tagName,
const FormatVector &encodedFormats) :
- DeviceDescriptorBase(deviceTypeAddr), mTagName(tagName), mEncodedFormats(encodedFormats)
+ DeviceDescriptorBase(deviceTypeAddr), mTagName(tagName), mEncodedFormats(encodedFormats),
+ mDeclaredAddress(DeviceDescriptorBase::address())
{
mCurrentEncodedFormat = AUDIO_FORMAT_DEFAULT;
/* If framework runs against a pre 5.0 Audio HAL, encoded formats are absent from the config.
@@ -75,6 +78,10 @@
void DeviceDescriptor::detach() {
mId = AUDIO_PORT_HANDLE_NONE;
PolicyAudioPort::detach();
+ // The device address may have been overwritten on device connection
+ setAddress(mDeclaredAddress);
+ // Device Port does not have a name unless provided by setDeviceConnectionState
+ setName("");
}
template<typename T>
diff --git a/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp b/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp
index d31e443..3a143b0 100644
--- a/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp
@@ -41,6 +41,14 @@
}
}
+std::string HwModule::getTagForDevice(audio_devices_t device, const String8 &address,
+ audio_format_t codec)
+{
+ DeviceVector declaredDevices = getDeclaredDevices();
+ sp<DeviceDescriptor> deviceDesc = declaredDevices.getDevice(device, address, codec);
+ return deviceDesc ? deviceDesc->getTagName() : std::string{};
+}
+
status_t HwModule::addOutputProfile(const std::string& name, const audio_config_t *config,
audio_devices_t device, const String8& address)
{
@@ -49,7 +57,8 @@
profile->addAudioProfile(new AudioProfile(config->format, config->channel_mask,
config->sample_rate));
- sp<DeviceDescriptor> devDesc = new DeviceDescriptor(device, "" /*tagName*/, address.string());
+ sp<DeviceDescriptor> devDesc =
+ new DeviceDescriptor(device, getTagForDevice(device), address.string());
addDynamicDevice(devDesc);
// Reciprocally attach the device to the module
devDesc->attach(this);
@@ -116,7 +125,8 @@
profile->addAudioProfile(new AudioProfile(config->format, config->channel_mask,
config->sample_rate));
- sp<DeviceDescriptor> devDesc = new DeviceDescriptor(device, "" /*tagName*/, address.string());
+ sp<DeviceDescriptor> devDesc =
+ new DeviceDescriptor(device, getTagForDevice(device), address.string());
addDynamicDevice(devDesc);
// Reciprocally attach the device to the module
devDesc->attach(this);
@@ -271,8 +281,9 @@
return nullptr;
}
-sp <HwModule> HwModuleCollection::getModuleForDeviceType(audio_devices_t type,
- audio_format_t encodedFormat) const
+sp<HwModule> HwModuleCollection::getModuleForDeviceType(audio_devices_t type,
+ audio_format_t encodedFormat,
+ std::string *tagName) const
{
for (const auto& module : *this) {
const auto& profiles = audio_is_output_device(type) ?
@@ -284,9 +295,15 @@
sp <DeviceDescriptor> deviceDesc =
declaredDevices.getDevice(type, String8(), encodedFormat);
if (deviceDesc) {
+ if (tagName != nullptr) {
+ *tagName = deviceDesc->getTagName();
+ }
return module;
}
} else {
+ if (tagName != nullptr) {
+ *tagName = profile->getTag({type});
+ }
return module;
}
}
@@ -325,15 +342,32 @@
}
for (const auto& hwModule : *this) {
+ if (!allowToCreate) {
+ auto dynamicDevices = hwModule->getDynamicDevices();
+ auto dynamicDevice = dynamicDevices.getDevice(deviceType, devAddress, encodedFormat);
+ if (dynamicDevice) {
+ return dynamicDevice;
+ }
+ }
DeviceVector moduleDevices = hwModule->getAllDevices();
auto moduleDevice = moduleDevices.getDevice(deviceType, devAddress, encodedFormat);
+
+ // Prevent overwritting moduleDevice address if connected device does not have the same
+ // address (since getDevice with empty address ignores match on address), use dynamic device
+ if (moduleDevice && allowToCreate &&
+ (!moduleDevice->address().empty() &&
+ (moduleDevice->address().compare(devAddress.c_str()) != 0))) {
+ break;
+ }
if (moduleDevice) {
if (encodedFormat != AUDIO_FORMAT_DEFAULT) {
moduleDevice->setEncodedFormat(encodedFormat);
}
if (allowToCreate) {
moduleDevice->attach(hwModule);
+ // Name may be overwritten, restored on detach.
moduleDevice->setAddress(devAddress.string());
+ // Name may be overwritten, restored on detach.
moduleDevice->setName(name);
}
return moduleDevice;
@@ -352,18 +386,19 @@
const char *name,
const audio_format_t encodedFormat) const
{
- sp<HwModule> hwModule = getModuleForDeviceType(type, encodedFormat);
+ std::string tagName = {};
+ sp<HwModule> hwModule = getModuleForDeviceType(type, encodedFormat, &tagName);
if (hwModule == 0) {
ALOGE("%s: could not find HW module for device %04x address %s", __FUNCTION__, type,
address);
return nullptr;
}
- sp<DeviceDescriptor> device = new DeviceDescriptor(type, name, address);
+ sp<DeviceDescriptor> device = new DeviceDescriptor(type, tagName, address);
device->setName(name);
device->setEncodedFormat(encodedFormat);
-
- // Add the device to the list of dynamic devices
+ device->setDynamic();
+ // Add the device to the list of dynamic devices
hwModule->addDynamicDevice(device);
// Reciprocally attach the device to the module
device->attach(hwModule);
@@ -375,7 +410,7 @@
for (const auto &profile : profiles) {
// Add the device as supported to all profile supporting "weakly" or not the device
// according to its type
- if (profile->supportsDevice(device, false /*matchAdress*/)) {
+ if (profile->supportsDevice(device, false /*matchAddress*/)) {
// @todo quid of audio profile? import the profile from device of the same type?
const auto &isoTypeDeviceForProfile =
@@ -406,10 +441,9 @@
device->detach();
// Only remove from dynamic list, not from declared list!!!
- if (!hwModule->getDynamicDevices().contains(device)) {
+ if (!hwModule->removeDynamicDevice(device)) {
return;
}
- hwModule->removeDynamicDevice(device);
ALOGV("%s: removed dynamic device %s from module %s", __FUNCTION__,
device->toString().c_str(), hwModule->getName());