Commit graph

697 commits

Author SHA1 Message Date
Wim Taymans
59ed07864d media-session: log info when loading monitor fails
Log info in all monitor plugins instead of an error.
2021-04-09 11:55:55 +02:00
Wim Taymans
7bd6b725dc Fix some warnings
When memfd and systemd are disabled.

See #987
2021-04-04 21:09:39 +02:00
Wim Taymans
efd52d633f examples: only use memfd_create when defined
See #987
2021-03-30 09:59:07 +02:00
Wim Taymans
51c700a655 media-session: only save routes with the save flag set
We only want to save the route properties when they were changed
by a user action.
2021-03-29 15:52:31 +02:00
Wim Taymans
30659c5f61 media-session: remove double ;; 2021-03-29 11:41:30 +02:00
Pauli Virtanen
2681b8236b media-session/pulse-server: more error checks + minor fixes 2021-03-27 19:16:19 +02:00
Wim Taymans
69a8c302b1 media-session: clean up default node names 2021-03-26 15:13:23 +01:00
Wim Taymans
f6356a3441 media-session: handle node destroy during linking
Mark a node as busy linking while we call _create_links. The
_create_links method does a roundtrip and this might cause the node
to be destroyed. Set a flag when we notice this and avoid accessing
the destroyed object.
2021-03-26 13:07:28 +01:00
Pauli Virtanen
3d82700edb media-session: retry link a few times if it fails
Retry linking nodes a few times instead of giving up immediately.

This is a workaround, but it fixes moving streams on BT profile changes.
2021-03-25 19:51:02 +02:00
Wim Taymans
5629885e41 media-session: avoid strcmp on unterminated string
The string might not be 0 terminated so use the length to set a
limit for strcmp.
2021-03-25 17:29:19 +01:00
Wim Taymans
b54af4ab0a media-session: don't loop forever on link failures
Based on patch from Pauli Virtanen

Keep track of the last node that we failed to link to and don't try
to link to it again over and over.

See #882
2021-03-23 17:27:01 +01:00
Wim Taymans
3981f15ec6 media-session: also suspend error nodes
When a node is in the error state we need to suspend it to be
able to use it later again.
2021-03-23 17:21:06 +01:00
Wim Taymans
ae85a3da39 media-session: make link_nodes return the number of links
Return the result from sm_media_session_create_links() as the
result of link_nodes. This is > 0 when something was linked, < 0
on error and 0 when no ports are available. We should be able to
use this result later to handle errors.
2021-03-23 16:36:46 +01:00
Wim Taymans
7ee52b396d media-session: use restore stream for routeless nodes
When a node does not have routes, treat it like a stream and use
the restore-stream logic to restore the volumes.

Rework some of the logic a little. Don't save empty strings. Wait
for param updates to save/restore values.

This makes volume restore work on virtual sinks/sources and
sinks/sources without any routes.

See #729
2021-03-22 17:10:31 +01:00
Wim Taymans
92f1a24849 media-session: check stream move after configuring a new node
When a new node is configured, check if existing streams might need to
be moved to it.

This fixes the case where a stream has a target node set to some
bluetooth device and it starts playing to the default device because
the bluetooth device is not connected. When the BT device is then
connected and configured, the stream is moved to the new BT device.
2021-03-19 15:51:17 +01:00
Wim Taymans
972cf8d657 media-session: make midi sequencer bridge name configurable
Setting this to a2j might make it look pretier in some jack apps.
Not sure yet if this should be the default.
2021-03-18 16:27:46 +01:00
Wim Taymans
2ee4e94c59 policy-node: take into account sinks as a default source
A sink can be set as a default source, which means that the default
source is the monitor ports of the sink.

Move the direction check for later so that we can first check if we
are dealing with a potential default sink/source for the given
direction. If we found a default sink/source, we don't need to do
the direction check anymore.

This makes it possible to set a sink as a configured default source
and have policy-node take this into account when defining the
default.source metadata.

See #715, #908
2021-03-18 11:57:16 +01:00
Huang-Huang Bao
68677774fc
bluez5: fix reference to already freed spa_bt_device
Fixes #907
2021-03-18 12:09:30 +08:00
Pauli Virtanen
83443967a0 media-session: set node list change flag
See a96d8aa1aa
2021-03-17 16:19:04 +00:00
Wim Taymans
a96d8aa1aa media-session: guard against node destroy while iterating
When we are iterating the nodes and one is destroyed, restart the
scan operation so that we avoid accessing invalid memory.

See #901
2021-03-17 16:19:16 +01:00
Wim Taymans
35c27d0c10 media-session: restored saved profile from off
Always attempt to restore the saved profile again from the off state.
This can happen when the device goes into suspend or when hdmi is
unplugged.
2021-03-17 12:23:58 +01:00
Huang-Huang Bao
4200ca98d6
media-session: don't destroy bluez sm_object in session destroy handler, let object been destroyed in session_shutdown.
Avoid double free on object proxy, although it has been handled by d143c169cc.
2021-03-17 08:42:31 +08:00
Pauli Virtanen
d143c169cc media-session: free sm_objects only after session destroy emitted
Allows monitors (eg. bluez5) free any sm_objects they hold in
session_destroy.  In session_shutdown, destroy such objects before the
event, and free them only afterward.

Fixes double-free in bluez monitor.
2021-03-16 19:06:42 +00:00
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