Commit graph

3126 commits

Author SHA1 Message Date
Wim Taymans
d59e1094cd alsa: fix capture timings and drift
Don't reschedule a timeout when we have less samples available than the
target but only reschedule when we have less that the required amount we
need to read. This ensures that we hover around the target level and the
timeouts/rate matching adapts correctly. Previously we would only rate
match if the have at least the target amount of samples, which would
then always result in a possitive rate adjustment and cause drift.

For capture, make sure that there is at least 32 samples of headroom
when we are not using IRQ mode to handle jitter in the timer wakeup.

For capture of batch devices this results in (for a 1024 quantum) a
target buffer fill level of 1024 + 512, and we will read if there are at
least 1024 samples available.

For non-batch devices we aim for a target buffer fill level of 1024 + 32
and read if there are at least 1024 samples available.
2023-04-10 15:02:29 +02:00
Wim Taymans
501a80b247 alsa: fix rate match when using IRQ
When using the IRQ, we are woken up based on processed samples so
compare expected and current clock times to rate match the clock.

Fixes #3144
2023-04-10 13:18:25 +02:00
Pauli Virtanen
882f9ad2b3 bluez5: emit BAP device set nodes as needed
Emit BAP device set nodes, which the session manager can use to combine
the sinks/sources of a device set to a single sink/source.

Emit the actual sinks/sources with media.class=.../Internal to hide them
from pipewire-pulse.

Add separate device set routes to the set leader device.  Other routes
of the set members will be marked as unavailable when the set is active.

Accordingly, return failure for attempts to set these unavailable
routes, so that volumes etc. of the "internal" nodes are only controlled
via the device set route.
2023-04-10 07:00:44 +00:00
Pauli Virtanen
1a44754f8d bluez5: wait for devices in the same set before emitting nodes
Emit nodes only after all devices in the same set are ready, or until
add timeout elapses.
2023-04-10 07:00:44 +00:00
Pauli Virtanen
d642569394 bluez5: parse device set information via dbus
Parse device set information from DBus, and link devices to each other
according to it.  Add signal for notifying about device set changes.
2023-04-10 07:00:44 +00:00
Pauli Virtanen
eca13ec230 bluez5: iso-io: get BAP interval from dbus, not getsockopt
For ISO server sockets, the QOS struct from getsockopt contains values
with different meaning from ISO client socket. Get the values via DBus
instead, which is right in both cases.
2023-04-10 07:00:44 +00:00
Pauli Virtanen
ae76789f24 bluez5: iso-io: ensure streams are initially marked idle
Mark streams idle when they are being stopped/started, so that the
pause-to-sync logic always triggers when they are added.
2023-04-10 07:00:44 +00:00
Pauli Virtanen
6e94487057 bluez5: set BAP channel location from transport if unset
If BAP codec configuration is mono channel with unspecified location,
set the channel position from transport location.

This in principle should be set in SelectProperties, but currently BlueZ
doesn't tell us that yet there, so we hack it up later on.
2023-04-10 07:00:44 +00:00
Pauli Virtanen
8f840e703b bluez5: lc3: number of blocks is not the number of channels
The number of channels is determined by Audio_Channel_Allocation.
One frame block contains all channels. (BAP v1.0.1 Sec. 4.2)

Fix the handling of frame blocks and counting of numbers of channels. We
support and configure only one frame block per packet.

Consider omitted Audio_Channel_Allocation to indicate MONO stream (see
BAP v1.0.1 Sec 4.3.2).
2023-04-10 07:00:44 +00:00
Pauli Virtanen
e4cd99f76f bluez5: add some debug for media-sink 2023-04-10 07:00:44 +00:00
Forest
252620a18d alsa-profiles: SB Audigy: stereo mixer paths
This is a follow-up to d5390c7, where we switched to the 'PCM' mixer controls
on Sound Blaster Audigy devices, since the ones we used before only work in the
stereo-to-all-speakers mirroring mode.

It turns out we do use that mode after all, but only in a couple of profiles.
Since returning those profiles to the default mixer path yields uneven volume
steps similar to #2934, we instead add a new mixer path just for that mode.
2023-04-09 12:20:26 -07:00
Forest
1e77a7cc51 alsa-profiles: SB Audigy: rename path config file
This makes the file name consistent with the other device-specific ones.
2023-04-09 12:14:39 -07:00
Forest
6939c1e4ee alsa-profiles: SB Audigy: remove absent elements
Some of the elements/keys that were copied from analog-output.conf are not
implemented by the Audigy driver, so we don't need to reference them.
2023-04-09 12:14:29 -07:00
Pauli Virtanen
772ff3365b bluez5: backend-native: add two missing OK HFP replies
We should reply OK to both AT+BIEV and AT+IPHONEACCEV.
2023-04-08 11:05:06 +00:00
Forest
d5390c7199 alsa-profiles: use SB Audigy PCM mixer controls
Creative Labs Sound Blaster Audigy cards (snd_emu10k1 driver) expose
mixer controls named 'PCM Front', 'PCM Rear', etc. in addition to the
more common 'Front', 'Rear', etc.  The latter seem to be intended for
a stereo-to-all-speakers mirroring mode that we do not use, and have
no effect when we adjust them.
https://docs.kernel.org/sound/cards/audigy-mixer.html

We therefore define a custom mixer path for Audigy devices, using the
PCM mixer controls.

This has been tested on an Audigy 5/Rx.  Based on a brief look at the
ALSA driver, I think all Audigy devices (vendor 0x1102, device 0x0004
or 0x0008) have the same PCM controls, making this change probably safe
for our existing Audigy udev rules.

Relevant kernel files:
sound/pci/emu10k1/emu10k1_main.c
sound/pci/emu10k1/emufx.c
include/sound/emu10k1.h

Fixes #2934
2023-04-07 21:15:38 +00:00
Sourav Das
8cf9986774 spa:bluez5: fix compilation
on lower bluez version, BT_ISO_QOS macro is not available
    So, need to check it also fixes the compilation.
2023-04-06 09:19:47 +00:00
Wim Taymans
463e723a1e test: add more lossless tests
Also test that S16->F32->S32 and U16->F32->U32 are lossless.
2023-04-06 10:00:17 +02:00
Wim Taymans
edf2062830 fix compilation 2023-04-05 19:53:33 +02:00
Wim Taymans
6dcf0027d8 audioconvert: implement mix/resample_disabled
Fail when resampling or channelmixing is required but disabled.
2023-04-05 19:51:16 +02:00
Ashok Sidipotu
7dbad54ae5 audioconvert: donot return errors in the volume ramp setparams
Also avoid the divide by zero while generating sequence.
2023-04-05 16:27:48 +05:30
Wim Taymans
74831aa967 support: add support for checking loop context
Add check for running the the loop context and thread.

Add checks in filter and stream to avoid doing things when not run from
the context main-loop because this can crash things when doing IPC from
concurrent threads.
2023-04-04 16:19:41 +02:00
Wim Taymans
f2be2923e6 thread: use pthread_equal to compare thread ids 2023-04-04 12:43:25 +02:00
Wim Taymans
d41d8cf983 audioconvert: fix return values
Return negative error numbers for errors.
2023-04-03 21:34:10 +02:00
Ashok Sidipotu
dcec2e785e audioconvert: add a invalid value for scale
The invalid value here is zero, this will help avoid inadvertant parameter
updates and brings this on par with rest of the volume ramp parameters
2023-04-03 19:04:55 +00:00
Ashok Sidipotu
74872250e8 audioconvert: make volume ramp parameters non-sticky
This mean the volume ramp parameters will have to be issued along with volume
every time. They will not be persistant.
2023-04-03 19:04:55 +00:00
Ashok Sidipotu
737bc89ab9 audioconvert: grow the volume ramp buffer
Grow the volume ramp sequence command buffer dynamically, if needed.
2023-04-03 19:04:55 +00:00
Ashok Sidipotu
8bfafaeca2 audioconvert: add support of volume ramp scale parameter
- Add support for Linear and Cubic volume scales
- Also start treating a "zero" value of volume ramp parameters as invalid
2023-04-03 19:04:55 +00:00
Ashok Sidipotu
b0f6c4a8c0 audioconvert: add support for volume ramp time params 2023-04-03 19:04:55 +00:00
Ashok Sidipotu
40cf237eb3 audioconvert: add volume ramp parameters
Add volume ramp parameters and the add ramp up and down funtions which get
triggered on volume change.
2023-04-03 19:04:55 +00:00
Ashok Sidipotu
3b1ce6c268 audioconvert: parameterize channelmix_process_control() function
Decouple the function from control port and parameterize it, so that it can be
called any spa pod sequence.
2023-04-03 19:04:55 +00:00
Pauli Virtanen
6db234ad0c bluez5: media-sink: use iso-io for BAP
Use the ISO IO helpers to get synchronized BAP output, and rate match to
the ISO schedule.

The rate matching is necessary, since the driver may be ticking at a
corrected rate, different from the ISO interval rate.
2023-04-03 16:35:22 +00:00
Pauli Virtanen
cec050ac25 bluez5: add spa_bt_iso_io that does the low-level part for ISO
Add factored out helper for ISO socket I/O.

ISO sockets need synchronization of writes and audio position for
different stream fds in the same isochronous group, and it's easier to
separate out the part that coordinates it.
2023-04-03 16:35:22 +00:00
Pauli Virtanen
0ed124f0fb bluez5: add rate matching for BAP to media-sink
Add basics for rate matching.
2023-04-03 16:35:22 +00:00
Pauli Virtanen
41c155bb4c bluez5: split rate control out of decode-buffer 2023-04-03 16:35:22 +00:00
Pauli Virtanen
e0939ff8ab bluez5: don't set bluez timeout on transport release
Setting bluez timeout on transport release makes codec switches delayed,
and is not necessary.
2023-04-03 16:35:22 +00:00
Pauli Virtanen
c0d55eae86 bluez5: use release timeout for all transport types
Avoiding unnecessary release + reacquire when nodes restart makes sense
for all transport types.  Do timed releases for all transport types, not
only SCO.
2023-04-03 16:35:22 +00:00
Arun Raghavan
3dc08c09d1 volume: Fix inverted check for buffer validity 2023-03-31 08:19:07 +00:00
Wim Taymans
108715ebfb alsa: add tsched use to info log
Fixes !1580
2023-03-30 17:50:35 +02:00
Wim Taymans
b3940627dd audioconvert: pass the NODE_ASYNC flag correctly
Pass the follower async flag correctly in the adapter.
2023-03-30 15:03:29 +02:00
Wim Taymans
4fb17d1c03 audioadapter: clear rate matching when not using converter
Ensure that we clear the rate matching when we are not using the
converter. This will make the follower use the quantum instead of the
dummy unused rate matching area.

Exit when we can't make an internal converter because then things really
are not going to work. Remove some of the pointless NULL checks.
2023-03-30 15:03:29 +02:00
Wim Taymans
a163f29a43 improve logging 2023-03-30 15:03:21 +02:00
Wim Taymans
5ae73fccdd alsa: only update alsa sources when added to the data loop 2023-03-29 15:31:21 +02:00
Wim Taymans
b16b80601d alsa: start playback right away in IRQ mode 2023-03-29 15:13:00 +02:00
Wim Taymans
354836075d alsa: setup sources from the data thread
For IRQ based scheduling we might otherwise be woken up after we only
added one of the fds to the poll loop and then we get an error when we
try to update it afterwards. Instead, add the fds from the data thread
to get things nicely in sync.
2023-03-29 12:21:23 +02:00
Wim Taymans
8c264d2dcb alsa: in IRQ mode, disable sources while we wait
In IRQ mode, disable the ALSA fds while we wait for the graph to produce
data. Otherwise we will wake up very quickly over and over.

When we get more data, we activate the sources again to start the next
cycle.
2023-03-29 11:30:40 +02:00
Wim Taymans
dc5aa21c87 alsa-pcm: use full period size in IRQ mode
We can simply wake up every period and check the timers there is no need
to tweak the period size.
2023-03-29 11:29:43 +02:00
Wim Taymans
aa0d9c5b41 alsa: add disable-tsched to params 2023-03-28 18:27:53 +02:00
Arun Raghavan
26e37b6575 alsa: Implement period-based wakeups
Provides configuration to disable timer-based scheduling. This can be
useful at low latencies, for example, where period-based interrupts
might be more reliable than timers.
2023-03-28 16:22:53 +00:00
Wim Taymans
a0457a3bdf camera: work around target_ mishandling
A driver node should use the target_duration and target_rate to adjust
the quantum and rate when the graph starts.

The camera nodes don't currently support any of this and simply enforce
a specific rate and duration for the graph clock. Mark this with a
FIXME. Otherwise, pipewire will complain that the node is ignoring the
configured graph rate.

We should really look at the graph target rate/quantum and only produce
a buffer when it is inside the current graph cycle. This would make it
possible to join audio and camera nodes and have them be in sync.
2023-03-27 09:59:21 +02:00
Pauli Virtanen
b50ca80281 bluez5: do transport release synchronously
Do transport release synchronously for simplicity.  BlueZ handles
releasing while acquire is pending, but acquire while release is pending
would fail the acquire.

Otherwise we need to maintain an operation chain to handle trying to
acquire/release while the other operation is pending.  This makes things
complex with little gained, as releases generally don't block for a long
time.
2023-03-26 15:12:51 +03:00