Tag Archives: gsoc09

1, 2, 3, 4, A2DP Stream

After a few people asking me how to use the A2DP Sink with BlueZ, I’ve decided to write this mini-tutorial with a step-by-step on how to establish a A2DP stream from any device to a BlueZ-enabled host.

Before we start the hands-on, let’s see a little bit of nomenclature. In our use-case we have an stream being transmitted between two devices through a pipeline. Our pipeline is constructed of the remote host, BlueZ and PulseAudio. Each element of this pipeline has a Source (SRC) and a Sink (SNK) interface. The stream is handled between different elements by being sent from one element’s source to another element’s sink. So, the big picture of our pipeline is something like this (with the stream being represented by an arrow):

Remote-SRC ----> SNK-BlueZ-SRC ----> SNK-PulseAudioBT-SRC

With the PulseAudio bluetooth source being available for applications to connect to it and serve themselves with fresh, just-decoded PCM frames of pure stereo audio. In our example, we gonna add another element to the pipeline tho. In order to able to hear the audio we’re receiving, we gonna connect the PulseAudio bluetooth source to a PulseAudio ALSA sink which pushes the audio out through our soundcard speakers.

PulseAudioBT-SRC ----> SNK-PulseAudioALSA ----> SoundCard

So after these lines on theory, let’s get out hands dirty. First of all, you need a recent version of BlueZ and PulseAudio. BlueZ 4.46 and PulseAudio 0.9.16 should be enough, but I strongly recommend getting the newest releases available by the time you read this. Right now the most recent releases are BlueZ 4.58 and PulseAudio 0.9.21.

  1. PulseAudio must be running with module-bluetooth-discover loaded;
    • This module is automatically loaded on startup with the default configuration;
    • If it’s not loaded you can use pactl to load it manually or configure PulseAudio to load it on startup in /etc/pulse/default.pa;
  2. Enable the Source interface on BlueZ:
    • edit /etc/bluetooth/audio.conf and add the following line: Enable=Source ;
    • restart bluetoothd;
  3. Pair both devices;
  4. On the object path representing the remote host, on org.bluez D-Bus service, call the org.bluez.AudioSource.Connect() method;
    • For the connection to succeed you’ll probably have to grant access on the remote host;
    • When the connection is established, a new card should show up on PulseAudio with one source available;
  5. Connect PulseAudio bluetooth source to PulseAudio ALSA sink;
    • load-module module-loopback source=<name> sink=<name>
    • You can use the line above to load the module-loopback, using pactl (on the command line) or inside pacmd shell;
    • To find out the name of the source and the sink, you can use the commands list-sources and list-sinks inside pacmd shell;
    • This step is only needed if you want to send the audio coming through A2DP to your speakers.

It’s important to remember that the current implementation is working but could see some improvements, so expect to hear some glitches if you go through signal variation. Happy bluetooth audio streaming!

Advertisements

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.

GSoC09 is up and running!

I’m glad to announce that I was accepted for one more Google Summer of Code program. I’m going to work with BlueZ again, this year to implement the A2DP sink profile. Full proposal following.

Abstract

This project is to implement the Sink role on BlueZ, according to the A2DP specification v1.2. This role provide means to receive an audio stream coming from an audio Source on the same piconet. It’s very important, and can add several use cases for the Linux bluetooth stack, like Linux to Linux streams, bluetooth microphones support or using a Linux device as bluetooth speakers. It’s also a mandatory feature for an implementation to be full compliant with A2DP v1.2.

Content

Have you worked on a Linux system before?

I’ve been working with Linux since 2002, when I’ve started the Computer Engineering undergrad. In the beginning I just did the school projects on Linux, but since the middle of 2002 it’s my main system. By that time I had Conectiva on my home computer, RedHat on the school, and Slackware on my home router. After a few years I got in touch with Gentoo, and I liked so much the idea that it became my main distro. In addition, I’ve also started working on a project at University of Campinas, to make a Linux distribution for Itautec, a brazilian IT company, which was Gentoo based. Nowadays I’m using Ubuntu in my laptop, because of the speedy install and no need of much tweaking, so I have more time to work with other projects, but I’m confortable using and administrating any distribution.

Have you contributed to a open source project? if yes, please provide the details

My first contribution was a little bit frustrating, since I never got any answer (a two lines patch to python-dialog – http://sourceforge.net/projects/pythondialog/ – to support one dialog that was missing). After that I’ve made some performance improvements in ImageMagick and DevIL using OpenMP, both of them being accepted upstream. I was also accepted and successfully completed a GSoC 08 project with BlueZ to make the bluetooth audio client for PulseAudio. All these successful experiences were outstanding and all of them (now including the never answered patch) were very useful to learn about the community and how to work with open source model. Now I’m looking for a job with open source, and also plan to continue contributing to some projects of my personal interest. Right now I’m following the BlueZ and PulseAudio mailing lists.

What is your educational Qualification (grad/under-grad) ?

I’m a Computer Engineer, majored on University of Campinas (Unicamp), Brazil. I’ve started my master degree on Computer Science studies last year, on the same university, working with visualization of concurrent algorithms. I’ve also been working as a teaching assistant of the Operating Systems course in my university, for two semesters. The last time we proposed to the students to make some changes in a memory filesystem that was developed for them to work on. This activity is giving me a bit more of knowledge on the Linux kernel, that maybe can be helpful to complete this project.

Why do you want to do a project involving Bluetooth/BlueZ ?

I’ve already been a GSoC student with BlueZ and was a very good experience. I’ve worked with the same protocol of this project, so I already have some knowledge on it. The initial motivation to choose BlueZ last year was because it’s something that I use on my daily activities (I have a bluetooth mouse on my notebook and a headset that I use to talk with friends and family on VoIP systems) and because I’m very enthusiastic about wireless devices and mobility. Besides that, I always had interest about network-related stuff.

If your application is accepted will it be a part of your graduation process or it will it be just for hobby?

If I get accepted to this project, it will not be part of my graduation process.

Give us an *estimative* of your schedule (exams period, etc.) and how much time you would be able to dedicate to the project.

The project will be divided into 5 activities. I plan to work around 20h per week with this project, during the whole program. The other 20h of a working week are going to be dedicated to my Master degree program, but it’s flexible enough to allow me some extra hours near deadlines, if needed.

1. Re-read the A2DP specification v1.2 from bluetooth.com (and related specs like AVDTP, GAVDP etc) and understand it’s current implementation. The A2DP Sink role is the dual of the A2DP Source role, with the main difference being the implementation of the “Receive Audio Stream” procedure, described in Section 3.2.2 of the spec, instead of the “Send Audio Stream procedure”. Together with this study of the spec, the code under the audio dir on BlueZ source code will be studied, to learn exactly what’s implemented and which files implement each part.

2. Maybe reorganize some code to enable reuse. If there are some already implemented parts for the Source which the Sink is also going to use (likely the AVDTP signaling procedures), the idea is to use the same implementation to minimize bugs and easy the maintenance.

3. Find out which are the missing parts and procedures to full support the Sink role and implement them.

4. Create the API for clients that want to obtain the audio received by BlueZ and export it via D-Bus, as it already done for the Source profile (which acts as a sink for software clients like media players).

Community Bounding Period (April 20th – May 22nd): Activities 1 and 2 are going to be performed on this period.

Coding Phase I (May 23rd – July 12nd): Most of activity 3 is going to be performed on this period.

Coding Phase II (July 13rd – August 17th): Finish of activity 3 and activity 4 are going to be performed on this period.

Future Work: If there is enough time, or as a future project, I would like to implement a client that uses the bluetooth audio somehow, in order to test the Sink implementation. My first idea is to do so on PulseAudio, as I’ve already worked with it before, but other ideas are also welcome.

GSoC09 Talk at University of Campinas

This week we made a talk about the Google Summer of Code program at the University of Campinas. The talk was part of a serie of seminars about free software, that are held as course of the Institute of Computing in this university. We were five people on speech, all of us past GSoC’ers, some for more than one edition. The main focus of the talk was not just to tell people about what the GSoC program is, but also to tell people how participating in GSoC was a great experience to all of us. In adition, we tried to give people some tips on what to do in order to get accepted and sucessfully complete the program, and also left an open channel to support them during the application process.

We started with the oficial program slides, to tell people what exactly the GSoC program consists of. After that, we showed some statistical data about our university in the program, since we were ranked 2nd both on number of applicants and accepted applications. Then, we had a look at the list of mentoring organizations for last year, and showed then how to get to the ideas list of each org, how to find their bugzilla, feature requests, etc. After, we tried to teach them a little on how to write a good application, how to get in touch with the mentoring organization, and some what-not-to-do’s in a FOSS community. To finish, each of us told a little bit about his own experience on past GSoC’s and opened to questions.

This serie of seminars has the support of the GPSL (a student’s group to promote FOSS), which all speakers are members of, and of the FSFLA, so in the end we all got a FSFLA pen as a stipend!

The speakers were Bruno Cardoso, Bruno Dilly, Luis Felipe Strano Moraes, João Batista Correa Gomes Moreira, and João Paulo Rechi Vita (me).

The talk
The talk
People asking questions at the end
People asking questions at the end
The audience
The audience