Files
Febe/tests/Febe.Tests/Media/H264/H264MultiviewLimitsTests.cs
Alby96andClaude Opus 5.5 cdc3cc11b9 Correzioni dopo la revisione del decodificatore H.264, dei lettori FLV e della CI (#58)
- CI: le due prove MVC di FeaturesStillToDo finivano con «da verificare: …», che
  riepilogo-prove.sh contava come saltate: ogni verifica del ramo sarebbe fallita.
  Ora cominciano con «da fare: », e lo script esenta solo le inconclusive di
  FeaturesStillToDo il cui motivo comincia con «da fare: » subito dopo la cornice
  di MSTest (prima bastava la parola in qualunque punto di qualunque prova).
  PipelineTests prova lo script su .trx con le cornici inglese e italiana;
  processo.md, Sviluppo.md e verifica.yml descrivono la categoria.
- Partizionamento dei dati: una partizione B o C sperduta (partizione A persa)
  sovrascriveva il buffer delle partizioni della slice in attesa. Ora slice_id e
  redundant_pic_cnt si leggono prima di copiare, e contano l'ordine A, B, C.
- MVC: le viste tengono insieme al massimo 2 × MaxDpbMbs di immagini, e il
  decodificatore di una vista nuova si tiene solo dopo il controllo dell'SPS di
  sottoinsieme; Wanted vale per ogni vista.
- FLV: senza durata nei metadati la durata arriva alla fine dell'ultimo
  fotogramma, come per MPEG; «solo audio» solo con una prova vera nella testa
  (un onMetaData grande non fa più scartare un video).
- Flussi di conformità: tolti i 48 readme e schede di terzi (decisione di
  Alberto: nel repository solo flussi e MD5).
- Prove nuove: partizioni A perse, limite delle viste e Wanted in MVC, unità di
  estensione troncate, flussi rovinati 4:2:2, 10 bit, 4:0:0, SVC e MVC.
- Commenti sulla provenienza che citano i file di ricostruzione ufficiali e
  §8.7 invece del decodificatore di riferimento; commento di
  ImportEnvironment.VideoProbe aggiornato; righe nuove in decisioni.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 19:30:45 +01:00

125 lines
5.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Febe.Core.Codecs.H264;
using static Febe.Tests.Codecs.H264.SyntheticStreams;
namespace Febe.Tests.Codecs.H264;
/// <summary>
/// The decoders of the non-base views of an MVC stream (Annex H): what a damaged subset SPS may make them allocate, and
/// the <see cref="H264Decoder.Wanted"/> filter, which holds for every view.
/// </summary>
[TestClass]
public sealed class H264MultiviewLimitsTests
{
[TestMethod]
public void TheViewsOfAStreamShareOneBoundForTheirBuffers()
{
// A subset SPS may list up to 1,024 views, and each view has a decoder and frame stores of its own: together they
// stay within H264Decoder.MaxAllViewsMbs, here sixteen reference frames of 1920×1088 per view.
var s = new SequenceSettings(WidthInMbs: 120, HeightInMbs: 68, MaxNumRefFrames: 16);
var decoder = new H264Decoder();
var frames = new List<H264Frame>();
decoder.FrameDecoded += frames.Add;
decoder.DecodeUnit(MvcSubsetSps(s, views: 64)[4..]);
decoder.DecodeUnit(Pps()[4..]);
// Views the subset SPS does not list are refused, and leave nothing behind that would count against the bound.
for (var id = 100; id < 140; id++)
{
var absent = Assert.ThrowsExactly<H264Exception>(() => decoder.DecodeUnit(ViewIdr(s, id)[4..]));
StringAssert.Contains(absent.Message, "Vista assente");
}
var perView = (s.MaxNumRefFrames + 1L) * s.WidthInMbs * s.HeightInMbs;
var allowed = (int)(H264Decoder.MaxAllViewsMbs / perView) - 1; // besides the base view
Assert.AreEqual(9, allowed);
for (var id = 1; id <= allowed; id++)
{
decoder.DecodeUnit(ViewIdr(s, id)[4..]);
}
var refused = Assert.ThrowsExactly<H264Exception>(() => decoder.DecodeUnit(ViewIdr(s, allowed + 1)[4..]));
StringAssert.Contains(refused.Message, "Troppe viste");
// The views kept still decode: one frame each, grey (Intra_16x16 DC with nothing around gives 128).
decoder.Flush();
CollectionAssert.AreEqual(Enumerable.Range(1, allowed).ToArray(), frames.Select(f => f.ViewId).ToArray());
foreach (var frame in frames)
{
Assert.IsTrue(frame.Y.All(v => v == 128), $"vista {frame.ViewId}");
}
}
[TestMethod]
public void ExtensionUnitsCutShortGiveNothingOrAnH264Exception()
{
// NAL units 14, 15 and 20 whose header is read byte by byte (svc_extension_flag, view_id, dependency_id), from one
// byte to a few, SVC and MVC, after an MVC subset SPS and a PPS or without them.
var s = new SequenceSettings(WidthInMbs: 2, HeightInMbs: 2);
foreach (var withParameters in new[] { false, true })
{
foreach (var type in new[] { 14, 15, 20 })
{
for (var length = 1; length <= 8; length++)
{
foreach (var second in new byte[] { 0x00, 0x40, 0x80, 0xC0, 0xFF })
{
var decoder = new H264Decoder();
decoder.FrameDecoded += _ => { };
var unit = new byte[length];
unit[0] = (byte)(0x60 | type);
for (var i = 1; i < length; i++)
{
unit[i] = i == 1 ? second : (byte)(0x35 * i);
}
try
{
if (withParameters)
{
decoder.DecodeUnit(MvcSubsetSps(s, views: 2)[4..]);
decoder.DecodeUnit(Pps()[4..]);
}
decoder.DecodeUnit(unit);
decoder.Flush();
}
catch (H264Exception)
{
}
}
}
}
}
}
[TestMethod]
[DataRow("MVCDS-4")]
[DataRow("MVCNV-3")]
public void WantedHoldsForEveryView(string name)
{
// The filter of the root decoder applies to the decoders of the other views too, each with its own decoding
// index; the frames handed out are those of the full decoding, and the view components the views after them
// refer to are still reconstructed.
var data = File.ReadAllBytes(H264ConformanceTests.StreamFile(H264ConformanceTests.Folder(name)));
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.IsGreaterThan(1, all.Select(f => f.ViewId).Distinct().Count(), "più viste");
CollectionAssert.AreEqual(
all.Where(f => f.DecodeIndex % 3 == 2).Select(f => (f.ViewId, f.DecodeIndex)).ToArray(),
some.Select(f => (f.ViewId, f.DecodeIndex)).ToArray());
foreach (var frame in some)
{
var expected = all.Single(f => f.ViewId == frame.ViewId && f.DecodeIndex == frame.DecodeIndex);
CollectionAssert.AreEqual(expected.ToPlanar(), frame.ToPlanar(), $"{name}: vista {frame.ViewId}, fotogramma {frame.DecodeIndex}");
}
}
}