Unione di funzione/decoder-h264 in funzione/decoder-hevc (catena della 0.3.0)
Il ramo HEVC era partito da b23632f; la catena porta qui documenti e regole, S4b, i codec di casa (C1) e il resto dell'H.264 (campi, Extended, alta profondità, MVC, SVC, lettori ASF/FLV/MPEG). Le due serie restano intere: - VideoFrameDecoder sceglie H.264 o HEVC come nel ramo HEVC; dell'H.264 prende la sola vista di base dell'MVC e i piani a 16 bit, passati al convertitore comune YuvToRgb (anche 4:2:2, 4:4:4 e 4:0:0) al posto del suo. - Le foto HEIC passano dalla facciata dei codec di C1: HeifImageDecoder trasforma l'HeifImage in RgbaImage senza copia e irot/imir nell'orientamento, così ImageDecoding, miniature e impronte le trattano come le altre foto; la dimensione di un HEIC grande si legge dai soli box. - decisioni.md tiene tutte le righe dei due lati (prima quelle della catena). - Prove: entrambe le copie dei flussi di conformità H.264 e H.265 e delle immagini di riferimento; nei file rovinati entrano sia HEVC sia WMV/FLV/MPEG. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
14920afebf
420 files changed
+39437
-2446
No files matched your search
@@ -21,6 +21,10 @@ public sealed class MalformedInputTests
|
||||
[DataRow("frammentato.mp4")]
|
||||
[DataRow("mkv")]
|
||||
[DataRow("avi")]
|
||||
[DataRow("wmv")]
|
||||
[DataRow("flv")]
|
||||
[DataRow("mpg")]
|
||||
[DataRow("h264.mpg")]
|
||||
[DataRow("hevc.mp4")]
|
||||
[DataRow("hevc.mkv")]
|
||||
public void TruncatedFilesNeverBreakTheReaders(string kind)
|
||||
@@ -38,6 +42,10 @@ public sealed class MalformedInputTests
|
||||
[DataRow("frammentato.mp4", 5802)]
|
||||
[DataRow("mkv", 5803)]
|
||||
[DataRow("avi", 5804)]
|
||||
[DataRow("wmv", 5805)]
|
||||
[DataRow("flv", 5806)]
|
||||
[DataRow("mpg", 5807)]
|
||||
[DataRow("h264.mpg", 5808)]
|
||||
public void GarbledFilesNeverBreakTheReaders(string kind, int seed)
|
||||
{
|
||||
var file = Build(kind);
|
||||
@@ -53,6 +61,9 @@ public sealed class MalformedInputTests
|
||||
[DataRow("frammentato.mp4", 5812)]
|
||||
[DataRow("mkv", 5813)]
|
||||
[DataRow("avi", 5814)]
|
||||
[DataRow("wmv", 5815)]
|
||||
[DataRow("flv", 5816)]
|
||||
[DataRow("mpg", 5817)]
|
||||
[DataRow("hevc.mp4", 5815)]
|
||||
[DataRow("hevc.mkv", 5816)]
|
||||
[DataRow("hevc.avi", 5817)]
|
||||
@@ -72,8 +83,16 @@ public sealed class MalformedInputTests
|
||||
_ = stillness;
|
||||
}
|
||||
|
||||
// Most damage hits frame data, not headers: many variants still give a frame.
|
||||
Assert.IsGreaterThan(0, decoded, "nessuna variante ha dato un fotogramma");
|
||||
// Most damage hits frame data, not headers: many variants still give a frame. WMV and MPEG program streams have
|
||||
// no samples Febe decodes, so no frame ever.
|
||||
if (kind is "wmv" or "mpg")
|
||||
{
|
||||
Assert.AreEqual(0, decoded);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.IsGreaterThan(0, decoded, "nessuna variante ha dato un fotogramma");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -194,6 +213,54 @@ public sealed class MalformedInputTests
|
||||
Assert.IsLessThan(4L * 1024 * 1024, allocated, $"{allocated} byte allocati");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeepOrEndlessFlvMetadataKeepsWhatCameBefore()
|
||||
{
|
||||
// onMetaData: a duration, then objects nested a hundred thousand deep (a stack overflow if followed blindly).
|
||||
var deep = new List<byte> { 2, 0, 10 };
|
||||
deep.AddRange("onMetaData"u8.ToArray());
|
||||
deep.Add(3);
|
||||
deep.AddRange([0, 8, .. "duration"u8, 0, .. Be64(5.0)]);
|
||||
for (var i = 0; i < 100_000; i++)
|
||||
{
|
||||
deep.AddRange([0, 1, (byte)'a', 3]);
|
||||
}
|
||||
|
||||
var container = ReadMeasured(LegacyTestVideos.FlvWithScript([.. deep]), out var allocated);
|
||||
Assert.AreEqual(TimeSpan.FromSeconds(5), container!.Duration);
|
||||
Assert.IsLessThan(4L * 1024 * 1024, allocated, $"{allocated} byte allocati");
|
||||
|
||||
// A strict array that claims four billion values, then a width: the array ends the reading, the duration stays.
|
||||
List<byte> endless = [2, 0, 10, .. "onMetaData"u8, 8, 0, 0, 0, 2, 0, 8, .. "duration"u8, 0, .. Be64(7.0),
|
||||
0, 4, .. "list"u8, 10, 0xFF, 0xFF, 0xFF, 0xFF, 0, .. Be64(1), 0, 5, .. "width"u8, 0, .. Be64(640)];
|
||||
container = ReadMeasured(LegacyTestVideos.FlvWithScript([.. endless]), out _);
|
||||
Assert.AreEqual(TimeSpan.FromSeconds(7), container!.Duration);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AnAsfObjectLargerThanItsFileAllocatesNothing()
|
||||
{
|
||||
var file = LegacyTestVideos.Asf(new AsfOptions { Title = "Prova" });
|
||||
|
||||
// The file properties object (the first after the 30 bytes of the header) claims a gigabyte.
|
||||
BinaryPrimitives.WriteUInt64LittleEndian(file.AsSpan(30 + 16), 1L << 30);
|
||||
var container = ReadMeasured(file, out var allocated);
|
||||
Assert.IsLessThan(4L * 1024 * 1024, allocated, $"{allocated} byte allocati");
|
||||
Assert.IsNull(container!.Duration, "nulla dopo l'oggetto rovinato");
|
||||
|
||||
// A header object smaller than its own fields.
|
||||
file = LegacyTestVideos.Asf(new AsfOptions());
|
||||
BinaryPrimitives.WriteUInt64LittleEndian(file.AsSpan(16), 12);
|
||||
Assert.ThrowsExactly<ContainerException>(() => ReadMeasured(file, out _));
|
||||
}
|
||||
|
||||
private static byte[] Be64(double value)
|
||||
{
|
||||
var bytes = new byte[8];
|
||||
BinaryPrimitives.WriteDoubleBigEndian(bytes, value);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
private static void AssertReadersSurvive(byte[] data, string what)
|
||||
{
|
||||
foreach (var samples in new[] { false, true })
|
||||
@@ -260,6 +327,16 @@ public sealed class MalformedInputTests
|
||||
"frammentato.mp4" => TestVideos.FragmentedMp4(es, perFragment: 6, defaults: true),
|
||||
"mkv" => TestVideos.Matroska(es, new DateTimeOffset(2024, 1, 2, 3, 4, 5, TimeSpan.Zero)),
|
||||
"avi" => TestVideos.Avi(es, "Thu Mar 04 05:06:07 2021"),
|
||||
"wmv" => LegacyTestVideos.Asf(new AsfOptions
|
||||
{
|
||||
Created = new DateTimeOffset(2009, 6, 7, 8, 9, 10, TimeSpan.Zero),
|
||||
EncodingTime = new DateTimeOffset(2009, 6, 7, 8, 9, 10, TimeSpan.Zero),
|
||||
Title = "Prova",
|
||||
VideoInExtension = true,
|
||||
}),
|
||||
"flv" => LegacyTestVideos.Flv(es, creationDate: "Thu Mar 04 05:06:07 2021", audio: true),
|
||||
"mpg" => LegacyTestVideos.MpegPs(new PsOptions { Frames = 30, PictureBytes = 300, StreamMap = true }),
|
||||
"h264.mpg" => LegacyTestVideos.MpegPs(new PsOptions { Video = "h264", Stream = es, Audio = "ac3" }),
|
||||
_ => TestVideos.Mp4(es, new DateTimeOffset(2024, 1, 2, 3, 4, 5, TimeSpan.Zero), rotation: 90, audio: true),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user