Move bitrate, FEC and redundancy to a Network settings page
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,62 @@
|
|||||||
|
package com.ts3client.android.ui
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.ts3client.android.SessionController
|
||||||
|
import com.ts3client.config.Settings
|
||||||
|
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. */
|
||||||
|
@Composable
|
||||||
|
fun NetworkSettingsScreen(vm: SessionController, onBack: () -> Unit) {
|
||||||
|
val settings = vm.settings
|
||||||
|
fun change(edit: Settings.() -> Unit) {
|
||||||
|
settings.edit()
|
||||||
|
vm.applySettings()
|
||||||
|
}
|
||||||
|
var vbr by remember { mutableStateOf(settings.vbr) }
|
||||||
|
var fec by remember { mutableStateOf(settings.fec) }
|
||||||
|
var redundancy by remember { mutableStateOf(settings.redundancyDelay) }
|
||||||
|
var copies by remember { mutableStateOf(settings.redundancyCopies) }
|
||||||
|
|
||||||
|
SubScreen("Network", onBack) { padding ->
|
||||||
|
Column(Modifier.padding(padding).verticalScroll(rememberScrollState()).padding(bottom = 8.dp)) {
|
||||||
|
Section("Encoder")
|
||||||
|
Level("Bitrate", settings.bitrate / 1000f, MIN_BITRATE_KBITS..MAX_BITRATE_KBITS, { "${it.roundToInt()} kbit/s" }) {
|
||||||
|
change { bitrate = it.roundToInt() * 1000 }
|
||||||
|
}
|
||||||
|
Toggle("Variable bitrate (VBR)", vbr) {
|
||||||
|
vbr = it
|
||||||
|
change { this.vbr = it }
|
||||||
|
}
|
||||||
|
Toggle("Forward error correction (FEC)", fec) {
|
||||||
|
fec = it
|
||||||
|
change { this.fec = it }
|
||||||
|
}
|
||||||
|
|
||||||
|
Section("Redundancy")
|
||||||
|
Picker("Delay", Settings.REDUNDANCY_DELAYS.map { it to if (it == 0) "Off" else "$it ms" }, redundancy) {
|
||||||
|
redundancy = it
|
||||||
|
change { redundancyDelay = it }
|
||||||
|
}
|
||||||
|
if (redundancy > 0) {
|
||||||
|
Picker("Copies", (1..Settings.MAX_REDUNDANCY_COPIES).map { it to "$it" }, copies) {
|
||||||
|
copies = it
|
||||||
|
change { redundancyCopies = it }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
private enum class SettingsPage { SOUND, DESIGN, IDENTITIES, MY_TEAMSPEAK }
|
private enum class SettingsPage { SOUND, NETWORK, DESIGN, IDENTITIES, MY_TEAMSPEAK }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The settings, by category. Every change is saved and put into effect at once,
|
* The settings, by category. Every change is saved and put into effect at once,
|
||||||
@@ -32,6 +32,7 @@ fun SettingsScreen(vm: SessionController, onContacts: () -> Unit, onBack: () ->
|
|||||||
var page by rememberSaveable { mutableStateOf<SettingsPage?>(null) }
|
var page by rememberSaveable { mutableStateOf<SettingsPage?>(null) }
|
||||||
when (page) {
|
when (page) {
|
||||||
SettingsPage.SOUND -> return SoundSettingsScreen(vm, onBack = { page = null })
|
SettingsPage.SOUND -> return SoundSettingsScreen(vm, onBack = { page = null })
|
||||||
|
SettingsPage.NETWORK -> return NetworkSettingsScreen(vm, onBack = { page = null })
|
||||||
SettingsPage.DESIGN -> return DesignScreen(vm, onBack = { page = null })
|
SettingsPage.DESIGN -> return DesignScreen(vm, onBack = { page = null })
|
||||||
SettingsPage.IDENTITIES -> return IdentitiesScreen(vm.identities, onBack = { page = null })
|
SettingsPage.IDENTITIES -> return IdentitiesScreen(vm.identities, onBack = { page = null })
|
||||||
SettingsPage.MY_TEAMSPEAK -> return MyTeamSpeakScreen(vm, onBack = { page = null })
|
SettingsPage.MY_TEAMSPEAK -> return MyTeamSpeakScreen(vm, onBack = { page = null })
|
||||||
@@ -44,6 +45,9 @@ fun SettingsScreen(vm: SessionController, onContacts: () -> Unit, onBack: () ->
|
|||||||
LinkRow("Sound Settings", "Devices, transmission, voice activation, processing, volume", "PLAYBACK") {
|
LinkRow("Sound Settings", "Devices, transmission, voice activation, processing, volume", "PLAYBACK") {
|
||||||
page = SettingsPage.SOUND
|
page = SettingsPage.SOUND
|
||||||
}
|
}
|
||||||
|
LinkRow("Network", "Bitrate, error correction, redundancy", "PING_4") {
|
||||||
|
page = SettingsPage.NETWORK
|
||||||
|
}
|
||||||
LinkRow("Design", "Icon pack, country flags, description pictures", "GUISETUP") {
|
LinkRow("Design", "Icon pack, country flags, description pictures", "GUISETUP") {
|
||||||
page = SettingsPage.DESIGN
|
page = SettingsPage.DESIGN
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ import com.ts3client.config.Settings
|
|||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
private val DENOISE_LEVELS = listOf("Off", "6 dB", "12 dB", "18 dB", "21 dB")
|
private val DENOISE_LEVELS = listOf("Off", "6 dB", "12 dB", "18 dB", "21 dB")
|
||||||
private const val MIN_BITRATE_KBITS = 8f
|
|
||||||
private const val MAX_BITRATE_KBITS = 160f
|
|
||||||
|
|
||||||
/** Audio devices, transmission, voice activation, processing and playback. */
|
/** Audio devices, transmission, voice activation, processing and playback. */
|
||||||
@Composable
|
@Composable
|
||||||
@@ -53,11 +51,7 @@ fun SoundSettingsScreen(vm: SessionController, onBack: () -> Unit) {
|
|||||||
var inputMode by remember { mutableStateOf(settings.inputMode) }
|
var inputMode by remember { mutableStateOf(settings.inputMode) }
|
||||||
var vadMode by remember { mutableStateOf(settings.vadMode) }
|
var vadMode by remember { mutableStateOf(settings.vadMode) }
|
||||||
var agc by remember { mutableStateOf(settings.agc) }
|
var agc by remember { mutableStateOf(settings.agc) }
|
||||||
var vbr by remember { mutableStateOf(settings.vbr) }
|
|
||||||
var fec by remember { mutableStateOf(settings.fec) }
|
|
||||||
var music by remember { mutableStateOf(settings.music) }
|
var music by remember { mutableStateOf(settings.music) }
|
||||||
var redundancy by remember { mutableStateOf(settings.redundancyDelay) }
|
|
||||||
var copies by remember { mutableStateOf(settings.redundancyCopies) }
|
|
||||||
var mutedTalkWarning by remember { mutableStateOf(settings.mutedTalkWarning) }
|
var mutedTalkWarning by remember { mutableStateOf(settings.mutedTalkWarning) }
|
||||||
var threshold by remember { mutableFloatStateOf(settings.vadThresholdDb.toFloat()) }
|
var threshold by remember { mutableFloatStateOf(settings.vadThresholdDb.toFloat()) }
|
||||||
var inputDevice by remember { mutableStateOf(settings.inputDevice) }
|
var inputDevice by remember { mutableStateOf(settings.inputDevice) }
|
||||||
@@ -155,34 +149,13 @@ fun SoundSettingsScreen(vm: SessionController, onBack: () -> Unit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Section("Encoder")
|
Section("Encoder")
|
||||||
Level("Bitrate", settings.bitrate / 1000f, MIN_BITRATE_KBITS..MAX_BITRATE_KBITS, { "${it.roundToInt()} kbit/s" }) {
|
|
||||||
change { bitrate = it.roundToInt() * 1000 }
|
|
||||||
}
|
|
||||||
Level("Complexity", settings.complexity.toFloat(), 0f..10f, { "${it.roundToInt()}" }, steps = 9) {
|
Level("Complexity", settings.complexity.toFloat(), 0f..10f, { "${it.roundToInt()}" }, steps = 9) {
|
||||||
change { complexity = it.roundToInt() }
|
change { complexity = it.roundToInt() }
|
||||||
}
|
}
|
||||||
Toggle("Variable bitrate (VBR)", vbr) {
|
|
||||||
vbr = it
|
|
||||||
change { this.vbr = it }
|
|
||||||
}
|
|
||||||
Toggle("Forward error correction (FEC)", fec) {
|
|
||||||
fec = it
|
|
||||||
change { this.fec = it }
|
|
||||||
}
|
|
||||||
Toggle("Music codec (stereo, higher fidelity)", music) {
|
Toggle("Music codec (stereo, higher fidelity)", music) {
|
||||||
music = it
|
music = it
|
||||||
change { this.music = it }
|
change { this.music = it }
|
||||||
}
|
}
|
||||||
Picker("Redundancy", Settings.REDUNDANCY_DELAYS.map { it to if (it == 0) "Off" else "$it ms" }, redundancy) {
|
|
||||||
redundancy = it
|
|
||||||
change { redundancyDelay = it }
|
|
||||||
}
|
|
||||||
if (redundancy > 0) {
|
|
||||||
Picker("Copies", (1..Settings.MAX_REDUNDANCY_COPIES).map { it to "$it" }, copies) {
|
|
||||||
copies = it
|
|
||||||
change { redundancyCopies = it }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Section("Playback")
|
Section("Playback")
|
||||||
Level("Volume", settings.outputVolume.toFloat(), 0f..2f, { "${(it * 100).roundToInt()} %" }) {
|
Level("Volume", settings.outputVolume.toFloat(), 0f..2f, { "${(it * 100).roundToInt()} %" }) {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import java.util.function.Supplier;
|
|||||||
/**
|
/**
|
||||||
* Options page for everything on the way from the microphone to the server: the capture
|
* Options page for everything on the way from the microphone to the server: the capture
|
||||||
* device and gain, how transmission is activated (with the microphone test), the
|
* device and gain, how transmission is activated (with the microphone test), the
|
||||||
* pre-processing, and the encoder. Changes preview live on the connected microphone and
|
* pre-processing, and the encoder (bar what the Network page holds). Changes preview live on the connected microphone and
|
||||||
* the test alike.
|
* the test alike.
|
||||||
*/
|
*/
|
||||||
final class CapturePanel extends FormPanel {
|
final class CapturePanel extends FormPanel {
|
||||||
@@ -34,10 +34,10 @@ final class CapturePanel extends FormPanel {
|
|||||||
private final JSlider agcBoost;
|
private final JSlider agcBoost;
|
||||||
|
|
||||||
CapturePanel(Settings settings, AudioBackend audio, VoiceInput liveMic, HotkeyService hotkeys,
|
CapturePanel(Settings settings, AudioBackend audio, VoiceInput liveMic, HotkeyService hotkeys,
|
||||||
HotkeysPanel hotkeysPanel, Supplier<Settings> audioSnapshot) {
|
HotkeysPanel hotkeysPanel, Supplier<Settings> audioSnapshot, Runnable pushEncoder) {
|
||||||
this.liveMic = liveMic;
|
this.liveMic = liveMic;
|
||||||
this.activation = new VoiceActivationSection(settings, audio, liveMic, hotkeys, hotkeysPanel, audioSnapshot);
|
this.activation = new VoiceActivationSection(settings, audio, liveMic, hotkeys, hotkeysPanel, audioSnapshot);
|
||||||
this.encoder = new EncoderSection(settings, liveMic);
|
this.encoder = new EncoderSection(settings, pushEncoder);
|
||||||
GridBagConstraints c = gbc();
|
GridBagConstraints c = gbc();
|
||||||
|
|
||||||
inputCombo = AudioDevices.combo(audio.io().inputDevices(), settings.inputDevice);
|
inputCombo = AudioDevices.combo(audio.io().inputDevices(), settings.inputDevice);
|
||||||
|
|||||||
@@ -1,131 +1,46 @@
|
|||||||
package com.ts3client.ui;
|
package com.ts3client.ui;
|
||||||
|
|
||||||
import com.ts3client.audio.OpusParameters;
|
|
||||||
import com.ts3client.audio.VoiceInput;
|
|
||||||
import com.ts3client.config.Settings;
|
import com.ts3client.config.Settings;
|
||||||
|
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JComboBox;
|
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JSlider;
|
import javax.swing.JSlider;
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
|
|
||||||
/** The Capture page's Opus encoder controls, applied to the running encoder as they change. */
|
/**
|
||||||
|
* The Capture page's Opus encoder controls, applied to the running encoder as they change.
|
||||||
|
* Bitrate and error correction live on the Network page.
|
||||||
|
*/
|
||||||
final class EncoderSection {
|
final class EncoderSection {
|
||||||
|
|
||||||
private static final int MIN_BITRATE_KBITS = 8;
|
|
||||||
private static final int MAX_BITRATE_KBITS = 160;
|
|
||||||
|
|
||||||
private final Settings settings;
|
|
||||||
private final VoiceInput liveMic;
|
|
||||||
|
|
||||||
private final JSlider bitrateSlider;
|
|
||||||
private final JSlider complexitySlider;
|
private final JSlider complexitySlider;
|
||||||
private final JCheckBox vbrCheck;
|
|
||||||
private final JCheckBox fecCheck;
|
|
||||||
private final JCheckBox musicCheck;
|
private final JCheckBox musicCheck;
|
||||||
private final JComboBox<String> redundancyCombo;
|
|
||||||
private final JComboBox<Integer> copiesCombo;
|
|
||||||
|
|
||||||
private final JLabel bitrateLabel;
|
|
||||||
|
|
||||||
EncoderSection(Settings settings, VoiceInput liveMic) {
|
|
||||||
this.settings = settings;
|
|
||||||
this.liveMic = liveMic;
|
|
||||||
int kbits = Math.max(MIN_BITRATE_KBITS, Math.min(MAX_BITRATE_KBITS, settings.bitrate / 1000));
|
|
||||||
bitrateSlider = new JSlider(MIN_BITRATE_KBITS, MAX_BITRATE_KBITS, kbits);
|
|
||||||
bitrateLabel = new JLabel(kbits + " kbit/s");
|
|
||||||
bitrateSlider.addChangeListener(e -> {
|
|
||||||
bitrateLabel.setText(bitrateSlider.getValue() + " kbit/s");
|
|
||||||
pushLive();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
/** @param pushEncoder puts the encoder settings on screen, across pages, into effect */
|
||||||
|
EncoderSection(Settings settings, Runnable pushEncoder) {
|
||||||
complexitySlider = new JSlider(0, 10, settings.complexity);
|
complexitySlider = new JSlider(0, 10, settings.complexity);
|
||||||
FormPanel.limitWidth(complexitySlider, FormPanel.SLIDER_WIDTH);
|
FormPanel.limitWidth(complexitySlider, FormPanel.SLIDER_WIDTH);
|
||||||
complexitySlider.addChangeListener(e -> pushLive());
|
complexitySlider.addChangeListener(e -> pushEncoder.run());
|
||||||
|
|
||||||
vbrCheck = new JCheckBox("Variable bitrate (VBR)", settings.vbr);
|
|
||||||
fecCheck = new JCheckBox("Forward error correction (FEC)", settings.fec);
|
|
||||||
musicCheck = new JCheckBox("Music codec (stereo, higher fidelity)", settings.music);
|
musicCheck = new JCheckBox("Music codec (stereo, higher fidelity)", settings.music);
|
||||||
musicCheck.setToolTipText("<html>Transmits <b>OPUS_MUSIC</b>: stereo when the capture "
|
musicCheck.setToolTipText("<html>Transmits <b>OPUS_MUSIC</b>: stereo when the capture "
|
||||||
+ "device has two channels, and without the voice pre-processing "
|
+ "device has two channels, and without the voice pre-processing "
|
||||||
+ "(noise removal, typing attenuation, AGC).<br>"
|
+ "(noise removal, typing attenuation, AGC).<br>"
|
||||||
+ "Voice mode (<b>OPUS_VOICE</b>) is mono, as in the official client.</html>");
|
+ "Voice mode (<b>OPUS_VOICE</b>) is mono, as in the official client.</html>");
|
||||||
vbrCheck.addActionListener(e -> pushLive());
|
musicCheck.addActionListener(e -> pushEncoder.run());
|
||||||
fecCheck.addActionListener(e -> pushLive());
|
|
||||||
musicCheck.addActionListener(e -> pushLive());
|
|
||||||
|
|
||||||
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));
|
|
||||||
Integer[] copies = new Integer[Settings.MAX_REDUNDANCY_COPIES];
|
|
||||||
for (int i = 0; i < copies.length; i++) copies[i] = i + 1;
|
|
||||||
copiesCombo = new JComboBox<>(copies);
|
|
||||||
copiesCombo.setSelectedItem(Math.max(1, Math.min(Settings.MAX_REDUNDANCY_COPIES, settings.redundancyCopies)));
|
|
||||||
copiesCombo.setEnabled(selectedDelay() > 0);
|
|
||||||
redundancyCombo.addActionListener(e -> {
|
|
||||||
copiesCombo.setEnabled(selectedDelay() > 0);
|
|
||||||
pushRedundancy();
|
|
||||||
});
|
|
||||||
copiesCombo.addActionListener(e -> pushRedundancy());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void pushRedundancy() {
|
|
||||||
if (liveMic != null) liveMic.setRedundancy(selectedDelay(), selectedCopies());
|
|
||||||
}
|
|
||||||
|
|
||||||
private int selectedCopies() {
|
|
||||||
return (Integer) copiesCombo.getSelectedItem();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int nearestDelay(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;
|
|
||||||
}
|
|
||||||
return best;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int selectedDelay() {
|
|
||||||
return Settings.REDUNDANCY_DELAYS[redundancyCombo.getSelectedIndex()];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds the section's rows to {@code form} from {@code row} on; returns the next free row. */
|
/** Adds the section's rows to {@code form} from {@code row} on; returns the next free row. */
|
||||||
int layOut(JPanel form, GridBagConstraints c, int row) {
|
int layOut(JPanel form, GridBagConstraints c, int row) {
|
||||||
FormPanel.addRow(form, c, row++, new JLabel("Bitrate:"), FormPanel.sliderWithLabel(bitrateSlider, bitrateLabel, 70));
|
|
||||||
FormPanel.addRow(form, c, row++, new JLabel("Complexity:"), complexitySlider);
|
FormPanel.addRow(form, c, row++, new JLabel("Complexity:"), complexitySlider);
|
||||||
FormPanel.addWide(form, c, row++, vbrCheck);
|
|
||||||
FormPanel.addWide(form, c, row++, fecCheck);
|
|
||||||
FormPanel.addWide(form, c, row++, musicCheck);
|
FormPanel.addWide(form, c, row++, musicCheck);
|
||||||
FormPanel.addRow(form, c, row++, new JLabel("Redundancy:"), redundancyCombo);
|
|
||||||
FormPanel.addRow(form, c, row++, new JLabel("Copies:"), copiesCombo);
|
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Copies the form into {@code target}, without touching anything else. */
|
/** Copies the form into {@code target}, without touching anything else. */
|
||||||
void writeInto(Settings target) {
|
void writeInto(Settings target) {
|
||||||
target.bitrate = bitrateSlider.getValue() * 1000;
|
|
||||||
target.complexity = complexitySlider.getValue();
|
target.complexity = complexitySlider.getValue();
|
||||||
target.vbr = vbrCheck.isSelected();
|
|
||||||
target.fec = fecCheck.isSelected();
|
|
||||||
target.music = musicCheck.isSelected();
|
target.music = musicCheck.isSelected();
|
||||||
target.redundancyDelay = selectedDelay();
|
|
||||||
target.redundancyCopies = selectedCopies();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void pushLive() {
|
|
||||||
if (liveMic == null) return;
|
|
||||||
liveMic.setOpusParameters(new OpusParameters(
|
|
||||||
bitrateSlider.getValue() * 1000,
|
|
||||||
complexitySlider.getValue(),
|
|
||||||
vbrCheck.isSelected(),
|
|
||||||
fecCheck.isSelected(),
|
|
||||||
settings.packetLoss,
|
|
||||||
musicCheck.isSelected()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
package com.ts3client.ui;
|
||||||
|
|
||||||
|
import com.ts3client.audio.VoiceInput;
|
||||||
|
import com.ts3client.config.Settings;
|
||||||
|
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JSlider;
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
final class NetworkPanel extends FormPanel {
|
||||||
|
|
||||||
|
private static final int MIN_BITRATE_KBITS = 8;
|
||||||
|
private static final int MAX_BITRATE_KBITS = 160;
|
||||||
|
|
||||||
|
private final VoiceInput liveMic;
|
||||||
|
|
||||||
|
private final JSlider bitrateSlider;
|
||||||
|
private final JCheckBox vbrCheck;
|
||||||
|
private final JCheckBox fecCheck;
|
||||||
|
private final JComboBox<String> redundancyCombo;
|
||||||
|
private final JComboBox<Integer> copiesCombo;
|
||||||
|
|
||||||
|
/** @param pushEncoder puts the encoder settings on screen, across pages, into effect */
|
||||||
|
NetworkPanel(Settings settings, VoiceInput liveMic, Runnable pushEncoder) {
|
||||||
|
this.liveMic = liveMic;
|
||||||
|
GridBagConstraints c = gbc();
|
||||||
|
|
||||||
|
int kbits = Math.max(MIN_BITRATE_KBITS, Math.min(MAX_BITRATE_KBITS, settings.bitrate / 1000));
|
||||||
|
bitrateSlider = new JSlider(MIN_BITRATE_KBITS, MAX_BITRATE_KBITS, kbits);
|
||||||
|
JLabel bitrateLabel = new JLabel(kbits + " kbit/s");
|
||||||
|
bitrateSlider.addChangeListener(e -> {
|
||||||
|
bitrateLabel.setText(bitrateSlider.getValue() + " kbit/s");
|
||||||
|
pushEncoder.run();
|
||||||
|
});
|
||||||
|
|
||||||
|
vbrCheck = new JCheckBox("Variable bitrate (VBR)", settings.vbr);
|
||||||
|
fecCheck = new JCheckBox("Forward error correction (FEC)", settings.fec);
|
||||||
|
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));
|
||||||
|
Integer[] copies = new Integer[Settings.MAX_REDUNDANCY_COPIES];
|
||||||
|
for (int i = 0; i < copies.length; i++) copies[i] = i + 1;
|
||||||
|
copiesCombo = new JComboBox<>(copies);
|
||||||
|
copiesCombo.setSelectedItem(Math.max(1, Math.min(Settings.MAX_REDUNDANCY_COPIES, settings.redundancyCopies)));
|
||||||
|
copiesCombo.setEnabled(selectedDelay() > 0);
|
||||||
|
redundancyCombo.addActionListener(e -> {
|
||||||
|
copiesCombo.setEnabled(selectedDelay() > 0);
|
||||||
|
pushRedundancy();
|
||||||
|
});
|
||||||
|
copiesCombo.addActionListener(e -> pushRedundancy());
|
||||||
|
|
||||||
|
int row = 0;
|
||||||
|
addSection(this, c, row++, "Encoder");
|
||||||
|
addRow(this, c, row++, new JLabel("Bitrate:"), sliderWithLabel(bitrateSlider, bitrateLabel, 70));
|
||||||
|
addWide(this, c, row++, vbrCheck);
|
||||||
|
addWide(this, c, row++, fecCheck);
|
||||||
|
addSection(this, c, row++, "Redundancy");
|
||||||
|
addRow(this, c, row++, new JLabel("Delay:"), redundancyCombo);
|
||||||
|
addRow(this, c, row++, new JLabel("Copies:"), copiesCombo);
|
||||||
|
addFiller(this, c, row);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void pushRedundancy() {
|
||||||
|
if (liveMic != null) liveMic.setRedundancy(selectedDelay(), selectedCopies());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int selectedCopies() {
|
||||||
|
return (Integer) copiesCombo.getSelectedItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int nearestDelay(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;
|
||||||
|
}
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int selectedDelay() {
|
||||||
|
return Settings.REDUNDANCY_DELAYS[redundancyCombo.getSelectedIndex()];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Copies the page into {@code target}, without touching anything else. */
|
||||||
|
void writeInto(Settings target) {
|
||||||
|
target.bitrate = bitrateSlider.getValue() * 1000;
|
||||||
|
target.vbr = vbrCheck.isSelected();
|
||||||
|
target.fec = fecCheck.isSelected();
|
||||||
|
target.redundancyDelay = selectedDelay();
|
||||||
|
target.redundancyCopies = selectedCopies();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package com.ts3client.ui;
|
|||||||
import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
import com.formdev.flatlaf.util.ScaledEmptyBorder;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
import com.ts3client.audio.AudioBackend;
|
import com.ts3client.audio.AudioBackend;
|
||||||
|
import com.ts3client.audio.OpusParameters;
|
||||||
import com.ts3client.audio.VoiceInput;
|
import com.ts3client.audio.VoiceInput;
|
||||||
import com.ts3client.audio.VoiceOutput;
|
import com.ts3client.audio.VoiceOutput;
|
||||||
import com.ts3client.config.Settings;
|
import com.ts3client.config.Settings;
|
||||||
@@ -42,6 +43,7 @@ public final class SettingsDialog extends JDialog {
|
|||||||
private final ApplicationPanel applicationPanel;
|
private final ApplicationPanel applicationPanel;
|
||||||
private final PlaybackPanel playbackPanel;
|
private final PlaybackPanel playbackPanel;
|
||||||
private final CapturePanel capturePanel;
|
private final CapturePanel capturePanel;
|
||||||
|
private final NetworkPanel networkPanel;
|
||||||
private final NotificationsPanel notificationsPanel;
|
private final NotificationsPanel notificationsPanel;
|
||||||
private final DesignPanel designPanel;
|
private final DesignPanel designPanel;
|
||||||
private final HotkeysPanel hotkeysPanel;
|
private final HotkeysPanel hotkeysPanel;
|
||||||
@@ -59,7 +61,11 @@ public final class SettingsDialog extends JDialog {
|
|||||||
|
|
||||||
applicationPanel = new ApplicationPanel(settings);
|
applicationPanel = new ApplicationPanel(settings);
|
||||||
hotkeysPanel = new HotkeysPanel(hotkeys);
|
hotkeysPanel = new HotkeysPanel(hotkeys);
|
||||||
capturePanel = new CapturePanel(settings, audio, liveMic, hotkeys, hotkeysPanel, this::audioSnapshot);
|
Runnable pushEncoder = () -> {
|
||||||
|
if (liveMic != null) liveMic.setOpusParameters(OpusParameters.from(audioSnapshot()));
|
||||||
|
};
|
||||||
|
capturePanel = new CapturePanel(settings, audio, liveMic, hotkeys, hotkeysPanel, this::audioSnapshot, pushEncoder);
|
||||||
|
networkPanel = new NetworkPanel(settings, liveMic, pushEncoder);
|
||||||
playbackPanel = new PlaybackPanel(settings, audio.io(), livePlayback, sounds,
|
playbackPanel = new PlaybackPanel(settings, audio.io(), livePlayback, sounds,
|
||||||
capturePanel::setTestOutputDevice);
|
capturePanel::setTestOutputDevice);
|
||||||
notificationsPanel = new NotificationsPanel(settings, sounds);
|
notificationsPanel = new NotificationsPanel(settings, sounds);
|
||||||
@@ -72,6 +78,7 @@ public final class SettingsDialog extends JDialog {
|
|||||||
new OptionsPage("myTeamSpeak", myTeamSpeak, "MYTS_ACCOUNT"),
|
new OptionsPage("myTeamSpeak", myTeamSpeak, "MYTS_ACCOUNT"),
|
||||||
new OptionsPage("Playback", scrollable(playbackPanel), "PLAYBACK"),
|
new OptionsPage("Playback", scrollable(playbackPanel), "PLAYBACK"),
|
||||||
new OptionsPage("Capture", scrollable(capturePanel), "CAPTURE"),
|
new OptionsPage("Capture", scrollable(capturePanel), "CAPTURE"),
|
||||||
|
new OptionsPage("Network", scrollable(networkPanel), "PING_4"),
|
||||||
new OptionsPage("Design", designPanel, "GUISETUP", "CHANNEL_EDIT"),
|
new OptionsPage("Design", designPanel, "GUISETUP", "CHANNEL_EDIT"),
|
||||||
new OptionsPage("Hotkeys", hotkeysPanel, "HOTKEYS"),
|
new OptionsPage("Hotkeys", hotkeysPanel, "HOTKEYS"),
|
||||||
new OptionsPage("Contacts", scrollable(contactsPanel), "CONTACT", "EDIT_FRIEND_FOE_STATUS"),
|
new OptionsPage("Contacts", scrollable(contactsPanel), "CONTACT", "EDIT_FRIEND_FOE_STATUS"),
|
||||||
@@ -165,6 +172,7 @@ public final class SettingsDialog extends JDialog {
|
|||||||
private void writeAudioSettings(Settings target) {
|
private void writeAudioSettings(Settings target) {
|
||||||
playbackPanel.writeInto(target);
|
playbackPanel.writeInto(target);
|
||||||
capturePanel.writeInto(target);
|
capturePanel.writeInto(target);
|
||||||
|
networkPanel.writeInto(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -176,6 +184,7 @@ public final class SettingsDialog extends JDialog {
|
|||||||
*/
|
*/
|
||||||
private Settings audioSnapshot() {
|
private Settings audioSnapshot() {
|
||||||
Settings snapshot = new Settings();
|
Settings snapshot = new Settings();
|
||||||
|
snapshot.packetLoss = settings.packetLoss;
|
||||||
writeAudioSettings(snapshot);
|
writeAudioSettings(snapshot);
|
||||||
if (snapshot.inputMode == Settings.InputMode.PUSH_TO_TALK) {
|
if (snapshot.inputMode == Settings.InputMode.PUSH_TO_TALK) {
|
||||||
snapshot.inputMode = Settings.InputMode.VOICE_ACTIVATION;
|
snapshot.inputMode = Settings.InputMode.VOICE_ACTIVATION;
|
||||||
|
|||||||
Reference in New Issue
Block a user