Bluetooth pulseaudio problems after 23.05->23.11 update

i have a laptop with nixos.
it has bluetooth and i quite often use bt headphones with it. Everything ran pretty smoothly, but after update from 23.05 to 23.11 bluetooth became unstable:

  • on boot it connecting to bt device, but headphones does not apper in KDE’s audio device list.
    disconnecting and connecting again does not change anything - bluetooth applet shows device as connected, but pulseaudio does not see it.
  • after putting laptop to sleep and waking it - on first connecting bt headphones pulseaudio does not see it again, but on disconnect and next connect it does see the headphones, and it seem to work fine after that, untill next sleep-wake event (or reboot).

here’s the log of attempted connects:

  • first, first connect after waking laptop: bt device is connected, but pulseaudio does not see anything: log 1
  • then if i click disconnect on bt device - pulseaudio seem to crash and restart: log 2
  • after that it works fine (until next sleep): log 3

my sound config is as simple as:

hardware.bluetooth.enable = true;
sound.enable = true;
hardware.pulseaudio.enable = true

Does anyone have any idea what happened in-between releases and how to fix this?

1 Like

does bluetoothctl report any oddities? do they appear there devices Connected

Check Bluetooth headset - ArchWiki section 2.4.6; perhaps something changed with PulseAudio configuration? I do see something like what is reported in Arch wiki in your logs:

Dec 06 18:03:22 hostname plasmashell[3163]: org.kde.plasma.pulseaudio: context kaput
Dec 06 18:03:22 hostname bluetoothd[1732]: Endpoint unregistered: sender=:1.568 path=/MediaEndpoint/A2DPSink/sbc
Dec 06 18:03:22 hostname systemd[2731]: pulseaudio.service: Main process exited, code=dumped, status=6/ABRT
Dec 06 18:03:22 hostname plasmashell[3163]: org.kde.plasma.pulseaudio: No object for name "alsa_output.pci-0000_00_1f.3.analog-stereo"
Dec 06 18:03:22 hostname bluetoothd[1732]: Endpoint unregistered: sender=:1.568 path=/MediaEndpoint/A2DPSource/sbc

I’m having similar problem to your first point (on NixOS 23.05), usually what helps me is a restart of bluetooth service - systemctl restart bluetooth. I even added this command as a startup script to my nixos profile.

Does pipewire has the same issues?

bluetoothctl reports device correctly: name, type, that it’s connected, etc (though i’m not familiar with that command, so i just checked info, devices)

from arch wiki - it basically says (as i understand) if you see those lines in log - then the problem is not in bluetoothd, otherwise go see another section.

also i do see the headphones with pacmd ls , as described in wiki, but it has no available profiles (except Off), so trying to switch to a2dp_sink fails

gah. This is an odd one. Would be nice to not have to workaround and use pipewire if one doesn’t want to. That failed assertion here https://github.com/pulseaudio/pulseaudio/blob/81a6cc4967d1f19cef800932b10ade7f896ee2ea/src/modules/bluetooth/module-bluez5-device.c#L2331C91-L2331C98 makes me wonder if something is getting ahead of itself; pulseaudio attempting to handle a state change before things are ready. check out the bluez config, perhaps a setting in there will help? https://github.com/Vudentz/BlueZ/blob/d326a96ed4186cb3cd904d86e8a7f76f82349467/src/main.conf#L240 (ResumeDelay)

tested now, briefly, just boot, and a couple of sleep-wake cycles - pipewire seem to be working fine, no problems.
only inconveinences like sometimes it does not auto switch to headphones, and sometimes kde continues to show mute status of speakers in tray, even though in the tray popup it shows that headphones are active and playing

However i’ve noticed, that playing youtube videos in firefox now eats up 1.5-2 times more CPU, maybe because pipewire sees way more profiles for my headphones compared to pulseaudio and selects something compression-heavy? that i’m not sure. (i see more CPU consumption from firefox process itself)

edit: need to correct myself about CPU usage: later i’ve run a proper test, running same video on same quality with different outputs enabled on both configurations several times, and i cannot establish statistically significant difference in CPU usage between pulseaudio and pipewire configurations. I guess that one small short test I did in the beginning just happened to happen in parallel firefox’s internal workings? still kinda strange.
What I’ve also noticed is that with pipewire and bt headphones youtube video always starts with around 0.5 second of lagging, but then continues properly. This lag is NOT happening with pipewire when outputing to speakers (even with headphones connected), and not happening with pulseaudio, with or without bt headphones.

about resume delay - for now for experiment i always disable bluetooth before suspend and reenable it after, just to exclude all those waking racing.

but it does seem like something happens in the wrong order - that’s why after pulseaudio crashes and is restarted it works fine

hey there everyone,
me again with new, but still related problems.
after switching to pipewire, which solved bluetooth audio output problem, i’ve noticed this new problem:

The problem is that youtube video starts to stutter just a tiny bit when audio is on (there is no problems and no stutter in audio though).
Even if video has silent audio - the problem still manifests, but as soon as you press “mute” button on the youtube player - the video stutter goes away.

take a video with smooth linear movement - the problem is easy to spot with them, like this one: https://www.youtube.com/watch?v=vigX3H7WX5Q

no mute - you can spot tiny stuttering from time to time (around once a second for me). mute the video - and stutter goes away.

(using flatpak firefox)
same downloaded test videos played with vlc play fine with or without sound

i think, this problem deserves a separate topic: Pipewire Firefox tiny video stutter