Commit graph

83 commits

Author SHA1 Message Date
Pauli Virtanen
79e098bdf2 bluez5: implement HFP codec switching
Implement switching HFP codecs in bluez5-devices, currently only for
backend-native.

Codecs are exposed via profiles similarly as for A2DP.

Some hardware appears to not properly reply to the +BCS message. Catch
these cases with a timeout, in which case we fall back to previously
existing transports.
2021-03-20 20:01:52 +00:00
Pauli Virtanen
e18df4e344 bluez5: use callback table in hsp/hfp backends 2021-03-20 20:01:52 +00:00
Huang-Huang Bao
6512c2b5f6 bluez5: fix a use-after-free on transport handle
'remove_dynamic_node()' reference transport after it got freed in 'spa_bt_transport_free()'.
2021-03-20 09:15:02 +00:00
George Kiagiadakis
9b788b5a66 bluez: expose transport_set_state method to backends 2021-03-19 11:49:41 +00:00
Wim Taymans
08f2284eea bluez5: add device.string in properties
See #842
2021-03-18 12:44:09 +01:00
Huang-Huang Bao
d0636875ee bluez5: fix memory leak on device battery path 2021-03-18 08:27:32 +00:00
Huang-Huang Bao
e9adb2844e bluez5: clear obsolete objects also when bluetooth daemon appeared
See #906
2021-03-18 08:24:06 +00:00
Huang-Huang Bao
68677774fc
bluez5: fix reference to already freed spa_bt_device
Fixes #907
2021-03-18 12:09:30 +08:00
Huang-Huang Bao
75b4c80dc6 bluez5: add logic to fallback to previous behavior if connection info handling is not supportrd by session manager (i.e wireplumber). 2021-03-16 10:31:08 +00:00
Huang-Huang Bao
374180e211 bluez5: pass per-device settings to codec handler, make 'bluez5.sbc-xq-support' a per-device setting 2021-03-16 10:31:08 +00:00
Huang-Huang Bao
af8272fe08 bluez5: create device handle before profile negotiation started so that profile handler can retrieve per-device settings 2021-03-16 10:31:08 +00:00
Huang-Huang Bao
d6be84ddd0
bluez5: close sco socket if bluetooth daemon disappeared
Fixes pipewire/pipewire#853
2021-03-13 19:06:49 +08:00
Dmitry Sharshakov
e2ac16ccbd fix: remove v-battery when device disconnects 2021-03-12 15:45:41 +00:00
Dmitry Sharshakov
a0ac3ac8dd fix: cancel and free battery register pending call 2021-03-12 15:45:41 +00:00
Dmitry Sharshakov
5c9028a94d bluez5-dbus: move battery provider functions, fix ghost batteries 2021-03-12 15:45:41 +00:00
Dmitry Sharshakov
a1ed8aec68 chore: bluez5: move spa_bt_monitor to common header file 2021-03-12 15:45:41 +00:00
Wim Taymans
c0ab4b1b8d bluez5: fix compiler warning 2021-03-09 12:25:20 +01:00
Pauli Virtanen
511bafb436 bluez5: release transports on profile change
SCO transports have timer-delayed release, but they need to be released
immediately when changing profiles to close connections before switching
to A2DP.
2021-03-08 23:42:08 +02:00
Pauli Virtanen
e42261c6d2 bluez5: remove per-device codec filtering
This does not work as intended, because we no longer do a codec switch
on device connect.  It should be done in a different way, but since it's
not used for anything right now, can as well remove it.
2021-03-06 15:19:14 +02:00
Frédéric Danis
0e2a153bd3 bluez5: Start only one backend at a time for HSP/HFP
This will prevent to run the different backends concurrently.

The native backend will only register to BlueZ if neither oFono nor
hsphfpd are running. If one of them starts, the native backend will be
unregistered and the corresponding backend will register to its daemon.
2021-03-02 09:43:16 +00:00
Pauli Virtanen
6114ca7c4a bluez5: fix queueing codec switches
Make queueing a codec switch work properly.  When receiving the dbus
reply, it should move to latest one. Others should be discarded.

Previously, it instead hit an assert, if there were more than two
queued.
2021-02-24 21:14:25 +00:00
Pauli Virtanen
d75a79babc bluez5: add delay adjustment property + fallback value for a2dp-sink
Not all devices report their A2DP delay. In those cases, use a fallback
value of 150ms by default.

Make the delay adjustable with a SPA_Prop, and expose it as a part of
the route. Implement the corresponding parts in media-session.
2021-02-18 11:33:45 +00:00
Wim Taymans
344eb2baa3 bluez5: handle info == NULL when parsing codecs 2021-02-16 17:58:56 +01:00
Pauli Virtanen
b6108df6f3 bluez5: remove device on disconnect
Do device_remove when device disconnects.

This can occur, as profile check is not run on HFP/HSP profile
disconnect.
2021-02-11 21:55:42 +02:00
Huang-Huang
cd78003e66 bluez5: don't create device if there is no connected profile 2021-02-07 18:38:10 +00:00
Pauli Virtanen
f99eefeb4f bluez5: a2dp-source: release transport if it went idle
Release the transport if it went idle, ensuring that the fd is closed,
and add safeguards we won't double-acquire/release it.

This can occur if the device pauses the playback. The transport may also
activate again later on, and in this case we need to reacquire a new fd.
Not closing the old fd causes problems in this case.

However, apparently the BlueZ Release() call fails if the transport is
idle. We just ignore the error and downgrade the error message; it might
not be safe to not call Release() because the idle property update is
async.
2021-02-07 18:32:44 +00:00
Pauli Virtanen
da5f17f653 bluez5: enable A2DP delay reporting
Inform BlueZ we'd like delay reporting from remote devices.
2021-02-05 05:00:06 +02:00
Pauli Virtanen
fdbcaeb20f bluez5: fix bug in endpoint sort function 2021-02-03 23:00:33 +02:00
Huang-Huang
ab4223601f
bluez5: fix type of 'Codec' on remote endpoint
Vendor codec(LDAC, aptX) uses codec ID 0xff, use uint8 to fill it.
2021-02-03 00:01:29 +08:00
Wim Taymans
41063578a5 bluez5: use for_each_safe when items can be removed
Removing items when iterating a list of only allowed when using the
_safe versions of for_each
2021-02-02 11:48:47 +01:00
Wim Taymans
9d74bd61a7 bluez5: fix debug line 2021-02-02 11:00:16 +01:00
Pauli Virtanen
f841bc0b5b bluez5: remove pipewire device when bluez device disappears
The pipewire device holds a pointer to the device, and should be removed
when BlueZ removes the underlying device.
2021-02-02 09:56:30 +00:00
Pauli Virtanen
4d9e9fcc33 bluez5: emit events on profile change and handle them
BlueZ may connect transports long after DEVICE_PROFILE_TRANSPORT_SEC has
passed on already existing devices.  When this occurs, the bluez5
pipewire device should notify that the profile enumeration has changed.

Ignore these events during A2DP codec switch, and handle any changes
when the switch completes.
2021-02-02 09:56:29 +00:00
Pauli Virtanen
8ffde47080 bluez5: deal with device removal while we're switching the codec
Don't remove devices when there's a codec switch active, but check if
they should be removed once it completes.
2021-02-02 09:56:29 +00:00
Pauli Virtanen
0c74b90f0e bluez5: helper functions for querying codecs on device 2021-02-02 09:56:29 +00:00
Pauli Virtanen
b642c7f209 bluez5: support device capability checks beyond A2DP caps + split sbc-xq to separate codec
We would like to have BT device codec capability checks beyond what's
possible based on A2DP caps.

Split SBC-XQ to a separate codec, and enable it in the device-dependent
check (although currently it just uses the config option).
2021-02-02 09:56:29 +00:00
Pauli Virtanen
e860f2bb4e bluez5: basic codec-switching framework 2021-02-02 09:56:29 +00:00
Pauli Virtanen
ce335b6d88 bluez5: keep track of remote endpoints 2021-02-02 09:56:29 +00:00
Wim Taymans
28376d1db2 bluez: avoid warning 2021-01-30 19:31:52 +01:00
Pauli Virtanen
494194c4bf bluez5: allow selecting codecs to use in config file
For debugging, it may be useful to disable some of the codecs.  Enable
configuring this in config file, to make it more convenient for users,
who may not know how to recompile/install pipewire.
2021-01-30 17:23:07 +00:00
Sebastian Apel
8ac5a89583 bluez5: Added mSBC support in bluze5 backend native, including check to make sure the computer's bluetooth adapter
supports the transport modes required for mSBC
2021-01-13 11:20:22 +01:00
Frédéric Danis
00cce32514 bluez5: Rename backend-hsp-native to backend-native 2021-01-12 11:21:55 +01:00
Wim Taymans
4d15df6f24 bluez5: improve device and node properties
Set form factor, name routes based on form factor.
Improve profile names
Make card and node names like pulseaudio, with bt address in them.
Fill in port type in the route info.

Fixes #544
2021-01-10 20:56:27 +01:00
Pauli Virtanen
7ca568db86 bluez5: don't crash if validate_config fails
transport->device_link has to be set when transport->device is not NULL
2021-01-09 12:08:47 +01:00
Wim Taymans
4440ede41c bluez5: add SBC XQ support with a config option 2021-01-08 13:00:44 +01:00
Wim Taymans
e91fbd2721 bluez5: Implement routes
Implement routes on the device. This makes it possible for the
session manager to restore the device volumes.
Use validate_config to get the negotiated channels for the route
volumes.
2021-01-07 18:10:22 +01:00
Pauli Virtanen
a81158f3d5 bluez5: after registering a2dp profiles, connect them to connected devices
After registering a2dp profiles on startup, call
org.bluez.Device1.ConnectProfile on already connected devices, if
applicable.
2021-01-06 17:36:34 +02:00
Pauli Virtanen
5a22d0bfca bluez5: delay SCO transport releases in case they get reacquired
SCO socket connect may fail with ECONNABORTED if it is done too soon
after previous close. To avoid this in cases where nodes are toggled
between stopped/started rapidly, postpone release until the transport
has remained unused for a time. Since this behavior appears common to
multiple SCO backends, do it for all SCO backends.
2021-01-04 20:37:25 +02:00
Pauli Virtanen
368182d963 bluez5: rework sco i/o + autodetect mtu
Move SCO polling to a single place, and abstract mtu handling.
Autodetect suitable tx packet size based on rx, instead of relying on
the kernel providing correct values.
2021-01-04 19:19:16 +02:00
Huang-Huang Bao
389a125488
bluez5: fix connecting device with multiple adapters 2020-12-30 06:44:36 +08:00