mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-21 03:52:48 +00:00
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:
parent
7e30d043eb
commit
3af3df0544
@ -17,6 +17,7 @@ public class AudioStream {
|
|||||||
public static final int RTCP_PORT = 47999;
|
public static final int RTCP_PORT = 47999;
|
||||||
|
|
||||||
public static final int RTP_RECV_BUFFER = 64 * 1024;
|
public static final int RTP_RECV_BUFFER = 64 * 1024;
|
||||||
|
public static final int MAX_PACKET_SIZE = 100;
|
||||||
|
|
||||||
private DatagramSocket rtp;
|
private DatagramSocket rtp;
|
||||||
|
|
||||||
@ -142,7 +143,7 @@ public class AudioStream {
|
|||||||
Thread t = new Thread() {
|
Thread t = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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);
|
DatagramPacket packet = new DatagramPacket(desc.data, desc.length);
|
||||||
|
|
||||||
while (!isInterrupted())
|
while (!isInterrupted())
|
||||||
@ -150,9 +151,11 @@ public class AudioStream {
|
|||||||
try {
|
try {
|
||||||
rtp.receive(packet);
|
rtp.receive(packet);
|
||||||
desc.length = packet.getLength();
|
desc.length = packet.getLength();
|
||||||
|
|
||||||
|
// DecodeInputData() doesn't hold onto the buffer so we are free to reuse it
|
||||||
depacketizer.decodeInputData(new RtpPacket(desc));
|
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) {
|
} catch (IOException e) {
|
||||||
connListener.connectionTerminated(e);
|
connListener.connectionTerminated(e);
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user