Commit graph

10442 commits

Author SHA1 Message Date
Wim Taymans
3698593481 spa: reuse code to clear the timers
We have set_timeout and enable_flush_timer functions to disable the
timers so use those.
2023-03-24 17:55:15 +01:00
Wim Taymans
78b8e1af57 node-driver: fix position calculation
Set the driver node position based on the current time when we
start and keep incrementing it with the previous duration.
2023-03-24 17:34:14 +01:00
Wim Taymans
5ea3c10dca support: sync timers with data loop
Start and stop the timers in the data_loop. Otherwise we might be trying
to stop a timer while the data loop is starting it and we end up with
"ready non-active node" messages.
2023-03-24 17:24:56 +01:00
Wim Taymans
157a97cc98 bluez5: do rate matching before next timeout
Because else we might not have a rate and divide by 0.
2023-03-24 16:13:51 +01:00
Wim Taymans
7b6680ba57 plugins: simplify target_ handling
Drivers should only read the target_ values in the timeout, update the
timeout with the new duration and then update the position.

For the position we simply need to add the previous duration to the
position and then set the new duration + rate.

Otherwise, everything else should read the duration/rate and not use
the target_ values.
2023-03-24 11:36:15 +01:00
Wim Taymans
f309543810 context: update the duration/rate directly when node idle
When the node is not running, update the duration/rate directly
so that followers can see the current duration/rate when they start.
2023-03-23 18:50:24 +01:00
Wim Taymans
6e8625cf96 node: update the duration/rate from the target
Before scheduling the graph from the driver, update the duration and
rate with the new targets.
2023-03-23 18:39:27 +01:00
Wim Taymans
1bdd5eee69 alsa: update rate/duration from target
Also reorganize some things to reuse more code.
2023-03-23 18:04:36 +01:00
Wim Taymans
2adf8d38d5 node: add target_rate and target_duration in io_clock
Place the target rate and duration in the io clock area.

The driver is meant to read these new values at the start of the cycle
and update the position rate and duration.

This used to be done by the pipewire server when it received the ready
callback from the driver but this is in fact too late. Most driver would
start processing and set the next timeout based on the old rate/duration
instead of the new pending ones.

There is still a fallback for the old behaviour (with a warning) when
the driver doesn't yet update the position.
2023-03-23 17:57:16 +01:00
Wim Taymans
87d64f5cad context: rename current_quantum/rate to target_*
They are really the target rate and quantum that we would like to
have and are only current after target_pending is false.
2023-03-23 17:20:01 +01: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
2a29e7b9e2 alsa: improve properties
Make NODE_NAME something that looks more like other node names.
Add MEDIA_NAME and NODE_DESCRIPTION.

Makes things look better in pw-top and the same in pavucontrol.
2023-03-23 12:41:08 +01:00
Wim Taymans
d78bea5e32 module-combine-stream: improve docs 2023-03-23 11:47:27 +01:00
Wim Taymans
d3cd900d06 context: restore driver rate when no longer forced
Keep track of when a rate was forced on a driver and restore the
best rate again when no longer forced.

This handles:

- paplay playing a file at 44100Hz
  --> driver openeing the device at 44100
- PIPEWIRE_PROPS='{ node.force-rate=48000 }' jack_simple_client
  --> driver being forced to a new rate of 48000
- Stop jack_simple_client
  --> Driver reverting back to 44100

Previously the driver would stay in 48000Hz until it idles.

This also works with pw-metadata -n settings 0 clock.force-rate 0.

Fixes #2133
2023-03-23 11:35:50 +01:00
Wim Taymans
8ddb6d711f context: don't reconfigure when already pending
When we already have a pending rate/quantum change, don't reconfigure
the driver.

This avoids going into an endless loop when:

1- paplay plays with 44100Hz on device1
2- jack_simple_client starts and attaches to device1
3- jack_simple_client links to device2
4- jack_simple_client is moved from device1 to device2, rate from
   device1 is moved to device2 (44100Hz)
5- device2 becomes schedulable and sees the rate should be 48000Hz (the
   default) it does a rate switch to 48KHz
6- jack_simple_client is suspended, links are back to init
7- jack_simple_client is moved back to device1
8- jack_simple_client links are activated and cycle restarts at 4

The cycle is broken because at 6 we avoid doing the suspend.
2023-03-23 10:26:21 +01:00
Wim Taymans
07e6f44e58 modules: clean up USAGE arguments
use () to mark optional arguments to avoid confusion with arrays.
Add some more optional arguments.
2023-03-22 16:35:55 +01:00
Wim Taymans
3decaa6457 audioconvert: use spa_strbuf 2023-03-22 15:41:27 +01:00
Wim Taymans
5d2773a554 audioconvert: fix test
Enable upmix manually because we test that.
2023-03-22 15:41:06 +01:00
Wim Taymans
d07e1b5641 audioconvert: disable upmix by default again
But instead ship config override files to enable it again.

The idea is that distros can make extra packages that can than be
installed to enable the upmixing.

Also ship a config file to enable more samplerates.

Fixes #3081
2023-03-22 15:21:55 +01:00
Wim Taymans
2d6669d571 acp: fix pa_strbuf
We need vfprintf.
2023-03-22 15:08:29 +01:00
jdavidsson
0d0af4c9d8 module-echo-cancel: null check playback stream
Protect against segfault when monitor.mode = true and playback stream
isn't created.
2023-03-22 11:07:17 +00:00
Wim Taymans
943f40fd3a filter-chain: add docs
Add docs for sofa and improve docs for the convolver.
2023-03-22 11:52:02 +01:00
Wim Taymans
5af265ed22 protocol-native: emit bound_id and bound_props from protocol
Emit both the bound_id and bound_props events from the protocol on
the core_resource.

Doing the dispatching of the bound_id/bound_props in the core to the
proxy doesn't handle the case where the client has a listener directly
on the core_resource.

Fixes #3109
2023-03-22 10:20:14 +01:00
Wim Taymans
fb8709716c core: add bound_props event
this event extends the bound_id event and sends the global properties as
well.

This can be used to get the object.serial, for example.

It can also be used in the future to let the server generate unique
property values, like the node.name, and let the client know about the
new property value.
2023-03-21 17:22:27 +01:00
Wim Taymans
59cd5670d7 impl-core: store hello version in core resource
So that we can later get the client core version from the resource.
2023-03-21 17:20:18 +01:00
Wim Taymans
aae770f18b alsa: avoid assert
We're doing something different than pulseaudio when setting up the
ports.
2023-03-21 12:29:37 +01:00
Wim Taymans
2216956e05 alsa: fixup after merge 2023-03-21 10:07:39 +01:00
Wim Taymans
1d3c4501ef alsa: use pa_strbuf 2023-03-21 09:47:10 +01:00
Wim Taymans
c7ca024607 alsa: ucm: Fix spurious mixer path removal on initial profile set
The code that removes the mixer path if probing fails can be called in
the path that sets a non-off device profile on hotplug *before*
card->active_profile is updated, which results in spuriously removing
the mixer path. By this point, context->ucm->active_verb would be set
to the same as the profile name, so we can use that instead to avoid
the issue.

On Apple Silicon machines with the UCM profiles in the Asahi Linux repo,
this manifests as the headphones jack having hardware volume controls
*only* if PA is started with headphones connected and until they are
disconnected. Hotplugs end up triggering the bad codepath, and it falls
back to software volume (which is particularly a problem when the
hardware volume happens to be very low or 0 at that point).

Fixes: a9cc1373e2a7 ("alsa: ucm - update the mixer path also after volume probe")
Signed-off-by: Hector Martin <marcan@marcan.st>
2023-03-20 18:35:15 +01:00
Wim Taymans
8e4a5f5d5e alsa-ucm: Fix more instances of profile-verb conflation
The ucm_get_device_property() function adds to each UCM device's
playback_volumes (or capture_volumes) hash map an associated volume
mixer keyed with the UCM verb. These key-value pairs are then iterated
over in various places which assume the key is a profile name. This
assumption is no longer true since we can generate multiple profiles to
use conflicting devices.

A previous commit 45278904167f ("alsa-ucm: Stop conflating profile name
with UCM verb name") fixes some instances of this assumption, but misses
the relation explained above. Fix more instances of misleading
"profile"s where the UCM verb name is actually meant.

Fixes: 45278904167f ("alsa-ucm: Stop conflating profile name with UCM verb name")
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 18:33:36 +01:00
Wim Taymans
8b20675ad1 alsa-ucm: Consider devices using the same PCM as incompatible
Although it's a valid UCM configuration to have multiple devices using
the same PlaybackPCM or CapturePCM, it's unclear how PulseAudio should
handle the cases where multiple of these devices are enabled. Some
options I can think of are:

- Merge all devices sharing the same PCM into the same mapping, open
  only one PCM substream for this mapping, and add 'combination ports'
  that enable combinations of the devices. This has been the case until
  recently, although the combination port logic was broken. A problem
  with this is that we can't independently control device volumes. We
  most likely cannot use hardware volumes either.

- Have one mapping for each device in the same profile, and open one PCM
  substream for each mapping. This is the current state, and it fails
  when there are fewer substreams than devices. Otherwise it works, but
  it's still confusing, as sound directed to a device-specific mapping
  might end up playing at multiple devices.

- Make multiple profiles each with combinations of upto-substream-count
  devices, and have one mapping/substream per device. This still causes
  the confusion mentioned above. And it's likely that the substream
  count will almost always be one, where this case degenerates into the
  last one.

- Have one mapping for each device in the same profile, but open only
  one PCM substream. I assume this is possible with software mixing, but
  it is still confusing like the above, and probably less performant.

- Generate multiple profiles each with one of the shared-PCM devices,
  again with one mapping/substream for that one device. The trade-off
  with this is that we can't use multiple of these devices at the same
  time. However, this doesn't have the output device confusion,
  combination port's volume problems, or the substream count limitation.

This patch takes a short-cut to achieve the last option, by considering
shared-PCM devices implicitly conflicting with each other.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 18:29:51 +01:00
Wim Taymans
ebe6f8b51a alsa-ucm: Disable old modifiers when switching profiles of same verb
While switching profiles of the same UCM verb, existing code first
disables devices that are only on the first profile to avoid conflicts.
However, it only disables devices, not modifiers. Even worse, modifiers
which have PlaybackPCM/CapturePCM are incorrectly treated as devices and
result in a segmentation fault.

Check what we are disabling, and call the appropriate disable function
for both devices and modifiers. Modifiers are disabled before devices,
because _dismod calls fail when the modifier's supported devices are
disabled.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 18:28:10 +01:00
Wim Taymans
4b97da1277 alsa-ucm: Add enable, disable, status helpers for modifiers
These are mostly the same as the device helpers added in c83b34516929
("alsa-ucm: Add enable, disable, status helpers for devices"), but for
modifiers instead.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 18:26:46 +01:00
Wim Taymans
7c46a656c7 alsa-util: Fix pa_alsa_get_supported_formats fallback.
Looks like original intention was to scan over sample formats supported by PA,
but code does the scan by list of alsa formats. Reverse the map and adjust
fallback case which now can use the same map.
2023-03-20 18:24:20 +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
43770c533c alsa-profiles: rename mappings for Xonar SE
Remove descriptions as well.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/754>
2023-03-20 17:56:33 +01:00
Wim Taymans
ccb2fce054 alsa-util: Add more standard sample rates.
Dump probed rates
2023-03-20 17:54:54 +01:00
Wim Taymans
93d0ddc8b3 alsa-mixer: extend pa_alsa_mixer_find with the subdevice check
The full identifier check must be executed for the new melem
creation, otherwise the duplicate control element code check
is reached.

Example (using the snd-aloop driver):

numid=56,iface=PCM,name='PCM Notify',device=1,subdevice=1
numid=62,iface=PCM,name='PCM Notify',device=1,subdevice=2

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-03-20 17:50:17 +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
97b99a0f7c alsa-ucm: remove extra space from the device.intended_roles property
Before:
  device.intended_roles = " voice"

After:
  device.intended_roles = "voice"

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-03-20 17:40:33 +01:00
Wim Taymans
7e4d87402b alsa-ucm: Create multiple profiles per verb for conflicting devices
Right now we try to add all UCM devices of a verb to a single profile.
But if some devices using different PCMs are configured as conflicting
with one another, we will only be able to utilize one of them, chosen
seemingly based on the order in the UCM config file.

This is not a problem with conflicting devices sharing a PCM, as they
are assigned to the same mapping and the ports mechanism only enables
one of them to be active at a time.

To utilize all devices in a UCM verb even when there are conflicting
devices using different PCMs, calculate subsets of devices which
can be simultaneously used and create a profile for each such set.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 17:38:44 +01:00
Wim Taymans
168b3ee22c alsa-ucm: Disable old devices when switching profiles of same verb
While switching profiles, it was enough to switch UCM verbs since that
disables all enabled UCM devices and every profile had a distinct verb.
However, switching to the current verb does not disable any devices.

To support multiple profiles for a verb we need to explicitly disable
the old profile's devices, since they might be conflicting with the new
profile's devices and will prevent them from being enabled. Compare both
profiles' mappings, and disable the devices not in the new mappings.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 17:33:10 +01:00
Wim Taymans
5128cdba31 alsa-ucm: Make mapping UCM contexts have only one modifier
After previous patches, we should be generating no combination ports, so
we don't need to store multiple modifiers per mapping. Simplify the code
based on this.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 17:31:31 +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
96cfc9bc1a alsa-ucm: Make one input/output mapping per UCM device
PulseAudio combines UCM devices that have the same PlaybackPCM or
CapturePCM value into a single mapping with multiple ports. It also
creates ports in the same mapping for each valid combination of those
UCM devices.

Since mappings are the things we put in profiles, we can put in a
profile either all devices of a joint mapping or none of them. This
causes some complications with device conflicts. For example, a
different UCM device might be marked as conflicting with some (but not
all) of the devices in a joint mapping. In this case we can do one of
three things:

- Include all devices in one profile, and hope the conflicting device
  isn't chosen as the mapping's active port. We shouldn't do this as it
  puts conflicting devices in the same profile.

- Make one profile with the joint group, and one with the other device.
  This is somewhat acceptable as we have no conflicts, but we sacrifice
  some compatible combinations of devices.

- Do not group the devices into the same mapping, and make one profile
  for each compatible combination of devices. This appears to be the
  best option, one where we can always have the maximum number of
  working devices.

This patch chooses the third option and makes one input and/or output
mapping per UCM device, by using UCM device names instead of PCM device
strings in the mapping names.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 16:36:40 +01:00
Wim Taymans
e2d642a20b alsa-ucm: Split out helpers for device set name, description, priority
Combination port logic calculates some useful properties for device
groups that we could reuse while generating multiple profiles to support
conflicting devices. Split them into their own functions.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 16:34:05 +01:00
Wim Taymans
80fc80c343 alsa-ucm: Fix device conformance check
Right now this check is rejecting devices whose UCM config specifies
neither a conflicting device nor a supported device list, and accepting
devices which specify both. However, a device without neither list is
actually unrestricted, and a device with both lists is a configuration
error. Fix the check to accept the former.

Furthermore, this is missing another case where an already selected
device might have a supported devices list that doesn't have the
candidate device. Make this function also check against that, and also
make it accept devices already in the set.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 16:30:00 +01:00
Wim Taymans
3a68905c7c alsa-ucm: Rewrite conformant device group generation with idxsets
The existing code meant to generate device groups for combination ports
is tightly coupled to port creation. Similar functionality would be
useful to generate nonconflicting device groups for multiple profiles as
well, so this tries to rewrite it into a more reusable state.

Several things (e.g devices, mapping contexts) use idxsets to store a
device selection. This also switches this conformance check and device
group generation to using idxsets to make it easier to work with those,
with the eventual aim to unify device group representations.

Also try to adjust users of these functions to use idxsets these will
need/return, without causing too much interference.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
2023-03-20 16:28:32 +01:00