using Febe.Core.Codecs.H264; namespace Febe.Tests.Codecs.H264; /// The constant tables of the decoder: shape checks and a few values taken from the text of the standard. [TestClass] public sealed class H264TablesTests { [TestMethod] public void VariableLengthCodesArePrefixFree() { foreach (var (name, codes) in CavlcTables.AllCodeTables()) { var present = codes.Where(c => c is not null).Select(c => c!).ToList(); for (var i = 0; i < present.Count; i++) { for (var j = 0; j < present.Count; j++) { if (i != j) { Assert.IsFalse(present[j].StartsWith(present[i], StringComparison.Ordinal), $"{name}: {present[i]} รจ prefisso di {present[j]}"); } } } } } [TestMethod] public void DeblockingTablesCoverEveryIndex() { Assert.AreEqual(52, H264Tables.Alpha.Length); Assert.AreEqual(52, H264Tables.Beta.Length); Assert.AreEqual(52 * 3, H264Tables.Tc0.Length); Assert.AreEqual(25, H264Tables.Tc0[(51 * 3) + 2]); Assert.AreEqual(52, H264Tables.ChromaQp.Length); Assert.AreEqual(39, H264Tables.ChromaQp[51]); } [TestMethod] public void CodedBlockPatternTablesArePermutations() { CollectionAssert.AreEquivalent(Enumerable.Range(0, 48).ToArray(), H264Tables.CbpIntra.Select(b => (int)b).ToArray()); CollectionAssert.AreEquivalent(Enumerable.Range(0, 48).ToArray(), H264Tables.CbpInter.Select(b => (int)b).ToArray()); } [TestMethod] public void ScansArePermutations() { CollectionAssert.AreEquivalent(Enumerable.Range(0, 16).ToArray(), H264Tables.ZigZag4x4.Select(b => (int)b).ToArray()); CollectionAssert.AreEquivalent(Enumerable.Range(0, 64).ToArray(), H264Tables.ZigZag8x8.Select(b => (int)b).ToArray()); } [TestMethod] [DataRow(-1, 402, -17, 120)] [DataRow(0, 11, 23, 33)] [DataRow(1, 417, 17, -10)] // once taken from the field table by mistake [DataRow(1, 426, -5, 71)] [DataRow(1, 178, 102, -94)] [DataRow(2, 435, -10, 79)] [DataRow(2, 165, -22, 127)] public void ContextInitialisationMatchesTheStandard(int idc, int ctx, int m, int n) { var table = idc < 0 ? CabacTables.InitI : CabacTables.InitPB[idc]; Assert.AreEqual(CabacTables.ContextCount * 2, table.Length); Assert.AreEqual(m, table[ctx * 2]); Assert.AreEqual(n, table[(ctx * 2) + 1]); } }