A2DP-sink配置文件连接失败

当我使用GNOME时,我的蓝牙设备工作得很好。但现在我已经转移到了i3并使用blueman。当我尝试连接任何耳机时,blueman会抛出异常。
blueman.bluez.errors.DBusFailedError: Protocol not available.

日志中有非常相似的错误:
сен 09 21:00:45 keddad-pc bluetoothd[916]: a2dp-sink profile connect failed for FC:A8:9A:90:B

唯一的解决方法是安装,但它已经安装了。可能是什么原因导致了这个问题?
我尝试添加了
load-module module-bluetooth-policy
load-module module-bluetooth-discover

/etc/pulse/system.pa中的内容修改为Arch Wiki中所述的方式,但是没有解决任何问题。 这个gist也没有帮助。

添加并启用pulseaudio用户也可能有所帮助,请查看https://unix.stackexchange.com/a/721697/221903。 - Japheth Ongeri - inkalimeva
8个回答

运行以下命令:
sudo apt-get install pulseaudio-module-bluetooth
sudo killall pulseaudio
pulseaudio --start    
sudo systemctl restart bluetooth

在我的情况下,我不小心卸载了pulseaudio-module-bluetooth。我重新安装了它并重新启动了系统。谢谢。 - Aravind
1在确认我正在运行pulseaudio而不是pipewire之后,这个方法解决了我在Ubuntu 22.04上的问题。你可以使用pactl info | grep -i "server name"来进行确认。 - Tobias Gierke

我能够根据this的解决方案,在Ubuntu 21.04上解决了相同的问题:
在pulseaudio的/etc/pulse/default.pa配置文件末尾添加module-bluez5-discover。
load-module module-bluez5-discover

重新启动PulseAudio:

killall pulseaudio

1我还不能通过给@mrcll点赞来感谢你,但是你的解决方案在我的Ubuntu 21.04和我的JBL Charge 5.1上完美运行! - Quentin
2这适用于Ubuntu 21.04和WH-1000XM4。 - Nelson Patricio Jimenez
同样适用于Kubuntu 20.04版本。 - BinarSkugga
这在21.10版本对我来说没有起作用。 - Paul A.
我不知道该如何感谢你为我的Ubuntu 20.4所做的工作。 - Mohsen

运行以下命令以适用于Ubuntu 22.101:
sudo apt install libspa-0.2-bluetooth
systemctl --user restart wireplumber

在Ubuntu 22.10上,我的pulseaudio-module-bluetooth不再工作了,但它已经被libspa-0.2-bluetooth替代了。这似乎是由于Ubuntu从PulseAudio切换到PipeWire引起的。

这并没有真正回答问题。如果你有其他问题,可以点击提问来提出。如果你想在这个问题有新的回答时收到通知,你可以关注此问题。一旦你获得足够的声望,你还可以添加悬赏以吸引更多关注。- 来自评论 - David
我重新修改了我的回答,使其更像顶级回答的风格。现在这个回答是否解答了问题? - Daniel T

在我的情况下(Ubuntu 18.04 / Awesome wm),pulseaudio-module-bluetooth也已经安装好了。
运行以下命令来修复权限:
sudo chown -R $USER:$USER $HOME/
sudo apt-get --purge --reinstall install pulseaudio-module-bluetooth alsa-base pulseaudio
mv ~/.config/pulse ~/.config/pulse.old

然后重新启动您的系统。

看起来加载模块出了一些问题。我没真正找到原因,但我让i3在启动时手动加载它们。
将以下行添加到~/.config/i3/config中。
exec --no-startup-id pactl load-module module-bluetooth-policy
exec --no-startup-id pactl load-module module-bluetooth-discover

这取决于所使用的声音系统。对于使用 pipewire(Ubuntu 22.04)的用户,答案 https://askubuntu.com/a/1432859/1646539 是有效的。当在 Ubuntu 上使用 pipewire 安装 libspa-0.2-bluetooth 并重新启动 wireplumber,如上所述。

您可以检查是否使用 pipewire:

$ pactl info | grep -i "server name"
Server Name: PulseAudio (on PipeWire 0.3.48)

我在安装软件包libspa-0.2-bluetooth时也遇到了问题。
Preparing to unpack .../libldacbt-abr2_2.0.2.3+git20200429+ed310a0-4_amd64.deb ...
Unpacking libldacbt-abr2:amd64 (2.0.2.3+git20200429+ed310a0-4) ...
dpkg: error processing archive /var/cache/apt/archives/libldacbt-abr2_2.0.2.3+git20200429+ed310a0-4_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/x86_64-linux-gnu/libldacBT_abr.so.2', which is also in package libldac:amd64 2.0.2.3~r26478861
Errors were encountered while processing:
 /var/cache/apt/archives/libldacbt-abr2_2.0.2.3+git20200429+ed310a0-4_amd64.deb

以下命令解决了我的问题(使用pipewire):
sudo apt purge libldac
sudo apt install libspa-0.2-bluetooth
systemctl --user restart wireplumber.service

安装完软件包并运行systemctl status bluetooth后,错误src/service.c:btd_service_connect() a2dp-sink profile connect failed for …: Protocol not available消失了。
… bluetoothd[1246]: Player registered: sender=:1.32573 path=/media_player0
… bluetoothd[1246]: Endpoint registered: sender=:1.32573 path=/MediaEndpoint/A2DPSource/ldac
… bluetoothd[1246]: Endpoint registered: sender=:1.32573 path=/MediaEndpoint/A2DPSink/sbc
… bluetoothd[1246]: Endpoint registered: sender=:1.32573 path=/MediaEndpoint/A2DPSource/sbc
… bluetoothd[1246]: Endpoint registered: sender=:1.32573 path=/MediaEndpoint/A2DPSink/sbc_xq
… bluetoothd[1246]: Endpoint registered: sender=:1.32573 path=/MediaEndpoint/A2DPSource/sbc_xq
… bluetoothd[1246]: Endpoint registered: sender=:1.32573 path=/MediaEndpoint/A2DPSource/faststream
… bluetoothd[1246]: Endpoint registered: sender=:1.32573 path=/MediaEndpoint/A2DPSource/faststream_duplex

我有完全相同的问题 a2dp-sink profile connect failed + blueman.bluez.errors.DBusFailedError: Protocol not available. 我认为问题可能出在我们的 ~/.config/pulse/default.pa 文件中。
#!/usr/bin/pulseaudio -nF
#
# Work around for PA not allowing access to A2DP profiles in the user session
# because GDM already has it open.
# LP: #1703415

# 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

由于我无法复现此解决方法中列出的原始错误 (https://bugs.launchpad.net/ubuntu/+source/gdm3/+bug/1703415),我认为可以安全地加上注释:
#!/usr/bin/pulseaudio -nF
#
# Work around for PA not allowing access to A2DP profiles in the user session
# because GDM already has it open.
# LP: #1703415

# 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

然后使用以下命令重新启动pulseaudio
$ pulseaudio -k

这个有问题的解决方法在最新版本的Ubuntu上可能不存在,我没有检查过。(我目前使用的是20.10版本,之前是在18.10版本上安装的)

如果在启动时尝试自动连接蓝牙音频设备时出现此类错误,那么可能是systemd蓝牙服务和pulseaudio之间缺乏同步导致的。
同步bluetoothd和pulseaudio
问题所在
Linux中处理蓝牙设备的蓝牙守护进程bluetoothd通常在系统初始化管理器(如Systemd)的控制下启动。而pulseaudio音频路由过程通常作为与图形桌面管理器关联的自动启动机制的每个用户进程启动。桌面管理器本身通常是初始引导处理的最后一批进程之一。这两种启动机制之间没有同步。这意味着在pulseaudio启动之前,bluetoothd通常已经完成了初始化。 对于非音频蓝牙设备,这不是问题。然而,试图通过dbus使用pulseaudio作为其初始化的一部分的音频蓝牙设备将始终失败。实际上,这意味着任何需要在pulseaudio配置中使用“load-module module-bluez5-discover”的设备都会失败。这种类型的故障的特征是系统日志和日志中出现类似以下消息的情况。
Sep 15 09:04:25 dragon bluetoothd[1423]: src/service.c:btd_service_connect() a2dp-sink profile connect failed for 65:DE:65:37:94:79: Protocol not available.

解决方案

修复这个问题最简单的方法是在pulseaudio完全启动后重新启动bluetoothd。 这个解决方案有两个组成部分。一个是使用systemctl重新启动蓝牙守护进程的简单shell脚本。该脚本从kick-bluetooth.desktop文件中调用。此文件需要放置在需要使用设备的用户的自动启动目录中。通常是~/.config/autostart。

注意事项

这个解决方案在gnome桌面环境下运行良好。其他环境可能需要一些调整。欢迎分享您的经验,我将把它添加到这些说明中。

有关文件,请参见此处。https://github.com/rogerjames99/kick-bluetooth.git


1你的回答可以通过提供更多支持性信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人能够确认你的回答是否正确。你可以在帮助中心找到关于如何撰写好回答的更多信息。 - Community
如果链接中有对这个问题有帮助的信息,那么它需要以文字形式出现在答案中,而不是作为一个链接。 - David