Commit graph

4386 commits

Author SHA1 Message Date
Wim Taymans
7b03a41e3d spa: add some helpers to convert MIDI to and from UMP 2024-07-29 18:15:57 +02:00
Wim Taymans
3e87aca7a9 spa: Add UMP control type
UMP (universal Midi Packet) is an improved version of transmitting MIDI
messages. It also has support for MIDI 2.0 and is backwards compatible
with MIDI 1.0.
2024-07-29 18:15:57 +02:00
Wim Taymans
61dcd8dede audioconvert: set IO_Buffers only when buffers are negotiated
The IO_Buffers is used in the data thread to check if the port should be
scheduled or not. Make sure it is only set after we set buffers on the
port and cleared before the buffers are cleared.

Make sure we sync the port->io with the data thread.

See #4094
2024-07-29 18:15:06 +02:00
Vlad
308a93bd14 bluez5: Update default sync_factor
Due to the how the kernel part of BlueZ computes the extended
advertising interval for a Broadcast Source, a sync_factor smaller
than 2 will result in an invalid interval value (too small).
2024-07-28 13:45:45 +00:00
Wim Taymans
2a8a08f303 loop: signal when queue is full
When our queue is full, signal the wakeup event to make sure the thread
will wake up and try to clear the queue before we go to sleep.
2024-07-20 14:05:09 +02:00
Arun Raghavan
0dc17d8d88 spa: alsa: Fix stale function name in comment 2024-07-17 20:07:57 -04:00
Sven Püschel
0c07c78621 spa: libcamera: uncomment setting integer controls
When using Open Broadcaster Software with Pipewire and a libcamera
camera node, changing the ExposureTime doesn't work.

The commit introducing the camera control setting has commented out the
integer case: ef4b9745b2 ("libcamera: handle canceled requests")
But as it doesn't give a reson for the comment, it looks like an
oversight.

Therefore removing the comment to allow setting the ExposureTime integer.

Signed-off-by: Sven Püschel <s.pueschel@pengutronix.de>
2024-07-17 16:00:23 +00:00
Sven Püschel
5932963506 spa: match camera property types with libcamera
The Pipewire libcamera spa plugin exposes multiple camera properties.
Unlike v4l2, libcamera usually exposes these as normalized floating
point values. But as the SPA_PROP types are based on v4l2, they are
currently set to integers.

This causes a problem when using pw-cli to change the properties,
as the spa_json_to_pod_part function casts the properties according
to their spa_type_info. Other software that doesn't depend on the
spa_type_info can correctly set the properties, as the values are
encoded in the spa_pod type and therefore also carry a type.

As the limited range from switching integers to floats is likely not a
problem, the affected spa properties were changed to the Float type.
This will cause pw-cli to also generate spa_pod values of type float
when setting v4l2 properties. Therefore the v4l2 spa plugin is also
adapted to allow floating point properties and cast these to integers.

Signed-off-by: Sven Püschel <s.pueschel@pengutronix.de>
2024-07-17 15:56:53 +00:00
Frédéric Danis
291fd9704f bluez5: backend-native: Send error for not supported event only as AG
The HS/HF roles should not sent error messages, only commands.
2024-07-15 13:27:30 +02:00
Wim Taymans
d4515378e7 node-driver: 5 seconds of freewheel timeout is enough
We retry to run the graph every 5 seconds in case it didn't complete. A
10 seconds timeout feels quite long.
2024-07-12 12:25:18 +02:00
Wim Taymans
42096de3cc node: add a clock XRUN_RECOVER flag
Make a new flag that is set when the process function is called because
of a recover from a graph xrun.

Use this flag in the freewheel driver to detect a recover and to avoid
scheduling a new timeout. We should schedule a new timeout only when the
process function was called after completion.

This fixes export in ardour some more when the initial driver timeout
didn't complete (when, for example, some nodes were still starting up).
2024-07-12 12:21:59 +02:00
Wim Taymans
4baa94fce2 thread: make it possible to set a custom create function
Make a property to pass a custom function pointer to create threads
instead of pthread_create.

Use this in jack instead of bypassing the thread utils create function,
which gives the wrong thread rt priority with rtkit.

Fixes #4099
2024-07-09 17:04:35 +02:00
Wim Taymans
853a46120e v4l2: Improve format and control enumeration
Use dynamic pod builder so that we can also build complex formats.

Make sure we zero the format before we parse it or else we end up with
potentially uninitialized values.

When ENUM_FRAMESIZES or VIDIOC_ENUM_FRAMEINTERVALS return EINVAL for the
first index, make a dummy result and continue with that. This will
trigger an intersect withe filter so that we end up with something valid
instead of nothing.

Handle 0 framerates without crashing.

See #4063
2024-07-09 14:14:42 +02:00
Wim Taymans
2c1ec7fa43 v4l2: use a dynamic pod builder to handle larger PropInfo
The labels from the vivid driver need more space so use a dynamic
builder to make sure we can handle them.

See #4063
2024-07-09 09:23:49 +02:00
Pauli Virtanen
38d7dedf0c alsa-card-profiles: reduce priority of HDMI/AC3 profiles
These don't appear to work correctly on all hardware, even if ACP thinks
they are present, so reduce their priority
2024-07-05 16:12:17 +03:00
Pauli Virtanen
ea19554e8d spa: alsa: recognize plug+a52 as a52 device strings
HDMI/AC3 profiles use plug+a52 for a52 output, and should be handled
like a52.
2024-07-05 16:06:17 +03:00
Pauli Virtanen
589a06e105 spa: utils: explicitly preserve errno in spa_cleanup handlers
The cleanup handlers like free(), close(), etc. aren't necessarily
guaranteed to preserve errno, so do it explicitly.

This allows for usage in functions that return NULL + errno to signal
errors.
2024-07-04 20:57:51 +00:00
Pauli Virtanen
677f3a152c spa: alsa: fix multiple %f in node device strings of nodes
ACP allows multiple %f in device strings (cf pa_alsa_open_by_template),
but we replace only one of them when emitting the nodes. The a52
profiles in default.conf use multiple %f and probably don't work.

Fix to replace also multiple %f when emitting ACP device nodes.
2024-07-04 20:57:19 +00:00
David Coles
015a367e30 Rename sample config that prevents checkout on Windows
`:` is a reserved character on Windows filesystems.

As far as I can tell from looking through both PulseAudio and PipeWire
commit history the files under `alsa/mixer/samples` are not used or
installed by anything.

See #2474.
2024-07-01 15:28:58 +00:00
David Coles
9ae9009edf Define setlinebuf for MSVC
According to `setbuf(3)`, `setlinebuf` is exactly equivalent to
`setvbuf(stream, NULL, _IOLBF, 0)`.
2024-07-01 15:28:58 +00: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
David Coles
a97e8b6d1f Avoid using interface as a variable name
While not a reserved keyword, MSVC `#define interface struct`[1]
which causes a compile error when including the `spa/support/plugin.h`
header. While this can be worked around by `#undef interface`, it's
also easy to just rename the local variable.

[1]: https://stackoverflow.com/questions/25234203/what-is-the-interface-keyword-in-msvc
2024-07-01 15:28:58 +00:00
David Coles
dd652d01b8 Port videotestsrc to LoopUtils
The `LoopUtils` interface can be used on platforms that don't
support the Linux-specific `timerfd` interface.

Added `local-videotestsrc` to validate the plugin still functions.

Restructured the SDL event loop as the window would not update
under WSL2, resulting in a black window being shown. All rendering
in SDL2 must happen on the same thread that originally created the
renderer.

To prevent the SDL event loop from being starved, we make sure to
poll it at least every 100 ms.
2024-07-01 15:28:14 +00:00
Wim Taymans
c94d5ed215 tests: don't iterate all possible values
Or else the valgrind unit test times out.
2024-07-01 17:20:25 +02:00
Wim Taymans
b1bb0ead3c alsa: remove unused variables 2024-06-30 21:23:00 +02:00
Barnabás Pőcze
04450e14a4 treewide: fix more -Wformat issues
See !2057
2024-06-30 19:22:17 +00:00
Eli Schwartz
b5f031bc15 meson: fix conflicting use of feature-based dependency lookups
When spa-plugins is enabled, the gio-2.0 global dependency is
overwritten.

When bluez support is enabled, OR when gsettings is enabled, the gio-2.0
dependency is then detected as found. This means that
pipewire-module-protocol-pulse can end up enabling gsettings support
even if it has been forcibly turned off.

Rename the meson variables to ensure they are looked up separately.
2024-06-30 18:39:38 +00:00
David Coles
2770e96e08 loop: fix update_timer handling of solo repeat argument
I believe the intent here is that if a `interval` is provided
but `value` is unset, then `value` should default to `period`
so the timer first fires after one `interval`.

Since `interval` is always a relative duration, `value` should
be interpreted as a relative duration, not an absolute one.
2024-06-30 18:37:49 +00:00
Stefan Ursella
0b39c4ec68 alsa-pcm: add basic bind-ctl write functionality 2024-06-28 12:00:16 +02:00
Barnabás Pőcze
ec521ca870 meson.build: enable -Werror=format 2024-06-27 21:18:06 +00:00
Barnabás Pőcze
adc60af45b spa: utils: use SPA_N_ELEMENTS in for-each macros
This way the compiler is able to detect cases when
a pointer is specified instead of an array.

Furthermore, incompatible pointer types can also
be diagnosed in `SPA_FOR_EACH_ELEMENT()`.
2024-06-27 21:18:06 +00:00
Roman Lebedev
7c40cafa7c
audioconvert: avoid even more precision loss in F32 to S32 conversion
This is somewhat similar to the S32->F32 conversion improvements,
but here things a bit more tricky...

The main consideration is that the limits to which we clamp
must be valid 32-bit signed integers, but not all such integers
are exactly losslessly representable in `float32_t`.

For example it we'd clamp to `2147483647`,
that is actually a `2147483648.0f`,
and `2147483648` is not a valid 32-bit signed integer,
so the post-clamp conversion would basically be UB.
We don't have this problem for negative bound, though.

But as we know, any 25-bit signed integer is losslessly
round-trippable through float32_t, and since multiplying by 2
only changes the float's exponent, we can clamp to `2147483520`!
The algorithm of selection of the pre-clamping scale is unaffected.

This additionally avoids right-shift, and thus is even faster.

As `test_lossless_s32_lossless_subset` shows,
if the integer is in the form of s25+shift,
the maximal absolute error is finally zero.

Without going through `float`->`double`->`int`,
i'm not sure if the `float`->`int` conversion
can be improved further.
2024-06-27 19:41:20 +03:00
Roman Lebedev
f4c89b1b40
audioconvert: avoid even more precision loss in S32 to F32 conversion
There's really no point in doing that s25_32 intermediate step,
to be honest i don't have a clue why the original implementation
did that \_(ツ)_/¯.

Both `S25_SCALE` and `S32_SCALE` are powers of two,
and thus are both exactly representable as floats,
and reprocial of power-of-two is also exactly representable,
so it's not like that rescaling results in precision loss.

This additionally avoids right-shift, and thus is even faster.

As `test_lossless_s32_lossless_subset` shows,
if the integer is in the form of s25+shift,
the maximal absolute error became even lower,
but not zero, because F32->S32 still goes through S25 intermediate.
I think we could theoretically do better,
but then the clamping becomes pretty finicky,
so i don't feel like touching that here.
2024-06-27 19:41:20 +03:00
Roman Lebedev
c517865864
audioconvert: somewhat avoid precision loss in S32 to F32 conversion
At the very least, we should go through s25_32 intermediate
instead of s24_32, to avoid needlessly loosing 1 LSB precision bit.

That being said, i suspect it's still not doing the right thing.
Why are we silently dropping those 7 LSB bits?
Is that really the way to do it?
2024-06-27 19:41:20 +03:00
Roman Lebedev
175d533b56
audioconvert: somewhat avoid precision loss in F32 to S32 conversion
At the very least, we should go through s25_32 intermediate
instead of s24_32, to avoid needlessly loosing 1 LSB precision bit.

FIXME: the noise codepath is not covered with tests.
2024-06-27 19:41:20 +03:00
Roman Lebedev
2a035ac49e
audioconvert: introduce s25_32 type, f32<->s25 cast is lossless
The largest integer that 32-bit floating point can exactly represent
is actually `(2^24)-1`, not`(2^23)-1` like the code assumes.
This means, whenever we use s24 as an intermediate step
to go between f32 and s32, we lose a bit of precision.

s25_32 is really a i32 with highest byte always being a sign byte.

Printing was done by adding
```
for(int e = 0; e != 13; ++e)
fprintf(stderr, "%16.32e,", ((float*)m1)[e]);
```
to `compare_mem`. I don't like how these tests work.

https://godbolt.org/z/abe94sedT
2024-06-27 19:41:20 +03:00
Arun Raghavan
3f35b80402 spa: aec: webrtc: Fix multichannel processing
Missed this parameter while porting to webrtc-audio-processing 1.0.
2024-06-25 15:34:30 -04:00
Wim Taymans
9d1d1fcbef impl-port: add port.group property
Can be used to group ports together. Mostly because they are all from
the same stream and split into multiple ports by audioconvert/adapter.

Also useful for the alsa sequence to group client ports together.

Also interesting when pw-filter would be able to handle streams in the
future to find out what ports belong to what streams.
2024-06-24 13:38:09 +02:00
Pauli Virtanen
6b6e9c4ea9 bluez5: make node.group valid JSON
The node.group property is parsed as JSON, and as it here contains ":"
it needs to be quoted accordingly. Fixes pw_strv_parse errors in logs.
2024-06-21 13:29:30 +03:00
Vlad Pruteanu
88d9d58333 bluez5: bap: Rework broadcast code length check
Co-authored-by: P V <pav@iki.fi>
2024-06-20 21:06:32 +00:00
Vlad Pruteanu
4c1271805e bluez5: bap: Fix parsing of broadcast code
This fixes the endianness of the parsed broadcast code. It also
fixes pontetial out-of-bouns write by using a bigger, temporary
bcode string, then, after checking it's length, copying it's content
to big_entry->broadcast_code.
2024-06-20 21:06:32 +00:00
Wim Taymans
ea7e0e9152 spa: revert peer_enum_params node event again
It's not used anymore because it does work so well.

The problem is that while it transparently proxies param enums on
ports to peers, it fails to emit events when those peer
params change in a way that would make the enum result change as well.
This makes it quite hard to use this correctly.
2024-06-20 10:22:45 +02:00
Wim Taymans
e3ffcbefb6 spa: fix volume plugin compilation 2024-06-18 15:44:26 +02:00
Wim Taymans
f7d59bcea7 fix compilation some more
The math M_*f symbols are GNU extensions.
2024-06-18 15:41:12 +02:00
Wim Taymans
69251948ee vulkan: fix compilation 2024-06-18 15:16:06 +02:00
Wim Taymans
1ae4374ccf Fix compilation with -Werror=float-conversion
Better make the conversions explicit so that we don't get any surprises.

Fixes #4065
2024-06-18 12:17:56 +02:00
Arnav Singh
2501b347ef
spa: bluez: fix crash when receiving signal from modemmanager
6e581deb91 added an `spa_autoptr(DbusMessage) m`
for the new message sent out when a signal is received from modemmanager.
However this ended up shadowing the original `m` function arg,
so the code that wanted to interrogate the original arg with
`dbus_get_message_path` etc ended up interrogating this `NULL` value instead.
This triggered a NULL-check in `dbus_get_message_path` and caused
the process to abort.

Original downstream report: https://gitlab.com/postmarketOS/pmaports/-/issues/2886
2024-06-15 10:11:38 -07:00
Vlad Pruteanu
1466d0ae78 bluez5: bap: Use a string instead of int array to set Broadcast code
Currently, the user sets the Broadcast Code via an array of integers
in the config file. However, the Bluetooth Core Specification indicates
that it should be set via a 16 byte string. This commit replaces the old
implementation with the one required by the spec.

Tested the commit with the example provided in the Core Spec:
Broadcast Code: Børne House
Result from btsnoop log:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
...
Broadcast Code[16]: 000000006573756f4820656e72b8c342

The result matches the example given in the spec.
2024-06-14 06:05:14 +00:00
Wim Taymans
b421331275 doc: clarify the dither.noise
Fixes #4057
2024-06-13 11:38:26 +02:00
Wim Taymans
0115042adb buffer: add that the mapoffset is page aligned 2024-06-13 10:22:58 +02:00