Commit graph

107 commits

Author SHA1 Message Date
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
Barnabás Pőcze
f5d51162c4 treewide: mark things static and const
Mark some structures, arrays static/const at various places.
In some cases this prevents unnecessary initialization
when a function is entered.

All in all, the text segments across all shared
libraries are reduced by about 2 KiB. However,
the total size increases by about 2 KiB as well.
2021-06-30 14:44:08 +02:00
Huang-Huang Bao
4c9ac08310 bluez5: always emit node object info for dynamic node
impl_add_listener() could be called more than one time, ensure that we always emit node info
so that session manager(bluez-monitor) can receives it.

Fixes #1308
2021-06-17 07:22:46 +00:00
Huang-Huang Bao
c7cac40e03 bluez5: init node soft volumes to 1.0f 2021-06-03 07:17:41 +00:00
Huang-Huang Bao
f92a5b3bbd bluez5: emit node volume and mute right after bluez5 node creating
bluez5 nodes will always be removed & created again during profile changing, hence
node volume & mute will always be reset. This is OK if profile did changed, because
session manager would carries volume & mute to bluez5 route param. But if profile
was not changed after setting profile (a2dp-sink-sbc -> a2dp-sink -> a2dp-sink-sbc),
session manager would think node volume & mute are not changed and no route
setting is performed, causing route volume out of sync with node volume.

To fix this, we emit node volume and mute right after bluez5 node is created.

Fixes #1254
2021-06-03 07:17:41 +00:00
Huang-Huang Bao
27433c4000 bluez5: clean up node volume emitting
The problem described in previous 'volume_changed()' has been fixed
in 5bf2144438, hence we don't need
that workaround anymore.
2021-06-03 07:17:41 +00:00
Wim Taymans
46ef88e520 spa: save the old change_mask and restore when emitting full
When we add a new listener to an object, it will emit the full state
of the object. For this it temporarily sets the change_mask to all
changes. Restore the previous state after this or else we might not
emit the right change_mask for the next listener.

Consider the case where one there are two listeners on an object.
The object emits a change and the first listener wants to enumerate the
changed params. For this is adds a new listener and then triggers the
enumeration. If we set the change_mask to 0 after adding the listener,
the second listener would get a 0 change_mask and fail to update
its state.
2021-05-27 15:21:44 +02:00
Peter Hutterer
7697ed0757 treewide: replace strcmp() == 0 with spa_streq()
This change is only done in source files for now, header files will be done
separately.
2021-05-18 22:10:27 +10:00
Huang-Huang Bao
03cde9751b
bluez5: guard against device profile
Invalid device profile should not be set.
2021-05-11 19:22:42 +08:00
Huang-Huang Bao
0c102b3e33
bluez5: emit SPA_PROP_softMute when route mute changed
Fixes #1137
2021-05-04 01:11:14 +08:00
Andrea Gelmini
47ef2b6b09 Fix typos 2021-04-30 07:40:20 +00:00
Wim Taymans
5bf2144438 spa: improve volume handling
Make a new softVolume property that contains only the soft volume
to apply.

In the case of HW/SW volume, we pass the real volume in the
channelVolume and the leftover volume in softVolume. We don't
use the monitorVolume for this anymore because it is a completely
separate volume handled by the merger node.

This way, channelVolume always represents the effective volume
set on routes, channelmix and merger and only the softVolume (when
available) is applied as software volume by channelmix.

This makes things map a bit better to what is actually happening with
the real volume and leftover software volumes after applying the
hardware volumes in the device.

With this change, the volume on the monitor is not affected by the
sink volume anymore and we can use the monitorVolume for this later.

This also means that the monitor volume in pavucontrol of the sinks
does not change when the sink volume changes. PulseAudio is inconsistent
here: If the volume is HW, the monitor volume is not affected, if the
volume is SW, it is. In PipeWire there is an option in merger to
let the volume affect the monitor with monitor.channel-volumes = true.
2021-04-29 12:46:29 +02:00
Huang-Huang Bao
8129b6658e bluez5: rename 'bluez5.reconnect-profiles' property to 'bluez5.auto-connect'
Avoid confusion with 'ReconnectUUIDs' in bluez policy config. See #1081.
2021-04-22 07:36:47 +00:00
Huang-Huang Bao
f44d00424f bluez5: don't clear dynamic node flag from node id in volume changed handler
It causes transport state handler don't emit node removing info.
Fixes #1080.
2021-04-22 07:34:02 +00:00
Huang-Huang Bao
01f2c91b89 bluez5: fix HSP HS profile enumeration
HSP don't supports codec switching.
2021-04-21 08:58:48 +00:00
Huang-Huang Bao
98d1a3cb16
bluez5: improve bluetooth profile descriptions, make them more translatable 2021-04-18 16:53:45 +08:00
Huang-Huang Bao
edee633f96
bluez5: add property to enable hardware volume control 2021-04-17 19:35:46 +08:00
Huang-Huang Bao
80f6ddf526
bluez5: add hardware volume support
Add necessary apis to bluez transport.
Add A2DP(AVRCP) absolute volume support. Source volume can only update to adapter node but not from due to AG nodes don't have route.
Since A2DP/HSP/HFP volume is already percentage itself, it has been mapped to pulseaudio volume then converting to linear volume.
2021-04-17 19:07:35 +08:00
Wim Taymans
036c54b043 Add i18n support for some more user-visible strings 2021-04-15 17:56:40 +02:00
Dmitry Sharshakov
97b01ed9b0 bluez5: add a property to select default profile 2021-04-04 08:43:09 +00:00
Wim Taymans
f0ab2bc1db bluez5: pass the route save property around
So that volumes are saved by the session manager.

Fixes  #995
2021-03-30 16:31:17 +02:00
Pauli Virtanen
f330446291 bluez5: better error/malformed input handling
Safer parsing of AT commands, additional null and error checks.
2021-03-27 14:38:31 +00:00
Huang-Huang Bao
bd7dba617f
bluez5: fix SPA_PROP_bluetoothAudioCodec param prop setting
Remove 'const' from 'codec_id' declaration.
2021-03-27 09:27:33 +08:00
Pauli Virtanen
51b0248d09 bluez5: update a2dp codec list when remote endpoints change 2021-03-26 16:59:07 +00:00
Pauli Virtanen
a552655edc bluez5: add bluetoothAudioCodec property to device
Also make the "codecless" profiles to automatically switch to the codec
profiles.
2021-03-26 16:59:07 +00:00
Huang-Huang Bao
34c9f24d2a bluez5: autoconnect device profiles on startup
Auto-connect all paired & trusted devices on startup.
Since devices that already connected or powering off would reject the connecting requests, it should be fine with this behavior.
Also reconnect remaining profiles if only partial profiles are connected.
2021-03-26 14:15:55 +00:00
Wim Taymans
fc44013d17 device: place the number of routes in the nodes
So that we can know if this node has routes or not.
Nodes without routes might need their volumes restored directly
with the node properties, like streams. Nodes with a route need their
volumes set on the device managing the node.
2021-03-22 16:43:54 +01:00
Pauli Virtanen
132786c202 pulse-server: implement send_object_message
Use it for providing Bluez codec listing/switching interface.  It
currently works by just switching device profiles.
2021-03-20 23:30:38 +02:00
Pauli Virtanen
b7a1f11842 bluez5: check profile existence before listing in routes
Check profile existence before listing in routes, since it depends on
codec availability that may vary.
2021-03-20 20:01:52 +00:00
Pauli Virtanen
79e098bdf2 bluez5: implement HFP codec switching
Implement switching HFP codecs in bluez5-devices, currently only for
backend-native.

Codecs are exposed via profiles similarly as for A2DP.

Some hardware appears to not properly reply to the +BCS message. Catch
these cases with a timeout, in which case we fall back to previously
existing transports.
2021-03-20 20:01:52 +00:00
George Kiagiadakis
bca9e55d12 bluez: add a new "Audio Gateway" device profile
This profile is meant to be used with audio gateways, such as mobile
phones, making pipewire act as a headset. It activates all 3 "dynamic"
nodes (all of which are "Stream/*/Audio"), allowing both A2DP source
and HSP/HFP AG to be available at the same time. Ultimately, the remote
device (the AG), is the one that decides which profile to use and pipewire
just creates/destroys the appropriate stream nodes dynamically.

To make things less confusing, the HFP/HSP profile is now only available
if the remote device is a Head Unit and the A2DP profile is only available
if the remote device has an A2DP Sink.

If the device has both A2DP Source & A2DP Sink (not sure if this is a real world
possibility, but just in case...), the A2DP profile allows using them both,
while the AG profile will only allow the source.

In addition, to keep things less complex, the routes are now only used for
device nodes (the "Audio/*" ones). A2DP source and HSP/HFP AG never have a route.
Restoring their props should be possible to be handled by the restore-stream
module.
2021-03-19 20:27:49 +02:00
George Kiagiadakis
34425a8027 bluez: make sco nodes dynamic when the remote end is an AG 2021-03-19 11:49:41 +00:00
Wim Taymans
8a4d2ed7ce pipewire-pulse: set correct errno values
errno should be set to the positive errno value.

This does not cause problems except for the pulse-server where the
errno value is negated and returned as an error result.
2021-03-19 12:46:05 +01:00
George Kiagiadakis
a75fe69c8e bluez5: emit & remove the A2DP source node depending on transport state
Typically a source stops the connection when it has nothing to play
and this causes the transport to become "idle" and our A2DP source
also stops. However, the node is still present and "running" (if linked),
which causes the graph to underrun as it receives no data from this node.

This patch dynamically creates and destroys the a2dp source node depending
on the transport state. So, when the transport is idle, there is no node
in the graph at all.
2021-03-18 14:34:27 +00:00
Huang-Huang Bao
374180e211 bluez5: pass per-device settings to codec handler, make 'bluez5.sbc-xq-support' a per-device setting 2021-03-16 10:31:08 +00:00
Huang-Huang Bao
af8272fe08 bluez5: create device handle before profile negotiation started so that profile handler can retrieve per-device settings 2021-03-16 10:31:08 +00:00