Commit graph

5250 commits

Author SHA1 Message Date
Wim Taymans
4625f7ee3a mixer-dsp: only use passthrough when DYNAMIC_DATA
We can only change the data pointers on the output buffer when the data
had the DYNAMIC_DATA flag.
2025-10-01 11:13:42 +02:00
Wim Taymans
0915ed8be0 adapter: enhance converter flags with follower flags
We don't want to override the converter flags with the follower flags,
just enhance them with specific follower flags. Otherwise we lose the
DYNAMIC_DATA and other port flags from the converter.

See #4918
2025-10-01 11:03:53 +02:00
Wim Taymans
c91f75ae2e audio: bump max channels to 128 2025-10-01 09:21:36 +02:00
Wim Taymans
532140ca90 bluez5: Don't assume channels fit in uint8_t
There is no reason to believe the number of channels can fit in a
uint8_t. Limit the number of channels in some places where it can not
be avoided.
2025-10-01 09:13:42 +02:00
Pauli Virtanen
2248807835 bluez5: sco-io: send keepalive TX data if sink is not feeding it
When using LC3-24kHz, remote device drops connection after a few seconds
if there is no sink playback.  Avoid this by sending silence, one TX
packet for each RX packet, if sink hasn't been feeding data within a
timeout.
2025-09-29 14:15:46 +00: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
Peter Ujfalusi
9c42c06af0 alsa: Use the minimum period size as headroom for SOF cards
Configure the headroom to be equal of the minimum allowed period size for
the configuration.

This is desirable when the ALSA driver's hw_ptr is 'jumpy' due to
underplaying hardware architecture, like SOF.
In case of SOF the DSP firmware will burst read at stream start to fill
it's host facing buffer and later settles to a constant pace. The minimal
period size is constrained by the driver to cover the initial burst and
settling time of the hw_ptr.

Guard this mode of working with a new boolean flag, which is only enabled
for SOF cards, kept it disabled for other cards to avoid any unforeseen
side effects.

Even if the use-period-size-min-as-headroom is set to true, the manual
headroom configuration will take precedence to allow experimentation.

Link: https://github.com/thesofproject/linux/issues/5284
Link: https://github.com/thesofproject/sof/issues/9695#issuecomment-2569033847
Link: https://github.com/thesofproject/sof/issues/10172
Link: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4489
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
2025-09-25 16:30:08 +03:00
Wim Taymans
f8389cbdb7 alsa: improve force_rate handling
Replace force_rate with force_quantum. We use force_rate when we need
to play an IEC958 or a DSD format but it does not make sense to just
force the rate without also forcing the duration.

This is also what happens when doing IRQ based scheduling, we then force
both the duration and rate of the graph so we can reuse this logic.

Also when forcing a quantum, take into account the suggested duration
and rate of the graph and scale that with the currently configured rate
for the period size. This gives a quantum that will match the requested
rate better. This is important for the DSD, where rate are very high and
we want the period size to be something reasonable relative to the
selected graph rate.

For batch devices (and when using a timer) we also configure a period
size that is half the duration of the quantum, to make sure we get some
headroom. We however need to force the full duration as the quantum, so
keep track of this scaling and apply when calculating the duration.
2025-09-25 12:29:05 +02:00
Wim Taymans
f1e1f720bf adapter: fix Start of adapter
Commit cbbf37c3b8 changed the logic of the
Start command. Before this commit, when there was no converter, the
follower would always get the Start command. After the commit, the
follower would only get Start when previously Paused.

This however breaks when we set a format or buffers on the follower
without a converter because those actions might change the state of the
follower to Paused implicitly.

We should simply remove the started check here and always call Start on
the converter and follower, the implementations themselves will keep track
if anything needs to be done.

Fixes #4911
2025-09-24 12:36:13 +02:00
Pauli Virtanen
2e2f7c9f79 alsa: don't fail if 3 periods_min fails
Some drivers (emu10k1) appear to not necessarily support more than 2
periods.

Don't fail start if snd_pcm_hw_params_set_periods_min() fails, then we
just set nearest possible periods and buffer sizes.
2025-09-23 07:21:29 +00:00
Wim Taymans
00d983a40d meta: add metadata features
Add a new features property to the metadata param. This should be
of type CHOICE_FEATURES_Int and should contain the extra features
supported by this metadata.

Make a special features metadata type that is a combination of the
metadata type in the upper 16 bits and the features for that type in the
lower 16 bits. Make a function to search if a type has certain feature
bits.

On the server, when negotiating buffers and metadata, check the result
of the features after filtering and if they are not 0, place them as
0 sized extra feature metadata on the buffer.

Add some metadata features for the sync_timeline, one that specifies
that the RELEASE flag is supported. With this in place, a producer can
see if a consumer supports the UNSCHEDULED_RELEASE flag.

See #4885
2025-09-19 14:05:04 +02:00
Wim Taymans
a859c7a651 builder: add support for FEATURE choice
This is the same as the Flags choice but the property (if any) has the
DROP flag set.

This means that when filtering, the property is dropped when one side
is missing the property. Otherwise, the flags are AND-ed together with a
negotiation failure when the result if 0.

This can be used to make sure both sides present compatible feature bits.
The result of the filter is then:

  1. no property (one side didn't present bits). This is likely because
     the other side is old and doesn't know about the feature bits yet.
     Code can take a backwards compatibility codepath.
  2. a negotiation failure, both sides presented bits but the AND is 0,
     they don't have compatible features.
  3. a property with bits (features) that are compatible.

This is different from normal flags in that the flags are not dropped
when the other size is missing the property.
2025-09-19 13:40:52 +02:00
Wim Taymans
d5608c07c3 control: unit test for event sort
After some discussions with CLAUDE it made me this unit test, which
I think is ok and actually tests useful things.
2025-09-17 13:42:12 +02:00
Wim Taymans
83b59d6ebe pod: add SPA_POD_PROP_FLAG_DROP
The property will be dropped from the filtered result when one of the
pods to filter does not have the property.

This can be used as a feature mask. If side A provides a flags property
and B doesn't, the property will be removed from the result. Without the
flag, property A would be added and it would not be possible to see if
filtering happened (when B had compatible flags) or not.
2025-09-16 11:00:04 +02:00
Wim Taymans
03c5f493dc 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-16 10:47:12 +02:00
Wim Taymans
f89428d9f8 tools: print async node state in pw-top
Pass the node async state in the profiler and use this in pw-top to draw
the node with = instead of a + in the tree when it's async.
2025-09-15 12:29:57 +02:00
Wim Taymans
9df770eb16 spa: support props flags building and parsing
Add an option to make a property with specific flags. Do this by
changing the parser and builder to see the invalid property as an escape
sequence followed by the property key and the flags.
2025-09-12 16:54:04 +02:00
Wim Taymans
41e6e875e5 spa: clean up the filter code
Use SPA_FLAG_IS_SET() and use the same if/else pattern.
2025-09-12 16:33:48 +02:00
Wim Taymans
818ef4e138 spa: flags just have 1 value 2025-09-12 16:17:26 +02:00
Wim Taymans
2be4c2ba51 meta: add SPA_META_SYNC_TIMELINE_UNSCHEDULED_RELEASE
This flag is set by the producer and should be cleared by the consumer
when it promises to signal the release point.

When a consumer dequeues a buffer with the flag set, it should assume
the client is not going to signal the release point and so it should
reuse the buffer right away. This can only happen when the client
didn't dequeue the buffer at all (killed, timeout, error, ...) or when
it dequeued and queued the buffer without clearing the flag.

See #4885
2025-09-10 13:43:51 +02:00
Wim Taymans
1e5a938e43 adapter: disable rate_match for the video adapter
We don't actually implement this for the video adapter. We should
ideally check for the SPA_IO_RateMatch param to decide this..
2025-09-09 15:10:12 +02:00
Pauli Virtanen
589bc4b6f4 bluez5: iso-io: sync to ISO RX clock, align stream RX in group
Align RX of streams in same ISO group:

- Ensure all streams in ISO group have same target latency also for BAP
  Client

- Determine rate matching to ISO group clock from RX times of all
  streams in the group

- Based on this, compute nominal packet RX times, and feed them to
  decode-buffer instead of the real RX time. This is enough for
  sub-sample level sync.

- Customise buffer overrun handling for ISO so that it drops data to
  arrive exactly at the target, for faster convergence at RX start

The ISO clock matching is done based on kernel-provided packet RX times,
so it has unknown offset from the actual ISO clock, probably a few ms.

Current kernels (6.17) do not provide anything better to use for the
clock matching, and doing it properly appears to be controller
vendor-defined (if possible at all).
2025-09-07 18:26:03 +00:00
Pauli Virtanen
94c354c290 bluez5: decode-buffer: sub-sample accurate fill level tracking
Take resampler delay into account when computing the buffer fill level,
including the fractional part.

If decode-buffer is now fed nominal packet reference times in
write_packet(), it converges the total buffer + resampler latency to the
target at sub-sample accuracy.

This is needed for aligning RX of ISO streams in the same group, so that
e.g. stereo pair alignment is achieved even though the streams have
separate resamplers. Resampler phases get aligned via independent rate
matching.
2025-09-07 18:26:03 +00:00
Pauli Virtanen
e446e3aac5 bluez5: media-source: account for driver clock rate difference in rate match
The rate matching calculations are done in the system clock domain.  If
the driver ticks at a different rate, the correction factor needs to be
adjusted by the rate_diff.

setup_matching() also needs to be before spa_bt_decode_buffer_process():
as follower we should use rate matching value calculated on the
*previous* cycle, because this is what driver is doing when it adjusts
it tick rate.
2025-09-07 18:26:03 +00:00
Pauli Virtanen
f48a72a504 bluez5: smaller max latency for BAP client capture
4 packets should be enough jitter buffer. This matters only for BAP
client, server is controlled by presentation delay.
2025-09-07 18:26:03 +00:00
Pauli Virtanen
7e04f8fe44 bluez5: ensure capture target latency is uniform for an ISO group
All BAP client sources in the ISO group should use same target latency,
so that capture streams stay in sync.
2025-09-07 18:26:03 +00:00
Pauli Virtanen
396d37594c bluez5: media-source: drop all errqueue data when ignoring 2025-09-07 18:26:03 +00:00
Pauli Virtanen
28393cb896 audioconvert: add log topic for resampler 2025-09-07 18:26:03 +00:00
Pauli Virtanen
bf783ab08f 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-07 18:23:31 +00:00
Pauli Virtanen
916896c1cc 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-07 18:23:31 +00:00
Pauli Virtanen
64aaf8a832 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-07 18:23:31 +00:00
Barnabás Pőcze
7a98bcf735 spa: libcamera: source: fix typo in log message
';' -> ':'
2025-09-07 18:21:53 +00:00
Barnabás Pőcze
756df7b6ae spa: libcamera: source: remove buffer::ptr
With the removal of `SPA_DATA_MemPtr` support, this member is no longer used.

Fixes: b948ffdb25 ("spa: libcamera: source: remove `SPA_DATA_MemPtr` support")
2025-09-07 18:21:53 +00:00
Barnabás Pőcze
93941e5207 spa: libcamera: source: query frame buffer planes just once 2025-09-07 18:21:53 +00:00
Pauli Virtanen
47780884e1 bluez5: media-source: pass through node.rate and node.latency
Allow user to specify custom values for node.rate and note.latency.

Also restore the 512 default latency.
2025-09-07 18:04:28 +00:00
George Kiagiadakis
e9b78f1c31 bluez5: media-source: add option to control the target latency of the decode-buffer
On production systems, having a constant high latency is favored over
dynamically adjusting it in order to optimize for low latency,
because every time a dynamic adjustment happens, there's a glitch.

This adds an option to let the user specify the exact amount of latency
they want.
2025-09-07 18:04:28 +00:00
George Kiagiadakis
5af8340183 bluez5: media-source: don't set node.latency by default
The hardcoded latency of 512/<rate> is quite low on some ALSA devices.
Instead of forcing that latency onto the graph, just don't set it at all
unless it originates from the BAP presentation delay. That means that
the functionality remains the same for BAP but changes for A2DP to favor
the preferred quantum of the ALSA sink (or whatever is the driver).

Also, avoid setting an empty string ("") latency and rate in the cases
where it's not defined. This allows users to override those properties
through the wireplumber monitor rules if they need to.
2025-09-07 18:04:28 +00:00
Barnabás Pőcze
3b33f60d2f 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-05 17:26:44 +02:00
Wim Taymans
f10dec9dae spa: fix typo in raw-types for LLFE
Spotted by Nikolai

Fixes #4881
2025-09-05 15:44:22 +02:00
Wim Taymans
9f88d6997f audiomixer: set change mask correctly 2025-09-03 10:01:38 +02:00
Wim Taymans
233b7f1d4a audiomixer: format is Id 2025-09-03 10:01:00 +02:00
Wim Taymans
0f6aae914f 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-02 18:52:38 +02:00
Wim Taymans
9606b37776 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-02 17:29:26 +02:00
Wim Taymans
0095d79ef8 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-02 14:13:19 +02:00
Wim Taymans
0310bb5c5c 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-01 12:39:08 +02:00
Wim Taymans
e2ac91b860 ump: make sure we set the group correctly 2025-08-29 16:59:38 +02:00
Martin Geier
c99311e822 filter-graph: clear external field in unsetup_graph
Without this change the playback with different number of channels
fails with `input port %s[%d]:%s already used as input %d, use mixer`
on the first port.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>

Fixes #4866
2025-08-28 10:15:05 +02:00
Wim Taymans
2385aa18e1 audioconvert: handle filter-graph setup better
Force filter graph reconfiguration in setup_convert.

When adding/removing filter-graphs, only perform setup when we were
already setup, otherwise we will do this in setup_convert later.

Don't do channelmix_init when we were not setup.

Deactivate the filter-graphs when we suspend.

Fixes #4866
2025-08-27 17:56:14 +02:00
Pauli Virtanen
984c44b044 bluez5: fix BIS source presentation delay
The value comes from QoS preset, not configurable otherwise right now.

Patch from @michael-kong754
2025-08-27 15:55:50 +00:00
alexdlm
b0b6b1fcc5 Map Razer BlackShark v3 ACP 2025-08-27 15:55:02 +00:00