Commit graph

12649 commits

Author SHA1 Message Date
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
Wim Taymans
8cff77706a module-snapcast: don't hardcode the JSON message id
Use a counter to make it increment for each message.
2024-07-09 09:10:31 +02:00
Arun Raghavan
9b33cea0f7 module-rtp: Minor robustness improvement to PTP socket reading
Mark socket as CLOEXEC like we do everything else, log when we flush
stale data, and check for errors in the while loop.
2024-07-06 22:45:56 +00:00
Arun Raghavan
858f534436 module-rtp: Allow setting session ID/version as parameters
This allows for externally setting the value at runtime, like we do with
the session name.
2024-07-06 22:45:56 +00:00
Arun Raghavan
6623eb8254 module-rtp: Allow overriding session version
This allows us to set an session version for the SAP externally. Also
the default is changed from 0 to an NTP timestamp, as recommended by the
spec[1].

[1] https://datatracker.ietf.org/doc/html/rfc4566#section-5.2
2024-07-06 22:45:56 +00:00
Arun Raghavan
7c8453f260 module-rtp: Allow overriding session ID
This allows us to specify a static session ID, so that (Dante) receivers
can uniquely identify us as a sender. This prevents duplicate streams in
Dante Controller, for example.
2024-07-06 22:45:56 +00:00
Wim Taymans
f5512e8b88 module-protocol-simple: use interface address as server address
Move the address:port parsing code to the net helper. Add a default
address option.

Pass the interface address to protocol-simple and use this as the
default address for listening.

This makes sure that when the user passes tcp:3400 that we don't end up
publishing 0.0.0.0:3400 but the actual address of the interface we are
listening on so that the snapcast discover can use this to notify the
snapcast server.

Fixes #4093
2024-07-06 10:12:27 +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
Pauli Virtanen
daef48b0eb conf: fix context.exec args parsing
The 'args' can be either JSON array, or a string.  If a string it should
not be parsed as JSON for a second time, but instead split at
whitespaces.
2024-07-04 20:54:51 +00:00
Arun Raghavan
35ba50f117 module-rtp: Update SAP session if stream properties change
This allows us to propagate changes to session name, destination IP,
etc.
2024-07-04 08:38:14 -04:00
Wim Taymans
2d0bc982bc impl-node: set INACTIVE state on server
Don't wait for the client to set the INACTIVE state, do it on the
server. We already decremented the target required so we don't want to
schedule the node anymore.

Fixes some xruns when removing nodes in a stress test.
2024-07-03 17:42:39 +02:00
Arun Raghavan
02fea0ba8f module-rtp: Allow updating sess.name from params
We might want to add more such properties to be dynamically updated, but
just adding this one for now.
2024-07-03 10:07:27 -04:00
Wim Taymans
59b9da9477 impl-node: disable async for driver nodes
Make it so that a driver node can never be scheduled async. It could
possibly make sense when the driver node is not currently driving the
graph but when it drives the graph it always needs to be sync. This
also simplifies the target activation because we can simply check the
async state and ignore if the node is driving or not.

Also make sure that we never make an async link with a driver output port.
This does not make sense because the driver node will always be
triggered sync first and before the async node so we can simply make
a sync link.

This fixes the modified (only generate 1 buffer) video-src -> video-play
case where the buffer never arrives in video-play because of the
useless async link.

Fixes #4092
2024-07-03 14:49:12 +02:00
Robert Mader
586e116f3c gst: stream: Destroy stream before clearing variable
`pw_stream_destroy()` chains up to `on_remove_buffer()` in
GstPipeWireSrc which again needs the stream to still be around to call
`pw_stream_queue_buffer()` on it. By using `g_clear_pointer()` it will
already have been cleared, causing crashes.

Revert to the behavior from before the commit mentioned below and add a
comment in order to avoid regressing in a future cleanup.

Fixes: 0c40c0147 (gst: factor out the stream management and some common variables in a new class)
2024-07-02 20:36:57 +02:00
Robert Mader
226440382b gst: src: Reset transform on stream stop
When a stream is stopped, chances are high that downstream elements
change or get reset, i.e. don't remember a previously send rotation
event. Thus reset the transform value in order to ensure we create a new
one on the next stream start.

In order to not regress the case when downstream *does* remember the
orientation and the buffer orientation changes from e.g.
`TRANSFORMATION_90` to `TRANSFORMATION_None` between stream
stop and restart, initialize the remembered transform to an invalid
value and ensure we always send a rotation event, even for
`TRANSFORMATION_None`.
2024-07-02 15:15:05 +02: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
29171cadb5 context: improve sync group handling some more
Keep track of the sync nodes we added to a driver and bring in the other
nodes from the same sync group, group or link groups. This makes it
possible to have disjoint sync groups each with their own driver.
2024-07-01 16:05:07 +02:00
Wim Taymans
070bcea63b context: Fix node collect with groups and sync enabled
When checking for the nodes to collect with a driver, don't just skip
checking the other nodes when the driver is not in the sync group.
Instead collect all nodes that have the same group and link group as
the driver first and then check the sync groups.

Fixes export in ardour8

Fixes #4083
2024-07-01 14:50:34 +02:00
Wim Taymans
dc5f441909 module-raop: only set softVolume when valid 2024-07-01 11:42:29 +02:00
Wim Taymans
b151b1f570 impl-node: fix required state for async driver nodes
When the node activation.required was incremented because it was a
driver, only decrement it in that case, regardless of the current driver
state of the node.

This fixes the case of KODI where the required field gets out of sync
and things become unschedulable.

Fixes #4087
2024-07-01 10:36:09 +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
17fcc9fc51 pw-container: use smaller path for temporary file
The automatically deduced size is sufficient. This
prevents a -Wformat-overflow warning.
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
Wim Taymans
7b4c0dd5ec 1.2 2024-06-27 15:31:45 +02:00
Wim Taymans
1e5d9cc635 impl-node: increment async driver nodes required field
A driver can't be async, we always need to be able to trigger it
to start it so increment the required field.

Fixes an issue with asunc drivers such as the video-src example or gnome
screen sharing.
2024-06-27 13:22:52 +02:00
Barnabás Pőcze
7732d0e3e5 pipewire: module-raop-sink: use uint32_t for sample rate
32 bits are enough, and additionally this also fixes an incorrect
format string, which caused the default `audio.rate` to be
incorrectly set on some platforms, such as 32-bit arm ones.

Fixes #4080
2024-06-27 09:46:45 +02:00
Christian Glombek
4067b3a985 module-rtp/stream: Fix setting marker_on_first prop for RAOP 2024-06-27 06:04:56 +02:00
Christian Glombek
34ae5ce649 module-raop-sink: Fix setting sess.ts-direct prop 2024-06-27 05:44:50 +02: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
Barnabás Pőcze
7674b15fab pipewire-v4l2: move open*() flag check into function
This commit moves the check that determines whether the mode
argument of `open*()` exists into a separate function.

With that, the check is fixed because previously it failed to
account for the fact that `O_TMPFILE` is not a power of two.

Furthermore, add `assert()`s in the fortified variants that
ensure that no mode is required by the specified flags.
2024-06-25 19:10:13 +02:00