Commit graph

12535 commits

Author SHA1 Message Date
Wim Taymans 8459f6d25c data-loop: add functions to get name and class
This can be used to force nodes in the same class or data-loop.
2024-04-22 11:00:22 +02:00
Wim Taymans 4f352ca46b context: fill basic properties early
So that we can use them in match rules, such as the application.name
etc.
2024-04-22 10:48:23 +02:00
Wim Taymans 8dce124720 impl-port: only go through mixer for IO
Since we don't follow updates of the params on the mixer but only on the
port, we might get out of sync and fail to negotiate.

Going through the mixers for everything needs some more work.

Fixes #3971
2024-04-22 10:01:39 +02:00
Pauli Virtanen ac95f796bf combine-stream: fix latency-compensate with resample.disabled=true
When resample.disabled=true, which is now the default, Format has zero
rate, so latency buffers get zero size. The rate in this case is the
graph rate.

Fix by just using the delay in samples, as all streams must in any case
run at same rate for the combining to work.

Fixes: bff252ce60 ("combine-stream: actually make use of resample.disable")
2024-04-19 18:39:52 +03:00
Wim Taymans 04bda2c28c spa: proxy tag and latency to peer of the mixer
We can probably do this better later but right now we do all of the tag
and latency handling bypassing the mixers.

Fixes #3970
2024-04-19 15:32:08 +02:00
Wim Taymans a4bfdd7f82 context: add support for multiple data loops
Add config options to create and start multiple data loops, each with
their own priority and thread affinity if requested.

Make it possible to assign loop.classes to the data-loops. Use the
node.loop.class to find a data-loop for the node of the same class. Try
to evenly spread the nodes over the available matching loops.

With this, it is possible to separate the processing of the nodes
depending on the classes, like audio/video and improve concurency on
the server.

No attempt is done yet to move nodes between loops or to move
independent nodes to separate data loops.

Fixes #3969
2024-04-19 14:57:53 +02:00
Wim Taymans e85bb7194b profiler: remove unused data-loop 2024-04-19 12:16:39 +02:00
Wim Taymans a97a9b737c data-loop: support custom name and affinity 2024-04-18 17:46:22 +02:00
Wim Taymans 2d87310b60 thread: add support for thread affinity 2024-04-18 17:45:35 +02:00
Wim Taymans 696cd8977a context: remove redundant variable 2024-04-18 16:00:25 +02:00
Wim Taymans e1e0a886d5 stream: improve async handling
We can remove most of the special async handling in adapter, filter and
stream because this is now handled in the core.

Add a node.data-loop property to assign the node to a named data-loop.

Assign the non-rt stream and filter to the main loop. This means that
the node fd will be added to the main-loop and will be woken up directly
without having to wake up the RT thread and invoke the process callback
in the main-loop first. Because non-RT implies async, we can do all of
this like we do our rt processing because the output will only be used
in the next cycle.
2024-04-18 15:20:07 +02:00
Wim Taymans 34be6c76a6 v4l2: fix printf format 2024-04-18 12:48:09 +02:00
Ashok Sidipotu 9062182985 spa: v4l2: encode device id into a json array 2024-04-18 14:02:55 +05:30
Ashok Sidipotu 4d3d15aebe spa: libcamera: encode device ids into a json array 2024-04-18 14:02:54 +05:30
Wim Taymans 68916e062b impl-node: implement async scheduling
When node.async is set, make the node async.

Advertize SPA_IO_AsyncBuffers on mixer ports when supported. Set a new
port flag when AsyncBuffer is supported on the port.

When making a link and if one of the nodes is async and the linked ports
support AsyncBuffer, make the link async and set this as a property on
the link. For async nodes we will use SPA_IO_AsyncBuffers on the mixer
ports.

Nodes that are async will not increment the peer required counters. This
ensures that the peer can start immediately before the async node is
ready.

On an async link, writers will write to the (cycle+1 & 1) async buffers
entry and readers will read from (cycle & 1). This makes the readers read
from the previously filled area.

We need to have two very controlled areas with specific rules for who
reads and who writes where because the two nodes will run concurrently
and no special synchronization is possible otherwise.

These async nodes can be paused and blocked without blocking or xrunning
the rest of graph. If the node didn't produce anything when the next
cycle starts, the graph will run with silence.

See #3509
2024-04-18 10:31:29 +02:00
Wim Taymans e8ac4e6a34 spa: add SPA_IO_AsyncBuffers
This structure has 2 io_buffers. Readers and writers operate on different
io_buffers to implement an asynchronous transfer.
2024-04-17 16:18:04 +02:00
Wim Taymans 84ed9c0fe9 impl-port: query all params through the mixer
Go through the mixers of the port to get the params.

This makes it possible to let the mixer decide on formats, buffers and
io areas.

Currently, the format is the same on all mixer input and output ports
and the buffers are shared on the output port but the idea is to make it
possible to have different formats and buffers per link.
2024-04-17 16:18:04 +02:00
Wim Taymans abb28e5255 impl-link: log error when activate fails 2024-04-17 16:18:04 +02:00
Wim Taymans 271f2d855d impl-port: implement port_enum_param on mixers
Implement the IO areas the default mixers support and proxy all other
queries to the peer port with the new node event.
2024-04-17 16:18:04 +02:00
Wim Taymans 67aafec8ab node: add an event to enumerate the peer port params
This can be used by nodes to filter or proxy the peer params.

Add test for new peer_enum_params event
2024-04-17 16:17:50 +02:00
Wim Taymans af6638251d impl-port: set position io on the mixer nodes
When adding the node, set the current node position IO. We don't need to
set the IO_Buffers because we did that when we set the mixer on the port.
2024-04-17 13:17:51 +02:00
Wim Taymans 77ed5ccb31 spa: give meaning to port_enum_params with SPA_ID_INVALID port_id
This is to iterate params that are common to all ports, such as
EnumFormat or the supported IO areas. Mostly interesting for mixer and
splitter nodes so that we don't have to create a new port just to query
things.
2024-04-17 12:49:13 +02:00
Wim Taymans bf273690fd impl-node: add cycle to debug
Emit rt_start after incrementing the cycle so that it can use the new
cycle value.
2024-04-17 11:24:56 +02:00
Wim Taymans ec13e9148b impl-port: avoid doing work when the port is destroyed 2024-04-17 11:18:15 +02:00
Wim Taymans f8831f84d5 impl-port: refactor check_params
Make a new function to iterate the port params and update the flags etc.
Make sure we clear the cache first and reset the flags. This makes it
possible to call check_params later again.
2024-04-17 11:12:22 +02:00
Wim Taymans 4d01fa34fa impl-port: use 0 size when clearing IO 2024-04-17 11:07:03 +02:00
Wim Taymans 40b8ff187b stream: log a warning when media.class and direction mismatch
Fixes #2493
2024-04-17 09:53:54 +02:00
Jonas Holmberg 09088b376f rtp_stream: Use the log topic of the module
Set log topic to the topic of the module linked with stream instead of
logging with "default" topic.
2024-04-17 07:13:53 +00:00
Wim Taymans 24478b9128 module-loopback: only enable delay with valid rate and channels
Or else we can't calculate the required delay buffer size and we might
even end up with a double free.

Fixes #3748
2024-04-16 11:16:00 +02:00
Wim Taymans 0e45836c36 properties: only count valid property updates
Log warnings when some property update failed. Only add valid property
updates to the total update count.
2024-04-16 11:05:39 +02:00
Jonas Holmberg 64d75b6b2e module-rtp-sink: Send all remaining packets when stopping
Don't close rtp_fd until all packets have been sent by the timer, if
the timer is running when the stream is stopped.
2024-04-16 07:50:33 +00:00
Barnabás Pőcze 4cea8eb01f pulse-server: use memcpy() to write string into message
The length of the string is already known, so use `memcpy()`
instead of `strcpy()` to copy the string into the message buffer.
2024-04-16 07:37:12 +00:00
Barnabás Pőcze 150211a3f8 pulse-server: message_dump(): fix format_info memory leak 2024-04-16 07:37:12 +00:00
Barnabás Pőcze 3fa92bbd15 pulse-server: ignore unsaveable values when deserializing property list
PulseAudio's property list can store arbitrary data, but
pw_properties can only store null-terminated strings.
So for the time being, ignore those values that don't
have null-terminators or have zero bytes inside.
2024-04-16 07:37:12 +00:00
Barnabás Pőcze 12bddf6521 pulse-server: stricter length checking when deserializing property list
The length of the value for each value in a property list is serialized
twice. Both the reference implementation and pipewire-pulse send
the same length, so be stricter and only accept a property list
if both lengths are the same.
2024-04-16 07:37:12 +00: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 232f4f01e4 protocol-native: fail when security context init fails 2024-04-15 16:43:46 +02:00
Wim Taymans 6499b8572e tests: don't crash when security context is not available
Fixes #3952
2024-04-15 16:41:03 +02:00
Wim Taymans b97c6e2eac audioconvert: also clamp monitor volume to min/max
When we set a min/max value, also clamp the monitor volume to it.

Fixes #3962
2024-04-15 16:28:24 +02:00
Wim Taymans 2379e83283 pipewire: document and improve -v option
Take the log level after we init pipewire to get the default level. Then
let the -v option increase it.

Fixes #3963
2024-04-15 15:39:50 +02:00
Wim Taymans b9fad5b89c doc: add -P option to docs 2024-04-15 15:39:13 +02:00
Pauli Virtanen bff252ce60 combine-stream: actually make use of resample.disable
resample.disable was made to default to true, but copying it to stream
properties was forgotten so it didn't have any effect. Make sure to copy
it.

This will also prevent different input/output streams from negotiating
to different rates, which would result to broken audio since we are just
passing sample data through.
2024-04-14 18:58:45 +03:00
Pauli Virtanen e1849a0650 combine-stream: check module arguments for syntax errors
Refuse to create module if the arguments were not properly parsed.
2024-04-14 16:24:16 +03:00
Pauli Virtanen cd166ac899 bluez5: don't use spa_invoke from data loop to main loop
spa_loop_invoke from data loop to main loop is not OK, as Wireplumber
currently runs its main loop with "pw_loop_enter(); pw_loop_iterate();
pw_loop_leave();" which causes the loop to be entered only when it is
processing an event.

In this case, part of the time the loop impl->thread==0, and calling
spa_loop_invoke() at such time causes the callback to be run from the
current thread, ie. in this case data loop which must not happen here.

Fix this by using eventfd instead, which is safe as the callback always
runs from the main loop.

Eventfd is also slightly more natural here, as multiple events will
group to the same mainloop cycle.
2024-04-13 15:54:22 +03:00
Wim Taymans 37a8dd5cb3 bluez: initialize variable to avoid warning 2024-04-12 18:14:54 +02:00
Pauli Virtanen a6dcdfae0c bluez5: iso-io: track and apply corrections to tx latency
Use TX timestamps to get accurate reading of queue length and latency on
kernel + controller side.

This is new kernel BT feature, so requires kernel with the necessary
patches, available currently only in bluetooth-next/master branch.
Enabling Poll Errqueue kernel experimental Bluetooth feature is also
required for this.

Use the latency information to mitigate controller issues where ISO
streams are desynchronized due to tx problems or spontaneously when some
packets that should have been sent are left sitting in the queue, and
transmission is off by a multiple of the ISO interval.  This state is
visible in the latency information, so if we see streams in a group have
persistently different latencies, drop packets to resynchronize them.

Also make corrections if the kernel/controller queues get too long, so
that we don't have too big latency there.

Since BlueZ watches the same socket for errors, and TX timestamps arrive
via the socket error queue, we need to set BT_POLL_ERRQUEUE in addition
to SO_TIMESTAMPING so that BlueZ doesn't think TX timestamps are errors.

Link: https://github.com/bluez/bluez/issues/515
Link: https://lore.kernel.org/linux-bluetooth/cover.1710440392.git.pav@iki.fi/
Link: https://lore.kernel.org/linux-bluetooth/f57e065bb571d633f811610d273711c7047af335.1712499936.git.pav@iki.fi/
2024-04-12 18:50:15 +03:00
Pauli Virtanen 9165291c43 bluez5: iso-io: drop RX data when source is not running
When media-source is not running, we need to drop any RX data so that
there is room in the socket buffer for the latency reporting.
2024-04-12 18:31:26 +03:00
Pauli Virtanen 4f91f0bcb0 bluez5: move spa_bt_ptp to rate-control.h 2024-04-12 18:31:26 +03:00
Pauli Virtanen cfb29af672 bluez5: bap: use priority from conf table in PAC selection 2024-04-12 18:31:26 +03:00
Wim Taymans 66ba147bfc filter: fix -UFASTPATH compilation 2024-04-10 18:28:18 +02:00