Commit graph

7243 commits

Author SHA1 Message Date
Wim Taymans
c4244a6cf3 string: use spa_strbuf instead of snprintf magic 2025-10-24 17:00:11 +02:00
Wim Taymans
d18670d7bb pw-cat: improve channel checks
Make sure we don't use too many channels.
2025-10-24 10:42:05 +02:00
Wim Taymans
aa0272f6f3 treewide: remove some obsolete channel checks
The spa_audio_info can not be parsed with too many channels so there
is always enough space for the positions.
2025-10-24 10:31:45 +02:00
Wim Taymans
78219471ff spa: remove some obsolete functions
The spa_audio_info array now always holds enough positions for all
channels and we don't need to wrap around.
2025-10-24 09:35:59 +02:00
Wim Taymans
5e1e3fca1e modules: handle format parsing errors 2025-10-23 18:01:35 +02:00
Wim Taymans
11f1298f53 spa: make a function to make a channel short name
Make a function that can generate and parse a short name for
the positions that are not in the type list, like the AUX channels.
2025-10-22 13:04:53 +02:00
Wim Taymans
dbc5c81e4a spa: avoid using SPA_AUDIO_MAX_CHANNELS
Use SPA_N_ELEMENTS instead of the array we try to handle.
2025-10-21 16:05:33 +02:00
Wim Taymans
818d1435ce treewide: access the position information using helpers
Make sure we don't access out of bounds and that we use the helpers
wherever we can to access the position information.
2025-10-21 13:06:25 +02:00
Wim Taymans
8bbca3b8f3 spa: add spa_audio_parse_position_n
Add a function that accepts the size of the position array when reading
the audio positions. This makes it possible to decouple the position
array size from SPA_AUDIO_MAX_CHANNELS.

Also use SPA_N_ELEMENTS to pass the number of array elements to
functions instead of a fixed constant. This makes it easier to change
the array size later to a different constant without having to patch up
all the places where the size is used.
2025-10-21 09:59:13 +02:00
Wim Taymans
13b8c23767 Don't use SPA_AUDIO_MAX_CHANNELS directly
Make a MAX_CHANNELS define and use that one in code. This makes it
easier to change the constant later.
2025-10-21 09:43:06 +02:00
Wim Taymans
f453b1545d audio: don't use SPA_AUDIO_MAX_CHANNELS in some places
When we know the max size of the array, just use this instead of the
SPA_AUDIO_MAX_CHANNELS constant.
2025-10-20 18:31:17 +02:00
Wim Taymans
fb49759d1f module-echo-cancel: drop samples when source not ready
When we can't dequeue a buffer from the source stream, drop the samples
instead of leaving them queued in the ringbuffer.
2025-10-17 14:51:14 +02:00
Wim Taymans
a75cea96fb modules: port modules to timer-queue
Instead of using timerfd, use the context timer-queue to schedule
timeouts. This saves fds and removes some redundant code.

Make the rtp-source timeout and standby code a bit better by using
atomic operations.
2025-10-15 16:57:24 +02:00
Wim Taymans
b220f85790 module-rtp-sap: reorganize generation of SDP
Move the code to recalculate the hash and version into make_sdp. Add a
boolean argument to the make_sdp function. Recalculate the hash and
version when we are making a new SDP and leave the old values if we
are making an SDP to compare against the current one.
2025-10-15 14:08:24 +02:00
Wim Taymans
c40e0d1d98 module-rtp: unset ptp_fd or else we might close it 2025-10-15 14:05:29 +02:00
Wim Taymans
f91aed5eeb impl-link: pass error codes in link error state
Pass the error code when setting the link in the error state.

Add some more debug.
2025-10-15 11:20:01 +02:00
Wim Taymans
9b507d3210 context: add support for rlimit.<resource> = <value>
Add support for rlimit.<resource> = <value> in the context.properties to
adjust the rlimits of the process. A value of -1 sets the max limit.

This can be used to increase the number of file descriptors in a
pipewire process when select() is not used, for example. Other resource
limits might be interesting as well maybe.

Fixes #4047
2025-10-15 09:26:36 +02:00
Wim Taymans
9f2d873760 examples: set exclusive and reliable flags
We need exclusive port use if we negotiated SyncTimeline because there
can only be one consumer of the syncobj.

We also need to enable reliable transport if synctimeline is supported
but the release flag isn't.

Add some more logging to the port when the exclusive and reliable states
changed.

Fixes #4885
2025-10-14 11:56:22 +02:00
Wim Taymans
20d2a331be impl-node: add a NODE_RELIABLE property
Add a PW_KEY_NODE_RELIABLE and PW_KEY_PORT_RELIABLE property. the port
property value is inherited from the parent when not explicitly set.

Setting the property on a port will activate a more reliable tee, that
actually only recycles buffers that were consumed. It will also activate
a mode in stream that gives out new buffers only when the previous one
was recycled and nothing else is queued. This is necessary to avoid
queuing in the stream when the other side is not consuming.

When a link is async but the output node is a driver of the input, we
can avoid async io. This also removes a potential out-of-order buffer
recycling when the node resumes at a different cycle.

See #4885
2025-10-14 11:55:25 +02:00
Wim Taymans
d268b6e104 examples: add some options to enable features 2025-10-10 10:41:53 +02:00
Wim Taymans
4fb0a0aeea example: add sync timeline example
Add an example producer and consumer using the SyncTimeline metadata.
The syncobj are just eventfd for the purpose of the example.

Also demonstrate the RELEASE feature when negotiated.

Add some switches to tweak the SyncTimeline and features support.

See #4885
2025-10-08 12:53:30 +02:00
Wim Taymans
7d781e696f profiler: avoid null dereference
Avoid shadowing some variables from the parent block.

The node of a target can be NULL when the target is running in another
instance. We already do some checks for this but make sure we never
deref the NULL pointer.

Fixes #4922
2025-10-06 14:38:38 +02:00
Barnabás Pőcze
e72962fb42 pw-cat: do not use deprecated FF_PROFILE_*
These macros were deprecated in 2023[0], and are absent in the latest
ffmpeg 8.0[1]. So use the new names.

[0]: 8238bc0b5e
[1]: 8224327698
2025-10-06 12:10:23 +00:00
Wim Taymans
e9aef9196f examples: add example MemFd sink
Add an example of a filter sink that requires MemFd memory on the
input port. Show that it gets automatically mapped and that it contains
MemFd memory.

Fixes #4918
2025-10-06 13:37:59 +02:00
Wim Taymans
5ccaf29793 stream: only mmap buffers when not already mapped
Don't just blindly mmap the buffer but only when the data pointer
is NULL. If it was mapped already by the peer or the adapter or the
buffer allocation, we don't want to mmap it again and override the buffer
data pointer.

Also mmap with the permissions on the data. There is not much point in
limiting the permissions for an input port (to read only). We could do
this but then we would not be allowed to modify the existing data
pointer. The problem is that when the stream mmaps the data as READ only
and set the data pointer, if it is then handed to the mixer, it would
assume it is mapped with the permissions and then segfault when it
tries to write to the memory. It's just better to only mmap when the
data is NULL.
2025-10-06 13:17:00 +02:00
Wim Taymans
e7bc261830 filter: don't lock the Buffers param
It should be possible to override the Buffers params in the filter.
2025-10-06 13:16:32 +02:00
Wim Taymans
984b2d296e context: only make active nodes runnable
Only try to make active nodes runnable. This can happen when the node is
destroyed.

Avoids a -EIO error when destroying nodes from pavucontrol.
2025-10-06 11:48:40 +02:00
Wim Taymans
b66d49702f examples: avoid mmap in the example
We don't need to do this ourselves, the MAP_BUFFERS port flag already
makes sure this is done for use.

We used to have to do this here to ensure the mixer could find the data
pointer and not error out. Now that the mixer can MMAP, this can go.

See #4918
2025-10-06 11:17:08 +02:00
Wim Taymans
af3ad7bf9f buffers: improve allocation
There are really 2 options for the buffer allocation:

1. allocate the buffers skeleton and meta/chunk/data in malloc memory.
   This is when the PW_BUFFERS_FLAG_SHARED is unset.
2. allocate buffers skeleton in alloc memory and the meta/chunk/data
   in shared memory when the PW_BUFFERS_FLAG_SHARED is set.

Optionally the data can be left unallocated in both cases when the
PW_BUFFERS_FLAG_NO_MEM is set. In this case we also need to pass the
SPA_BUFFER_ALLOC_FLAG_NO_DATA flag to allocator or else it will set the
data pointers to 0 sized memory in the skeleton.

If we use SHARED and we allocated memory, we can also set the MemFd and
mapoffset into our shared mem. We can do this even if the data_type is
MemPtr.

We can decide on the datatype to use earlier, based on the negotiated
flags. In the MemFd case, make sure the buffer data is page aligned in
that case to make things easier. Also force everything in SHARED mem
when the data is in SHARED mem. We also don't need to
PW_BUFFERS_FLAG_SHARED_MEM because we work with the negotiated flags
now to decide if SHARED mem is needed or not.

With this change, a node port could provide a MemFd data_type mask in
the Buffers param and this would negotiate shared mem with the mixer.
Previously, it would only ever allocate malloc memory.

See #4918
2025-10-06 10:58:19 +02:00
Wim Taymans
1a54b9e66f impl-port: handle errors from the mixer use_buffers
Also handle errors when we fail to set mixer buffers on the output port
of the mixer.
2025-10-06 10:38:08 +02:00
Wim Taymans
fe78e80614 tools: fix compilation after removal of field 2025-10-02 16:39:18 +02:00
Wim Taymans
0b0226322f examples: add DSP sink example
Add example of ALLOC_BUFFERS on the input port.

See #4918
2025-10-02 16:26:27 +02:00
Wim Taymans
4161fa3071 impl-port: also honour CAN_ALLOC flag between mixer/node
When we have a mixer node and we need to negotiate buffers between the
mixer and the node, take the CAN_ALLOC flag into account.

This is for input ports, which can have a mixer. If you make a filter
with a CAN_ALLOC input port, it will now not already contain buffer
data.

See #4918
2025-10-02 16:26:27 +02:00
Wim Taymans
1fdde582c0 buffers: add some more comments to the flags 2025-10-02 16:26:27 +02:00
Wim Taymans
91ae1c13b7 impl-port: only use DYNAMIC_DATA when allowed
Allocate buffers with the DYNAMIC_DATA flag set only when the port
actually allows it.

See #4918
2025-10-01 11:11:36 +02:00
Niklas Carlsson
3f9ae1ee10 filter-graph: allow 8 channels in max plugin
Mimic the same channel behavior as for other plugins that allows
for 8 channels, such as Mixer and Mult.
2025-09-29 14:11:27 +00:00
Wim Taymans
3cf182255f context: handle leaf nodes better
Find leaf nodes by looking at the number of max in/out ports and the
link group. This should give us nodes that only consume/produce data.

If a leaf node is linked to a driver with only passive links, it will
never be able to be scheduled unless we also make it runnable when the
driver is made runnable from another node.

This can happen when you do:

pw-record -P '{ node.passive=true }' test.wav

and then

pw-record test2.wav

Without this, the first pw-record would never be scheduled. With the
patch it will be scheduled when the second pw-record is started.

Fixes #4915
2025-09-29 14:38:19 +02:00
Wim Taymans
468a9ac954 pulse-server: add the peer ip to client properties
When clients connect with IP, add the peer IP address to properties. We
might use this later to make a better stream node.name than a copy of the
client application name.
2025-09-29 09:39:57 +02:00
Wim Taymans
fdc74df383 modules: use timer-queue in avahi-poll
Pass the pw_context to get to the shared queue and loop.
Patch up the users of avahi-poll.

Fixes #4913
2025-09-26 13:39:49 +02:00
Wim Taymans
678e571d80 timer-queue: delete next timer event when it got fired
When we fire the timer event, mark the next timeout as NULL because
nothing else is going to timeout anymore until we rearm the timer.

This has the effect that if we cancel and add the same timer from the
callback that we will reprogram the timer with the new timeout instead
of thinking the item as already programmed.
2025-09-26 13:02:53 +02:00
Wim Taymans
9be06c46b7 pulse-server: fix case statement 2025-09-26 11:43:52 +02:00
Wim Taymans
17cad8e7ef pulse-server: add a help message
Shows all available messages on /core because I keep forgetting.
2025-09-26 10:57:04 +02:00
Wim Taymans
5a894270e6 pulse-server: add a pipewire-pulse:list-modules message
It list all available module names, which you can then describe further.
Make a little module_info iterator function for this.
2025-09-26 10:55:10 +02:00
Wim Taymans
ecac86b0ca avahi: handle fd allocation errors
When we fail to allocate an io source or a timerfd, return NULL instead
of crashing later on.

See #4913
2025-09-26 10:52:40 +02:00
Wim Taymans
06214b6087 pulse-server: map some more errno to errors
Mostly EADDRINUSE to ERR_BUSY, which happens when loading TCP when
it's already loaded on the address.
2025-09-26 10:50:52 +02:00
Wim Taymans
19198d2982 pw-cat: fix DSD file reading
Now that the server asks for the right amount of samples for DSD, just
give it the right amount of samples without doing some weird scaling.

Make a method to calculate the size (stride) of one sample, which
depends on the interleave and channels of the stream.

See !2540
2025-09-25 13:56:51 +02:00
Carlos Rafael Giani
65e49b38d1 module-rtp: Add process.latency.from.sess prop to set process latency 2025-09-24 22:54:06 +02:00
Carlos Rafael Giani
63df661eff module-rtp: Handle Latency and ProcessLatency in stream 2025-09-24 22:54:06 +02:00
Wim Taymans
3c921acb48 impl-port: rework port properties
Don't update info.props all the time, just once when we create the
properties, the dict will not change after that.

Move the port property check code to a new function. Keep track if we
auto generated path, name or alias and if we explicitly update it or
not.

Listen for node property changes and update the port properties if
necessary. Some of the port properties or feature depend on the node
properties so we want to keep those in sync.
2025-09-22 14:30:09 +02:00
Wim Taymans
6bc451cf6d timer: fix compilation on arm 2025-09-19 16:16:25 +02:00