Commit graph

5335 commits

Author SHA1 Message Date
Wim Taymans
83588daf60 adapter: support control ports in PortConfig 2022-06-17 12:49:33 +02:00
Wim Taymans
16a7c27498 settings: remove 44.1KHz from allowed rates again
It seems to cause too many problems. It people want rate switching they
can add an override themselves.
2022-06-17 09:02:13 +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
Jonas Holmberg
671fc51d27 pw-cli: Work without readline too
Build and install pw-cli using getline() (standardized in POSIX.1-2008)
if readline is not found.
2022-06-15 16:37:01 +02:00
Wim Taymans
b9fa0e6f28 pw-cat: also set rate/latency for pipe
Move the latency and rate properties to a separate function so that
we can call it in all cases and not just for sndfile io.
Simplify format handling.
2022-06-15 12:35:56 +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
Jonas Holmberg
aa3aa6bb05 stream: Fix memory leak
Cleanup controls instead of inserting new elements with id 0 into the
controls list every time there is an unsupported or invalid PropInfo in
an info_changed node event.
2022-06-10 11:50:40 +02:00
Wim Taymans
9255cfbd7c pw-cli: add -m option
To keep the mainloop running and keep the process (and objects) alive.
Interesting when doing pw-cli load-module libpipewire-module-loopback.
2022-06-09 17:24:13 +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
Wim Taymans
47e1f38f03 pw-dump: also dump object removal
When in monitor mode, also dump object removal with info/props as
NULL.

Fixes #2426
2022-06-08 16:24:22 +02:00
Wim Taymans
5b23adbb65 examples: fix modifier handling
Use a preallocated array of modifiers instead of using a dynamically
allocated one that is too small.
2022-06-08 15:13:03 +02:00
Aleix Pol
04b579f5f3 video-play-fixate: Address initialising modifiers
We were writing twice in the same space, leaving another one undefined.
2022-06-08 11:24:52 +00: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
6c310cf5e2 gst: add client-properties
To update the client properties of the connection.

Fixes #1573
2022-06-03 13:00:52 +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
774ade1467 stream: improve docs about direction 2022-06-02 13:06:03 +02:00
Wim Taymans
2c4d36e4d0 pulse-server: always send frame_size multiples of samples.
See #2421
2022-06-02 09:05:23 +02:00
James Hilliard
64e8dee3a7 gst: dup buffer file descriptor before allocating
Since gst_fd_allocator_alloc lazy mmap's the buffer to the assigned
file descriptor we can get downstream mmap failures if the pipewire
src(such as the v4l2 spa plugin) closes the file descriptor before
it gets mmap'd. To prevent the closed original file descriptor from
causing a mmap failure dup the file descriptor so that the original
being closed doesn't invalidate the descriptor passed to
gst_fd_allocator_alloc.

Add some more validation to dequeue_buffer as well.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
2022-06-02 06:44:10 +00: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
James Hilliard
a1f33a99df gst: dequeue a shared buffer instead of original pool buffer
This seems to prevent the pool buffer from getting corrupted.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
2022-06-01 04:09:59 -06:00
James Hilliard
7305d38b85 gstpipewiresrc: don't mix tabs and spaces
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
2022-05-31 02:46:27 -06:00
George Kiagiadakis
b8bb7ce9da impl-port: set port.alias if not already set
This makes the video nodes have meaningful aliases on their ports,
which make them look nicer in user-facing tools like wpctl and qpwgraph.
2022-05-31 11:17:56 +03:00
James Hilliard
7cc509b117 buffers: ensure buffer size does not exceed maxsize
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
2022-05-31 07:25:31 +00:00
George Kiagiadakis
bf0ff347c1 pipewiresink: trigger process() manually when in driver mode
When in driver mode (mode=provide), the process() function is never
called. It needs to be triggered manually every now and then.

This fixes starting a mode=provide sink, but it doesn't fix re-starting
it... if the client disconnects while streaming, all buffers are getting
filled up and the pool blocks in aqcuiring one more; when the client
connects again, even if we signal the cond to unblock the pool, it still
can't acquire any more buffers and deadlocks.

Relates to: #1980
2022-05-31 07:24:41 +00:00
Wim Taymans
b6aeb1310c impl-port: pass the right param 2022-05-30 10:54:32 +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
3e7f975f83 utils: fix reallocarray macro 2022-05-27 16:06:41 +02:00