Commit graph

4438 commits

Author SHA1 Message Date
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
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
Barnabás Pőcze
82b1ee1b8a hook: avoid macro expansion of the method names
Fixes #4491
2025-03-05 16:05:42 +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
Andrew Sayers
5ac432e5be Downgrade snd_pcm_mmap_commit error to warning 2025-01-23 10:42:43 +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
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
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
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
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
Arun Raghavan
ff63ca4d36 spa: alsa: Try to initialise card_index from path if needed
If the PCM is loaded directly using only api.alsa.path,
state->card_index may never be initialised, and then we end up opening
the wrong ctl device. Let's try a fallback for this case.
2024-11-26 10:01:11 +01:00
Wim Taymans
b409f5f5d1 v4l2: Add mmap fallback when USERPTR is not supported
When we don't support EXPBUF according to the probe, the host will
allocate memory for us. We will then try to use USERPTR to import the
memory into v4l2.

If this is not supported, try to fall back to MMAP support, mmap the
buffers and memcpy the MMAP buffer to the host allocated buffers.
2024-11-18 11:02:09 +01:00
Wim Taymans
7a0aea835a v4l2: improve debug a little 2024-11-18 11:01:39 +01:00
Wim Taymans
0056fdac83 v4l2: fix sign 2024-11-18 11:01:23 +01:00
Wim Taymans
4c487ea59d v4l2: use a separate flag to skip the first buffer
The buf.sequence value might stay to 0 (v4l2loopback)
2024-11-18 11:01:10 +01:00
Wim Taymans
cba2fad86b v4l2: probe number of buffers as well
Instead of just probing with 2 buffers, probe with the MAX_BUFFERS and
remember how many buffers we received.

Some drivers (v4l2loopback) work with less than MAX_BUFFERS (8) and we
need to set the max number of buffers in the Buffers param.
2024-11-18 11:00:58 +01:00
Wim Taymans
02c332bb78 alsa: handle the case where the driver is destroyed
When the driver node is destroyed (like when unplugging the cable) it
will drop/pause all of the follower ALSA nodes. This is something that
happens internally because of how the ALSA nodes work together, on the
PipeWire level, the nodes are still running and they will just be moved to
another driver.

The problem is that nothing will then start the nodes again after moving
it to the new driver. Fix this by keeping track of the desired target
state of the ALSA node and restoring that state when we detect that we are
paused when moved to a new driver.

Fixes #4401
2024-11-18 10:54:30 +01:00
Wim Taymans
0266b82e78 alsa: remove unused variable 2024-11-18 10:50:51 +01:00
Wim Taymans
c57f2345f3 keys: add lazy scheduling flags and docs 2024-11-11 15:03:43 +01:00
Wim Taymans
5759a88f27 v4l2: first probe and then update port flags
The probe is to decide it we can use EXPBUF or not and this is used to
decide on the flags.

This got broken with 842ac9e110
2024-11-07 11:20:32 +01:00
Wim Taymans
92c7c56e15 audioconvert: only output when there is something to output
Or else we get 0 sized output buffers.
2024-11-06 11:19:27 +01:00
Wim Taymans
00057d211f audioconvert: interchange the resampler loops
Iterate the channels in the inner loop instead of the outer loop. This
makes it handle with 0 channels better but also does the more
complicated phase increment code only once for all channels. Also the
filters might stay in the cache for each channel now.
2024-11-06 10:58:31 +01:00
Wim Taymans
cdb3c64753 json: improve infinite checks
Avoid compiler errors like this:

/usr/include/spa-0.2/spa/utils/json.h:417:25: error: comparing floating-point with '==' or '!=' is unsafe [-Werror=float-equal]
|   417 |                 if (val == INFINITY)
|       |                         ^~
2024-11-06 10:52:05 +01:00
Arun Raghavan
41b5c50c86 spa: audiotestsrc: Validate loop and system before using them
Makes sure we don't crash if those are not available (like with
DataSystem under spa-inspect).

Fixes: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4365
2024-11-06 10:49:51 +01:00
Wim Taymans
9a5bbbee00 alsa: clean up followers and our driver link in _clear
When we are going to be freed, make sure we remove ourself from the
driver list and also remove all the followers that we might still have.

Fixes #4355
2024-10-22 10:17:30 +02:00
Pauli Virtanen
5e47838f24 bluez5: don't exit if system DBus goes down
Similarly as in spa_dbus, don't exit if bus goes down.  Neither the
audio or midi Bluetooth backend reconnects to DBus, but they shouldn't
exit the process.
2024-10-21 10:30:56 +02:00
Pauli Virtanen
fb54fb94cc bluez5: add quirk for Phonak hearing aids 2024-10-21 10:26:36 +02:00
Pauli Virtanen
abfec78c51 bluez5: fix crash with broadcast sinks 2024-10-21 10:26:25 +02:00
Pauli Virtanen
5e0899b29e doc: backport docs from master branch to 1.2
Pick commits

doc: drop the links to configuration wiki pages
doc: rename pipewire-devices.7 and move stream properties into it
doc: document some more device properties
doc: move configuration index to a separate page
doc: document node/device disabled property
doc: add some small docs updates
docs: document negotiation of explicit sync
doc: remove duplicated entries, link to wireplumber docs
2024-10-12 11:35:56 +03:00
Wim Taymans
c132a67c7d adapter: increase max-retry to 64
When the follower doesn't produce enough data for this many attempts,
bail and cause an xrun to avoid an infinite loop.

The limit of 8 cause real-life problems and should be larger. It should
probably depend on the expected size per cycle (node.latency) and the
current quantum but we don't always have this information.

See #4334
2024-10-07 18:36:03 +02:00
Arun Raghavan
0cc6ac2769 acp: Trim trailing whitespace in monitor name from HDMI ELD
The ELD ends with a \n and spaces to pad the length, but most drivers
except NVidia trim that out while presenting to userspace. While this is
being tracked upstream [1], let's deal with this locally.

[1] https://github.com/NVIDIA/open-gpu-kernel-modules/pull/715

Fixes: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4332
2024-10-06 12:44:20 +02:00
Barnabás Pőcze
0a631d61e6 acp: do not overwrite properties of PCM with that of the card
The properties of the card might overwrite those of the PCM.
For example, the cards's `alsa.id` will be set on the PCM too
since 37a51533e0 ("acp: add more properties for the card").

To avoid that, call `pa_alsa_init_proplist_card()` first
in `pa_alsa_init_proplist_pcm_info()` instead of last.

See #4135
2024-10-06 12:41:55 +02:00
Wim Taymans
546acfc006 spa: fix event pod type 2024-10-02 16:24:55 +02:00
Wim Taymans
3ef6acdfb1 spa: avoid C23 empty initializers in the headers
Patch by Petar Popovic to avoid using empty initializers in headers.

Fixes #4317
2024-09-25 10:56:30 +02:00
Alper Nebi Yasak
351bc9ac3c acp: sync the mixer after selecting the port
Otherwise we might sync the wrong port and end up muted.

Fixes #4084
2024-09-25 10:18:33 +02:00
Wim Taymans
5bed12569d jack: Improve transport BBT handling
The bar can start from 0 in JACK.

Add bar_start_tick and ticks_per_beat to the io_segment_bar so that we
can losslesly store the complete jack BBT values.

See #4314
2024-09-25 10:18:15 +02:00