services/pipewire: cache route device volumes to initialize nodes

Nodes referencing a device can be bound later than the device is
bound. If this happens, the node will not receive an initial route
device volume change event. This change caches the last known route
device volume and initializes the device with it if present.
This commit is contained in:
outfoxxed 2025-11-14 02:12:42 -08:00
parent fc704e6b5d
commit a00ff03944
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
5 changed files with 28 additions and 1 deletions

View file

@ -125,12 +125,22 @@ void PwDevice::addDeviceIndexPairs(const spa_pod* param) {
// Insert into the main map as well, staging's purpose is to remove old entries.
this->routeDeviceIndexes.insert(device, index);
// Used for initial node volume if the device is bound before the node
// (e.g. multiple nodes pointing to the same device)
this->routeDeviceVolumes.insert(device, volumeProps);
qCDebug(logDevice).nospace() << "Registered device/index pair for " << this
<< ": [device: " << device << ", index: " << index << ']';
emit this->routeVolumesChanged(device, volumeProps);
}
bool PwDevice::tryLoadVolumeProps(qint32 routeDevice, PwVolumeProps& volumeProps) {
if (!this->routeDeviceVolumes.contains(routeDevice)) return false;
volumeProps = this->routeDeviceVolumes.value(routeDevice);
return true;
}
void PwDevice::polled() {
// It is far more likely that the list content has not come in yet than it having no entries,
// and there isn't a way to check in the case that there *aren't* actually any entries.