arkq / bluez-alsa

Bluetooth Audio ALSA Backend
MIT License
864 stars 189 forks source link

Fail to use google home mini as bluetooth speaker #627

Closed neslinesli93 closed 1 year ago

neslinesli93 commented 1 year ago

Problem

Hi, I'm trying to use my google home mini as a bluetooth speaker to play audio from a raspberry pi 4. The raspberry uses dietpi, a distro that doesn't have pulseaudio nor pipewire, just plain ALSA. After pairing and connecting to the speaker using bluetoothctl, running aplay -D bluealsa beep.wav works just the first time, then it fails to play further sounds until a reboot is performed, followed by a reconnect. Using the home mini as a bluetooth speaker from my android phone works fine with no issues.

Here are the debug logs of the bluealsa service, which contain the successful play attempt and a couple failed attempts: logs.txt

And here are the logs of aplay: logs_aplay.txt

Setup

OS: Linux 5.15.84-v8+, DietPi v8.14.2, RPi 4 Model B (aarch64) Bluealsa: I'm using the master branch of bluez-alsa (541523ae1a3c4c2fb7264543777a48a93d66cd47), built using the following flags: ../configure --enable-mp3lame --enable-manpages --enable-systemd --enable-debug --disable-payloadcheck BlueZ: 5.55 ALSA: aplay: version 1.2.4

arkq commented 1 year ago

It's quite possible that you've hit the bug introduced some time ago. Unfortunately, I've got no time right now to fix it properly. Try to replace these lines: https://github.com/arkq/bluez-alsa/blob/541523ae1a3c4c2fb7264543777a48a93d66cd47/src/ba-transport.c#L1625-L1626 with:

    if ((fd = t->acquire(t)) != -1) {
        ba_transport_thread_state_set_idle(&t->thread_enc);
        ba_transport_thread_state_set_idle(&t->thread_dec);
        acquired = true;
    }

EDIT: If this will fix your problem, please let me know, and do not close this issue.

neslinesli93 commented 1 year ago

Thank you for the quick reply. I tried your fix and the result was virtually the same as before: aplay worked two times and then it got stuck. Here are the logs: logs_aplay2.txt

Disconnecting and reconnecting to the speaker does not change anything, I always have to reboot. Not even restarting bluealsa.service fixes it :(

arkq commented 1 year ago

OK, I'll look deeper into that issue... Restarting bluealsa.service should have fixed the "stuck" issue. However, it's quite possible that bluealsa service is not restarted. Simply kill it with -9: pkill -9 -x bluealsa

neslinesli93 commented 1 year ago

You were right, killing the daemon fixed the issue! It still got stuck after a couple aplay runs, but at least it didn't require a reboot. It was kind of strange as the bluetoothctl connect command took almost 30 seconds to run, and it even logged an error before connecting. I'll add the logs again, as I don't know if they are useful or not... logs_pkill_connect.txt

arkq commented 1 year ago

Please try the current master branch. If the issue is not fixed, please reopen it.