Wednesday 7 March 2012

Call for testing: BlueZ A2DP and HSP/HFP profiles

We just landed bluez 4.98-2ubuntu2 in Precise. The key change was to enable the Source and Gateway profiles by default, which will now allow people to use their system as an audio output device. It works great on Android, but any help in testing this on a bunch of different devices (especially on iPhone) would be much appreciated!

The Source profile is what enables the A2DP bluetooth profile. With it, you can use your system as a stereo audio output device: in other words, you can send output audio from an external device such as a phone or a tablet to your computer (though this will require a bit of work on the PulseAudio side to get the audio stream to go through the right devices).

There's the AskUbuntu question "Can I use my computer as an A2DP receiver?" that describes the steps to use this right now. Thanks to Steve Langasek for figuring out the details. I've also written a draft script that implements the suggested steps and makes it simple:

#!/bin/sh

BTSOURCE=`pactl list short sources | grep bluez_source | awk '{print $2;}'`
SINK=`pactl list short sinks | grep -v Monitor | grep alsa_output.pci | awk '{ print $2; }'`

case $1 in
enable)
 pactl load-module module-loopback source=$BTSOURCE sink=$SINK
 ;;
disable)
 pactl unload-module $(pactl list short modules | grep loopback | grep $BTSOURCE | cut -f 1) || true
 ;;
esac 

That script is meant to be called as '"whatever_you_named_it" enable'. Don't forget the "enable" part, or "disable" to turn off the streams, otherwise it won't work.

The Gateway profile enables the HSP/HFP bluetooth profiles. This means we're getting closer to supporting phone calls from a bluetooth-connected phone on a Ubuntu computer. There's already some amounts of support for this via Ofono and the telepathy-ring project, although there is some extra work needed -- hopefully we can fix this by the Precise release. :D

7 comments:

Anonymous said...

This almost works on my up-to-date precise system:

$ sdptool search --bdaddr local a2snk
Searching for a2snk on FF:FF:FF:00:00:00 ...
Service Name: Audio Sink
Service RecHandle: 0x10005
Service Class ID List:
"Audio Sink" (0x110b)
Protocol Descriptor List:
"L2CAP" (0x0100)
PSM: 25
"AVDTP" (0x0019)
uint16: 0x102
Profile Descriptor List:
"Advanced Audio" (0x110d)
Version: 0x0102

but mysteriously

$ pactl list short sources
0 alsa_output.pci-0000_00_1b.0.hdmi-stereo-extra2.monitor module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
1 alsa_input.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED

I have no bluez source according to pulseaudio. Any idea what's going wrong for me?

Matt Trudel said...

It's unclear. Perhaps the device isn't properly being detected.

The way I'd verify this would be to file a bug on Launchpad, and include the debugging logs from pulseaudio before pairing the device (or enabling the connection, really); which is done by sending the "set-log-level 4" command in pacmd (then the logs will appear in /var/log/syslog); and debugging logs from bluez (sudo stop bluetooth && /usr/sbin/bluetoothd -n -d).

juantascon said...

hi! could you please provide a bit more info on how to test this on android, I've tried by changing my audio.conf but it seems like I'm missing something else, perhaps something like what you are doing with pulse here but doing it with audioflinger?

Matt Trudel said...

juantascon: I'm not sure I understand what you mean. For Android, all that is needed is to possibly remove the current pairing and do a new one, so that all the right bluetooth profiles are detected.

karfes said...

I have streaming from android (ideos U8150)working quite well, though i had to hack a little by editing the file:
"/system/etc/bluetooth/audio.conf"
on the android system which required read-write "rw" remount of the system using the command:
"mount -o rw,remount -t yaffs2 /dev/block/mtdblock4 /system"
where "/dev/block/mtdblock4" and "/system" was figured out using the command " cat /proc/mounts" as the system and mount point(install and use a terminal app on android for checking using cat and remounting, and also changing the permissions of the file so its editable using "chmod permissions /path_to_file"). that file contains a section for enabling audio Headset, Control, source and sink, its well documented. All you gotta do is pull it to PC using "adb pull /system/etc/bluetooth/audio.conf ~/audio.conf" and edit the file ~/audio.conf accordingly, save and do "adb push ~/audio.conf /system/etc/bluetooth/audio.conf"(this uses phone debug via usb cable)
and switch bleutooth off, then on, on the phone. then use blueman applet on precise to pair, list services and connect to your phone. Also you have to make your phone ubuntu bluetooth discoverable, basic steps... and use pulseaudio volume controller to select audio source. just click on ua phone if listed, if not use the drop-down menu on pulseaudio to select "show all" under sources. Thats all.

Sun said...

Any clues on integrating A2DP sink feature on Android mobile devices using the Bluez capabilities. I mean to use ANdroid phone to behave like a BT headset to play music from some other devices like PC or another smart phone?

Donny Kurnia said...

It's work on my devices:
- iPhone 3Gs iOS 6.1
- Ubuntu 12.10 on Thinkpad Edge E125

Just one small fix. When I run this:
➜ pactl list short sinks | grep -v Monitor | grep alsa_output.pci

I got 2 line result:

0 alsa_output.pci-0000_00_01.1.hdmi-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
1 alsa_output.pci-0000_00_14.2.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED

So I modify your script:

SINK=`pactl list short sinks | grep -v Monitor | grep alsa_output.pci | grep analog | awk '{ print $2; }'`