Commit graph

4048 commits

Author SHA1 Message Date
Wim Taymans
863b3be343 audioconvert: add monitor.passthrough option
Add a monitor.passthrough option. This will pass all latency information
directly between the port and its monitor ports.

This is interesting when the adapter (and audioconvert) is used with a
null-audio-sink that simply forwards the data to a real sink/souce. In
that case, we want the sink/source latency to be passed unmodified.

Set the monitor.passthrough on the pulseaudio null-sink because
a passthrough virtual sink is the most likely use case for this.

Add some monitor.passthrough default config where it makes sense.

Fixes #3888
2024-03-12 17:39:33 +01:00
David Turner
e5c810c0fa Add SOC-style jack names to HDMI audio paths
Currently the HDMI output paths have jack mixers named "HDMI/DP" and
with append-pcm-to-name=true.  However, most of the SOC audio drivers
are just named "HDMI" and don't add the ",pcm=N".  Add these alternate
jack names to the HDMI audio path files so that jack detection will work
on these SOCs.
2024-03-01 13:55:34 +01:00
Wim Taymans
b41e2391bd audioconvert: handle invalid ports better
Keep track of the valid ports and don't emit port info for
invalid ports. When a listener is added while the ports are being
created, it is possible that the ports are still NULL or invalid.
2024-03-01 13:54:29 +01:00
Wim Taymans
8942b74c18 audioconvert: handle port remove
The info is NULL when the port is removed, don't crash on that.
2024-03-01 13:53:56 +01:00
Dimitrios Katsaros
67e0ebc336 alsa: Added handle for controlling htimestamp autodisable
You can now do this to permanently enable htimestamp:

pw-cli s 38 Props '{ params: [ api.alsa.htimestamp.max-errors: 0, api.alsa.htimestamp: true ]}'
2024-03-01 13:51:49 +01:00
Jonas Holmberg
c51ced42b4 pipewire-alsa: Propagate errors from eventfd().
Propagate the error if spa_system_eventfd_create() fails. Also copy
errno before calling spa_log_debug() in spa_system_eventfd_create() to
make sure it is not overwritten.
2024-03-01 13:50:31 +01:00
Ruben Gonzalez
876c3f43ab logger: minor performance improvement to avoid syscall done by isatty 2024-02-19 09:01:34 +01:00
Dimitrios Katsaros
1f578e858c resampler: Only use copy when rate is 1.0
The rate we get from dlls can have a subsample precision. However,
the check for using process_copy is in sample precision. This means
that an adaptive stream will oscillate rather then lock into the
exact rate.
2024-02-19 09:01:30 +01:00
Dimitrios Katsaros
e25f7716b5 resample: use a float phase in update_rate
My making the phase into a float, the resampler can do finer grained
adjustments, which should improve the stability of adaptive
resampling
2024-02-19 09:01:22 +01:00
Wim Taymans
119636cb3f alsa: split irq and timer wakeup functions
Because it's easy to do and avoids some runtime checks.
2024-02-16 10:00:35 +01:00
Dimitrios Katsaros
32f507d687 alsa: Reduce jitter in irq based software timestamping
We would timestamp within an unlikely block, which would introduce
additional jitter to current_time, which would have an impact on
the performance of the timer sensitive code.
2024-02-16 09:59:32 +01:00
Wim Taymans
151a2f0dea spa: use errno values in warnings
Propagate the errno values from syscalls and use them in the warning
messages to give info about what is going on.
2024-02-12 10:55:14 +01:00
Wim Taymans
acf9b67067 buffer: add MAPPABLE data flag
Add a MAPPABLE data flag that hints that the fd in the data is mappable
with a simple mmap/munmap. Normally, DmaBuf is not mappable like that
unless explicitly indicated with this flag.

Set the MAPPABLE flag on the DmaBuf from v4l2 and libcamera fd.

When asked, mmap the buffer memory in all cases when the MAPPABLE
flag is set.

This solves the case where v4l2 has exported DmaBuf and is streaming to
node A and then node B links but doesn't get automatically mmaped
memory.

Fixes #3840
2024-02-12 10:49:56 +01:00
Wim Taymans
b147753554 alsa: always reevaluate matching when driver changed
Always reevaluate the rate matching even when we did not change the
follower state.

It is possible that we were a follower from some node with the same
clock and now become a follower of a node with a different clock. The
follower state doesn't change but we need to activate the rate matching
logic in that case.

Fixes rate matching in pro audio (playback) when capture and playback
are moved to another driver.
2024-02-02 14:06:45 +01:00
Arun Raghavan
1f40695b69 node-driver: Log when we resync 2024-01-30 18:43:08 +01:00
Wim Taymans
c690aedc89 v4l2: probe EXPBUF and disable alloc_buffer flag
After we set the format, probe if we can do EXPBUF and enable/disable
the ALLOC_BUFFERS flag on the port.

This should gracefully handle the case where EXPBUF is not available.

Fixes #3821
2024-01-30 18:42:58 +01:00
Wim Taymans
18b112bcfe v4l2: clear support for alloc_buffers on failure
When we try to alloc buffers but EXPBUF is not supported, make sure to
clear the alloc_buffers flag so that the caller can try again with
allocated buffers instead.

See #3821
2024-01-30 18:42:53 +01:00
Dmitry Sharshakov
73cda0c152 node-driver: allow fractional resync-ms 2024-01-25 12:07:11 +01:00
Wim Taymans
c28311fc97 support: add resync.ms option to node.driver
Move some of the tracking code for the DLL to where it is used.

Add resync.ms (default 10) option at which we give up rate adjusting
and instead do a hard resync. This results in a jump in the position
of the graph clock.
2024-01-25 12:06:50 +01:00
Wim Taymans
6ee48f0562 alsa: increase buffers when using small buffer
We can increase the MAX_LATENCY again if we increase the amount of
buffers when we are using a small buffer.

Normally we ask for 4 * quantum-limit as the buffer. This should be good
to use 1 buffer and quantum-limit as the quantum with enough headroom
to not run out of buffers.

If we are however using less buffer-frames we need to be careful and
allocate an extra buffer. Imagine using a buffer of 4096 frames, we can
support a quantum of up to 2048 frames if we use 2 buffers.

See #3744
2024-01-22 16:05:52 +01:00
Wim Taymans
7e1e05f0da alsa: improve max-latency property
Half of the buffersize is not enough to support as a max-quantum, we
need to divide by (4 * frame_scale) to allow some headroom and account
for the DSD scaling. We do the same calculation to suggest a buffer size
using the quantum-limit.

See #3744
2024-01-22 16:04:38 +01:00
Wim Taymans
7775363d8e v4l2: improve filter with missing format
When the filter has no format property, just enumerate all possible
framerates. Handle error case where the filter has the wrong type.

Makes gst-launch gstpipewiresrc ! video/x-raw ! fakesink work.

See #1793
2024-01-22 16:00:37 +01:00
Wim Taymans
ef0674751f v4l2: fix format enum with unsupported framerate
Actually count the number of frame fractions we add. If we added 0, we
don't have any supported framerate that intersects with the filter and we
try the next frame size.

See #1793
2024-01-22 16:00:30 +01:00
Pauli Virtanen
0feb68fc07 bluez5: lc3: fix wrong enum_config
The rate is not a bitmask.
2024-01-22 16:00:05 +01:00
Wim Taymans
9a9be2c2ed audioconvert: remove unnecessary casts 2024-01-22 15:54:19 +01:00
Dmitry Sharshakov
524edba9dd audioconvert: fix rare unaligned load exceptions
Supposed causes described in the issue. Also improve float semantics.

Fixes #3790
2024-01-22 15:54:07 +01:00
Pauli Virtanen
bae75e0d0b bluez5: add quirk for SoundCore mini2
AVRCP volume doesn't work properly with this device.

Closes #2927
2024-01-22 15:53:52 +01:00
Pauli Virtanen
46eb11051a bluez5: more informative warning with unknown transports
Unknown transports visible in DBus usually belong to a different
sound server instance that is talking to BlueZ.

Explain this in the warning message that we log, so that people can more
easily understand why things are not working.
2024-01-22 15:53:44 +01:00
Pauli Virtanen
c0716675e8 bluez5: add quirk for Rockbox Brick 2024-01-22 15:53:25 +01:00
Wim Taymans
469b7b0148 spa: small cleanups
Initialize result variable.
Use strncpy to avoid warnings about using non-NULL terminaded strings.
2024-01-12 12:14:06 +01:00
Barnabás Pőcze
01cb3fa862 spa: libcamera: bump minimum supported version to 0.2.0 2024-01-11 13:09:40 +01:00
Barnabás Pőcze
fd33d2d3bb spa: libcamera: use CameraConfiguration::orientation
libcamera commit cc65629b68d49d ("libcamera: camera: Introduce Orientation") [0]
introduced to the `CameraConfiguration::orientation` member to describe the
orientation of the image in the received memory buffers.

Then c65e40b8480ffb ("libcamera: Use CameraConfiguration::orientation") [1]
removed `CameraConfiguration::transform`, which broke the libcamera plugin.

Fix that by using the new `orientation` member.

[0]: https://git.linuxtv.org/libcamera.git/commit/?id=cc65629b68d49d5f2a4d61537584c56ba510a335
[1]: https://git.linuxtv.org/libcamera.git/commit/?id=c65e40b8480ffb5f50e01a4e6713164c7194a937
2024-01-11 13:09:32 +01:00
Wim Taymans
1733cc7fea support: fix freewheel timeout in node-driver
When freewheeling we will immediately schedule a new graph cycle when we
get a process call because the graph completed.

When the process call is not done, because of some xrun or
because some node was removed that causes the graph to fail completion,
The next cycle will happen after a timeout.

This timeout was calculated as the ideal wakeup time (after a quantum of
time) and would accumulate for each timeout. The result is that the
timeout ended up far in the future and would stall the freewheel driver
for a long time.

Fix this by always setting the next timeout to wakeup time + freewheel.timeout
seconds. Also add a config property for the timeout (10 seconds, like
jack2 by default).
2024-01-10 13:25:41 +01:00
Wim Taymans
5a596edd53 spa: small cleanups
Use snprint to ensure null terminated strings.
Initialize res, it would be uninitialized when setting a NULL Latency
param.
2024-01-10 13:25:35 +01:00
Wim Taymans
2b7fa2ff5a spa: remove some references to unimplemented items
Fixes #3763
2024-01-09 09:20:16 +01:00
Mauro Carvalho Chehab
4dfd8b4497 bluez5: update bluez-hardware.conf to ignore sbc-mq on Primark earbud
Primark True Wireless earbud doesn't support sbc-xq. Having it
enabled causes bluez to enter into a loop enabling/disabling
the device dozens of times per minute, making it unusable.
2024-01-09 09:10:53 +01:00
Dimitrios Katsaros
4331779e4d ALSA: Remove alsa timer from IRQ scheduling
As part of the setup for IRQ based scheduling, a period event
was installed. Not only is a timer based polling unecessary for
IRQ scheduling, depending on the state of the system, the timer
could fire far enough from the IRQ, causing alsa wakeup events
with no data in the ring buffer. Pipewire would identify these
events as an "early wakeup", adding an extra quantum of time
to the next_time estimate, skewing the clock and causing issues
with apps that depend on precise timing.
2023-12-14 13:12:38 +01:00
Wim Taymans
c07bef13be audioadapter: improve state check
Update the started and ready state after we suspend/pause the node so
that we don't complain if scheduling happens between setting the fields
and actually stopping the follower.

Also only complain when the scheduling happens when the node is not
ready. It is possible that the node is scheduled before we manage to set
the started field.
2023-12-14 13:12:23 +01:00
Wim Taymans
41e88b1267 audioconvert: avoid bitfield data races
Move the driver and warned bits after the int field in the struct so
that they are placed in separate memory.

Otherwise, a write from the data thread might race with a write from the
main thread and leave the bits in the wrong state.
2023-12-14 13:12:14 +01:00
Wim Taymans
0c1ee5f01d Revert "alsa: also use interpolated time as nsec in IRQ mode"
This reverts commit 49cdb468c2.

We should not do this, the nsec field should be relatable to the clock
monotonic time. If we use the estimated time, without actually using it
as a timer, we might end up with a wakeup time in the future compared to
the MONOTONIC clock time.

Instead, you can use the estimated current time simply by subtracting
the rate corrected duration from the next_nsec. This is really only
useful for some selected use cases (like in the JACK library).

This fixes some issues where in pro-audio mode, a client would try to
compare the current MONOTONIC time to nsec and find that it is in the
past.

This commit was done in an attempt to fix #3657 but it turned out the
real problem was something else.
2023-12-14 13:09:21 +01:00
Wim Taymans
22db59d8a3 alsa: fix rate matching in the sequencer
The alsa sequencer rate matching was not actually working correctly.
It would compare the previous queue time with the current time and
compare that to the quantum. This would include uncorrected errors from
jitter and would result in the timeouts being scaled in the wrong
direction forever.

Instead, calculate an ideal queue time and compare our current queue
time against that. We then use the correction to scale the timeout or
the next queue time prediction.

Also use the predicted time as the base time for the event timestamps.
this results in less jitter.

Fixes #3657
2023-12-05 15:37:02 +01:00
Wim Taymans
4e6b629ae2 alsa: reset dll when we reprogram the timers 2023-12-05 15:36:58 +01:00
George Kiagiadakis
bb29deb45a acp: avoid copying structure into itself
sync_mixer() calls d->set_volume(d, &d->real_volume);
which makes v and &dev->real_volume point to the same memory area
and valgrind complains:

Source and destination overlap in memcpy(0xcc53e2c, 0xcc53e2c, 260)
   at 0x488CFA0: __GI_memcpy (vg_replace_strmem.c:1121)
   by 0xBB0803F: set_volume (acp.c:1143)
   by 0xBB0EDCB: acp_device_set_port (acp.c:1897)
   by 0xBA9CD87: impl_set_param (alsa-acp-device.c:757)

because the compiler apparently implicitly converts this into a memcpy()
and memcpy(3) explicitly says "The memory areas must not overlap."
2023-12-04 11:19:08 +01:00
Wim Taymans
92928344c2 alsa: clamp buffer_frames correctly
Don't try to multiple the max_buffer_size with the frame scale or else
we might try to set a min_buffer_size larger than the max_buffer_size.

Instead, use the frame_scale only to scale the quantum_limit and then
clamp against the max_buffer size.

See #3000
2023-12-04 11:18:32 +01:00
Arun Raghavan
d49ceba2ac alsa: Correctly bail if pitch ctls are not available
The `goto error` got misplaced while refactoring this code for
bind-ctls.
2023-12-04 11:17:35 +01:00
Pauli Virtanen
4aa1deb929 meson.build: fix compile with -Dexamples=disabled 2023-12-04 11:16:11 +01:00
Wim Taymans
2af5a90c90 evl: add fds to pollfd from rt thread
When we don't have the thread id yet, don't add the pollfds yet
but wait until we do our first wait operation.

Use flags for eventfd. We can use this to communicate between all kinds
of threads with read/write.

Use evl_init() in the init function, don't attach the main loop, just
the thread that dos the first poll.
2023-11-24 11:58:28 +01:00
Pauli Virtanen
f14572648a bluez5: deal with too small Supported_Max_Codec_Frames_Per_SDU
Some devices appear to set Supported_Max_Codec_Frames_Per_SDU == 1 while
claiming they support two channels per stream, which is then not
possible.

In this case, limit the number of channels by the number of frames per
SDU when selecting.

Also adjust PAC sorting.
2023-11-23 17:47:55 +00:00
Pauli Virtanen
f327ed845f bluez5: add some debug to bap-codec-lc3
We don't want to dump on all calls to codec_select_config, so use debug
context.
2023-11-23 17:47:55 +00:00
Arun Raghavan
dec1102574 alsa: Move ctl sources to a main loop
It doesn't make sense to hang these on the data loop, so let's have
these on the main loop instead. Also avoids a potential crash while
removing them (since removal happens on the main loop and the data loop
might be polling while we're doing the remove).
2023-11-22 16:00:25 +00:00