PulseAudio在Debian 11出现GetManagedObjects() failed: org.freedesktop.DBus.Error.NoReply、VirtualBox HostAudioNotResponding等无声音输出问题的修复方案

不知道为什么,PulseAudio在Debian 11出现了无声音输出的问题,主要日志表现有:

1、Pulseaudio服务出现org.freedesktop.DBus.Error.NoReply:

systemctl --user  --no-pager -l status pulseaudio.service

● pulseaudio.service - Sound Service
     Loaded: loaded (/usr/lib/systemd/user/pulseaudio.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2023-01-06 16:29:31 CST; 2min 28s ago
TriggeredBy: ● pulseaudio.socket
   Main PID: 217228 (pulseaudio)
      Tasks: 2 (limit: 76768)
     Memory: 7.2M
        CPU: 169ms
     CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/pulseaudio.service
             └─217228 /usr/bin/pulseaudio --daemonize=no --log-target=journal

Jan 06 16:29:30 debian11 systemd[1122]: Starting Sound Service...
Jan 06 16:29:31 debian11 systemd[1122]: Started Sound Service.
Jan 06 16:29:56 debian11 pulseaudio[217228]: GetManagedObjects() failed: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

2、VirtualBox启动虚拟机无声音,并弹出HostAudioNotResponding:

Host audio backend (PulseAudio) initialization has failed. Selecting the NULL audio backend with the consequence that no sound is audible.


Error ID:
HostAudioNotResponding
Severity:
Warning

其VBox.log有一句话引起了注意:

PulseAudio: Failed to connect to server: Connection refused

3、syslog也出现org.freedesktop.DBus.Error.NoReply,不过更明确点是蓝牙模块引起。

cat /var/log/syslog |grep udio

Jan  6 16:22:09 debian11 dbus-daemon[702]: [system] Activating via systemd: service name='org.bluez' unit='dbus-org.bluez.service' requested by ':1.807' (uid=1000 pid=216065 comm="/usr/bin/pulseaudio --daemonize=no --log-target=jo")
Jan  6 16:22:34 debian11 pulseaudio[216065]: GetManagedObjects() failed: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

4、pacmd命令查看pulseaudio状态,确实载入了蓝牙模块:

pacmd dump | grep module-bluetooth
load-module module-bluetooth-policy
load-module module-bluetooth-discover

查找一番后,发现这是两个问题联合导致的:

1、PulseAudio蓝牙支持问题导致GetManagedObjects() failed: org.freedesktop.DBus.Error.NoReply。

2、PulseAudio authentication cookie问题导致VirtualBox连接PulseAudio出现Connection refused类型的HostAudioNotResponding。

所以解决问题主要是暂时禁用蓝牙模块(如果有需要)和配置正确的本地连接认证。

以下命令不需要root身份,需要的是当前登录用户身份。

以下假设当前登录用户名称为“test987654321”,其home目录为:“/home/test987654321”。

第一步:复制两份配置文件到当前登录用户目录下:

cp /usr/share/gdm/default.pa ~/.config/pulse/default.pa
cp /etc/pulse/client.conf ~/.config/pulse/client.conf

第二步:修改~/.config/pulse/default.pa,禁用蓝牙模块

找到load-module module-bluetooth相关字样,然后全部在前面加#变成注释,即修改为:

#load-module module-bluetooth-policy
#load-module module-bluetooth-discover

以下命令也能达到以上效果:

sed -Ei '/load-module module-bluetooth*/s/^/#/' ~/.config/pulse/default.pa

第三步:修改~/.config/pulse/default.pa,配置PulseAudio服务端本地连接认证【4】

找到:

load-module module-native-protocol-unix

将它改为:

load-module module-native-protocol-unix socket=/home/test987654321/.config/pulse/socket-instance auth-cookie=/home/test987654321/.config/pulse/cookie auth-cookie-enabled=true

(/home/test987654321请修改为实际的当前用户home目录)

第四步:修改~/.config/pulse/client.conf,配置PulseAudio客户端本地连接认证

添加如下内容:

default-server = unix:/home/test987654321/.config/pulse/socket-instance
cookie-file = /home/test987654321/.config/pulse/cookie

(/home/test987654321请修改为实际的当前用户home目录)

第五步:重启PulseAudio服务(建议保存为脚本文件):

systemctl --user mask pulseaudio.socket
systemctl --user stop pulseaudio.socket
systemctl --user stop pulseaudio.service
systemctl --user unmask pulseaudio.socket
systemctl --user start pulseaudio.service
systemctl --user status pulseaudio.service

参考资料:

【1】https://wiki.debian.org/PulseAudio

【2】Gentoo Forums :: 阅读主题 – [SOLVED] Pulseaudio for multi-user Linux:https://forums.gentoo.org/viewtopic-t-1110600-start-0.html

【3】[Solved] No sound in VirtualBox guest (Windows 7) / Multimedia and Games / Arch Linux Forums:https://bbs.archlinux.org/viewtopic.php?id=221934

【4】https://wiki.archlinux.org/title/PulseAudio/Examples#Allowing_multiple_users_to_share_a_PulseAudio_daemon

本页永久链接:https://www.orztip.com/?p=753&article_title=pulseaudio-org-freedesktop-dbus-error-noreply-virtualbox-hostaudionotresponding