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,10 +1,10 @@
# Flussi di conformità H.265 (HEVC)
Questi flussi provano il decodificatore HEVC scritto in casa (`src/Febe.Core/Codecs/H265`), che serve per i video HEVC
e per le foto HEIC (profilo Main Still Picture). Tutti i 136 flussi Main, Main 10 e Main Still Picture danno esattamente
i fotogrammi del YUV ufficiale (`H265ConformanceTests.FramesMatchTheReference`), e ogni immagine decodificata coincide
con l'hash SEI del suo codificatore dove il flusso lo porta (`H265DecoderTests.EveryPictureMatchesItsHash`). Le prove
dei flussi RExt restano inconcludenti finché Alberto non decide se servono.
e per le foto HEIC (profilo Main Still Picture). Tutti i 146 flussi, i 136 Main, Main 10 e Main Still Picture e i 10
delle estensioni di formato (RExt), danno esattamente i fotogrammi del YUV ufficiale
(`H265ConformanceTests.FramesMatchTheReference`), e ogni immagine decodificata coincide con l'hash SEI del suo
codificatore dove il flusso lo porta (`H265DecoderTests.EveryPictureMatchesItsHash`). Nessuna prova è inconcludente.
## Provenienza
@@ -252,11 +252,15 @@ con le righe per fotogramma.
| Insiemi di parametri | `VPSID_A_VIDYO_2`, `VPSSPSPPS_A_MainConcept_1`, `PPS_A_qualcomm_7`, `PS_B_VIDYO_3`, `EXT_A_ericsson_4`, `SLPPLP_A_VIDYO_2`, `TSCL_A_VIDYO_5`, `TSCL_B_VIDYO_4`, `HRD_A_Fujitsu_3`, `FILLER_A_Sony_1` |
| Dimensioni estreme | `PICSIZE_C_Bossen_1`, `PICSIZE_D_Bossen_1`, `AMP_A_Samsung_7` (2560×1600), `WPP_D_ericsson_MAIN_2` (1 CTB di larghezza) |
## Estensioni di formato (RExt): inconcludenti
## Estensioni di formato (RExt)
Un piccolo gruppo di flussi `RExt` (4:0:0, 4:2:2, 4:4:4, 12 bit e i loro strumenti) è qui solo per avere il riferimento
pronto: le loro prove restano **inconcludenti** finché Alberto non dice se «HEVC» per Febe li comprende (le foto HEIC e
i video dei telefoni sono Main, Main 10 o Main Still Picture). Nessuno di questi zip conteneva il YUV.
Un piccolo gruppo di flussi `RExt` (4:0:0, 4:2:2, 4:4:4, 12 bit e i loro strumenti). Le foto HEIC e i video dei
telefoni sono Main, Main 10 o Main Still Picture, ma questi flussi erano nella serie e il decodificatore li decodifica
tutti esattamente: 4:0:0, 4:2:2 (due blocchi di croma per unità di trasformata, modi intra della tabella 8-3), 4:4:4,
fino a 12 bit, predizione fra componenti, RDPCM implicito, rotazione e contesto unico del transform skip, smoothing
intra spento, adattamento persistente di Rice, `chroma_qp_offset_list`. Restano rifiutati con un'eccezione la
precisione estesa (`extended_precision_processing_flag`, i profili a 16 bit) e l'allineamento del CABAC
(`cabac_bypass_alignment_enabled_flag`), che nessun flusso qui usa. Nessuno di questi zip conteneva il YUV.
| Flusso | Profilo | Dimensioni | Fotogrammi | YUV | Che cosa prova |
|---|---|---|---:|:-:|---|
@@ -286,7 +290,7 @@ quelli grandi il cui strumento è già provato da altri.
| `OPFLAG_B_Qualcomm_1` | 2,1 MB | `pic_output_flag` è già in `OPFLAG_A_Qualcomm_1` e `OPFLAG_C_Qualcomm_1` |
| `AMP_D_Hisilicon_3`, `AMP_E_Hisilicon_3`, `AMP_F_Hisilicon_3` | 0,6–0,8 MB l'uno | AMP a 1080p, già in `AMP_A_Samsung_7` e `AMP_B_Samsung_7` |
| `PICSIZE_A_Bossen_1`, `PICSIZE_B_Bossen_1` | grandi | 1056×8440 e 8440×1056 al livello 5.1: la forma estrema è già in `PICSIZE_C/D` al livello 4.1 |
| il resto di `RExt` | | 16 bit ed EXTPREC, alto rendimento 4:4:4 (WPP di Apple), CCP a 10 e 12 bit, `Main_422_10_A/B`, `TSCTX`, `ExplicitRdpcm`, `PERSIST_RPARAM`, `QMATRIX`, `SAO_A_RExt`, `WAVETILES`, `Bitdepth_B` e gli altri `GENERAL`: finché Alberto non decide sulle estensioni basta il gruppo piccolo qui sopra |
| il resto di `RExt` | | 16 bit ed EXTPREC, alto rendimento 4:4:4 (WPP di Apple), CCP a 10 e 12 bit, `Main_422_10_A/B`, `TSCTX`, `ExplicitRdpcm`, `PERSIST_RPARAM`, `QMATRIX`, `SAO_A_RExt`, `WAVETILES`, `Bitdepth_B` e gli altri `GENERAL`: le estensioni non servono ai file dei telefoni, basta il gruppo piccolo qui sopra |
Le estensioni multistrato e 3D (MV-HEVC, SHVC, SCC) non sono nemmeno state guardate.
@@ -296,3 +300,9 @@ Le estensioni multistrato e 3D (MV-HEVC, SHVC, SCC) non sono nemmeno state guard
la disposizione a 16 bit di `TSUNEQBD_A_MAIN10_Technicolor_2` (10 e 9 bit) erano scelte nostre: il decodificatore le
ha confermate tutte: i suoi fotogrammi, in quel numero e in quella disposizione, hanno esattamente l'MD5 ufficiale
dello zip, che non può coincidere per caso.
- L'RDPCM esplicito (`explicit_rdpcm_flag`, solo nelle CU inter con transform skip o senza perdita) è acceso nell'SPS
di `Bitdepth_A_RExt_Sony_1` e `CCP_8bit_RExt_QCOM_1`, che coincidono, ma non si è contato quante CU lo usino davvero:
la prova vera sarebbe `ExplicitRdpcm_A/B`, rimasto fuori.
- `H265DecoderTests.TheSetExercisesEveryTool` controlla che ogni strumento che il decodificatore dichiara (tile anche non
uniformi e senza deblocking fra i tile, WPP, segmenti dipendenti, liste di scala nell'SPS e nel PPS, lungo termine,
PCM e gli strumenti RExt) sia acceso in almeno un flusso: acceso, non per forza usato in ogni sua variante.
@@ -35,7 +35,7 @@ internal sealed partial class H265ConformanceStream
/// <summary>The readme of the stream's authors, as published.</summary>
public string ReadmePath { get; private set; } = "";
/// <summary>Format range extensions (4:0:0, 4:2:2, 4:4:4, more than 10 bits, RExt tools): not covered by «HEVC» for now.</summary>
/// <summary>Format range extensions (4:0:0, 4:2:2, 4:4:4, more than 10 bits, RExt tools).</summary>
public bool IsRangeExtension => Name.Contains("_RExt_", StringComparison.Ordinal);
/// <summary>Output size, or null when the stream changes size (then only <see cref="Sizes"/> lists them).</summary>
@@ -4,10 +4,10 @@ using Febe.Core.Codecs.H265;
namespace Febe.Tests.Codecs.H265;
/// <summary>
/// The streams of the ITU-T H.265.1 conformance set in Media/H265/Conformita (see LEGGIMI.md there). Every Main, Main 10
/// and Main Still Picture stream must give exactly the frames of its official YUV (the MD5 of each frame where the YUV
/// came with the stream, of the whole YUV for all); the range extension streams (4:0:0, 4:2:2, 4:4:4, 12 bits, RExt
/// tools) stay inconclusive until Alberto says whether «HEVC» covers them.
/// The streams of the ITU-T H.265.1 conformance set in Media/H265/Conformita (see LEGGIMI.md there). Every stream, Main,
/// Main 10, Main Still Picture and the format range extensions (4:0:0, 4:2:2, 4:4:4, 12 bits, RExt tools), must give
/// exactly the frames of its official YUV (the MD5 of each frame where the YUV came with the stream, of the whole YUV for
/// all).
/// </summary>
[TestClass]
public sealed class H265ConformanceTests
@@ -19,11 +19,6 @@ public sealed class H265ConformanceTests
public void FramesMatchTheReference(string name)
{
var stream = H265ConformanceStream.Load(name);
if (stream.IsRangeExtension)
{
Assert.Inconclusive($"{name}: estensione di formato (RExt, {stream.Chroma} a {stream.LumaBitDepth} bit), da decodificare solo se Alberto la vuole.");
}
var frames = new List<byte[]>();
var decoder = new H265Decoder();
decoder.FrameOutput += frame => frames.Add(frame.ToYuvFile());
@@ -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")]