Decodifica Baseline, Main e High a fotogrammi progressivi 4:2:0 a 8 bit (CAVLC e CABAC, slice I/P/B, trasformata 8x8 e matrici di quantizzazione, predizione pesata, diretta spaziale e temporale, gestione dei riferimenti, filtro di deblocco), scritta dallo standard ITU-T H.264 senza codice di terzi. I dodici flussi della suite ITU-T H.264.1 in tests/Febe.Tests/Media/H264/Conformita danno, fotogramma per fotogramma, gli MD5 della ricostruzione ufficiale. Le tabelle di inizializzazione CABAC sono trascritte dal testo della Raccomandazione (03/2005): quelle a memoria per cabac_init_idc 1 e 2 erano sbagliate e le prove le hanno scoperte. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
2.5 KiB
C#
69 lines
2.5 KiB
C#
using Febe.Core.Codecs.H264;
|
|
|
|
namespace Febe.Tests.Codecs.H264;
|
|
|
|
/// <summary>The constant tables of the decoder: shape checks and a few values taken from the text of the standard.</summary>
|
|
[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]);
|
|
}
|
|
}
|