Decodificatore HEVC, terza parte: anche le estensioni di formato, tutti i 146 flussi di conformità coincidono (#58)

I 10 flussi RExt sono nella serie di conformità, quindi il decodificatore li
decodifica invece di lasciarli inconcludenti: 4:0:0, 4:2:2 (due blocchi di
croma per unità di trasformata, modi intra della tabella 8-3, QP del croma
senza la tabella del 4:2:0), 4:4:4, fino a 12 bit, predizione fra componenti,
RDPCM implicito ed esplicito, rotazione e contesto unico del transform skip,
smoothing intra spento, adattamento persistente di Rice salvato con i contesti
di WPP e dei segmenti dipendenti, chroma_qp_offset_list; deblocking del croma
sulla sua griglia e SAO con CTB di croma non quadrati. Precisione estesa e
allineamento del CABAC restano rifiutati: nessun flusso li usa.

Le prove RExt non sono più inconcludenti, così la CI non trova prove HEVC
saltate. Una prova nuova controlla che tile, WPP, segmenti dipendenti, liste
di scala, lungo termine, PCM e strumenti RExt siano accesi in almeno un flusso,
perché gli hash valgano qualcosa per ciascuno. Il ritaglio dei fotogrammi in
uscita usa array non inizializzati. Misurati 160-600 fotogrammi al secondo a
416x240 e 26-27 a 1080p su questa macchina; nei cicli delle CTU non si alloca.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-18 17:06:04 +01:00
1 parent d5e1282261
commit 3cabd87316
14 files changed
+535 -188

No files matched your search

@@ -1,22 +1,22 @@
using Febe.Core.Codecs.H264;
using Febe.Core.Codecs.H265;
using Pps = Febe.Core.Codecs.H265.Pps;
using Sps = Febe.Core.Codecs.H265.Sps;
namespace Febe.Tests.Codecs.H265;
/// <summary>
/// The HEVC decoder beyond the whole frames of <see cref="H265ConformanceTests"/>: every decoded picture of every Main and
/// Main 10 stream, in decoding order and before cropping, against the hash its encoder wrote in the bitstream (so a wrong
/// The HEVC decoder beyond the whole frames of <see cref="H265ConformanceTests"/>: every decoded picture of every stream
/// of the set, in decoding order and before cropping, against the hash its encoder wrote in the bitstream (so a wrong
/// picture is found where it first goes wrong, also when it is never output); length-prefixed samples; damaged streams.
/// </summary>
[TestClass]
public sealed class H265DecoderTests
{
public static IEnumerable<object[]> MainStreams => H265ConformanceStream.Names()
.Where(n => !H265ConformanceStream.Load(n).IsRangeExtension)
.Select(n => new object[] { n });
public static IEnumerable<object[]> AllStreams => H265ConformanceStream.Names().Select(n => new object[] { n });
[TestMethod]
[DynamicData(nameof(MainStreams))]
[DynamicData(nameof(AllStreams))]
public void EveryPictureMatchesItsHash(string name)
{
var stream = H265ConformanceStream.Load(name);
@@ -86,6 +86,77 @@ public sealed class H265DecoderTests
Assert.IsEmpty(none, $"nessuna immagine inter con hash: {string.Join(", ", none)}");
}
[TestMethod]
public void TheSetExercisesEveryTool()
{
// The hash checks are worth something for a tool only if some stream of the set turns it on: read the parameter
// sets of every stream and look for each tool the decoder claims to handle.
var seen = new HashSet<string>();
byte[]? buffer = null;
foreach (var name in H265ConformanceStream.Names())
{
var data = File.ReadAllBytes(H265ConformanceStream.Load(name).BitstreamPath);
var position = 0;
while (NalUnits.NextAnnexB(data, ref position, out var unit))
{
var nal = data.AsSpan(unit);
if (nal.Length < 3 || (nal[0] & 1) != 0 || (nal[1] >> 3) != 0)
{
continue;
}
var type = (nal[0] >> 1) & 63;
if (type == 33)
{
var s = Sps.Parse(H265NalUnit.Unescape(nal, ref buffer).Reader());
Mark(seen, "liste di scala", s.ScalingListEnabled);
Mark(seen, "lungo termine", s.LongTermRefsPresent);
Mark(seen, "PCM", s.PcmEnabled);
Mark(seen, "4:0:0", s.ChromaArrayType == 0);
Mark(seen, "4:2:2", s.ChromaArrayType == 2);
Mark(seen, "4:4:4", s.ChromaArrayType == 3);
Mark(seen, "12 bit", s.BitDepthY == 12);
Mark(seen, "rotazione", s.TransformSkipRotationEnabled);
Mark(seen, "contesto del transform skip", s.TransformSkipContextEnabled);
Mark(seen, "RDPCM implicito", s.ImplicitRdpcmEnabled);
Mark(seen, "smoothing intra spento", s.IntraSmoothingDisabled);
Mark(seen, "Rice persistente", s.PersistentRiceAdaptationEnabled);
Mark(seen, "RDPCM esplicito", s.ExplicitRdpcmEnabled);
}
else if (type == 34)
{
var p = Pps.Parse(H265NalUnit.Unescape(nal, ref buffer).Reader());
Mark(seen, "tile", p.TilesEnabled);
Mark(seen, "tile non uniformi", p.TilesEnabled && !p.UniformSpacing);
Mark(seen, "deblocking non attraverso i tile", p.TilesEnabled && !p.LoopFilterAcrossTilesEnabled);
Mark(seen, "WPP", p.EntropyCodingSyncEnabled);
Mark(seen, "segmenti dipendenti", p.DependentSliceSegmentsEnabled);
Mark(seen, "liste di scala nel PPS", p.ScalingList is not null);
Mark(seen, "predizione fra componenti", p.CrossComponentPredictionEnabled);
Mark(seen, "chroma_qp_offset_list", p.ChromaQpOffsetListEnabled);
}
}
}
string[] tools =
[
"liste di scala", "liste di scala nel PPS", "lungo termine", "PCM", "tile", "tile non uniformi",
"deblocking non attraverso i tile", "WPP", "segmenti dipendenti", "4:0:0", "4:2:2", "4:4:4", "12 bit",
"rotazione", "contesto del transform skip", "RDPCM implicito", "smoothing intra spento", "Rice persistente",
"predizione fra componenti", "chroma_qp_offset_list", "RDPCM esplicito",
];
var missing = tools.Where(t => !seen.Contains(t)).ToList();
Assert.IsEmpty(missing, $"strumenti che nessun flusso usa: {string.Join(", ", missing)}");
}
private static void Mark(HashSet<string> seen, string tool, bool used)
{
if (used)
{
seen.Add(tool);
}
}
[TestMethod]
[DataRow("IPRED_A_docomo_2")]
[DataRow("IPRED_C_Mitsubishi_3")]