Commit graph

135 commits

Author SHA1 Message Date
Wim Taymans
c4244a6cf3 string: use spa_strbuf instead of snprintf magic 2025-10-24 17:00:11 +02:00
Arun Raghavan
154ab33607 spa: alsa: Add option to use ELD-detected channels 2025-10-10 09:34:43 +00:00
Arun Raghavan
91e2f184e2 spa: alsa: Read and expose channel count and position from ELD
The next step will be to propagate this to the correct node.
2025-10-10 09:34:43 +00:00
Pauli Virtanen
916896c1cc alsa: force IRQ scheduling for firewire in pro-audio profile
FireWire ALSA driver latency is determined by the buffer size and not the
period. Timer-based scheduling is then not really useful on these devices as
the latency is fixed.

In pro-audio profile, enable IRQ scheduling unconditionally for these
devices, so that controlling the latency works properly.

See #4785
2025-09-07 18:23:31 +00:00
Julian Bouzas
a8b9ce2050 alsa: add option to disable pro-audio profiles
Some devices might have nonfunctional 'Pro Audio' sound. This patch adds a
new 'api.acp.disable-pro-audio' option to disable pro-audio profile entirely.
2025-07-02 08:11:48 -04:00
Pauli Virtanen
3539374ba7 spa: alsa: fix some coverity warnings
NULL checks.

Change pa_x* malloc functions act like the pulseaudio ones: assert on
failure, as code assumes that.
2025-06-14 14:38:26 +03:00
Stefan Binding
7f07448a80 spa: acp: Allow Volume control which supports mute to be used as a hardware mute
Some devices have a hardware volume control, but not a dedicated
hardware mute control. In some of these cases, the volume control is
described as having a hardware mute when volume is 0. This is described
in the TLV information of the volume control, when the
SNDRV_CTL_TLVD_DB_SCALE_MUTE flag is set in the TLV structure.
If set, alsa-lib will set the minimum dB value to -99999.99dB, which
can be detected inside PipeWire.

PipeWire can then use this hardware volume control to apply hardware
mute, when set.

In order to be able to set volumes and mutes separately, changing the
volume whilst muted will save the value, but not write it to the
hardware. When the device is unmuted, the saved value will be restored.

Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
2025-05-05 07:40:29 +00:00
Wim Taymans
14f48c7a1c acp: probe max 192 channels
Thr 256 channel probe can cause overflows because we use uint8_t for the
channel count in some places.

Fixes #4669
2025-04-28 09:47:43 +02:00
Wim Taymans
031014bbab acp: remove channel limit from API
Internally bump the channel limit and allocate the channel map
dynamically.
2025-04-04 15:46:03 +02:00
Wim Taymans
722776cf65 Remove some hardcoded channel number values
Mostly related to the number of channels.
2025-04-04 15:46:03 +02:00
Pauli Virtanen
bd3a8b594f spa: acp: indicate ALSA UCM profile errors in UIs
Add "[ALSA UCM error]" to the end of card description, to indicate
something is wrong.
2025-03-13 21:25:55 +00:00
Pauli Virtanen
90f8b0e40b spa: acp: remove some strictly not necessary SplitPCM properties
Remove some api.alsa.split.* properties that the monitor script can
figure out itself.
2024-12-23 11:46:02 +02:00
Pauli Virtanen
dcccfcab7f spa: acp: get and emit UCM information for SplitPCM devices
When api.alsa.split-enable=true for ACP device, instruct UCM to not
use alsa-lib plugins for SplitPCM devices.

Grab the information from UCM for the intended channel remapping, and
add the splitting information to the nodes emitted.

Session manager can then look at that, and load nodes to do the channel
splitting.
2024-12-21 16:03:19 +02: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
Arun Raghavan
e6bcc415fc 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-02 17:02:11 +00:00
Alper Nebi Yasak
d42bfa56b7 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:02:46 +02:00
Wim Taymans
99c23d5b0e acp: add api.alsa.disable-mixer-path
Don't use the api.alsa.soft-mixer option to disable the path selection
but make a new api.alsa.disable-mixer-path.

Disabling the path selection might leave cards unusable after suspend,
so a separate option is a better idea.

See #4311
2024-09-24 13:14:17 +02:00
Wim Taymans
322829cb2e acp: disable path_select when using soft-mixer
When using the soft mixer we should not use path_select because that one
will also touch the mixer and try to mute some switches.

Fixes #4311
2024-09-23 15:34:08 +02:00
Wim Taymans
cd81b5f39a spa: add spa_json_begin_array/object and relaxed versions
Add spa_json_begin_array/object to replace
spa_json_init+spa_json_begin_array/object

This function is better because it does not waste a useless spa_json
structure as an iterator. The relaxed versions also error out when the
container is mismatched because parsing a mismatched container is not
going to give any results anyway.
2024-09-16 09:50:33 +02:00
Wim Taymans
1ae4374ccf Fix compilation with -Werror=float-conversion
Better make the conversions explicit so that we don't get any surprises.

Fixes #4065
2024-06-18 12:17:56 +02:00
Wim Taymans
aec07d974e acp: move acp_dict_lookup to public header 2024-03-18 11:41:01 +01:00
Alper Nebi Yasak
7d2e824e97 acp: Disable active UCM profile before enabling Pro Audio profile
While switching to the Pro Audio profile from a UCM profile, the active
UCM profile is not disabled because the devices may need a UCM verb to
be set before being used. Then, switching away from the Pro profile to a
UCM profile is done by passing the Off profile as the old profile,
instead of the actually-still-enabled UCM profile.

This means the devices from the old UCM profile are kept enabled when we
try to switch to another UCM profile. And the devices to enable may be
conflicting with the still-enabled devices, which will cause failures.

To avoid this, we need to tell the UCM code to disable the profile when
switching away from it. Doing so disables UCM devices and the UCM verb.
Existing code sets the highest priority UCM verb before probing the Pro
profile, so manually enable the same one here as well, instead of
relying on unclean state from whatever profile that was last active.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-12-04 15:34:48 +00:00
Alper Nebi Yasak
9b9ce21b1d acp: Don't sync hardware volumes while UCM device is disabled
The hardware controls we track for volume and mute state can change as
part of enabling or disabling the UCM device. This then triggers a
re-sync of our state with the hardware controls, which can e.g. set our
volume to an unwanted value as the result of enabling the device, or set
a hardware control to a wrong value based on our volume while disabling
the device. So these UCM-triggered changes to enable/disable the device
will at best show up on user interfaces and cause confusion, but maybe
even will push the hardware into an unexpected state.

The volume and mute state we set from user interfaces only make sense
when the devices are enabled. They should not be kept in sync with
hardware for inactive UCM devices [1]. Skip the callbacks for reading
and changing volume and mute state if the UCM device is disabled. This
way, the volume/mute controls for sinks/sources are essentially detached
from the hardware controls until the UCM device is re-enabled.

[1] https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/772#note_1872757

Link: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/772
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-12-04 15:34:48 +00:00
Alper Nebi Yasak
bc42a617a4 alsa-ucm: Make mapping UCM contexts have only one device
After previous patches, we should be generating no combination ports, so
we don't need to store multiple devices per mapping. Simplify the code
based on this.

Link: 084d70a1e2
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
[Wim: Apply to acp add_profiles() and acp_card_set_profile()]
2023-12-04 15:34:48 +00:00
Alper Nebi Yasak
b8361cc568 alsa-ucm: Make ports store only one device
After previous patches, we should be generating no combination ports, so
we don't need to store multiple devices per port. Simplify the code
based on this.

Link: bf1708213b
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-12-04 15:34:48 +00:00
Alper Nebi Yasak
0fc80db7fe alsa-ucm: Remove combination port generation logic
A previous commit makes mapping names depend on the UCM device name.
Since UCM device names are unique, this means a mapping will at most
have one port and thus no combination ports can be generated.

This removes the dead code in the pa_alsa_ucm_add_ports_combination()
function, unrolls the remaining code in its helper functions that it
used, and renames it to pa_alsa_ucm_add_port() to signal that it no
longer generates combinations.

Link: 0789a8fb76
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
[Wim: Apply to acp add_profiles(), acp_card_set_profile(), compat.h]
2023-12-04 15:34:48 +00:00
Jaroslav Kysela
a5d87a43df alsa-ucm: Set profiles by their struct instance, not their name
While switching profiles, it's possible that we will want to do more
work besides switching UCM verbs. The alsa-card module already has our
profiles as structs, but passes in only the names instead of the entire
struct. Make things work with the struct instead, so we can add other
things (like a UCM context) to it and use those here.

Co-authored-by: Tanu Kaskinen <tanuk@iki.fi>
[Alper: Split into its own commit and integrated Tanu's snippet.]
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Link: 880ff393f1
[Wim: Apply to acp_card_set_profile() as well]
Co-authored-by: Wim Taymans <wtaymans@redhat.com>
2023-12-04 15:34:48 +00:00
Igor V. Kovalenko
082680d8a2 alsa-util: Perform format and rate detection before setting HW params
Perform detection of supported sample format and rates just after device is
opened, before `snd_pcm_hw_params()` is called for the first time. This fixes a
problem where device restricts available sample rates after HW params are set
preventing sample rate detection (seen with UAC2 devices and kernel 6.1.9)

Bug: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/1414
Bug: https://github.com/alsa-project/alsa-lib/issues/119
Link: aed52c507f
[Wim: Apply to acp add_pro_profile(), enable pa_alsa_supported_*()]
2023-12-04 15:34:48 +00:00
Jaroslav Kysela
4066bbaf09 alsa-mixer: fix the re-attach code for the mixer control element
The new helem must be tracked and old helem must be cleared
to make the code work properly. Introduce the pointer to helem
as the private value for melem and add the necessary code.

Also, add a check for the duplicate mixer elements. The duplicate
mixer element invokes the abort check in alsa-lib. Print a warning
instead and handle the exit gracefully.

Link: d1675df0cd
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-12-04 15:34:48 +00:00
George Kiagiadakis
f5546d27c1 acp: avoid copying structure into itself
sync_mixer() calls d->set_volume(d, &d->real_volume);
which makes v and &dev->real_volume point to the same memory area
and valgrind complains:

Source and destination overlap in memcpy(0xcc53e2c, 0xcc53e2c, 260)
   at 0x488CFA0: __GI_memcpy (vg_replace_strmem.c:1121)
   by 0xBB0803F: set_volume (acp.c:1143)
   by 0xBB0EDCB: acp_device_set_port (acp.c:1897)
   by 0xBA9CD87: impl_set_param (alsa-acp-device.c:757)

because the compiler apparently implicitly converts this into a memcpy()
and memcpy(3) explicitly says "The memory areas must not overlap."
2023-12-02 20:30:40 +00:00
Wim Taymans
a532c2abdb acp: add support for hiding profiles and ports
api.acp.hidden-ports and api.acp.hidden-profiles can be used to pass
a json array of ports and profiles to hide. They will not show and
will not be selectable.
2023-11-30 17:40:48 +01:00
Wim Taymans
2278dd1460 acp: only disable tsched when linking
Disable timer based scheduling only if we are going to link the devices
together.

See #3556
2023-10-09 12:28:46 +02:00
Wim Taymans
945be16617 acp: only join and link when 1 capture and 1 playback
Only schedule nodes together when there is just 1 capture and 1 playback
device. Devices might be mutually exclusive or require special setup
that would break otherwise.

See #3556
2023-10-09 10:35:30 +02:00
Wim Taymans
063805ccb4 acp: fix compilation 2023-10-09 10:15:10 +02:00
Wim Taymans
896fea62c2 alsa: add api.alsa.auto-link option
Add an option to automatically use snd_pcm_link when the follower clock
is matching the driver. Only set this to true in pro-audio and when
nodes are scheduled together.

See #3556
2023-10-09 10:13:43 +02:00
Wim Taymans
20db9e2d70 alsa: link driver and follower
When we are using the same clock (!matching) try to link the two PCM
devices together. This starts and stops the devices at the same time and
gives better latency.
2023-09-19 13:04:43 +02:00
Wim Taymans
3685081fd1 alsa: add device.profile.pro property
It is set to true when the node is using a pro audio profile.
2023-08-29 09:22:27 +02:00
Wim Taymans
091b5497a3 acp: try to set a verb before probing pro-audio devices
Some UCM devices need to be configured with a verb before we can try probing
the pcms. Find the highest priority verb and set that.
2023-08-07 12:56:24 +02:00
Wim Taymans
a66d5b90f9 Revert "alsa: UCM conflicting devices changes"
If needs some more work

This reverts commit aae770f18b.
This reverts commit 2216956e05.
This reverts commit 1d3c4501ef.
This reverts commit c7ca024607.
This reverts commit 8e4a5f5d5e.
This reverts commit 8b20675ad1.
This reverts commit ebe6f8b51a.
This reverts commit 4b97da1277.
This reverts commit 7c46a656c7.
This reverts commit 96ed03e1fc.
This reverts commit 43770c533c.
This reverts commit ccb2fce054.
This reverts commit 93d0ddc8b3.
This reverts commit 815e8c8fa0.
This reverts commit 97b99a0f7c.
This reverts commit 7e4d87402b.
This reverts commit 168b3ee22c.
This reverts commit 5128cdba31.
This reverts commit 31cde774c5.
This reverts commit b02c8ba153.
This reverts commit 68ac72d098.
This reverts commit 96cfc9bc1a.
This reverts commit e2d642a20b.
This reverts commit 80fc80c343.
This reverts commit 3a68905c7c.
This reverts commit 7e64680a65.
This reverts commit 8d1e38a281.
This reverts commit 591188195c.
This reverts commit 973fe0cb79.
This reverts commit 4d08c9ad60.
This reverts commit 3dce92e580.
This reverts commit 6b5e232c5c.
This reverts commit b1286c62c9.
2023-04-12 13:05:08 +02:00
Wim Taymans
25f5165e4c acp: return EEXIST when seeing a linked device
Otherwise we get ENOENT, which is confusing because it is the same
error when the plugin doesn't exist.

See #2016
2023-03-23 13:24:22 +01:00
Wim Taymans
96ed03e1fc alsa-util: Perform format and rate detection before setting HW params
Perform detection of supported sample format and rates just after device is
opened, before `snd_pcm_hw_params()` is called for the first time. This fixes a
problem where device restricts available sample rates after HW params are set
preventing sample rate detection (seen with UAC2 devices and kernel 6.1.9)
2023-03-20 18:22:09 +01:00
Wim Taymans
815e8c8fa0 alsa-mixer: fix the re-attach code for the mixer control element
The new helem must be tracked and old helem must be cleared
to make the code work properly. Introduce the pointer to helem
as the private value for melem and add the necessary code.

Also, add a check for the duplicate mixer elements. The duplicate
mixer element invokes the abort check in alsa-lib. Print a warning
instead and handle the exit gracefully.

Fixes: def8eb074 ("alsa-mixer: allow to re-attach the mixer control element")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-03-20 17:47:52 +01:00
Wim Taymans
31cde774c5 alsa-ucm: Make mapping UCM contexts have only one device
After previous patches, we should be generating no combination ports, so
we don't need to store multiple devices per mapping. Simplify the code
based on this.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 17:24:12 +01:00
Wim Taymans
b02c8ba153 alsa-ucm: Make ports store only one device
After previous patches, we should be generating no combination ports, so
we don't need to store multiple devices per port. Simplify the code
based on this.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 17:14:39 +01:00
Wim Taymans
68ac72d098 alsa-ucm: Remove combination port generation logic
A previous commit makes mapping names depend on the UCM device name.
Since UCM device names are unique, this means a mapping will at most
have one port and thus no combination ports can be generated.

This removes the dead code in the pa_alsa_ucm_add_ports_combination()
function, unrolls the remaining code in its helper functions that it
used, and renames it to pa_alsa_ucm_add_port() to signal that it no
longer generates combinations.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 16:49:35 +01:00
Wim Taymans
4d08c9ad60 alsa-ucm: Set profiles by their struct instance, not their name
While switching profiles, it's possible that we will want to do more
work besides switching UCM verbs. The alsa-card module already has our
profiles as structs, but passes in only the names instead of the entire
struct. Make things work with the struct instead, so we can add other
things (like a UCM context) to it and use those here.

Co-authored-by: Tanu Kaskinen <tanuk@iki.fi>
[Alper: Split into its own commit and integrated Tanu's snippet.]

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 15:13:41 +01:00
Barnabás Pőcze
934ab3036e treewide: use SPDX tags to specify copyright information
SPDX tags make the licensing information easy to understand and clear,
and they are machine parseable.

See https://spdx.dev for more information.
2023-02-16 10:54:48 +00:00
Wim Taymans
2681d7e3ec acp: add option to set Pro Audio channels
We always probe the Pro Audio profile with the maximum number of
channels but this can lead to a more limited amount of sample rates.

Add an option to set the channels used when probing so that the other
samplerates become available.

Fixes #2990
2023-01-31 15:59:39 +01:00
Wim Taymans
f62c40c205 acp: also add the Pro profile for UCM devices 2023-01-03 13:17:10 +01:00
Wim Taymans
3595e31124 acp: add ports only when there are ucm devices 2023-01-03 13:16:06 +01:00