Commit graph

4412 commits

Author SHA1 Message Date
Robert Mader
7e202a3844 spa: libcamera: add colorimetry support
Libcamera equivalent to 41b831d0f ("spa: v4l2: add colorimetry support")
2025-07-10 14:11:41 +00:00
Demi Marie Obenour
b3bf5be1f6 *: Avoid macros that use casts where possible
Use direct field access when the type is known, instead of a macro that
includes a cast.

These were missed in e4fcbef89a.
2025-07-10 14:02:55 +00:00
Wim Taymans
b4f97c62c6 filter-graph: support more complicated labels
If we see a container as the label, copy the whole container and use
that as the label.

The label is used to construct a plugin description.
2025-07-10 13:47:29 +02:00
Arun Raghavan
eec1ac20b7 spa: aec: webrtc: Expose echo canceller mobile_mode
Significantly better CPU performance in lieu of canceller quality. Not
implemented for 0.x series, as there's a lot more to enable there (such
as routing modes), and I am hoping to drop support for those versions
before too long.
2025-07-09 13:02:18 -04:00
Arun Raghavan
477674740e spa: aec: webrtc: Drop outdated comment
The Intelligibility enhancer was removed, so the FIXMEs are irrelevant.
2025-07-09 12:48:24 -04:00
Arun Raghavan
a328e0ae28 spa: audioconvert: Avoid reading past filter-graph param name end
Ensure we have at least a `.` after `audioconvert.filter-graph`, so we
don't try to read past the end if it does not exist.

Also document in the param name that an index is expected.
2025-07-09 15:20:09 +00:00
Arun Raghavan
8f429ac04b spa: aec: webrtc: Actually enable echo cancellation for 2.0 2025-07-09 08:54:36 -04:00
Wim Taymans
0efd0258a7 filter-graph: rename the plugin files
Move the plugin prefix to the front like everywhere else and this also
makes it easier to spot the plugins when listing the directory.
2025-07-08 16:18:13 +02:00
Frédéric Danis
80d44e8f39 bluez5: backend-native: Fix incorrect dial number management
When dialing an incorrect phone number some phones (e.g. iOS 18.5)
replies with OK but never send +CIEV updates, so there's no way to
know that the dial is not in progress and the call object should be
removed.

This change waits for +CIEV event to create the call object.
2025-07-08 11:37:45 +00:00
Julien Massot
8aa836d588 alsa-pcm: add support for api.alsa.dll-bandwidth-max
In USB Audio Class 2 (UAC2) setups, pitch control is handled by
feedback endpoints. The host adjusts its data rate accordingly.

When pitch control is active (pitch_elem), applying the default
delay-locked loop (DLL) bandwidth can lead to instability and
oscillations around the target rate.

This patch adds a new parameter, api.alsa.dll-bandwidth-max, to
configure the maximum DLL bandwidth. It introduces a new field
in the ALSA state to store this value.

By default, it uses SPA_DLL_BW_MAX, but when pitch control is in
use, setting it to a lower value (e.g. 0.02) helps ensure better
stability, based on empirical testing.
2025-07-07 10:40:11 +00:00
Arun Raghavan
019b53ace8 spa: alsa: Try to get driver rate before setting up matching
In some cases, it is possible that the follower shares a clock with the
driver, but the driver rate is not known when the follower is assigned
to the driver. If this happens, then state->driver_rate is 0, and when
setting the format, we might think that we need to resample (because
follower rate != driver rate). This can cause us to incorrectly halve
the period size for the node.

This was introduced in commit 0b67c10a9c,
which forces reevaluation of matching status on driver change.

To avoid this, let us also probe for the driver rate when updating the
matching status, so we can make the update more accurate.
2025-07-03 19:02:02 +00:00
Wim Taymans
ef5d9ff028 filter-graph: add a simple noise gate 2025-07-03 20:58:00 +02:00
Arun Raghavan
70aaec0ac4 spa: v4l2: Drop unused variable
Fixes warning:

[186/359] Compiling C object spa/plugins/v4l2/libspa-v4l2.so.p/v4l2-source.c.o
In file included from ../spa/plugins/v4l2/v4l2-source.c:164:
../spa/plugins/v4l2/v4l2-utils.c: In function ‘spa_v4l2_enum_format’:
../spa/plugins/v4l2/v4l2-utils.c:1103:22: warning: unused variable ‘drop_next’ [-Wunused-variable]
 1103 |                 bool drop_next = false;
      |                      ^~~~~~~~~
2025-07-03 10:07:54 -04:00
Julian Bouzas
a8b9ce2050 alsa: add option to disable pro-audio profiles
Some devices might have nonfunctional 'Pro Audio' sound. This patch adds a
new 'api.acp.disable-pro-audio' option to disable pro-audio profile entirely.
2025-07-02 08:11:48 -04:00
Wim Taymans
653e1578a1 audioconvert: use faster clear when dealing with empty buffers
When we are converting an empty buffer, use the more efficient
clear function.
2025-07-02 10:34:00 +02:00
Wim Taymans
0817001728 audioconvert: add clear function
Sets all samples to 0 in the target format.
2025-07-02 10:27:26 +02:00
Wim Taymans
f93b3b23a3 loop: fix use after free case
Because we can now destroy sources (and free the source structure) by
simply holding the lock, there is a window where we might access the
freed source.

When we in iterate release the lock and go into the epoll, another
thread might acquire the lock and delete the fd from epoll. This might
happen right after epoll detected activity on the fd. When iterate
manages to acquire the lock again, it will process to dispatch the
active fd and deref the ep.data pointer, which is now pointing to freed
memory.

Fix this by incrementing a removed_count whenever we remove a source.
Check the counter if it was the same as before the epoll otherwise we
can't assume all sources are alive still. Return in that case as if
there were no fds to poll. The caller should reenter the iterate at some
point and we will return all the fds with activity, minus the one that
got destroyed. We need to give control to the caller because part of the
removal could be to stop the loop iteration all together.
2025-06-30 12:44:15 +02:00
Michael Olbrich
41b831d0f8 spa: v4l2: add colorimetry support 2025-06-27 12:57:01 +00:00
Wim Taymans
9a6f8d31dc loop: unlock the lock when blocking on invoke
When we are the owners of the loop lock and we are not in the loop
thread itself, release all locks so that the loop can start processing
our invoke items and we get a chance to make progress. After that
re-acquire the locks.

This can happen when you change some of the core loop_locked() calls to
blocking _invoke functions that are called with the loop locked.

We have all core blocking invoke functions removed now so this is not
actually going to be used but just in case an application tries to
blocking invoke while locking the loop, this will now at least do
something else than deadlock.
2025-06-26 14:23:36 +02:00
Michael Olbrich
17c755714d v4l2: allow negotiation with modifier
This assumes that the modifier is always 'linear'. That is not quite
correct for all V4L2 formats. But PipeWire only uses input devices and
other modifiers are very unlikely.

This makes it possible to use DMABUFs with the GStreamer pipewiresrc.
2025-06-26 09:21:00 +00:00
Harald Sitter
1541ce3368 Revert "alsa: add Teufel Cage Pro mapping"
This reverts commit b57b87abbb.

It turns out this device is subtily different and doesn't work with the
current profile configurations. A UCM profile was added to alsa-ucm-conf
instead.
2025-06-26 09:19:09 +00:00
Wim Taymans
a9cece3c2e audioconvert: remove unused field 2025-06-25 10:37:56 +02:00
Wim Taymans
dd6c9de604 tests: set the flags on buffers correctly 2025-06-25 10:34:50 +02:00
Wim Taymans
8a09bacdf6 audioconvert: map buffers with right prot 2025-06-25 10:31:39 +02:00
Wim Taymans
bcb9ff20fd audioconvert: mark output as not empty when draining
When we are draining, we use an empty input buffer but then we push out the
remaining samples out of filters and we can't assume they are empty.
2025-06-25 10:31:24 +02:00
Wim Taymans
d093402d97 filter-graph: compare with float to avoid conversion 2025-06-24 13:46:30 +02:00
Wim Taymans
fa52a596f4 audioconvert: undef the right function 2025-06-24 13:46:08 +02:00
Pauli Virtanen
7fd05e7eaa bluez5: drop old SCO fragment data when sink starts
Any pending SCO fragment data should be cleared when sink starts, so
that we don't send out any old data.
2025-06-21 16:13:57 +03:00
Pauli Virtanen
665a27f281 bluez5: replace sco-source with media-source
Change media-source to use sco-io for HFP codecs.

Replace sco-source with media-source.

sco-source is mostly copypaste from media-source, only differed in the
IO handling.
2025-06-21 16:08:30 +03:00
Pauli Virtanen
5b4e9dc33e bluez5: replace sco-sink with media-sink
Change media-sink to use sco-io for HFP codecs.

Move SCO fragmentation to sco-io side.

Replace sco-sink with media-sink.

sco-sink is mostly copypaste from media-sink, and only differed in the
fragmentation detail, which can as well be handled on sco-io side.
2025-06-21 16:08:30 +03:00
Pauli Virtanen
f9b0bf3f95 bluez5: limit CVSD block size
Don't try to write data in too large blocks.

This controls the maximum amount of data to send at once. sco-io will
buffer and fragment packets to the right size.

Previously in sco-sink, SO_SNDBUF was not set, so there could be a
longer queue in the socket.
2025-06-21 16:08:30 +03:00
Wim Taymans
f3ff25c936 alsa: don't log unknown events with info
Debug is good enough
2025-06-20 15:49:17 +02:00
Pauli Virtanen
b91864eb37 bluez5: don't crash on codecs without caps_preference_cmp
E.g. LDAC doesn't have that. Add the missing guard that was accidentally
dropped in the rewrite.

Also explicitly filter out non-A2DP/BAP codecs that can't be used in
ensure_media_codec
2025-06-19 12:03:13 +00:00
Wim Taymans
cad0523617 audioconvert: refactor volume ramping
We don't actually have to store the ramp parameters so allocate them on
the stack and then use them to generate the sequence.

Make it possible to generate a sequence into a custom buffer as well.

Make sure we use the right rate (the graph rate) to calculate the number
of samples when converting from time to samples.
2025-06-19 11:16:34 +02:00
Wim Taymans
8047a37b02 spa: remove control type from formats
We just want to negotiate the control stream, we don't really care
about what is in the control stream.
2025-06-18 15:23:16 +02:00
Wim Taymans
54923bf5bd alsa: remove UMP negotiation constraint
Otherwise we won't be able to negotiate with a port that only wants old
style midi.

Instead just negotiate the control link, conversion to old style midi
will be done in the control mixer for the old client.

Fixes #4759
2025-06-18 10:10:10 +02:00
Wim Taymans
a6199c92a4 filter-graph: make sure strdupa is defined
Fixes #4756
2025-06-17 15:17:47 +02:00
Harald Sitter
b57b87abbb alsa: add Teufel Cage Pro mapping 2025-06-17 11:33:38 +00:00
Wim Taymans
f2905c74ed alsa-udev: support alsa.use-ucm
Make a new alsa.use-ucm option that sets api.alsa.use-ucm on the device
it creates (when set).

There is some documentation floating around (thr arch wiki) with this
property.

See #4755
2025-06-17 12:54:39 +02:00
Wim Taymans
953b0f81ad filter-graph: make sure M_PIf is defined 2025-06-17 09:25:54 +02:00
Wim Taymans
0b2b723a0e filter-graph: add a zeroramp plugin
The filter detects unnatural gaps (consisting of 0.0 values) and will
ramp-down or ramp-up the volume when entering/leaving those gaps.

This makes it filter out the pops and clicks you typically get when
pausing and resuming a stream.

See #4745
2025-06-17 09:14:18 +02:00
Frédéric Danis
75b4c3379d bluez5: hfp-hf: If available use AT+CLCC only to update calls state 2025-06-16 09:17:21 +02:00
Frédéric Danis
2cb678edb3 bluez5: hfp-hf: Remove disconnected calls from call list
After AT+CLCC command completion, the calls which has not been listed
should be removed.
This list the calls returned by AT+CLCC to be able to find the ones which
has not been listed but still in the call_list.
2025-06-16 09:17:20 +02:00
Frédéric Danis
931b6d9ad8 bluez5: hfp-hf: Fix condition for hfp_hf_swap_calls
AT+CHLD=2 can be called even if there is no active call, the only
condition is to have at least one held call.
2025-06-16 09:10:50 +02:00
Pauli Virtanen
3922247356 bluez5: sco-source: pass read mtu to codec 2025-06-15 14:35:32 +03:00
Pauli Virtanen
b869305282 bluez5: fix CVSD decode()
"Decoding" in CVSD should just copy bytes, packets may be any size.
2025-06-15 14:20:39 +03:00
Pauli Virtanen
3539374ba7 spa: alsa: fix some coverity warnings
NULL checks.

Change pa_x* malloc functions act like the pulseaudio ones: assert on
failure, as code assumes that.
2025-06-14 14:38:26 +03:00
Pauli Virtanen
7f2bdab8ea bluez5: fix some coverity issues
Missing null pointer checks, wrong array indices, uninitialized/unused
variables.
2025-06-14 14:34:55 +03:00
Pauli Virtanen
26b09b0ee3 bluez5: temporarily remove BAP nodes when another device is switching
Unicast BAP codec switch requires CIG reconfiguration, which cannot be
done if there is an acquired transport.

When doing BAP codec switch, disable nodes of other devices sharing the
same CIG.

To avoid problems with node start/stop, just remove and re-add them.
2025-06-13 22:16:03 +00:00
Pauli Virtanen
3ed969144a bluez5: bap: prefer 32 kHz in/out for duplex configuration
I'm not aware of any devices that support 48 kHz output in duplex
configuration, so disable that for now.

Doing this properly requires catching errors when on transport Acquire,
and switching to another configuration if the error was due to bad
configuration.

Due to how BAP specification works, it's not necessarily possible to
know whether a configuration was really accepted at earlier stage, and
anyway there's no proper error -> reconfiguration handling currently on
BlueZ side either.
2025-06-13 22:16:03 +00:00