Tuesday, August 22, 2017

Terrible experience with bluetooth headsets and what to do about it

If you own a Bluetooth A2DP headset and any kind of personal computer, good chance is you tried connecting them together. Isn't it nice to watch movies and listen to music free from cluttering wires? Well, good chance is you hated that experience and if that was the reason for buying the headset, you might've even considered throwing it away (or using it only with your phone).

Why do they suck so much? Everything points to the fact that it's not a hardware problem. The same headset most likely will work flawlessly paired with an android device or even the same computer under a different operating system (windows users report huge difference between, like, 8.0 and 8.1, and not in favor of the latter, surprisingly, I think only mac users report good stuff about their macbooks and beats although I didn't try it myself so they might all be faking it :) ). And most likely it's not even the drivers or other low-level stuff, android and desktop linux has mostly the same driver stack in the kernel. My prime suspects are bluez (userland part of the bluetooth stack on most modern linux installations) and pulseaudio (audio manager thingy). ALSA (low-level sound thing) could also be at fault but I don't think it is. Those two are not, let's be frank here, examples of excellent software development although not open source at its worst either, to be honest, they mostly get the job done even if you might have a few troubles connecting devices and, say, ensuring your wireless input devices work before you log in to the system (for example, I own a bluetooth-capable mouse and I use included dongle instead, forever sacrificing a USB port for the sake of trouble-less experience), or you might do some tweaks and tricks to get rid of sound defects (haven't heard that one for a while, I suspect pulseaudio had so trouble performing when CPUs were largely single-core and constantly overloaded). And the combination of those two is a pure nightmare, whenever I try to pair a headset I expect to be fumbling and clicking various controls for at least a few seconds and even connecting an already paired device is almost never flawless (having to connect and disconnect things several times before they finally work is not new). Then, when all is done and seems to work, you a video and you suddenly want to kill someone. It lags so much it's almost never synced and even if you try to play with A/V synchronization and add some video delay it's next to impossible to done right because delay is variable. Something is not right with this world.

Compare this with android. You take the headset, you turn pairing mode on, open bluetooth settings, find the device you want and tap "pair". That's all, it works. If your phone and headset and both NFC-capable it be even easier: hold on close to the other, hear the bell sound, tap "allow" and you're all set. And it never suddenly disconnects, never lags or anything. From now on you most usually can just turn the headset on and don it whenever you feel like it and it will connect and start working almost immediately! Magic!

Now to the sad part. How to make the first more like the second? The short answer is I don't know but something should be done. There are some hardware hacks, like usb/bluetooth sound dongles which can do basically the same thing that dongle does for a mouse or keyboard: take up another port forever in exchange for more or less lack of bugs. Then android is mostly open-source and we just might be able to learn what they do differently and port that somehow to desktop linux. Or just work on fixing and optimizing bluez/pulseaudio (just clearly identifying the exact reason for these shortcomings would be a great start). Burning it all with fire is another possible solutions but I don't thing either of projects mentioned is deserving it, they just have a few bugs or possible deep design issues but otherwise they mostly get the job done and writing anything from scratch is likely to be more bothersome and introduce more new bugs.

If anybody has any context like code or developer discussion threads or bug reports I would really like to hear about it in comments. And I will update this post when/if I find any solution worth pursuing.