Commit graph

2128 commits

Author SHA1 Message Date
Wim Taymans
ff05ebada6 pulse-server: tweak record attributes
Add some 'before' debug info of the attributes.
First clamp the fragsize to the maxlength and then clamp to the
minfrag or else we could bypass the configured minfrag by setting a
lower maxlength.
Scale the maxlength to at least twice the fragsize so that we can
buffer enough data in the ringbuffer to serve fragsize bytes.

See #2447
2022-06-20 11:42:59 +02:00
Lucas Holt
6a15a02ec2 Add support for MidnightBSD
Fix build issue

Fix build issue
2022-06-19 18:22:47 +00:00
Wim Taymans
6b09a304dc adapter: name control ports as "control" 2022-06-17 15:40:56 +02:00
Wim Taymans
83588daf60 adapter: support control ports in PortConfig 2022-06-17 12:49:33 +02:00
Barnabás Pőcze
ae34b68e3a pulse-server: message: improve resizing logic
As Coverity points out, `ensure_size()` is not fully correct.

Let us assume that the message already has some allocated storage,
and the `realloc()` call in the next `ensure_size()` invocation fails.
In that case `message::data` is freed, but the pointer is left behind.
If another `ensure_size()` call is made, then `realloc()` will be called
(since the previous call left `message::allocated` as zero), but the
first argument of the `realloc()` call will be a dangling pointer.

In order to avoid the above, first of all, clear `message::data` after
a failed `realloc()` call, and immediately return `-ENOMEM` if
`message::length` is greater than `message::allocated` since
that signals if the message has even run into an out-of-memory
situation.
2022-06-16 18:38:30 +00:00
Barnabás Pőcze
080a97c0bb pulse-server: message: store pointer to impl directly
Store a pointer to the owner `impl` object instead of
the (embedded) `stat` object. This way `message_free()`
can be simplified since the owner `impl` does not need
to be passed explicitly.
2022-06-16 18:38:30 +00:00
Barnabás Pőcze
b843b0ab29 pulse-server: message: remove unnecessary forward declaration
`struct client` is never referenced in "message.h",
so remove the forward declaration for it.
2022-06-16 18:38:30 +00:00
Barnabás Pőcze
bc67745c07 pipewire: module-raop-sink: fix memory leak
As Coverity points out, previously, when the `else`
branch was taken, then `tokens` was not freed.
2022-06-16 18:57:38 +02:00
Barnabás Pőcze
84c01bb0bc pipewire: module-pipe-tunnel: accept file descriptor 0
As Coverity points out, `open()` returning 0 is not an error,
it should be handled just like any other valid file descriptor.
2022-06-16 17:55:59 +02:00
Wim Taymans
68bafcf166 pulse-server: Don't send more than fragsize chunks
Send exactly fragsize chunks when capturing.

See #2418 and #2434
2022-06-14 11:20:18 +02:00
Wim Taymans
c1a61a7941 pulse-server: only append .monitor for capture streams 2022-06-13 20:12:10 +02:00
Wim Taymans
f88134232d pulse-server: fix name when moved to monitor
When a stream is moved to a monitor, make sure we append the .monitor
suffix to the node name.

Fixes #2440
2022-06-13 19:54:35 +02:00
Wim Taymans
4821c7ca2f pulse-server: don't append "/pulse" to PULSE_RUNTIME_PATH
Fixes #2431
2022-06-09 17:06:07 +02:00
Barnabás Pőcze
c8c2526f87 pulse-server: destroy modules first
The `impl::servers` list contains all servers, and they are all
destroyed in `impl_clear()`. However, by that time, modules were
not freed previously, so if there were any instances of
*module-protocol-native-tcp* loaded, then the unload() method
of those would call `server_free()` on already freed servers,
resulting in use-after-frees. Fix that by unloading modules
before destroying the servers.

==451490==ERROR: AddressSanitizer: heap-use-after-free on address 0x612000006050 ...
READ of size 8 at 0x612000006050 thread T0
    #0 0x7f45edb19a0c in server_free ../src/modules/module-protocol-pulse/server.c:1022
    #1 0x7f45edb46c7d in module_native_protocol_tcp_unload ../src/modules/module-protocol-pulse/modules/module-native-protocol-tcp.c:66
    #2 0x7f45eda893c7 in module_unload ../src/modules/module-protocol-pulse/module.c:128
    #3 0x7f45edaf7269 in impl_unload_module ../src/modules/module-protocol-pulse/pulse-server.c:5336
    #4 0x7f45edaa1583 in pw_map_for_each ../src/pipewire/map.h:238
    #5 0x7f45edaf79c5 in impl_clear ../src/modules/module-protocol-pulse/pulse-server.c:5358
    ...

0x612000006050 is located 16 bytes inside of 264-byte region [0x612000006040,0x612000006148)
freed by thread T0 here:
    #0 0x7f45f30be672 in __interceptor_free /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:52
    #1 0x7f45edb1a48a in server_free ../src/modules/module-protocol-pulse/server.c:1040
    #2 0x7f45edaf730b in impl_clear ../src/modules/module-protocol-pulse/pulse-server.c:5347
    ...

Fixes: f181210b29 ("pulse-server: properly unload modules")
2022-06-09 03:02:06 +02:00
Barnabás Pőcze
c248091528 pulse-server: module-switch-on-connect: remove dead code and one allocation
As Coverity correctly points out, the `if (blocklist)` condition
is never true after the `out` label, so this commit makes some
changes to remove the dead code.

First of all, the `regex_t` object is directly embedded in the
module's data struct, so the `malloc()` call can be removed,
and thus there is no need for the cleanup code anymore, so everything
after the `out` label is also removed.

Furthermore, two NULL checks are removed which check `d->blocklist`
from `module_switch_on_connect_unload()` and `manager_added()`
because both of those functions can only ever run if the `d->blocklist`
regex object has been successfully initialized in `module_switch_on_connect_prepare()`.
Those checks were not strictly needed to begin with.
2022-06-05 18:04:03 +00:00
Wim Taymans
a84412ccb7 modules: improve parsing of rate and channels 2022-06-04 18:54:50 +02:00
Wim Taymans
0f839c7b61 modules: clamp input offset and size
So that we don't cause memory errors with invalid input.
2022-06-04 11:47:48 +02:00
Wim Taymans
24ba3f4d92 module-roc: improve sender loop
FIxes #2422
2022-06-04 10:57:20 +02:00
Barnabás Pőcze
876a5977f3 pulse-server: module-pipe-{sink,source}: drop redundant log messages
It is already logged by the module loading code when a module is
successfully loaded, so there is no need to print it on a per-module
basis at the same log level.
2022-06-03 17:24:27 +02:00
Wim Taymans
efe30d5075 pulse-server: send STREAM_MOVED messages
Keep track of the last known peer of a stream and send a moved message
when it changes.

Fixes #2407
2022-06-03 16:59:08 +02:00
Wim Taymans
be9c738661 pulse-server: keep stream latency around 2022-06-03 16:58:37 +02:00
Wim Taymans
1252927d73 pulse-server: check all pending streams
Check all pending streams to see if the new link completes their
creation.

It is possible that the link linked 2 pending streams and then we
want to complete them both.
2022-06-03 15:50:54 +02:00
Wim Taymans
258a203d74 pulse-server: optimize link finding
When we get a new link object, only check if a pending stream is linked
according to the new link instead of iterating all links.
2022-06-03 15:48:08 +02:00
Wim Taymans
6276253c30 pulse-server: implement pipe sink/source with module 2022-06-03 11:51:29 +02:00
Wim Taymans
87172fde06 modules: align tunnel.mode
Source for a source, sink for a sink. We use capture and playback for
streams that link to a source/sink respectively.
2022-06-03 10:52:45 +02:00
Wim Taymans
fe1652e843 modules: add more docs and options to pipe-tunnel 2022-06-03 10:52:45 +02:00
Wim Taymans
af41d45e1a modules: add pipe tunnel 2022-06-03 10:52:45 +02:00
Barnabás Pőcze
f1b0cfd546 pulse-server: mark module_*_prepare() methods static
Since 37fa911a72 ("pulse-server: module: rework registry") none
of the module methods need to have external linkage.
2022-06-02 23:56:55 +02:00
Barnabás Pőcze
75d28cadcd pulse-server: rename module_info::prepare() to create()
Now that the method does not actually create the `module` object,
it would be somewhat misleading to call it "create",
so rename it to "prepare".
2022-06-02 23:56:55 +02:00
Barnabás Pőcze
fa3a28ab68 pulse-server: pass already created module object to module_info::create()
All modules need to manually create a `module` object and check
if it was successfully created. The same with argument parsing.
To simplify modules, move the module object creation and argument
parsing into `module_create()`, and pass the already initialized
module to `module_info::create()`.

The semantics of `module_info::create()` are kept, that is,
if it fails, `module_info::unload()` will not be called.
2022-06-02 23:56:55 +02:00
Barnabás Pőcze
5ad52bb88a pulse-server: do not put static properties into module::props
Now that the module's properties are served from `module_info::properties`,
there is no need for modules to put their static properties into
the `module::props` dictionary.
2022-06-02 23:56:50 +02:00
Barnabás Pőcze
c9f632da9f pulse-server: serve module properties from static list
None of the modules really need a dynamic property list,
so serve the properties from a static list.
2022-06-02 15:17:45 +02:00
Wim Taymans
2c4d36e4d0 pulse-server: always send frame_size multiples of samples.
See #2421
2022-06-02 09:05:23 +02:00
Wim Taymans
0d51f3b74e pulse-server: always send at least fragsize data
Make sure to never send less than the negotiated fragsize to a client.
Also make sure we don't send too much data in one go. This is more in
line with what pulseaudio does.

Fixes capture from multiple tabs in chrome.

Fixes #2418
2022-06-01 15:43:07 +02:00
Fabrice Fontaine
85ca67b927 fix detection of reallocarray
Fix detection of reallocarray (e.g. on glibc) raised since commit
0708a39b43

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2022-05-30 09:33:27 +02:00
Wim Taymans
57e732cd27 pulse-server: use 8 channels internally for TrueHD and DTSHD
So that the stride is what the server side expects.

See #2284
2022-05-23 18:54:18 +02:00
Barnabás Pőcze
893567bed6 pulse-server: module-x11-bell: initialize module member
Previously, `module_x11_bell_data::module` was not initialized
properly, which led to a NULL pointer dereference in
`module_schedule_unload()` when called from `module_destroy()`
in case the native pipewire module was unloaded.

See #2392
2022-05-21 18:45:25 +02:00
Wim Taymans
b81b7febee pulse-server: don't export NETWORK nodes
Don't export network nodes with zeroconf.

Fixes #2384
2022-05-18 20:40:46 +02:00
Wim Taymans
05deba85a4 pulse-server: reset message length when freeing
When we move a message to the free list, reset the length to 0.
Otherwise the previous length plus the new length will be used to
allocated the message size, which would overallocate.
2022-05-18 17:31:23 +02:00
Barnabás Pőcze
970b5906a8 pipewire: module-spa-node-factory: remove resource listener when node is destroyed
Previously, the resource listener was not removed when
the `node_data` object was freed, which could lead to
a use-after-free when the resource emitted an event
later.

==2787072==ERROR: AddressSanitizer: heap-use-after-free on address 0x61d000016728 at pc 0x7ffff7175b52 bp 0x7fffffffb930 sp 0x7fffffffb920
WRITE of size 8 at 0x61d000016728 thread T0
    #0 0x7ffff7175b51 in spa_list_remove ../spa/include/spa/utils/list.h:77
    #1 0x7ffff717cb5a in pw_resource_destroy ../src/pipewire/resource.c:335
    #2 0x7ffff7051c56 in pw_global_destroy ../src/pipewire/global.c:417
    #3 0x7ffff6f82a68 in registry_destroy ../src/pipewire/impl-core.c:130
    #4 0x7ffff3a5f349 in registry_demarshal_destroy ../src/modules/module-protocol-native/protocol-native.c:784
    #5 0x7ffff3a2c9ed in process_messages ../src/modules/module-protocol-native.c:352
    #6 0x7ffff3a2e2ea in connection_data ../src/modules/module-protocol-native.c:423
    #7 0x7ffff3e09402 in source_io_func ../spa/plugins/support/loop.c:427
    #8 0x7ffff3e0851d in loop_iterate ../spa/plugins/support/loop.c:409
    #9 0x7ffff709c21d in pw_main_loop_run ../src/pipewire/main-loop.c:148
    #10 0x555555559722 in main ../src/daemon/pipewire.c:131
    #11 0x7ffff62a528f  (/usr/lib/libc.so.6+0x2928f)
    #12 0x7ffff62a5349 in __libc_start_main (/usr/lib/libc.so.6+0x29349)
    #13 0x5555555582a4 in _start (./src/daemon/pipewire+0x42a4)

0x61d000016728 is located 2216 bytes inside of 2264-byte region [0x61d000015e80,0x61d000016758)
freed by thread T0 here:
    #0 0x7ffff798c672 in __interceptor_free /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:52
    #1 0x7ffff70f9bc3 in pw_impl_node_destroy ../src/pipewire/impl-node.c:1880
    #2 0x7ffff70d1d57 in global_destroy ../src/pipewire/impl-node.c:638
    #3 0x7ffff7051a4f in pw_global_destroy ../src/pipewire/global.c:414
    #4 0x7ffff6f82a68 in registry_destroy ../src/pipewire/impl-core.c:130
    #5 0x7ffff3a5f349 in registry_demarshal_destroy ../src/modules/module-protocol-native/protocol-native.c:784
    #6 0x7ffff3a2c9ed in process_messages ../src/modules/module-protocol-native.c:352
    #7 0x7ffff3a2e2ea in connection_data ../src/modules/module-protocol-native.c:423
    #8 0x7ffff3e09402 in source_io_func ../spa/plugins/support/loop.c:427
    #9 0x7ffff3e0851d in loop_iterate ../spa/plugins/support/loop.c:409
    #10 0x7ffff709c21d in pw_main_loop_run ../src/pipewire/main-loop.c:148
    #11 0x555555559722 in main ../src/daemon/pipewire.c:131
    #12 0x7ffff62a528f  (/usr/lib/libc.so.6+0x2928f)

previously allocated by thread T0 here:
    #0 0x7ffff798d411 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7ffff70e5bb7 in pw_context_create_node ../src/pipewire/impl-node.c:1192
    #2 0x7ffff28c748e in pw_spa_node_new ../src/modules/spa/spa-node.c:112
    #3 0x7ffff28c9a9f in pw_spa_node_load ../src/modules/spa/spa-node.c:276
    #4 0x7ffff28c1618 in create_object ../src/modules/spa/module-node-factory.c:134
    #5 0x7ffff7106c4e in pw_impl_factory_create_object ../src/pipewire/impl-factory.c:273
    #6 0x7ffff6f86dd7 in core_create_object ../src/pipewire/impl-core.c:349
    #7 0x7ffff3a5cba9 in core_method_demarshal_create_object ../src/modules/module-protocol-native/protocol-native.c:680
    #8 0x7ffff3a2c9ed in process_messages ../src/modules/module-protocol-native.c:352
    #9 0x7ffff3a2e2ea in connection_data ../src/modules/module-protocol-native.c:423
    #10 0x7ffff3e09402 in source_io_func ../spa/plugins/support/loop.c:427
    #11 0x7ffff3e0851d in loop_iterate ../spa/plugins/support/loop.c:409
    #12 0x7ffff709c21d in pw_main_loop_run ../src/pipewire/main-loop.c:148
    #13 0x555555559722 in main ../src/daemon/pipewire.c:131
    #14 0x7ffff62a528f  (/usr/lib/libc.so.6+0x2928f)

SUMMARY: AddressSanitizer: heap-use-after-free ../spa/include/spa/utils/list.h:77 in spa_list_remove
2022-05-16 17:40:35 +00:00
Pauli Virtanen
98aa7ccff0 pulse-server: emulate synchronous MOVE_* commands
Make MOVE_SINK_INPUT/MOVE_SOURCE_OUTPUT change the linked peer
immediately in subsequent GET_SINK_INPUT_INFO/GET_SOURCE_OUTPUT_INFO
commands.  Do this by keeping track of the sink/source where the client
moved the stream to, and temporarily replying so in future GET_INFO (but
only in messages for that client).

We discard the temporary override when we either get an update event for
the stream (i.e. SM moved the stream), or a 1sec timer runs out. If the
timer runs out, we emit a sink-input/source-output change event, as in
that case what we claimed in the earlier GET_INFO messages might not be
true, so clients need to update their information.

This gets rid of race conditions where an application moves a stream,
and expects the move to be visible in future GET_INFO replies, which may
fail to happen because it takes some time for the session manager to
re-link the streams.

Fixes pasystray behavior.
2022-05-15 17:14:52 +00:00
Pauli Virtanen
83be5d866f pulse-server: implement temporary data attached to manager objects
Add functions for setting timer-based lifetimes for object data.

Having the timers in the object data themselves simplifies life cycle
management, as client/manager disconnects are handled without further
work.
2022-05-15 17:14:52 +00:00
Wim Taymans
6ad59e0117 pulse-server: parse bool using pulseaudio rules 2022-05-11 17:06:33 +02:00
Wim Taymans
1fad806b8d pulse-server: add auth-anonymous option
Add the auth-anonymous option to module-native-protocol-tcp.

It does not exactly do what pulseaudio does but it will enable
unrestricted access instead.

Fixes #1899
2022-05-11 17:01:04 +02:00
Marcin Radomski
aa33c2841c pulse-server: avoid skipping more ringbuffer data than available
This prevents the ringbuffer from advancing the read pointer more than
the size of data actually available. It prevents the "avail" value from
keeping to drop when no audio is being played by the client.

Applying this patch seems to prevent the "randomly playing music after
a couple hours of silence" issue

Fixes #2366
2022-05-11 15:34:21 +02:00
Wim Taymans
daf53b94ed adapter: pass spa_node to adapter
Make it possible to pass a spa_node as the follower of the adapter. This
avoids us having to wrap it in a pw_impl_node in order to unwrap it
again for the adapter spa_node.
2022-05-11 12:28:26 +02:00
Wim Taymans
8afe5fe0f0 filtet-chain: handle empty nodes
When there are no nodes, we can't make links. This avoids getting into
an infinite loop when trying to find ports.
2022-05-07 15:58:39 +02:00
Wim Taymans
0c8cd4ab52 filter-chain: improve filter.graph parsing
First collect all the graph objects and then parse them in the
right order. Otherwise, we might try to parse links before the nodes if
they are first in the JSON string.

Fixes #1950
2022-05-07 15:53:10 +02:00
Barnabás Pőcze
211abaef5e protocol-native: remove destroyed client from client list
When the client destroys the protocol-native module, the server
and the client are destroyed but the client is still reffed (not freed).
It will be unreffed after its messages are processed, after which point
it will be freed and removed from the server client_list that is already
destroyed.

Fix this by removing the client from the server list when it is
destroyed.

See #565
2022-05-07 14:08:55 +02:00
Wim Taymans
d506781619 pulse-server: do a guess for the latency when starting
Guess the expected latency with the stream info we have and use that as
the node.latency. This way, the graph can attempt to start with some
sort of latency setting.

After we know the exact format, we can calculate the real latency and we
will update the node latency accordingly.
2022-05-06 16:54:22 +02:00