I have a question about a2dp sink profile in Android. I'm connected to other bluetooth device and I'm trying to play something from it but I can't hear sound.
Which place should I write some debugs to see that audio data are received and passed to rest of audio stack? I mean where are callbacks with audio data?
I was checking audio_a2dp_hw hal to it looks like it's not active in this type of connection.
Regards
Related
My application allows for users to transmit and receive audio, similar to a walkie talkie. Much like a walkie talkie, there is not always audio being transmitted/received, and we handle the audio focus as appropriate. Users are able to do this using both the phones built-in speaker + mic, and Bluetooth connected devices which provide speaker or mic. On Android 11, whenever my app is active while a Bluetooth device is connected, audio from other applications does not play.
As an example, say the user is using my app with a Bluetooth speaker mic connected. They are able to correctly receive (hear) my app audio through the Bluetooth device, and transmit (speak) audio through the Bluetooth device. However, if they attempt to play audio from another app, like say a video on YouTube - the video plays but the audio does not come through; either through the Bluetooth device or the phone speaker.
This incorrect behavior is new to my app on Android 11; audio works properly on prior versions of Android. Likewise, audio works properly when there is no connected Bluetooth audio device; other app audio plays as expected through the phone speaker when my app is not receiving/transmitting audio.
In my research into this issue, it appears there are some long-standing issues with Bluetooth on Android 11, with regards to both Android Auto and audio devices generally. My app utilizes the AudioManager SCO states to determine when an audio device is connected, and I suspect that a change in Android 11 related to this area is the culprit.
I haven't found many programmatic discussions about this issue, so if anyone has any ideas or suggestions about things to try, I would be most appreciative. Thanks for your time.
I am developing a custom hardware (peripheral) device that will communicate with Android smartphones through BLE. This device will have several capabilities, including the transmission of audio through GATT and keypresses through HID.
Is it somehow possible to re-route the BLE audio input to the Android OS if it was the internal device microphone? For instance, so that we could make voice searches using the default Google app, using the microphone on this external device. Can it be done without rooting the device, writing custom drivers or customize the kernel?
I found several similar threads on SO, but none with a specific solution for this issue (e.g., An extensive project: Streaming audio from microphone to Android device)
Thanks in advance!
It can be done. This is how I did it:
Have a service that talks to BLE Remote device and receives audio
Create a Audio HAL that implements an audio input.
Modify Audio Policy manager to use your HAL for Voice-recognition inputs
Send audio data from Service to HAL over any available IPC (I use socket)
Done.
There are other ways too. e.g. you could allow regular pairing but then intercept all audio messages from your device in fluoride and forward them to your, or A2DP HAL etc.
I'm trying to send audio over my cars speakers without having the cars audio input set to bluetooth. It supports the A2DP profile, and I also managed to get it to work. But that only works when I manually set the input to Bluetooth.
But I would like to 'force' the audio being sent over the speakers.
I previously had an iPhone. The Google Maps app would 'call' itself everything it would pronounce the directions. So my car would see it is an incoming call and play the audio over the speakers.
I looked around the internet, and it seems I need to use the HSF profile to pull of the same trick.
The documentation states that HSF is supported, but it does not show me how to do it. I also found exactly what I needed in the documentation. It states the following:
NOTE: up to and including API version JELLY_BEAN_MR1, this method initiates a virtual voice call to the bluetooth headset. After API version JELLY_BEAN_MR2 only a raw SCO audio connection is established.
So initiating virtual voice calls was possible. I would like to know how to do that now. Any other ideas on how to do this would also be very helpfull.
I have one android phone (Samsung S Duos) that will act as SOURCE and one Audio Development Kit i.e. CSR 8670 which will Act as SINK. I am trying to activate the a2dp profile and than transferring the incoming call of my phone (Samsung S Duos) to the Kit(CSR 8670) but not able to achieve it. Please assist me to overcome this problem.
A2DP uses ACL packets, voice calls (handsfree) uses SCO packets over the air.
The "Call" audio runs over SCO channel, so it is "technically" not possible to route calls to A2DP sink (unless you do some great hacks, which does not conform to the BT spec). Ideally you should use HFP for audio calls.
HCI can transport both ACL and SCO. BT chips often have PCM interface to which SCO data can be routed but usually its not accessible unless you can access the PINs of the chip.
Also, please try to ask some precise questions (with log/code) so that we can really assist you. If you ask some generic questions, it is difficult to answer.
I made a research on the same topic and found that android devices are a2dp sources and the audio can be streamed only from an a2dp source to an a2dp sink. A2dp sink can be a bluetooth headset or a bluetooth speaker.
But my question is then how the android app named "Bluetooth Music Player" works?
It allows streaming from one mobile to another. So in this case the listening mobile device must act as a sink. How this is possible?
Are they using some other profile instead of a2dp?
Ok, that may be a different profile what they are using. Because the application needs to be installed in the client side also.
But how it becomes possible to stream voice from a bluetooth microphone to an android device?
Please help.
Without knowing details about the mentioned Bluetooth Music Player, it seems to use simple Bluetooth data connection, otherwise you would not need to install a client on playing/sending device.
To stream audio from microphone to another device, you can record it on your sending device and send it to the receiving device. You will need to implement a protocol for that purpose.
OR
You can implement an alternative A2DP sink service. This is, what the sink is: a device with a Bluetooth Protocol Stack with an implementation of A2DP Sink.
Edit:
For the case you detailed by your comments, the sending device should be left as-is, without installing any app. That implicitly means that your solution must make use of out-of-the-box Bluetooth functionality of that Android device.
What you can use here is therefor limited to those profiles that Android typically support, which is HSP, HFP and A2DP. Since you obviously want to stream music, A2DP would be your choice.
On the device supposed to receive the audio stream and do the playback, you have to implement a service providing the A2DP sink as an self implemented BluetoothService opening a BluetoothServerSocket on RFCOMM as described in Android documentation.
You will have to spend much effort implementing this, and I am not sure if you will need a license for this.