Commit graph

4868 commits

Author SHA1 Message Date
Wim Taymans
90eb1c18e0 pulse-server: unlink operation before callback
To ensure that the callback can't accidentally find and free the
operation.
2022-02-21 08:54:50 +01:00
Wim Taymans
d7793501fd pulse-server: free pending sample reply
If the sample finished playing before we finished the roundtrip to
get the sink_index, it will be destroyed. When the roundtrip completes,
it will try to use invalid memoryy and crash.

Make sure we destroy all pending replies before destroying the sample
to avoid this problem.

Fixes #2151
2022-02-20 21:34:53 +01:00
Pauli Virtanen
bf9ef440c3 protocol-native: check invariant for marshaled data
There's an assumption that marshaled messages consist of a single POD,
since we now tag on a footer after it.  This is true for the
protocol-native implementations, which all wrap the message in a single
POD Struct.

To catch protocol-native implementation bugs here later, add assert that
marshaling produces a single POD.
2022-02-20 18:19:13 +02:00
Pauli Virtanen
d44bf0ffc0 impl-core/protocol-native: use generation counter for global registry
Some client messages have bare ids (as opposed to proxies/resources),
eg. as in pw_registry_bind/destroy.  If the client is processing
messages late, these may refer to an object that was already removed,
and the id may now refers to a differnt objects.  I.e. the following
race condition needs to be resolved:

server               client
Global 1 (gen. 1)
                     Global 1
Global 1 remove
Global 1 (gen. 2)
                     Bind/destroy 1

Where the client would bind/destroy the wrong global, since it did not
yet see the messages for the second one.

To keep track of which object the client means, the server keeps track of
the "generation number" of its global registry, and what generation
the client is at.

Each global remembers at what generation of registry they were
registered. When processing the messages that use bare ids, check the
registry generation of the client, to know whether the message refers to
a stale global that was already removed.

Messages where client sends bare ids to server are:

    pw_registry_bind, pw_registry_destroy, metadata_set_property

In pw_registry_* do the staleness check directly. Also add staleness
check in pw_impl_client_check_permissions, so that also the metadata
case is handled.

The generation numbers are passed around in message footers, but only if
they have changed.  When the generation number changes on server, we
send the updated value to the client in a message footer.  When client
has received an update value, it will send the value back in the footer
of the next message it sends to the server.

Based on: Wim Taymans <wtaymans@redhat.com> "impl-core: check serial number"
2022-02-20 16:59:25 +02:00
Pauli Virtanen
680c33d3eb protocol-native: extend v3 protocol with message footers
Extend version 3 protocol with message footers, which are for passing
around global state data that is not addressed to a specific object.

The extension is backward compatible with previous v3 clients, and won't
e.g. result to error spam in logs.

The footer is a single SPA POD, appended after the main message POD.
Because both the protocol message and the message POD record their
length, it's possible to append trailing data. Earlier clients will
ignore any data trailing the message POD.

The footer POD contains a sequence [Id opcode, Struct {...}]*,
so there is room to extend with new opcodes later as necessary.

There are separate marshal/demarshal routines for messages aimed at
resources and proxies.
2022-02-20 16:59:25 +02:00
Pauli Virtanen
c4997fc46d pipewire-pulse: moving DONT_MOVE streams should fail
Pulseaudio return EINVAL for attempts to move DONT_MOVE streams.
2022-02-20 01:30:48 +02:00
Wim Taymans
bb1cd23a1a modules: fix warning 2022-02-18 15:12:27 +01:00
Barnabás Pőcze
d6c5da5678 pipewire: module-x11-bell: mark connection as terminatable
Since XFixes version 6[1] it is possible to mark
an X connection as terminatable. The X server will
gracefully terminate after a timeout if only
terminatable connections remain.

[1]: https://gitlab.freedesktop.org/xorg/lib/libxfixes/-/merge_requests/1
2022-02-18 12:30:53 +01:00
Barnabás Pőcze
c9612225e1 pipewire: module-x11-bell: handle X11 errors
Unfortunately, libX11 has global error and I/O error handlers,
which make it inconvenient to use them from library code.

Since libX11 1.7.0, there is a per-display "exit_handler" which
is called from `_XIOError()`, however, the global I/O error
handler is still called before that, and that - by default -
calls `exit(1)` in `_XDefaultIOError()` after printing the error
to stderr.

To avoid exiting, custom handlers will be registered when
libpipewire-module-x11-bell.so is loaded given that at
that moment the default handlers are installed.

When the shared object is unloaded, the handlers will
be reset to the default ones given that the currently
registered handlers are the ones that were registered
when the module was loaded.

The logic only works correctly if there are no concurrent
calls to `XSet{IO}ErrorHandler()` while `{set,restore}_x11_handlers()`
is running. Since module-x11-bell is probably mostly going to
be loaded in `pipewire-pulse`, this seems like a reasonable
assumption to make.
2022-02-18 12:30:53 +01:00
Barnabás Pőcze
7c70c4e383 pipewire: module-x11-bell: remove unnecessary member
`xkb_event_base` is only ever set and never read. Remove it.
2022-02-18 12:30:53 +01:00
Barnabás Pőcze
45bd8532eb pipewire: use newly added function for deferred module destroy
Use the newly introduced `pw_impl_module_schedule_destroy()`
for deferred module destroy in all modules except
module-example-{sink,source}.
2022-02-18 12:30:53 +01:00
Barnabás Pőcze
a13e7ef091 pipewire: impl-module: add method for deferred destroy
Add `pw_impl_module_schedule_destroy()` which will
schedule a call to `pw_impl_module_destroy()` on
the module's context's work queue.

For now, do not add it to the public impl-module.h header,
only private.h.
2022-02-18 12:30:53 +01:00
Barnabás Pőcze
4d4c6f20df pipewire: remove work queue checks
Since now `pw_context_get_work_queue()` cannot
fail, the checks can be removed.
2022-02-18 12:30:53 +01:00
Barnabás Pőcze
eae6517c84 pipewire: context: create work queue immediately
Many modules cannot load without a work queue,
neither links nor nodes can be created without it.

It's probably better to try to create it immediately
when the context is created. This elliminates the
need for checking whether `pw_context_get_work_queue`
succeeded or not.
2022-02-18 12:30:53 +01:00
Barnabás Pőcze
afda4c81e7 pipewire: module-x11-bell: simplify x11_connect()
Since no cleanup needs to be in `x11_cleanup()`, the
`error` label may be removed and the error codes
can be returned directly.
2022-02-18 12:30:53 +01:00
Barnabás Pőcze
d558e87b51 pipewire: module-x11-bell: remove a function
`x11_close()` is no longer needed since X11 errors
are now considered fatal, so `module_destroy()` will
be called if `x11_connect()` fails, which means that
the code from `x11_close()` can be moved there.
2022-02-18 12:30:53 +01:00
Barnabás Pőcze
ffabf78cb7 pipewire: module-x11-bell: check source creation 2022-02-18 12:30:53 +01:00
Barnabás Pőcze
84cc3d7dc6 pipewire: module-x11-bell: make X11 errors fatal 2022-02-18 12:30:53 +01:00
Barnabás Pőcze
7f70d484c2 pipewire: module-x11-bell: only use the thread loop to play the sample
Register the X11 file descriptor in the main loop,
and use `pw_loop_invoke()` to offload the libcanberra
calls to the thread loop.
2022-02-18 12:30:50 +01:00
Barnabás Pőcze
0ed27e570f pipewire: module-x11-bell: only remove hook if registered
Only remove the module listener if it has actually
been added to the module's listener list.
2022-02-18 12:22:10 +01:00
Wim Taymans
cab1d905d6 proxy: break after the first leaked listener
The list entry might be corrupt and we should not try to follow it.
2022-02-17 18:02:52 +01:00
Wim Taymans
3c3d9a6b09 proxy: don't emit warnings for leaked listeners
It's too dangerous, they might point to freed or invalid memory.
2022-02-17 18:01:35 +01:00
Wim Taymans
1ca5bc6b94 pulse-server: do a roundtrip before replying to PLAY_SAMPLE
So that we can map the stream id to the sink_index.

Fixes #2142
2022-02-17 16:57:02 +01:00
Wim Taymans
7ddcc91461 pulse-server: add operation with custom callback
Add an operation with a custom callback when the roundtrip completed.
2022-02-17 16:56:21 +01:00
Wim Taymans
ae14ef7a49 fix compilation 2022-02-17 16:11:22 +01:00
Wim Taymans
d2f8cd2114 pulse-server: relax some warnings
Don't emit warnings for EPIPE and ECONNRESET when received from
recv. Some apps just disconnect violently.

Fixes #2141
2022-02-17 16:03:55 +01:00
Wim Taymans
c5c9ecdd87 spa: improve the AEC interface
Place the methods on the interface so that we can call them.
Rename create to init because that is what it does.
Add support for listener and events so that we can signal property
changes later.
2022-02-16 16:18:18 +01:00
Joakim Olsson
9386c70b3a module-echo-cancel: Move backends to dynamic libaries
Move all backends to dynamic libaries loaded with spa_plugin_loader so
new backends not needs changes in pipewire or pipewire dependency to
external code

Change-Id: I702ce047598d0c318d6dc6ac8248062a5c12f643
2022-02-15 15:45:46 +00:00
Barnabás Pőcze
762a523098 pipewire: conf: initialize return value
In some cases it is possible for `pw_context_conf_section_for_each()`
to not set `res` at all, which leads to an indeterminate value being returned.

Fix that by setting `res` to 0 initially.
2022-02-15 10:06:26 +01:00
Pauli Virtanen
2e3c749a01 pulse-server/combine-sink: mark loaded after streams appear
module-combine-sink should become loaded only after its input stream,
and all explicitly specified output sink stream nodes appear.  Since
output sinks may appear on the manager after a delay, wait for them only
up to a timeout, and fail load after that.

Fail load if there are errors in input stream, or in an explicitly
specified output.

This is needed for Zoom sound sharing to work. Pulseaudio additionally
fails the module load if streams fail to connect, but we do not do that
here at the moment.
2022-02-15 06:28:54 +00:00
Pauli Virtanen
77e50d2dfe pulse-server: sync manager before module unload completion
Operations sync manager, so use that.

On Pulseaudio, module unload is async procedure. However, this race
condition may be hard to hit in practice, whereas on pipewire-pulse it's
not hard. E.g. Zoom appears to assume that modules are unloaded
synchronously.
2022-02-15 06:28:54 +00:00
Pauli Virtanen
e737e14e8b pulse-server: sync client manager before returning from LOAD_MODULE
Sync client's manager, before returning from module load, also for async
module loads.  This is because the module load may have its own core, so
even though it has made changes on server, the client manager might not
see them yet.

Fix this by syncing client->manager before operation return.
2022-02-15 06:28:54 +00:00
Wim Taymans
fa484f346e raop-sink: use default latency of 2 seconds
See #2131
2022-02-13 18:41:01 +01:00
Pauli Virtanen
01a83a1362 pulse-server: make some modules load-once
Add mechanism for allowing some modules to be loaded only once.

Mark always-sink, raop-discover, switch-on-connect, zeroconf-discover as
such.
2022-02-13 17:50:54 +02:00
Pauli Virtanen
f5d47c079e conf: fix fork/execvp/waitpid usage
In context.exec after forking, if execvp returns we have to exit since
we're in the child process.

To avoid zombies, either SIGCHLD need to be handled/ignored, or
double-fork to create orphan processes. This is in library code, so it
seems best to just double-fork.
2022-02-13 16:48:26 +02:00
Pauli Virtanen
0b40d36a14 pulse-server: load module-always-sink on startup
Load fallback sink on startup as a Pulseaudio module, so that it is
easier to disable when necessary.
2022-02-13 14:17:48 +02:00
Pauli Virtanen
04cff777af pulse-server: add module-always-sink
It just loads/unloads libpipewire-module-fallback-sink.
2022-02-13 13:45:17 +02:00
Pauli Virtanen
8e63aa3d10 pulse-server: fix some error checks in modules
These should check if the previous pw_manager_new failed.
2022-02-13 13:40:31 +02:00
Pauli Virtanen
02e6f9fbca module-fallback-sink: add dynamically appearing fallback sink
Add a module for a fallback dummy sink, which appears dynamically when
no other sinks are present.

Enable it for pipewire-pulse, because Pulseaudio will also show
dynamically a dummy sink.
2022-02-13 09:54:55 +00:00
Wim Taymans
a6035dc4c0 pulse-server: convert node id to index in sample reply
See #2129
2022-02-13 09:56:43 +01:00
Wim Taymans
db6b7f6848 profiler: add force rate and quantum to latency
Overrite the node.latency with their forced values when available.

This will show the forced values in pw-top
2022-02-11 12:24:16 +01:00
Wim Taymans
613c0a2558 proxy: emit a warning when listener was not removed
Emit a warning when the listener was not removed now that most places
are fixed. Not removing a listener might fail to call the removed
callback and leave things in a broken state.
2022-02-09 16:34:06 +01:00
Wim Taymans
e82f775fb3 tools: remove listeners 2022-02-09 16:30:13 +01:00
Wim Taymans
cd361cb1b3 client-node: remove MAX_MIX limit
There is no limit anymore
2022-02-09 16:12:17 +01:00
Wim Taymans
f1788d0552 filter: remove unused define for MAX_PORTS 2022-02-09 16:10:32 +01:00
Wim Taymans
4e1e9aa8e7 filter: remove port limit
Use a map to allocate and keep track of port numbers.
2022-02-09 16:04:57 +01:00
Wim Taymans
f743aecd23 map: scale extend with the item size as well 2022-02-09 15:17:37 +01:00
Wim Taymans
9bebad6ed3 client-node: remove limit on ports
Use a pw_map to keep track of the ports by index so that we don't
have an upper limit on the node ports anymore.
2022-02-09 15:11:47 +01:00
Wim Taymans
d0d924c33c client-node: improve port handling
Index the ports by using the direction and port id instead of doing
conditional lookups in 2 arrays.
2022-02-09 12:41:49 +01:00
Wim Taymans
3db14600b2 remove some listeners 2022-02-09 12:33:52 +01:00