mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-04-04 23:16:14 +00:00
Lower the buffer size of the Opus decoder based on the data we're actual receiving. Handle invocations of the decoder with null data for packet loss indication.
This commit is contained in:
@@ -11,7 +11,7 @@ public class AvAudioDepacketizer {
|
||||
private LinkedBlockingQueue<AvShortBufferDescriptor> decodedUnits =
|
||||
new LinkedBlockingQueue<AvShortBufferDescriptor>(15);
|
||||
|
||||
private AvShortBufferPool pool = new AvShortBufferPool(512);
|
||||
private AvShortBufferPool pool = new AvShortBufferPool(OpusDecoder.getMaxOutputShorts());
|
||||
|
||||
// Sequencing state
|
||||
private short lastSequenceNumber;
|
||||
@@ -21,34 +21,11 @@ public class AvAudioDepacketizer {
|
||||
pool.purge();
|
||||
}
|
||||
|
||||
public void decodeInputData(AvRtpPacket packet)
|
||||
private void decodeData(byte[] data, int off, int len)
|
||||
{
|
||||
short seq = packet.getSequenceNumber();
|
||||
|
||||
if (packet.getPacketType() != 97) {
|
||||
// Only type 97 is audio
|
||||
return;
|
||||
}
|
||||
|
||||
// Toss out the current NAL if we receive a packet that is
|
||||
// out of sequence
|
||||
if (lastSequenceNumber != 0 &&
|
||||
(short)(lastSequenceNumber + 1) != seq)
|
||||
{
|
||||
System.out.println("Received OOS audio data (expected "+(lastSequenceNumber + 1)+", got "+seq+")");
|
||||
|
||||
// Tell the decoder about this packet loss
|
||||
//OpusDecoder.decode(null, 0, 0, null);
|
||||
}
|
||||
|
||||
lastSequenceNumber = seq;
|
||||
|
||||
// This is all the depacketizing we need to do
|
||||
AvByteBufferDescriptor rtpPayload = packet.getNewPayloadDescriptor();
|
||||
|
||||
// Submit this data to the decoder
|
||||
short[] pcmData = pool.allocate();
|
||||
int decodeLen = OpusDecoder.decode(rtpPayload.data, rtpPayload.offset, rtpPayload.length, pcmData);
|
||||
int decodeLen = OpusDecoder.decode(data, off, len, pcmData);
|
||||
|
||||
if (decodeLen > 0) {
|
||||
// Return value of decode is frames decoded per channel
|
||||
@@ -66,6 +43,31 @@ public class AvAudioDepacketizer {
|
||||
}
|
||||
}
|
||||
|
||||
public void decodeInputData(AvRtpPacket packet)
|
||||
{
|
||||
short seq = packet.getSequenceNumber();
|
||||
|
||||
if (packet.getPacketType() != 97) {
|
||||
// Only type 97 is audio
|
||||
return;
|
||||
}
|
||||
|
||||
// Toss out the current NAL if we receive a packet that is
|
||||
// out of sequence
|
||||
if (lastSequenceNumber != 0 &&
|
||||
(short)(lastSequenceNumber + 1) != seq)
|
||||
{
|
||||
System.out.println("Received OOS audio data (expected "+(lastSequenceNumber + 1)+", got "+seq+")");
|
||||
decodeData(null, 0, 0);
|
||||
}
|
||||
|
||||
lastSequenceNumber = seq;
|
||||
|
||||
// This is all the depacketizing we need to do
|
||||
AvByteBufferDescriptor rtpPayload = packet.getNewPayloadDescriptor();
|
||||
decodeData(rtpPayload.data, rtpPayload.offset, rtpPayload.length);
|
||||
}
|
||||
|
||||
public void releaseBuffer(AvShortBufferDescriptor decodedData)
|
||||
{
|
||||
pool.free(decodedData.data);
|
||||
|
||||
Reference in New Issue
Block a user