Commit graph

172 commits

Author SHA1 Message Date
Wim Taymans
13b8c23767 Don't use SPA_AUDIO_MAX_CHANNELS directly
Make a MAX_CHANNELS define and use that one in code. This makes it
easier to change the constant later.
2025-10-21 09:43:06 +02:00
Pauli Virtanen
26b09b0ee3 bluez5: temporarily remove BAP nodes when another device is switching
Unicast BAP codec switch requires CIG reconfiguration, which cannot be
done if there is an acquired transport.

When doing BAP codec switch, disable nodes of other devices sharing the
same CIG.

To avoid problems with node start/stop, just remove and re-add them.
2025-06-13 22:16:03 +00:00
Pauli Virtanen
209820bab8 bluez5: add separate BAP sink/source/duplex profiles
If device supports duplex, show also separate sink-only/source-only
profiles.

Devices don't necessarily support high-quality audio in duplex profile,
so add sink/source only profiles.

This is also a workaround for the current situation that devices may
signal duplex support, but the attempted duplex configuration fails to
work.
2025-06-13 22:16:03 +00:00
Pauli Virtanen
8795298f69 bluez5: implement BAP ucast reconfiguration
Use SelectProperties() DBus API to reconfigure BAP unicast setup.

Add support to spa_bt_ensure_codec() to select whether to configure as
sink/source/duplex.
2025-06-13 22:16:03 +00:00
Pauli Virtanen
a30d385636 bluez5: reduce debug spam 2025-06-13 22:16:03 +00:00
Pauli Virtanen
3f9fb8d664 bluez5: bluez5-device: reduce special casing of HFP codec related things
Get most information items out from media_codec properties, avoid
referring to HFP codec ids.
2025-06-13 17:51:16 +00:00
Pauli Virtanen
e375364c87 bluez5: fix device set profile/route enumerations
Now that we have ASHA & BAP, this->device_set now refers to the device
set of the active profile.  It cannot be used to produce
EnumProfile/EnumRoute.

Fix this by computing the device set for given profile(s) as needed.
2025-05-17 10:50:15 +00:00
Pauli Virtanen
e5d0dd2020 bluez5: enable asha device set only if there's a device set
Now that ASHA uses device set, no need to special case here.
2025-05-11 16:14:40 +03:00
Sanchayan Maity
a419f69bbb bluez5-device: Refactor device_set_update for ASHA & BAP 2025-05-07 07:39:46 +00:00
Pauli Virtanen
584ea400c3 bluez5: fix spelling "Headphone" -> "Headphones"
"Headphone" is usually plural
2025-05-05 07:45:24 +00:00
Pauli Virtanen
270eda63a9 bluez5: different icon for A2DP & HFP output routes
Set different icons for A2DP & HFP output routes, so that they look
different (in Gnome).

Don't call the non-HFP output route as "headset" or "handsfree" in this
case, to be less ambiguous about microphone availability.

Also set device.icon-name for the device too.
2025-05-05 07:45:24 +00:00
Sanchayan Maity
9586ef891e bluez5: Use device set for ASHA
While ASHA does not really use the D-Bus device set interface
but since ASHA has a device-wide HiSyncId and needs to handle
left and right side via a combine sink, use the device set
notion for ASHA as well.
2025-05-05 07:43:34 +00:00
Sanchayan Maity
db47c3e442 bluez5-device: Expose HiSyncId and Side information on ASHA node 2025-05-05 07:43:34 +00:00
Pauli Virtanen
bbe1587f71 bluez5: fix volume ids
Node ids don't map directly to volume ids. Fix the indexing.
2025-04-09 07:50:30 +00:00
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