Differences between revisions 1 and 34 (spanning 33 versions)
Revision 1 as of 2013-06-03 11:32:42
Size: 1327
Editor: ?JavierRodriguez
Comment:
Revision 34 as of 2021-11-06 20:24:23
Size: 9586
Comment: Add a warning to the PipeWire section after I received an email mentioning that gnome-core depends on pulseaudio-module-bluetooth. Also remove DebianExperimental reference now that it's in testing.
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
A2DP is the technology that allows connecting high quality audio bluetooth devices to your system. #language en
~-[[DebianWiki/EditorGuide#translation|Translation(s)]]: none-~
----
A2DP is the "Advanced Audio Distribution Profile", a standard for how Bluetooth devices can stream high-quality audio to remote devices. This is most commonly used for linking wireless headphones and speakers to your PC. The instructions in this page should apply to any A2DP-compatible device.
Line 3: Line 6:
== Packages == <<TableOfContents>>
Line 5: Line 8:
To connect your headphones, you need a working host device, and the following packages: == Pre-configuration ==

In short: To connect to a given device, you need Bluetooth hardware on your PC (either built-in, or in the form of a USB dongle), the Bluez daemon, and a compatible audio server (either PulseAudio or PipeWire).

=== Firmware ===
If your hardware supports Bluetooth but Debian is unable to find any Bluetooth devices, you may have a dongle based on a Broadcom BCM203x chipset, requiring extra firmware to be installed.

Add a non-free component to your [[SourcesList|apt sources]] and install the DebianPkg:bluez-firmware package.

=== PulseAudio ===
PulseAudio is the default audio server in Debian. Unless you know what you're doing, you probably want to follow these instructions.

Install the DebianPkg:pulseaudio-module-bluetooth package if it's not already installed. You probably also want DebianPkg:pavucontrol (or DebianPkg:pavucontrol-qt on LXQt or Plasma desktops) to configure your device after connecting it.

Once you have installed the Bluetooth module, it may be necessary to restart the bluetooth and pulseaudio services:
Line 8: Line 25:
apt-get install pulseaudio pulseaudio-module-bluetooth bluez-audio pavucontrol bluez-firmware bluez-tools # service bluetooth restart
$ killall pulseaudio
Line 11: Line 29:
It is also highgly recommended to install a graphical pairing tool. '''bluetooth-agent''' is already included with gnome, but you can also use '''blueman'''. After connecting your device (see the "Pairing" section), your device will appear in Pavucontrol, where you can set it as your default audio output device, change individual applications to output using it, configure its profile, etc.
Line 13: Line 31:
Don't forget to restart bluetooth service: === PipeWire ===
These instructions are mutually exclusive to the !PulseAudio section, for users
that are using the newer PipeWire audio server instead. This is also documented on
the !PipeWire wiki page in brief. Note that simply having the DebianPkg:pipewire
package installed does not mean this section is relevant to you, as it needs to
have also been specially configured to replace !PulseAudio.
Line 15: Line 38:
{{{
service bluetooth restart
}}}
In Debian, !PipeWire supports more modern codecs than !PulseAudio without the need to install any external modules. In particular, !PipeWire 0.3.26 supports mSBC, SBC, SBC-XQ, LDAC, AptX, and AptX-HD. It also supports the HSP_HS, HSP_AG, HFP_HF, and HFP_AG headset roles. Support for more codecs is in-progress.
Line 19: Line 40:
At minimum, you will need to install the [[DebianPkg:libspa-0.2-bluetooth]] package, remove the DebianPkg:pulseaudio-module-bluetooth package (if previously installed), and then either reboot your computer or restart the !PipeWire services, otherwise device connections will fail with "Protocol not available".

Note that, if you're using the GNOME desktop, the DebianPkg:gnome-core package
has a hard dependency on pulseaudio-module-bluetooth. Attempting to
remove it will also prompt to remove your desktop. If you run into issues when
attempting to use Bluetooth with this package installed, you may still have to
use !PulseAudio in order to have functioning Bluetooth audio.

!PipeWire will attempt to choose the best possible codec by default. You can override this, and tweak many other related settings, in the {{{/etc/pipewire/media-session.d/bluez-monitor.conf}}} file. You can edit this directly, or store local per-user changes by copying the file to {{{~/.config/pipewire/media-session.d/bluez-monitor.conf}}} and editing that instead. You can check the currently-used codec with {{{pactl list sinks}}}

=== ALSA only ===
If you want to completely avoid using a higher-level audio server like !PipeWire or !PulseAudio, see [[Bluetooth/Alsa|BlueALSA]]. Currently only available in Debian Unstable.

----
Line 22: Line 57:
Pair your device as usual and give it the "trust" attribute. It is also highly recommended to install a graphical pairing tool. GNOME relies on DebianPkg:gnome-bluetooth, after which you can find a "Bluetooth" section of your settings. KDE Plasma relies on DebianPkg:bluedevil, which is a module for your system settings, a system tray applet, and a wizard for connecting to your devices. Other desktops can use the agnostic DebianPkg:blueman tool.
Line 24: Line 59:
== Configuring == More information, and instructions on using the CLI {{{bluetoothctl}}} tool, can be found on the main BluetoothUser page.
Line 26: Line 61:
Using '''pavucontrol''', it is really easy to setup a2dp for your device, and map connections to it. Your paired headphones should appear as an option to output audio. ----
Line 28: Line 63:
Don't forget to put it in high quality mode (a2dp) in the configuration tab. This is necessary for some devices that have mixed mode. == Troubleshooting ==
Line 30: Line 65:
If you prefer to use the command line, just do: === Refused to switch profile to a2dp_sink: Not connected ===

Your Bluetooth headset is connected, but PulseAudio fails to pick up the connected device, or there's no device to pick. This happens because GDM captures A2DP sink on session start, as GDM needs !PulseAudio in the GDM session for accessibility. For example, the screen reader requires it. See [[DebianBug:805414]] for some discussion.

==== Workaround 1: Disable PulseAudio in GDM ====

In order to prevent GDM from capturing the A2DP sink on session start, edit ''/var/lib/gdm3/.config/pulse/client.conf'' (or create it, if it doesn't exist):
Line 33: Line 74:
bt-audio -c 00:02:3C:38:AC:B9 autospawn = no
daemon-binary = /bin/true
Line 36: Line 78:
Where ''00:02:3C:38:AC:B9'' is the address of your paired device. After that you have to grant access to this file to '''Debian-gdm''' user:
Line 38: Line 80:
== Compatible devices == {{{
chown Debian-gdm:Debian-gdm /var/lib/gdm3/.config/pulse/client.conf
}}}
Line 40: Line 84:
Any A2DP device should work out of the box. You may also need to disable !PulseAudio startup (however in Debian 10/Buster and newer, this has already been removed in the gdm3 postinst):
Line 42: Line 86:
If you still didn't bought one, the Creative WP-300 works very well and has a very very nice sound. {{{
rm /var/lib/gdm3/.config/systemd/user/sockets.target.wants/pulseaudio.socket
}}}

In order to auto-connect A2DP for some devices, add this to '''/etc/pulse/default.pa''':

{{{
load-module module-switch-on-connect
}}}

Reboot.

Now your audio device should be accessible through '''pavucontrol''' and your desktop's standard audio settings.

==== Workaround 2: Disable PulseAudio's Bluetooth in GDM ====

The actual solution package maintainers are looking into next is to simply disable the Bluetooth sink in the GDM !PulseAudio daemon so that it doesn't take over the device. Add this to `/var/lib/gdm3/.config/pulse/default.pa`:

{{{
#!text
#!/usr/bin/pulseaudio -nF
#

# load system wide configuration
.include /etc/pulse/default.pa

### unload driver modules for Bluetooth hardware
.ifexists module-bluetooth-policy.so
  unload-module module-bluetooth-policy
.endif

.ifexists module-bluetooth-discover.so
  unload-module module-bluetooth-discover
.endif
}}}

This was first discovered in the [[https://wiki.archlinux.org/index.php/Talk:Bluetooth_headset#GDMs_pulseaudio_instance_captures_bluetooth_headset|Arch wiki]].

==== Solution ====

The actual solution is for !PulseAudio to release the Bluetooth device when it is not in use. This is discussed in the !PulseAudio DebianBug:845938 which has a few upstream bugs pending as well that are related.

=== Unable to control volume with volumeicon-alsa ===

The volumeicon tray icon may not automatically recognize a Bluetooth A2DP device when a connection is established. See [[https://github.com/Maato/volumeicon/issues/73|issue #73, "volumeicon does not work to adjust bluetooth volume"]] and [[https://github.com/Maato/volumeicon/issues/49|issue #49, "change of the default device not automatically detected"]] for discussion and possible workarounds / fix. You might also try simply restarting Volumeicon, or adjusting your !PulseAudio configuration to switch on connect.

=== a2dp-sink profile connect failed [...]: Protocol not available ===

This error can appear when using !PipeWire as your audio server and attempting to pair a device via Bluetooth, without first uninstalling the DebianPkg:pulseaudio-module-bluetooth package.


If you're using !PulseAudio, !PulseAudio may not be properly connecting to the device. It might be because it was already playing. Stopping anything playing on !PulseAudio, restarting !PulseAudio, and reconnecting to the device may fix the problem.

In addition, you need the following settings in /etc/pulse/default.pa or /etc/pulse/default.pa.d/bluez5.pa:

{{{
load-module module-bluez5-device
load-module module-bluez5-discover
}}}

Then restart pulseaudio.

=== AptX, LDAC, and AAC codecs are not available with PulseAudio ===

While newer audio codecs such as AptX and LDAC are available in PipeWire, they're still unavailable for !PulseAudio users in Debian. AAC is unavailable outright because the library is non-free. However, !PulseAudio has recently gained support for all of these codecs via GStreamer. Unfortunately, GStreamer is only supporting these codecs from v1.20 onwards. This means that support for modern codecs with !PulseAudio is not available in Debian 10 or Debian 11. It is expected to land in Debian 12.

A third-party project adds support for these additional codecs as well. It is deprecated and the creator recommends users either avoid it entirely, or switch to !PipeWire. Nonetheless, it's still a fully functional option in Debian 10: https://github.com/EHfive/pulseaudio-modules-bt

Additionally, a third-party script for Debian 10 is available which will automatically configure and install the additional codecs via the deprecated pulseaudio-modules-bt project: https://github.com/lagerimsi-ds/debian-buster_bluetooth_aptX-LDAC

If the !PulseAudio sink adjusts automatically to SBC-sink (not A2DP-sink with aptX or LDAC), just reconnect your device.

----

== See also ==
 * [[BluetoothUser]] - Main page for Bluetooth in Debian
 * [[bluedevil|BlueDevil]] - Bluetooth with KDE Plasma
 * [[Bluetooth/Alsa|BlueALSA]] - Bluetooth over ALSA alone

----

CategorySound CategoryWireless

Translation(s): none


A2DP is the "Advanced Audio Distribution Profile", a standard for how Bluetooth devices can stream high-quality audio to remote devices. This is most commonly used for linking wireless headphones and speakers to your PC. The instructions in this page should apply to any A2DP-compatible device.

Pre-configuration

In short: To connect to a given device, you need Bluetooth hardware on your PC (either built-in, or in the form of a USB dongle), the Bluez daemon, and a compatible audio server (either PulseAudio or PipeWire).

Firmware

If your hardware supports Bluetooth but Debian is unable to find any Bluetooth devices, you may have a dongle based on a Broadcom BCM203x chipset, requiring extra firmware to be installed.

Add a non-free component to your apt sources and install the bluez-firmware package.

PulseAudio

PulseAudio is the default audio server in Debian. Unless you know what you're doing, you probably want to follow these instructions.

Install the pulseaudio-module-bluetooth package if it's not already installed. You probably also want pavucontrol (or pavucontrol-qt on LXQt or Plasma desktops) to configure your device after connecting it.

Once you have installed the Bluetooth module, it may be necessary to restart the bluetooth and pulseaudio services:

# service bluetooth restart
$ killall pulseaudio

After connecting your device (see the "Pairing" section), your device will appear in Pavucontrol, where you can set it as your default audio output device, change individual applications to output using it, configure its profile, etc.

PipeWire

These instructions are mutually exclusive to the PulseAudio section, for users that are using the newer PipeWire audio server instead. This is also documented on the PipeWire wiki page in brief. Note that simply having the pipewire package installed does not mean this section is relevant to you, as it needs to have also been specially configured to replace PulseAudio.

In Debian, PipeWire supports more modern codecs than PulseAudio without the need to install any external modules. In particular, PipeWire 0.3.26 supports mSBC, SBC, SBC-XQ, LDAC, AptX, and AptX-HD. It also supports the HSP_HS, HSP_AG, HFP_HF, and HFP_AG headset roles. Support for more codecs is in-progress.

At minimum, you will need to install the libspa-0.2-bluetooth package, remove the pulseaudio-module-bluetooth package (if previously installed), and then either reboot your computer or restart the PipeWire services, otherwise device connections will fail with "Protocol not available".

Note that, if you're using the GNOME desktop, the gnome-core package has a hard dependency on pulseaudio-module-bluetooth. Attempting to remove it will also prompt to remove your desktop. If you run into issues when attempting to use Bluetooth with this package installed, you may still have to use PulseAudio in order to have functioning Bluetooth audio.

PipeWire will attempt to choose the best possible codec by default. You can override this, and tweak many other related settings, in the /etc/pipewire/media-session.d/bluez-monitor.conf file. You can edit this directly, or store local per-user changes by copying the file to ~/.config/pipewire/media-session.d/bluez-monitor.conf and editing that instead. You can check the currently-used codec with pactl list sinks

ALSA only

If you want to completely avoid using a higher-level audio server like PipeWire or PulseAudio, see BlueALSA. Currently only available in Debian Unstable.


Pairing

It is also highly recommended to install a graphical pairing tool. GNOME relies on gnome-bluetooth, after which you can find a "Bluetooth" section of your settings. KDE Plasma relies on bluedevil, which is a module for your system settings, a system tray applet, and a wizard for connecting to your devices. Other desktops can use the agnostic blueman tool.

More information, and instructions on using the CLI bluetoothctl tool, can be found on the main BluetoothUser page.


Troubleshooting

Refused to switch profile to a2dp_sink: Not connected

Your Bluetooth headset is connected, but PulseAudio fails to pick up the connected device, or there's no device to pick. This happens because GDM captures A2DP sink on session start, as GDM needs PulseAudio in the GDM session for accessibility. For example, the screen reader requires it. See 805414 for some discussion.

Workaround 1: Disable PulseAudio in GDM

In order to prevent GDM from capturing the A2DP sink on session start, edit /var/lib/gdm3/.config/pulse/client.conf (or create it, if it doesn't exist):

autospawn = no
daemon-binary = /bin/true

After that you have to grant access to this file to Debian-gdm user:

chown Debian-gdm:Debian-gdm /var/lib/gdm3/.config/pulse/client.conf

You may also need to disable PulseAudio startup (however in Debian 10/Buster and newer, this has already been removed in the gdm3 postinst):

rm /var/lib/gdm3/.config/systemd/user/sockets.target.wants/pulseaudio.socket

In order to auto-connect A2DP for some devices, add this to /etc/pulse/default.pa:

load-module module-switch-on-connect

Reboot.

Now your audio device should be accessible through pavucontrol and your desktop's standard audio settings.

Workaround 2: Disable PulseAudio's Bluetooth in GDM

The actual solution package maintainers are looking into next is to simply disable the Bluetooth sink in the GDM PulseAudio daemon so that it doesn't take over the device. Add this to /var/lib/gdm3/.config/pulse/default.pa:

#!/usr/bin/pulseaudio -nF
#

# load system wide configuration
.include /etc/pulse/default.pa

### unload driver modules for Bluetooth hardware
.ifexists module-bluetooth-policy.so
  unload-module module-bluetooth-policy
.endif

.ifexists module-bluetooth-discover.so
  unload-module module-bluetooth-discover
.endif

This was first discovered in the Arch wiki.

Solution

The actual solution is for PulseAudio to release the Bluetooth device when it is not in use. This is discussed in the PulseAudio 845938 which has a few upstream bugs pending as well that are related.

Unable to control volume with volumeicon-alsa

The volumeicon tray icon may not automatically recognize a Bluetooth A2DP device when a connection is established. See issue #73, "volumeicon does not work to adjust bluetooth volume" and issue #49, "change of the default device not automatically detected" for discussion and possible workarounds / fix. You might also try simply restarting Volumeicon, or adjusting your PulseAudio configuration to switch on connect.

a2dp-sink profile connect failed [...]: Protocol not available

This error can appear when using PipeWire as your audio server and attempting to pair a device via Bluetooth, without first uninstalling the pulseaudio-module-bluetooth package.

If you're using PulseAudio, PulseAudio may not be properly connecting to the device. It might be because it was already playing. Stopping anything playing on PulseAudio, restarting PulseAudio, and reconnecting to the device may fix the problem.

In addition, you need the following settings in /etc/pulse/default.pa or /etc/pulse/default.pa.d/bluez5.pa:

load-module module-bluez5-device
load-module module-bluez5-discover

Then restart pulseaudio.

AptX, LDAC, and AAC codecs are not available with PulseAudio

While newer audio codecs such as AptX and LDAC are available in PipeWire, they're still unavailable for PulseAudio users in Debian. AAC is unavailable outright because the library is non-free. However, PulseAudio has recently gained support for all of these codecs via GStreamer. Unfortunately, GStreamer is only supporting these codecs from v1.20 onwards. This means that support for modern codecs with PulseAudio is not available in Debian 10 or Debian 11. It is expected to land in Debian 12.

A third-party project adds support for these additional codecs as well. It is deprecated and the creator recommends users either avoid it entirely, or switch to PipeWire. Nonetheless, it's still a fully functional option in Debian 10: https://github.com/EHfive/pulseaudio-modules-bt

Additionally, a third-party script for Debian 10 is available which will automatically configure and install the additional codecs via the deprecated pulseaudio-modules-bt project: https://github.com/lagerimsi-ds/debian-buster_bluetooth_aptX-LDAC

If the PulseAudio sink adjusts automatically to SBC-sink (not A2DP-sink with aptX or LDAC), just reconnect your device.


See also


CategorySound CategoryWireless