Skip to content

Draft: Add module-default-routes, and simplify policy-device-routes.lua

This MR essentially moves the logic that saves the default routes into a new module-default-routes C module, and refactors policy-device-routes.lua to use the new module API if the policy wants to restore a route. This code refactor has several advantages:

  • Simplifies policy-device-profiles.lua script.
  • Keep consistency with module-default-profiles and policy-device-profiles.lua.
  • Some users might not want to store/restore the default routes for a device. Instead, they might just want wireplumber to automatically select the best routes every time they change. This is now possible to do if we don't load module-default-routes, like module-default-profiles.
  • Having a module API to get the default routes and their properties can also be useful in case one day we want to print information about them in wpctl status. More APIs could also be added such as "clear-routes" and "clear-route-properties" to clear the current stored routes with wpctl, similar to the clear-default sub-command.
  • The new module-default-routes uses the WpSpaJson API to store the route properties. This is much cleaner than manually implementing a simple serializer in policy-device-routes.lua like before. Because of this, the information stored in the state file changes from this:
[default-routes]                                                        
alsa_card.pci-0000_00_1f.3:output:analog-output-headphones:channelMap=FL;FR;
alsa_card.pci-0000_00_1f.3:output:analog-output-headphones:channelVolumes=0.39999160170555;0.39999160170555;
alsa_card.pci-0000_00_1f.3:output:analog-output-headphones:latencyOffsetNsec=0
alsa_card.pci-0000_00_1f.3:output:analog-output-speaker:channelMap=FL;FR;
alsa_card.pci-0000_00_1f.3:output:analog-output-speaker:channelVolumes=0.043797824531794;0.043797824531794;
alsa_card.pci-0000_00_1f.3:output:analog-output-speaker:latencyOffsetNsec=0
alsa_card.pci-0000_00_1f.3:profile:output:analog-stereo+input:analog-stereo=analog-output-speaker;
alsa_card.pci-0000_00_1f.3:profile:output:analog-stereo=analog-output-speaker;

To like this:

[device-routes]                                                        
alsa_card.pci-0000_00_1f.3:output:analog-output-speaker={"mute":false, "channelVolumes":[0.209385, 0.209385], "volumeBase":1.000000, "volumeStep":0.000015, "channelMap":["FL", "FR"], "softVolumes":[1.000000, 1.000000], "latencyOffsetNsec":"0"}
alsa_card.pci-0000_00_1f.3:output:analog-output-headphones={"mute":false, "channelVolumes":[0.022422, 0.022422], "volumeBase":1.000000, "volumeStep":0.000015, "channelMap":["FL", "FR"], "softVolumes":[1.000000, 1.000000], "latencyOffsetNsec":"0"}
alsa_card.pci-0000_00_1f.3:profile:output:analog-stereo+input:analog-stereo=["analog-output-speaker"]
alsa_card.pci-0000_00_1f.3:profile:output:analog-stereo=["analog-output-speaker"]

The new format is stored in a different file (device-routes instead of default-routes) to avoid issues in case someone forgot to remove the old state files when updating wireplumber from 0.4 to 0.5. Maybe we should also rename the default-profiles state file to device-profiles for the sake of consistency?

cc @ashoks

Edited by Julian Bouzas

Merge request reports

Loading