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>
68 lines
2.5 KiB
C#
68 lines
2.5 KiB
C#
using System.Security.Cryptography;
|
||
using Febe.Core.Codecs.H264;
|
||
|
||
namespace Febe.Tests.Codecs.H264;
|
||
|
||
/// <summary>
|
||
/// The decoder against streams of the ITU-T H.264.1 conformance suite: every output frame, in output order, must have the
|
||
/// MD5 of the corresponding frame of the official reconstruction (see Conformita/LEGGIMI.md).
|
||
/// </summary>
|
||
[TestClass]
|
||
public sealed class H264ConformanceTests
|
||
{
|
||
[TestMethod]
|
||
[DataRow("BA1_Sony_D")]
|
||
[DataRow("SVA_BA1_B")]
|
||
[DataRow("BA3_SVA_C")]
|
||
[DataRow("BASQP1_Sony_C")]
|
||
[DataRow("CI_MW_D")]
|
||
[DataRow("CABA1_SVA_B")]
|
||
[DataRow("CABA2_SVA_B")]
|
||
[DataRow("CABA3_SVA_B")]
|
||
[DataRow("CANL1_SVA_B")]
|
||
[DataRow("FRExt1_Panasonic_D")]
|
||
[DataRow("FRExt3_Panasonic_E")]
|
||
[DataRow("HCAFR1_HHI_C")]
|
||
public void FramesMatchTheReference(string name)
|
||
{
|
||
var folder = Path.Combine(AppContext.BaseDirectory, "Media", "H264", "Conformita", name);
|
||
var stream = Directory.EnumerateFiles(folder)
|
||
.Single(f => Path.GetExtension(f) is ".264" or ".jsv" or ".avc");
|
||
var expected = ReadReference(Path.Combine(folder, "riferimento.md5"));
|
||
|
||
var frames = new List<H264Frame>();
|
||
var decoder = new H264Decoder();
|
||
decoder.FrameDecoded += frames.Add;
|
||
decoder.DecodeAnnexB(File.ReadAllBytes(stream));
|
||
|
||
var ordered = frames.OrderBy(f => f.Period).ThenBy(f => f.Poc).ThenBy(f => f.DecodeIndex).ToList();
|
||
var actual = ordered.Select(f => Convert.ToHexStringLower(MD5.HashData(f.ToI420()))).ToList();
|
||
for (var i = 0; i < Math.Min(actual.Count, expected.Count); i++)
|
||
{
|
||
if (actual[i] != expected[i])
|
||
{
|
||
var f = ordered[i];
|
||
Assert.Fail($"{name}: il fotogramma {i} (decodifica {f.DecodeIndex}, POC {f.Poc}, {f.Width}×{f.Height}) è diverso dal riferimento.");
|
||
}
|
||
}
|
||
|
||
Assert.AreEqual(expected.Count, actual.Count, $"{name}: numero di fotogrammi");
|
||
}
|
||
|
||
private static List<string> ReadReference(string path)
|
||
{
|
||
var frames = new List<string>();
|
||
foreach (var line in File.ReadAllLines(path))
|
||
{
|
||
var parts = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||
if (parts.Length == 2 && int.TryParse(parts[0], out var index))
|
||
{
|
||
Assert.AreEqual(frames.Count, index, "riferimento.md5 fuori ordine");
|
||
frames.Add(parts[1]);
|
||
}
|
||
}
|
||
|
||
return frames;
|
||
}
|
||
}
|