Commit graph

142 commits

Author SHA1 Message Date
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
Wim Taymans
2f5bba112f spa: Improve PropInfo fields
The PropInfo either has a registered id (and then also a name from the
type-info) or a custom name as a string.
In all cases, the description contains a free form text that clarifies
the property.

Use the description in the stream controls name.
2022-03-30 17:09:08 +02:00
Pauli Virtanen
4bb3ff739a bluez5: keepalive A2DP source / SCO AG dynamic node transports
When acting as SCO AG / A2DP sink, the remote end should decide when to
close the connection.  This does not work currently properly, because
stopping sources/sinks releases the transport, which causes it to go
idle, and which then destroys dynamic nodes.  The sources/sinks should
not cause the transport to be released.

Implement keepalive flag for spa_bt_transport, such that
spa_bt_transport_release does not actually release the transport when
the refcount reaches zero. Set the flag for dynamic nodes when the
transport becomes pending (remote end connects) and unset the flag when
idle (remote end disconnected, or dynamic node removed).
2022-01-31 21:59:39 +02:00
Pauli Virtanen
0a55085b14 bluez5: allow setting initial profile to off
This is useful if the session manager wants to set the profile itself,
and has special handling for the off profile.
2022-01-22 20:01:00 +00:00
Pauli Virtanen
38c8a19d9e bluez5: use save flag in profile
Add SPA_PARAM_PROFILE_save to current profile information, and handle it
properly in set_param and when setting profile.
2022-01-06 16:45:57 +02:00
Pauli Virtanen
effa0ca124 bluez5: adjust codec profile priority ordering
Higher priority for A2DP over HFP/HSP.  Prefer mSBC over CVSD for HFP,
and put A2DP codecs in the order we tell BlueZ to use.

Ensures that picking highest-priority profile gives sensible results
(e.g. does not pick HFP unless input route is required, and prefers A2DP
duplex codecs over HFP).
2022-01-03 15:23:55 +00:00
Sanchayan Maity
81fac5b896 bluez5: Set profile priority in SPA attributes 2021-12-30 18:15:32 +05:30
Pauli Virtanen
58c7caf1bc bluez5: use log topics
Use log topics instead of prepending NAME: to log messages.
2021-10-02 12:46:02 +03:00
Pauli Virtanen
d6509a243d bluez5: fix device.profile setting
Only keys with names starting with "bluez" are passed on to device
settings dict. Rename device.profile to match this.

Also add some debug.
2021-09-30 22:39:34 +03:00
Pauli Virtanen
def45adaec bluez5: fix behavior on HSP/HFP backends with no codec switching
Fix HSP/HFP profile not showing correctly when using hsphfpd/ofono
backends, which don't support codec switching and have no HFP codec
profiles.
2021-09-19 17:41:19 +00:00
Peter Hutterer
e55a5441b8 spa: silence two -Wformat-nonliteral warnings
In one we can duplicate the spa_asprintf call without real drawbacks.

The second one can be split up without losing details. Note that there
is another one in backend-native.c where splitting it up will make the
code harder to understand. The warning for that one remains.
2021-09-07 08:26:54 +10:00
Pauli Virtanen
59d572de09 bluez5: split A2DP codecs to separate SPA plugins
Make easier to package A2DP codecs separately, by splitting each to a
separate SPA plugin.  Adjust the code to not use a global variable for
the codec list.

The A2DP SPA interface API is in the bluez5 private headers, and not
exposed in installed SPA headers, as it's too close to the
implementation.
2021-09-03 20:40:30 +03:00
Pauli Virtanen
ab5fcf4a66 bluez5: boost A2DP duplex microphone volume by 20 dB
There doesn't seem to be a way to control the A2DP duplex microphone
HW volume gain, and devices sometimes have very low mic volumes.

Work around this by boosting the software volume scale by +20 dB.  If it
causes clipping, the user can just reduce the volume to bring SW gain
below 1.0.
2021-08-23 08:17:46 +00:00
Pauli Virtanen
eca37b58a6 bluez5: make room for a2dp duplex channel
Some non-standard A2DP codecs (FastStream/aptX-LL) have "voice duplex
channel" that can be used to provide an A2DP duplex mode.

Add support for duplex channels, accounting for the fact that the two
directions may be encoded with different actual codecs.
2021-08-21 20:00:52 +03:00
Pauli Virtanen
73994feda9 bluez5: allow same codec ID to correspond to multiple endpoints
The codec IDs are user-visible properties.

Some codecs can have multiple endpoints (e.g. different caps struct, or
multiple possible vendor ids), so this detail should not leak to the
user.
2021-08-18 19:55:22 +00:00
Sanchayan Maity
be6824cb15 bluez5-device: Set device intended role for HFP 2021-08-12 18:54:46 +00:00
Wim Taymans
d88e8edd11 avoid shadowing arguments 2021-07-06 17:55:16 +02:00