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:
2026-10-06 20:38:20 +00:00
co-authored by Claude Opus 5.5
parent 5ec4204d1d
commit 70aac6f5ce
20 changed files with 210 additions and 39 deletions
@@ -964,13 +964,14 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
dlg.setVisible(true);
}
/** Master volume / output device are global, so push them to every open connection. */
/** Master volume, output device and receive buffer are global, so push them to every open connection. */
private void applyOutputSettingsToAllTabs() {
soundPlayer.setOutputDevice(settings.outputDevice);
for (ServerTab tab : tabs) {
if (tab.connection().getPlayback() == null) continue;
tab.connection().getPlayback().setMasterVolume(settings.effectiveOutputVolume());
tab.connection().getPlayback().setOutputDevice(settings.outputDevice);
tab.connection().getPlayback().setReceiveBuffer(settings.receiveBuffer);
}
}
@@ -11,8 +11,8 @@ import java.awt.GridBagConstraints;
/**
* Options page for what voice costs and survives on the wire: the encoder's bitrate and
* error correction, and duplicate voice packets. Changes preview live on the connected
* microphone.
* error correction, duplicate voice packets, and how long incoming voice is buffered.
* Transmit changes preview live on the connected microphone.
*/
final class NetworkPanel extends FormPanel {
@@ -26,6 +26,7 @@ final class NetworkPanel extends FormPanel {
private final JCheckBox fecCheck;
private final JComboBox<String> redundancyCombo;
private final JComboBox<Integer> copiesCombo;
private final JComboBox<String> receiveBufferCombo;
/** @param pushEncoder puts the encoder settings on screen, across pages, into effect */
NetworkPanel(Settings settings, VoiceInput liveMic, Runnable pushEncoder) {
@@ -45,13 +46,8 @@ final class NetworkPanel extends FormPanel {
vbrCheck.addActionListener(e -> pushEncoder.run());
fecCheck.addActionListener(e -> pushEncoder.run());
String[] delays = new String[Settings.REDUNDANCY_DELAYS.length];
for (int i = 0; i < delays.length; i++) {
int ms = Settings.REDUNDANCY_DELAYS[i];
delays[i] = ms == 0 ? "Off" : ms + " ms";
}
redundancyCombo = new JComboBox<>(delays);
redundancyCombo.setSelectedIndex(nearestDelay(settings.redundancyDelay));
redundancyCombo = new JComboBox<>(delayLabels(Settings.REDUNDANCY_DELAYS));
redundancyCombo.setSelectedIndex(nearest(Settings.REDUNDANCY_DELAYS, settings.redundancyDelay));
Integer[] copies = new Integer[Settings.MAX_REDUNDANCY_COPIES];
for (int i = 0; i < copies.length; i++) copies[i] = i + 1;
copiesCombo = new JComboBox<>(copies);
@@ -63,6 +59,9 @@ final class NetworkPanel extends FormPanel {
});
copiesCombo.addActionListener(e -> pushRedundancy());
receiveBufferCombo = new JComboBox<>(delayLabels(Settings.RECEIVE_BUFFERS));
receiveBufferCombo.setSelectedIndex(nearest(Settings.RECEIVE_BUFFERS, settings.receiveBuffer));
int row = 0;
addSection(this, c, row++, "Encoder");
addRow(this, c, row++, new JLabel("Bitrate:"), sliderWithLabel(bitrateSlider, bitrateLabel, 70));
@@ -71,6 +70,8 @@ final class NetworkPanel extends FormPanel {
addSection(this, c, row++, "Redundancy");
addRow(this, c, row++, new JLabel("Delay:"), redundancyCombo);
addRow(this, c, row++, new JLabel("Copies:"), copiesCombo);
addSection(this, c, row++, "Receive");
addRow(this, c, row++, new JLabel("Extra buffering:"), receiveBufferCombo);
addFiller(this, c, row);
}
@@ -82,10 +83,16 @@ final class NetworkPanel extends FormPanel {
return (Integer) copiesCombo.getSelectedItem();
}
private static int nearestDelay(int ms) {
private static String[] delayLabels(int[] choices) {
String[] labels = new String[choices.length];
for (int i = 0; i < labels.length; i++) labels[i] = choices[i] == 0 ? "Off" : choices[i] + " ms";
return labels;
}
private static int nearest(int[] choices, int ms) {
int best = 0;
for (int i = 1; i < Settings.REDUNDANCY_DELAYS.length; i++) {
if (Math.abs(Settings.REDUNDANCY_DELAYS[i] - ms) < Math.abs(Settings.REDUNDANCY_DELAYS[best] - ms)) best = i;
for (int i = 1; i < choices.length; i++) {
if (Math.abs(choices[i] - ms) < Math.abs(choices[best] - ms)) best = i;
}
return best;
}
@@ -101,5 +108,6 @@ final class NetworkPanel extends FormPanel {
target.fec = fecCheck.isSelected();
target.redundancyDelay = selectedDelay();
target.redundancyCopies = selectedCopies();
target.receiveBuffer = Settings.RECEIVE_BUFFERS[receiveBufferCombo.getSelectedIndex()];
}
}