Commit graph

12822 commits

Author SHA1 Message Date
Wim Taymans
91a1ce183f 1.2.8 2025-07-23 15:01:47 +02:00
Wim Taymans
418b7198ee resample: optimize phase scaling
Precalculate the constant factor to avoid a division for each sample.
2025-07-23 14:59:25 +02:00
Wim Taymans
bacaec1a48 resample: fix compilation
Also fix a compiler warning in clang
2025-07-23 14:59:18 +02:00
Wim Taymans
aef595b5bf 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:59:15 +02:00
Wim Taymans
f31504fdc9 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:59:11 +02:00
Wim Taymans
f515f12916 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:58:57 +02:00
Wim Taymans
4d684a6384 raop: fix byte array initialization
Initialize the byte array with bytes instead of a string because the 0
byte at the end of the string does not fit in the array and causes a
compiler warning.
2025-07-22 16:09:06 +02:00
Wim Taymans
d23b479aaf client-node: close SyncObj fd as well
We also need to close the SynObj fd we got, just like we close any
DmaBuf or MemFd.

Make sure we get a compiler error when we add more items to the
data type enumeration later.

Fixes #4807
2025-07-22 16:09:06 +02:00
Pauli Virtanen
0833b0e790 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-11 10:31:23 +03:00
Wim Taymans
8c202a8307 Revert "loop: don't call the hooks around blocking wait"
This reverts commit 09fafdfc01.
2025-07-03 19:52:14 +02:00
Wim Taymans
09fafdfc01 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:30:42 +02:00
Wim Taymans
68d0cd2fbb 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 12:30:38 +02:00
Wim Taymans
0d1a18c054 pod: handle builder overflows
When the builder is overflowed, we might get a NULL pod. This is a valid
situation that we need to handle because it can be used to get the
required builder buffer size.
2025-04-14 12:48:16 +02:00
Wim Taymans
7d4079b285 v4l2: handle nearest set_format
The set_format function can return 1 when the format was adjusted to the
nearest supported format so return this from the port_set_param
function.

This instructs the adapter to recheck the configured format so that it
can store the adjuted format on the converter.
2025-04-14 12:47:49 +02:00
Wim Taymans
f97e131d96 netjack2: fix the large midi events offset
The midi events have their large data offsets relative to the start of
the buffer and the large data is at the end of the buffer. Because we
copied it down, right after the events, but we didn't adjust the
offsets, calculate a correction offset when unpacking the events.
2025-04-14 12:44:10 +02:00
Wim Taymans
d375b374f7 netjack2: set correct max midi buffer size
It depends on the negotiated period size, not the graph quantum.
2025-04-14 12:41:11 +02:00
Wim Taymans
86a492cf98 netjack2: copy large midi events to the end of the buffer
There is no need to keep an extra free byte at the end and it will cause
us to lose a byte when we copy the large midi events down.
2025-04-14 12:40:32 +02:00
Wim Taymans
0e7f39a3d3 rtp-sdp: format ptime in the C locale
Don't place locale dependent strings in the SDP.

Fixes #4615
2025-04-14 12:33:27 +02:00
Robert Mader
4847e3ad6e systemd: Depend on dbus.service
Solution suggested by Xi Ruoyao.

The dbus user service is required for various features - the summary says:
'dbus (Bluetooth, rt, portal, pw-reserve)'

On session logout the dbus service gets shut down while the Pipewire one
relies on a timeout. If a user logs in again before PW timed out, the
later stays alive but doesn't handle re-connecting to the dbus service
of the new session, breaking the camera portal and potentially other
features.

Thus hard-depend on the dbus service (if enabled at build time) and thus
shut down together with it.

(cherry picked from commit 2625983a23)
2025-03-20 14:09:10 +01:00
msizanoen
a909f6cb69 systemd: Disable pipewire user services for root
The `access(2)` based multi-user mediation mechanism doesn't quite work
for the root user, which may cause it to conflict with a running
foreground user session. Prevent this by not running the user service at
all for the root user, which nobody should be doing anyway.

(cherry picked from commit 9bc29b4b37)
2025-03-20 14:08:58 +01:00
Barnabás Pőcze
82b1ee1b8a hook: avoid macro expansion of the method names
Fixes #4491
2025-03-05 16:05:42 +01:00
Wim Taymans
b5a9974795 module-rtp: don't confuse time and samples
Round down the target_buffer size to a psamples multiple. Don't try to
mix time and sample units for this.

Fixes #4327
2025-02-17 15:55:32 +01:00
Pauli Virtanen
73488ee338 bluez5: backend-native: update HFP SDP records
Advertise SWB since we implement it.  Update HFP version to 1.9
accordingly.
2025-02-14 19:25:42 +02:00
Pauli Virtanen
c5e57a062d bluez5: aac: work around devices setting multiple bits in caps
Airpods don't follow the specification and set multiple bits in AAC
object type, including the ELD bit, but actually want AAC-LC.  So check
the AOT in the right order.
2025-02-14 19:15:11 +02:00
Pauli Virtanen
1f5c31dbc4 spa: alsa: do not allow setting Route that is not in current profile
When setting Route param, check that the route actually is part of the
active profile.

Also, check that the device given corresponds to the given route, before
setting properties. acp_device_set_port() also checks this, but we
shouldn't allow updating properties of Routes in non-active profiles.

Setting ports or applying props on devices not part of the profile can
do unexpected things e.g. alter mixer settings.
2025-02-12 18:17:30 +02:00
Barnabás Pőcze
6262717c6f spa: libcamera: don't use fixed size buffers for properties
Use `std::string` and `std::ostringstream` when processing the
camera properties, in order to avoid truncation.

See !2095
See !2268
2025-02-06 15:08:26 +01:00
Barnabás Pőcze
fbc1589ffe spa: libcamera: use references when getting camera properties
The argument is not nullable, so use a const lvalue reference
to express that clearly.
2025-02-06 15:08:17 +01:00
Wim Taymans
80c548edb2 stream: fix id and status swap 2025-02-06 15:07:03 +01:00
Michael Tretter
aca566a02d stream: clear buffer from io when clearing buffers
If a provider uses the stream API and pushes a buffer to the stream
after the stream is set to paused, the buffer_id of the last buffer
remains in the io.

If a consumer starts streaming in this state, the buffer_id of the old
buffer is still in the io. The consumer receives a stale buffer_id and
may discard the buffer. Now the buffer is lost, since it is still marked
as busy on the producer.

This can be reproduced by starting Weston with the PipeWire backend and
repeatedly restarting a GStreamer pipeline that connects to the Weston
output. Eventually Weston won't be able to dequeue buffers since the
lost buffer is still busy.

Clear the buffers in the io when the buffers are cleared to avoid
sending an old buffer_id to the consumer.
2025-02-06 15:06:48 +01:00
Andrew Sayers
5ac432e5be Downgrade snd_pcm_mmap_commit error to warning 2025-01-23 10:42:43 +01:00
Wim Taymans
6cffc887c3 rtp-source: avoid bitfield races
The different bits are written to from different threads.
2025-01-23 10:42:15 +01:00
Wim Taymans
09a2b32d1e pulse-server: clear old data when jumping forwards
When we write samples, check if we make a jump in the ringbuffer and
clear the samples we jumped over.

If we don't do this, the reader side might pick up old samples that we
didn't write or clear but that are now available for reading after we
made a jump in the ringbuffer.

This migh not be exactly what pulseaudio does but it is good for now.

Fixes #4464
2025-01-23 10:40:58 +01:00
Wim Taymans
2c3075f430 pulse-server: make a function to silence a buffer 2025-01-23 10:40:49 +01:00
Wim Taymans
fc3fb470f7 network-utils: handle inet_ntop errors 2025-01-23 10:39:00 +01:00
Wim Taymans
b8d89f5a2e pulse-server: increase max rate to 768000
Fixes #4482
2025-01-23 10:37:49 +01:00
Barnabás Pőcze
2d43b6b515 pipewire-jack: fix property list underallocation
`(n_items) + 1 * sizeof(*items)` is not the correct size to allocate
for `n_items + 1` count of objects each with size `sizeof(*items)`,
the `+ 1` should be inside the parentheses.

Fixes #4481
Fixes: 4baa94fce2 ("thread: make it possible to set a custom create function")
2025-01-23 10:37:23 +01:00
Barnabás Pőcze
4fa78021c7 spa: debug: pod: print unsigned numbers as unsigned
Both `spa_rectangle` and `spa_fraction` store unsigned numbers,
so print them as unsigned, the same way it is already done in
`spa_debug_strbuf_format_value()`.
2025-01-23 10:37:10 +01:00
Barnabás Pőcze
1c2fe03498 pipewire: context: pw_context_find_format(): fix stack use-after-free
Since fc49c1697a ("context: improve negotiation") it is possible
that the out parameter `format` will be set to `filter`. However,
`filter` is a SPA POD from the local SPA POD builder `fb`, which
references the local buffer `fbuf`.

In those cases, if the callers then make use of the returned SPA POD,
a stack use-after-free happens, such as the one displayed below.

The issue could be reliably triggered by executing the `video-play`
example program, and then trying to use the same camera in firefox.
As seen below, the input node, firefox's, provides no format preference,
causing the output format to be used. Previously, this had led
to the use-after-free described above.

pw.link    | [impl-link.c: 130 link_update_state()] (46.0.1 -> 114.0.0) init -> negotiating (paused-configure)
pw.context | [  context.c: 935 pw_context_find_format()] 0x51e000000080: finding best format 3 1
pw.context | [  context.c: 943 pw_context_find_format()] 0x51e000000080: states 3 1
pw.context | [  context.c: 958 pw_context_find_format()] 0x51e000000080: Got output format:
pw.context | [  context.c: 959 pw_context_find_format()]  video/raw
pw.context | [  context.c: 959 pw_context_find_format()]            format : (Id) YUY2
pw.context | [  context.c: 959 pw_context_find_format()]              size : (Rectangle) 640x480
pw.context | [  context.c: 959 pw_context_find_format()]         framerate : (Fraction) 30/1
pw.context | [  context.c: 966 pw_context_find_format()] 0x51e000000080: no input format filter, using output format: Success
=================================================================
==418404==ERROR: AddressSanitizer: stack-use-after-return on address 0x73993ee46200 at pc 0x739941d31020 bp 0x7fff526b4670 sp 0x7fff526b4660
READ of size 4 at 0x73993ee46200 thread T0
    #0 0x739941d3101f in spa_pod_builder_raw ../spa/include/spa/pod/builder.h:150
    #1 0x739941d3b35d in do_negotiate ../src/pipewire/impl-link.c:294
    #2 0x739941d46214 in check_states ../src/pipewire/impl-link.c:727
    #3 0x739941f14405 in process_work_queue ../src/pipewire/work-queue.c:64
    #4 0x73993d0dbe99 in source_event_func ../spa/plugins/support/loop.c:894
    #5 0x73993d0d6881 in loop_iterate ../spa/plugins/support/loop.c:727
    #6 0x739941d76b05 in spa_loop_control_enter ../spa/include/spa/support/loop.h:264
    #7 0x739941d76d93 in spa_loop_control_leave ../spa/include/spa/support/loop.h:268
    #8 0x739941d78946 in pw_main_loop_quit ../src/pipewire/main-loop.c:109
    #9 0x5a64b3cb1cec in main ../src/daemon/pipewire.c:130
    #10 0x739940c34e07  (/usr/lib/libc.so.6+0x25e07) (BuildId: 98b3d8e0b8c534c769cb871c438b4f8f3a8e4bf3)
    #11 0x739940c34ecb in __libc_start_main (/usr/lib/libc.so.6+0x25ecb) (BuildId: 98b3d8e0b8c534c769cb871c438b4f8f3a8e4bf3)
    #12 0x5a64b3caf3b4 in _start (/pipewire/build/src/daemon/pipewire+0x173b4) (BuildId: f9e8403a377e28bf8bd9cf0a5b89d33f08499917)

Address 0x73993ee46200 is located in stack of thread T0 at offset 512 in frame
    #0 0x739941c6ed5e in pw_context_find_format ../src/pipewire/context.c:907

  This frame has 15 object(s):
    [...]
    [432, 480) 'fb' (line 911)
    [512, 4608) 'fbuf' (line 912) <== Memory access at offset 512 is inside this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-use-after-return ../spa/include/spa/pod/builder.h:150 in spa_pod_builder_raw
    [...]

Fixes: fc49c1697a ("context: improve negotiation")
2025-01-23 10:33:03 +01:00
Barnabás Pőcze
de609ff994 spa: v4l2: query_ext_ctrl_ioctl(): only check errno on failure
`errno` is not guaranteed to be cleared, so only check it if
the previous call actually failed.
2025-01-23 10:27:43 +01:00
Taruntej Kanakamalla
0549996c87 gst: deviceprovider: allow pulseaudio and exclude pipewire for audio
Don't hide pulsedeviceprovider so pulsesink/src are listed by the device provider
and exclude pipewire's audio devices in its deviceprovider.
Continue showing video devices in pipewiredeviceprovider, so that pipewiresrc is
listed for the video devices
2025-01-20 16:36:07 +05:30
Wim Taymans
223569dc4a spa: initialize all fields explicitly
Patch by Petar Popovic

Fixes #4325

(cherry picked from commit 0ca64277b3)
2024-12-14 10:59:12 +00:00
Wim Taymans
8d9269374d filter-chain: handle 0 length IR
Make sure we copy the DSP functions in the convolver before leaving the
function because we need them to clear memory.

Don't store the DSP functions in the head and tail convolvers but pass
them from the main convolver because the convolvers might be NULL but we
still need the DSP functions to clear memory.

Fixes #4433
2024-12-03 15:43:56 +01:00
Wim Taymans
e42de413e8 spa: fix some param type info
Add an int array type and use this in the route properties.

Fixes #4441
2024-12-03 12:41:07 +01:00
Wim Taymans
91e26d6011 gst: add slave-method property
Set the slave-method to none by default to disable the resampler.

Fixes #4374
2024-12-03 12:29:07 +01:00
Wim Taymans
1e2b7f7c00 gst: add rate control to the sink
Track the elapsed time between buffers and try to keep the buffer fill
level constant by changing the rate of the stream.

See #4374
2024-12-03 12:29:07 +01:00
Wim Taymans
938283aee4 gst: mark the pipewiresink as EARLY_PROCESS
We want to receive process callbacks as soon as a buffer is ready for
reuse because we dequeue it for use in our buffer pool.
2024-12-03 12:29:07 +01:00
Arun Raghavan
a6019e6dd7 spa: alsa: Don't assume all PCMs have a card
dmix/dsnoop devices, for example, don't have an associated card, so all
the card-related checks don't make sense. Let's explicitly deal with
this case.

Fixes: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4432
2024-12-02 11:52:10 -05:00
Arun Raghavan
1993383ddf spa: alsa: Fix key name suggestion in log message
We use api.alsa.pcm.card to look up the PCM's card if we don't know it
by other means.
2024-12-02 11:52:08 -05:00
Wim Taymans
cc7439187f 1.2.7 2024-11-26 10:07:54 +01:00
Pauli Virtanen
858f6f3210 pw-dump: don't emit remove events when not monitoring
When pw-dump is called without --monitor, it should output exactly one
JSON array, and no remove event indicators.
2024-11-26 10:01:52 +01:00