Commit graph

90 commits

Author SHA1 Message Date
Huang-Huang Bao
80f6ddf526
bluez5: add hardware volume support
Add necessary apis to bluez transport.
Add A2DP(AVRCP) absolute volume support. Source volume can only update to adapter node but not from due to AG nodes don't have route.
Since A2DP/HSP/HFP volume is already percentage itself, it has been mapped to pulseaudio volume then converting to linear volume.
2021-04-17 19:07:35 +08:00
Pauli Virtanen
87e06783d1 bluez5: more cleanup on impl_clear
Remove dbus filters and close the dbus connection.  Closing the
connection lets BlueZ to clean up, so we don't call its unregistration
API.
2021-04-10 23:07:51 +03:00
Pauli Virtanen
87aa18edb1 bluez5: free rfcomm when device is freed
Avoids use-after-free if device gets freed before the corresponding
rfcomm.
2021-04-10 15:47:46 +00:00
Pauli Virtanen
026e3882d2 bluez5: remove battery when RFCOMM connection drops
There won't be further battery level updates when RFCOMM connection is
down, so remove the battery then.

Fix minor things with canceling the provider registration.
2021-04-05 15:04:16 +00:00
Pauli Virtanen
51b0248d09 bluez5: update a2dp codec list when remote endpoints change 2021-03-26 16:59:07 +00:00
Huang-Huang Bao
34c9f24d2a bluez5: autoconnect device profiles on startup
Auto-connect all paired & trusted devices on startup.
Since devices that already connected or powering off would reject the connecting requests, it should be fine with this behavior.
Also reconnect remaining profiles if only partial profiles are connected.
2021-03-26 14:15:55 +00:00
Pauli Virtanen
0385d0a07e bluez5: guard against transports without sco_io
If backend releases transport early and sco_io becomes NULL, don't
access it.

Also guard against calloc failing in sco_io creation.
2021-03-20 20:01:52 +00:00
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