Commit graph

256 commits

Author SHA1 Message Date
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
Pauli Virtanen
ea5ff6b3c1 bluez5: more informative warning with unknown transports
Unknown transports visible in DBus usually belong to a different
sound server instance that is talking to BlueZ.

Explain this in the warning message that we log, so that people can more
easily understand why things are not working.
2024-01-14 10:57:56 +00:00
Pauli Virtanen
d487dc0fc6 bluez5: bap: support ChannelAllocation parameter from BlueZ
For multi-ASE configurations, BlueZ does the channel allocation itself,
and passes us the result in the ChannelAllocation parameter.

If it is present, don't do the allocation ourselves but use that value
instead.
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
f327ed845f bluez5: add some debug to bap-codec-lc3
We don't want to dump on all calls to codec_select_config, so use debug
context.
2023-11-23 17:47:55 +00:00
Pauli Virtanen
43af0645b7 bluez5: set BAP QoS RTN correctly
Set QoS RTN according to values supported by server values.
2023-11-14 22:08:23 +02:00
Pauli Virtanen
b2e58198cc bluez5: make iso_io ISO groups transport-specific
Different BT adapters have separate ISO groups, so we should schedule
them separately.
2023-11-12 18:22:15 +02:00
Silviu Florian Barbulescu
e1fd73da66 Fix set state not seated on linked transport 2023-11-08 10:10:17 +02:00
Pauli Virtanen
b7e863b8cf bluez5: fix logic error in device set leader selection
Fix device set node sometimes not being emitted.

When leader changed it marked no-one as leader, do that in less buggy
way.
2023-10-24 19:45:03 +03:00
Pauli Virtanen
528c7c0f22 bluez5: set BAP Locations/Context endpoint properties
BlueZ now requires endpoints to set Locations/Context, so set them to
some sensible default values. These could in principle be made
configurable later.
2023-10-21 13:38:27 +03:00
Pauli Virtanen
e71cf62b69 bluez5: adapt to further BAP API changes in BlueZ
BlueZ master BAP API is changing, so match our code to that.
2023-10-04 18:36:34 +03:00
Pauli Virtanen
bfcbeccec2 bluez5: adapt to changes in BlueZ BAP API
BlueZ master branch now puts various QoS fields into a separate dict, in
properties and method input and return values.

Adjust our code to match that.
2023-09-30 18:13:30 +00:00
Barnabás Pőcze
436787d6ba treewide: try to use const char * for string literals 2023-09-16 17:47:35 +02:00
Pauli Virtanen
2804a8f1f6 bluez5: minor BAP broadcast fixups
Don't try to deref NULL if adapter not found. Disable bcast reconnect in
simpler way. Use adapter name as device name. Style fixes.
2023-09-13 15:51:50 +00: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
b07bb4e106 Check if the adapter supports bap broadcast before registering the broadcast endpoint. 2023-08-24 16:31:03 +00:00
Silviu Florian Barbulescu
e2fa5537f7 Add support for bluez5.roles for broadcast source. 2023-08-24 16:31:03 +00:00
Silviu Florian Barbulescu
decbeed2c4 Create the fake device with the actual adapter DBus path. 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
8f6d266632 bluez5: reacquire transport always for playing for A2DP
Some A2DP devices don't like reusing the same transport for different
media-sink instances, possibly because encoder is reset in between and
there can be a gap in transmitted audio.

This doesn't matter for SCO/ISO.
2023-08-18 15:07:01 +00:00
Barnabás Pőcze
4083502e03 spa: bluez: use some more spa_auto* 2023-07-30 13:45:49 +02:00
Barnabás Pőcze
ca85872e83 spa: bluez: use spa_auto for DBusError 2023-07-30 13:45:49 +02:00
Barnabás Pőcze
b52d590936 spa: bluez: add send_with_reply() dbus helper
This function sends a DBusMessage on a DBusConnection
and sets the reply callback of the resulting DBusPendingCall,
as well as properly cancelling the pending call if anything fails.
2023-07-30 13:45:49 +02:00
Barnabás Pőcze
6e581deb91 spa: bluez: use spa_autoptr for DBusMessage 2023-07-30 13:45:49 +02:00
Barnabás Pőcze
708e5443ae spa: bluez: add steal_reply_and_unref() helper
This function retrieves the reply from a DBusPendingCall and unrefs the call.
2023-07-15 01:04:23 +02:00
Barnabás Pőcze
183270f53c spa: bluez: add cancel_and_unref() dbus helper
This function cancels and unrefs a DBusPendingCall and
resets the pointer to NULL.
2023-07-15 01:04:22 +02:00
Barnabás Pőcze
33a5c4ba10 spa: bluez: fix spelling of HAVE_REALLOCARRAY feature macro
It should have two `R`s not three.
2023-07-14 18:20:07 +02:00
Barnabás Pőcze
abe8c3581f spa: bluez: free spa_bt_transport::configuration
`spa_bt_transport_free()` did not free `spa_bt_transport::configuration`,
so fix that.
2023-07-13 21:27:53 +02:00
Barnabás Pőcze
6275269f09 spa: bluez: remove some unused variables 2023-07-03 19:40:31 +02:00
Barnabás Pőcze
f6ea5421e6 spa: bluez: do not open-code asprintf() 2023-07-03 19:40:31 +02:00
Barnabás Pőcze
605404c781 spa: bluez: device_stop_timer(): remove redundant decl
Also move the declaration of `media_codec_switch_free()`
up to the beginning of the file, near the other decls.
2023-07-03 19:40:31 +02:00
Pauli Virtanen
7aae8c45ec bluez5: do not delay transport release if it is not active
Transport release should not be delayed if it is not active, since the
fd cannot be used any more, and the transport needs to be reacquired to
get a working fd.

Fixes reacquiring transports if the remote side causes them to become
inactive.
2023-05-26 07:17:51 +00:00
Pauli Virtanen
1d23d21ffe bluez5: check if we have any codecs before trying to register
Don't try to register A2DP / BAP with BlueZ if we don't have any codecs
for that.
2023-05-18 14:36:16 +03:00
Barnabás Pőcze
4d5f3620af spa: bluez: initalize DBusError object
The DBusError passed to `dbus_set_error_from_message()` must
be initialized, otherwise libdbus aborts:

  dbus[129473]: arguments to dbus_set_error_from_message() were incorrect,
                assertion "(error) == NULL || !dbus_error_is_set ((error))"
                failed in file dbus-message.c line 4043.
  This is normally a bug in some application using the D-Bus library.
2023-05-03 11:27:25 +00:00
Pauli Virtanen
04951ac15f bluez5: make set transport volume calls async
The transport set volume call may take a long time or never complete, so
make them async to not block main loop.

Also reduce log level to info for the failed volume setting, as this is
something the user can do nothing about.
2023-04-30 18:44:33 +03:00
Pauli Virtanen
9c788d0c7e bluez5: unref pending calls after cancel
Cancel doesn't decrease refcount, so needs unref too.
2023-04-30 18:38:30 +03:00
Pauli Virtanen
420f7cb48e bluez5: select BAP audio locations in SelectProperties
Do BAP audio location selection properly in SelectProperties, now that
BlueZ provides the supported locations there. Remove a previous
workaround.

The audio location in SelectProperties determines the audio channel
allocation, which determines the channel positions.
2023-04-25 21:44:38 +03:00
Pauli Virtanen
9d7d3599db bluez5: output silence if no data for some ISO sinks
When a sink contributing to an ISO CIG does not have data, output
silence for it, as long as at least one sink in the CIG is running.
Only if writes to sockets fail, pause all streams to reset
synchronization.

This way we write exactly the same number of packets for each CIS at the
same time, which probably is the best tested configuration in BT
adapters and devices. We also don't then have to pause output if some
sinks are not running or miss their timing, as we generate silence on
the fly.

When using iso-io, have it initialize the codec instance, and have
media-sink uses that instance, so that silence and actual audio are
encoded with the same codec.
2023-04-14 22:29:03 +03:00
Pauli Virtanen
2d1b02b5a2 bluez5: wait for all pending transports in CIG before marking active
Mark transports in CIG active only after all acquires are completed, so
that all iso-io are present before sinks are started.
2023-04-14 22:29:01 +03:00
Pauli Virtanen
645822b30b bluez5: refresh device set leader when current one disconnects 2023-04-12 10:12:00 +00:00