Commit graph

2171 commits

Author SHA1 Message Date
Wim Taymans
56c03c11f8 alsa: resync when quantum changes 2022-02-16 21:30:35 +01:00
Wim Taymans
798228a906 alsa: remove useless code
The resync check can be done in check_position_config.
2022-02-16 21:29:55 +01:00
Wim Taymans
4246961070 alsa: use rewind to remove excess delay
When the delay is too big, rewind a little to reduce it when resync.
2022-02-16 21:10:03 +01:00
Wim Taymans
c5c9ecdd87 spa: improve the AEC interface
Place the methods on the interface so that we can call them.
Rename create to init because that is what it does.
Add support for listener and events so that we can signal property
changes later.
2022-02-16 16:18:18 +01:00
Joakim Olsson
9386c70b3a module-echo-cancel: Move backends to dynamic libaries
Move all backends to dynamic libaries loaded with spa_plugin_loader so
new backends not needs changes in pipewire or pipewire dependency to
external code

Change-Id: I702ce047598d0c318d6dc6ac8248062a5c12f643
2022-02-15 15:45:46 +00:00
Wim Taymans
761199be70 alsa: improve resync
Use the max error to do a resync. Don't reset the dll, there is no
reason for that.
Don't use _rewind, but instead limit the amount of samples we read and
write
Should keep more stable sync in most cases.
2022-02-15 16:32:00 +01:00
Wim Taymans
87f4726164 alsa: protect against impossible timeouts
Check if the new timeout is larger than 1sec in the past or future
and reprogram a timeout with a saner timeout.
2022-02-15 15:35:40 +01:00
Wim Taymans
8b899dbc55 alsa: make sure we always trigger a timeout
If we get an error from get_status() make sure program the timer
for one period or else we would just end up with silence.
2022-02-15 15:32:09 +01:00
Wim Taymans
dc76ab2291 alsa: don't use dll when not rate matching
Only use the DLL when we are driver or rate matching with
another driver.
2022-02-15 15:29:40 +01:00
Pauli Virtanen
bae2cc0a6e spa/alsa-udev: ignore all errors in card busy check
If card busy check fails due to error, just log info message and
consider the card not busy.

For kernels with CONFIG_SND_PROCFS=n, /proc/asound is not present, and
we have to handle that.  It's also better to fail open here, rather than
end up with missing devices.
2022-02-14 20:50:53 +02:00
Wim Taymans
0bca352241 alsa: fill with silence when underrun
Also try to resync when the follower buffer is running empty.
Fill the buffer with silence instead of doing _pcm_forward.
2022-02-12 12:09:25 +01:00
Wim Taymans
9855e2b303 alsa: tweak capture follower
If the follower does not have enough data to capture, skip a cycle
instead of trying to capture and get an XRUN.

Tweak some limits a little.
2022-02-11 18:07:44 +01:00
Barnabás Pőcze
2c71282f16 spa: bluez: remove unused function
The `add_dict` function has not been used since
9785d99821. Remove it.
2022-02-10 23:20:47 +01:00
Julian Bouzas
e34d9d209a alsa: try to resume after suspend before recovering
Fixes no audio after suspending with some audio drivers.

See #2001
2022-02-10 16:57:58 -05:00
Wim Taymans
f636603844 alsa: pass current_time around in get_status()
Pass the current time around in various functions.
Make a higher precission htimestamp based get_delay() function. Seems to
work fine for playback but not for capturee.
2022-02-10 15:31:29 +01:00
Luis Correia
3cba294b65 Update texas-instruments-pcm2902.conf, add info about Behringer U-Phoria UM2 2022-02-09 20:58:20 +00:00
Wim Taymans
14d252ec9d alsa: try to resync on commit error
When we get a commit error, try to resync our pointers. This fixes a
problem of endless commit errors after a quantum change because it never
manages to resync properly.
2022-02-08 18:31:42 +01:00
Barnabás Pőcze
bf886ba209 support: also protect against recursive invocations
Add an extra private field to the source to store the pollevent of
the current iteration. This changes ABI but it seems an embedded source
is not used outside of our own plugins and the unit test doesn't test
this ABI case.

Whenever a source is removed, we can set the data field of the
pollevent to NULL so that it won't be handled in any iteration anymore.

Avoid dispatching the same event multiple times when doing recursive
iterations.

Add some more unit tests for this.

Fixes #2114
2022-02-08 17:21:10 +01:00
Alexandre BIQUE
0b637c3291 support: loop_enter/leave hardening
This commit adds a counter for loop_enter/leave and checks:

 - consecutive enter are used on the same thread
 - leave is used on the same thread as enter
 - at destruction, the enter_count must be 0
2022-02-08 12:02:50 +01:00
Wim Taymans
c346ee5e90 support: close log file when we opened it 2022-02-08 11:30:39 +01:00
Wim Taymans
c474846c42 loop: remove destroy list
Now that sources can't be dispatched anymore after a _remove, we don't
need to keep the destroy_list anymore and we can free the source
immediately.

See #2114
2022-02-08 10:18:02 +01:00
Wim Taymans
45d911641b loop: handle remove while dispatching better
Keep the array of dispatched sources around in the loop. When a source
is removed while dispatching, set the data to NULL so that we don't try
to deref the source again or call its function.

Fixes #2114
2022-02-08 10:17:13 +01:00
Barnabás Pőcze
cc73053512 treewide: meson.build: use feature.allowed()
Since meson 0.59.0, a feature object has an `allowed()`
method which returns true when the feature is set to
'enabled' or 'auto'.

Utilize that instead of the previously used

  not feature.disabled()
2022-02-04 00:15:59 +01:00
Barnabás Pőcze
15e7a61aa7 treewide: only define feature macros when the feature is available
Most feature checks already use #ifdef, and do not care about
the value of the macro. Convert all feature checks to do that,
and simplify the meson build scripts by replacing

  if cond
    cdata.set('X', 1)
  endif

with

  cdata.set('X', cond)
2022-02-04 00:15:59 +01:00
Pauli Virtanen
97a5fe80c1 spa/alsa-udev: fix /proc/asound handling without CONFIG_SND_VERBOSE_PROCFS
For kernels compiled with CONFIG_SND_VERBOSE_PROCFS=n, the pcmXX
/proc/asound entries do not exist.  In that case, the "device busy"
check cannot be done, but we should still check existence of PCM devices
correctly.

Count the number of PCM devices from /dev/snd, which should work also
without /proc/asound or /sysfs/class/sound.
2022-02-03 18:28:25 +00:00
Wim Taymans
76417fd2a6 alsa: use MONOTONIC clock for tstamp 2022-02-03 16:22:09 +01:00
Wim Taymans
7480d09589 alsa: update test-timer
Remove the bandwidth reduce, we don't do that.
Clamp large errors.
Add htimestamp mode, which seems more stable.
2022-02-03 16:22:09 +01:00
Pauli Virtanen
b369401c8e spa/alsa-udev: retry busy devices on inotify close event, not timeout
Alsa device acp probe results to missing profiles if some PCM devices
are busy. Currently, we retry based on a timeout and give up after some
retries. However, exposing cards with missing profiles is never
useful.

Never expose cards if some PCM devices are busy. Instead, retry adding
device on inotify fd close events, which arrive when some process has
closed a PCM device.

When probing for devices in alsa-udev, check via /proc to avoid inotify
busy loop.
2022-02-02 16:43:54 +00:00
Pauli Virtanen
f32935ec8a bluez5: sco-sink: fix behavior as follower
When sink is follower, and no data to write is available, it should not
schedule a timeout, but wait for the driver to wake it up again.

Fixes process ending up busylooping in data thread as follower, under
some conditions.

Also, clean up the code to be more clear about timeout logic. Just loop
directly instead of setting timeout 1, if we need to just flush more
immediately.
2022-01-31 21:59:39 +02:00
Pauli Virtanen
4bb3ff739a bluez5: keepalive A2DP source / SCO AG dynamic node transports
When acting as SCO AG / A2DP sink, the remote end should decide when to
close the connection.  This does not work currently properly, because
stopping sources/sinks releases the transport, which causes it to go
idle, and which then destroys dynamic nodes.  The sources/sinks should
not cause the transport to be released.

Implement keepalive flag for spa_bt_transport, such that
spa_bt_transport_release does not actually release the transport when
the refcount reaches zero. Set the flag for dynamic nodes when the
transport becomes pending (remote end connects) and unset the flag when
idle (remote end disconnected, or dynamic node removed).
2022-01-31 21:59:39 +02:00
Pauli Virtanen
a2a5012cb2 bluez5: backend-native: set transport volume on create
Initial transport volume was being set incorrectly to max for new
transports. This is usually masked by route restore, but not always.
2022-01-30 22:00:32 +02:00
Pauli Virtanen
3ffc0452a7 bluez5: backend-native: fallback switch msbc->cvsd on EOPNOTSUPP
If MSBC connect() fails with EOPNOTSUPP, trigger codec renegotiation.

When PW is AG, this also removes the msbc profile.
2022-01-30 22:00:32 +02:00
Pauli Virtanen
1da23145df bluez5: probe adapter msbc capability via hci commands
Using a probe connection to determine adapter msbc capability causes
problems on some adapters (ff8c3d2, 84bc0490a5, 717004334b,
pipewire#2030) and seems to be a bad idea.

Go back to probing for transparent msbc transport capability via HCI
commands. bluetooth/hci.h may be deprecated later, but for now it's
better to go back to using it.  (In practice, adapters not supporting
esco appear to be fairly rare; kernel commit in 2013 refers to "older
devices", so if we can't use HCI, assume the adapter supports the
necessary modes.)
2022-01-30 22:00:32 +02:00
Valentin Hăloiu
483831e514
bluez: handle non-hexadecimal XAPL version strings 2022-01-29 21:13:45 +00:00
Wim Taymans
92198e4d0d spa: clamp required alignment to cpu alignment
pipewire will allocate buffers aligned to the max alignment required for
the CPU. Take this into account and don't expect larger alignment.

Fixes a warning in mixer-dsp when the CPU max alignment is 16 but the
plugin requires 32 bytes alignment for the AVX2 path (that would never
be chosen on the CPU).

See #2074
2022-01-28 11:49:06 +01:00
Maciek Borzecki
78a239a370 spa/bluez: enable sbc-xq for JBL Endurance Run BT headset
Enable SBC-XQ codec for the JBL Endurance RUN BT headset. The codec worked well
with pulseaudio and works equally well with pipewire.

Signed-off-by: Maciek Borzecki <maciek.borzecki@gmail.com>
2022-01-28 07:58:22 +00:00
Wim Taymans
f2906a26f1 alsa: sync TI2902 conf with pulseaudio
Adn reenable it to see if it improves things again.
2022-01-27 11:10:24 +01:00
Wim Taymans
4660e16d5b meson: enable some more warnings
Fix some warnings
2022-01-27 11:07:17 +01:00
Gleb Popov
44b18b86cd Fix build on FreeBSD by defining bswap_64. 2022-01-26 14:37:19 +03:00
Wim Taymans
8d37451fb8 alsa: ensure period_size is not 0 2022-01-24 12:44:16 +01:00
Pauli Virtanen
a67f38f790 spa/v4l2: better device product names on current kernels
udev/kernel sometimes give "Video Capture N" as ID_V4L_PRODUCT, which is
bogus as a device product name.  The ID_MODEL* field seem to always have
a sensible product name.

Get device.product.name always from ID_MODEL*, and use ID_V4L_PRODUCT
only as the last fallback.
2022-01-23 12:57:11 +00:00
Pauli Virtanen
e1bc1c4569 alsa-udev: postpone emitting if pcm devices are busy, retry later
There is a race condition on udev permission changes (e.g. switching
VTs), when pipewire from one user closes devices, and the other process
from second user tries to open them.  The close/open are not ordered, so
opening a device may fail in alsa-acp-device.c resulting to missing
devices/profiles.

Address this by trying to open devices already in alsa-udev.c. If some
devices are busy, do not emit the device info yet, but retry after a
timeout.  If it still fails, go ahead emitting the device, even if some
profiles may be missing.  The retry with delay should be enough to solve
the race almost always.
2022-01-23 12:33:57 +00:00
Pauli Virtanen
0a55085b14 bluez5: allow setting initial profile to off
This is useful if the session manager wants to set the profile itself,
and has special handling for the off profile.
2022-01-22 20:01:00 +00:00
Wim Taymans
5b3bc4e80e alsa: first start monitor then enumerate devices
So that we can catch the SOUND_INITIALIZED update between enumerating
devices and starting the monitor.This fixes a races in detecting devices.

Thanks to Matthias Fend for finding this.

Fixes #2046
2022-01-21 10:50:13 +01:00
Pauli Virtanen
ee257b148b bluez5: deal with adapters appearing after devices
Devices may appear before or after their adapter does on BlueZ DBus
interface.

When an adapter appears, search the device list, and associated its
devices with it.
2022-01-21 00:01:28 +02:00
Wim Taymans
6a892c27b0 audioconvert: block volume updates when disabled 2022-01-20 20:07:05 +01:00
Pauli Virtanen
a4b1e4c42a bluez5: don't crash in battery_remove
If device has no adapter, then there's no battery provider.
2022-01-20 18:18:09 +00:00
Pauli Virtanen
dda65b95af bluez5: maintain transport->device_list properly
If device != NULL, the transport must be in its transport_list.
2022-01-20 18:18:09 +00:00
Pauli Virtanen
f2630ed6fc bluez5: require adapter before profile connect & after
All exposed bluez devices should have an adapter specified at all times.
Adapter-less devices appear in some race conditions in BlueZ interface.

Require device has non-null adapter, in all cases before adding any
profiles (which exposes the device), and reject BlueZ profile connection
attempts in that state.

If an adapter gets removed by BlueZ, remove also all its devices, so
that device->adapter pointers stay valid.
2022-01-20 18:18:09 +00:00
Wim Taymans
ba7e5d619d audioconvert: add option to disable channelmix 2022-01-20 18:08:30 +01:00