Add extra receive buffering and decode Opus FEC on loss
A new Extra buffering setting (Network page) holds more playback delay than the jitter buffer measures it needs, so late packets still make it in time on a bad connection. A lost frame is now rebuilt from the FEC copy in the next packet when that one is already held, and the Connection Info shows how many were recovered. Held packets' arrival marks now move with the timeline when the delay changes; libspeex leaves them, which made a multi-frame jump count twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+13
-4
@@ -54,17 +54,26 @@ final class NativeOpusDecoder implements OpusDecoder {
|
||||
throw new IllegalArgumentException("packet too large: " + packet.length);
|
||||
}
|
||||
MemorySegment.copy(packet, 0, packetBuffer, ValueLayout.JAVA_BYTE, 0, packet.length);
|
||||
return decode(packetBuffer, packet.length, out, frameSize);
|
||||
return decode(packetBuffer, packet.length, out, frameSize, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int conceal(float[] out, int frameSize) {
|
||||
return decode(MemorySegment.NULL, 0, out, Math.min(frameSize, this.frameSize));
|
||||
return decode(MemorySegment.NULL, 0, out, Math.min(frameSize, this.frameSize), 0);
|
||||
}
|
||||
|
||||
private int decode(MemorySegment data, int len, float[] out, int maxSamples) {
|
||||
@Override
|
||||
public int recover(byte[] next, float[] out, int frameSize) {
|
||||
if (next.length > MAX_PACKET_BYTES) {
|
||||
throw new IllegalArgumentException("packet too large: " + next.length);
|
||||
}
|
||||
MemorySegment.copy(next, 0, packetBuffer, ValueLayout.JAVA_BYTE, 0, next.length);
|
||||
return decode(packetBuffer, next.length, out, Math.min(frameSize, this.frameSize), 1);
|
||||
}
|
||||
|
||||
private int decode(MemorySegment data, int len, float[] out, int maxSamples, int fec) {
|
||||
if (closed) throw new IllegalStateException("decoder closed");
|
||||
int samples = Opus.decodeFloat(handle, data, len, pcmBuffer, maxSamples, 0);
|
||||
int samples = Opus.decodeFloat(handle, data, len, pcmBuffer, maxSamples, fec);
|
||||
if (samples < 0) {
|
||||
throw new IllegalStateException("opus_decode_float failed: " + Opus.strerror(samples));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user