CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout and the system SQLite. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow; the throw-away server runs without durability) and pe-check. - Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR, 3 on the shared runner; the weekly performance gates keep theirs). BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
230 lines
9.6 KiB
C#
230 lines
9.6 KiB
C#
using Chronos.Core.Video.Bitstream;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Core.Tests.Video;
|
|
|
|
public sealed class BitstreamTests
|
|
{
|
|
[Test]
|
|
public void ExpGolombRoundTrip()
|
|
{
|
|
uint[] unsigned = [0, 1, 2, 3, 7, 8, 254, 255, 256, 65535, 1_000_000, uint.MaxValue - 1];
|
|
int[] signed = [0, 1, -1, 2, -2, 100, -100, int.MaxValue, -int.MaxValue];
|
|
var w = new BitWriter();
|
|
foreach (var v in unsigned) w.WriteUe(v);
|
|
foreach (var v in signed) w.WriteSe(v);
|
|
w.WriteBits(0b101, 3);
|
|
var r = new BitReader(w.ToArray());
|
|
foreach (var v in unsigned) Assert.Equal(v, r.ReadUe());
|
|
foreach (var v in signed) Assert.Equal(v, r.ReadSe());
|
|
Assert.Equal(0b101u, r.ReadBits(3));
|
|
Assert.False(r.IsOverrun);
|
|
}
|
|
|
|
[Test]
|
|
public void ReadingPastTheEndSetsOverrunWithoutThrowing()
|
|
{
|
|
var r = new BitReader([0xFF]);
|
|
Assert.Equal(0xFFu, r.ReadBits(8));
|
|
Assert.Equal(0u, r.ReadBits(16));
|
|
Assert.True(r.IsOverrun);
|
|
var zeros = new BitReader(new byte[8]);
|
|
Assert.Equal(0u, zeros.ReadUe());
|
|
Assert.True(zeros.IsOverrun);
|
|
}
|
|
|
|
[Test]
|
|
public void Leb128RoundTrip()
|
|
{
|
|
Span<byte> buffer = stackalloc byte[8];
|
|
foreach (var v in new ulong[] { 0, 1, 127, 128, 16383, 16384, uint.MaxValue })
|
|
{
|
|
var n = Av1ObuParser.WriteLeb128(buffer, v);
|
|
Assert.Equal(Av1ObuParser.Leb128Size(v), n);
|
|
Assert.True(Av1ObuParser.TryReadLeb128(buffer[..n], out var back, out var length));
|
|
Assert.Equal(v, back);
|
|
Assert.Equal(n, length);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void SplitsThreeAndFourByteStartCodes()
|
|
{
|
|
byte[] stream = [0xAA, 0, 0, 0, 1, 0x67, 1, 2, 0, 0, 1, 0x68, 3, 0, 0, 0, 0, 1, 0x65, 4, 5, 6, 0, 0];
|
|
var units = AnnexBParser.Split(stream);
|
|
Assert.Count(3, units);
|
|
Assert.BytesEqual([0x67, 1, 2], units[0].Slice(stream));
|
|
Assert.BytesEqual([0x68, 3], units[1].Slice(stream));
|
|
Assert.BytesEqual([0x65, 4, 5, 6], units[2].Slice(stream));
|
|
Assert.Equal(H264NalUnitType.Sps, AnnexBParser.H264Type(stream[units[0].Offset]));
|
|
Assert.Equal(H264NalUnitType.IdrSlice, AnnexBParser.H264Type(stream[units[2].Offset]));
|
|
}
|
|
|
|
[Test]
|
|
public void ConvertsAnnexBToLengthPrefixedAndDetectsBoth()
|
|
{
|
|
var annexB = AnnexBParser.ToAnnexB([SyntheticStreams.H264Sps(), SyntheticStreams.H264Pps(), SyntheticStreams.H264Slice(true, 300, 1)]);
|
|
var prefixed = AnnexBParser.ToLengthPrefixed(annexB);
|
|
var fromAnnexB = AnnexBParser.SplitAccessUnit(annexB, out var wasAnnexB);
|
|
var fromPrefixed = AnnexBParser.SplitAccessUnit(prefixed, out var wasAnnexB2);
|
|
Assert.True(wasAnnexB);
|
|
Assert.False(wasAnnexB2);
|
|
Assert.Equal(3, fromAnnexB.Count);
|
|
Assert.Equal(3, fromPrefixed.Count);
|
|
for (var i = 0; i < 3; i++)
|
|
Assert.BytesEqual(fromAnnexB[i].Slice(annexB), fromPrefixed[i].Slice(prefixed));
|
|
}
|
|
|
|
[Test]
|
|
public void LengthPrefixedSplitRejectsInconsistentLengths()
|
|
{
|
|
Assert.False(AnnexBParser.TrySplitLengthPrefixed([0, 0, 0, 9, 1, 2], 4, out _));
|
|
Assert.False(AnnexBParser.TrySplitLengthPrefixed([0, 0, 0, 0], 4, out _));
|
|
Assert.True(AnnexBParser.TrySplitLengthPrefixed([0, 2, 0x41, 9, 0, 1, 0x41], 2, out var units));
|
|
Assert.Count(2, units);
|
|
}
|
|
|
|
[Test]
|
|
public void EmulationPreventionRoundTrip()
|
|
{
|
|
var rng = new Random(7);
|
|
for (var trial = 0; trial < 200; trial++)
|
|
{
|
|
var data = new byte[rng.Next(1, 200)];
|
|
for (var i = 0; i < data.Length; i++) data[i] = rng.Next(4) == 0 ? (byte)rng.Next(4) : (byte)0;
|
|
var escaped = AnnexBParser.AddEmulationPrevention(data);
|
|
for (var i = 2; i < escaped.Length; i++)
|
|
Assert.False(escaped[i - 2] == 0 && escaped[i - 1] == 0 && escaped[i] <= 2, "start code prefix survived escaping");
|
|
var back = AnnexBParser.RemoveEmulationPrevention(escaped);
|
|
// After a lone trailing 0x00 the appended 0x03 is not preceded by two zeros, so it stays.
|
|
if (back.Length == data.Length + 1) back = back[..^1];
|
|
Assert.BytesEqual(data, back);
|
|
}
|
|
Assert.BytesEqual([0, 0, 3, 1, 0, 0, 3, 0], AnnexBParser.AddEmulationPrevention([0, 0, 1, 0, 0, 0]).AsSpan(0, 8));
|
|
}
|
|
|
|
[Test]
|
|
public void ParsesH264HighProfileSps()
|
|
{
|
|
var nal = SyntheticStreams.H264Sps(1920, 1080, 100, 41);
|
|
Assert.True(H264SpsParser.TryParse(nal, out var sps));
|
|
Assert.Equal(100, sps.ProfileIdc);
|
|
Assert.Equal(41, sps.LevelIdc);
|
|
Assert.Equal(1, sps.ChromaFormatIdc);
|
|
Assert.Equal(8, sps.BitDepthLuma);
|
|
Assert.Equal(1920, sps.Width);
|
|
Assert.Equal(1080, sps.Height);
|
|
Assert.Equal(1088, sps.CodedHeight);
|
|
Assert.Equal(1, sps.ColourPrimaries);
|
|
Assert.Equal(false, sps.FullRange);
|
|
Assert.Approximately(29.97, sps.FrameRate!.Value, 0.01);
|
|
}
|
|
|
|
[Theory]
|
|
[Case(1280, 720, 77, 31)]
|
|
[Case(3840, 2160, 100, 51)]
|
|
[Case(642, 482, 66, 30)]
|
|
public void ParsesH264SizesWithCropping(int width, int height, int profile, int level)
|
|
{
|
|
Assert.True(H264SpsParser.TryParse(SyntheticStreams.H264Sps(width, height, profile, level), out var sps));
|
|
Assert.Equal(width, sps.Width);
|
|
Assert.Equal(height, sps.Height);
|
|
Assert.Equal(profile, sps.ProfileIdc);
|
|
}
|
|
|
|
[Test]
|
|
public void ParsesHevcMain10Sps()
|
|
{
|
|
Assert.True(HevcSpsParser.TryParse(SyntheticStreams.HevcSps(1920, 1080, 10, 153), out var sps));
|
|
Assert.Equal(1920, sps.Width);
|
|
Assert.Equal(1080, sps.Height);
|
|
Assert.Equal(1080, sps.CodedHeight);
|
|
Assert.Equal(10, sps.BitDepthLuma);
|
|
Assert.Equal(10, sps.BitDepthChroma);
|
|
Assert.Equal(1, sps.ChromaFormatIdc);
|
|
Assert.Equal(2, sps.ProfileTierLevel.ProfileIdc);
|
|
Assert.Equal(153, sps.ProfileTierLevel.LevelIdc);
|
|
Assert.Equal(0x2000_0000u, sps.ProfileTierLevel.ProfileCompatibilityFlags);
|
|
Assert.Equal(0x9000_0000_0000UL, sps.ProfileTierLevel.ConstraintIndicatorFlags);
|
|
Assert.False(sps.ProfileTierLevel.HighTier);
|
|
Assert.True(sps.TemporalIdNesting);
|
|
}
|
|
|
|
[Test]
|
|
public void AppliesHevcConformanceWindow()
|
|
{
|
|
Assert.True(HevcSpsParser.TryParse(SyntheticStreams.HevcSps(1916, 1076, 8, 120), out var sps));
|
|
Assert.Equal(1920, sps.CodedWidth);
|
|
Assert.Equal(1080, sps.CodedHeight);
|
|
Assert.Equal(1916, sps.Width);
|
|
Assert.Equal(1076, sps.Height);
|
|
Assert.Equal(1, sps.ProfileTierLevel.ProfileIdc);
|
|
}
|
|
|
|
[Test]
|
|
public void ParsesAv1SequenceHeader()
|
|
{
|
|
var obuBytes = SyntheticStreams.Av1SequenceHeaderObu(3840, 2160, 12, tenBit: true);
|
|
Assert.True(Av1ObuParser.TryReadObu(obuBytes, 0, out var obu));
|
|
Assert.Equal(Av1ObuType.SequenceHeader, obu.Type);
|
|
Assert.True(obu.HasSizeField);
|
|
Assert.Equal(obuBytes.Length, obu.TotalLength);
|
|
Assert.True(Av1ObuParser.TryParseSequenceHeader(obu.Payload(obuBytes), out var header));
|
|
Assert.Equal(3840, header.MaxFrameWidth);
|
|
Assert.Equal(2160, header.MaxFrameHeight);
|
|
Assert.Equal(12, header.SeqLevelIdx);
|
|
Assert.Equal(10, header.BitDepth);
|
|
Assert.True(header.ChromaSubsamplingX && header.ChromaSubsamplingY);
|
|
Assert.Equal(1, header.ColorPrimaries);
|
|
Assert.False(header.FullRange);
|
|
}
|
|
|
|
[Test]
|
|
public void ReadsObuWithoutSizeFieldAndSplitsTemporalUnits()
|
|
{
|
|
byte[] lastWithoutSize = [(byte)Av1ObuType.Frame << 3, 9, 8, 7];
|
|
Assert.True(Av1ObuParser.TryReadObu(lastWithoutSize, 0, out var obu));
|
|
Assert.False(obu.HasSizeField);
|
|
Assert.Equal(3, obu.PayloadLength);
|
|
|
|
var stream = SyntheticStreams.Concat(
|
|
SyntheticStreams.Av1TemporalDelimiter(), SyntheticStreams.Av1SequenceHeaderObu(), SyntheticStreams.Av1Frame(50, 1),
|
|
SyntheticStreams.Av1TemporalDelimiter(), SyntheticStreams.Av1Frame(40, 2),
|
|
SyntheticStreams.Av1TemporalDelimiter(), SyntheticStreams.Av1Frame(30, 3));
|
|
var units = Av1ObuParser.SplitTemporalUnits(stream);
|
|
Assert.Count(3, units);
|
|
Assert.Equal(0, units[0].Offset);
|
|
Assert.Equal(stream.Length, units[2].Offset + units[2].Length);
|
|
Assert.Equal(units[0].Length, units[1].Offset);
|
|
}
|
|
|
|
[Test]
|
|
public void ParsersSurviveTruncationAndGarbage()
|
|
{
|
|
byte[][] inputs = [SyntheticStreams.H264Sps(), SyntheticStreams.HevcSps(), SyntheticStreams.Av1SequenceHeaderObu()];
|
|
var rng = new Random(3);
|
|
foreach (var input in inputs)
|
|
{
|
|
for (var length = 0; length < input.Length; length++)
|
|
{
|
|
var slice = input.AsSpan(0, length);
|
|
H264SpsParser.TryParse(slice, out _);
|
|
HevcSpsParser.TryParse(slice, out _);
|
|
Av1ObuParser.Split(slice);
|
|
if (length > 2) Av1ObuParser.TryParseSequenceHeader(slice[2..], out _);
|
|
}
|
|
for (var trial = 0; trial < 300; trial++)
|
|
{
|
|
var corrupt = (byte[])input.Clone();
|
|
corrupt[rng.Next(corrupt.Length)] ^= (byte)(1 << rng.Next(8));
|
|
H264SpsParser.TryParse(corrupt, out _);
|
|
HevcSpsParser.TryParse(corrupt, out _);
|
|
Av1ObuParser.SplitTemporalUnits(corrupt);
|
|
Av1ObuParser.TryParseSequenceHeader(corrupt, out _);
|
|
AnnexBParser.SplitAccessUnit(corrupt, out _);
|
|
}
|
|
}
|
|
Assert.False(H264SpsParser.TryParse(SyntheticStreams.H264Sps().AsSpan(0, 5), out _));
|
|
}
|
|
}
|