Commit graph

48 commits

Author SHA1 Message Date
Wim Taymans
ba544c8e36 media-session: handle dbus disconnect
Make a signal in media-session to signal dbus disconnect.
Get the DBusConnection when we need it in alsa and access-portal.
Remove device reservation if dbus disconnects and try again later
when needed.

See #1099
2021-05-17 15:17:54 +02:00
Pauli Virtanen
462c50acd6 media-session: keep track of seq in pw_*_enum_params
If multiple async enum param are running at the same time, take results
only from the latest one.
2021-04-25 20:56:57 +03:00
Pauli Virtanen
0e80a2497a media-session: add logind seat status support 2021-04-10 21:53:29 +03: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
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
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
7ba9044c3d Revert "media-session: fix sm_object ownership"
This reverts commit 791a38f3fa.
2021-02-15 15:28:42 +01: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
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
fac80e76d2 media-session: add conf file for v4l2 and bluez as well 2021-01-12 20:42:58 +01:00
Wim Taymans
24c68b0067 media-session: add config files
Remove -e and -d options
Manage modules in media-session.conf
Add alsa-monitor.conf that can match node/device properties with
a regex and update properties on it. All previous configuration and
more cane be done with this.
2020-12-30 13:15:08 +01:00
Wim Taymans
19dc150643 media-session: don't emit metadata remove in shutdown
When in shutdown we destroy all objects but don't remove all
the metadata associated with them, like route settings.
2020-12-01 12:03:28 +01:00
Wim Taymans
7ca8491be3 media-session: store values as json
Save settings as jason and use a small json compatible tokenizer to
load settings instead of our own less flexible format.
Save settings with a prefix and filter out entries without prefix
Listen for changes in restore.stream metadata and update properties.
2020-11-22 10:00:58 +01:00
Wim Taymans
5af2efdaa6 media-session: expose metadata method
Expose a method to create an export metadata with a certain name.
2020-11-20 17:58:08 +01:00
Wim Taymans
3733a5e219 media-session: save last target_node
Keep a per node entry of the saved target node and use this when
there is no other target node.
When explicitly moving a stream, save the new target node.
2020-10-14 12:35:27 +02:00
Wim Taymans
8a4dd83883 media-session: add API to load/store state 2020-08-13 11:33:48 +02:00
Wim Taymans
5e51cbe48e media-session: improve param enumeration
Don't use subscribe, enum is more manageable.
Use user data field to check for changes.
Only enumerate readable params.
Enum all node params.
2020-07-31 13:59:25 +02:00
Wim Taymans
03c2185efe media-session: rework linking nodes
Rework how nodes are linked. score each port pair and link the
highest score taking into account the type, direction, channels,
and number of linked ports.
2020-07-22 15:05:45 +02:00
Wim Taymans
f6753eefc3 media-session: keep more info about ports
Parse the DSP type and the channel and keep it around
2020-07-22 11:27:23 +02:00
Wim Taymans
d720724d48 media-session: add method to iterate objects 2020-07-16 17:48:29 +02:00
Wim Taymans
5f2c4c70ec media-session: expose metadata 2020-07-15 14:21:35 +02:00
Wim Taymans
2d5a404244 media-session: add method to remove links 2020-07-15 14:20:46 +02:00
Wim Taymans
ed31ca30cd media-session: improve cleanup of objects
Don't try to use the proxy destroy event to destroy the objects.
It is not called automatically anymore, only when we call
pw_proxy_destroy() ourselves.

Destroy the proxy objects when we destroy the session managed
object instead, either when the global is removed or when we
explicitly call _destroy()

Add an object free signal to clean up final resources after the
proxies have been destroyed, like closing libraries.

Track and destroy our link proxies.
2020-06-04 17:41:01 +02:00
Wim Taymans
c20100eabb media-session: Add method to destroy a global
Destroy the stream when it is disconnected and it was marked as
DONT_RECONNECT.
2020-04-02 15:27:23 +02:00
Wim Taymans
2b7f01f5af media-session: add getopt support
Add options to media-session
Add an option to enable or disable modules
Add an option to set properties for later use
2020-03-30 14:09:44 +02:00
Wim Taymans
d3634aca7e media-session: rework device reservation
Monitor the device reservation objects and mark the device available.
Don't select nodes from devices that are not available.
Acquire the device reservation when a device starts.
Release the device reservation when we suspend the device again.
2020-02-19 18:15:57 +01:00
Wim Taymans
b99074879f policy-node: use the daemon samplerate
Use the samplerate of the daemon to configure the nodes.
2020-01-09 15:52:53 +01:00
Wim Taymans
b312e77385 Make simple node policy
Make it possible to run the session manager without endpoint
modules. Add a simple node policy that links nodes.

Move the session-manager implementation and startup of the
endpoint monitors to a separate module.

Handle async set_param on the device
2020-01-07 17:19:09 +01:00
Wim Taymans
f391353c7f Make interface types a string
This is more in line with wayland and it allows us to create new
interfaces in modules without having to add anything to the type
enum. It also removes some lookups to map type_id to readable
name in debug.
2019-12-19 13:36:04 +01:00
Wim Taymans
147f488514 media-session: improve cleanup 2019-12-18 12:15:03 +01:00
Wim Taymans
05f93cd750 media-session: improve cleanup 2019-12-17 10:47:31 +01:00
Wim Taymans
f06fc5a62b media-session: add sync_update
Add method to only emit the update event when all actions up to
the sync point completed.

Update the available bits on NODES/PORTS/STREAMS/ENDPOINTS
2019-12-16 13:38:16 +01:00
Wim Taymans
1bca1b15ea context: add object store
Add method to set and get typed objects from the context. This can
be used to pass around context objects between modules without having
to register them.
2019-12-16 10:28:18 +01:00
Wim Taymans
1317ca140c pass spa_dict around as config
Don't pass pw_properties around when we simply need to pass around
config info, only use pw_properties when used to construct an object
that keeps the properties.
2019-12-13 11:26:05 +01:00
Wim Taymans
d70a47b7fe move proxy implementations in their own file
Rearrange headers
2019-12-11 10:58:51 +01:00
Wim Taymans
8ea78c2e3f pw_core -> pw_context
The proxy API is the one that we would like to expose for applications
and the other API is used internally when implementing modules or
factories.

The current pw_core object is really a context for all objects so
name it that way. It also makes it possible to rename pw_core_proxy
to pw_proxy later.
2019-12-10 18:19:56 +01:00
Wim Taymans
125fcb5660 session-manager: remove obsolte _set_id
media-session: Wait for devices to appear and be bound before setting
the profile on the device. Then wait for all the nodes to appear
before attempting the create endpoints on the device.
2019-11-29 13:34:09 +01:00
Wim Taymans
e1ef01c860 alsa-endpoint: move to separate service
Let the session manager monitor device objects as well.

Make the alsa-endpoint monitor a separate service instead of letting
the alsa-monitor call it directly. This means that it listens for
device objects and then tries to configure the endpoints when the
device profile is set to active. This does not work yet because we
can't link the nodes to the device yet because there is no way to know
what the global id is of the device we created.

Make sure implementations of objects run in a separate remote connection
because the main remote connection might block while waiting for a
return value from the implementation.

Trigger an object update after all object info is collected. We do this
by triggering a roundtrip after receiving the info event. When we get
the reply, we can assume all info is flushed. This includes the
parameters that we received.
2019-11-29 13:34:09 +01:00
Wim Taymans
87946ed2cf media-session: move all flags to the object 2019-11-29 13:34:09 +01:00
Wim Taymans
c46753bcae media-session: track nodes we create
Add a method to create a node and track the proxy. We can then
use this to track the params on a node.

Don't listen end enumerate the params in the monitors bbut let the
session do that. Use the collected params from the session to create
endpoints and streams.

Always activate the default stream on alsa nodes to create the
ports and have something we can present to apps.
2019-11-29 13:34:09 +01:00
Wim Taymans
80ac755670 media-session: make the services more modular 2019-11-29 13:34:09 +01:00
Wim Taymans
b7aa8f5c85 media-session: subscribe to params when needed
Subscribe to params and collect them.
2019-11-29 13:34:08 +01:00
Wim Taymans
541f3a4cc6 media-session: keep globals in a list as well
Also keep a list of globals and use it to emit the globals in
add_listener.
2019-11-29 13:34:08 +01:00
Wim Taymans
e24e383550 media-session: add callback based sync method
Call the callback when the sync completes. Implement roundtrip
with this.
2019-11-29 13:34:08 +01:00
Wim Taymans
709a52e286 media-session: also create EndpointLink objects
Create an endpoint link object when linking endpoints. Keep track
of the links in the endpoint_link and cleanup when they are all
gone.

Improve properties on session objects.
2019-11-29 13:34:08 +01:00
Wim Taymans
3cd7d90d88 media-session: link all stream ports
Create a helper in the session manager to link all ports between
2 nodes.

Make the output endpoint call the input endpoint create_link, passing
the node or ports to link to.

Make the input endpoint complete the link by calling the session
helper to link all ports.

Remove the node policy, we're only using a policy for the endpoints
now.
2019-11-29 13:34:07 +01:00
Wim Taymans
9bc5d23ffe media-session: add _roundtrip helper
Add a function to force a roundtrip
2019-11-29 13:34:07 +01:00
Wim Taymans
161cf46898 media-session: add media session helpers
Move all the media-session object monitoring into one place and
provide an API to get to the session objects.

Make API to add module specific info to objects.

Add methods to export and create objects in the session. This should
make it possible to link proxy to implementation and avoid a server
roundtrip in some cases.
2019-11-29 13:34:07 +01:00