Add adaptive packet loss handling
This commit is contained in:
@@ -26,6 +26,8 @@ public sealed class ChannelEditDialog : Form
|
||||
private NumericUpDown _numFrameMs = null!;
|
||||
private ComboBox _cboApplication = null!;
|
||||
private CheckBox _chkFec = null!;
|
||||
private CheckBox _chkAutomaticLoss = null!;
|
||||
private ComboBox _cboLossSpeed = null!;
|
||||
private NumericUpDown _numExpectedLoss = null!;
|
||||
private CheckBox _chkDtx = null!;
|
||||
private CheckBox _chkDred = null!;
|
||||
@@ -33,11 +35,14 @@ public sealed class ChannelEditDialog : Form
|
||||
|
||||
public ChannelEditInfo? Result { get; private set; }
|
||||
|
||||
public ChannelEditDialog(IEnumerable<ChannelInfo> channels, ChannelEditInfo? existing = null)
|
||||
private readonly bool _supportsAdaptivePacketLoss;
|
||||
|
||||
public ChannelEditDialog(IEnumerable<ChannelInfo> channels, ChannelEditInfo? existing = null, bool supportsAdaptivePacketLoss = true)
|
||||
{
|
||||
_isCreate = existing is null;
|
||||
_editingId = existing?.Id ?? 0;
|
||||
_channels = channels.Where(c => c.Id != _editingId).ToList();
|
||||
_supportsAdaptivePacketLoss = supportsAdaptivePacketLoss;
|
||||
|
||||
Text = _isCreate ? "Create channel" : "Edit channel";
|
||||
FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||
@@ -269,6 +274,31 @@ public sealed class ChannelEditDialog : Form
|
||||
page.Controls.Add(_cboApplication);
|
||||
y += 34;
|
||||
|
||||
_chkAutomaticLoss = new CheckBox
|
||||
{
|
||||
Text = "&Automatic packet loss",
|
||||
Location = new Point(inputX, y),
|
||||
AutoSize = true,
|
||||
Checked = audio.PacketLossMode != VcPacketLossMode.Manual,
|
||||
Enabled = _supportsAdaptivePacketLoss,
|
||||
TabIndex = 15,
|
||||
};
|
||||
page.Controls.Add(_chkAutomaticLoss);
|
||||
y += 30;
|
||||
|
||||
AddLabel(page, "Adaptation &speed:", 12, y, labelWidth);
|
||||
_cboLossSpeed = new ComboBox
|
||||
{
|
||||
Location = new Point(inputX, y - 2),
|
||||
Size = new Size(160, 23),
|
||||
DropDownStyle = ComboBoxStyle.DropDownList,
|
||||
TabIndex = 16,
|
||||
};
|
||||
_cboLossSpeed.Items.AddRange(["Fast", "Balanced", "Stable"]);
|
||||
_cboLossSpeed.SelectedIndex = audio.PacketLossMode == VcPacketLossMode.Manual ? 1 : (int)audio.PacketLossMode - 1;
|
||||
page.Controls.Add(_cboLossSpeed);
|
||||
y += 34;
|
||||
|
||||
AddLabel(page, "Expected packet loss (%):", 12, y, labelWidth);
|
||||
_numExpectedLoss = new NumericUpDown
|
||||
{
|
||||
@@ -277,9 +307,16 @@ public sealed class ChannelEditDialog : Form
|
||||
Minimum = 0,
|
||||
Maximum = 100,
|
||||
Value = audio.ExpectedPacketLoss,
|
||||
TabIndex = 15,
|
||||
TabIndex = 17,
|
||||
};
|
||||
page.Controls.Add(_numExpectedLoss);
|
||||
void UpdateLossControls()
|
||||
{
|
||||
_numExpectedLoss.Enabled = !_chkAutomaticLoss.Checked;
|
||||
_cboLossSpeed.Enabled = _supportsAdaptivePacketLoss && _chkAutomaticLoss.Checked;
|
||||
}
|
||||
_chkAutomaticLoss.CheckedChanged += (_, _) => UpdateLossControls();
|
||||
UpdateLossControls();
|
||||
y += 34;
|
||||
|
||||
AddLabel(page, "Com&plexity (0–10):", 12, y, labelWidth);
|
||||
@@ -290,7 +327,7 @@ public sealed class ChannelEditDialog : Form
|
||||
Minimum = 0,
|
||||
Maximum = 10,
|
||||
Value = audio.Complexity,
|
||||
TabIndex = 16,
|
||||
TabIndex = 18,
|
||||
};
|
||||
page.Controls.Add(_numComplexity);
|
||||
y += 34;
|
||||
@@ -301,7 +338,7 @@ public sealed class ChannelEditDialog : Form
|
||||
Location = new Point(inputX, y),
|
||||
AutoSize = true,
|
||||
Checked = audio.Fec,
|
||||
TabIndex = 17,
|
||||
TabIndex = 19,
|
||||
};
|
||||
page.Controls.Add(_chkFec);
|
||||
y += 28;
|
||||
@@ -312,7 +349,7 @@ public sealed class ChannelEditDialog : Form
|
||||
Location = new Point(inputX, y),
|
||||
AutoSize = true,
|
||||
Checked = audio.Dtx,
|
||||
TabIndex = 18,
|
||||
TabIndex = 20,
|
||||
};
|
||||
page.Controls.Add(_chkDtx);
|
||||
y += 28;
|
||||
@@ -323,7 +360,7 @@ public sealed class ChannelEditDialog : Form
|
||||
Location = new Point(inputX, y),
|
||||
AutoSize = true,
|
||||
Checked = audio.Dred,
|
||||
TabIndex = 19,
|
||||
TabIndex = 21,
|
||||
};
|
||||
page.Controls.Add(_chkDred);
|
||||
}
|
||||
@@ -375,7 +412,8 @@ public sealed class ChannelEditDialog : Form
|
||||
ExpectedPacketLoss: (uint)_numExpectedLoss.Value,
|
||||
Dtx: _chkDtx.Checked,
|
||||
Complexity: (uint)_numComplexity.Value,
|
||||
Dred: _chkDred.Checked);
|
||||
Dred: _chkDred.Checked,
|
||||
PacketLossMode: _chkAutomaticLoss.Checked ? (VcPacketLossMode)(_cboLossSpeed.SelectedIndex + 1) : VcPacketLossMode.Manual);
|
||||
|
||||
Result = new ChannelEditInfo(
|
||||
Id: _editingId,
|
||||
|
||||
@@ -1132,7 +1132,7 @@ public partial class MainForm : Form
|
||||
|
||||
private void CreateChannel()
|
||||
{
|
||||
using var dlg = new ChannelEditDialog(_channels);
|
||||
using var dlg = new ChannelEditDialog(_channels, supportsAdaptivePacketLoss: _client.SupportsAdaptivePacketLoss);
|
||||
if (dlg.ShowDialog(this) != DialogResult.OK || dlg.Result is null) return;
|
||||
_client.CreateChannel(dlg.Result);
|
||||
}
|
||||
@@ -1148,7 +1148,7 @@ public partial class MainForm : Form
|
||||
channel.PasswordProtected, null, channel.MaxUsers, channel.SortOrder,
|
||||
channel.Audio);
|
||||
|
||||
using var dlg = new ChannelEditDialog(_channels, editInfo);
|
||||
using var dlg = new ChannelEditDialog(_channels, editInfo, _client.SupportsAdaptivePacketLoss);
|
||||
if (dlg.ShowDialog(this) != DialogResult.OK || dlg.Result is null) return;
|
||||
_client.EditChannel(dlg.Result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user