BlueZ now has A2DP Sink support

Last week was the midterm evaluations for GSoC and also the very same week when my patches were merged upstream into BlueZ. Most of the work was to adapt the existing Source functions to support both Source and Sink and to add Sink logic to the A2DP Server.

There is now a new Source interface on D-Bus, similar to the Sink interface, than can be used to access the Sink functionality. It may sound odd the Sink being accessed through an interface called Source, but in this case it actually acts as a sink on the air interface (receives audio stream from other bluetooth device) and as a source on the application interface (generates audio stream to applications).

Unfortunately, that’s not enough for one to be able to stream audio to a BlueZ device. Right now there is no client able to handle the incoming stream. The good news are that this is part 2 of my SoC project, to implement some clients outside BlueZ to handle this stream. I’m gonna start with PulseAudio, since I’ve implemented the bluetooth sink module on it last year and am more familiar with it’s implementation. After that, I’ll probably implement an ALSA client too.

So what’s the current implementation useful for? From an users perspective, not much. But it shows we are on the way to have it done. Right now it’s possible to connect to the audio sink and put it on STREAMING state, but it doesn’t know how handle the stream and disconnects after a few packets. I’ve tested it with two bluetooth adapter on my laptop and also trying to stream from an Android phone to the laptop.

The Source interface is disabled by default, so if want to test it, make sure to add an “Enable=Source” line to your audio.conf. The code is available on bluez git repo and will be on release 4.46.

About these ads

20 responses to “BlueZ now has A2DP Sink support

  1. Hello Joao,

    Can you elaborate more on the testing part i.e, after I connect my A2DP enabled mobile phone to a linux PC running bluez 4.46, what steps do I need to follow to make sure that my PC is receiving audio packets from the phone via bluetooth?

  2. Wow. I’ve been looking for something like this for a while now. So BlueZ will now support a2dp streams from other devices? But there’s no implementation for what to do with the stream?

  3. @Divya: With BlueZ 4.46 only, the only way to make sure is using hcidump, since no client handles the stream coming to bluez. BlueZ will disconnect after a few packets transmitted because of that fact.

    @snicker: BlueZ receives the encoded stream through it’s air interface and make it available to the applications through it’s application interface (a bluetooth socket). A client has to connect to that socket, decode the audio, and use that stream somehow (play, record, etc).

  4. I’ve just implemented a pulseaudio client to handle the stream. It’s still not on pulseaudio upstream because there is some clock-synch improving to be done, and also automatic detection and loading of the bluetooth module into PA.

  5. Thanks Joao,

    Let us know when you are done with your pulse audio integration :)

  6. indeed! I’m fairly excited for this. I’ve been trying to get this implemented on my PS3 so I can stream music from my iPhone over my stereo system (or play games, which would be doubly awesome). I’ve been playing with the old bluetooth-alsa and btsco packages trying to register a A2SNK with sdptool, but the iPhone just isn’t playing along. I use the a2recv binary from the btsco package, pair my iPhone, and start playing music.. but nothing. Good to hear there is some work going on for this again, those mp3car audio folk will be ecstatic.

  7. Hi João,
    Gustavo Padovan told me about your work.

    I am willing to test audio streaming between my computer and other BT devices.

    Congratulations for your great work!

    Best Regards,

    Alan

  8. How goes it João?

  9. Paul Ionescu

    Hello João,

    I saw that you posted on 16 August some pulse-audio patches on the PA mailing list for A2DP source.
    Are they enough for streaming sound from an A2DP source to a linux pc ?

  10. Paul Ionescu

    Hi João,

    Your pulseaudio A2DP patches for “handling bluetooth source”
    and “add discover of bluetooth sources” are present in
    PulseAudio 0.9.16-test7.

    Can you please describe how can I use this latest pulseaudio together with bluez-4.50 in order to stream A2DP sound to the computer?

    Thank you,
    Paul

  11. Hi João,

    Any news on this front ?

  12. Hello everybody!

    Sorry for the very long delay, I’ve been busy with my MSc and also I got a job (partly thanks to this work). For all of you willing to stream audio from any A2DP enabled device to your linux box, all you need is a recent version of bluez and pulseaudio (any recent distro should provide you the necessary packages). What you want to look for is module-bluetooth-discover and then when you connect an A2DP source to you pc, a new source will be available to your applications through pulseaudio.

  13. Thank for your reply Paulo…

    Indeed this sink/source it a bit confusing :).
    I have module-bluetooth-discover module loaded… what’s now?
    I’m not familiar with Bluetooth protocol stack… how can I connect to my PC? Shouldn’t be any A2DP service (or whatever) running on my PC?
    If you have little time would you please write a few steps?

    Thank you!!!
    Peter

  14. Peter, take a look at the slides I’ve just attached to a new post. There is an outline on how to stream audio between two computers using A2DP, BlueZ, and PulseAudio.

  15. Your documentation says “Stream A2DP between 2 BlueZ hosts”. Does it mean that both side needs BlueZ implementation?

    Anyway can’t find AudioSource dbus interface just Audio(bluez 4.51). It has a Connect method indeed. Should I use that one? It doesn’t take any parameters. How is it gonna find out which devices to connect? My devices (Htc Hero + PC(Bluez)) are paired already of course.

    Sorry maybe my questions are out of this subject.

    Thank You.

  16. In my example in the talk I’ve used two laptops running BlueZ, but you can use any other device that implements the A2DP Source service to send the stream. You can use ‘sdptool records BT_ADDRESS’ to check which services your device implements.

    About the AudioSource interface, did you enable it in audio.conf? Anyway, I’ve just published more detailed instructions about how to use the A2DP Sink, hope that helps!

  17. jean-jacques

    All sound nice. I had also think about such an implementation. Where can I find your sources ?

  18. Can we do that with alsa, and skip pulseaudio?

  19. Brian Landsberger

    I saw this a little while ago, is there an implementation that I can look at? Thanks!
    -b

  20. Every thing working fine without any error but i cant listen any sound in my speakers. in my mobile its playing for 5 seconds and disconnecting from audio source.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s