Commit graph

569 commits

Author SHA1 Message Date
Julian Bouzas
ed58f65184 state-routes.lua: Don't save again the route when restoring it
There is no need to save the route again after it has been restored because its
value has not changed.
2025-08-22 12:15:13 -04:00
Julian Bouzas
5060b27a9e apply-routes.lua: Always set save=false when applying routes
When applying new routes, we always want the save property to be false because
it is done by WirePlumber (not the user). WirePlumber applies routes when
restoring them from the state file, or when finding the best routes after the
profile has changed. In both cases, it does not make sense to set save=true.
2025-08-22 12:15:13 -04:00
Julian Bouzas
ea6f24e861 state-routes: Don't save routes that are not available
If the user changed the volume on a ACP 'Headphones' route to a value different
than 100%, and then unplugs the jack headset, the ACP 'Headphones' route becomes
unavailable with volume set to 100% and the save flag not cleared.

Since the save flag is not cleared when the ACP 'Headphones' route becomes
unavailable, WirePlumber will save it with 100% volume, overriding the previous
volume value set by the user. This is not ideal because the volume will be
restored to 100% by WirePlumber when plugging back the headset.

This change fixes this by never saving routes that are not available.
2025-08-22 12:15:13 -04:00
Julian Bouzas
ebd6d49a81 state-routes.lua: Make sure routes cache is always updated when evaluating them
The Route params changed event can be emitted before the EnumRoute params with
some devices, causing wrong evaluation of the routes because their cached info
is not updated. This change always enumerates the EnumRoute params before
evaluating them to make sure the cache info is always valid.

Fixes: #762
2025-08-22 12:15:13 -04:00
Pauli Virtanen
fb218fe016 scripts: add mpris-pause.lua to pause media streams when target removed
When current output target of a media player application is removed, it
can be useful if playback is paused (to avoid e.g. music playback to
going to speakers when headset is accidentally unplugged).  Android etc.
implement a policy like this.

Add a policy script that monitors stream target removals. When it
detects a media player application that is linked to a no longer present
output target, it checks whether the stream is associated with a media
player seen in MPRIS. If yes, it sends MPRIS Pause() command to the
media player.

Enable this policy by default.
2025-07-23 10:19:44 +03:00
George Kiagiadakis
e9928b4beb default-nodes/README: update documentation regarding the select-default-node event 2025-07-01 13:20:22 +03:00
George Kiagiadakis
754c805061 default-nodes/find-best: skip the hook if a very high priority node is selected
Just to optimize a bit more for performance
2025-07-01 13:13:21 +03:00
George Kiagiadakis
f1c96843ee default-nodes/rescan: remove unused table and access node.properties only once 2025-07-01 12:52:36 +03:00
Julian Bouzas
a433a49e28 default-nodes: Use session and route priorities when finding the default node
Some PCM devices can expose multiple nodes with same session priorities but
different route priorities. This improves the default nodes logic to also check
the route priorities when the session priorities are the same.
2025-07-01 12:52:36 +03:00
Julian Bouzas
84e2fcc050 monitor/alsa: Increase priority for USB devices
We always want the plugged USB ALSA device to have higher priority than the
internal ALSA device.
2025-06-26 14:05:38 -04:00
Richard Acayan
73f52cfb94 monitors/alsa: manage node when bound
If the managed node needs to emit events before it is bound, Wireplumber
treats it as destroyed and ignores the events. Add the node as pending
before it is bound so the node can run set_param on events that happen
before it gets bound.

Signed-off-by: Richard Acayan <mailingradian@gmail.com>
2025-06-23 08:02:46 +03:00
Tiago de Paula
ee42211bc6
fix: nil value in haveAvailableRoutes
Cause from partially renamed variables in af3c520d.

Closes #797
2025-05-21 01:00:59 -03:00
Julian Bouzas
0251d644a8 default-nodes/rescan: Check available routes using linking-utils
The linking-utils module already implements a way to check for available routes,
this patch uses it in default-nodes/rescan.lua to remove redundant code.
2025-05-18 14:11:53 +02:00
George Kiagiadakis
b8506d0d56 linking-utils: fix missing 'end' 2025-05-18 14:11:53 +02:00
George Kiagiadakis
af3c520d3e linking-utils: improve haveAvailableRoutes
Based on nodeHasAvailableRoutes() from default-nodes/rescan.lua
2025-05-18 13:56:14 +02:00
Pauli Virtanen
2d48caa74b monitors/alsa: fix nil table indexing
It's possible that managed_node.properties["node.name"] == nil if the
node is gone.

The removeDevice call above has already cleared the node names, so no
need to do it again.
2025-04-11 13:07:43 +00:00
George Kiagiadakis
9f440d0b50 monitors/libcamera: fix deduplicating devices with the same name 2025-04-11 15:53:44 +03:00
Lukas Riezler
e51e1b6080 v4l2/monitor: scripts: fix for deduplicate devices with the same name 2025-04-08 10:06:45 +02:00
Robert Mader
0d356f90ed monitor-utils: Support devices without any device ids
Such as libcameras virtual devices.
2025-04-07 17:04:22 +00:00
Julian Bouzas
0b716118c7 scripts: Add audio-group-utils.lua to group audio streams
This allows grouping audio streams that have a pw-audio-namespace ancestor
process name. The grouping is done by creating a loopback filter for each group
or namespace. Those loopback filters are then linked in between the actual
stream and device nodes. A '--target-object' flag is also supported in the
ancestor process name to define a target for the loopback stream node.
2025-03-05 16:28:34 +02:00
Pauli Virtanen
78f1e34029 autoswitch-bluetooth-profile: use s-device log topic 2025-03-02 15:09:53 +02:00
Andrew Sayers
d91c366c2f
Change the new "skipping device" warning to debug
The other "skipping device" (a few lines later) uses log:debug,
so it makes sense for these to be the same.
2025-02-21 13:03:03 +00:00
George Kiagiadakis
b031d3fcd1 scripts: populate session.services via a script
See pipewire!1409 / wireplumber!441
2025-02-07 11:05:44 +00:00
George Kiagiadakis
b8f0cf3644 monitors/bluez: make the source loopback node appear as non-virtual
Fixes: #729
2025-02-07 12:54:43 +02:00
luzpaz
cb770c1d7e docs: fix various codebase typos Found via codespell -q 3 -S "*.po,./po/*,NEWS.rst" -L bootup,gir,inout 2025-01-28 15:45:54 +01:00
Pauli Virtanen
899943bfcf monitors: disable stream-restore for device loopback nodes
stream-restore should not be touching node properties of the Bluetooth
mic / device set / offload / ALSA UCM split loopback nodes. Those are
controlled by Route settings on the device.

Set device.routes and state.restore-props=false as appropriate to avoid
that.
2025-01-26 21:33:22 +02:00
Pauli Virtanen
4d02d0275f monitors/alsa: provide splitting of UCM SplitPCM nodes
Instruct ACP to provide information about UCM SplitPCM channel
splitting instead of doing it with alsa-lib plugins.

Use the provided information to load loopbacks that create virtual sinks
that do the channel remapping from UCM.
2024-12-23 11:42:23 +02:00
Pauli Virtanen
027aba7f3b monitors/bluez: rename api.bluez5.id -> spa.object.id
Use same name as in alsa monitor.
2024-12-19 18:45:16 +02:00
Pauli Virtanen
ada687a4cc monitors/alsa: decouple name deduplication from node objects
Node name deduplication relying on presence of node objects creates race
conditions, as the name cannot be marked unused if the node object was
not created or was destroyed.

Use separate (device_id, node_id) -> name table to track name ownership
separately from the existence of node objects.

Also clear up the reserved names when device is destroyed, by the
monitor or device reservation.  In these cases "object-removed" for
nodes is not called, so this fixes names leaking when e.g. pw-reserve is
used.
2024-12-19 18:41:01 +02:00
Pauli Virtanen
65989e7e38 monitors: use WpSpaDevice:set_managed_pending()
In cases where a Node is created asynchronously and associated with the
Device later, set the id pending so that we don't miss ObjectConfig
events.

The "set Route again" workaround is also not needed, moreover it was not
reliable before either since the Device might issue ObjectConfig only
for changed properties.
2024-12-15 20:51:55 +02:00
Pauli Virtanen
4c1a6f5840 monitors/bluez: recreate SCO source when loopback is emitted
If loopback is emitted after the SCO node, e.g. when A2DP profile
connects late, recreate the SCO node.

This ensures the underlying SCO node is hidden when the loopback is
present.
2024-12-09 20:28:53 +02:00
George Kiagiadakis
4c07fd1da1 device: find-preferred-profile: define device_name variable
Fixes: #751
2024-12-02 12:18:42 +02:00
George Kiagiadakis
f79d4b1b3b monitors: alsa: disable api.acp.auto-profile by default
This seems to be an omission from when we transferred the default device
properties from the config file on to the Lua script. Both auto-profile
and auto-port are meant to be disabled, so that we can apply our own
management logic.

Fixes: #734
2024-11-28 16:02:57 +02:00
George Kiagiadakis
77d2dcd97f autoswitch-bluetooth-profile.lua: drop local function declarations
There is no point in local functions in the global script scope.
We use a sandbox anyway to isolate from other scripts.
2024-11-28 11:55:38 +02:00
Pauli Virtanen
1ddb473deb monitors/alsa: handle node activation failure
When node activation fails, it won't be created and its object-removed
signal can be called with some properties missing.  This breaks node
name deduplication, causing error

wplua: [string "alsa.lua"]:182: attempt to concatenate a nil value (local 'node_name')

It occurs e.g. when switching ALSA device profile, while some
application has opened the device with ALSA and is keeping it busy.

Fix by handling the activation failure, and tolerating missing property
in object-removed.
2024-11-23 17:11:37 +02:00
Julian Bouzas
76985fff5b autoswitch-bluetooth-profile: Switch to HSP/HFP on timeout
This patch adds a 500ms timeout callback to switch to HSP/HFP when a stream
starts capturing BT audio. This avoids quickly switching from A2DP to HSP/HFP
back and forth if an application just wants to probe the BT source for a short
period of time.

See #634
2024-10-10 15:54:59 +00:00
Robert Mader
b2d2f656fd monitor-utils: Check all libcamera v4l2 devices
The actual deduplication only checked the first device. Extend it to the
full list, as intended.

Fixes: 848b6326 (monitor-utils: Rework camera deduplication code)
2024-10-03 10:46:49 +02:00
Robert Mader
848b6326a9 monitor-utils: Rework camera deduplication code
The previous code made some invalid assumptions and was rather
complicated. Rework and simplify it.

The approach work as follows:
1. Once a new device gets registered, store its data in a list of pending
   devices.
2. Start a timer. On timeout, we check all pending devices and depulicate
   according to our heuristic. The timer gets reset whenever a device is
   added in order to avoid race conditions.
3. On timeout, add the pending devices to categories. For now: UVC cameras
   from the V4L2 plugin, libcamera cameras and other cameras from the V4L2
   plugin.
4. Then process the different categories in order of preference and store
   their V4L2 device IDs in a list for each plugin.
5. Before creating a camera, check that the V4L2 device(s) it uses are not
   yet used by a already existing camera from the other plugin.

While on it, drop support for Pipewire versions that don't report V4L2
device IDs at all.

Closes https://gitlab.freedesktop.org/pipewire/wireplumber/-/issues/689
Closes https://gitlab.freedesktop.org/pipewire/wireplumber/-/issues/708
2024-09-30 01:06:40 +02:00
Pauli Virtanen
b68a6794cd autoswitch-bluetooth-profile: switch only Bluetooth devices
Handle only devices associated with Bluetooth loopback nodes.

Make sure the node.link-group iteration cannot get stuck if there is a
loop in the link graph.
2024-09-10 07:51:03 +00:00
Julian Bouzas
0a86653085 autoswitch-bluetooth-profile: Use event source object managers
This patch removes the manually created object managers in the BT profile
autoswitch logic, and instead uses the object managers from the event source,
simplifying the logic a bit.
2024-07-12 10:18:12 -04:00
Julian Bouzas
afcb91f59b rescan: Stop rescan for 2s if BT node is removed
The intention here is to fix a Bluetooth bug where changing between different
profiles momentarily causes streams to be linked to an internal speaker.
Unfortunately, this case is not handled by the event dispatcher because some
signals are emitted using idle callbacks, and therefore we have to rely on
extra logic in rescan.lua to solve the problem.
2024-07-01 08:12:33 -04:00
Julian Bouzas
ff33f38bea rescan: Merge filters metadata changed hook with rescan-trigger 2024-06-28 11:42:11 -04:00
George Kiagiadakis
01a7339625 linking: explicitly mark targets that should be managed by the role-based policy
The previous assumption that any target with "device.intended-roles"
should be managed by the role-based policy is wrong, as for example
Bluetooth SCO nodes always have "device.intended-roles = Communication"
and some ALSA devices managed by ACP also do. This is meant to be used
as a hint for the desktop policy (it's been there in PulseAudio as well)
and does not necessarily mean that a role-priority-based policy should
be applied on all links to those devices.

Instead, use a new property to explicitly mark all the targets that
are meant to be managed by the role-based policy and respect that in
all places where we check for a potential role-based policy link.

Fixes: #682
2024-06-28 10:21:02 +03:00
George Kiagiadakis
abc299c1d3 linking: redefine script dependencies
This way of definining dependencies ensures that if we remove one
of the find-* hooks from the config, the rest of them will continue
to work in the expected order. Previously, removing one of them
would break the entire chain.
2024-06-28 10:21:02 +03:00
Julian Bouzas
96dc045382 l/find-best-target: Allow regular filters to be best targets
Similar to 4868b3c3 and fa671216, we always want to treat regular filters as
normal stream/device nodes.
2024-06-27 15:36:42 +00:00
George Kiagiadakis
fe42d931da linking-utils: fallback to role priority 0 if none is defined
See #682
2024-06-27 17:10:04 +03:00
George Kiagiadakis
317b5e8013 config: rename the duck-level option to have "role-based" in its name
Also, move the example from linking.conf to media-role-nodes.conf,
as it's more relevant there, and make sure the setting is constantly
read back in the Lua script, so that runtime changes can work.
2024-06-26 17:23:09 +03:00
George Kiagiadakis
52590ac850 docs: linking: update existing hooks documentation 2024-06-26 16:34:39 +03:00
George Kiagiadakis
d8fbf887b8 scripts: remove deprecated and outdated intended-roles.lua
This is now provided by find-media-role-target.lua
2024-06-26 16:30:45 +03:00
George Kiagiadakis
54d0f6fc7b l/rescan: use parseBool() to interpret boolean property
The previous check was also working, but this is safer
2024-06-26 16:19:32 +03:00