Corregge i difetti confermati dalla revisione del decodificatore H.264 e dei lettori di contenitori. - Fotogrammi: un AVI senza idx1 (o OpenDML oltre il primo GB) segna ogni campione come chiave; ora si parte dall'immagine IDR più vicina (entro 300 campioni), altrimenti da un'immagine di slice I o dal primo campione. Oltre 300 campioni vale il fotogramma del punto di partenza; ogni chiamata ha al più 30 secondi, come l'estrattore con ffmpeg che sostituisce. - H.264: una slice P/B senza riferimenti è un errore invece di una predizione da sé stessa; SPS con riferimenti oltre MaxDpbMbs del livello 6.2 rifiutato (1,4 GB da pochi byte); FrameNumOffset dei fotogrammi mancanti di un salto di frame_num; immagini ridondanti saltate e inizio d'immagine secondo §7.4.1.2.4; immagini non di riferimento non chieste non ricostruite; CABAC con finestra di 64 bit; unità NAL in un solo buffer. Il sommario non dice più verificato ciò che nessun MD5 verifica. - Matroska: un blocco rovinato o troncato ferma la lettura e i blocchi letti restano; scala dei tempi esatta per ogni TimecodeScale. - MP4: una traccia con tkhd/elst/mdhd/hdlr/esds rovinati si scarta senza perdere le altre; esds con limiti controllati; nei soli metadati niente copie delle tabelle né campioni dei frammenti. - AVI: durata impossibile ignota senza perdere la data. - Sonda dei metadati davvero asincrona, annullabile fra i frammenti. - Prove nuove: flussi H.264 sintetici scritti bit per bit (salto di frame_num, immagine ridondante, P senza riferimenti, immagini saltate, SPS enormi con PPS e slice), AVI senza indice, blocchi Matroska rovinati, audio MP4 rovinato, durata AVI, TimecodeScale di 3 ms, trun sotto il limite ma oltre il file, limite di run e di tempo, i due MP4 x264 del sito di prova, ffmpeg/ffprobe fuori dal Dockerfile. Provate contro il codice senza le correzioni: falliscono tutte. - decisioni.md: quattro righe del 18 novembre. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
103 lines
4.4 KiB
C#
103 lines
4.4 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). None of these streams uses
|
||
/// weighted prediction, memory management operations, long-term references, gaps in frame_num, POC type 1, I_PCM or
|
||
/// CABAC pictures of several slices: those parts of the decoder have no reference MD5 here (some are reached by
|
||
/// <see cref="H264SyntheticStreamTests"/>, without an official reference).
|
||
/// </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");
|
||
}
|
||
|
||
[TestMethod]
|
||
[DataRow("CABA3_SVA_B")]
|
||
[DataRow("CANL1_SVA_B")]
|
||
[DataRow("FRExt1_Panasonic_D")]
|
||
[DataRow("FRExt3_Panasonic_E")]
|
||
[DataRow("HCAFR1_HHI_C")]
|
||
public void PicturesLeftOutDoNotChangeTheOthers(string name)
|
||
{
|
||
// Pictures nobody refers to and nobody wants are not reconstructed (only their headers count): every frame
|
||
// handed out must still be the one of the full decoding, in the same place of the output order.
|
||
var folder = Path.Combine(AppContext.BaseDirectory, "Media", "H264", "Conformita", name);
|
||
var data = File.ReadAllBytes(Directory.EnumerateFiles(folder).Single(f => Path.GetExtension(f) is ".264" or ".jsv" or ".avc"));
|
||
var all = new List<H264Frame>();
|
||
var full = new H264Decoder();
|
||
full.FrameDecoded += all.Add;
|
||
full.DecodeAnnexB(data);
|
||
|
||
var some = new List<H264Frame>();
|
||
var partial = new H264Decoder { Wanted = index => index % 3 == 2 };
|
||
partial.FrameDecoded += some.Add;
|
||
partial.DecodeAnnexB(data);
|
||
|
||
Assert.AreEqual(full.FramesDecoded, partial.FramesDecoded);
|
||
CollectionAssert.AreEqual(all.Where(f => f.DecodeIndex % 3 == 2).Select(f => f.DecodeIndex).ToArray(), some.Select(f => f.DecodeIndex).ToArray());
|
||
foreach (var frame in some)
|
||
{
|
||
var expected = all.Single(f => f.DecodeIndex == frame.DecodeIndex);
|
||
Assert.AreEqual((expected.Poc, expected.Period), (frame.Poc, frame.Period), $"{name}: ordine del fotogramma {frame.DecodeIndex}");
|
||
CollectionAssert.AreEqual(expected.ToI420(), frame.ToI420(), $"{name}: fotogramma {frame.DecodeIndex}");
|
||
}
|
||
}
|
||
|
||
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;
|
||
}
|
||
}
|