Decodificatore HEVC, seconda parte: predizione inter, tutti i flussi Main e Main 10 coincidono (#58)

La predizione inter scritta dalla norma ITU-T H.265 (§8.3.4, §8.5.3): liste di
riferimento con le modifiche, merge con candidati spaziali, temporale,
bi-predittivi combinati e nulli e livello di merge parallelo, AMVP con la scala
per distanza di POC, TMVP sull'immagine co-locata, interpolazione a 8 prese per
la luma e 4 per il croma, predizione pesata di base ed esplicita. Il deblocking
prende l'intensità 1 anche dal moto; ogni immagine conserva il moto dei blocchi
4x4, la slice di ogni CTB e le liste delle sue slice per chi la usa come
co-locata. Un riferimento mancante diventa un'immagine grigia fuori dal DPB.
I filtri d'interpolazione usano i vettori della BCL (Vector128).

Perché: senza inter nessun video HEVC reale si decodifica. Ora i 136 flussi
Main, Main 10 e Main Still Picture della serie ITU-T H.265.1 danno esattamente
il YUV ufficiale e ogni immagine il suo hash SEI; questo conferma anche il
numero di fotogrammi e gli MD5 scelti per i flussi senza YUV. Restano
inconcludenti solo i 10 flussi RExt, in attesa della decisione di Alberto.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-18 16:18:32 +01:00
1 parent f77b5e4db6
commit d5e1282261
10 files changed
+1219 -125

No files matched your search

+31 -27
View File
@@ -4,9 +4,9 @@ using Febe.Core.Codecs.H265;
namespace Febe.Tests.Codecs.H265;
/// <summary>
/// The HEVC decoder beyond the intra-only streams of <see cref="H265ConformanceTests"/>: every picture made only of I
/// slices, in every Main and Main 10 stream, against the MD5 its encoder wrote in the bitstream; the syntax of the P and
/// B slices read to the end of every slice; length-prefixed samples; damaged streams.
/// 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
/// 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
@@ -17,17 +17,14 @@ public sealed class H265DecoderTests
[TestMethod]
[DynamicData(nameof(MainStreams))]
public void IntraPicturesMatchTheirHashAndEverySliceIsReadToItsEnd(string name)
public void EveryPictureMatchesItsHash(string name)
{
var stream = H265ConformanceStream.Load(name);
var data = File.ReadAllBytes(stream.BitstreamPath);
var hashes = H265PictureHashes.Read(data).ToDictionary(h => h.Picture);
// Inter prediction is not written: P and B slices are read with their prediction units mid-grey, so only the
// pictures of I slices alone can be checked; reading every slice to its end_of_slice_segment_flag without an
// error checks the inter syntax.
var decoder = new H265Decoder { ParseInterSlices = true };
int decoded = 0, hashed = 0, intra = 0;
var decoder = new H265Decoder();
int decoded = 0, hashed = 0;
var wrong = new List<string>();
decoder.PictureDecoded += picture =>
{
@@ -38,12 +35,6 @@ public sealed class H265DecoderTests
}
hashed++;
if (!picture.IntraOnly)
{
return;
}
intra++;
for (var c = 0; c < hash.Planes.Length; c++)
{
var width = c == 0 ? picture.Width : picture.ChromaWidth;
@@ -69,21 +60,30 @@ public sealed class H265DecoderTests
}
Assert.AreEqual(stream.FrameCount, frames, $"{name}: fotogrammi in uscita");
if (hashes.Count > 0)
{
Assert.IsGreaterThan(0, intra, $"{name}: nessuna immagine intra controllata");
}
}
[TestMethod]
public void InterSlicesAreRefusedByDefault()
public void TheHashesCoverInterPictures()
{
// BUMPING_A begins with an IDR picture and goes on with P and B slices: the IDR comes out, then the refusal.
var data = File.ReadAllBytes(H265ConformanceStream.Load("BUMPING_A_ericsson_1").BitstreamPath);
var decoder = new H265Decoder();
var error = Assert.ThrowsExactly<H265Exception>(() => decoder.DecodeAnnexB(data));
StringAssert.Contains(error.Message, "inter");
Assert.IsGreaterThanOrEqualTo(1, decoder.PicturesDecoded);
// The check above is worth something for inter prediction only if the hashes cover P and B pictures: count
// them in the streams that carry hashes, decoding a few streams whose names say they are about inter tools.
string[] names = ["MERGE_A_TI_3", "TMVP_A_MS_3", "WP_A_Toshiba_3", "WP_B_Toshiba_3", "PMERGE_A_TI_3", "MVCLIP_A_qualcomm_3", "MVEDGE_A_qualcomm_3", "SAO_A_MediaTek_4", "RAP_B_Bossen_2"];
var none = new List<string>();
foreach (var name in names)
{
var data = File.ReadAllBytes(H265ConformanceStream.Load(name).BitstreamPath);
var hashes = H265PictureHashes.Read(data).Select(h => h.Picture).ToHashSet();
var inter = 0;
var decoder = new H265Decoder();
decoder.PictureDecoded += picture => inter += !picture.IntraOnly && hashes.Contains((int)picture.DecodeIndex) ? 1 : 0;
decoder.DecodeAnnexB(data);
if (inter == 0)
{
none.Add(name);
}
}
Assert.IsEmpty(none, $"nessuna immagine inter con hash: {string.Join(", ", none)}");
}
[TestMethod]
@@ -155,6 +155,10 @@ public sealed class H265DecoderTests
[DataRow("WPP_C_ericsson_MAIN_2", 2708)]
[DataRow("TILES_B_Cisco_1", 2709)]
[DataRow("DSLICE_A_HHI_5", 2710)]
[DataRow("MVEDGE_A_qualcomm_3", 2711)]
[DataRow("WP_B_Toshiba_3", 2712)]
[DataRow("TMVP_A_MS_3", 2713)]
[DataRow("PMERGE_B_TI_3", 2714)]
public void DamagedStreamsGiveFramesOrAnH265Exception(string name, int seed)
{
var data = File.ReadAllBytes(H265ConformanceStream.Load(name).BitstreamPath);
@@ -186,7 +190,7 @@ public sealed class H265DecoderTests
try
{
var decoder = new H265Decoder { ParseInterSlices = true };
var decoder = new H265Decoder();
decoder.FrameOutput += _ => { };
decoder.DecodeAnnexB(copy);
}