Commit graph

14186 commits

Author SHA1 Message Date
Wim Taymans
4dccddd564 impl-link: add 1 quantum latency for async links
Update the scheduling doc with some information about how async
scheduling works. Also add something about the latency.

Async links add 1 quantum of latency so take that into account when
aggregating latencies.

Also a source directly linked to an async node does not add latency
(we evaluate the tee before incrementing the cycle so that it effectively
is executed in the previous cycle and consumed immediately by async
nodes). We can do this because the driver source always provides data
before the async node, and never concurrently.

Add a listener to the link for the node driver change as well because
that can now influence the latency for async nodes.
2025-09-15 17:42:03 +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
09cd7bf783 impl-node: only do unprepare once
There is not reason to do the unprepare logic twice and it might
actually interfere with the actions of the client.

See #4840
Fixes #4893
2025-09-15 10:22:16 +02:00
Wim Taymans
f81bb670c3 Revert "impl-node: improve the node unprepare function"
This reverts commit 2891e579a1.

This seems to cause regresssions with nodes xrun etc.

See #4893
2025-09-15 10:15:07 +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
862ac1f7c8 examples: use BGRA as the format
RGB is not supported by videoconvert.
2025-09-09 16:40:42 +02:00
Wim Taymans
2891e579a1 impl-node: improve the node unprepare function
do_node_unprepare runs in both the server and the client when a node is
stopped. On the server size, set the status to FINISHED and trigger any
targets. This ensures the node will not be scheduled in this cycle
anymore. We have to do this because we can't know if the node is still
alive or not.

When the client receives the stop message, it will unprepare and set the
status to INACTIVE. This ensures the driver will no longer trigger the
node. If the server didn't already trigger the targets, do this in the
remote node then.

This avoid a race where both the client and the server are setting the
status and if the INACTIVE state is set by the server, it might stall
processing of the client.

Fixes #4840
2025-09-09 15:14:36 +02:00
Wim Taymans
d6488c5351 stream: decouple the requested size from scheduling
The docs say that a requested size of 0 can be returned and it means
that there is no suggestion for the size.

Make this so by decoupling the requested size value and the triggering
of the process callback. If we have no rate_match and no quantum
(because the driver didn't set it) we still want to schedule with a 0
requested size.
2025-09-09 15:11:45 +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
Wim Taymans
144c3630ea examples: fix texture updates 2025-09-09 14:29:18 +02:00
Barnabás Pőcze
0b08468035 pipewire: mem: pw_memblock_map(): fix pointer when reusing mapping
Previously the pointer was determined as follows:

  mm->this.ptr = SPA_PTROFF(m->ptr, range.start, void);

however, when `pw_map_range` is calculated, `pw_map_range::start` is the offset
from the beginning of the first page, starting at `pw_map_range::offset`.

This works correctly if `memblock_map()` runs because that will map the file
with expected offset, so using `range.start` is correct.

However, when a mapping is reused (i.e. `memblock_find_mapping()`) finds something,
then `range.start` is not necessarily correct. Consider the following example:

  * page size is 10
  * one memblock with size 20 (2 pages)
  * the applications wants to mappings:
    * (offset=5,size=10)
    * (offset=15,size=5)

After the first request from the application, a `mapping` object is created
that covers the first two pages of the memblock: offset=0 and size=20. During
the second request, the calculated `pw_map_range` is as follows:

  { start = 5, offset = 10, size = 10 }

and the only previously created mapping is reused since (0 <= 5) and (10 <= 20). When
the pointer of the mapping is adjusted afterwards it will be incorrect since `m->ptr`
points to byte 0 on page 0 (instead of byte 0 on page 1 -- that is assumed). Thereforce
the two will unexpectedly overlap.

Fix that by using `offset - m->offset` when adjusting the mapping's pointer. Also move
the `range` variable into a smaller scope because it only makes sense there. And add
a test that check the above previously incorrect case.

Fixes: 2caf81c97c ("mem: improve memory handling")
Fixes #4884
2025-09-08 11:38:42 +00:00
Barnabás Pőcze
93774b1d14 pipewire: mem: log page size on creation 2025-09-08 11:38:42 +00:00
Barnabás Pőcze
9d01a26242 pipewire: mem: forward declare spa_hook
This type is used in function arguments, so forward declare it.
2025-09-08 11:38:42 +00:00
Barnabás Pőcze
91b764faac pipewire-v4l2: support choice sizes
Add support for `SPA_CHOICE_{None,Enum,Step,Range}`. They can all
be naturally mapped to `v4l2_frmsizeenum`.
2025-09-08 11:36:24 +00:00
Barnabás Pőcze
cec0ab322e meson.build: set PW_BUILDDIR in devenv
This is needed by `pw-v4l2`.
2025-09-08 11:36:24 +00: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
0877eba761 tools: add Latency reporting to pw-link
Rework how the monitor mode works. Instead of having separate paths for
the list and monitor mode, reuse the list mode. We simply mark all
changes and then list the changes in a loop.

This makes it possible to accumulate some updates and print them
together.

Add a -t option to list the latency params on a port.
2025-09-03 14:42:23 +02:00
Pauli Virtanen
0f1e4f8706 doc: add more properties missing from docs 2025-09-03 09:34:54 +00:00
Pauli Virtanen
36871ff1ff doc: show tabs on top on doxygen >= 1.13 2025-09-03 09:34:54 +00:00
Pauli Virtanen
bde2aa34ef doc: improve property documentation
Add some more examples, and more xref links to index.
2025-09-03 09:34:54 +00:00
Pauli Virtanen
98b7a34102 doc: support alternative index name in @IDX@ 2025-09-03 09:34:54 +00:00
Wim Taymans
1bf5ca28d8 modules: nmake dynamic ports work in link-factory
Just making a port and adding it to a node does not make it a working
port..

Make a new node function to get a new free port, this will actually call
the implementation spa_node_add_port(), which will add the new port
which we can then pick up and use.

See #4876
2025-09-03 10:38:59 +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
00bb4a936a filter: removed QUEUED flag and add DEQUEUED flag
Remove the QUEUED flags to check if a buffer is in some queue.

Add a new flag to check if a buffer was dequeued by the application.
Check if the application only queues buffers with the DEQUEUED flag set.
2025-09-02 16:46:03 +02:00
Wim Taymans
b6ce585da6 stream: remove QUEUED buffer flag
The flag was used to see if a buffer was in a queue or not but that
doesn't really matter much and with the DEQUEUED flag we can only move
buffers from dequeued to queued.
2025-09-02 16:37:53 +02:00
Jonas Ådahl
220bdf8a00 pipewire/stream: Don't queue back cleared buffers
When renegotiating stream parameters (e.g. size), the buffers
are cleared should no longer be queued back. Add a flag to detect this,
while logging a warning and erroring out when the user tries to queue
such a buffer.
2025-09-02 14:32:46 +00: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