Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

having some trouble keeping a stable connection #1

Open
createcandle opened this issue Mar 8, 2022 · 9 comments
Open

having some trouble keeping a stable connection #1

createcandle opened this issue Mar 8, 2022 · 9 comments

Comments

@createcandle
Copy link

I don't know if I should post this here or at BlueAlsa "prima", but I thought it safe to start here, since I'm now using your version.

First: it rocks. It's so nice to have the audio mixing work transparently.

I'm having some trouble keeping a speaker connected to my Raspberry Pi 4B though, and I'm not sure where to start debugging this.

  • After booting, the audio will be choppy, and then speed up and catch up two seconds later. This later stabiliszes, so probably has to do with the Pi just being busy. Oddly, the network cable is plugged in, so interference from the wifi is not an issue. Similarly, processor use isn't particularly high during boot either.
  • Once the speaker is connected it wil work ok for a while (about 30 minutes to an hour, it varies), but then will randomly stop working. My system does periodic bluetooth scans (3 seconds every 5 minutes, to detect rogue Airtags), but the disconnect doesn't seem to be aligned with that. Once disconnected the speaker doesn't want to reconnect until after a reboot.

This is now BlueAlsa is started in the systemd file:

[Unit]
Description=BluezALSA proxy
Requires=bluetooth.service
After=bluetooth.service

[Service]
Type=simple
User=root
Environment="LD_LIBRARY_PATH=/usr/local/lib"
Environment="LIBASOUND_THREAD_SAFE=0"
ExecStart=/usr/bin/bluealsa --multi-client -p a2dp-source -p a2dp-sink --a2dp-volume -p hfp-ag

[Install]
WantedBy=multi-user.target

This is an error I spotted:

Mar 08 21:52:50 candle bluealsa[409]: /usr/bin/bluealsa: E: PCM poll and read error: Bad file descriptor
Mar 08 21:52:54 candle bluealsa[409]: /usr/bin/bluealsa: E: PCM poll and read error: Bad file descriptor
Mar 08 21:53:21 candle bluealsa[409]: /usr/bin/bluealsa: E: Couldn't release transport: GDBus.Error:org.freedesktop.DBus.Error.UnknownObject: Method "Release" with signature "" on interface "org.bluez.MediaTransport1" doesn't exist
Mar 08 21:53:21 candle bluealsa[409]: /usr/bin/bluealsa: E: Couldn't release transport: GDBus.Error:org.freedesktop.DBus.Error.UnknownObject: Method "Release" with signature "" on interface "org.bluez.MediaTransport1" doesn't exist

I suspect the first two lines refer to the speaker being offline.

@borine
Copy link
Owner

borine commented Mar 9, 2022

I don't know if I should post this here

Try without --multi-client to see if any of the symptoms disappear. If it works without, the the problem is almost certainly in my patch, so there's no point posting upstream. Try with the upstream sources, if that works the problem is very certainly in my patch!

choppy, and then speed up and catch up two seconds later

This is a classic symptom of dropped PCM samples. I've seen it with a Pi3 two or three years ago, before Raspbian fixed up the UART config correctly for bluetooth. Possibly some other device (maybe console?) is using the same UART as bluetooth during and just after boot. You could try a USB adapter to rule out UART issues.

I've only used this fork on an Intel box (I developed it specifically for use with chromium browser). I don't have a Pi4, but do have a spare Pi Zero W I could use for testing. It may take me a couple of weeks before I can set it up though.

@borine
Copy link
Owner

borine commented Mar 9, 2022

Once disconnected the speaker doesn't want to reconnect until after a reboot.

Looks like some service has failed. What does systemctl status report after the disconnection ?

@createcandle
Copy link
Author

I'm still testing. Your hint that the bluetooth stutter may have come from serial being enabled was spot on. Disabling that seems to have improved that situation already. Now I'm testing longevity. My speakers are sending out a submarine Ping sound every 30 seconds, until I tune it out.. and at some point I go "hey, where did the sound go" :-)

@createcandle
Copy link
Author

createcandle commented Mar 10, 2022

The speaker seems to remain connected so far. I'm playing silence every 30 seconds.

I am seeing an error, but the speaker seems to still be connected (I can play music to it).

Mar 10 16:01:39 candle bluealsa[407]: /usr/bin/bluealsa: E: PCM poll and read error: Bad file descriptor
Mar 10 16:01:40 candle bluealsa[407]: /usr/bin/bluealsa: E: PCM poll and read error: Bad file descriptor
Mar 10 16:02:08 candle bluealsa[407]: /usr/bin/bluealsa: E: PCM poll and read error: Bad file descriptor
Mar 10 16:02:36 candle bluealsa[407]: /usr/bin/bluealsa: E: PCM poll and read error: Bad file descriptor

Would you mind if a ask a few other questions regarding bluetooth? Feel free to ignore.

The speaker I'm currently testing with is a JBL GO. It has a microphone and can accept phone calls.

When I check the systemctl status of bluetooth.service, I see an error once in a while:

Mar 10 09:11:51 candle bluetoothd[502]: Endpoint registered: sender=:1.4 path=/org/bluez/hci0/A2DP/SBC/source/1
Mar 10 09:11:51 candle bluetoothd[502]: Endpoint registered: sender=:1.4 path=/org/bluez/hci0/A2DP/SBC/source/2
Mar 10 09:11:51 candle bluetoothd[502]: Endpoint registered: sender=:1.4 path=/org/bluez/hci0/A2DP/SBC/sink/1
Mar 10 09:11:51 candle bluetoothd[502]: Endpoint registered: sender=:1.4 path=/org/bluez/hci0/A2DP/SBC/sink/2
Mar 10 09:45:32 candle bluetoothd[502]: src/profile.c:ext_connect() Headset Voice gateway failed connect to B8:69:C2:F1:48:XX: Connection refused (111)
Mar 10 09:45:39 candle bluetoothd[502]: /org/bluez/hci0/dev_B8_69_C2_F1_48_XX/sep1/fd0: fd(32) ready

Bluetooth is started with: /usr/libexec/bluetooth/bluetoothd --noplugin=sap --plugin=a2dp
Bluealsa is started with /usr/bin/bluealsa --multi-client -p a2dp-source -p a2dp-sink --a2dp-volume -p hfp-ag

The mac address of my Raspberry Pi 4's bluetooth adapter seems to be wrong: AA:AA:AA:AA:AA:AA. I've tried removing the bluetooth folder, which is a solution I found online, but to no avail.

Could it be because the bluetooth folder is on a second partition that is mounted over /etc/bluetooth ? (only the second partition is writable)

I've also been trying to allow the system to connect to bluetooth keyboards and mice. To original system is "Raspbian lite", which has been modified to run a minimal kiosk desktop (X11, openbox, chromium-browser).

After enabling a kernel mod file I can now see the keyboard presses coming into bluetooth via btmon. But key presses and mouse movements do not show up in Chromium. Nothing shows up in /dev/input either. Do you have a suggestion which other parts I should enable to get Bluetooth hid to work? More kernel modules perhaps?

@borine
Copy link
Owner

borine commented Mar 10, 2022

  1. Not sure. Is the connection request being initiated by yourself on the bluealsa box, or by the speaker ("autoconnect") ?

  2. The MAC address needs to be set by the system when it initialises the broadcom bluetooth module. RasperryPiOS lite does this based on the Pi's serial number in the script /usr/bin/bthelper, which in turn is invoked by systemd when the hci device is created ([email protected]).

  3. You need to read man bluetoothd. It is almost always wrong to use --plugin= ; it does not do what you think it does. You have in fact disabled lots of bluetooth function, including input !!

@createcandle
Copy link
Author

And just like that the keyboard started working. Thank you SO much, I never would have figured that out!

@createcandle
Copy link
Author

createcandle commented Mar 11, 2022

Good news, this morning the connection has survived all through the night.

I also managed to fix the AA:AA:AA:AA:AA:AA following the advise in this thread to create a symlink: sudo ln -s /lib/firmware /etc/firmware

Perhaps the "Headset Voice gateway failed connect" error was also caused by my plugin abuse :-)

@borine
Copy link
Owner

borine commented Mar 11, 2022

So far I have only tested SBC and AptX codecs. Once you are happy with your system setup, if you could possibly report back results with other codecs that would be very helpful for knowing if the mixing code is ready for merging upstream.

I've done very little testing of the snoop code, so anything you can contribute there would also very useful.

@createcandle
Copy link
Author

I'm using the legally 'safe' codecs, as mentioned here:

arkq#544

APTx is not part of that. MP3Lame is, and I'm listening to internet radio streams via ffplay, most of which are MP3. It's mixing in 22500 and 16000 wav files from voice control via aplay. So far it's been perfect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant