Commit graph

13584 commits

Author SHA1 Message Date
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
8f35e18d18 systemd: remove RestrictNamespaces from service file
Wireplumber loads the libcamera nodes into the pipewire server.
We need to remove the RestrictNamespaces option from the service file
to allow libcamera to load sandboxed IPA modules.
2025-09-17 10:29:35 +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
Wim Taymans
24ab601201 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:33:14 +02:00
Wim Taymans
3e574b314a Revert "impl-node: improve the node unprepare function"
This reverts commit 839383d0dd.
2025-09-15 10:32:56 +02:00
Wim Taymans
8b43ed5c91 1.4.8 2025-09-11 10:12:34 +02:00
Wim Taymans
67a541eac5 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-11 09:48:21 +02:00
Wim Taymans
839383d0dd 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-10 10:30:30 +02:00
Barnabás Pőcze
08dcd3a83a 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-10 10:29:53 +02:00
Barnabás Pőcze
31151dbb97 pipewire: mem: log page size on creation 2025-09-10 10:29:46 +02:00
Barnabás Pőcze
7eceaf360e pipewire: mem: forward declare spa_hook
This type is used in function arguments, so forward declare it.
2025-09-10 10:29:34 +02:00
Barnabás Pőcze
f5da303c9f 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-10 10:29:27 +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
f0629fa8be spa: fix typo in raw-types for LLFE
Spotted by Nikolai

Fixes #4881
2025-09-10 10:21:10 +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
6dbef07e72 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-10 10:19:35 +02:00
Wim Taymans
d48c012715 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-10 10:19:29 +02:00
Jonas Ådahl
4ec9994bf0 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-10 10:19:20 +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
fabfdb1b01 v4l2: delay pipewire init until first openat call
Initialization of PipeWire could happen too early and deadlock in some
cases. Instead, initialize pipewire right before we're going to actually
use it for the first time.

Fixes #4859
2025-09-10 10:18:27 +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
Robert Mader
52852f66cb systemd: Allow mincore syscal for Mesa/EGL
This is required in order to allow plugins to use GL as mincore
is used in Mesas `_eglPointerIsDereferenceable()`.

One example for a client wanting to do so is the in-development
libcamera GPUISP, see https://patchwork.libcamera.org/cover/24183/
2025-09-10 10:16:24 +02:00
Wim Taymans
1efd76455f ump: make sure we set the group correctly 2025-09-10 10:15:44 +02:00
Wim Taymans
6a44b2e10f raop: write ALAC end tag
Fixes #4853
2025-09-10 10:14:57 +02:00
alexdlm
ee0809ead9 Map Razer BlackShark v3 ACP 2025-09-10 10:12:37 +02:00
Wim Taymans
f0cfe9449d tools: dump sndfile loginfo on error when verbose 2025-09-10 10:12:00 +02:00
Arun Raghavan
487c7ee933 tools: Fix -C handling for pw-dump
The short form needs to have a :: to signal an optional argument so
that something like -Calways can work.
2025-09-10 10:11:36 +02:00
Barnabás Pőcze
1c032f6ad6 pipewire: module-link-factory: cancel async work in link's destroy event
When a link enters the "ERROR" state, it is scheduled for destruction in
`module-link-factory.c:link_state_changed()`, which queues `destroy_link()`
to be executed on the context's work queue.

However, if the link is destroyed by means of `pw_impl_link_destroy()`
directly after that, then `link_destroy()` unregisters the associated
`pw_global`'s event hook, resulting in `global_destroy()` not being called
when `pw_impl_link_destroy()` proceeds to call `pw_global_destroy()` some
time later. This causes the scheduled async work to not be cancelled. When
it runs later, it will trigger a use-after-free since the `link_data` object
is directly tied to the `pw_impl_link` object.

For example, if the link is destroyed when the client disconnects:

==259313==ERROR: AddressSanitizer: heap-use-after-free on address 0x7ce753028af0 at pc 0x7f475354a565 bp 0x7ffd71501930 sp 0x7ffd71501920
READ of size 8 at 0x7ce753028af0 thread T0
    #0 0x7f475354a564 in destroy_link ../src/modules/module-link-factory.c:253
    #1 0x7f475575a234 in process_work_queue ../src/pipewire/work-queue.c:67
    #2 0x7b47504e7f24 in source_event_func ../spa/plugins/support/loop.c:1011
    [...]

0x7ce753028af0 is located 1136 bytes inside of 1208-byte region [0x7ce753028680,0x7ce753028b38)
freed by thread T0 here:
    #0 0x7f475631f79d in free /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:51
    #1 0x7f4755594a44 in pw_impl_link_destroy ../src/pipewire/impl-link.c:1742
    #2 0x7f475569dc11 in do_destroy_link ../src/pipewire/impl-port.c:1386
    #3 0x7f47556a428b in pw_impl_port_for_each_link ../src/pipewire/impl-port.c:1673
    #4 0x7f475569dc3e in pw_impl_port_unlink ../src/pipewire/impl-port.c:1392
    #5 0x7f47556a02d8 in pw_impl_port_destroy ../src/pipewire/impl-port.c:1453
    #6 0x7f4755634f79 in pw_impl_node_destroy ../src/pipewire/impl-node.c:2447
    #7 0x7b474f722ba8 in client_node_resource_destroy ../src/modules/module-client-node/client-node.c:1253
    #8 0x7f47556d7c6c in pw_resource_destroy ../src/pipewire/resource.c:325
    #9 0x7f475545f07d in destroy_resource ../src/pipewire/impl-client.c:627
    #10 0x7f47554550cd in pw_map_for_each ../src/pipewire/map.h:222
    #11 0x7f4755460aa4 in pw_impl_client_destroy ../src/pipewire/impl-client.c:681
    #12 0x7b474fb0658b in handle_client_error ../src/modules/module-protocol-native.c:471
    [...]

Fix this by cancelling the work queue item in `link_destroy()`, which should
always run, regardless of the ordering of events.

Fixes #4691
2025-09-10 10:09:16 +02:00
Wim Taymans
9e8f50e3ef jack: emit port_rename callbacks
When the port is renamed, we queue a PORT_RENAME callback with an arg1
as 1. Before emitting the event we check the registered state of the
port but we want to suppress the event if the port was *not* registered,
ie. when the registered state != 1 (arg1).
2025-09-10 10:08:59 +02:00
Wim Taymans
acf463050d jack: only update port name for other ports
Don't try to check for renames of our own port, we cause that
ourselves.

Also use the name of the port to find our ports.
2025-09-10 10:08:17 +02:00
Wim Taymans
e3fd6fac49 jack: support port_rename callbacks
Look at the port name in the port_info properties and emit the
port_rename callback when it changes.

Fixes #4761
2025-09-10 10:08:06 +02:00
Wim Taymans
f5c3d0d29a midifile: fix seeking in midifile
When we perform a seek, we need to update the current position in the
file as well or we calculate wrong offsets.
2025-09-10 10:05:31 +02:00
Pauli Virtanen
165bd9965b alsa: show correct value in api.alsa.period-num 2025-09-10 10:04:30 +02:00
Wim Taymans
23b0ff136a vban: truncate sess.name when too large 2025-09-10 09:39:23 +02:00
Christian Glombek
9695fafc06 raop: don't set improper media.format 2025-08-25 12:57:24 +02:00
Christian Glombek
f81d733644 raop: set mtu to 1448 by default 2025-08-25 12:57:17 +02:00
Christian Glombek
30df4e70d0 raop: Add fp_sap25 encryption type
Add support for FairPlay SAP v2.5 (encryption type 5) type devices such as Apple Home Pod Minis.

Apparently only these devices require the `POST /feedback` heartbeat, so fix that.
2025-08-25 12:56:38 +02:00
Wim Taymans
1c542e9a0c 1.4.7 2025-07-23 17:42:58 +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