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:
@@ -74,10 +74,13 @@ Java_com_ts3client_android_audio_NativeOpus_decoderCreate(JNIEnv *env, jclass, j
|
||||
return reinterpret_cast<jlong>(created);
|
||||
}
|
||||
|
||||
/** Decodes {@code packet}, or conceals {@code frameSize} samples when it is null. */
|
||||
/**
|
||||
* Decodes {@code packet}, or conceals {@code frameSize} samples when it is null; with {@code fec},
|
||||
* rebuilds the packet before {@code packet} from its error correction copy.
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_ts3client_android_audio_NativeOpus_decode(JNIEnv *env, jclass, jlong handle, jbyteArray packet,
|
||||
jfloatArray out, jint frameSize) {
|
||||
jfloatArray out, jint frameSize, jboolean fec) {
|
||||
std::vector<unsigned char> data;
|
||||
if (packet != nullptr) {
|
||||
data.resize(static_cast<size_t>(env->GetArrayLength(packet)));
|
||||
@@ -85,7 +88,7 @@ Java_com_ts3client_android_audio_NativeOpus_decode(JNIEnv *env, jclass, jlong ha
|
||||
}
|
||||
jfloat *samples = env->GetFloatArrayElements(out, nullptr);
|
||||
int decoded = opus_decode_float(decoder(handle), packet != nullptr ? data.data() : nullptr,
|
||||
static_cast<opus_int32>(data.size()), samples, frameSize, 0);
|
||||
static_cast<opus_int32>(data.size()), samples, frameSize, fec ? 1 : 0);
|
||||
env->ReleaseFloatArrayElements(out, samples, decoded < 0 ? JNI_ABORT : 0);
|
||||
if (decoded < 0) throwOpus(env, "opus_decode_float", decoded);
|
||||
return decoded;
|
||||
|
||||
@@ -68,12 +68,17 @@ public final class NativeOpus implements OpusCodec {
|
||||
|
||||
@Override
|
||||
public int decode(byte[] packet, float[] out) {
|
||||
return NativeOpus.decode(live(), packet, out, maxFrameSize);
|
||||
return NativeOpus.decode(live(), packet, out, maxFrameSize, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int conceal(float[] out, int frameSize) {
|
||||
return NativeOpus.decode(live(), null, out, Math.min(frameSize, maxFrameSize));
|
||||
return NativeOpus.decode(live(), null, out, Math.min(frameSize, maxFrameSize), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int recover(byte[] next, float[] out, int frameSize) {
|
||||
return NativeOpus.decode(live(), next, out, Math.min(frameSize, maxFrameSize), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,7 +109,7 @@ public final class NativeOpus implements OpusCodec {
|
||||
|
||||
private static native long decoderCreate(int sampleRate, int channels);
|
||||
|
||||
private static native int decode(long handle, byte[] packet, float[] out, int frameSize);
|
||||
private static native int decode(long handle, byte[] packet, float[] out, int frameSize, boolean fec);
|
||||
|
||||
private static native void decoderReset(long handle);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user