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:
@@ -420,6 +420,7 @@ class SessionController(private val context: Context) {
|
||||
for (server in _servers.value) {
|
||||
server.playback?.setMasterVolume(settings.outputVolume)
|
||||
server.playback?.setOutputDevice(settings.outputDevice)
|
||||
server.playback?.setReceiveBuffer(settings.receiveBuffer)
|
||||
server.microphone?.apply(settings)
|
||||
server.refresh()
|
||||
server.scheduleTree(structure = false)
|
||||
|
||||
@@ -18,7 +18,7 @@ import kotlin.math.roundToInt
|
||||
private const val MIN_BITRATE_KBITS = 8f
|
||||
private const val MAX_BITRATE_KBITS = 160f
|
||||
|
||||
/** What voice costs and survives on the wire: bitrate, error correction and duplicate packets. */
|
||||
/** What voice costs and survives on the wire: bitrate, error correction, duplicate packets and receive buffering. */
|
||||
@Composable
|
||||
fun NetworkSettingsScreen(vm: SessionController, onBack: () -> Unit) {
|
||||
val settings = vm.settings
|
||||
@@ -30,6 +30,7 @@ fun NetworkSettingsScreen(vm: SessionController, onBack: () -> Unit) {
|
||||
var fec by remember { mutableStateOf(settings.fec) }
|
||||
var redundancy by remember { mutableStateOf(settings.redundancyDelay) }
|
||||
var copies by remember { mutableStateOf(settings.redundancyCopies) }
|
||||
var receiveBuffer by remember { mutableStateOf(settings.receiveBuffer) }
|
||||
|
||||
SubScreen("Network", onBack) { padding ->
|
||||
Column(Modifier.padding(padding).verticalScroll(rememberScrollState()).padding(bottom = 8.dp)) {
|
||||
@@ -57,6 +58,12 @@ fun NetworkSettingsScreen(vm: SessionController, onBack: () -> Unit) {
|
||||
change { redundancyCopies = it }
|
||||
}
|
||||
}
|
||||
|
||||
Section("Receive")
|
||||
Picker("Extra buffering", Settings.RECEIVE_BUFFERS.map { it to if (it == 0) "Off" else "$it ms" }, receiveBuffer) {
|
||||
receiveBuffer = it
|
||||
change { this.receiveBuffer = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ fun SettingsScreen(vm: SessionController, onContacts: () -> Unit, onBack: () ->
|
||||
LinkRow("Sound Settings", "Devices, transmission, voice activation, processing, volume", "PLAYBACK") {
|
||||
page = SettingsPage.SOUND
|
||||
}
|
||||
LinkRow("Network", "Bitrate, error correction, redundancy", "PING_4") {
|
||||
LinkRow("Network", "Bitrate, error correction, redundancy, buffering", "PING_4") {
|
||||
page = SettingsPage.NETWORK
|
||||
}
|
||||
LinkRow("Design", "Icon pack, country flags, description pictures", "GUISETUP") {
|
||||
|
||||
@@ -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