Commit graph

13350 commits

Author SHA1 Message Date
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
David Härdeman
f33e1bc8c3 spa: alsa: autodetect supported iec958 codecs via ELD info
The alsa/acp code already supports getting a user-friendly monitor name
using the EDID-Like Data (ELD) information available from cards that follow
the Intel HDA specification.

This patch adds support for also parsing the SAD fields of the ELD, and
exposing the results as a "iec958.codecs.detected" property on the
corresponding node, which should make it possible to provide more
user-friendly configuration UIs and defaults.

The default value will take effect if the session manager does not set a
different value.

Brief example:
test@test:~/checkouts/pipewire$ pw-dump | grep -E "(iec958.codecs.detected|iec958.codecs)\":"
        "iec958.codecs": "[\"PCM\",\"AC3\",\"EAC3\",\"TrueHD\"]",
        "iec958.codecs.detected": "[\"PCM\",\"AC3\",\"EAC3\",\"TrueHD\"]",

<after powering on my receiver>

test@test:~/checkouts/pipewire$ pw-dump | grep -E "(iec958.codecs.detected|iec958.codecs)\":"
        "iec958.codecs": "[\"PCM\",\"DTS\",\"AC3\",\"EAC3\",\"TrueHD\",\"DTS-HD\"]",
        "iec958.codecs.detected": "[\"PCM\",\"DTS\",\"AC3\",\"EAC3\",\"TrueHD\",\"DTS-HD\"]",

Big thanks to Pauli Virtanen <pav@iki.fi>, who also wrote large paths of the
code for this patch.
2024-11-28 09:18:07 +01:00
Jonas Holmberg
0570d1dd00 filter-graph: Use biquad from audioconvert
Remove the biquad-implementation in filter-graph and use the one in
audioconvert instead.
2024-11-27 18:18:10 +01:00
Jonas Holmberg
e9092d7d2f core: Remove redundant declaration
Fix problem when building with -Werror=redundant-decls:

../src/pipewire/core.h:661:7: error: redundant redeclaration of ‘pw_core_get_user_data’ [-Werror=redundant-decls]
  661 | void *pw_core_get_user_data(struct pw_core *core);
      |       ^~~~~~~~~~~~~~~~~~~~~
../src/pipewire/core.h:446:7: note: previous declaration of ‘pw_core_get_user_data’ with type ‘void *(struct pw_core *)’
  446 | void *pw_core_get_user_data(struct pw_core *object);
      |       ^~~~~~~~~~~~~~~~~~~~~
2024-11-27 17:33:11 +01:00
Wim Taymans
0a0b1d594b audioconvert: use the same biquad as filter-chain 2024-11-27 16:47:53 +01:00
Wim Taymans
98365470c7 v4l2: set a clock name 2024-11-27 15:12:10 +01:00
Arun Raghavan
45eee02a99 module-rtp: Account for in-flight samples in RTP receive
When not using PTP as the driver, it is possible that packet receive and
the process() callback are out of sync, meaning that the target buffer
fill level might be off by upto one ptime's worth of samples
occasionally. This would make the DLL hunt for the target rate, and
cause a constantly varying delay.

Accounting for the delta between the packet receive time and the
process() time allows us to eliminate this jitter, resulting in much
more consistent rate matching.
2024-11-27 11:48:50 +00:00
Michael Olbrich
e76e057038 v4l2: ensure that the default frame rate is within the min/max bounds
Without this for continuous frame intervals, the default is set to 25
fps even if that is outside the min/max bounds (e.g. defined by the
peer).
Clip the default with the min/max bound to avoid this.
2024-11-27 11:46:26 +00:00
Michael Olbrich
669f53946e v4l2: handle min/max for continuous frame interval correctly
v4l2 frame intervals instead of frame rates, which is basically the
inverse. For the most part, this is already handled correctly and
numerator and denominator are swapped accordingly.

However, the minimim frame interval is the maximum frame rate so those
need to be swapped as well.

Without this, the minimum frame rate is larger than the maximum frame
rate for v4l2 devices that define a continuous frame interval.
2024-11-27 11:46:26 +00:00
Wim Taymans
89993a3cc6 gst: enable the pipewire ticks as a clock source
Use the pipewire ticks again as the clock source.

This was disabled because the v4l2 sources created bad ticks for the
graph. Now that this is improved we can enable the ticks again.

This has the advantage that simple audio playback does not drift
anymore. The only remaining problem would be timestamp drift or
discontinuities, which we don't handle here yet.
2024-11-26 17:23:00 +01:00
Wim Taymans
41e35c7b17 v4l2: use dll to track rate difference
Track the difference between the configured and real framerate and use
that as the rate correction to adjust the next_nsec clock field.
2024-11-26 17:14:26 +01:00
Wim Taymans
043245ca11 v4l2: set the NO_RATE clock flag
These sources have very inaccurate position/duration/rate information
that is not suitable for use as a clock so set the NO_RATE flag.
2024-11-26 17:05:20 +01:00
Wim Taymans
3f0fe0032f node: add a clock flag to mark rate/duration inaccurate
Some clocks (v4l2) don't process exactly process buffers at the given
rate/duration so mark this in the clock flags.

We need to use the nsec field in the clock to derive ticks in pw-stream
in that case to get a good clock.
2024-11-26 17:02:02 +01:00
Wim Taymans
ef8d2ab125 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-11-26 16:57:14 +01:00
Wim Taymans
25e06e5912 spa: remove some old includes 2024-11-26 13:30:58 +01:00
Wim Taymans
4d4607e62a doc: copy docs from the _methods struct 2024-11-26 13:21:04 +01:00
Wim Taymans
853c4783bc spa: inline some metadata functions 2024-11-26 12:46:58 +01:00
Wim Taymans
9fc33a6142 spa: add some more functions 2024-11-26 12:21:05 +01:00
Wim Taymans
d966a36fdd spa: compile all function into libspa.so 2024-11-26 11:58:51 +01:00
Wim Taymans
31802d4994 add per type API defines 2024-11-26 11:58:51 +01:00
Wim Taymans
b03f2f7afa make per object IMPL 2024-11-26 11:35:50 +01:00