Commit graph

13220 commits

Author SHA1 Message Date
Barnabás Pőcze
1f06d00838 pw-container: fix indentation 2024-12-14 23:27:45 +01:00
Barnabás Pőcze
705c2a652b pipewire: module-vban: fix vban serial header
The expression `VBAN_PROTOCOL_SERIAL | vban_BPSList[14]` is assigned
to an 8 bit field of the header, but, `vban_BPSList[14]` being
115200, it does not fit. Instead, its index, 14, should be
placed in the header.

In addition to fixing the issue, add `-Werror=constant-conversion`,
and clang diagnostic that catches such issues.

Fixes: 1a5514e5cf ("module-vban: create streams per stream_name")
2024-12-14 23:09:45 +01:00
Pauli Virtanen
a4e2d9cbb0 bluez5: lc3: bump media_codec version 2024-12-14 10:57:23 +00:00
Pauli Virtanen
bf12fe6d8b bluez5: lc3: simplify parsing 2024-12-14 10:57:23 +00:00
Pauli Virtanen
8f1983d14c bluez5: lc3: fix log name conflict 2024-12-14 10:57:23 +00:00
Iulia Tanasescu
3309fa0674 doc: Document BAP LC3 codec audio capabilities
This documents the configurable values for the BAP LC3 codec capabilities.
2024-12-14 10:57:23 +00:00
Iulia Tanasescu
9a5b2d42f9 bluez5: Configure LC3 codec capabilities
Currently, the PipeWire daemon registers BlueZ LE Media Endpoints
with audio capabilities covering all settings defined in the BAP spec.
However, some scenarios might require the capabilities to be restricted
to specific configurations.

This adds a method to read LC3 codec specific capabilities from the
Wireplumber config file, and provide those settings when registering
Media Endpoint objects with BlueZ. If the values are not present in
the config file, all settings will be used by default.

Below is an example of how to set the LC3 capabilities in the config
file, to support the 16_2 setting from the BAP spec:

bluez5.bap-server-capabilities.rates = [16000]
bluez5.bap-server-capabilities.durations = [10]
bluez5.bap-server-capabilities.channels = [1, 2]
bluez5.bap-server-capabilities.framelen_min = 40
bluez5.bap-server-capabilities.framelen_max = 40
bluez5.bap-server-capabilities.max_frames = 2
2024-12-14 10:57:23 +00:00
Barnabás Pőcze
b5490954d0 spa: filter-graph: ladspa: add dl_lib dependency
The ladspa plugin uses `dlopen()`, etc. directly,
so add the `dl_lib` dependency. This is not necessary
in a new enough environment since newer glibc versions
have merged most things into libc.
2024-12-14 10:55:28 +00:00
Iulia Tanasescu
d6567ea6a2 doc: Add sync_factor config option
This adds the new "sync_factor" entry in the JSON for Broadcast Source
endpoint config parameters.
2024-12-14 10:54:38 +00:00
Iulia Tanasescu
cb000ad3dc bluez5: Configure sync_factor
For a BAP Broadcast Source endpoint, the QoS sync_factor enables the user
to adjust the Periodic Advertising interval based on the ISO interval
configured for the stream:

PA_Interval = sync_factor * ISO_Interval

Currently, this value is hardcoded to 2. This commit makes the sync_factor
configurable in the Wireplumber config file, along with the other config
parameters for BIGs.
2024-12-14 10:54:38 +00:00
Arun Raghavan
85fa0aae40 gst: src: Set possible_caps before stream connect
The value is used when a the format changes in handle_format_change(),
and while it seems this was typically expected to happen async and thus
protected by the thread lock, there are cases (such as with
auto-port-config) where a param might be set within the
pw_stream_connect() call itself (in the case of auto-port-config, by the
impl_init() of the audioadapter).
2024-12-13 13:44:09 +00:00
Barnabás Pőcze
ff75f550ad ci: add missing libebur128 dependency
The `build_all` job enables most features, including the ebur128
filter-graph plugin. However, the dependency is currently not
installed, which leads to meson failing to set up the build.

Fixes: df271d13f3 ("filter-chain: add ebur128 filter")
2024-12-10 22:18:46 +00:00
Barnabás Pőcze
69dcc7db7b 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")
2024-12-10 22:48:13 +01:00
Wim Taymans
94e823ddad filter-graph: add dcblock and ramp plugins 2024-12-09 15:00:35 +01:00
Wim Taymans
df271d13f3 filter-chain: add ebur128 filter
The EBU R128 filter measures the signal and generates LUFS control
notifications for further processing.

It also adds a plugin that can convert LUFS to a gain (based on a target
LUFS).

Also add an example filter-chain to enable the EBU R128 measurement and
how to use the results to adjust the volume dynamically.

See #2286 #222 #2210
2024-12-09 11:31:33 +01:00
Wim Taymans
f0f9fbb009 filter-graph: activate nodes after linking
Don't activate the nodes while linking but make a last stage where all
the nodes are activated. This makes it possible to better set up the
nodes based on the port data.
2024-12-09 11:30:05 +01:00
Wim Taymans
1bead99daf filter-graph: handle nodes with only control
It's possible to make a node with only control and notify so don't error
out on those nodes.
2024-12-09 11:30:05 +01:00
Wim Taymans
2b24b27f7f meson: move some filter-graph deps to spa
The filter-graph deps can now be in spa meson
2024-12-09 11:30:04 +01:00
Alper Nebi Yasak
507ec0b39a alsa-ucm: Set up hardware volumes again on duplicate port additions
While initializing ALSA cards with UCM, we call pa_alsa_ucm_add_port()
for each UCM device for each UCM verb. This checks if a port has been
already added by name and skips port initialization if it is already
done. Different UCM verbs can have devices with the same name, which
means their port names end up being the same. So, this port creation
step currently is only done for one UCM verb for both UCM devices.

Volume control setup is also part of this process. The UCM devices only
know about the volume mixer information from the UCM verb that they are
defined in, so the volume control setup is done for one UCM verb at a
time. Skipping this setup when a same-named port exists means only the
profiles belonging to the first initialized UCM verb have working
hardware volume control.

Move the volume control setup out of the port initialization block so
that we try to do it every time, therefore for every UCM verb. However,
check that we don't run it twice for the same UCM verb for a port.

In theory, the PlaybackVolume etc. value can be different per-verb
for the same device, so we can't simplify this code to a single volume
setup per port.

Link: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/840
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2024-12-07 18:32:48 +00:00
Pauli Virtanen
61f9018e15 spa: fix spa_api_method_null macro NULL checks
What may be NULL in these methods is the pointer to the object
containing the spa_interface, not the interface pointer itself.

Fixes spa-acp-tool crashing with NULL deref in spa_i18n.
2024-12-07 18:30:25 +00:00
Pauli Virtanen
2d30ab94c2 bluez5: account for codec internal delay in latency values
Encoders and some decoders have additional internal latency that needs
to be accounted for.

This mostly matters for AAC (~40ms), as the other BT codecs have much
lower delays (~5ms).
2024-12-07 18:28:17 +00:00
Pauli Virtanen
1b3b577b8f 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.
2024-12-07 18:25:53 +00:00
Martin Louazel
8ee1b4b614 context: fix erroneous clamping of quantum for high sample rates
When calculating the adjusted max quantum based off of max_latency, the
first multiplication can overflow uint32_t, leading to the quantum being
wrongfully clamped down.

Signed-off-by: Martin Louazel <martin.louazel@streamunlimited.com>
2024-12-07 18:24:07 +00:00
Pauli Virtanen
2bf48487cb bluez5: handle A2DP inverted ClearConfiguration/SetConfiguration order
When in A2DP sink role and remote end switches codec, BlueZ nowadays
appears sometimes emit first SetConfiguration (creating new transport),
and then ClearConfiguration (removing old transport).

Handle this case: emit profiles_changed event always when transports
come/go.

Redefine profiles_changed() to take bitmask of profiles whose connection
status changed, so we don't need to emit two remove+add events.
2024-12-06 16:36:14 +02:00
Arun Raghavan
5cbf3654c7 spa: alsa: Add a NULL check before updating rate match
The RateMatch IO might be NULL for the driver, and trying to update rate
matching with state->rate_match crashes in this case.
2024-12-05 13:08:04 -05:00
Alper Nebi Yasak
35dbaa840b alsa-ucm: Set icon names for mappings as well
Commit 88bb0bd7cc ("alsa: Allow to augment ucm port properties") adds
icon properties for some common port names, so that GUIs can show a
relevant icon to help disambiguate devices. However, these still do not
show up in pavucontrol, because it shows icons based on mappings'
properties. Add the relevant property to mappings as well.

Link: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/839
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2024-12-04 20:42:03 +00:00
Alper Nebi Yasak
e726c5f6db alsa-ucm: Fix possible segfault from recursion due to too many devices
While trying to figure out device subsets that have aren't internally
contain conflicting devices, we walk through all possible subsets and
check each set if it satisfies ConflictingDevices/SupportedDevices
listed in UCM configuration. For a better user experience, we want to
skip subsets that are fully included in another valid subset we will
also generate.

The iterate_device_subsets() function that achieves the former is
intentionally in iterative form to avoid a stack overflow, since it will
walk through 2^n sets. However, the iterate_maximal_device_subsets()
function that skips incomplete sets is in recursive form, as I had
assumed tail-call optimization would take care of the potential problem.

Convert iterate_maximal_device_subsets() to an iterative form, because
the recursion seems to trigger a segfault with more than 16 devices on
PulseAudio. It doesn't seem to happen on PipeWire, but it's better to
not leave it to luck.

Link: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/838
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2024-12-04 20:40:16 +00:00
Wim Taymans
f3a7f2c28e filter-graph: use SPA_MAX instead of fmaxf
fmaxf is a function unless compiled with special flags.
2024-12-04 16:40:53 +01:00
Wim Taymans
dc76254d03 filter-graph: fix compilation 2024-12-04 16:38:16 +01:00
Wim Taymans
6e2f631230 filter-graph: handle NULL data
Because the max plugin is marked as SUPPORTS_NULL, the input and output
pointers can be NULL. Handle these cases. Also reindent with tabs (not 7
spaces).
2024-12-04 16:30:33 +01:00
Jonas Holmberg
7f80711158 filter-graph: Make builtin plugin compile 2024-12-04 14:05:57 +01:00
Torkel Niklasson
bfb5ae18d1 filter-chain: add max builtin plugin
add max which takes two inputs and output the max value of them. it can
e.g. be used to create the same sidechain input to two mono limiters.
2024-12-04 13:17:36 +01:00
Barnabás Pőcze
a71cd05401 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.
2024-12-03 20:54:20 +01:00
Wim Taymans
e2a0d720f9 alsa: reduce debug level that got accidentally increased 2024-12-03 16:44:45 +01:00
Wim Taymans
a4b553f3d4 spa: serialize in_thread flushes with a mutex
When we have no thread running the loop, we need to flush the queues
from the invoking thread. Make sure that when multiple threads attempt
this that we serialize the flushing because the flushing code is not
thread safe.
2024-12-03 16:38:28 +01:00
Wim Taymans
1274bc2c42 filter-graph: handle IR length of 0
When the IR is 0 length, make sure we copy the DSP to the convolver
because we will use it to clear memory.

Pass the dsp to the head and tail convolvers functions because they
might be NULL and we need the dsp to clear memory.

Fixes #4433
2024-12-03 15:37:00 +01:00
Jonas Holmberg
5796013b35 filter-graph: Fix double spa_handle_clear()
Don't explicitly call spa_handle_clear() in plugin_unref() since it is
called from spa_plugin_loader_unload() too.
2024-12-03 15:15:49 +01:00
Wim Taymans
31c240f6b8 docs: update some LAC links 2024-12-03 13:25:29 +01:00
Wim Taymans
4c8886f5dc context: use timestamp for load-balancing of loops
We increment the refcount of the loop when we hand it out. We use this
refcount to do some load balancing. In some cases we also decrease the
refcount again when the release_loop() functions is called but we only do
this in some modules. The result is that in most cases the refcount
just keeps on going up and this is misleading.

Change the refcount to a last_used timestamp and prefer to use loops
that have not been used in a while.

Fixes #4436
2024-12-03 13:01:36 +01:00
Wim Taymans
498aea661e spa: fix some param type info
Add an int array type and use this in the route properties.

Fixes #4441
2024-12-03 12:42:31 +01:00
Wim Taymans
0658ff93d8 gst: add slave-method property
Set the slave-method to none by default to disable the resampler.
2024-12-03 12:11:47 +01:00
Wim Taymans
9419a12e74 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:11:47 +01:00
Wim Taymans
22f0b858b1 alsa: improve target bandwidth calculation
Also use the average error to calculate the bandwidth. If we are not
around 0, we should increase the bandwidth.
2024-12-03 12:11:20 +01:00
Taruntej Kanakamalla
922efaf6ed gst: drop empty buffers in pipewiresrc
In case the dequeued buffer is empty or of size 0, skip the buffer
so that the downstream elements do not report an error
2024-12-02 14:15:23 +05:30
Pauli Virtanen
46c89f1e0c bluez5: improve decode-buffer latency accuracy
Interpolate buffer level to current playback position, and change its
definition so it directly corresponds to the total buffer latency.  This
is also a bit simpler.
2024-12-01 23:05:27 +02:00
Pauli Virtanen
41ca76685c bluez5: media-source: account for sink latency for BAP
BAP delay to rendering should be constant, so take sink latency into
account when selecting the buffer level.
2024-12-01 20:14:36 +02:00
Pauli Virtanen
2847d90b4b bluez5: report latency to rendering when in A2DP sink role
Now that BlueZ supports delay reporting in A2DP sink role, implement
that.

Report value that gives the total latency between packet reception and
audio rendering.

Also make Latency parameter in media-source to be not just a dummy
value.
2024-12-01 20:14:36 +02:00
Arun Raghavan
7bc84305e6 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-11-29 12:12:28 -05:00
Arun Raghavan
4c09451e77 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-11-29 10:55:39 -05:00
Pauli Virtanen
371781e214 pulse-server: fix pulse.cmd load-module not loading multiple overrides
pw_context_conf_section_for_each() stops iterating on nonzero return
value, so make sure 0 is returned on success.
2024-11-28 19:34:22 +00:00