From 8c3b23e31c1a1c74b06f0a38a31a490d04d1fe09 Mon Sep 17 00:00:00 2001 From: Diego Waxemberg Date: Fri, 13 Dec 2013 12:26:46 -0500 Subject: [PATCH] Drop audio samples if buffer space is not available to preserve real-time audio behavior --- .../com/limelight/binding/audio/JavaxAudioRenderer.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/limelight-pc/src/com/limelight/binding/audio/JavaxAudioRenderer.java b/limelight-pc/src/com/limelight/binding/audio/JavaxAudioRenderer.java index d4af9ca..e6f94f2 100644 --- a/limelight-pc/src/com/limelight/binding/audio/JavaxAudioRenderer.java +++ b/limelight-pc/src/com/limelight/binding/audio/JavaxAudioRenderer.java @@ -20,7 +20,12 @@ public class JavaxAudioRenderer implements AudioRenderer { if (soundLine != null) { byte[] pcmDataBytes = new byte[length * 2]; ByteBuffer.wrap(pcmDataBytes).asShortBuffer().put(pcmData, offset, length); - soundLine.write(pcmDataBytes, 0, pcmDataBytes.length); + if (soundLine.available() < length) { + soundLine.write(pcmDataBytes, 0, soundLine.available()); + } + else { + soundLine.write(pcmDataBytes, 0, pcmDataBytes.length); + } } } @@ -37,7 +42,7 @@ public class JavaxAudioRenderer implements AudioRenderer { DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat, OpusDecoder.getMaxOutputShorts()); try { soundLine = (SourceDataLine) AudioSystem.getLine(info); - soundLine.open(audioFormat, 131072); + soundLine.open(audioFormat, OpusDecoder.getMaxOutputShorts()*4*2); soundLine.start(); } catch (LineUnavailableException e) { soundLine = null;