Commit graph

158 commits

Author SHA1 Message Date
Pauli Virtanen
50437fb4eb bluez5: set device.routes on device set nodes
Device set node props are controlled by a Route, so set device.routes=1
to avoid Wireplumber restoring node props on it.
2025-01-26 21:04:49 +02:00
Pauli Virtanen
de0f54c324 bluez5: support BAP hardware volume on device sets
Enable hardware volume for device sets, when all devices in the set
support HW volume.
2025-01-25 15:37:52 +00:00
Sanchayan Maity
e83f01a33b bluez5: Clean up ASHA implementation 2025-01-09 14:51:50 +00:00
Sanchayan Maity
13c026417b bluez5: Implement support for ASHA
ASHA is a Bluetooth specification for hearing aids.

For a high level overview of the ASHA Specification for BlueZ.
https://asymptotic.notion.site/ASHA-Spec-for-Bluez-61a46027fd46458d8235e14d6bedb2ce

The original specification in Android.
https://source.android.com/docs/core/connect/bluetooth/asha

Corresponding support in BlueZ.
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/profiles/audio/asha.c

This only implements handling of one side of a ASHA device
pair. Stereo support/handling of both "left" & "right" side
will follow later requiring work on clock synchronization
between the pair.
2025-01-09 14:51:50 +00:00
Pauli Virtanen
2bf48487cb bluez5: handle A2DP inverted ClearConfiguration/SetConfiguration order
When in A2DP sink role and remote end switches codec, BlueZ nowadays
appears sometimes emit first SetConfiguration (creating new transport),
and then ClearConfiguration (removing old transport).

Handle this case: emit profiles_changed event always when transports
come/go.

Redefine profiles_changed() to take bitmask of profiles whose connection
status changed, so we don't need to emit two remove+add events.
2024-12-06 16:36:14 +02:00
Pauli Virtanen
e74e7b938e bluez5: don't re-emit nodes on device set events if unchanged
Only re-emit nodes on BAP device set changes, if our configuration
actually needs to be changed.
2024-11-25 21:26:13 +02:00
Pauli Virtanen
603c67628e bluez5: fix BAP route non-deviceset availability
Fix issue where BAP routes are marked unavailable for devices not in a
device set.

Fixes: a154169942
2024-11-23 11:25:46 +02:00
Pauli Virtanen
1b5c244ee0 bluez5: clean up route/profile building
Clean up route/profile building a bit so that it is easier to add new
device profiles.

Use names instead of magic numbers for the routes.

Fix marking BAP set input route unavailable by error due to magic number
off by one.
2024-11-04 21:54:29 +02:00
Wim Taymans
e2991f6398 json: add helper function to parse channel positions
Use the helper instead of duplicating the same code.

Also add some helpers to parse a json array of uint32_t

Move some functions to convert between type name and id.
2024-09-18 09:54:34 +02:00
Wim Taymans
1ae4374ccf Fix compilation with -Werror=float-conversion
Better make the conversions explicit so that we don't get any surprises.

Fixes #4065
2024-06-18 12:17:56 +02:00
Barnabás Pőcze
0b87144d26 spa: bluez: fix whitespaces 2024-02-05 20:01:21 +01:00
Pauli Virtanen
805e5cf9c1 bluez5: show only codec profiles also for HFP/HSP
Don't show a "codecless" profile for HFP, similarly as we do for A2DP.

Simplify codec handling: for HFP/A2DP there's at most one transport for
each profile, so no need to check it has right codec.  There's also no
need for "fallback profile", we always just emit nodes for the transport
we find.
2024-02-03 16:10:12 +00:00
Pauli Virtanen
65f594c6a1 bluez5: further HFP cleanups
Fix naming issues.
2024-01-25 08:43:45 +00:00
Pauli Virtanen
fe412784a4 bluez5: support LC3-SWB in HFP RFCOMM & add codec id for it
HFP 1.9 adds LC3 as a possible codec in addition to CVSD & mSBC.
E.g. Pixel Buds Pro latest firmware supports it.

Add the RFCOMM side and codec selection for it.
2024-01-25 08:43:45 +00:00
Pauli Virtanen
70ffbaed74 bluez5: fix node initialization to init all nodes
Now that we can have more than 4 nodes, so should init them all.
2024-01-09 08:07:33 +00:00
Pauli Virtanen
a154169942 bluez5: support multiple BAP transports per device
In multi-ASE configurations there can be multiple transports per device,
each corresponding to different channels.

Emit sink/source nodes for each BAP transport present.

Combine them into a single sink/source in the same way as we do for
device sets.
2024-01-08 10:09:13 +00:00
Pauli Virtanen
eaea03c26c spa: export log topic enumerations 2024-01-04 10:02:55 +00:00
Pauli Virtanen
7f2dd3531c bluez5: use only one input route
Don't have separate input route for A2DP and HFP, as it is generally not
necessary.

When in A2DP mode when there's also HFP possible, emit the input route
in SPA_PARAM_Route, even though there is no corresponding input node
emitted.

The host may then emit a loopback microphone node, and switch profiles
according to its status. Having the input route available at all times
allows to retain changes to volume settings made when there is no real
input node.
2023-12-09 14:05:50 +02:00
Frédéric Danis
442a208382 Bluez5: backend-native: HSP AG release SCO link on AT+CKPD=200
Bluetooth PTS test HSP/AG/ACR/BV-01-I request AG to release the SCO link
upon reception of AT+CKPD=200 reception
2023-11-29 15:43:22 +00:00
Pauli Virtanen
d121d273f0 bluez5: add more debug for device sets 2023-10-24 19:40:44 +03:00
Pauli Virtanen
a9cc3f2813 bluez5: deprioritize audio-gateway if remote is HFP HF + A2DP sink
If remote supports both HFP HF and AG, both may get connected, which
occurs with Pipewire<->Pipewire connection.  In this case, Pipewire on
both sides may pick the audio-gateway profile.

To avoid both sides being audio-gateway, if remote is both A2DP sink and
HF, use lower priority for the audio-gateway profile.  Generally, BlueZ
won't connect both A2DP Source and Sink between same devices at the same
time, so we use that to determine which side should be the receiver.
2023-09-24 15:45:33 +03:00
Pauli Virtanen
186b730c9c bluez5: fix device supported codec checks
Make supported codec checks to use profiles, not "is-a-sink" flag, to
determine which codecs can be used.

Fixes bluez5-device checking only source profiles, even when the local
device is only a sink.
2023-09-13 15:51:50 +00:00
Silviu Florian Barbulescu
32084ff3c6 Fix problems found in the review of the broadcast sink support. 2023-08-24 16:31:03 +00:00
Silviu Florian Barbulescu
8660066af6 Add suport for braodcast sink 2023-08-24 16:31:03 +00:00
Silviu Florian Barbulescu
c6760105df Fix problems found in the review. 2023-08-24 16:31:03 +00:00
Silviu Florian Barbulescu
ef3fac401d bluez5: Add LE Audio BAP broadcast source support
Once Pipewire is started it will try to register a BAP broadcast source media endpoint on UUID 00001852-0000-1000-8000-00805f9b34fb if the media codec that supports BAP and the adapter indicates LE Audio is supported.
When the endpoint is detected (over DBus) by Pipewire and it has a broadcast sink UUID, a new device will be created with the address 00:00:00:00:00:00. This device will be our simulated remote device. This is done because a broadcast source emitting device does not need any connection to start transmitting the audio. This device is set as connected.
When the SetConfiguration DBus method is called and the spa_bt_transport structure with the profile BAP broadcast source is created we switch the device from the one read from DBus to the one created by us. This is done because in BlueZ, when the transport is created, at the Device property, BlueZ sets the adapter as the device that the transport is connected to. Here the device will have the newly created SPA_BT_PROFILE_BAP_BROADCAST_SINK profile connected.
Added code that allows to create a node in the graph for a device connected to the SPA_BT_PROFILE_BAP_BROADCAST_SINK profile.
2023-08-24 16:31:03 +00:00
Pauli Virtanen
dbd97020da bluez5: fix BAP profiles showing
Now that we only show codec profiles, the logic that showed codecless
profile for BAP has to be removed.

This fixes BAP only showing off profile.
2023-08-23 10:07:15 +00:00
Ashok Sidipotu
cd24fe2fe9 bluez5: A2DP and BAP profiles to enumerate only codec profiles
This avoids the potential confusion when both codecless and codec profiles are
enumerated for A2DP.
Give base name to highest priority profile, so that best codec can be selected
at command line with out knowing which codecs are actually supported.
2023-08-21 08:21:37 +00:00
Pauli Virtanen
882f9ad2b3 bluez5: emit BAP device set nodes as needed
Emit BAP device set nodes, which the session manager can use to combine
the sinks/sources of a device set to a single sink/source.

Emit the actual sinks/sources with media.class=.../Internal to hide them
from pipewire-pulse.

Add separate device set routes to the set leader device.  Other routes
of the set members will be marked as unavailable when the set is active.

Accordingly, return failure for attempts to set these unavailable
routes, so that volumes etc. of the "internal" nodes are only controlled
via the device set route.
2023-04-10 07:00:44 +00:00
Pauli Virtanen
a49d2d41af bluez5: ensure nodes are removed on disconnect
Emit any remove node events before resetting initial profile.  It
indicates to the session manager that nodes if any went away before
device disconnected.

Usually the profile is removed first which removes the nodes. This
depends on ordering of events from bluez, which apparently can be
different depending on how remote device disconnects.
2023-03-16 19:42:31 +02:00
Barnabás Pőcze
934ab3036e treewide: use SPDX tags to specify copyright information
SPDX tags make the licensing information easy to understand and clear,
and they are machine parseable.

See https://spdx.dev for more information.
2023-02-16 10:54:48 +00:00
Pauli Virtanen
b94cb5d99d bluez5: fix BAP current profile
Fix BAP profiles again: make sure the current profile is indicated
properly.
2023-02-07 22:54:37 +02:00
Pauli Virtanen
cfee662f0b bluez5: fix BAP profiles for source/duplex cases
Codec switching does not currently work properly for source/duplex.
With BAP it's also possible only when we're BAP client.

When we can't codec switch, emit the "codecless" BAP profile.
2023-02-06 06:35:40 +00:00
Wim Taymans
6207d98ff1 spa: add debug log context
Make a real debug context with a log function and move it to a new file.
This way we don't need to redefine a macro.
Make a new context for debugging to a log file. Make new functions to
debug to a log file.
Move the stringbuffer to string utils.
Integrate file/line/func and topics into the debug log.
We can remove some more things from the pipewire log_object function and
also add support for topics.
2023-01-18 17:51:16 +01:00
Wim Taymans
3c67821c4a spa: add context to debug functions
Add new spa_debugc_ funnctions that take a context. The user should also
redefine the spa_debugc macro to handle the context.

Use this to let some plugins log the pod and format to the log without
using the global logger.

Also use this to remove our custom pod logger function by reusing the
spa one with a custom context.
2023-01-18 13:12:16 +01:00
Pauli Virtanen
4b408e2978 bluez5: fix reported BAP profile index 2023-01-17 20:14:14 +02:00
Pauli Virtanen
9496078be5 bluez5: add bluetoothOffloadActive device prop for acquiring transports
Add a device prop that causes transports to be acquired.
2022-12-02 11:11:47 +01:00
Pauli Virtanen
7066aa7e15 bluez5: fix build_profile index handling
The codec profiles come at profile indices after the no-codec profiles.
Make the codec clearer by not using magic numbers here.
2022-10-12 07:26:00 +00:00
Pauli Virtanen
8de03f5c29 bluez5: support and use old api.bluez5.a2dp.* factory names for A2DP
For backward compatibility with old Wireplumber releases, support the
old api.bluez5.a2dp.sink/source names, and use them in object events
instead of the media.sink/source names.
2022-09-15 23:04:37 +03:00
Pauli Virtanen
13eb00fd44 bluez5: fix error in search/replace for a2dp->media
The A2DP factory source<->sink was erroneously swapped in
commit 00d51c3d31 ("bluez5: Rename codec API from *a2dp* to *media*")
2022-09-15 19:39:26 +03: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
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
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
d29aafd857 bluez5: enable A2DP duplex volume boost only if codec asks for it
Make A2DP volume boost conditional on a flag the codec sets.

Bump codec API version.
2022-07-19 13:44:56 +00:00
Pauli Virtanen
fe7c6bcef9 bluez5: volume changes from headset should be saved
User changing volume via headset buttons should be treated on the same
level as changing from desktop UI.  Also initial headset volume should
be considered saved (even though session managers currently ignore the
initial route values on route restore).

Mark route as saved on volume events.
2022-07-09 18:19:45 +00:00
Pauli Virtanen
77959a2c1c bluez5: get initial node volume from transport
When emitting node, get initial volumes from transport hardware volume,
if available.

The session manager usually overrides these immediately with saved
values, but it's better to show the HW volume when the node first
appears.
2022-07-09 18:19:45 +00:00
Pauli Virtanen
276c4bc554 bluez5: use separate routes for HFP and A2DP
The A2DP and HFP profiles may have different volume curves, so trying to
convert volumes between the two can produce undesirable volume spikes.
For example, when one of them is using hardware volume and the other
software.

Fix by separating HFP and A2DP routes.
2022-07-09 18:19:45 +00:00
Pauli Virtanen
689e2d0cc9 bluez5: clear codec switch flag on device connnection change
Codec switch flag should be cleared on device connection status change,
to deal with codec_switched() callback not being called if device is
suddenly disconnected.
2022-04-25 21:28:39 +03:00