Commit graph

298 commits

Author SHA1 Message Date
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
Silviu Florian Barbulescu
e4432190f7 Add broadcast sink support for multiple BISes 2024-05-30 13:37:27 +00:00
Silviu Florian Barbulescu
5be2f5e096 Resolve problems found on review 2024-05-27 16:08:36 +00:00
Barnabás Pőcze
625c0f5784 Apply 1 suggestion(s) to 1 file(s)
Co-authored-by: Barnabás Pőcze <pobrn@protonmail.com>
2024-05-27 16:08:36 +00:00
Silviu Florian Barbulescu
1259829ac3 Remove device and transport for broadcast source on interfaces_removed 2024-05-27 16:08:36 +00:00
Silviu Florian Barbulescu
ab87eba149 Add support for the broadcast source multiple BIS implementation in BlueZ. 2024-05-27 16:08:36 +00:00
Diego Viola
7410755c03 Fix typos
found them with codespell.

Signed-off-by: Diego Viola <diego.viola@gmail.com>
2024-05-22 09:19:34 +02:00
Pauli Virtanen
b94d6e53a1 bluez5: use initial SCO RX wait workaround only for USB controllers
Kernel-provided MTU does not work for USB controllers and the correct
packet size to send can be known currently only from RX. So we are
waiting for RX to get it.

The known problem is USB-specific, we shouldn't need the workaround for
other transport types.

Don't wait for POLLIN for non-USB controllers on connect, but ready
things on POLLOUT as usual.

For non-USB controllers, pick some sensible packet sizes to use
initially, before we switch to same size as for RX.
2024-05-18 13:53:45 +03:00
Silviu Florian Barbulescu
bb1c2c3272 Fix review comments, added METADATA_VALUE_MAX_LEN and removed entry_key in configure_bis. 2024-05-15 08:11:50 +00:00
Pauli Virtanen
345131475c bluez5: cleanup bluez5.bcast_source.config parsing
Also fix doc.
2024-05-15 08:11:50 +00:00
Silviu Florian Barbulescu
44d96ed4b9 bluez: on metadata, parse remove the length field, and deduce the length from the value plus type 2024-05-15 08:11:50 +00:00
Silviu Florian Barbulescu
be3e87f485 Add code to fix problem found at review 2024-05-15 08:11:50 +00:00
Silviu Florian Barbulescu
2bff4a9337 bluez: Configure the BlueZ broadcast source
This is the first draft where the configuration is done based on BIS information loaded from the config file.
2024-05-15 08:11:50 +00:00
Pauli Virtanen
5ae0dfb239 bluez5: bap: determine SDU interval from codec frame duration
BlueZ API as BAP Server gives us the ISO interval, instead of the SDU
interval, in the MediaTransport.QoS.Interval property.  They are not
necessarily the same. What we need is the SDU interval.

The SDU interval is the interval between packets the encoder outputs, so
it is determined by the codec configuration, and for LC3 is equal to the
frame duration.

Add codec method get_interval() that returns the correct interval, and
use it in iso-io.
2024-04-01 19:13:01 +03:00
George Kiagiadakis
ddfe3daa22 bluez: print a nicer warning when the bluez service is not available 2024-03-25 14:54:30 +00:00
Pauli Virtanen
31b387f269 bluez5: add per-device option for BAP unicast stream group ID
Add some option to set manually group IDs of unicast streams
of devices.

Intel controllers don't appear to support more than one group at a time,
but in principle this can be done.
2024-02-21 18:22:38 +02:00
Barnabás Pőcze
0b87144d26 spa: bluez: fix whitespaces 2024-02-05 20:01:21 +01:00
Barnabás Pőcze
4aa2e44796 spa: move dbus helpers out of bluez plugin
The file is moved into a new "include-private" directory. This is done
because otherwise adjustments would have to be made to the list of installed
headers, the way include tests currently work and which files are
used for generating documentation.
2024-02-05 13:03:20 +00:00
Pauli Virtanen
0c434e4821 bluez5: reset A2DP codec shared endpoint status on disconnect 2024-02-04 12:57:31 +02:00
Pauli Virtanen
21392d327f bluez5: lowball fallback delay values
Reduce fallback delay values used when BT device doesn't provide the
information itself.

It may be better to have audio late than early, so use values that are
probably close to or below the delays of majority of headsets.
2024-01-28 18:00:04 +02:00
Pauli Virtanen
08819e3d17 bluez5: indicate to LC3 plugin whether endpoint is sink/duplex
The codec can make use of information on whether the endpoint is sink,
and whether there will be both sink and source configured.
2024-01-23 08:40:46 +00:00
Pauli Virtanen
9474030582 bluez5: determine available BAP profiles from remote endpoints
The PAC profile UUIDs do not appear in the UUID list, but are still
useful to know before SelectProperties.

Set them ahead of time based on the visible remote endpoints.
2024-01-23 08:40:46 +00:00
Pauli Virtanen
8eb1f5aa35 bluez5: pick right codec when multiple ones share the endpoint
The "default" codec is the one with fill_caps != NULL, and should be
picked if we don't know which one we are using.

Fixes showing AAC-ELD as supported when it's not, which happened because
it's ordered before the default AAC in the codec list unlike the other
"shared endpoint" codecs.
2024-01-22 22:38:45 +02:00
Adam Marcus
79ee1eaff0 bluez5: add AAC-ELD codec 2024-01-22 14:04:16 +00:00
Pauli Virtanen
89cdf4f6eb bluez5: move no-HFP fast connect checks to better place
Not waiting for HFP when no HFP backend should be checked via
adapter_connectable_profiles in spa_bt_device_check_profiles where the
relevant logic is.

Cleanup by moving the checks there.
2024-01-16 14:29:01 +00:00