diff --git a/moonlight-common/src/com/limelight/nvstream/av/ShortBufferDescriptor.java b/moonlight-common/src/com/limelight/nvstream/av/ShortBufferDescriptor.java deleted file mode 100644 index 44cd2d8e..00000000 --- a/moonlight-common/src/com/limelight/nvstream/av/ShortBufferDescriptor.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.limelight.nvstream.av; - -public class ShortBufferDescriptor { - public short[] data; - public int offset; - public int length; - - public ShortBufferDescriptor(short[] data, int offset, int length) - { - this.data = data; - this.offset = offset; - this.length = length; - } - - public ShortBufferDescriptor(ShortBufferDescriptor desc) - { - this.data = desc.data; - this.offset = desc.offset; - this.length = desc.length; - } - - public void reinitialize(short[] data, int offset, int length) - { - this.data = data; - this.offset = offset; - this.length = length; - } -} diff --git a/moonlight-common/src/com/limelight/nvstream/av/audio/AudioDepacketizer.java b/moonlight-common/src/com/limelight/nvstream/av/audio/AudioDepacketizer.java index 0e1a9db6..3c8e634d 100644 --- a/moonlight-common/src/com/limelight/nvstream/av/audio/AudioDepacketizer.java +++ b/moonlight-common/src/com/limelight/nvstream/av/audio/AudioDepacketizer.java @@ -4,13 +4,15 @@ import java.util.concurrent.LinkedBlockingQueue; import com.limelight.nvstream.av.ByteBufferDescriptor; import com.limelight.nvstream.av.RtpPacket; -import com.limelight.nvstream.av.ShortBufferDescriptor; +import com.limelight.nvstream.av.ByteBufferDescriptor; +import java.nio.ByteBuffer; +import java.nio.ShortBuffer; public class AudioDepacketizer { private static final int DU_LIMIT = 15; - private LinkedBlockingQueue decodedUnits = - new LinkedBlockingQueue(DU_LIMIT); + private LinkedBlockingQueue decodedUnits = + new LinkedBlockingQueue(DU_LIMIT); // Sequencing state private short lastSequenceNumber; @@ -18,15 +20,15 @@ public class AudioDepacketizer { private void decodeData(byte[] data, int off, int len) { // Submit this data to the decoder - short[] pcmData = new short[OpusDecoder.getMaxOutputShorts()]; + byte[] pcmData = new byte[OpusDecoder.getMaxOutputShorts()*2]; int decodeLen = OpusDecoder.decode(data, off, len, pcmData); if (decodeLen > 0) { - // Return value of decode is frames decoded per channel - decodeLen *= OpusDecoder.getChannelCount(); + // Return value of decode is frames (shorts) decoded per channel + decodeLen *= 2*OpusDecoder.getChannelCount(); // Put it on the decoded queue - if (!decodedUnits.offer(new ShortBufferDescriptor(pcmData, 0, decodeLen))) { + if (!decodedUnits.offer(new ByteBufferDescriptor(pcmData, 0, decodeLen))) { System.out.println("Audio player too slow! Forced to drop decoded samples"); // Clear out the queue decodedUnits.clear(); @@ -59,7 +61,7 @@ public class AudioDepacketizer { decodeData(rtpPayload.data, rtpPayload.offset, rtpPayload.length); } - public ShortBufferDescriptor getNextDecodedData() throws InterruptedException + public ByteBufferDescriptor getNextDecodedData() throws InterruptedException { return decodedUnits.take(); } diff --git a/moonlight-common/src/com/limelight/nvstream/av/audio/AudioRenderer.java b/moonlight-common/src/com/limelight/nvstream/av/audio/AudioRenderer.java index ebffda58..a7125998 100644 --- a/moonlight-common/src/com/limelight/nvstream/av/audio/AudioRenderer.java +++ b/moonlight-common/src/com/limelight/nvstream/av/audio/AudioRenderer.java @@ -3,7 +3,7 @@ package com.limelight.nvstream.av.audio; public interface AudioRenderer { public void streamInitialized(int channelCount, int sampleRate); - public void playDecodedAudio(short[] audioData, int offset, int length); + public void playDecodedAudio(byte[] audioData, int offset, int length); public void streamClosing(); } 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 ff635b2b..d401f9cd 100644 --- a/moonlight-common/src/com/limelight/nvstream/av/audio/AudioStream.java +++ b/moonlight-common/src/com/limelight/nvstream/av/audio/AudioStream.java @@ -12,7 +12,7 @@ import java.util.concurrent.LinkedBlockingQueue; import com.limelight.nvstream.NvConnectionListener; import com.limelight.nvstream.av.ByteBufferDescriptor; import com.limelight.nvstream.av.RtpPacket; -import com.limelight.nvstream.av.ShortBufferDescriptor; +import com.limelight.nvstream.av.ByteBufferDescriptor; public class AudioStream { public static final int RTP_PORT = 48000; @@ -140,7 +140,7 @@ public class AudioStream { public void run() { while (!isInterrupted()) { - ShortBufferDescriptor samples; + ByteBufferDescriptor samples; try { samples = depacketizer.getNextDecodedData(); diff --git a/moonlight-common/src/com/limelight/nvstream/av/audio/OpusDecoder.java b/moonlight-common/src/com/limelight/nvstream/av/audio/OpusDecoder.java index c01f7fa5..a3d6d740 100644 --- a/moonlight-common/src/com/limelight/nvstream/av/audio/OpusDecoder.java +++ b/moonlight-common/src/com/limelight/nvstream/av/audio/OpusDecoder.java @@ -10,5 +10,5 @@ public class OpusDecoder { public static native int getChannelCount(); public static native int getMaxOutputShorts(); public static native int getSampleRate(); - public static native int decode(byte[] indata, int inoff, int inlen, short[] outpcmdata); + public static native int decode(byte[] indata, int inoff, int inlen, byte[] outpcmdata); }