Commit graph

324 commits

Author SHA1 Message Date
Barnabás Pőcze
8ca5c0f15b spa: bluez: dbus: do not use NameHasOwner()
Commit 947ee152d3 ("bluez: check dbus service before enumerating objects")
introduced a check that would esure that GetManagedObjects()
is not called if the "org.bluez" name has no owner. This
was done to avoid auto-starting the bluez daemon.

However, this is not needed because it is possible to set on
a per-message basis whether or not the destination service
should be automatically started by the dbus daemon.
2022-10-08 17:59:41 +02:00
Barnabás Pőcze
1d3497b0cd spa: bluez: dbus: do not call GetManagedObjects() if there is a pending call 2022-10-08 17:59:41 +02:00
Barnabás Pőcze
bf18d948b3 spa: bluez: dbus: immediately unref pending call after retrieving reply 2022-10-08 17:59:41 +02:00
Barnabás Pőcze
58d9fbff88 spa: bluez: dbus: keep a reference to the GetManagedObjects() call 2022-10-08 17:59:41 +02:00
Barnabás Pőcze
008d836608 spa: bluez: dbus: do not call GetManagedObjects() again
If a reply to a previous GetManagedObjects() call have been
received, and there is no reason to call it again, do not do it.
2022-10-08 17:59:41 +02:00
Demi Marie Obenour
bb4f274ae0 Make all fopen() calls use O_CLOEXEC
by adding "e" to the mode strings.
2022-09-23 15:19:01 +00:00
Frédéric Danis
fdccc10bc7 bluez5: Use SelectProperties Endpoint property to detect device role
BlueZ adds the Endpoint property to the Properties dictionary of
SelectProperties.
This allows to know which remote Endpoint is an acceptor, and so which
local transport should be used as an initiator.
2022-09-15 11:17:20 +00:00
Frédéric Danis
28b4fbecfb bluez5: Manage BAP linked transports
Multiple transport from the same device may share the same stream (CIS)
and group (CIG) but for different direction, e.g. a speaker and a
microphone. In this case they are linked.
In this case:
- On acquire, if another transport has already been acquired, the new
  transport should not call Acquire or TryAcquire but re-use values from
  the previously acquired transport,
- on release, the closing of transport fd and call to Release should be
  done only for the last transport.
2022-09-15 11:17:20 +00:00
Frédéric Danis
cd50188787 bluez5: Fix node creation depending on device role
We can't determine which remote endpoint or device the
SelectConfiguration() call is associated with. For LE Audio BAP, as this
method is called only for the Initiator we set the whole instance as a
Central/Initiator.
This flag is unset on BAP media endpoint removal.
2022-09-15 11:17:20 +00:00
Frédéric Danis
071730ecab bluez5: Use delay from QoS for BAP 2022-09-15 11:17:20 +00:00
Frédéric Danis
f428b13d06 bluez5: Set BAP QoS depending on selected configuration
This move the QoS setup to be codec specific and fills it depending on the
selected codec configuration.
2022-09-15 11:17:20 +00:00
Frédéric Danis
284da66deb bluez5: Add BAP_SINK/SOURCE from PACS UUID to adapter profiles
BAP sink/source are characteristics of the PACS profile, but we're more
interested by those characteristics then the more generic profile.
2022-09-15 11:17:20 +00:00
Frédéric Danis
496dda1bcc bluez5: Check if BlueZ daemon support LE Audio
Legacy BlueZ 5 API doesn't support to register BAP codecs, which prevents
to register A2DP enhanced codecs.
2022-09-15 11:17:20 +00:00
Frédéric Danis
b7ad1d1869 bluez5: Add SelectProperties DBus method support 2022-09-15 11:17:20 +00:00
Frédéric Danis
fd0bcb1699 bluez5: Add LE Audio BAP support to media-codecs 2022-09-15 11:17:20 +00:00
Frédéric Danis
00d51c3d31 bluez5: Rename codec API from *a2dp* to *media*
The BlueZ Media1 interface will not only be used for A2DP but also for
LE Audio and code related can be shared.
2022-09-15 11:17:20 +00:00
Frédéric Danis
2c72597271 bluez5: Use spa_log_hexdump() to dump media properties/configuration 2022-09-07 07:50:23 +02:00
Huang-Huang Bao
c5bce24f01
bluez5: correct type of arguments to a dbus function
The 3rd "value" arguments to dbus_message_iter_append_basic() should be the address of a basic-typed value.

Fixes #2591
2022-07-23 16:35:01 +08:00
Frédéric Danis
343ae88bbf bluez5: Simplify DBus append_basic_* helpers
String key is used in all calls to append_basic_variant_dict_entry() and
append_basic_array_variant_dict_entry().
2022-07-22 19:10:26 +00:00
Pauli Virtanen
0dc8255057 bluez5: handle sink vs. source correctly in get_supported_codecs
Make a distinction between sink and source endpoints when determining
supported codecs.
2022-07-19 13:44:56 +00:00
Pauli Virtanen
92b2b44954 bluez5: pass global setting dict to codec select_config / preference_cmp
The device is not know at SelectConfiguration time, so the settings
argument in select_config is currently unused. Pass on a global settings
dict instead, so that codec parameters can be configured.

Also add settings argument to caps_preference_cmp.

Bump codec API version.
2022-07-19 13:44:56 +00:00
Pauli Virtanen
a8eb146d39 bluez5: tell the codec whether endpoint is sink or source
Add a flag A2DP_CODEC_FLAG_SINK to incidate a sink endpoint.

Also enum_config and caps_preference_cmp may need to know whether the
codec is being configured for SRC or SNK. Also add the flags argument to
init_props.

Bump codec API version.
2022-07-19 13:44:56 +00:00
Pauli Virtanen
783fbc507b bluez5: fix minor error handling/warning issues 2022-07-06 14:36:22 +00:00
Pauli Virtanen
5b429607a8 bluez5: disable dummy avrcp player by default
It causes some headsets behave strangely. See pipewire#2391,
pipewire#1853.

The BlueZ issue of AVRCP volume sometimes missing that this worked
around was fixed in recent versions. The issue of some headsets not
sending volume without AVRCP player remains, but it appears this breaks
more headsets than fixes.
2022-06-07 18:13:06 +03:00
Pauli Virtanen
8898a6a8f0 bluez5: don't consider profiles the adapter doesn't have
Don't try to reconnect or wait for profiles, which cannot be connected
because the adapter doesn't have the counterpart sink/source profile.

E.g. we should not reconnect/wait for HFP HF on remote device, if
we don't have the corresponding HFP AG.
2022-06-05 18:15:42 +00:00
Pauli Virtanen
8949d45c69 bluez5: check decode/encode capability also at registering
Endpoints without decode/encode capability are skipped in the object
manager, but we should also skip them in the registration calls (even
though in practice this doesn't appear to matter).
2022-06-05 18:03:24 +00:00
Pauli Virtanen
ca18b8b733 bluez5: endpoint can be used only by one device at a time
AVDTP (v1.3 Sec 5.3) has a limitation that a local SEP (on the same
adapter) can be connected to at most one remote SEP. Trying to do have
it connected to multiple remotes either fails or causes misbehavior
later on.

Skip SetConfigure the same local endpoint for multiple remote ones in
codec switch. BlueZ observes this restriction in SelectConfiguration,
so also it won't try to do invalid configurations.

In BlueZ 5.64, the SetConfiguration calls succeed, but subsequent
transport acquires will fail. (Likely already the SetConfiguration DBus
call should fail.)

This all has the consequence, with the current approach to the
codec=endpoint correspondence, that if multiple devices are connected to
the same adapter, they currently have to use different codecs.
2022-05-30 07:35:54 +00:00
Fabrice Fontaine
85ca67b927 fix detection of reallocarray
Fix detection of reallocarray (e.g. on glibc) raised since commit
0708a39b43

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2022-05-30 09:33:27 +02:00
Wim Taymans
9e3b784b34 bluez5: use reallocarray 2022-04-27 09:27:32 +02:00
Pauli Virtanen
3be019d7a8 bluez5: stop running codec switch on disconnect
When device is disconnected, running codec switches are not meaningful,
and should be stopped.

The codec switch callback may also trigger A2DP profile switch, which
may reconnect the device. Fix it so this does not happen.

See #2334
2022-04-25 20:15:37 +03:00
Pauli Virtanen
24fd273820 bluez5: backend-ofono: don't do codec probe connections + add wait
Codec probe connections can trigger bad behavior from oFono if done when
device is busy (e.g. at connect), and they might be done at the same
time as A2DP transport is acquired which cannot work.

Also, oFono will not reply to DBus Acquire, if device does not complete
codec negotiation correctly. This is most likely to happen just after
device connect, when it is busy with other stuff (eg A2DP).

Remove codec probe connections altogether: instead, we guess mSBC if
mSBC is enabled and otherwise CVSD. If the guess turns out to be wrong,
which is unlikely (almost all devices have mSBC), we recreate the
transport with correct codec (from main loop, must not be done in
*_acquire because that can destroy nodes + unload the spa libs while
we're being called from there).

To avoid oFono DBus hangs at startup, add delay before marking the
profile connected, enforcing a time difference to A2DP operations.
2022-03-05 17:46:40 +00:00
Julian Bouzas
6dbdb2eecb bluez5: only consider A2DP profiles if HSP/HFP backed is none
This allows BT device to connect instantly instead of waiting for profile
timeout when hsp/hfp backend is none, because all available profiles are
connected.
2022-02-24 15:17:19 +00: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
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
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
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
Pauli Virtanen
67dcc0d291 bluez5: don't create device if adapter is missing
BlueZ may be missing adapter information for devices in some cases.
Ignore devices without specified adapter.
2022-01-17 18:54:10 +00:00
Pauli Virtanen
e4f7b2285b bluez5: bump device profile timeout
Double device profile timeout to 6sec.

In some cases, BlueZ can take more than the previous 3sec to connect all
profiles. It's better to wait for a bit longer, so that devices have all
profiles visible already when they first appear.

This works around issues in Wireplumber profile selection logic.
2022-01-09 11:05:42 +00:00
Pauli Virtanen
b92a378a29 bluez5: mark connected when all source/sink profiles connected
Don't require all device profiles to be connected before marking the
device as connected before profile timeout. Show device already when all
A2DP/HSP/HFP profiles for sink/source direction have connected.

There are devices that in principle can have both sink/source profiles
present, but cannot operate both directions at the same time.  In case
profiles come online later, the only effect is that the device profiles
will get an update after the device is published.
2022-01-09 11:05:42 +00:00
Pauli Virtanen
9b43388cee bluez5: retry codec switch with timeout on BlueZ failure
Try to call SetConfiguration after timeout when BlueZ reports a failure
for it.
2022-01-04 22:14:10 +02:00
Pauli Virtanen
cc43b2f601 bluez5: rate limit BlueZ SetConfiguration calls
A2DP profile may disappear if several SetConfiguration events occur too
rapidly. Rate limit these calls when switching codecs.

This resolves failures if e.g. the session manager attempts to set the
profile immediately after the device is created, which previously might
cause a failure.
2022-01-04 22:14:10 +02:00
Wim Taymans
947ee152d3 bluez: check dbus service before enumerating objects
First check if the bluez dbus service is active before doing a
GetManagedObjects() call.

Else we might try to activate the bluetooth dbus service, which
should normally only be activated during bootup.
2021-11-17 12:00:00 +01:00
Pauli Virtanen
2329a4d323 bluez5: quirks for headset without a2dp duplex codecs
See #1756 (another headset with non-working, probably faststream duplex)
2021-11-08 08:25:55 +00:00
Pauli Virtanen
4b831021fb bluez5: add a dummy AVRCP player as a workaround
Some devices (Bose Mini Soundlink II, Air 1 Plus, ...) don't enable
AVRCP volume control, or fail to enable it before a hardware button is
pressed.  However, these devices appear to enable it, if an AVRCP player
is present.

As a workaround, register a dummy AVRCP player for each adapter. It only
displays the current transport acquisition state as playing/stopped, but
just its presence appears to be enough to make devices behave.

Multiple AVRCP players interfere with each other, as BlueZ uses the one
registered earliest as the default player. So add also a config option
for disabling this. (It's not common to have mpris-proxy etc. running,
so defaulting to true should be OK.)

See pipewire#1157
2021-10-10 16:24:41 +03:00
Pauli Virtanen
d28b36bb93 bluez5: fix HFP backend behavior when BlueZ goes away
Ensure unavailable backends get unregistered.

Don't log error-level messages on HFP unregistration failures.
2021-10-09 13:03:08 +00:00
Pauli Virtanen
c620121529 bluez5: add faststream quirks
For some devices FastStream causes problems. Add quirk for disabling it.
2021-10-03 20:55:02 +03:00
Pauli Virtanen
58c7caf1bc bluez5: use log topics
Use log topics instead of prepending NAME: to log messages.
2021-10-02 12:46:02 +03:00
Pauli Virtanen
0af3c85806 bluez5: don't probe native backend presence
Don't do a blocking probe of native backend presence, because it may
trigger DBus activation for Bluez.  If the DBus activation fails, it
ends up blocking until timeout.

ofono/hsphfpd usually don't have DBus activation configured, so they
fail instantly (which is why this problem was not encountered, even
though they do blocking calls on startup in previous pipewire versions
too).

Instead, select the backend once we have Bluez objects listed.
2021-09-25 16:24:10 +00:00