Commit graph

207 commits

Author SHA1 Message Date
Wim Taymans
11f1298f53 spa: make a function to make a channel short name
Make a function that can generate and parse a short name for
the positions that are not in the type list, like the AUX channels.
2025-10-22 13:04:53 +02:00
Wim Taymans
818d1435ce treewide: access the position information using helpers
Make sure we don't access out of bounds and that we use the helpers
wherever we can to access the position information.
2025-10-21 13:06:25 +02:00
Wim Taymans
8bbca3b8f3 spa: add spa_audio_parse_position_n
Add a function that accepts the size of the position array when reading
the audio positions. This makes it possible to decouple the position
array size from SPA_AUDIO_MAX_CHANNELS.

Also use SPA_N_ELEMENTS to pass the number of array elements to
functions instead of a fixed constant. This makes it easier to change
the array size later to a different constant without having to patch up
all the places where the size is used.
2025-10-21 09:59:13 +02:00
Wim Taymans
9e7cae13df alsa: use the amount of positions we will write 2025-10-21 09:43:59 +02:00
Wim Taymans
13b8c23767 Don't use SPA_AUDIO_MAX_CHANNELS directly
Make a MAX_CHANNELS define and use that one in code. This makes it
easier to change the constant later.
2025-10-21 09:43:06 +02:00
Wim Taymans
a5e63102d9 alsa: unlock pending drain in drop
When we set activated=false, signal the thread because it might be
waiting in drain.

See #4728
2025-06-02 19:14:45 +02:00
Wim Taymans
5cfd461ba2 alsa: Use the configured max channels
Don't hardcode the max channels to 64 but use the globally configured
SPA_AUDIO_MAX_CHANNELS value.
2025-04-04 15:46:03 +02:00
Wim Taymans
3905e3b3d3 stream: set errno to the current error
Make the state_changed event and _get_state() function set errno with
the current error value if the state is in error, so that application
can use this to give more detailed error reporting.

Use this in alsa, v4l2 and pulse to give some other error codes than
EIO.

Fixes #4574
2025-03-04 13:22:51 +01:00
Wim Taymans
24bcacc619 conf: remove client-rt.conf
We now automatically move non-rt clients into non-rt threads so the
client-rt.conf is obsolete.

Move the module-rt in client.conf and add conditions to disable modules.

Transparently load client.conf in case applications still specify
client-rt.conf.

Custon configuration in the client-rt.conf.d/ should be moved to
client.conf.d/
2025-01-14 12:40:05 +01:00
Wim Taymans
188d920733 pass the right types to the methods
This currently works because we accept void* for these functions but it
will fail when we will use the real types.
2024-11-20 10:17:37 +01:00
Wim Taymans
e2991f6398 json: add helper function to parse channel positions
Use the helper instead of duplicating the same code.

Also add some helpers to parse a json array of uint32_t

Move some functions to convert between type name and id.
2024-09-18 09:54:34 +02:00
Wim Taymans
b5cccdb382 json: add and use spa_json_str_object_find()
Parse a string as a json object and copy the value with key as a string.
2024-09-16 13:12:05 +02:00
Wim Taymans
ce390d5b22 spa: add spa_json_object_next
This gets the next key and value from an object. This function is better
because it will skip key/value pairs that don't fit in the array to hold
the key.

The previous code patter would stop parsing the object as soon as a key
larger than the available space was found.
2024-09-16 09:50:36 +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
feccb882b6 spa: add spa_json_begin
That combines spa_json_init() and spa_json_next, a common thing to do.
2024-09-16 09:50:31 +02:00
Wim Taymans
dede88fc22 alsa: add DSD format support
Add DSD support to the ALSA plugin.

You will need to manually enable the supported DSD formats for the
platform you are running on because we don't support any conversions or
probing for DSD:

PIPEWIRE_ALSA='{ alsa.format = "DSD_U32_BE" }' src/tools/pw-alsa-dsd somefile.dsf

Fixes #4160
2024-08-02 13:01:35 +02:00
David Coles
5d7624001d Add spa/utils/endian.h
This provides access to GNU C library-style endian and byteswap functions.

Windows doesn't provide pre-processor defines for endianness, but
all current Windows architectures (X32, X64, ARM) are little-endian.
2024-07-01 15:28:58 +00:00
Diego Viola
7410755c03 Fix typos
found them with codespell.

Signed-off-by: Diego Viola <diego.viola@gmail.com>
2024-05-22 09:19:34 +02:00
Wim Taymans
62aa77d469 alsa: remove racy atomic operations
The atomic operations were used in an attempt to limit the amount of
wakeups done on the eventfd. It's however racy and causes trouble in
some cases.

Remove the atomic operations all together, it's probably not worth
optimizing this too much.
2024-05-07 10:07:30 +02:00
Wim Taymans
6ab10237cd alsa: use semaphore semantics for the eventfd
Because we write from multiple threads, a thread might write a second
wakeup and a concurrent thread might remove all wakeups before seeing
it's error and retrying, which would leave the eventfd in a wrong state.

With a semaphore, things balance out and the eventfd always ends up in
a consistent state.
2024-05-06 16:26:06 +02:00
Wim Taymans
2b11efdf3b alsa: fix race when updating the eventfd
The eventfd is read/written from/to the data thread and the main thread
concurrently with the update_active() function.

Use an atomic compare and swap to make this update atomic and avoid an
inconsistency between the active boolean and the eventfd. This could
result in the eventfd being unsignaled while the active flag was true
and the application receiving a timeout and XRun in its poll loop.

Fixes #3711
2024-04-16 09:30:23 +02:00
Wim Taymans
f4e391dd41 stream: add pw_stream_get_nsec() to get current time
Make a method to get the current time to compare agains the pw_time-now
field. This is currently CLOCK_MONOTONIC but make this into a method
so that we can more easily change it later.
2024-03-04 12:59:26 +01:00
Jonas Holmberg
e78e97cb99 pipewire-alsa: Propagate errors from eventfd().
Propagate the error if spa_system_eventfd_create() fails. Also copy
errno before calling spa_log_debug() in spa_system_eventfd_create() to
make sure it is not overwritten.
2024-02-19 14:16:26 +00:00
Wim Taymans
b3e3d301c0 alsa: restart the node on hw_param change
When we emit a new EnumFormat, the adapter will renegotiate a new format
that will be applied when we restart.

Fixes #3858
2024-02-19 15:11:30 +01:00
Wim Taymans
16479acc60 alsa: fix version check
See #3711
2024-02-01 21:42:07 +01:00
Wim Taymans
4e1b10073a alsa: handle period events
When the period events are enabled, we need to wake up whenver there is
a period elapsed. Otherwise, we only wake up when there is avail_min.

Fixes #3676
2023-11-30 12:05:41 +01:00
Wim Taymans
92330b9de3 alsa: the default poll_descriptors is good now
Remove our custom poll_descriptors function because the default is
enough now that we update from revents.
2023-11-15 16:35:17 +01:00
Wim Taymans
266ef3b986 alsa: update pollfd from poll_revents() as well
Some clients don't call _poll_descriptors() before entering the poll and
so don't get updated fds. This would result in a whole bunch of wakeups
when the eventfd was set but the new state is no longer active.

Part of the problem is also that check_active() returns the desired new
state and update_active() does check_active() + update. We could be
getting into a new desired inactive state without updating the eventfd.
Improve this by merging them together into update_active() which only
writes/reads the eventfd when something changes.

This also makes things less heavy because the eventfd is only
read/written when needed.

Fixes #3648
2023-11-15 15:40:02 +01:00
Wim Taymans
920beea3eb alsa: guard agaist NULL areas
snd_pcm_ioplug_mmap_areas() can fail and return NULL

Fixes #3600
2023-10-22 17:27:27 +02:00
Wim Taymans
e063cc38a9 alsa: add alsa.deny to fail init of the PCM
Handy to block audacity from probing the hardware.
2023-10-12 18:41:37 +02:00
Wim Taymans
ee05daea53 alsa: improve property handling
Add support for setting lists and min/max values for the alsa params.

list:    alsa.rate = [ 32000 44100 ]
min/max: alsa.rate = { min=32000 max=44100 }
value:   alsa.rate = 32000

See #3451
2023-08-22 12:44:51 +02:00
Wim Taymans
0501ef165a spa: add atomic.h and port macros to it 2023-07-13 12:25:22 +02:00
Jonas Holmberg
ecbb1b0c4c pipewire-alsa: Propagate stream errors
Propagate stream errors and check for successful negotioation or error
in _prepare(). This will return an error from _prepare() if there is no
target node to link to (unless PIPEWIRE_AUTOCONNECT=false).

It would be preferable to also set PW_STREAM_FLAG_INACTIVE to not start
processing until _start() is called but then it would not be possible to
signal successful negotiation.
2023-04-25 17:04:54 +02: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
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
c8850f8766 env vars should override everything
Always first use the env var and then check the properties. So that
PIPEWIRE_CORE=pipewire-1 PIPEWIRE_REMOTE=pipewire-1 make run runs
everything on pipewire-1 sockets regardless of the config files.

Also PIPEWIRE_NODE always needs to be taken into account first.
2023-01-24 17:39:54 +01:00
Wim Taymans
ee55df9f9e alsa: add option to change the volume-method
Add option to set linear or cubic volume, cubic is now the default.
2023-01-20 10:11:49 +01:00
Wim Taymans
c7239b1f2a alsa: also use client-rt.conf for the mixer
There is no reason to use the non-rt version. It makes more sense to be
able to put all ALSA properties and rules in the same conf file.
2023-01-20 09:30:37 +01:00
Wim Taymans
eadab2ffe3 alsa: clean up volume min/max values 2023-01-20 09:29:59 +01:00
anteater
1442fa7da7 alsa: add mathlib dep 2023-01-20 08:16:50 +00:00
anteater
057a6c490b alsa: make displayed ALSA volume match PulseAudio volume
This is the same behavior as `apulse`, for example, and is more clear for users.
2023-01-20 08:16:50 +00:00
Wim Taymans
6af85f2371 alsa: fix compilation 2023-01-19 19:18:53 +01:00
Wim Taymans
e0bfd7421b alsa: improve property handling some more
Use properties from the context for matching first, then fill in some
defaults, then override with env variables.
Add property rules in ctl as well.
2023-01-19 18:15:32 +01:00
Wim Taymans
3c11772df6 alsa: rework config and properties
Place the configuration options directly into a pw_properties and use
that to connect the client and stream.
Add support for alsa.properties and alsa.rules to set default client and
stream properties based on rules.

See !1502
2023-01-19 17:12:29 +01:00
Wim Taymans
3873256211 alsa: free properties
When we simply update the properties of an existing stream, don't leak
the properties.
2023-01-19 15:32:29 +01:00
Wim Taymans
2254c74fb9 use TARGET_OBJECT instead of the deprecated NODE_TARGET
Clarify the docs.
2023-01-10 16:51:47 +01:00
Thomas Weißschuh
ed46324872 alsa: fix memory leak of properties 2023-01-01 02:00:36 +00:00
Wim Taymans
89ac6b3535 alsa: don´t set -1 as node.target
Leave the target unset when -1, just like what pw-stream does.

See #2893
2022-12-17 18:17:33 +01:00
Wim Taymans
122252ce52 alsa: add brackets for clarity 2022-10-27 09:12:06 +02:00
Wim Taymans
431176c618 alsa: avoid division by 0
Use the wanted amount of samples to determine the buffered data.
Also make sure we don't divide by 0.
2022-10-26 13:22:38 +02:00