Commit graph

134 commits

Author SHA1 Message Date
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
Wim Taymans
b0a9945ed0 alsa: only enable PCM iec958 codec when configured
Rework the codec enumeration a little and don't automatically enable PCM
as the code unless requested by the user.
2021-08-23 17:07:17 +02:00
Wim Taymans
437275460c alsa: add set_format for iec958 formats 2021-08-23 11:31:52 +02:00
Wim Taymans
9dfe35b17c alsa: add enumeration of iec958 format
For hdmi and iec958 devices, enumerate the iec958 formats and
codecs. Initially only PCM is supported as a codec but with
a property or an init option, the list of codecs can be dynamically
configured.
2021-08-23 11:31:52 +02:00
Wim Taymans
0a5a4c046d alsa: Free global state
We need to do this or else newly plugged devices might not load.

It does not seem to harm UCM config on my machine, so this reverts
3d372424cc

See #1478
2021-08-10 11:25:41 +02:00
Wim Taymans
b7162d2c09 alsa: free alibpref after use 2021-08-10 11:14:15 +02:00
Wim Taymans
3d372424cc alsa: don't free alsa global info for each node
Don't clear the global config or else we might lose the UCM state.

See #1437
2021-07-21 12:18:43 +02:00
Wim Taymans
8184d4576a handle snprintf errors better 2021-07-06 17:56:04 +02:00
Wim Taymans
35194d6de0 node-driver: remove timers when not a driver 2021-07-01 12:28:18 +02:00
Wim Taymans
8cf5927e95 alsa: keep track of input and output latency
track and report both input and output latency.
2021-06-24 09:59:48 +02:00
Konstantin Kharlamov
ed9560fb03 alsa: fix "now.tv_sec maybe used uninitialized" warnings
Fixes a number of warnings that look like this:

    In file included from ../spa/include/spa/utils/result.h:37,
                     from ../spa/plugins/alsa/alsa-seq.c:35:
    In function ‘set_timers’,
        inlined from ‘do_reassign_follower’ at ../spa/plugins/alsa/alsa-seq.c:909:2:
    ../spa/include/spa/utils/defs.h:191:39: warning: ‘now.tv_sec’ may be used uninitialized [-Wmaybe-uninitialized]
      191 | #define SPA_TIMESPEC_TO_NSEC(ts) ((ts)->tv_sec * SPA_NSEC_PER_SEC + (ts)->tv_nsec)
          |                                   ~~~~^~~~~~~~
    ../spa/plugins/alsa/alsa-seq.c:840:28: note: in expansion of macro ‘SPA_TIMESPEC_TO_NSEC’
      840 |         state->next_time = SPA_TIMESPEC_TO_NSEC(&now);
          |                            ^~~~~~~~~~~~~~~~~~~~
    ../spa/plugins/alsa/alsa-seq.c: In function ‘do_reassign_follower’:
    ../spa/plugins/alsa/alsa-seq.c:836:25: note: ‘now’ declared here
      836 |         struct timespec now;
          |                         ^~~

The reason for these warnings is that spa_system_clock_gettime() may
fail if a version check fails, but the code in question didn't check for
the possible fail. If it failed, then execution would continue, and the
arguments that were passed to the macro will be used uninitialized.

Fix this by checking whether function succeeded.
2021-06-22 22:42:25 +03:00
Konstantin Kharlamov
252e798ece alsa: remove unused res variable in alsa_on_timeout_event 2021-06-22 22:42:25 +03:00
Wim Taymans
c726dd887c alsa: refactory _io_position checking
Move the code to check the position duration for changes to one
new method.
Also check for samplerate changes and adjust the resampler state
accordingly.
2021-06-17 11:11:44 +02:00
Wim Taymans
1c513464c8 alsa: strip and add the _alibpref from device names
Strip the _alibpref from the device name, it contains a local counter
to identify the ucm card that should remain internal. We set a flag on
the device to notify of this.

Re-add the _alibpref of the local card to the device name if the
device was flagged.

See #1286
2021-06-10 15:36:26 +02:00
Wim Taymans
283e13629c alsa: use the local alibpref of the card
The _alibpref of the device was created in the session manager and
does not match our local _alibpref. Patch the device name with
the local _alibpref to make things match.

See #1286
2021-06-10 13:25:54 +02:00
Wim Taymans
d8e0176bcf alsa: open UCM only once.
See #1286 #1269
2021-06-10 09:58:11 +02:00
Wim Taymans
35e81fbfdc alsa: rework UCM open
Use _alibpref to check if a device needs a UCM local config. Mark
the device as such and use this to set the OPEN_UCM property on
the device.
Open the UCM for a card when the device has the property set. Use the
same logic for loading the UCM as the acp code.

See #1251
2021-06-02 17:25:21 +02:00
Wim Taymans
e3d3f04780 alsa: if we are passed a UCM device, make sure to open UCM
UCM devices can require local data from use_case_mgr_open() but since
we do that in a separate process, make sure we reopen the use case
manager in case we are passed a UCM device so that the config is
available.

See #1251
2021-06-02 13:23:08 +02:00
Wim Taymans
b9b89b92b2 spa: add some latency helpers
Add more fields to the latency object.
Add methods to create, parse and process latency info.
2021-05-27 15:26:09 +02:00
Wim Taymans
1cd6d7b01d spa: Implement latency reporting
Implement latency reporting in alsa
Implement latency reporting on audioconf by passing on the latency
from the follower to outside of the adapter.
2021-05-27 15:26:09 +02:00
Peter Hutterer
4dd886188a alsa: fix scan-build errors for unused variables
All cases of value stored but never read
2021-05-26 07:51:27 +00:00