Commit graph

49 commits

Author SHA1 Message Date
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
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
4c1be71773 modules: Propagate the combine latency
When we get latency on the combine stream, forward it to all
streams after setting the per stream compensate latency (if any).

See #4731
2025-06-12 16:36:51 +02:00
Wim Taymans
549f3fc46f module-combine: use a better empty property string
The empty string fails to parse as a properties, use "{}" instead.
2025-06-12 16:35:49 +02:00
Martin Geier
c2e539b780 module-combine-stream: flush data in paused state
When stream is paused, internal delay buffers were cleared, but some
data could stay in stream output queue. Without a flush, these data where
played in front of a new data.
Patch was inspired by 64d6ff4184 fixing the
same issue in a filter-chain module.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2025-06-10 16:28:43 +02:00
Martin Geier
ff3bc8818f module-combine-stream: update latency right before playback starts
Combine stream selects the biggest latency from all output streams and sent
the latency upstream. To select the biggest latency, each stream needs to have
the sample rate and the quantum size set.
The combine stream recalculates the latency in the latency changed callback
or during data processing.
Stream sets the sample rate and the quantum size in a copy_position call
which is normally called during processing the output data or when state
changes to streaming.
Before this change, it wasn't guarantee the copy_position was called for
each stream already and latency in the combine stream was selected from
random stream.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2025-06-10 16:28:40 +02:00
Sam James
2cec77e7df *: unify config.h handling
config.h needs to be consistently included before any standard headers
if we ever want to set feature test macros (like _GNU_SOURCE or whatever)
inside. It can lead to hard-to-debug issues without that.

It can also be problematic just for our own HAVE_* that it may define
if it's not consistently made available before our own headers. Just
always include it first, before everything.

We already did this in many files, just not consistently.
2025-05-30 10:24:13 +00:00
Wim Taymans
c45d667934 loop: spa_loop_invoke -> spa_loop_locked where possible
When we simply need to change some state for the code executed in the
loop, we can use locked() instead of invoke(). This is more efficient
and avoids some context switches in the normal case.
2025-05-30 11:59:35 +02:00
Torkel Niklasson
75566a238f modules: fix flag setup in combine-stream
When combine-stream initiation code was moved around in b46673b4, a
bitwise or of flags was accidentally dropped, and thus flags were
overwritten instead of added to.
2024-10-02 05:31:58 +00:00
Wim Taymans
e3a7035e8f spa: make helper to init spa_audio_info_raw from dict
Make a function that can initialize raw audio info from a dict and fill
in the defaults. We can use this in many of the modules when the audio
format is parsed.
2024-09-18 15:48:27 +02:00
Wim Taymans
e2991f6398 json: add helper function to parse channel positions
Use the helper instead of duplicating the same code.

Also add some helpers to parse a json array of uint32_t

Move some functions to convert between type name and id.
2024-09-18 09:54:34 +02:00
Pauli Virtanen
ec5684302c doc: in user-facing config examples, indicate which file it goes into
Add suggestions for config fragments in config file examples, as
applicable.
2024-09-16 15:51:59 +00:00
Wim Taymans
cd81b5f39a spa: add spa_json_begin_array/object and relaxed versions
Add spa_json_begin_array/object to replace
spa_json_init+spa_json_begin_array/object

This function is better because it does not waste a useless spa_json
structure as an iterator. The relaxed versions also error out when the
container is mismatched because parsing a mismatched container is not
going to give any results anyway.
2024-09-16 09:50:33 +02:00
Wim Taymans
3d34ec384b modules: remove FIXME 2024-08-26 16:29:11 +02:00
Wim Taymans
fc3d7cf7c7 modules: implement mixing in combine stream
When the combine-stream module is used as a source and the input streams
are overlapping, mix the samples instead of overwriting the previous
samples.

See #3710
2024-08-26 15:59:38 +02:00
Wim Taymans
b46673b475 modules: improve node names of combine-stream
use the "output" and "input" prefixes for output and input streams
respectively instead of always "output"
2024-08-26 15:58:18 +02:00
Diego Viola
7410755c03 Fix typos
found them with codespell.

Signed-off-by: Diego Viola <diego.viola@gmail.com>
2024-05-22 09:19:34 +02:00
lunks
4706fc8a9b combine-stream tag forward 2024-04-28 07:51:02 +00:00
Wim Taymans
c3d4abd7f1 modules: use acquire/release loop
Expose the acquire_loop/release_loop functions and use them in the
modules.

Make sure the nodes created from the module use the same data loop as
the module. We need to ensure this because otherwise, the nodes might
be scheduled on different data loops and the invoke or timer logic will
fail.
2024-04-22 16:19:02 +02:00
Pauli Virtanen
ac95f796bf combine-stream: fix latency-compensate with resample.disabled=true
When resample.disabled=true, which is now the default, Format has zero
rate, so latency buffers get zero size. The rate in this case is the
graph rate.

Fix by just using the delay in samples, as all streams must in any case
run at same rate for the combining to work.

Fixes: bff252ce60 ("combine-stream: actually make use of resample.disable")
2024-04-19 18:39:52 +03:00
Pauli Virtanen
bff252ce60 combine-stream: actually make use of resample.disable
resample.disable was made to default to true, but copying it to stream
properties was forgotten so it didn't have any effect. Make sure to copy
it.

This will also prevent different input/output streams from negotiating
to different rates, which would result to broken audio since we are just
passing sample data through.
2024-04-14 18:58:45 +03:00
Pauli Virtanen
e1849a0650 combine-stream: check module arguments for syntax errors
Refuse to create module if the arguments were not properly parsed.
2024-04-14 16:24:16 +03:00
Pauli Virtanen
fdcb02ed75 modules: add Module Name section to the module reference docs 2023-11-20 08:41:13 +00:00
Pauli Virtanen
eca773fc12 modules: strip "PipeWire Module:" from Doxygen page name
Make them appear nicer in the output.
2023-11-19 16:39:15 +00:00
George Kiagiadakis
8735d07c0a combine-stream: add support for "on-demand" streams
Instead of just following static target match rules to create output streams,
this feature allows the user to dynamically create more output streams
with custom targets using metadata.
2023-10-17 19:38:03 +03:00
Wim Taymans
d2b6a76798 modules: the combined streams are always async
We never trigger processing from their callbacks in all cases so they
need one extra buffer.
2023-10-16 10:42:39 +02:00
Wim Taymans
b094057b0b handle NULL latency param
Fixes #3504
2023-09-13 11:13:48 +02:00
Wim Taymans
8dd294bf44 conf: support ! to negate the match
So that you can do "application.name" = "!pw-cat" to match anything
that is not pw-cat and "application.name" = "!~pw-cat$".

Fixes #3460
2023-08-25 11:39:28 +02:00
Wim Taymans
39165a8471 modules: add ASYNC flag
Add ASYNC flags for the streams that don't dequeue/queue in the realtime
process function so that an extra buffer is allocated.
2023-06-27 13:11:13 +02:00
Wim Taymans
ad5ac964af module: disable resample when following graph rate
When we don't set a rate, assume both input and output streams are
following the graph rate and so disable the resampler.

This mostly works around an issue where the input and output could
negotiate to different rates in some cases. With the resampler disabled
this would still result in the same amount of samples going in as
comming out instead of a stuttering mismatch.

See #2969
2023-06-22 11:18:04 +02:00
Wim Taymans
b9789e36cd module-combine: always use last input buffer
To handle the case where buffers are queued up because a trigger didn't
complete.
2023-06-16 11:31:13 +02:00
Pauli Virtanen
2a0f1597ab module-combine-stream: fix race when destroying streams
Use separate flag for indicating if pw_stream_destroy is needed.

Don't set s->stream = NULL to indicate that, it will race with data
loop. Setting to null separately is not needed, removing from the stream
list is enough.
2023-05-06 07:24:31 +00:00
Pauli Virtanen
cc5da73665 module-combine-stream: add option to add delays for latency compensation
Add combine.latency-compensate option, which uses delay buffers to
compensate for different latencies in the target streams.
2023-05-03 11:22:01 +00:00
Pauli Virtanen
7d4491ce6b module-combine-stream: add latencyOffsetNsec prop
Add latencyOffsetNsec prop to the combine node.

This is mainly useful for BAP device sets; the property appears in
Pulseaudio UI only when the node is associated with a device.
2023-05-02 13:43:56 +00:00
Pauli Virtanen
a6481c48aa module-combine-stream: propagate latency
Propagate latency information from the target streams to the combine
stream.
2023-04-30 19:02:52 +00:00
Wim Taymans
d78bea5e32 module-combine-stream: improve docs 2023-03-23 11:47:27 +01:00
Wim Taymans
07e6f44e58 modules: clean up USAGE arguments
use () to mark optional arguments to avoid confusion with arrays.
Add some more optional arguments.
2023-03-22 16:35:55 +01:00
Wim Taymans
1985eb3549 module-combine-stream: make sure str is != NULL 2023-03-16 11:44:28 +01:00
Barnabás Pőcze
934ab3036e treewide: use SPDX tags to specify copyright information
SPDX tags make the licensing information easy to understand and clear,
and they are machine parseable.

See https://spdx.dev for more information.
2023-02-16 10:54:48 +00:00
Thomas Weißschuh
4f9f32084c module-combine-stream: add missing proxy event version 2023-02-06 06:07:13 +00:00
Wim Taymans
64dca0b36d pipewire: add conf.h to standard includes
Also fix function signature so that it matched the .h file.
2023-01-25 13:23:44 +01:00
Wim Taymans
6d6cd6bbfb module-combine-sink: remove listener before core_disconnect 2023-01-24 15:41:00 +01:00
Wim Taymans
4eac50966a combine-stream: also set DONT_RECONNECT 2023-01-24 13:28:48 +01:00
Wim Taymans
94b4fd80eb module-combine: destroy stream when unconnected 2023-01-23 18:06:07 +01:00
Wim Taymans
2db9035538 module-combine-stream: safely add/remove stream from data thread
Use invoke to sync the data thread with the main thread when adding
and removing streams.
2023-01-23 17:53:22 +01:00
Wim Taymans
29787b51ef modules: add combine-stream module
The module can:

- Make a sink that sends all or some channels to other sinks.
- Make a source that combines multiple sources into one.

The selection of what streams to combine is implemented with rules so
that the selection is very configurable. By default all Audio/Sink or
Audio/Source nodes are selected.
2023-01-23 17:06:56 +01:00