Commit graph

5482 commits

Author SHA1 Message Date
Jonas Ådahl
3c1b8dcdcc spa/util/json-core: Fix condition checking for container end
Fixes the following warning:

    /usr/include/spa-0.2/spa/utils/json-core.h: In function ‘spa_json_is_container_end’:
    /usr/include/spa-0.2/spa/utils/json-core.h:404:41: warning: logical ‘or’ of equal expressions [-Wlogical-op]
      404 |         return len > 0 && (*val == '}'  || *val == '}');
          |                                         ^~
2026-03-12 22:21:41 +01:00
Barnabás Pőcze
3273ba6333 spa: support: logger: print thread id for each message
The thread id is very useful for debugging, add it to the every log
message so that it does not have to be inferred from the content itself.

This is already done in the systemd journal logger, so implement
it here as well.

Before:

  [I][00:13:11.120303] pw.context   | [      pipewire.c:  585 pw_init()] version 1.7.0

After:

  [I][365073][00:13:11.120303] pw.context   | [      pipewire.c:  585 pw_init()] version 1.7.0
2026-03-12 18:31:46 +01:00
Barnabás Pőcze
9098996b87 spa: support: logger: use spa_strbuf
Using `spa_strbuf` simplifies a code a great deal by removing the manual
tracking of buffer sizes, and it also removes the need for the separate
strings for the timestamp, topic, etc.
2026-03-12 16:53:16 +00:00
Barnabás Pőcze
00148467ef spa: utils: string: add spa_strbuf_appendv()
Add a function that makes it possible to pass a `va_list` when
printing into a `spa_strbuf`.
2026-03-12 16:53:16 +00:00
Wim Taymans
16bde0c61d filter-graph: set some more def/min/max for control input
So that the values don't get clamped to 0.0
2026-03-12 16:01:52 +01:00
Jonas Holmberg
1344bec7bb filter-graph: set min, max and def values for ramp
Set min, max and def values for the control ports of ramp plugin to
avoid clamping all control values to 0.
2026-03-12 15:34:35 +01:00
Arun Raghavan
f11ab0da3e spa: loop: Mark cancellation fields as volatile
Cancellation handlers use setjmp/longjmp, for which the C99
specification has the following note:

> 17.3.2.1 (3)
> All accessible objects have values, and all other components of the
> abstract machine) have state, as of the time the longjmp function was
> called, except that the values of objects of automatic storage
> duration that are local to the function containing the invocation of
> the corresponding setjmp macro that do not have volatile-qualified
> type and have been changed between the setjmp invocation and longjmp
> call are indeterminate.

While everything works fine with GCC, with Clang we see that the
cancellation handler doesn't seem to have an effect (loop-test fails
when it notices that its spa_source's priv and mask have not been
cleaned up).

The underlying cause is that the compiler can assume data.ep_count is
only used in loop_iterate_cancel(), and so can be cached in a register.
When we access that field in the cancellation handler, it was never
actually written to the memory on the stack, so the read in
cancellation_handler() does not see the current value.

We fix this by marking all fields on the stack that we expect to be
modified in loop_iterate_cancel() as volatile, forcing the memory to be
updated and correctly available to the cancellation handler.
2026-03-12 09:24:53 +00:00
Siva Mahadevan
0393fd8a72 spa/plugins: include <stdlib.h> for alloca() on non-linux 2026-03-12 09:21:40 +00:00
Siva Mahadevan
357f27658e spa/utils: remove FreeBSD workaround for bswap*
Both <endian.h> and <byteswap.h> have the things we need.
2026-03-12 09:20:50 +00:00
Siva Mahadevan
a671625637 spa/plugins: revert "Disable alsa plugin on !Linux platforms."
This reverts commit 01096bf669.

The linux-specific headers are gone, it builds fine now with alsa enabled.
2026-03-12 09:20:05 +00:00
Siva Mahadevan
e447b46d36 spa/tests: remove unused #include <linux/limits.h> 2026-03-11 21:50:21 +00:00
Siva Mahadevan
cd84d007cd spa: replace ECHRNG with EINVAL
ECHRNG is linux-specific and does not exist on all OSes.
On the other hand, EINVAL is specified in POSIX[0] (and is thus cross-platform)
and is commonly used to signify an index out of bounds error.

https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/errno.h.html
2026-03-11 20:40:24 +00:00
Wim Taymans
f45e619559 filter-graph: emit control change after loading
Always do a control change to the instances when they are created. This
is to make sure the internal state is synced to the control values.

The sofa filter and biquads need this to correctly configure themselves
after a suspend.

Fixes #5152
2026-03-11 12:39:46 +01:00
Wim Taymans
5cc63c1b34 audiomixer: only add the input port to mix_list
Adding the output port is not a problem because there is never a buffer
to consume and mix but it wastes cycles.
2026-03-11 12:36:39 +01:00
Wim Taymans
5f4b422ab1 loop: improve cancellation handling
Now that the loop_leave function will assert when the unlock fails we
need to be extra careful with the cancellable loop. If it cancels inside
the poll or one of the before/after callbacks we need to make sure that
we lock the loop correctly again or we will create an assert later on.

Do this by pushing the cleanup earlier and then record all the things we
managed to do before we get canceled. If we ever get canceled and the
lock was unlocked but not locked again, fix this up.

Fix fixes issues when using the JACK API causing assertions when the
data loop is stopped/cancelled.
2026-03-10 16:46:29 +01:00
Wim Taymans
8f22785cf0 json-core: use table to classify chars for number check 2026-03-10 12:30:03 +01:00
Barnabás Pőcze
810617997b spa: libcamera: source: SPA_PARAM_Props is write-only
There are no readable `SPA_PARAM_Props` on the node, so mark it write-only.
2026-03-09 21:19:38 +00:00
Barnabás Pőcze
a661f14d2c spa: support: loop: check enter_count before iterating
Calling "iterate()" on a loop that has not been entered by the
calling thread is invalid. So try to diagnose misbehaving applications
on a "best effort" basis by checking `impl::enter_count`.

This is not a foolproof check, and can also technically cause data
races while reading the variable.

See #5148
2026-03-09 22:08:23 +01:00
Barnabás Pőcze
dc1738ce57 spa: support: loop: more mutex lock checks
Check the return values of `pthread_mutex_{,un}lock()` in more places
to diagnose misbehaving applications.

See #5148
2026-03-09 22:08:22 +01:00
Pauli Virtanen
22a5fad902 bluez5: cleanup get_codec_profile()
Check codec kinds for each direction properly when mapping to profiles
corresponding to it. Being sloppy here masked another bug, so best fix
it.
2026-03-09 21:35:22 +02:00
Pauli Virtanen
75c3d3ecf8 bluez5: fix spa_bt_device_supports_media_codec() for HFP codecs
HFP codecs don't have a direction dependent "target" profile, and this
function was returning false if A2DP is disabled.

Don't check target profile for HFP, leave checks to backend.

Fixes HFP-only configurations, which were missing profiles.
2026-03-09 21:33:28 +02:00
Wim Taymans
2548fcad25 spa: update lib.c 2026-03-09 18:33:32 +01:00
Wim Taymans
f6939a1cf0 json: Use state machine and fix 1E10 parsing
Use a state machine to check for valid numbers and fix the 1E10
parsing case.

With help from Claude.
2026-03-09 18:17:04 +01:00
Pauli Virtanen
d42646e91f bluez5: sbc: clean up codec_enum_config
Non-spec compliant devices may set multiple bits in code config, which
we currently reject in validate_config().

enum_config() does work to deal with multiple bits set, but this is
never used, so write the code in a simpler way to return a single
configuration.
2026-03-09 15:53:35 +00:00
Pauli Virtanen
67b4732c26 bluez5: aac: for multiple bits in aot, normalize to mandatory
Non-spec compliant devices may set multiple bits in AAC AOT, which is
invalid.

In this case, we should normalize to MPEG-2 AAC LC which is the
mandatory value in spec, not to MPEG-4 AAC LC. In select_config() we
also prefer MPEG-2 over MPEG-4.
2026-03-09 15:53:35 +00:00
Pauli Virtanen
5f8ece7017 bluez5: aac: coerce non-spec compliant freq/channels to single choice
Some non-spec compliant devices (Sony XB100) set multiple bits
in all AAC field, including the frequency & channels.

Although they set multiple bits, these devices appear to intend that the
sender picks some specific format and uses it, and don't work correctly
with the others.

validate_config() already picks one configuration, so use the result in
enum_config(), instead of allowing also other settings.

Assume devices generally want preferably 44.1 kHz stereo.

Note we cannot reject the configuration, as BlueZ does not necessarily
retry, leaving the device connected but with no audio.
2026-03-09 15:53:35 +00:00
Pauli Virtanen
f9e2b1d8b9 bluez5: backend-native: don't crash without dbus session bus
When there is no DBus session bus, creation of the telephony backend
fails, and we later crash on null ptr deref.

In this case, avoid crash trying to create telephony_ag or iterate its
call list.
2026-03-09 15:52:05 +00:00
Wim Taymans
ddf63e0863 json: relax float parsing some more
We already support more float variants than standard JSON in the relaxed
format, adding extra restrictions does not actually help much. If you
need to know if this is a value JSON number, there is now a function to
check that instead.
2026-03-09 16:48:05 +01:00
Wim Taymans
6f73e42d05 v4l2: use 0x as the prefix for hex values
fixes #5161
2026-03-09 13:50:38 +01:00
Wim Taymans
3a2d16a3bc json-builder: do better json number check
If we are going to produce valid JSON we need to do a better JSON number
check because our own float and int parser can accept more variants
and will let through numbers that are not valid JSON.

See #5161
2026-03-09 13:33:20 +01:00
qaqland
d1c372f5ee alsa-udev: support alsa.ignore-dB
Some sound cards are only adapted for Android/macOS and other
systems, without considering Linux. The hardware-reported dB
volume is incorrect (while the percentage volume is normal).
Add support for the ignore-dB option to simplify compatibility.

For example, the 3206:0798 HP SIMGOT GEW1 Sound Card reports:

numid=4,iface=MIXER,name='PCM Playback Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=100,step=0
  : values=100,100
  | dBminmax-min=0.00dB,max=0.39dB

This dB value does not match actual audio perception, and the
vendor attributed this issue to non-target system compatibility.
2026-03-07 13:53:38 +08:00
Wim Taymans
106b4a37d4 node: remove node.link-group from drivers
Sink/Source pairs should not have the same link-group otherwise the
session manager will not be able to autoconnect them with a loopback or
some other internally linked stream.
2026-03-05 14:32:41 +01:00
Wim Taymans
06f336a581 json-builder: handle allocation failures in vasprintf 2026-03-01 12:40:34 +01:00
Frédéric Danis
ee18160c4e bluez5: bap: Fix typos 2026-02-27 17:19:01 +00:00
Wim Taymans
d6654e84a7 sendspin: add sendspin sender and receiver
The sender makes an input stream for each connected client. This makes
it easier to do the per client conversion using the adapter and send
different channels to clients.

The receiver uses linear regression to map ringbuffer indexes to server
timestamps and server timestamps to client timestamps. It can then
schedule playback against its own clock.
2026-02-26 12:17:17 +01:00
Wim Taymans
6daa8ccc0d json-builder: zero the struct 2026-02-26 12:08:26 +01:00
Wim Taymans
03662b3dfe json-builder: avoid indent on the first item
Avoids putting a \n or (now also) space as the first item.
2026-02-26 11:17:17 +01:00
Wim Taymans
bdbb5f6d27 json-builder: add raw mode that leaves keys/strings like they are 2026-02-26 11:09:13 +01:00
Wim Taymans
7dd924797b audioconver: reformat the graph description for properties 2026-02-26 10:59:57 +01:00
Wim Taymans
ed361a856f tools: port various tools to the new json-builder
Remove custom json serialization code and use the new json-builder
from various tools.

spa-json-dump now has color and raw mode and can probably be simplified
a bit more.

The properties can now serialize arbitrarily large keys, which makes
a unit test work. It also has a new 'simple' option for SPA output,
which is added and used in pw-config.
2026-02-26 10:51:17 +01:00
Wim Taymans
6753c51ab8 spa: add a new json-builder helper
It keeps track of the json bits like commas and indentation, supports
colors and recursive reformatting. It also supports a simple mode that
implements the SPA syntax.
2026-02-26 10:48:53 +01:00
Wim Taymans
692590b30a json: a container start also ends a bare string
This stops the parser from seeing foo{bar as a single string.

This also makes a valid test work, add another small test.
2026-02-26 10:42:14 +01:00
Barnabás Pőcze
848ac24490 spa: libcamera: source: fix stop sequence
Currently it is possible for the request completion handler (`impl::requestComplete`)
to observe `impl::source.fd` while it is being modified in `impl::stop()`.

Fix that by closing the eventfd after the camera has been stopped.

Fixes: 3e28f3e859 ("spa: libcamera: source: rework startup sequence")
2026-02-24 18:29:51 +01:00
Ripley Tom
c847b81629 spa/plugins/alsa/acp/compat.h: Fix missed -Wdiscarded-qualifiers warning 2026-02-22 15:59:56 +00:00
Arun Raghavan
5bd93b97ad Revert "spa: json: Add a helper method to shrink an object string"
Drop this until we have better API for building/visiting JSON.

This reverts commit c244fbf945.
2026-02-19 20:02:51 +00:00
Barnabás Pőcze
e46bfe67b6 treewide: fix some -Wdiscarded-qualifiers
Newer glibc versions have made certain `str*()` functions into macros
that ensure that the const-ness of the argument is propagated to the
return type.
2026-02-19 21:00:10 +01:00
Arun Raghavan
d4329600d1 audioconvert: Report loaded filter graphs in props
Makes it easier to know what filters have been loaded.
2026-02-19 19:29:40 +00:00
Arun Raghavan
c244fbf945 spa: json: Add a helper method to shrink an object string 2026-02-19 19:29:40 +00:00
Wim Taymans
7887c365d1 filter-graph: Make a new control_sync function
This function is run for all the nodes with the data loop locked. It can
be used to atomically update multiple node controls.

We can't use the control_changed function because this one runs without
the lock and might do slow things, like what the sofa plugin currently
does.

See #5019
2026-02-19 13:15:40 +01:00
Wim Taymans
e7ca02c4d8 filter-graph: sync control updates with data thread.
don't read the control ports from the processing thread and check for
updates. Use the control_changed signal to check and update the
parameters of the biquad atimically.

See #5019
2026-02-19 13:15:39 +01:00