Commit graph

322 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
8bf8600e59 bluez5: if Acquire results to NoReply, try to clean up with Release
If BlueZ doesn't reply, it may consider the operation still active.
Try to Release the transport to get to a known state.

This can happen if device doesn't respond to operations in reasonable
time and BlueZ doesn't have its own timeout which is the case for BAP
currently (which is a bug there).
2025-10-11 20:52:59 +03:00
Pauli Virtanen
8277bf6b36 bluez5: improve error messages when connection drops
Log something less confusing when connection to remote device drops
unexpectedly.

Silence logging transport Release() error in cases where the transport
was simultaneously deleted.
2025-10-02 01:25:56 +03:00
Pauli Virtanen
984c44b044 bluez5: fix BIS source presentation delay
The value comes from QoS preset, not configurable otherwise right now.

Patch from @michael-kong754
2025-08-27 15:55:50 +00:00
Pauli Virtanen
b91864eb37 bluez5: don't crash on codecs without caps_preference_cmp
E.g. LDAC doesn't have that. Add the missing guard that was accidentally
dropped in the rewrite.

Also explicitly filter out non-A2DP/BAP codecs that can't be used in
ensure_media_codec
2025-06-19 12:03:13 +00:00
Pauli Virtanen
7f2bdab8ea bluez5: fix some coverity issues
Missing null pointer checks, wrong array indices, uninitialized/unused
variables.
2025-06-14 14:34:55 +03: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
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
592a97a7b0 bluez5: keep BAP endpoint properties in spa_bt_remote_endpoint
Make QoS, Context etc. always up to date in spa_bt_remote_endpoint.
2025-06-13 22:16:03 +00:00
Pauli Virtanen
6e0970c14b bluez5: simplify codec switch code
Simplify codec switching code: determine what switch to perform
immediately in spa_bt_device_ensure_media_codec().

The previous code doing "fallback" switching to various codecs is not
useful, as A2DP generally disconnects on the first failure and all
remote endpoints disappear.

Add iteration over multiple endpoints, for reconfiguring both source and
sink directions at the same time.  This is in preparation of supporting
BAP reconfiguration (for A2DP there's usually only one direction
connected at a time).
2025-06-13 22:16:03 +00:00
Pauli Virtanen
52fc22a76b bluez5: make sure mandatory codecs are always enabled
It should not be possible to disable mandatory codecs: csvd, sbc, lc3
2025-06-13 17:51:16 +00:00
Pauli Virtanen
83f6d719b1 bluez5: remove HFP codec id from transports
Make HFP codec id backend/codec internal detail. Remove
spa_bt_transport::codec field which is now unused.
2025-06-13 17:51:16 +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
62bec49c27 bluez5: add spa_bt_get_hfp_codec() / spa_bt_get_media_codecs()
These are for HFP backends to get media codecs.
2025-06-13 17:51:16 +00:00
Pauli Virtanen
4e0d0c5f0b bluez5: replace codec->bap/asha flags with codec->kind enum
Indicate codec type with enum instead of bool flags.  This is in
preparation of moving also HFP to media codecs.
2025-06-13 17:51:16 +00:00
Sam James
2cec77e7df *: unify config.h handling
config.h needs to be consistently included before any standard headers
if we ever want to set feature test macros (like _GNU_SOURCE or whatever)
inside. It can lead to hard-to-debug issues without that.

It can also be problematic just for our own HAVE_* that it may define
if it's not consistently made available before our own headers. Just
always include it first, before everything.

We already did this in many files, just not consistently.
2025-05-30 10:24:13 +00:00
Pauli Virtanen
897748759e bluez5: update timestamping code to match kernel & bluez
Update code to match the final version landed in mainline Linux 6.15
2025-05-17 10:51:37 +00:00
Sanchayan Maity
a5a6973472 bluez5-dbus: Fix another build failure on 32-bit system 2025-05-09 07:09:26 +00:00
Sanchayan Maity
42b9b0eb4c bluez5-dbus: Fix the audio channel position for ASHA
For stereo to work, we need to advertise the channel position based on
whether the side is left or right.
2025-05-07 18:29:01 +05:30
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
8120493edb bluez5-dbus: Track ASHA HiSyncId & Side information in transport
ASHA devices with the same HiSyncId are a pair and this
will be used later on to set them up together with a
combine sink like device set for BAP. Side information
is required for channel information when setting up the
combine sink.
2025-05-05 07:43:34 +00:00
Pauli Virtanen
0d61cc1b1d bluez5: use kernel-provided RX timestamps
Use kernel-provided packet reception timestamps to get less jitter in
packet timings. Mostly matters for ISO/SCO which have regular schedule.

A2DP (L2CAP) doesn't currently do RX timestamps in kernel, but we can as
well use the same mechanism for it.
2025-04-21 10:22:50 +00:00
Pauli Virtanen
081116906d bluez5: bap: allow configuring server locations/context
Add configuration options for the BAP/PACS sink and source endpoint
location (= channel positions) and context settings.

Although BlueZ associates these with individual endpoints, in the PACS
spec they are actually device-global, so configure directly in monitor
settings.
2025-04-20 20:34:35 +03:00
Pauli Virtanen
e9dae61cca bluez5: simplify BAP settings parsing and use device settings for them
Parse BAP settings in a single place, and simplify QoS customization a
bit.

Ensure the selected preset gets selected.

For all the BAP codec settings, use device settings instead of global
monitor ones.
2025-04-14 07:26:28 +00:00
Vinit Mehta
55372a41b1 bluez5: Add support to select BAP QoS config
The current BAP QoS configuration allows to register a sampling
frequency based on the configuration done using wireplumber configuration.
However, for a scenario were the user need to use a specific SDU framelength
it cannot be done as the select_bap_qos function selects the QOS based on
priority and hence it will use the best possible config rather than the user
configured.

This PR adds option to select the QoS set based on user configured value. If
the remote device doesn't have the user configured capabilities it will always
use the best priority config.

Further, this change also allows the user to set RTN, Latency, Delay QoS config
for certain use case to have controller use optimum bandwidth usage.

Below are the example configuration on setting LC3 capabilities in config file:

bluez5.bap.set_name = "48_2_1"
bluez5.bap.rtn = 5
bluez5.bap.latency = 20
bluez5.bap.delay = 40000
bluez5.framing = false
2025-04-14 07:26:28 +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
Sanchayan Maity
23ae55015d bluez5-dbus: Do not setup ASHA profile for unconnected devices
Do not add/connect the profile for unconnected devices.

This fixes the issue where a previously paired ASHA device
would show up in the pavucontrol output device list even
when not connected.
2025-01-27 09:22:41 +00:00
Pauli Virtanen
34ac0d8256 bluez5: support BAP hardware volume
Support BAP HW volume now that it's implemented in BlueZ, with the
volume range 0-255 per spec.
2025-01-25 15:37:52 +00:00
George Kiagiadakis
d0b3c00d29 bluez: enable delay reporting for a2dp-source
This allows our a2dp-source (sink endpoint) to report delay to the
remote source endpoint. Setting the "Delay" property is already
implemented, but by failing to configure DelayReporting, bluez rejects
the property change.
2025-01-21 16:11:08 +00:00
Pauli Virtanen
65f6e5ffa7 bluez5: clean up ASHA transport handling
Don't mix endpoint and transport paths, they're generally different.

If ASHA transport already existed, free the old one but not the device,
as the ASHA device existence should track how it appears in DBus.
2025-01-09 22:15:03 +00:00
Sanchayan Maity
b1e4799ea6 bluez5: Ensure codec_id comparison is against codec of right type
G722 codec id for ASHA is chosen arbitrarily to be different from
A2DP and BAP codec IDs. ASHA spec does not specify a codec ID like
A2DP/BAP.

In places where codec_id comparisons are done, ensure that the check
is done against the codec of the right type viz. A2DP/BAP/ASHA.
2025-01-09 14:51:50 +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
Sanchayan Maity
41d099a580 bluez5: Add G722 codec for ASHA
For documentation on ASHA, see
https://source.android.com/docs/core/connect/bluetooth/asha
2025-01-09 14:51:50 +00:00
Iulia Tanasescu
9a5b2d42f9 bluez5: Configure LC3 codec capabilities
Currently, the PipeWire daemon registers BlueZ LE Media Endpoints
with audio capabilities covering all settings defined in the BAP spec.
However, some scenarios might require the capabilities to be restricted
to specific configurations.

This adds a method to read LC3 codec specific capabilities from the
Wireplumber config file, and provide those settings when registering
Media Endpoint objects with BlueZ. If the values are not present in
the config file, all settings will be used by default.

Below is an example of how to set the LC3 capabilities in the config
file, to support the 16_2 setting from the BAP spec:

bluez5.bap-server-capabilities.rates = [16000]
bluez5.bap-server-capabilities.durations = [10]
bluez5.bap-server-capabilities.channels = [1, 2]
bluez5.bap-server-capabilities.framelen_min = 40
bluez5.bap-server-capabilities.framelen_max = 40
bluez5.bap-server-capabilities.max_frames = 2
2024-12-14 10:57:23 +00:00
Iulia Tanasescu
cb000ad3dc bluez5: Configure sync_factor
For a BAP Broadcast Source endpoint, the QoS sync_factor enables the user
to adjust the Periodic Advertising interval based on the ISO interval
configured for the stream:

PA_Interval = sync_factor * ISO_Interval

Currently, this value is hardcoded to 2. This commit makes the sync_factor
configurable in the Wireplumber config file, along with the other config
parameters for BIGs.
2024-12-14 10:54:38 +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
2847d90b4b bluez5: report latency to rendering when in A2DP sink role
Now that BlueZ supports delay reporting in A2DP sink role, implement
that.

Report value that gives the total latency between packet reception and
audio rendering.

Also make Latency parameter in media-source to be not just a dummy
value.
2024-12-01 20:14:36 +02:00
Pauli Virtanen
656ebcfcbb bluez5: fix handling of multiple transports for same profile
Don't mark a profile disconnected, if it still has active transports.

For BAP, emit device set changed events when transports come and go, so
that the SPA device can reconfigure accordingly.
2024-11-25 21:26:13 +02:00
Pauli Virtanen
8504e58120 bluez5: reduce quirks logspam
There's no need to log quirks every time they are used, it's enough to
log them once when a device connects.
2024-11-04 21:41:24 +02:00
Iulia Tanasescu
b2a70f5933 bluez5: Add support for Broadcast links
This adds support for BAP Broadcast transport links.

Unlike unicast, broadcast links are used by a BAP Broadcast Sink
device to link together multiple transports in the same BIG that
the user wants to start receiving audio from. Each transport is
associated with a different BIS, so each one has a different fd.
Thus, each link needs to be acquired and released separately.
2024-10-28 17:57:44 +00:00
Pauli Virtanen
f89d42b8bc bluez5: fix crash with broadcast sinks 2024-10-12 11:03:21 +00:00
Wim Taymans
cd81b5f39a spa: add spa_json_begin_array/object and relaxed versions
Add spa_json_begin_array/object to replace
spa_json_init+spa_json_begin_array/object

This function is better because it does not waste a useless spa_json
structure as an iterator. The relaxed versions also error out when the
container is mismatched because parsing a mismatched container is not
going to give any results anyway.
2024-09-16 09:50:33 +02:00
Vlad
308a93bd14 bluez5: Update default sync_factor
Due to the how the kernel part of BlueZ computes the extended
advertising interval for a Broadcast Source, a sync_factor smaller
than 2 will result in an invalid interval value (too small).
2024-07-28 13:45:45 +00:00
Vlad Pruteanu
88d9d58333 bluez5: bap: Rework broadcast code length check
Co-authored-by: P V <pav@iki.fi>
2024-06-20 21:06:32 +00:00
Vlad Pruteanu
4c1271805e bluez5: bap: Fix parsing of broadcast code
This fixes the endianness of the parsed broadcast code. It also
fixes pontetial out-of-bouns write by using a bigger, temporary
bcode string, then, after checking it's length, copying it's content
to big_entry->broadcast_code.
2024-06-20 21:06:32 +00: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
Vlad Pruteanu
1466d0ae78 bluez5: bap: Use a string instead of int array to set Broadcast code
Currently, the user sets the Broadcast Code via an array of integers
in the config file. However, the Bluetooth Core Specification indicates
that it should be set via a 16 byte string. This commit replaces the old
implementation with the one required by the spec.

Tested the commit with the example provided in the Core Spec:
Broadcast Code: Børne House
Result from btsnoop log:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
...
Broadcast Code[16]: 000000006573756f4820656e72b8c342

The result matches the example given in the spec.
2024-06-14 06:05:14 +00:00
Vlad Pruteanu
34b17a6269 bluez5: bap: Enable control of Broadcast Encryption
Add "encryption" parameter to bluez5.bcast_source.config entry in
the configuration file. This allows the user to control the use of
Broadcast encryption.
2024-06-11 07:17:17 +00:00