Skip to content

Draft: create-item: register linkables in the order nodes appear

P V requested to merge pvir/wireplumber:fix-ordering into master

Linkables should appear in the same order as the nodes do, so that cross-references (e.g. node.target) can be handled correctly by policies. However, their activation can take time which scrambles the ordering.

Keep track of proper linkable activation order in a queue, removing and registering entries from the top when they are activated, and waiting if the top entry is not activated. Linkables taking more than ACTIVATION_USEC to activate are removed from the queue, and registered later when they activate.


This probably fixes a race condition with Zoom (flatpak version) desktop audio sharing, see #197 (closed), I'm not able to repro the condition with this branch.

If you run Zoom outside flatpak, this MR is not yet enough, because it does not synchronize changes in default nodes with node appearance. (Flatpak default policy forbids default node changes, so flatpak Zoom works.)

An easier race condition to reproduce is to add

context.exec = [ { path = "pactl" args="load-module module-combine-sink" } ]

to ~/.config/pipewire/pipewire-pulse.conf.d/10-startup.conf and then observe that playback to the sink on most restarts doesn't produce output. In policy-node logs, one observes that the combine_output.sink-* streams are usually destroyed instead of getting linked, since policy-node sees them before the nodes they would be linked to. With this MR, they always get linked, looks like this:

D 23:14:06.464624 script/create-item create-item.lua:148:addItem: <WpSiAudioAdapter:0x6250014d50e0> add node: combined-sink (38)
D 23:14:06.541446 script/create-item create-item.lua:162:chunk: <WpSiAudioAdapter:0x6250014d50e0> activated item for node 38
I 23:14:06.541655 script/create-item create-item.lua:69:registerItem: <WpSiAudioAdapter:0x6250014d50e0> register item for node: combined-sink (38)
D 23:14:06.583902 script/create-item create-item.lua:148:addItem: <WpSiAudioAdapter:0x6250014d52c0> add node: alsa_output.pci-0000_01_00.1.hdmi-stereo-extra3 (51)
D 23:14:06.586478 script/create-item create-item.lua:148:addItem: <WpSiAudioAdapter:0x6250014d54a0> add node: alsa_output.usb-Logitech_Inc._Logitech_USB_Headset_H340-00.analog-stereo (52)
D 23:14:06.589522 script/create-item create-item.lua:148:addItem: <WpSiAudioAdapter:0x6250014d5680> add node: alsa_input.usb-Logitech_Inc._Logitech_USB_Headset_H340-00.analog-stereo (53)
D 23:14:06.591968 script/create-item create-item.lua:148:addItem: <WpSiAudioAdapter:0x6250014d5860> add node: combine_output.sink-536870912.alsa_output.pci-0000_01_00.1.hdmi-stereo-extra3 (54)
D 23:14:06.597882 script/create-item create-item.lua:148:addItem: <WpSiAudioAdapter:0x6250014d5a40> add node: combine_output.sink-536870912.alsa_output.usb-Logitech_Inc._Logitech_USB_Headset_H340-00.analog-stereo (55)
D 23:14:06.599700 script/create-item create-item.lua:162:chunk: <WpSiAudioAdapter:0x6250014d5860> activated item for node 54
T 23:14:06.599747 script/create-item create-item.lua:91:flushQueue: <WpSiAudioAdapter:0x6250014d52c0> waiting for activation for node 51
D 23:14:06.600631 script/create-item create-item.lua:162:chunk: <WpSiAudioAdapter:0x6250014d5a40> activated item for node 55
T 23:14:06.600673 script/create-item create-item.lua:91:flushQueue: <WpSiAudioAdapter:0x6250014d52c0> waiting for activation for node 51
D 23:14:06.613940 script/create-item create-item.lua:162:chunk: <WpSiAudioAdapter:0x6250014d52c0> activated item for node 51
I 23:14:06.614100 script/create-item create-item.lua:69:registerItem: <WpSiAudioAdapter:0x6250014d52c0> register item for node: alsa_output.pci-0000_01_00.1.hdmi-stereo-extra3 (51)
T 23:14:06.615008 script/create-item create-item.lua:91:flushQueue: <WpSiAudioAdapter:0x6250014d54a0> waiting for activation for node 52
D 23:14:06.616875 script/create-item create-item.lua:162:chunk: <WpSiAudioAdapter:0x6250014d54a0> activated item for node 52
I 23:14:06.617018 script/create-item create-item.lua:69:registerItem: <WpSiAudioAdapter:0x6250014d54a0> register item for node: alsa_output.usb-Logitech_Inc._Logitech_USB_Headset_H340-00.analog-stereo (52)
T 23:14:06.618046 script/create-item create-item.lua:91:flushQueue: <WpSiAudioAdapter:0x6250014d5680> waiting for activation for node 53
D 23:14:06.620173 script/create-item create-item.lua:162:chunk: <WpSiAudioAdapter:0x6250014d5680> activated item for node 53
I 23:14:06.620317 script/create-item create-item.lua:69:registerItem: <WpSiAudioAdapter:0x6250014d5680> register item for node: alsa_input.usb-Logitech_Inc._Logitech_USB_Headset_H340-00.analog-stereo (53)
I 23:14:06.621492 script/create-item create-item.lua:69:registerItem: <WpSiAudioAdapter:0x6250014d5860> register item for node: combine_output.sink-536870912.alsa_output.pci-0000_01_00.1.hdmi-stereo-extra3 (54)
I 23:14:06.623453 script/create-item create-item.lua:69:registerItem: <WpSiAudioAdapter:0x6250014d5a40> register item for node: combine_output.sink-536870912.alsa_output.usb-Logitech_Inc._Logitech_USB_Headset_H340-00.analog-stereo (55)

Yes, I had to add a timeout here, but it's at least guaranteed Wireplumber will live at most one second in the past... I think in usual operation the timeout will not be triggered. Might be useful to test with the players (which?) that earlier had problems with the timeouts in policy-node, even though they probably won't apply here.

Edited by P V

Merge request reports

Loading