From 3af3df0544605277c29215196601f0097d1728a0 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 13 Mar 2014 21:53:10 -0400 Subject: [PATCH] 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 --- .../src/com/limelight/nvstream/av/audio/AudioStream.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/moonlight-common/src/com/limelight/nvstream/av/audio/AudioStream.java b/moonlight-common/src/com/limelight/nvstream/av/audio/AudioStream.java index 11567487..190ec4ab 100644 --- a/moonlight-common/src/com/limelight/nvstream/av/audio/AudioStream.java +++ b/moonlight-common/src/com/limelight/nvstream/av/audio/AudioStream.java @@ -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;