LWN.net Logo

OLS: Audio Streaming over Bluetooth

August 12, 2008

This article was contributed by Ian Ward

On July 23 Marcel Holtmann delivered a presentation on the state of Audio Streaming over Bluetooth at the 2008 Linux Symposium in Ottawa. Holtmann's background involves working on improving Linux Bluetooth audio support for laptops and embedded systems such as cell phones.

Marcel expressed frustration with the complexity of the Bluetooth specifications which include approximately 20 protocols and 40 profiles. Profiles include things like mono headsets, in-car usage and high quality stereo headphones. There are protocols for serial device emulation, phone book access, caller ID information, text messaging and multiple options for audio and video.

Bluetooth defines separate protocols for streaming and control, such as skipping tracks, seeking within tracks, and displaying ID3 information. Having these aspects split into different protocols was called "messy" because they are always used together.

Mono headsets are supported by the Synchronous Connection Oriented link (SCO), while the Advanced Audio Distribution Profile (A2DP) is designed for high quality stereo audio. For audio compression Bluetooth defines a royalty-free SubBand-Codec (SBC) to avoid fees for use of common codecs like MP3 and AAC. All A2DP devices must support SBC, but many also support decoding MP3 and AAC as well. Linux's SBC support was initially very poor, but some developers from the Instituto Nokia de Tecnologia in Brazil stepped up to improve encoding and now the the LGPL SBC implementation rivals some of the best commercial implementations.

Early Bluetooth headset support in Linux involved copying all the audio data over sockets from the application to the Bluetooth daemon. The daemon would then copy the data again to the device, causing unnecessary CPU usage and increasing latency. The current design works by setting up channels and connecting external applications directly to the device sockets. Marcel also mentioned investigating a shared memory approach for better performance at the cost of some extra complexity.

Adding support for a Bluetooth audio device is quite different than for standard audio hardware — compressed data must be sent directly to the devices, possibly with ID3 and other information. If the audio being played is in a format that a device does not support it must be decoded and re-encoded first. Bluetooth devices will also appear and disappear while audio is being played.

Marcel on ALSA: "I won't touch it anymore." ALSA's primary failing is that it wasn't designed to support virtual devices. He is also not convinced that the current direction of PulseAudio is suitable for Bluetooth audio, in particular there is no support for changing codecs while audio is being sent to a device. GStreamer, however can support the concept of virtual devices, sending out encoded data and sending ID3 information when required. If a file format is supported by a Bluetooth device, GStreamer can easily be told to send it as-is without re-encoding it. It can also handle the passing off of the encoding and decoding tasks to special hardware, which is commonly required for embedded systems.

Future work includes adding more intelligence to the handling of control signals. When the user presses Pause and there are multiple devices and streams active, which stream should be affected? The current implementation applies the action to all streams, but it may be better to be able to tell which control device is associated with which stream.

There is also ongoing work to support new hardware. Marcel has had some issues with headsets that are very sensitive to timing, but don't provide enough timing information to reliably fix. There have also been some problems supporting "Enhanced" Synchronous Connection-oriented (eSCO) Links due to vendors that are unwilling to cooperate with the developers.

For more information on Bluetooth development see Marcel's OLS Paper [pdf] and BlueZ.org, the site for the official Linux Bluetooth protocol stack.


(Log in to post comments)

OLS: Audio Streaming over Bluetooth

Posted Aug 14, 2008 9:10 UTC (Thu) by dvrabel (subscriber, #9500) [Link]

The profiles for mono headsets are the Hands Free Profile (HFP) and the older Headset Profile
(HSP).  SCO is the underlying data transport for these profiles and provides a guaranteed
latency link.

A2DP uses L2CAP over ACL as it's data transport.

Hands Free/Headset Profiles vs. SCO Transport

Posted Aug 14, 2008 17:35 UTC (Thu) by Webexcess (subscriber, #197) [Link]

Thank you for the correction.

Ian

And with all the zillions of Bluetooth profiles

Posted Aug 14, 2008 20:11 UTC (Thu) by brouhaha (guest, #1698) [Link]

There apparently still isn't a way that I can use my stereo BT headset to listen to stereo music, but still be able to answer an incoming phone call. :-(

Prius Bug

Posted Aug 15, 2008 0:11 UTC (Fri) by quotemstr (subscriber, #45331) [Link]

Might as well mention a weird Prius interaction while we're talking about Bluetooth.

I have a Nokia N95 and a Prius. The Prius seems to act as both a car audio kit *and* a generic
audio device, but it refuses to play sound when a call isn't active. Yet the N95 insists on
routing audio through the Bluetooth connection.

So, for starters, I can't simply listen to music on the N95, transmit the audio over
Bluetooth, and listen to it on the car's stereo. Instead, I have to use a physical audio
cable. Then, if I'm doing that, and the phone wants to play a sound (say, for an incoming text
message), it tries to route it over Bluetooth. But since the car isn't listening, the only
indication that something happened is a gap in the music.

It's just a weird situation, and it's really not practical to patch the software in either
device.

is it possible to use Linux as an audio router?

Posted Aug 15, 2008 7:24 UTC (Fri) by dlang (✭ supporter ✭, #313) [Link]

with so many things being bluetooth capable, but with extremely limited UIs (one bi-colored
LED and two buttons for example) it would seem very handy if linux could do the work of
logicly connecting the devices (along with the aility to insert additional controls.

anyone know of any projects that are working in this area?

OLS: Audio Streaming over Bluetooth

Posted Aug 15, 2008 16:44 UTC (Fri) by bronson (subscriber, #4806) [Link]

Agree 100% on ALSA.  How long have USB-based audio devices existed?  So why does ALSA still
choke when plugging and unplugging?  If USB is still so painful for ALSA, just imagine what it
would be like for Bluetooth!

PulseAudio appears to have solved plug/unplug problem 100%.  When I plug in the USB headset,
it appears in PA and I can route some audio streams to it on the fly.  Unplug it, its audio
automatically reroutes to another device.  It's really satisfying.  Finally, audio that
doesn't suck on Linux!  (this is with Intrepid alpha 4)

But I can't for the life of me figure out how to get PA to work with Bluetooth.  I paired my
computer with my headset (no easy task!), but I just can't figure out how to get the headset
to appear as an audio sink in PA.  I guess I'll keep a close eye on Holtmann's work.

OLS: Audio Streaming over Bluetooth

Posted Aug 27, 2008 14:07 UTC (Wed) by gdamjan (guest, #33634) [Link]

there's a GSOC project to add bluetooth support to PulseAudio

I think this is it: http://code.google.com/p/bluez-pulseaudio/

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds