Commit graph

3631 commits

Author SHA1 Message Date
Wim Taymans
77ed5ccb31 spa: give meaning to port_enum_params with SPA_ID_INVALID port_id
This is to iterate params that are common to all ports, such as
EnumFormat or the supported IO areas. Mostly interesting for mixer and
splitter nodes so that we don't have to create a new port just to query
things.
2024-04-17 12:49:13 +02:00
Wim Taymans
b97c6e2eac audioconvert: also clamp monitor volume to min/max
When we set a min/max value, also clamp the monitor volume to it.

Fixes #3962
2024-04-15 16:28:24 +02:00
Pauli Virtanen
cd166ac899 bluez5: don't use spa_invoke from data loop to main loop
spa_loop_invoke from data loop to main loop is not OK, as Wireplumber
currently runs its main loop with "pw_loop_enter(); pw_loop_iterate();
pw_loop_leave();" which causes the loop to be entered only when it is
processing an event.

In this case, part of the time the loop impl->thread==0, and calling
spa_loop_invoke() at such time causes the callback to be run from the
current thread, ie. in this case data loop which must not happen here.

Fix this by using eventfd instead, which is safe as the callback always
runs from the main loop.

Eventfd is also slightly more natural here, as multiple events will
group to the same mainloop cycle.
2024-04-13 15:54:22 +03:00
Wim Taymans
37a8dd5cb3 bluez: initialize variable to avoid warning 2024-04-12 18:14:54 +02:00
Pauli Virtanen
a6dcdfae0c bluez5: iso-io: track and apply corrections to tx latency
Use TX timestamps to get accurate reading of queue length and latency on
kernel + controller side.

This is new kernel BT feature, so requires kernel with the necessary
patches, available currently only in bluetooth-next/master branch.
Enabling Poll Errqueue kernel experimental Bluetooth feature is also
required for this.

Use the latency information to mitigate controller issues where ISO
streams are desynchronized due to tx problems or spontaneously when some
packets that should have been sent are left sitting in the queue, and
transmission is off by a multiple of the ISO interval.  This state is
visible in the latency information, so if we see streams in a group have
persistently different latencies, drop packets to resynchronize them.

Also make corrections if the kernel/controller queues get too long, so
that we don't have too big latency there.

Since BlueZ watches the same socket for errors, and TX timestamps arrive
via the socket error queue, we need to set BT_POLL_ERRQUEUE in addition
to SO_TIMESTAMPING so that BlueZ doesn't think TX timestamps are errors.

Link: https://github.com/bluez/bluez/issues/515
Link: https://lore.kernel.org/linux-bluetooth/cover.1710440392.git.pav@iki.fi/
Link: https://lore.kernel.org/linux-bluetooth/f57e065bb571d633f811610d273711c7047af335.1712499936.git.pav@iki.fi/
2024-04-12 18:50:15 +03:00
Pauli Virtanen
9165291c43 bluez5: iso-io: drop RX data when source is not running
When media-source is not running, we need to drop any RX data so that
there is room in the socket buffer for the latency reporting.
2024-04-12 18:31:26 +03:00
Pauli Virtanen
4f91f0bcb0 bluez5: move spa_bt_ptp to rate-control.h 2024-04-12 18:31:26 +03:00
Pauli Virtanen
cfb29af672 bluez5: bap: use priority from conf table in PAC selection 2024-04-12 18:31:26 +03:00
Wim Taymans
61af61a4b3 v4l2: handle empty properties gracefully
When a property is not found or is empty, go on to the next format
instead of failing.

See #3959
2024-04-10 11:06:44 +02:00
columbarius
c223e02d9b vulkan: Complete vulkan_pass
vulkan_pass now contains everything required for a single blit pass.
2024-04-09 09:05:03 +00:00
columbarius
11ff1471e9 vulkan: Cache buffer_type
All buffers should have the same type.
2024-04-09 09:05:03 +00:00
columbarius
f935a191ad vulkan: Move vulkan_pass handling to filter
The current buffers are directly tracked by vulkan_pass.
2024-04-09 09:05:03 +00:00
columbarius
75daa140f3 vulkan: Split buffer import into CPU and GPU part 2024-04-09 09:05:03 +00:00
columbarius
3f47825082 vulkan: Introduce vulkan_pass for blit operations 2024-04-09 09:05:03 +00:00
columbarius
522546e8d3 vulkan: Sync buffers on in and export in blit 2024-04-09 09:05:03 +00:00
columbarius
f10e8d2717 vulkan: Export functions to handle implicit_fd 2024-04-09 09:05:03 +00:00
Martin Geier
5c8799a480 alsa-pcm: set threshold to final value before set_swparams is called
This patch fixes use case, when disable_tsched is set and
api.alsa.period-size is set to value different from default quantum size.

In a such configuration, threshold needs to be set to a final value
before snd_pcm_sw_params_set_avail_min is called to get IRQs with
right timing.

Avail minimum is calculated from a threshold set in the check_position_config.
The method returned different value for threshold right before playback
started and after the playback started. Therefore threshold used in
the snd_pcm_sw_params_set_avail_min was incorrect.

Force the check_position_config to use configured values when called
from spa_alsa_prepare as this method is called when starting new playback
and the state->period_frames and the state->rate are already known.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2024-04-09 09:03:49 +00:00
Martin Geier
4c11a2aa9a alsa-pcm: start playback immediately if there is start delay set
Without this change, playback_ready or capture_ready was called
immediately after spa_alsa_start even tho start-delay was set.
Ready function was called with not precise "nsec" value, as "nsec"
plus latency should return time when the next buffer should be played
which wasn't true as start-delay was not included.

Now the playback is started immediately when the start_delay is set.
The alsa_do_wakeup_work is still called immediately but two things can
happened. Either start-delay is smaller then max_error and *_ready
function is called immediately, or start-delay is bigger then max_error
and state->next_time will be updated to correct value.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2024-04-09 09:03:49 +00:00
Martin Geier
1e6dad14d3 alsa-pcm: use headroom to calculate minimum available frames for non time scheduling
Alsa needs to call handler soon enough to have headroom plus threshold
frames in the buffer and not only threshold left.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2024-04-09 09:03:49 +00:00
Martin Geier
b4ed8dcf14 alsa-pcm: do not allow headroom plus threshold be bigger then the alsa buffer
Headroom are extra samples available in alsa buffer on top of a threshold.
Its use to prefill alsa buffer with silence before the playback starts
and later its use to calculate target number of a frames in the alsa buffer
when get_status is called. Target is calculated as headroom plus
threshold, which should be smaller then buffer size to make sense.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
2024-04-09 09:03:49 +00:00
Carlos Rafael Giani
695f236f5f alsa-compress-offload-device: notify observers when profile changes
Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
2024-04-09 09:03:49 +00:00
Martin Geier
d6184bd9bb alsa-pcm-device: notify observers when profile changes
Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2024-04-09 09:03:49 +00:00
columbarius
7206980023 vulkan: Sync renderer for blit filters
A spa_node has callback both on the main and data thread, which can
modify the internal state of vulkan_blit_state. Especially critical are
functions, which might drop buffers currently in use. To mitigate this
a read-write lock is used. The data thread shall try to aquire a read
lock before accessing the buffers, while the main thread has to aquire
exclusive access via a write lock before modifying the buffers.
2024-04-08 20:24:30 +00:00
columbarius
2010fa1349 vulkan: Name params 2024-04-08 20:24:30 +00:00
Arun Raghavan
e4da3b95f5 alsa-pcm: Fix copy-pasto while listing ctls
Can cause a crash on startup under some circumstances.
2024-04-06 07:25:39 +00:00
Adam Gensler
63af3a4b5c Update 90-pipewire-alsa.rules with support for Astro Mixamp Pro TR. 2024-04-01 18:31:10 +00:00
Pauli Virtanen
5ae0dfb239 bluez5: bap: determine SDU interval from codec frame duration
BlueZ API as BAP Server gives us the ISO interval, instead of the SDU
interval, in the MediaTransport.QoS.Interval property.  They are not
necessarily the same. What we need is the SDU interval.

The SDU interval is the interval between packets the encoder outputs, so
it is determined by the codec configuration, and for LC3 is equal to the
frame duration.

Add codec method get_interval() that returns the correct interval, and
use it in iso-io.
2024-04-01 19:13:01 +03:00
Pauli Virtanen
b9ac79e99a bluez5: bap: no need to check for mtu, kernel fragments as needed
It's not necessary for ISO SDU to fit into the adapter MTU, as kernel
will fragment the packet as needed.

Remove MTU checks.
2024-04-01 15:23:32 +03:00
Robert Mader
bd5cc52c5c libcamera: add camera rotation property on nodes
Like the location, the orientation is a static property of libcamera
devices. While the rotation is already exposed as buffer transform,
knowing the property can be handy for applications in various ways.

See also: cd8ac5c1a ("libcamera: add camera location property on nodes")
2024-03-31 13:24:19 +02:00
Robert Mader
1a2fee260b v4l2: Drop the first frame after camera startup
A quite big number of UVC cameras - due to firmware or kernel driver
issues - have bad timestamps of the first frame, confusing clients
like pipewiresrc.
Drop the first frame, as this seems to be the most reliable workaround
for the time being.

Closes https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/3910
2024-03-30 14:14:44 +01:00
Wim Taymans
af310523db spa: improve null-audio-sink channels
We can just update the channels in the props, we don't need an extra
property that can go out of sync with the channels.

See #3931
2024-03-28 17:11:16 +01:00
Wim Taymans
d4581755e6 spa: Improve JSON error reporting
Add struct spa_error_location that holds information about some parsing
context such as the line and column number, error and line fragment
with the error.

Make spa_json_get_error() fill in the spa_error_location instead. Add
some error codes to the error state and use this to add a parsing reason
to the location.

Add a debug function to log the error location in a nice way. Also
add a FILE based debug context to log to any FILE.

Replace pw_properties_check_string() with
pw_properties_update_string_checked() and add
pw_properties_new_string_checked(). The check string behaviour can still
be done by setting props to NULL but the main purpose is to be able to
avoid parsing the json file twice in the future.

When using the old pw_properties_update_string(), log a warning to the
log when we fail to parse the complete string.

Use the new checked functions and the debug functions to report about
parsing errors in the tools and conf parsing.

This gives errors like:

```
> pw-loopback --playback-props '{ foo =  [ f : g ] }'
error: syntax error in --playback-props: Invalid array separator
line:      1 | { foo =  [ f : g ] }
col:      14 |              ^
```
2024-03-27 15:42:29 +01:00
Pauli Virtanen
0da9255057 treewide: check for JSON parse errors
Check for JSON parse errors, and log error messages as appropriate.

It's mostly enough to do this where the input is parsed for the first
time, e.g. via pw_properties_new_string, as that already validates the
JSON syntax.
2024-03-25 21:42:26 +02:00
George Kiagiadakis
ddfe3daa22 bluez: print a nicer warning when the bluez service is not available 2024-03-25 14:54:30 +00:00
Samuel Thibault
7ee8192ce9 spa plugins: Include Linux headers on Linux only 2024-03-25 14:53:14 +00:00
Wim Taymans
4db0811878 alsa: add option to skip the busy check
Makes the card exposed even if some of the pcms are busy.

Fixes #3914
2024-03-22 12:42:48 +01:00
Wim Taymans
842ac9e110 v4l2: set latency on port
Use the duration of one frame as the latency.

See #3910
2024-03-22 11:15:10 +01:00
Wim Taymans
ce86b9a398 alsa: improve acp device/node object paths
Use alsa:acp: as the object prefix to make it different from the
alsa:pcm prefix when we are not using ACP.

Replace the card index in the object.path with the card_name, which
we try to construct from the alsa.id when it is available. This brings
the object.path in line with the alsa-pcm-device naming and adds the
user configurable id in the object.path to make it possible to
differentiate between identical devices.

Place the acp device index after the card_name instead of the unstable
device name (which depends on the alsa card number, which depends on the
kernel probing order).

This should make the object.path stable accross reboots for ACP and user
configurable with udev. With such a stable id, the other fields can be
made stable as well with custom rules.

See #3912
2024-03-18 11:41:37 +01:00
Wim Taymans
aec07d974e acp: move acp_dict_lookup to public header 2024-03-18 11:41:01 +01:00
Wim Taymans
37a51533e0 acp: add more properties for the card
Use snd_ctl_card_info to set some more card properties such as the
alsa.id, alsa.mixer_name and alsa.components.

alsa.id is interesting because it is possible to use udev rules to set a
custom id, which is handy when you have two identical cards in the
system and want to assign unique ids to them.

See #3912
2024-03-18 10:59:23 +01:00
Arun Raghavan
46e6fd2ae4 spa: alsa: Read ctl events instead of doing a global diff
This does a couple of things: first, we implement revents demangling,
which seems to be required (although hw: devices work fine without it).

The second is to actually read the ctl events so we can tell when
elements we care about have changed, instead of reading everything and
trying to do a diff.

The latter is also required from a correctness perspective, as otherwise
the ctl might keep triggering wakeups while the fd is ready to be read.
2024-03-14 10:13:41 -04:00
Pauli Virtanen
e784de3933 spa: use log topics everywhere
Use log topics properly everywhere, convert from "#define NAME".
2024-03-11 18:45:21 +02:00
Wim Taymans
ea524b158c audioconvert: add monitor.passthrough option
Add a monitor.passthrough option. This will pass all latency information
directly between the port and its monitor ports.

This is interesting when the adapter (and audioconvert) is used with a
null-audio-sink that simply forwards the data to a real sink/souce. In
that case, we want the sink/source latency to be passed unmodified.

Set the monitor.passthrough on the pulseaudio null-sink because
a passthrough virtual sink is the most likely use case for this.

Add some monitor.passthrough default config where it makes sense.

Fixes #3888
2024-03-11 16:20:27 +01:00
Pauli Virtanen
7d0ca2d103 spa: node-driver: always put CLOCK_MONOTONIC values to clock->nsec
When timer is not using monotonic clock, apply clock offset to translate
the time values to the monotonic clock when putting them to spa_io_clock
nsec fields.

Get appropriate clock offset by smoothed filtering.  The parameters here
keep the offset jitter < 10ns or so.

As monotonic/boottime/realtime all contain adjtime(), there generally is
no drift in the offset here, so just averaging should be fine.

Also fix using wrong timer clock when freewheeling.
2024-03-07 20:04:54 +02:00
Barnabás Pőcze
cf984fcd4c spa: alsa: fix clang build
Variable declarations after a label are not allowed,
and clang does not accept them. Fix the build failure
by removing the variable.

Fixes b3fbd0e607 ("alsa-pcm: add_bind_ctl_param: add support for array")
2024-03-07 17:16:55 +00:00
Emil Svendsen
b3fbd0e607 alsa-pcm: add_bind_ctl_param: add support for array
ALSA controls are represented as an array. So let's make it possible to
handle array's and bytes.
2024-03-06 08:44:13 +01:00
Emil Svendsen
96f35e15a0 alsa-pcm: bind_ctl: add better ctl name matching
For matching kctl without the numid you need to specify interface,
device, subdevice, name and index. So the current implementation can
only match kctls on IFACE_PCM, device 0, subdevice 0 and index 0.

Instead of adding all these matching parameters this commit fetches all
kctls attached to the audio card and match on the first occurred kctl
with matching name.

This should be sufficient for audio cards with unique kctl names. When
non unique names are needed, more kctl matching parameters needs to be
added.
2024-03-05 17:48:56 +00:00
Emil Svendsen
81d8ecf0dc alsa-pcm: snd_ctl_open: remove device suffix
ALSA controls can only be opened on the card itself and will fail when
trying to open controls on the ALSA device. The device name we get may
or may not include the device suffix. If no suffix is present the
default device is 0 that's why currently it works on most audio cards.
But all other devices above 0 needs the suffix [1].

[1]
Device 0: hw:cardname
Device 0: hw:cardname,0
Device 1: hw:cardname,1
Device 2: hw:cardname,2
Device X: hw:cardname,X
2024-03-04 09:45:37 +00:00
Dimitrios Katsaros
c1eacce3fc alsa: Use hi-res timestamps in irq mode when available
We know in IRQ mode that any valid hi-res timestamp that the
driver privides will be before the wakeup event in pipewire.

This makes it so in IRQ mode we use better timestamping when possible,
which decreases jitter injected into the DLL, which in turn reduces
the amount of oscillations the resampler is exposed to.
2024-03-01 21:46:21 +01:00
David Turner
0cfe57f33d Add SOC-style jack names to HDMI audio paths
Currently the HDMI output paths have jack mixers named "HDMI/DP" and
with append-pcm-to-name=true.  However, most of the SOC audio drivers
are just named "HDMI" and don't add the ",pcm=N".  Add these alternate
jack names to the HDMI audio path files so that jack detection will work
on these SOCs.
2024-03-01 09:33:55 +00:00