Commit graph

4038 commits

Author SHA1 Message Date
Barnabás Pőcze
bf1c57928b spa: libcamera: source: do not make expensive queries multiple times
`StreamFormats::pixelformats()` and `StreamFormats::sizes()` both
return newly created `std::vector`s, so do not call them multiple
times.

(cherry picked from commit 311b3cc37f)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
bdf904ebad spa: libcamera: source: simplify format lookup
Use range based for loops instead of indices.

(cherry picked from commit 489cc49937)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
d1eb5f6d20 spa: libcamera: source: use enum types
Use the appropriate enum types instead of bare `uint32_t`,
this provides better type safety in C++.

(cherry picked from commit 0ea7dc9f19)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
3dd413e131 spa: libcamera: source: handle camera acquire failure
Check the return value of `Camera::acquire()` and return the error
if that fails.

(cherry picked from commit f53ac8d57c)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
a233905f75 spa: libcamera: inline libcamera-utils.cpp
The file is not useful without `libcamera-source.cpp` because it
uses symbols only defined there. And being a non-self-contained
source file, it also breaks clangd. So move its contents directly
to `libcamera-source.cpp`. This makes the file about 2200 lines long,
but I feel that is still manageable (and it is by far not the longest).

(cherry picked from commit 1a1cf55efb)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
60d95e447a spa: libcamera: clean up includes
Remove some unnecessarily includes.

(cherry picked from commit 5a9cdd724f)
2025-09-19 05:35:47 +02:00
Barnabás Pőcze
de97a682f2 spa: libcamera: use lock when acquiring CameraManager
Make `libcamera_manager_acquire()` thread safe by locking a mutex
when the `CameraManager` instance is created and started.

(cherry picked from commit 5f4f4b5dd3)
2025-09-19 05:35:39 +02:00
Robert Mader
74bd520224 spa: libcamera: add colorimetry support
Libcamera equivalent to 41b831d0f ("spa: v4l2: add colorimetry support")

(cherry picked from commit 7e202a3844)
2025-09-19 05:35:23 +02:00
David Turner
8094cdf846 libcamera: Default to auto-focus & auto-exposure
libcamera says that cameras should default to manual focus mode.  This
means that unless pipewire clients specifically change this control,
users with an autofocus-capable camera are left with an out-of-focus
image.  This patch sets the autofocus mode to continuous and enables
auto-exposure (as the default for this is unspecified).

Testing with an imx708 on Raspberry Pi OS on a Raspberry Pi 4, before
this patch the image was generally out of focus in Firefox/webrtc, after
this patch autofocus works correctly.

(cherry picked from commit 3a0ffe21e6)
2025-09-19 05:34:37 +02:00
Wim Taymans
5212649ee1 control: fix event compare function
We can only compare UMP when both types are 2 or 4, so it must be
different from 2 *and* 4 to be rejected.

Fixes #4899
2025-09-17 10:29:15 +02:00
Pauli Virtanen
16b3c8a6f6 audioconvert: add log topic for resampler 2025-09-10 10:28:57 +02:00
Pauli Virtanen
e8d739fdd7 alsa: report extra latency for FireWire drivers
Based on testing, ALSA FireWire drivers introduce additional latency
determined by the buffer size.

Report that latency.

Pass device.bus to the node, so it can recognize firewire.
2025-09-10 10:28:42 +02:00
Pauli Virtanen
3cb2c93c48 alsa: force IRQ scheduling for firewire in pro-audio profile
FireWire ALSA driver latency is determined by the buffer size and not the
period. Timer-based scheduling is then not really useful on these devices as
the latency is fixed.

In pro-audio profile, enable IRQ scheduling unconditionally for these
devices, so that controlling the latency works properly.

See #4785
2025-09-10 10:28:34 +02:00
Pauli Virtanen
8077dabd3a alsa: set minimum period count before automatic period size
Some devices (FireWire) fail to produce audio if period count is < 3,
and also have small buffer size. When quantum is too large, we might
then get too few periods and broken sound.

Set minimum for the period count in ALSA, to determine the maximum
period size we can use. If smaller than what we were going to use, round
down to power-of-2.

See #4785
2025-09-10 10:28:27 +02:00
Barnabás Pőcze
2735baa4ce treewide: map SPA_PROP_exposure to V4L2_CID_EXPOSURE_ABSOLUTE
Currently the v4l2 and libcamera plugins map `SPA_PROP_exposure` in incompatible
ways. So change the v4l2 mapping to `V4L2_CID_EXPOSURE_ABSOLUTE` because at least
that is in units of time (a step closer to addressing #4697), and because that
is more relevant for UVC cameras.

Also change the pipewire-v4l2 translation layer.
2025-09-10 10:28:08 +02:00
Wim Taymans
35dbea3c6c audiomixer: set change mask correctly 2025-09-10 10:20:34 +02:00
Wim Taymans
42eb28c0d2 audiomixer: format is Id 2025-09-10 10:20:18 +02:00
Wim Taymans
881d0e44d0 alsa: don't add MAX_LATENCY when using IRQ scheduling
The Max latency property only works for timer based scheduling so that
we don't select a quantum larger than we can handle in our buffer.

With IRQ based scheduling this does not make sense because we will
reconfigure the buffer completely when we change quantums and so the
currently selected buffer size does not limit the latency in any way.

Fixes #4877
2025-09-10 10:20:07 +02:00
Wim Taymans
ec1f3437e5 alsa: use 3 periods in IRQ mode by default
3 seems to work better as a default for Firewire. It does not actually
add latency because we only keep 1 period filled with data at all times.
2025-09-10 10:19:51 +02:00
Wim Taymans
124aa40f64 alsa: use 2 (or 3 for batch) periods in IRQ mode
Some drivers (Firewire) have a latency depending on the ALSA buffer size
instead of the period size.

In IRQ mode, we can safely use 2 (or 3 for batch devices) periods
because we always need to reconfigure the hardware when we want to
change the period and so we don't need to keep some headroom like we do
for timer based scheduling.

See #4785
2025-09-10 10:18:55 +02:00
Wim Taymans
0da4afca76 audiommixer: only clear mix_ops when initialized
It's possible that the mix_ops was not initialized and then the free
pointer is NULL, so check this instead of segfaulting.
2025-09-10 10:17:29 +02:00
alexdlm
ee0809ead9 Map Razer BlackShark v3 ACP 2025-09-10 10:12:37 +02:00
Pauli Virtanen
165bd9965b alsa: show correct value in api.alsa.period-num 2025-09-10 10:04:30 +02:00
Wim Taymans
fefea32d9f resample: optimize phase scaling
Precalculate the constant factor to avoid a division for each sample.
2025-07-23 14:51:25 +02:00
Wim Taymans
140ae1bb62 resample: fix compilation
Also fix a compiler warning in clang
2025-07-23 14:51:11 +02:00
Wim Taymans
f04e8164a6 resample: avoid calculating GCD in rate updates
We don't actually need to calculate the GCD for each resampler rate
update. The GCD is only used to scale the in/out rates when using the
full resampler and this we can cache and reuse when we did the setup.

The interpolating resampler can work perfectly fine with a GCD of 1 and
so we can just assume that.
2025-07-23 14:50:15 +02:00
Wim Taymans
4a22b53b74 resample: reorder resample function setup
We also don't need to copy the resampler function name with each dynamic
function update, this is just for debugging.
2025-07-23 14:50:12 +02:00
Wim Taymans
a95d6dd553 alsa: update resampler requested size before reading
spa_alsa_read is called from the source process function when we are a
follower and no buffer is ready yet.

Part of the rate correction was performed by the ALSA driver when it
woke up but now, the resampler has updated the requested size and we
need to requery it before we can start reading samples.

Otherwise, we end up with requested samples from before the rate update
and we might not give enough samples to the resampler. In that case, the
adapter will call us again and we will again try to produce a buffer
worth of the requested samples, which will xrun.
2025-07-23 14:50:05 +02:00
Niklas Carlsson
5aa46bbddd filter-graph: fix index off by one in dsp_delay_c
Checking w + 1 > n_buffer means that w will go to n_buffer, which
in turn leads to reading buffer[2 * n_buffer].
2025-07-22 15:54:48 +02:00
Wim Taymans
74ad61f094 alsa: update resample state in all cases
We need to manually recheck the resample state when the matching state
got updated.
2025-07-22 14:43:37 +02:00
Wim Taymans
83fa53ba6e alsa: don't try to activate resampling with unknown rates
If the driver or our rate is not known yet, don't assume we will need to
resample.
2025-07-17 10:21:25 +02:00
Pauli Virtanen
7cd256d14c bluez5: aac: fix for A2DP v1.4 using rfa bits for more channels
A2DP v1.4 uses the rfa bits for adding 5.1 and 7.1 configurations.
Clear those bits properly when sending configuration, in case remote
device sets them.

(cherry picked from commit ae7a893ce9)
2025-07-10 17:17:22 +03:00
Arun Raghavan
7b70906162 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:29:23 -04:00
Arun Raghavan
c5e90d7d51 spa: aec: webrtc: Drop outdated comment
The Intelligibility enhancer was removed, so the FIXMEs are irrelevant.
2025-07-09 13:29:21 -04:00
Arun Raghavan
5c9ddfd882 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.

Cherry-picked from a328e0ae28, dropping
the param doc update as that doesn't exist.
2025-07-09 12:14:27 -04:00
Arun Raghavan
af7ce19919 spa: aec: webrtc: Actually enable echo cancellation for 2.0 2025-07-09 15:26:11 +00:00
Wim Taymans
060d0e1761 Revert "loop: don't call the hooks around blocking wait"
This reverts commit 46dfa69f26.

We do actually need to release the locks for now. The reason is that
pipewire core will at various points do a blocking invoke into the
thread-loop (which is the data-loop when using non-rt/async processing)
to synchronize state. Because these functions are called with the
thread-loop lock and from some other thread (like gstreamer) it causes
a deadlock because the thread-loop is locked and can't run and the
caller is waiting for the thread-loop to complete.

See #4472
2025-06-26 12:45:29 +02:00
Wim Taymans
ff60e68a23 Revert "alsa: add Teufel Cage Pro mapping"
This reverts commit 0321f543d3.
2025-06-26 11:34:20 +02:00
Wim Taymans
c644f54ea7 audioconvert: remove unused field 2025-06-25 10:46:05 +02:00
Wim Taymans
cc94909ca1 tests: set the flags on buffers correctly 2025-06-25 10:45:59 +02:00
Wim Taymans
0fa5ceba1c 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:44:11 +02:00
Wim Taymans
86d1233107 alsa: don't log unknown events with info
Debug is good enough
2025-06-25 10:43:18 +02:00
Harald Sitter
0321f543d3 alsa: add Teufel Cage Pro mapping 2025-06-25 10:42:03 +02:00
Wim Taymans
a53a960645 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-25 10:41:51 +02:00
Wim Taymans
ecbd4f552c spa: make the wave, pattern and ditherType Int
Properties of type Id should have a type of the enum with the possible
values associated with them.

The other types that don't have a fixed enumeration but are usually
mapped to some constant/description with PropInfo should be Int.

Fixes !2399
2025-06-13 11:53:42 +02:00
Wim Taymans
e3f6a81df1 alsa: reset alsa_sync when linked
When a linked node needs to be resynced we actually never clear the
flag or reset the dll. Move the code around so that it still does
the reset of the flag and dll without actually doing the resync in
the ringbuffer when it is a linked node.
2025-06-13 11:53:42 +02:00
Wim Taymans
4cfef13042 alsa: reset dll in prepare
When we do_prepare, always reset the dll. We already set the alsa_sync
field but that is only used by followers to resync in some cases.

When reseting the dll, we also reset the next_time and base_time values,
we however need to do this before calculating the error in update_time
when we are the driver in IRQ mode or else we get some crazy error
that distorts the rate estimation.
2025-06-13 11:53:42 +02:00
Martin Geier
b5e9e59cdb alsa-pcm: enable interrupts after alsa recovery
Interrupts are disabled in alsa_irq_wakeup_event -> playback_ready method
to not produce another wakeups when waiting for a new data. Interrupts are
enabled again when a new data arrives in a method spa_alsa_write.
In rare cases, when there is multiple streams providing data and one of
them is disconnected, a new data fails to be delivered and the spa_alsa_write
is not called. Not providing data produces underrun and alsa-pcm invokes
recovery process. Recovery process starts a new playback, but without interrupts
enabled is graph not triggered and new data are not delivered (to enable
interrupts). Recovery process keeps running in loop.
Now the interrupts are enabled again after the recovery and the starvation
should not occur.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2025-06-13 11:14:22 +02:00
Wim Taymans
46dfa69f26 loop: don't call the hooks around blocking wait
The blocking invoke function is not meant to be called with any of the
loop context locks acquired so that it can actually run the invoke call
while blocking. Make this (and other blocking risks) clear in the
documentation.

Because it is not supposed to be called with any of the locks, we should
also not try to call the hooks (that implement the unlock/lock).

Fixes #4472
2025-06-10 12:18:28 +02:00
Wim Taymans
1139ab5966 alsa: handle NULL io
It is possible that the port io is set to NULL when the node is
negotiating or destroying.

Fixes #4734
2025-06-10 11:01:36 +02:00