Commit graph

154 commits

Author SHA1 Message Date
Wim Taymans
56c03c11f8 alsa: resync when quantum changes 2022-02-16 21:30:35 +01:00
Wim Taymans
798228a906 alsa: remove useless code
The resync check can be done in check_position_config.
2022-02-16 21:29:55 +01:00
Wim Taymans
4246961070 alsa: use rewind to remove excess delay
When the delay is too big, rewind a little to reduce it when resync.
2022-02-16 21:10:03 +01:00
Wim Taymans
761199be70 alsa: improve resync
Use the max error to do a resync. Don't reset the dll, there is no
reason for that.
Don't use _rewind, but instead limit the amount of samples we read and
write
Should keep more stable sync in most cases.
2022-02-15 16:32:00 +01:00
Wim Taymans
87f4726164 alsa: protect against impossible timeouts
Check if the new timeout is larger than 1sec in the past or future
and reprogram a timeout with a saner timeout.
2022-02-15 15:35:40 +01:00
Wim Taymans
8b899dbc55 alsa: make sure we always trigger a timeout
If we get an error from get_status() make sure program the timer
for one period or else we would just end up with silence.
2022-02-15 15:32:09 +01:00
Wim Taymans
dc76ab2291 alsa: don't use dll when not rate matching
Only use the DLL when we are driver or rate matching with
another driver.
2022-02-15 15:29:40 +01:00
Wim Taymans
0bca352241 alsa: fill with silence when underrun
Also try to resync when the follower buffer is running empty.
Fill the buffer with silence instead of doing _pcm_forward.
2022-02-12 12:09:25 +01:00
Wim Taymans
9855e2b303 alsa: tweak capture follower
If the follower does not have enough data to capture, skip a cycle
instead of trying to capture and get an XRUN.

Tweak some limits a little.
2022-02-11 18:07:44 +01:00
Julian Bouzas
e34d9d209a alsa: try to resume after suspend before recovering
Fixes no audio after suspending with some audio drivers.

See #2001
2022-02-10 16:57:58 -05:00
Wim Taymans
f636603844 alsa: pass current_time around in get_status()
Pass the current time around in various functions.
Make a higher precission htimestamp based get_delay() function. Seems to
work fine for playback but not for capturee.
2022-02-10 15:31:29 +01:00
Wim Taymans
14d252ec9d alsa: try to resync on commit error
When we get a commit error, try to resync our pointers. This fixes a
problem of endless commit errors after a quantum change because it never
manages to resync properly.
2022-02-08 18:31:42 +01:00
Wim Taymans
76417fd2a6 alsa: use MONOTONIC clock for tstamp 2022-02-03 16:22:09 +01:00
Wim Taymans
8d37451fb8 alsa: ensure period_size is not 0 2022-01-24 12:44:16 +01:00
Wim Taymans
5010125452 alsa: make internal latency configurable with params 2022-01-18 11:46:08 +01:00
Wim Taymans
d8c867b515 alsa: improve rate selection
Make sure we don't select an invalid rate when the default is set or
when the card is already opened in some unsupported rate.

See #1975
2022-01-17 14:56:45 +01:00
Wim Taymans
776b52749f Use configured quantum_limit instead of hardcoded value
Parse the quantum_limit parameters and use this to scale the buffers so
that they can contain the maximum allowed samples instead of the
hardcoded 8192 value.

See #1931
2022-01-12 17:50:12 +01:00
Wim Taymans
39716cdd44 alsa: limit batch period size to default
We take half of the current quantum as the period size for batch
devices. Limit this to the default quantum to ensure we don't end up
with too much headroom.
2022-01-11 16:33:19 +01:00
Wim Taymans
67dc97fa43 alsa: add audio.allowed-rates param
Add a construct and runtime param to limit the amount of allowed
samplerates used by the node.

Fixes #1932
2022-01-03 16:03:23 +01:00
Barnabás Pőcze
b04b52ecf8 spa: alsa: do not look up the card again when releasing
Currently, `release_card()` uses `find_card()` to find the card
by the index stored in the state object. However, `find_card()`
increments the reference count of the object, therefore
`release_card()` will drop the reference that it has just
created by calling `find_card()` and not the "calling scope's"
reference. This prevents the card objects from being
freed when the SPA handle is cleared.

Fix it by having `release_card()` take a pointer to the card
and not its index.
2021-12-20 19:50:57 +01:00
Barnabás Pőcze
ee0963b68e spa: alsa: change index type
The `card` structure uses `uint32_t` for its index member,
on the other hand, the `state` structure uses `int`. No code
depends on it being `int`, therefore change it to `uint32_t`
for consistency.
2021-12-20 19:50:57 +01:00
Wim Taymans
f8cdc05720 alsa: allow multi-rate by default
We don't enable multiple rates by default and kernel 5.16 will fix
most issues so allow multiple rates per card.

See #1916
2021-12-18 08:33:34 +01:00
Wim Taymans
b476d6b503 alsa: add api.alsa.period-num param
To configure the amount of periods. By default we use as many as
possible but it is now possible to force a value.

See #1473
2021-12-17 16:09:52 +01:00
Wim Taymans
8630b8846c alsa: use position duration as period size
Use half of the configured quantum as the period size in batch mode.
This gives lower latency for USB devices depending on the quantum.
2021-12-17 16:08:08 +01:00
Wim Taymans
68cd9ac738 alsa: only use graph rate when nothing else is fixed
Only fall back to suggest the graph rate when we don't have a forced
rate or the card was not already in a format.

See #1892
2021-12-16 15:32:36 +01:00
Wim Taymans
738cbcf789 alsa: fix rate for EAC3
EAC3 needs to be opened in 4x the rate of the EAC3 stream, which can be
32, 44.1 or 48 KHz. Some clients already multiply but others don't.
Check here what is the case and fix it up.

Fixes #1902
2021-12-16 11:02:39 +01:00
Wim Taymans
0648297fcb alsa: make it possible to configure the clock name
When nodes are synchronized to a common clock, the clock name can
be set to the same value on the alsa nodes and no resampling will
be done.
2021-12-10 11:04:38 +01:00
Wim Taymans
30a78fe2b8 alsa: improve debug
Remove the rather useless dll values.
Add the threshold
2021-12-07 12:05:49 +01:00
Wim Taymans
57361ed0ee alsa: improve param log a bit 2021-12-02 11:35:13 +01:00
Wim Taymans
e31f9aa0f2 alsa: don't set id in PropInfo for params
The id is useless when dealing with props params, we need to use the
name of the property as the key. Also the id can clash with other ids
of other plugins.
2021-12-02 11:35:12 +01:00
Wim Taymans
befe7b13eb alsa: add position and format to props params 2021-11-30 18:19:08 +01:00
Wim Taymans
d673158db1 alsa: expose all config options as params
Add PropInfo for all the params that we can configure at construct
time and also add them as PROP_params.

This way you can configure the headroom at runtime with this:

pw-cli s <id> Props '{ params = [ "api.alsa.headroom" 1024 ] }'
2021-11-30 17:43:07 +01:00
Wim Taymans
d79d2f69fb alsa: improve debug
Log the configured default_format.
2021-11-24 17:25:59 +01:00
Wim Taymans
8995129e6c alsa: refactor property parsing
Move the common property parsing to the init function.
2021-11-23 12:27:36 +01:00
Wim Taymans
25bfc9c63d alsa: refactor a bit
Make spa_alsa_close() do spa_alsa_pause() first and also clear the
format.
2021-11-23 12:20:27 +01:00
Wim Taymans
13923416e0 alsa: keep track of rate in card object
Expose the card object and always obtain one per pcm.

Keep the configured format in the card object.

Add a api.alsa.multi-rate property. When multi_rate is disabled,
only allow the last configured card rate on all PCMs.

This works around drivers that can't handle multiple samplerates
on their PCMs.

With this patch it should be mostly safe to configure multiple
sample rates in pipewire.conf

See #1547
2021-11-23 11:44:26 +01:00
Wim Taymans
f5f66d1718 alsa: free card on error 2021-11-17 12:55:51 +01:00
Wim Taymans
dfdd9a6b3b alsa: don't prefix NAME, log topics are enough 2021-10-03 08:05:40 +02:00
Wim Taymans
7c11dcf808 alsa: enumerate all passthrough formats
Don't use the audio.channels and audio.rate settings influence the
passthrough formats.

See #93
2021-09-21 13:02:48 +02:00
Wim Taymans
0ec77ab09c dsd: show rate in bytes per seconds. 2021-09-21 12:25:42 +02:00
Wim Taymans
670efe2811 alsa: implement set_format for DSD formats 2021-09-21 10:50:45 +02:00
Wim Taymans
af6e887077 spa: add interleave DSD param
And make alsa report the interleaving.
2021-09-21 10:50:45 +02:00
Wim Taymans
25d39a5ea1 alsa: only expose DSD format when DSD_U32_BE is supported 2021-09-21 10:50:44 +02:00
Wim Taymans
1b5d02dd31 alsa: add enumeration of DSD formats 2021-09-21 10:50:44 +02:00
Wim Taymans
349324b9a6 alsa: pass AES bits to S/PDIF devices
This is the right thing to do and might even fix output to some
devices.
2021-09-14 12:42:03 +02:00
Wim Taymans
44f10330e8 alsa: remove AES0 settings
Remove this for now, we should only add this when actually sending
encoded formats.

Fixes #1570
2021-09-05 08:21:07 +02:00
Wim Taymans
99e6c77525 alsa: improve device name construction
Get the ucm prefix only once, when we open the UCM card and then
use it for all devices using the card.

Construct the device name right before we open it with the ucm prefix
and possibly the AES flags instead of messing with the property.
2021-09-02 12:35:58 +02:00
Wim Taymans
01f640709e alsa: always list PCM as iec958 codec
Always put PCM as the supported format for iec958.
Only accept iec958codecs for iec958 capable nodes.
2021-09-01 13:22:39 +02:00
Wim Taymans
71055dce73 alsa: handle excessive delay values gracefully
When we read an excessively large delay value, clamp it to twice the
delay so that we don't set our timeout to something too far in the
future.
2021-08-31 12:38:18 +02:00
Wim Taymans
09ee977141 alsa: cache UCM config
ALSA has problems with creating more than 8 configs per card so cache
the config per card and reuse it.

Fixes problems with no devices after logging out and in again because
ALSA can't create UCM profiles anymore.

See #1553
2021-08-30 17:36:11 +02:00