Commit graph

774 commits

Author SHA1 Message Date
Huang-Huang Bao
75b4c80dc6 bluez5: add logic to fallback to previous behavior if connection info handling is not supportrd by session manager (i.e wireplumber). 2021-03-16 10:31:08 +00:00
Huang-Huang Bao
af8272fe08 bluez5: create device handle before profile negotiation started so that profile handler can retrieve per-device settings 2021-03-16 10:31:08 +00:00
Huang-Huang Bao
e7cecaaea6 media-session: apply updated properties to bluez/v4l2 device handle 2021-03-16 10:31:08 +00:00
Pauli Virtanen
d9c5ea54fd media-session: set bluetooth volume directly on the local adapter node
Avoid problems with session proxy appearing too late by setting props on
directly on the local SPA node.
2021-03-15 21:24:39 +02:00
Wim Taymans
5c91f23c18 default-routes: only restore routes when profile changed
When the profile changes, try to restore the previously saved
routes. Otherwise, follow the best route when it changes.

See #863
2021-03-15 16:06:13 +01:00
Wim Taymans
85a102f414 default-profile: restore saved profile only for first time
Don't always try to restore the saved profile when it's available
but only do this the first time. From then on, try to follow the
best profile when it changes.
2021-03-15 14:57:10 +01:00
Wim Taymans
0b6d3e4b71 default-routes: reconfigure the profile when routes change
When something changes to the route status, try to reconfigure the
current profile.
2021-03-15 11:51:24 +01:00
Pauli Virtanen
8ba6e98320 media-session: move libcamera+bluez5 device removal to object free callback
libcamera + bluez5 devices should be freed/unloaded via the sm_object
free callback, similarly as in alsa and v4l2 monitors.  This ensures
they are run at session_shutdown.
2021-03-15 08:20:38 +00:00
Pauli Virtanen
5b8c7c405d media-session: deal with global id race conditions
To resolve monitor and policy core global ids racing with each other,
use separate registry event handlers for both cores.  Each handles only
their own objects, determined by where the object handle was created.

Postpone handling of policy core new global events after monitor sync,
which orders them after the corresponding monitor proxy and registry
events. Monitor core is then more up-to-date, so we resolve id clashes
in favor of monitor globals, which avoids duplicate objects.

Fix use-after-free by tracking whether a monitor holds references to
sm_object. Keep also objects pending for id in a list, so that they can
be cleaned up on session_shutdown (monitors may leak objects at
shutdown, because spa objectinfo events won't be handled then).

Caveats:

Zombie objects may still created if policy core is late by several
events, but in those cases the corresponding remove events are already
in the queue.

Also, there's a (theoretical) possibility that pw_registry_bind will
bind the wrong object, if the registry event is handled too late and an
id is reused by the server.

For details, see reverted 77e4fdb1e4
for which this is a another approach.
2021-03-15 08:20:38 +00:00
Thibault Saunier
22f6e8e36d meson: Fixed remaining issues from the port to feature options 2021-03-11 18:29:11 +00:00
Wim Taymans
38d36f1921 media-session: improve saved profile restore
We only want to restore the saved profile when it is available, when
it is not available and there was no change in best profile, leave
the profile as it is.
2021-03-11 10:22:33 +01:00
Wim Taymans
d295d97160 media-session: only restore best profile when something changed
Keep track of the best profile. Only try to switch away from the
saved profile when something changed and the saved profile is not
available.

This makes it possible to select an unavailable profile but when
something is changed, it will switch away from it.
2021-03-11 09:32:17 +01:00
Thibault Saunier
485bae5eb0 meson: Use feature options everywhere it makes sense 2021-03-10 20:18:34 +00:00
Wim Taymans
ef4b3c403e media-session: -1 as node.target is default
A node.target property of -1 also means to follow the default
sink/source. The ALSA plugin might use this to select the
target node and would otherwise not move to the new default sink.
2021-03-10 15:27:06 +01:00
Wim Taymans
dd0342167f policy-node: move variable up in scope
We are using it outside of the scope it is defined in.
2021-03-09 12:48:48 +01:00
Wim Taymans
1b6060ef5f media-session: schedule more rescan for pending changes
Trigger/delay a rescan until the profiles, routes and stream
volume are restored.

See #789
2021-03-08 15:14:40 +01:00
Wim Taymans
d603c1086a media-session: (re)schedule rescan after new pending operation
Every time a new operation is started, schedule a rescan. This
ensures that there are no more pending actions before the policy
module scans the nodes.

This has the effect that all devices and nodes are up to data and
ready to be used by policy-node.

Fixes #789
2021-03-08 13:20:02 +01:00
Wim Taymans
59f86df9f3 media-session: move profile switch to default-profile
Move the profile switching from default-route to the default-profile
module. This makes more sense and it also allows us to restore the
saved profile when it becomes available.

Make default-profile always check if the saved profile can be restored
before attempting to switch to the best profile.

Default-route now just monitors profile changes and restores the
routes associated with it.

See #466
2021-03-08 11:52:38 +01:00
Wim Taymans
662fd8a1f9 pulse-server: avoid crashing when clearing metadata
The key will be NULL so we can't strdup it.

Fixes #845
2021-03-05 20:16:29 +01:00
Wim Taymans
1c365f6169 policy-node: fix compiler warning 2021-03-05 20:16:05 +01:00
Wim Taymans
c8fd34a41d metadata: store default-nodes as JSON
Don't just store the id in the metadata but a JSON object with
the node name. This makes it possible to easily introspect the
metadata and also extend the metadata with more fields later.

Instead of matching the metadata id to the global ids we now
have to match it against the name.
2021-03-05 17:37:12 +01:00
Wim Taymans
b40397d986 media-session: check metadata before using it
The session manager might be configured without metadata support
so check this before attempting to use the metadata. It's not
really a problem because the default sink/source can only be
changed with the pulseaudio API, which activates metadata.
2021-03-05 10:34:27 +01:00
Wim Taymans
93002ecd11 media-session: remove unused prefix from load/save state
The prefix was used to filter the properties when loading and
saving but since the conversion to the core provided functions, this
feature is not longer available.

It's not exactly a problem, we could implement the filtering ourselves
afterwards but there is little point because we just ignore the unknown
items and never write invalid items.
2021-03-05 09:23:19 +01:00
Wim Taymans
1642e5220f media-session: sanitize device names as well
See #827
2021-03-04 12:45:35 +01:00
Wim Taymans
6f26210361 media-session: simplify routing a bit
1) detect port changes
2) restore or save port changes
3) if port changes:
     check and restore the best profile
     else check and restore the best ports
4) if profile changed, check and restore best ports

See #533
See #708
2021-02-24 20:28:21 +01:00
Wim Taymans
1f2cb7ac67 don't crash with missing libraries 2021-02-23 17:48:57 +01:00
George Kiagiadakis
3a7ce9660a meson: add option to enable/disable media-session 2021-02-23 16:21:59 +00:00
Wim Taymans
ab45b16a05 media-session: improve routing
First check all the routes to see if anything changed. If there is
a change check if we need a profile switch.
Then check all the active routes and restore state when they changed.
2021-02-23 11:09:42 +01:00
Wim Taymans
3b0fcdd525 media-session: don't save invalid route properties
When we switch away from a route, don't save the properties.
2021-02-22 17:47:04 +01:00
Wim Taymans
8414092763 Rework profile/route handling
Add save property to Profile and Route params to notify the session
manager that they should be saved. Let the session manager only save
the Profile and Routes with the save flag.
Make pulse-server set the save flag on Profile and Route changes.
The result is that we can make a difference between user requested
changes and automatical changes and only remember the user preferences.
When a port changes availability, first check if we need to perform
a profile switch, if not select the new best port.
2021-02-22 16:51:59 +01:00
Wim Taymans
5ae92fd643 media-session: Fix saved_profile check
ID_INVALID is when the profile was not saved.
2021-02-22 10:54:55 +01:00
Wim Taymans
3673265ae2 policy-node: don't crash without metadata 2021-02-19 17:54:31 +01:00
Wim Taymans
72e03e3dc8 media-session: add -c option to load custom config 2021-02-19 17:48:27 +01:00
Wim Taymans
84fc63e601 media-session: don't switch to pro-audio by default
Ignore the pro-audio profile when finding the best profile. We only
want to enable the profile when explicitly set.

Fixes #761
2021-02-18 19:51:00 +01:00
Wim Taymans
63a3811aa7 fix some warnings 2021-02-18 12:42:06 +01:00
Pauli Virtanen
2efdb78239 media-session: save and restore latencyOffsetNsec 2021-02-18 11:33:45 +00:00
Wim Taymans
bf062e455a media-session: always remember the new route availability 2021-02-17 15:49:20 +01:00
Wim Taymans
aea79cd79c media-session: sanitize description
Because we use the description as the JACK name, remove the : so
that it looks somewhat ok in more cases.
2021-02-17 13:12:22 +01:00
Wim Taymans
6079830591 media-session: add option to configure suspend timeout
Set the property on the node and use the value when suspending the
node. a timeout of 0 disables suspend.
2021-02-16 15:41:53 +01:00
Wim Taymans
7ba9044c3d Revert "media-session: fix sm_object ownership"
This reverts commit 791a38f3fa.
2021-02-15 15:28:42 +01:00
Wim Taymans
a85be79135 Revert "media-session: when resolving duplicate objects, bind a proxy if missing"
This reverts commit 77e4fdb1e4.
2021-02-15 15:28:35 +01:00
Pauli Virtanen
77e4fdb1e4 media-session: when resolving duplicate objects, bind a proxy if missing
When duplicate objects are created, the new object has missed its
registry_global event, and is missing its proxy.

In this case, bind a proxy for the new object.
2021-02-13 19:04:21 +00:00
Pauli Virtanen
791a38f3fa media-session: fix sm_object ownership
sm_object may be owned by either (i) monitors, created via
sm_media_session_create/export*, or (ii) registry, via
registry_global+bind_object.  However, registry adds the objects to its
globals list when their proxy appears, even if it does not own them.

Only owner should call sm_object_destroy which unrefs obj->handle,
because the sm_object structure is stored inside the handle's user_data
and becomes invalid afterward.

The sm_object_destroy call removes the object from the registry globals
map, so if monitor calls first, there is no problem. However, sometimes
the registry wins the race.

Previously, registry did sm_object_destroy regardless of whether it owns
the object or not, possibly causing the monitor's sm_object_destroy to
refer to freed memory. This could cause segfaults, e.g.

    CARD=XX:XX:XX:XX:XX:XX
    bluetootctl connect $CARD
    while true; do pactl set-card-profile bluez_card.$CARD a2dp-sink; pactl set-card-profile bluez_card.$CARD off; done

leads to a race between bluez5_remove_node and registry_global_remove,
and problems appear when the latter wins.  (As usual, if it doesn't
segfault, a heisenbug appears instead.)

Fix this by keeping track who owns the objects, and having registry
destroy the objects only if it owns them. Otherwise, it just removes
them from its lists.

Also call pw_proxy_unref unconditionally in sm_object_destroy, so its
asserts catch refcounting errors (although now there shouldn't be any).

***

Another problem is conflict between bound_proxy and register_global,
which generates duplicate objects with the same id.  We resolve this by
keeping the object not owned by the registry and discarding the other
one.

This fixes a memory leak, and possible consistency problems in session
modules (due to session_create events for different objects with same
id; now there will be paired session_remove ones in between).
2021-02-13 19:04:21 +00:00
Wim Taymans
b23e33c99f media-session: only replace : with space for node.nick 2021-02-13 07:17:55 +01:00
Wim Taymans
062911640c media-session: sanitize name and nick
Replace unwanted chars in the name with _. This makes it compatible
with pulseaudio names and avoids problems with regex.
Replace unwanred chars in the nick with ' '. This ensures JACK
clients don't receive ':' in the device names, which cause it to
fail when parsing the ports.

See #714 and #130
2021-02-12 20:47:41 +01:00
Wim Taymans
2c2ba6eec3 media-session: handle missing dbus support 2021-02-12 17:55:56 +01:00
Wim Taymans
04354215b6 media-session: get the right key for properties 2021-02-12 17:28:52 +01:00
Pauli Virtanen
dfb3bff15b bluez5: fix source priority assignment 2021-02-12 16:11:56 +00:00
Wim Taymans
3cc577ddd6 v4l2: fix sink/source and output/input names 2021-02-12 16:13:00 +01:00
Wim Taymans
2a83811297 bluez: input = source, output = sink 2021-02-12 16:10:58 +01:00