fury
Posts: 15
Joined: Thu Sep 20, 2012 4:37 pm

Pi as A2DP sink - SBC decoding error; audio completely stops

Wed Jun 15, 2016 5:22 pm

I'm using the 5/27 Jessie build which has Bluetooth audio source enabled, but I want to receive audio from my phone too. My Pi is hooked up to a TV via HDMI cable, audio is also going out that HDMI cable.

I started pulseaudio

Code: Select all

pulseaudio --start
and saw via bt-adapter -i that the sink service is already enabled. I paired my phone (iPhone 5s) through the Pi's Bluetooth menu. It paired, and then the Pi GUI said the phone didn't have any services available that the Pi could use, since the phone is not a sink. I then tapped raspberrypi on my iPhone's Bluetooth devices list, and audio started routing to the Pi.

Everything was great, I heard audio up until I started doing something else on the Pi, like loading up the web browser or scrolling through the terminal. The audio cut out as soon as I did that.

I checked /var/log/syslog and spotted, at the time of cutout, the following messages:

Code: Select all

raspberrypi kernel: [  146.295944] Bluetooth: hci0: Frame reassembly failed (-84)
^-- above message repeated dozens and dozens of times, sometimes the number is -90
raspberrypi pulseaudio[1006]: SBC decoding error (-2)
Then it would either start back up again about 10 seconds later, or it would give up and disconnect from the phone.

Code: Select all

raspberrypi bluetoothd[657]: Suspend: Connection timed out (110)
It's pretty reliably reproducible at any time I try to do anything on the Pi, even cat / grep / tail on the log file.

I googled around a bit for those error messages and came across this post:

https://delx.net.au/blog/2014/01/blueto ... pberry-pi/
Secondly PulseAudio seems to be very picky about the SBC data it receives from the phone. After 5-10 mins of playing I’ll see “SBC Decoding Error (-3)”, after which PulseAudio will terminate playback & clean up the Bluetooth connection. I wrote a quick patch to fix this, see commit 4a5f48e7a42f997793db76e2001b7c252f8d93fe.
Directly above that paragraph was the following note:
Update! This patch was merged into Pulseaudio. It is no longer necessary for PulseAudio >= 6.
As the Pi was running PulseAudio 5.0, I set out to update it to see if that fixed this problem. I changed the distro in sources.list to stretch (nothing can possibly go wrong!), upgraded pulseaudio to 8.0, restarted. Nope. Same problem. Whenever I do anything on the Pi, I get that frame reassembly failed and SBC decoding error. I also tried upgrading bluez, but then it doesn't seem to find the Bluetooth controller at all, so I reverted bluez and pulseaudio and all that back to what's in the jessie distro. (I also flashed my Pi fresh with the 5/27 image again and re-paired)

After some amount of time and some unknown thing occurring, the whole Pi audio system seems to break down and I can't get any audio whatsoever to work consistently, not even a speaker-test. Incoming Bluetooth audio cuts out completely for a while, and if I hear it again, it's extremely far behind what the phone is actually playing.

In syslog while receiving Bluetooth stream from the phone:

Code: Select all

Jun 15 14:53:23 raspberrypi pulseaudio[1006]: Sample rates too different, not adjusting (44100 vs. 73423).
Jun 15 14:53:33 raspberrypi pulseaudio[1006]: Sample rates too different, not adjusting (44100 vs. 117581).
Jun 15 14:53:43 raspberrypi pulseaudio[1006]: Sample rates too different, not adjusting (44100 vs. 161741).
Jun 15 14:53:53 raspberrypi pulseaudio[1006]: Sample rates too different, not adjusting (44100 vs. 205837).
... the number on the right side keeps going up until finally reaching 462925 at 14:54:53, message repeats every 10 seconds or so with a number at or close to 462925 until 15:02:43 then audio starts coming back, kinda
At this time, speaker-test looks like this, whether I'm doing speaker-test at the same time as receiving Bluetooth or just speaker-test on its own with no incoming Bluetooth audio:

Code: Select all

speaker-test 1.0.28

Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 192 to 2097152
Period size range from 64 to 699051
Using max buffer size 2097152
Periods = 4
was set period_size = 524288
was set buffer_size = 2097152
 0 - Front Left
Time per period = 11.018455
 0 - Front Left
Time per period = 30.086247
 0 - Front Left
Time per period = 11.041197
 0 - Front Left
Time per period = 11.009435
 0 - Front Left
Time per period = 11.011568
 0 - Front Left
Time per period = 30.086640
During the periods where it says 11 seconds, I hear the test noise, and during the periods where it says 30 seconds, I hear nothing.

After a fresh reboot:

Code: Select all

speaker-test 1.0.28

Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 512 to 32768
Period size range from 512 to 32768
Using max buffer size 32768
Periods = 4
was set period_size = 8192
was set buffer_size = 32768
 0 - Front Left
Time per period = 11.866896
 0 - Front Left
Time per period = 2.899850
 0 - Front Left
Time per period = 2.909913
 0 - Front Left
Time per period = 2.899846
 0 - Front Left
Time per period = 2.900281
 0 - Front Left
Time per period = 2.899361
Pink noise is audible the entire time of speaker-test.

If I pulseaudio --start right after this, the speaker-test does the same thing as the first one I posted - 11 to 30 seconds per "period", where sound is not audible during the 30 second periods (about every other iteration)

Any ideas on fixing the SBC decoding error when multitasking, or this weird problem that seems to break the whole audio system?

jbuehl
Posts: 32
Joined: Fri Jun 08, 2012 2:49 pm
Location: Los Angeles

Re: Pi as A2DP sink - SBC decoding error; audio completely s

Sun Aug 21, 2016 9:04 pm

I'm seeing the same behavior on my Pi 3 running Raspbian 8.0, bluez 5.23, and pulseaudio 5.0. I think the root cause is wifi interference with bluetooth. I have the wlan0 interface disabled because if it isn't, the audio is choppy, but occasionally it just goes silent for a while and I see the "SBC decoding error" message from pulseaudio, along with a whole bunch of "Frame reassembly failed" messages from bluetooth. The Pi is sitting right next to my laptop and close to a wifi access point. If I move it away from the wifi devices, the problem seems to not occur. If big chunks of data are getting lost going across bluetooth, I don't see how ignoring the SBC decoding error is going to fix anything.

fury
Posts: 15
Joined: Thu Sep 20, 2012 4:37 pm

Re: Pi as A2DP sink - SBC decoding error; audio completely s

Wed Oct 19, 2016 5:56 pm

I'm still having the problem even after disabling wifi (ifdown wlan0)

Sadly it doesn't even always depend on me doing something, just at random it will drop some frames and then take a good chunk of time to restart the A2DP stream, or in some cases just plain give up and disconnect. That said, doing stuff on the Pi does make it happen more frequently (e.g. posting on this forum it's done it about a dozen times in a row).

I'm now on kernel 4.4, and looking at the code most likely spitting out that error, https://github.com/raspberrypi/linux/bl ... _h4.c#L124

Looks like the error is most likely from not getting a valid packet of data in some cases from the H4 transport. Is there perhaps a problem with the UART communication with the Bluetooth chip?

jbuehl
Posts: 32
Joined: Fri Jun 08, 2012 2:49 pm
Location: Los Angeles

Re: Pi as A2DP sink - SBC decoding error; audio completely s

Wed Oct 19, 2016 10:36 pm

Contrary to what I posted earlier, the problem continued to occur for me even when I was not in range of wifi. I gave up on trying to get this to work with pulseaudio and I am currently working on using bluez 4 to connect directly to alsa. For a number of other reasons, I abandoned using raspbian and I'm now working with arch linux. There is a lot of work involved, including writing an application to connect bluez to alsa, which I haven't started yet. If/when I get it working I'll post something.

Return to “Troubleshooting”