Reduce GC pressure significantly by using a single 100 byte buffer for all audio data instead of allocating 1500 bytes for each audio packet received

This commit is contained in:
Cameron Gutman 2014-03-13 21:53:10 -04:00
parent 7e30d043eb
commit 3af3df0544

View File

@ -17,6 +17,7 @@ public class AudioStream {
public static final int RTCP_PORT = 47999;
public static final int RTP_RECV_BUFFER = 64 * 1024;
public static final int MAX_PACKET_SIZE = 100;
private DatagramSocket rtp;
@ -142,7 +143,7 @@ public class AudioStream {
Thread t = new Thread() {
@Override
public void run() {
ByteBufferDescriptor desc = new ByteBufferDescriptor(new byte[1500], 0, 1500);
ByteBufferDescriptor desc = new ByteBufferDescriptor(new byte[MAX_PACKET_SIZE], 0, MAX_PACKET_SIZE);
DatagramPacket packet = new DatagramPacket(desc.data, desc.length);
while (!isInterrupted())
@ -150,9 +151,11 @@ public class AudioStream {
try {
rtp.receive(packet);
desc.length = packet.getLength();
// DecodeInputData() doesn't hold onto the buffer so we are free to reuse it
depacketizer.decodeInputData(new RtpPacket(desc));
desc.reinitialize(new byte[1500], 0, 1500);
packet.setData(desc.data, desc.offset, desc.length);
packet.setLength(MAX_PACKET_SIZE);
} catch (IOException e) {
connListener.connectionTerminated(e);
return;