I would like to do audio live streaming over WiFi between 2 Android devices.

In order to reduce the audio latency, applying the Oboe C++ library seems to be a right direction to go.

My current structure is to use DatagramPacket to transmit and receive the audio data. The data type of the buffer holding the incoming datagram is byte[]. According to my study, I need to pass the data from the byte[] buffer through JNI (Java Native Interface) and then read the data into a non-blocking queue? (ex: https://github.com/google/oboe/blob/master/samples/RhythmGame/src/main/cpp/utils/LockFreeQueue.h)

If I understand correctly, there is no byte[] data type in C++, so I have to convert the byte[] (jbyteArray in JNI) to the data type (ex: int16_t)?

However, I am not very sure how to implement such a conversion? Or even I am in a wrong direction?

Any suggestions or sample code would be highly appreciated!

Thank you very much!

1

There are 1 answers

0
Botje On

I suggest you look into using a pool of direct ByteBuffers. These objects wrap a blob of native memory and can be accessed directly from C++.

When you receive a packet from the network, take a free ByteBuffer from the pool, copy the packet contents into it, and mark the buffer as taken somehow. (by adding it to a taken queue?) Then, add the pointer + size to a queue that C++ can access.

In the Oboe onAudioReady callback, you can then simply take elements off that queue and copy their contents to Oboe's data buffer. Tell the Java world how many elements were consumed so it can recycle the buffers back to the free pool.