From ac0d8ee4a88113c831963b2c01d9139d79ddc4a1 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Tue, 14 Nov 2023 21:32:18 +0200 Subject: [PATCH] monitors/alsa: remove vm.node.defaults and use match rules instead The vm.node.defaults logic which was inherited from p-m-s is not really good because it seems like different VM hardware requires different values for the defaults. Also, passthrough USB hardware should not inerhit these values, they just cause trouble. Instead, we can use rules to match the vm.type and specific device properties to set a more informed period & headroom. For now, I am also decreasing the default headroom down to 2048, which works for me and perhaps it's a good default. We can always add more rules here and fine-tune per vm type and virtual hardware. See !394, #316, #348, #507, #162, pipewire#3452 --- src/config/wireplumber.conf.d/alsa-vm.conf | 23 ++++++++++++++++++++++ src/config/wireplumber.conf.d/alsa.conf | 8 -------- src/scripts/monitors/alsa.lua | 13 ++++-------- 3 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 src/config/wireplumber.conf.d/alsa-vm.conf diff --git a/src/config/wireplumber.conf.d/alsa-vm.conf b/src/config/wireplumber.conf.d/alsa-vm.conf new file mode 100644 index 00000000..1ababe97 --- /dev/null +++ b/src/config/wireplumber.conf.d/alsa-vm.conf @@ -0,0 +1,23 @@ +# ALSA node property overrides for virtual machine hardware + +monitor.alsa.rules = [ + # Generic PCI cards on any VM type + { + matches = [ + { + node.name = "~alsa_input.pci.*" + vm.type = "~.*" + } + { + node.name = "~alsa_output.pci.*" + vm.type = "~.*" + } + ] + actions = { + update-props = { + api.alsa.period-size = 1024 + api.alsa.headroom = 2048 + } + } + } +] diff --git a/src/config/wireplumber.conf.d/alsa.conf b/src/config/wireplumber.conf.d/alsa.conf index 7c15c069..bda1657c 100644 --- a/src/config/wireplumber.conf.d/alsa.conf +++ b/src/config/wireplumber.conf.d/alsa.conf @@ -22,14 +22,6 @@ monitor.alsa.midi.node-properties = { # api.alsa.disable-longname = false } -monitor.alsa.vm.node.defaults = { - ## These properties override node defaults when running in a virtual machine. - ## The rules below still override those. - - api.alsa.period-size = 1024 - api.alsa.headroom = 8192 -} - monitor.alsa.rules = [ ## The list of monitor rules diff --git a/src/scripts/monitors/alsa.lua b/src/scripts/monitors/alsa.lua index 708deb55..edc37d1a 100644 --- a/src/scripts/monitors/alsa.lua +++ b/src/scripts/monitors/alsa.lua @@ -12,7 +12,6 @@ defaults = {} defaults.reserve_priority = -20 defaults.reserve_application_name = "WirePlumber" defaults.properties = Json.Object {} -defaults.vm_node_defaults = Json.Object {} config = {} config.reserve_device = Core.test_feature ("monitor.alsa.reserve-device") @@ -22,8 +21,6 @@ config.reserve_application_name = Conf.get_value_string ("wireplumber.settings", "monitor.alsa.reserve-application-name", defaults.reserve_application_name) config.properties = Conf.get_section ( "monitor.alsa.properties", defaults.properties):parse () -config.vm_node_defaults = Conf.get_section ( - "monitor.alsa.vm.node.defaults", defaults.vm_node_defaults):parse () -- unique device/node name tables device_names_table = nil @@ -155,12 +152,10 @@ function createNode(parent, id, obj_type, factory, properties) end end - -- apply VM overrides - if nonempty(Core.get_vm_type()) and - type(config.vm_node_defaults) == "table" then - for k, v in pairs(config.vm_node_defaults) do - properties[k] = v - end + -- add vm.type for rule matching purposes + local vm_type = Core.get_vm_type() + if nonempty(vm_type) then + properties["vm.type"] = vm_type end -- apply properties from rules defined in JSON .conf file