Add adaptive packet loss handling
Build and test / test (macos-latest) (push) Canceled after 0s
Build and test / test (ubuntu-24.04) (push) Canceled after 0s
Build and test / test (windows-latest) (push) Canceled after 0s
Build and test / apple-client (push) Canceled after 0s

This commit is contained in:
2026-09-22 16:54:49 +02:00
parent 7c4708c3de
commit 7b0c003ad4
35 changed files with 518 additions and 60 deletions
+34 -1
View File
@@ -1,4 +1,5 @@
using VoiceCat.Server.Data;
using VoiceCat.Protocol;
using Voicecat.V1;
using static VoiceCat.Tests.ServerTests;
@@ -11,7 +12,8 @@ public class ChannelManagementTests
using (var store = new AccountStore(Path.Combine(fixture.Directory, "voicecat.db")))
await store.CreateAccountAsync("Admin", "secret", true);
Client client = await fixture.ConnectAsync();
client.Send(new() { ClientHello = new() { ProtoVersion = 2 } });
var hello = new ClientHello { ProtoVersion = 2 }; hello.Features.Add(ProtocolFeatures.AdaptivePacketLoss);
client.Send(new() { ClientHello = hello });
await client.ReadUntilAsync(e => e.ServerHello is not null);
client.Send(new() { AuthRequest = new() { Password = new() { Username = "Admin", Password = "secret" } } });
Assert.True((await client.ReadUntilAsync(e => e.AuthResult is not null)).AuthResult.Ok);
@@ -114,6 +116,7 @@ public class ChannelManagementTests
music.Audio.Dtx = true;
music.Audio.Fec = true;
music.Audio.Dred = true;
music.Audio.PacketLossMode = PacketLossMode.PacketLossAutoStable;
music.Audio.Complexity = 10;
Assert.True(await ResultAsync(admin, new() { EditChannel = new() { Channel = music } }));
}
@@ -126,6 +129,36 @@ public class ChannelManagementTests
Assert.True(audio.Dtx);
Assert.True(audio.Fec);
Assert.True(audio.Dred);
Assert.Equal(PacketLossMode.PacketLossAutoStable, audio.PacketLossMode);
Assert.Equal(10U, audio.Complexity);
}
[Fact]
public async Task LegacyAdministratorEditsPreserveAutomaticPacketLossMode()
{
await using var fixture = new ServerFixture();
await using var current = await AdminAsync(fixture);
Channel music;
using (var store = new AccountStore(Path.Combine(fixture.Directory, "voicecat.db")))
{
music = store.LoadChannels().Single(channel => channel.Name == "Music Room");
music.Audio.PacketLossMode = PacketLossMode.PacketLossAutoBalanced;
}
Assert.True(await ResultAsync(current, new() { EditChannel = new() { Channel = music } }));
await using Client legacy = await fixture.ConnectAsync();
legacy.Send(new() { ClientHello = new() { ProtoVersion = 2 } });
await legacy.ReadUntilAsync(envelope => envelope.ServerHello is not null);
legacy.Send(new() { AuthRequest = new() { Password = new() { Username = "Admin", Password = "secret" } } });
Assert.True((await legacy.ReadUntilAsync(envelope => envelope.AuthResult is not null)).AuthResult.Ok);
await legacy.ReadUntilAsync(envelope => envelope.ServerState is not null);
music.Audio.PacketLossMode = PacketLossMode.PacketLossManual;
music.Audio.ExpectedPacketLoss = 23;
Assert.True(await ResultAsync(legacy, new() { EditChannel = new() { Channel = music } }));
using var verify = new AccountStore(Path.Combine(fixture.Directory, "voicecat.db"));
AudioConfig saved = verify.LoadChannels().Single(channel => channel.Id == music.Id).Audio;
Assert.Equal(PacketLossMode.PacketLossAutoBalanced, saved.PacketLossMode);
Assert.Equal(23U, saved.ExpectedPacketLoss);
}
}