Commit graph

4293 commits

Author SHA1 Message Date
Barnabás Pőcze da1dbc1120 treewide: fix C++20 compilation error wrt. designated initializers
C++20 introduced designated initializers similar to the ones found
in C99, however, in C++ designated initializers cannot be mixed
with non-designated initializers. GCC rejects mixed initializers
with an error.
2024-05-03 07:16:57 +00:00
Barnabás Pőcze d80989ab56 treewide: fix errno assignments
Do not set `errno` to a negative value.
2024-05-01 09:28:17 +00:00
Wim Taymans 44f2ed7579 alsa: add sync.id in acp properties 2024-04-30 10:14:30 +02:00
Lukas Rusak 9e88aafa30 alsa-pcm: don't force quantum for iec958 formats
This fixes an issue introduced in 771f71f622
where the quantum is forced and may break applications the specify their
own quantum.

Signed-off-by: Lukas Rusak <lorusak@gmail.com>
2024-04-30 09:34:19 +02:00
Wim Taymans 8ff40e6252 loop: improve in_thread handling of invoke queue
Because we now have a dedicated queue per thread, we can simply add our
invoke item to the queue and then flush all the queues when we are
running in the thread of the loop.

This simplifies some things and removes potential out-of-order messages
that got queued while flushing.
2024-04-29 15:56:00 +02:00
Wim Taymans de0db48f17 loop: create a per-thread queue
Keep a thread local queue. This makes it possible for multiple threads
to write to the ringbuffer.

There is a lock to protect the list of queues. It can only be contended
when new queues are created in the threads but this can be done at
thread startup.

Fixes #3983
2024-04-29 15:17:45 +02:00
Wim Taymans c76424da36 loop: move invoke queue to separate object
Make an internal queue object that implements the invoke queue.

Because we can not do invokes concurrently from different threads, this
is required to make per-thread invoke queues later.
2024-04-29 12:10:48 +02:00
Pauli Virtanen ac35ecf329 journal: prepend code location to messages at debug log levels
Debug and trace log messages are often written based on the stderr
logging, where code location is always visible.

journalctl does not show the code location without extra tricks,
which makes user-submitted debug logs from journal more cryptic.

Make journal log more similar to stderr logs by prepending the code
location and log level in the log message when the log topic
level is >= DEBUG.
2024-04-28 16:02:28 +03:00
Wim Taymans 9bb5780cc2 meta: add explicit sync metadata and data type
Change the GenericFd data type to SyncObj. It's probably better to
explicitly state the data type than to make something generic. Otherwise
we would need to transfer the specific fd type somewhere else and there
is no room for that in the buffer and the the metadata is not a good idea
either because it can be modified and corrupted at runtime.

Add the SyncTimeline metadata. This contains 2 points on two timelines
(SyncObj datas in the buffer). The buffer can be accessed when the
acquire_point is signaled on the timeline and when the buffer
can be released, the release_point on the timeline should be signaled.
2024-04-25 09:55:19 +02:00
Barnabás Pőcze 6a26e6dd3f treewide: fix some format string issues
Use the proper specifier, and cast to a known type where the type
is not guaranteed by any standard.

See #3975
2024-04-25 07:24:10 +00: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 2d87310b60 thread: add support for thread affinity 2024-04-18 17:45:35 +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 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 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 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
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 61af61a4b3 v4l2: handle empty properties gracefully
When a property is not found or is empty, go on to the next format
instead of failing.

See #3959
2024-04-10 11:06:44 +02:00
columbarius c223e02d9b vulkan: Complete vulkan_pass
vulkan_pass now contains everything required for a single blit pass.
2024-04-09 09:05:03 +00:00
columbarius 11ff1471e9 vulkan: Cache buffer_type
All buffers should have the same type.
2024-04-09 09:05:03 +00:00
columbarius f935a191ad vulkan: Move vulkan_pass handling to filter
The current buffers are directly tracked by vulkan_pass.
2024-04-09 09:05:03 +00:00
columbarius 75daa140f3 vulkan: Split buffer import into CPU and GPU part 2024-04-09 09:05:03 +00:00
columbarius 3f47825082 vulkan: Introduce vulkan_pass for blit operations 2024-04-09 09:05:03 +00:00
columbarius 522546e8d3 vulkan: Sync buffers on in and export in blit 2024-04-09 09:05:03 +00:00
columbarius f10e8d2717 vulkan: Export functions to handle implicit_fd 2024-04-09 09:05:03 +00:00
Martin Geier 5c8799a480 alsa-pcm: set threshold to final value before set_swparams is called
This patch fixes use case, when disable_tsched is set and
api.alsa.period-size is set to value different from default quantum size.

In a such configuration, threshold needs to be set to a final value
before snd_pcm_sw_params_set_avail_min is called to get IRQs with
right timing.

Avail minimum is calculated from a threshold set in the check_position_config.
The method returned different value for threshold right before playback
started and after the playback started. Therefore threshold used in
the snd_pcm_sw_params_set_avail_min was incorrect.

Force the check_position_config to use configured values when called
from spa_alsa_prepare as this method is called when starting new playback
and the state->period_frames and the state->rate are already known.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2024-04-09 09:03:49 +00:00
Martin Geier 4c11a2aa9a alsa-pcm: start playback immediately if there is start delay set
Without this change, playback_ready or capture_ready was called
immediately after spa_alsa_start even tho start-delay was set.
Ready function was called with not precise "nsec" value, as "nsec"
plus latency should return time when the next buffer should be played
which wasn't true as start-delay was not included.

Now the playback is started immediately when the start_delay is set.
The alsa_do_wakeup_work is still called immediately but two things can
happened. Either start-delay is smaller then max_error and *_ready
function is called immediately, or start-delay is bigger then max_error
and state->next_time will be updated to correct value.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2024-04-09 09:03:49 +00:00
Martin Geier 1e6dad14d3 alsa-pcm: use headroom to calculate minimum available frames for non time scheduling
Alsa needs to call handler soon enough to have headroom plus threshold
frames in the buffer and not only threshold left.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2024-04-09 09:03:49 +00:00
Martin Geier b4ed8dcf14 alsa-pcm: do not allow headroom plus threshold be bigger then the alsa buffer
Headroom are extra samples available in alsa buffer on top of a threshold.
Its use to prefill alsa buffer with silence before the playback starts
and later its use to calculate target number of a frames in the alsa buffer
when get_status is called. Target is calculated as headroom plus
threshold, which should be smaller then buffer size to make sense.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
2024-04-09 09:03:49 +00:00
Carlos Rafael Giani 695f236f5f alsa-compress-offload-device: notify observers when profile changes
Signed-off-by: Carlos Rafael Giani <crg7475@mailbox.org>
2024-04-09 09:03:49 +00:00
Martin Geier d6184bd9bb alsa-pcm-device: notify observers when profile changes
Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2024-04-09 09:03:49 +00:00
columbarius 7206980023 vulkan: Sync renderer for blit filters
A spa_node has callback both on the main and data thread, which can
modify the internal state of vulkan_blit_state. Especially critical are
functions, which might drop buffers currently in use. To mitigate this
a read-write lock is used. The data thread shall try to aquire a read
lock before accessing the buffers, while the main thread has to aquire
exclusive access via a write lock before modifying the buffers.
2024-04-08 20:24:30 +00:00
columbarius 2010fa1349 vulkan: Name params 2024-04-08 20:24:30 +00:00
Arun Raghavan e4da3b95f5 alsa-pcm: Fix copy-pasto while listing ctls
Can cause a crash on startup under some circumstances.
2024-04-06 07:25:39 +00:00
Wim Taymans 0633be3c12 node: add a cycle counter to the position
So that we can count the number of times the graph is scheduled.
2024-04-04 20:47:43 +02:00
Wim Taymans 986de92521 buffers: add support for mandatory metadata
Add a SPA_PARAM_BUFFERS_metaType in the Buffers object. This contains a
bitmask of the mandatory metadata items that should be included on a
buffer when using this Buffers param.

Make the buffer allocation logic skip over the Buffers params that
require unavailable metadata.

This can be used to, for example, enforce specific metadata to describe
extra buffer memory (such as the meaning of generic file descriptors).

One such use is the explicit sync, where an extra buffer data is needed
for the sync fd along with metadata that contains the sync_point.
2024-04-02 12:28:21 +02:00
Wim Taymans f3fe20bdde buffer: add GenericFd memory type
Add a Generic fd type. These could be eventfd or timerfd, the meaning
can depend on extra metadata.
2024-04-02 12:28:09 +02:00
Adam Gensler 63af3a4b5c Update 90-pipewire-alsa.rules with support for Astro Mixamp Pro TR. 2024-04-01 18:31:10 +00:00
Pauli Virtanen 5ae0dfb239 bluez5: bap: determine SDU interval from codec frame duration
BlueZ API as BAP Server gives us the ISO interval, instead of the SDU
interval, in the MediaTransport.QoS.Interval property.  They are not
necessarily the same. What we need is the SDU interval.

The SDU interval is the interval between packets the encoder outputs, so
it is determined by the codec configuration, and for LC3 is equal to the
frame duration.

Add codec method get_interval() that returns the correct interval, and
use it in iso-io.
2024-04-01 19:13:01 +03:00
Pauli Virtanen b9ac79e99a bluez5: bap: no need to check for mtu, kernel fragments as needed
It's not necessary for ISO SDU to fit into the adapter MTU, as kernel
will fragment the packet as needed.

Remove MTU checks.
2024-04-01 15:23:32 +03:00