Commit graph

270 commits

Author SHA1 Message Date
Wim Taymans
e940361c94 alsa: don't check early wakeup when PCM stopped
When the PCM is stopped, don't check for early wakeup because if we
are early, we will never be on time in the next iteration either because the
PCM is stopped and doesn't advance.

Also don't try to align when stopped.

See #3565
2023-10-12 15:28:53 +02:00
Wim Taymans
0ca1acb3d5 alsa: don't resync capture when linked
We should be aligned correctly.
2023-10-12 15:28:21 +02:00
Wim Taymans
080c40d938 alsa: handle errors from get status
And skip a cycle.
2023-10-12 15:17:48 +02:00
Wim Taymans
a8636b04cb alsa: always read/write follower samples
Ignore errors such as -EAGAIN, just write what we have.

See #3565
2023-10-12 11:40:50 +02:00
Wim Taymans
a9659d9dce alsa: add Tag set and enum support
So that we can see the tags on the sinks and sources.
2023-10-11 15:56:52 +02:00
Wim Taymans
77651e130e alsa: add extra checks
Check if the device is opened when doing _prepare or _start. When it was
a follower but failed to open, we might otherwise crash.

Fixes #3554
2023-10-11 11:39:45 +02: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
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
96c12c2988 alsa: do playback sync even when alsa is paused
We only start the ALSA pcm after we get our first buffer.

We still need to do the sync through (and get the number of prefilled
samples) to make sure we set our new timeout and don't keep on waking
up quickly while the graph fetches the first buffer.
2023-10-02 15:38:52 +02:00
Wim Taymans
099e2cf27a alsa: silence an error after resync 2023-09-22 11:23:51 +02:00
Wim Taymans
03840a2a9a alsa: fix recover logic
We can't call spa_alsa functions from the data thread. Iterate ourselves
over the linked devices that we all need to recover as a group.
2023-09-20 15:38:41 +02:00
Wim Taymans
a56ed47c5e alsa: set the driver rate in the clock io
Rename some variables to make it clear that we are dealing with the rate
and duration of the driver.
Set the driver rate in the clock instead of the target_rate, which we
might have rejected.
2023-09-20 11:32:34 +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
ee1bb2362d alsa: sync followers from the driver
Keep track or the follower state and do the sync from the driver
wakeup.

This improves sync between devices because the sync no longer
depends on when the node was woken up in the graph and scheduled. We
would have been able to handle this difference by using the htimestamp
but that doesn't seen to work reliably on some hardware.

This is also essential for the interrupt based scheduling.
2023-09-18 14:53:15 +02:00
Wim Taymans
c51f6ccbd7 alsa: rework the state sync code
Make one function to sync the state with the realtime thread.
2023-09-18 14:46:56 +02:00
Wim Taymans
86f1d14b72 alsa: keep states in global list 2023-09-18 09:40:52 +02:00
Barnabás Pőcze
fc72208fa0 spa: alsa: mark spa_alsa_silence() static 2023-09-16 17:38:51 +02:00
Wim Taymans
71808454e7 alsa: add and remove sources from data_loop
Add and remove timers and pollfd from the data-loop.
Rework setup_sources.
Start IRQ playback after adding pollfd to make sure we get all events.
2023-09-15 16:31:55 +02:00
Wim Taymans
c6f9cfa220 alsa: IRQ based scheduling wakes up after finishing 1 period
So we need to keep 2 periods of silence to keep 1 period of data inside
the ringbuffer when starting the graph.
2023-09-15 15:36:56 +02:00
Wim Taymans
eac74f6ece alsa: fix warning when compiling without FASTPATH 2023-09-15 15:35:52 +02:00
Wim Taymans
c8db951d61 alsa: some cleanups
Make sure we recycle an old buffer even if we don't have a new buffer to
push.
2023-09-15 13:05:31 +02:00
Wim Taymans
bf5b526464 alsa: small cleanups 2023-09-15 12:40:30 +02:00
Wim Taymans
c6745ed0d0 alsa: refactor read and write functions
Separate the sync logic from the read/write functions so that we can use
it in the wakeup logic as well.
2023-09-15 12:21:18 +02:00
Wim Taymans
e975cb16d3 alsa: add spa_alsa_prepare()
Split the spa_alsa_start() in a prepare and start function. Prepare
will then also reset state and prefill the playback buffer with silence.

This makes it possible to reuse the prepare function in recover().
2023-09-15 11:15:26 +02:00
Wim Taymans
a5d684af8a alsa: make sure we recalculate config when samplerate changes
The threshold depends on the samplerate and even when the graph rate or
quantum didn't change, the driver could be opened in a different
samplerate, which would cause the timeouts to be wrong and cause xruns.
2023-09-15 11:14:10 +02:00
Wim Taymans
99cf172bc7 alsa: improve debug
Use a new state variable to store the device name and direction so that
we consistently can debug those.
2023-09-15 09:09:04 +02:00
Wim Taymans
3c5da11706 alsa: set_timeout is only called when tsched is enabled.
We don't need to do an extra check.
2023-09-14 17:16:44 +02:00
Wim Taymans
4ffa7860bc alsa: update the clock name when we can
Update the clock name as soon as we get a io_clock. This way we can use
it to compare the clock name against the driver right away.
2023-09-14 17:15:06 +02:00
Wim Taymans
354ee6fd96 alsa: with IRQ we can use avail_update()
It does not need an ioctl because the driver already updated the info
before waking us up from poll.
2023-09-14 16:16:48 +02:00
Wim Taymans
016d15e598 ratelimit: missed -> suppressed
To avoid confusing with missed samples.
2023-09-08 12:18:23 +02:00
Wim Taymans
ccc591ae0f alsa: use target_rate from the position
We need to use the target_rate of the clock in the position io area to
get the next rate of the graph.
2023-09-01 10:02:28 +02:00
Wim Taymans
6fb53fc9f1 alsa: round to next power of 2 for max period_size
Prefer to make the period_size bigger rather than smaller because of
rate conversion.
2023-09-01 09:54:58 +02:00
George Kiagiadakis
af020bc425 alsa: report latency in the samplerate domain of the graph 2023-09-01 00:30:14 +03:00
Wim Taymans
21392d898e alsa: improve xrun clock field calculation
We're missing the delay in samples plus all of the extra samples of
silence we use to restart the device. This is in the samplerate of
the device.

Convert this to the time domain of the graph before adding it to xrun.
2023-08-31 14:28:56 +02:00
Wim Taymans
d2c29760e9 alsa: scale the default period with the rate
The default period is based on the default rate and might be too small
when using high samplerates. Scale the rate with the samplerate and make
sure it's a power of 2 to avoid trouble.

Fixes #3444
2023-08-31 12:01:06 +02:00
Wim Taymans
6bf42e9bcd alsa: refuse quantum/rate changes when driving irq based 2023-08-29 10:14:43 +02:00
Wim Taymans
e90cab1cde node: add xrun counter in clock io
Add an xrun counter in the clock that accumulated the duration of
xruns. Fill this in in alsa-pcm.

A client could use this to dectect xruns (when it changes) and to align
the position and nsec after an xrun.
2023-08-29 09:22:45 +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
d08d05629b alsa: reflow some code
Move common code outside the if branches.
Only do the batch and timer stuff when using timers.
2023-08-23 13:56:20 +02:00
Wim Taymans
fd585baa88 alsa: don't change avail when unchanged
Only update the avail when we did a snd_pcm_forward(). Otherwise
we might think there is more available than there really is and we
might get xrun.

See #3395
2023-07-31 12:10:36 +02:00
Wim Taymans
dd78f3d5f7 alsa: disable htimestamp by default
It seems there are drivers that don't return a good values and we end up
with a lot of delay or automatic disable of htimestamp when the values
look too off.
2023-07-26 10:32:53 +02:00
Wim Taymans
dc07c2321b spa: add spa_ratelimit 2023-07-11 19:25:35 +02:00
Wim Taymans
159fa7177a alsa: fix threshold sign
Be careful when converting the uint32_t to int64_t, first convert and
then flip the sign.
2023-07-05 12:01:08 +02:00
Wim Taymans
937a13d93f alsa: relax htimestamp threshold a little
Only assume an error when larger than 3 times the expected size. Clamp
to the threshold to not cause excessive delay compensation.
2023-07-05 11:46:19 +02:00
Wim Taymans
927eb64177 alsa: use get_avail() recover logic
Always use get_avail() and then only fetch the hires timestamp when
enabled to enhance the delay reporting. This way we also recover from
errors from snd_pcm_avail() instead of ignoring them.

This should make the recover after mmap_begin obsolete but we'll leave
that just to be safe.
2023-07-03 17:08:08 +02:00
Wim Taymans
2963e7fd4c alsa: disable htimestamp when it seems to error too much 2023-06-29 16:40:21 +02:00
Wim Taymans
f76191c792 alsa: add option to disable htimestamps
Add api.alsa.htimestamp to disable the use of hires timestamps.
2023-06-29 16:23:39 +02:00
Wim Taymans
3dab0091bb alsa: warn when the htimestamp seems wrong
The htimestamp should be close to the current_time, if it is further
away that the threshold, something is wrong.
2023-06-29 15:56:43 +02:00
Wim Taymans
b32715ba41 alsa: try to recover when mmap_begin fails
In case the get_avail call did not catch the device error, handle the
error and try to recover in the mmap_begin call instead.

See #3315
2023-06-27 13:25:47 +02:00
Arun Raghavan
de2d7a583b alsa: Actually write out pitch elem value during initial reset
Without this, we were assuming our inital rate of 1.0 was also what was
applied to the feedback endpoint, but that was not actually true.
2023-06-23 16:45:36 +00:00