Commit graph

146 commits

Author SHA1 Message Date
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
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
96acc5a79a bluez5: Add LE Audio BAP support to bluez5-device 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
e7f17e1523 bluez5: use lower case for UUIDs
BlueZ uses lower case version for the UUIDs in its DBus interface.
This will simplify future UUID tests.
2022-08-03 06:15:54 +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
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
Pauli Virtanen
377bc16eb5 bluez5: handle any quantum in a2dp-sink
Remove quantum limitation from a2dp-sink, and adjust how flushing is
done.

The "low-latency" A2DP codecs are not able to flush all data at once, so
for them flush based on a timeout, such that "excess samples" for each
quantum is bounded.  We also limit excess samples for the other A2DP
codecs, based on some testing on flaky headset/adapter combinations (for
most cases, this does not appear to matter).

Leave decision of packet sizes to the codecs. Currently, we send packets
based on min_latency, but sendinf full packets might help with stutter
on some headset/adapter combinations.  The slightly increased latency
hardly matters against the 100ms delays in BT headsets.

Bump codec API version.
2022-03-11 18:09:55 +02: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
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
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
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
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
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
90b4efd98d bluez5: cleanup hfp/hsp backend handling + config file option
It seems not uncommon that people have not properly configured ofono
running, which results to loss of HFP/HSP functionality. It's less
surprising if the backend selection is fixed in the configuration file,
and (by default) does not depend on running services.

Add a configuration file option for selecting HFP/HSP backend, and set
the default value to the native backend. Emit warnings if conflicting
backend services are detected to be running.

Also cleanup hfp/hsp backend handling a bit, now that it's mostly
abstracted behind an interface.
2021-09-19 17:33:32 +00:00
Pauli Virtanen
dedc08cdf8 bluez5: enable duplex for aptx-ll
aptX-LL sink devices may send back mSBC encoded data corresponding to
microphone input.  It appears to be enabled when the bidirectional link
is set in the caps, and the device also supports this.

Implement mSBC decoding in the duplex channel.

Tested to be working on Avantree Aria Pro.
2021-08-22 17:41:50 +03:00
Zsombor Welker
f5850af4d8 bluez5: handle XAPL battery level per Apple Guidelines
Corrects the handling of AT+XAPL Apple extensions to send
`+XAPL=iPhone,2` instead of `+XAPL: iPhone,2` based on Apple's
documentation.

Replaces magic numbers with enum values.

[Accessory Design Guidelines](https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf)
2021-08-13 10:30:36 +02:00
Zsombor Welker
f87942027f bluez5: report HF indicator 2 based battery status
HF indicator 2 (see [assigned-numbers], Hands-Free Profile) is able to
report battery percentage at 1% intervals (in range [0, 100]), contrary
to the `+XAPL` `+IPHONEACCEV` extension which only supports 10%
increments.  This does not guarantee increased granularity however, as
peers may still be limited to imprecise battery measurements internally
or round to coarser percentages.
Supporting both additionally broadens the range of devices for which PW
can report its battery level.

[assigned-numbers]:
https://www.bluetooth.com/specifications/assigned-numbers/
2021-08-12 18:45:44 +00:00
Huang-Huang Bao
9f2d6d6d28 bluez5: fix rounding error on hardware volume conversion
Ensure the conversions between spa_bt_volume_linear_to_hw and spa_bt_volume_hw_to_linear are reversible when
operating on hardware volume.
2021-07-30 08:46:14 +00:00
Barnabás Pőcze
f5d51162c4 treewide: mark things static and const
Mark some structures, arrays static/const at various places.
In some cases this prevents unnecessary initialization
when a function is entered.

All in all, the text segments across all shared
libraries are reduced by about 2 KiB. However,
the total size increases by about 2 KiB as well.
2021-06-30 14:44:08 +02:00
Pauli Virtanen
9d38d375d2 bluez5: add and use quirk for broken mic HW volume
Some headsets emit AT+VGM even though +VGM commands do not actually
adjust the recording volume.
2021-06-22 10:58:50 +03:00
Pauli Virtanen
b57ae8c2a6 bluez5: add support for hardware quirk/feature database
Implement hardware quirk/feature database with pattern matching.
2021-06-22 10:58:50 +03:00
Pauli Virtanen
2c9764da1d bluez5: parse bluez vendor/product ids
It seems few devices support the Device Id via bluez.

Try to figure out vendor/product ids for usb devices also via sysfs.
Also try to figure out the adapter bus type.
2021-06-22 10:58:50 +03:00
Huang-Huang Bao
3433f40cd9 bluez5: fix device connection issue if profile(UUIDs) info is delayed
Keep all types of devices, only emit device info if device has audio profiles.
Heuristically add profiles based on bluez actions so device can still be connected
even without initial UUIDs info from signal InterfaceAdded for org.bluez.Device1.

Fixes #1330
2021-06-21 07:10:02 +00:00
Huang-Huang Bao
d3fcc0a37a bluez5: correct parameter names in spa_bt_sco_io_create declaration
From its definition and parameters passed to its function call, the 3rd parameter
is read_mtu and the 4th is write_mtu.

Fixes #1256
2021-06-05 15:17:10 +00:00
Huang-Huang Bao
38bcec9022
bluez5: add port latency reporting 2021-05-28 20:02:10 +08:00
Andrea Gelmini
47ef2b6b09 Fix typos 2021-04-30 07:40:20 +00:00
Huang-Huang Bao
0dde4f8774 bluez5: cache a2dp volumes activation info
So we don't get a sudden boost on soft volumes when switching profile/codec.
2021-04-21 08:54:10 +00:00
Huang-Huang Bao
edee633f96
bluez5: add property to enable hardware volume control 2021-04-17 19:35:46 +08:00
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
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
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
George Kiagiadakis
9b788b5a66 bluez: expose transport_set_state method to backends 2021-03-19 11:49:41 +00:00
Huang-Huang Bao
d0636875ee bluez5: fix memory leak on device battery path 2021-03-18 08:27:32 +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
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
2683c1ef5e backend-native: report battery status to BlueZ 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
Dmitry Sharshakov
0078b3b73e backend-native: get battery status via HFP 2021-03-12 15:45:41 +00: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
Huang-Huang Bao
97cc27600a bluez5: add missing function defination 2021-03-02 14:08:14 +00:00