Android Device as a Receiver for A2Dp Profile

Android device as a receiver for A2DP profile

Since Android L the BlueDriod stack does support A2DP sink, but it is disabled by default.

To enable it do the following:

/* Enable bluetooth av sink. */
#define BTA_AV_SINK_INCLUDED TRUE

in /external/bluetooth/bluedroid/include/bt_target.h.
This enables sink support in the bluetooth stack.

Also you have to do this change:

<!-- Enable sink support. -->
<bool name="profile_supported_a2dp_sink">true</bool>

in /packages/apps/Bluetooth/res/values/config.xml. This enables the particular UI.

Now you can pair your devices and start streaming. Unfortunately you will hear no sound although you'll receive the packets. The reason is that there is no audio route for A2DP sink. In the commit message of this patch https://android-review.googlesource.com/#/c/98161/ you can find a sample implementation on how to fix this.

Here is a list of these changes:

  • https://android-review.googlesource.com/#/c/97832/
  • https://android-review.googlesource.com/#/c/97853/
  • https://android-review.googlesource.com/#/c/97833/
  • https://android-review.googlesource.com/#/c/98130/
  • https://android-review.googlesource.com/#/c/98131/

How To Modify Android's Bluetooth Stack to Enable A2dp Sink

This is actually what I'm trying to do for a long time...
The reason you can't find the configuration file is because Google replaced the Bluetooth stack from BlueZ with a new stack built by Google and Broadcom. The new stack uses a different configuration file, which I don't know how to tinker with.

If you are serious about it, the closest thing I found to start with is the official introduction for the bluetooth framework on Android:
https://source.android.com/devices/bluetooth.html

Bluetooth A2DP profile

A bluetooth profile is a specification on the protocol and functionality of a bluetooth device. It is not just a hardware specification, because implementing a profile will often depend on both the software stack and the hardware chip. You can find more information from the wikipedia page.

And in the case of A2DP, it is specifically designed for music streaming. It cannot be used for arbitrary data communication (if that's what you mean by "sender and receiver"). If you are looking for a generic data communication mechanism over bluetooth transport, the Serial Port Profile (SPP) is what you need (some people also call it RFCOMM). Android SDK user guide has quite detailed information on how to use RFCOMM API: http://developer.android.com/guide/topics/wireless/bluetooth.html

need idea on sending/receiveing audio over A2DP between android/non-android device

There are two different A2DP profiles, A2DP source and A2DP sink. The A2DP source profile is supported by Android thus allowing you to stream music from your device to a sink like a bluetooth speaker. To my knowledge the A2DP sink profile is not enabled, which is why you're unable to stream music to your mobile phone and have it act as a speaker. I only know this from having googled around some time ago so things may have changed.

It is possible to enable the A2DP sink profile by editing /etc/bluetooth/audio.conf and rebooting your phone. Unfortunately this has the side-effect of disabling the A2DP source profile and thus cannot be used in a widely distributed app. The other downside is that there is not much of a java software stack for working with that profile so you'd have to do quite a bit of work to get things rolling.

To answer your question as to why a headset is able to connect to the Android, that is because headsets use a different profile called Headset profile (HSP), commonly used by headsets, or Handsfree profile (HFP) commonly used in cars. Both profiles have two sides: a client side and the gateway side (mobile phone). The audio quality of both of these profiles is considered voice quality. 8 or 16kHz sample rates and a crappy codec. There is also a lot of protocol for answering/making calls, etc... I'm not sure if you'd even get audio to transmit without an active connection to the phone network.

How to connect two android devices using a2dp and avrcp bluetooth profiles?

BluetoothProfileManager is only available for Android Things Devices, and it won't work with phones or tablets.

Another problem is that android device works as music source, not receiver, i.e., it has a2dp source profile and u cant change it in your application. This is only possible by modifying android source code.

So if u want to make one android device to act as bluetooth music receiver u need to make a few changes in AOSP.



Related Topics



Leave a reply



Submit