Commit graph

4283 commits

Author SHA1 Message Date
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
Robert Mader
bd5cc52c5c libcamera: add camera rotation property on nodes
Like the location, the orientation is a static property of libcamera
devices. While the rotation is already exposed as buffer transform,
knowing the property can be handy for applications in various ways.

See also: cd8ac5c1a ("libcamera: add camera location property on nodes")
2024-03-31 13:24:19 +02:00
Robert Mader
1a2fee260b v4l2: Drop the first frame after camera startup
A quite big number of UVC cameras - due to firmware or kernel driver
issues - have bad timestamps of the first frame, confusing clients
like pipewiresrc.
Drop the first frame, as this seems to be the most reliable workaround
for the time being.

Closes https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/3910
2024-03-30 14:14:44 +01:00
Wim Taymans
af310523db spa: improve null-audio-sink channels
We can just update the channels in the props, we don't need an extra
property that can go out of sync with the channels.

See #3931
2024-03-28 17:11:16 +01:00
Wim Taymans
66b8cd3e32 json: fix SPA_JSON_STATE
It should copy the state as well or else parsing will fail.
2024-03-28 09:14:18 +01:00
Pauli Virtanen
27ccf32030 spa: fix spelling 2024-03-27 18:42:31 +02:00
Pauli Virtanen
3e99a0e839 spa: deal with non-null terminated strings in spa_error_location
Add len field to indicate number of valid characters after location.
2024-03-27 18:36:06 +02:00
Wim Taymans
a0af514581 context: make error line debug a little better
Make a line to the ^ so that it is more visible. Spell out column
completely. Make the sizes a little smaller to avoid awkward gaps.
2024-03-27 16:23:38 +01:00
Wim Taymans
a9fdc6a408 spa: improve JSON error reporting in spa-json-dump 2024-03-27 15:57:39 +01:00
Pauli Virtanen
04c5d3958b test: add tests validating all json conf files 2024-03-27 15:53:09 +01:00
Wim Taymans
d4581755e6 spa: Improve JSON error reporting
Add struct spa_error_location that holds information about some parsing
context such as the line and column number, error and line fragment
with the error.

Make spa_json_get_error() fill in the spa_error_location instead. Add
some error codes to the error state and use this to add a parsing reason
to the location.

Add a debug function to log the error location in a nice way. Also
add a FILE based debug context to log to any FILE.

Replace pw_properties_check_string() with
pw_properties_update_string_checked() and add
pw_properties_new_string_checked(). The check string behaviour can still
be done by setting props to NULL but the main purpose is to be able to
avoid parsing the json file twice in the future.

When using the old pw_properties_update_string(), log a warning to the
log when we fail to parse the complete string.

Use the new checked functions and the debug functions to report about
parsing errors in the tools and conf parsing.

This gives errors like:

```
> pw-loopback --playback-props '{ foo =  [ f : g ] }'
error: syntax error in --playback-props: Invalid array separator
line:      1 | { foo =  [ f : g ] }
col:      14 |              ^
```
2024-03-27 15:42:29 +01:00