简体   繁体   中英

Capturing RTP packets from sockets in android

I am using rtp stream to stream pcm(16kHz) data from remote server to android device. Using audiotrack seems to be right approach to play pcm audio . I am just looking for a way to capture the rtp packets from the server and can write it in audiotrack.write() . This is what I have got so far.

int bufsize = AudioTrack.getMinBufferSize(16000,
AudioFormat.CHANNEL_OUT_STEREO,
AudioFormat.ENCODING_PCM_16BIT);

AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
                                                    16000,
                          AudioFormat.CHANNEL_OUT_STEREO,
                          AudioFormat.ENCODING_PCM_16BIT,
                          bufsize,
                          AudioTrack.MODE_STREAM);
audioTrack.play();

But writing data is where I am bit confused about.How can I feed the incoming rtp packets from sockets.

audioTrack.write(byte[], int, int);

I got stuck here and looking for some guidance on how to approach it ? Any type of material to proceed forward would be helpful. Thank you.

Once you read the data from the udp socket.

Remove the 12 Bytes RTP header (rfc 3550), you will get the payload (PCM data),

you can pass the pcm data to audio track.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM