diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md index 4414bbab..eee9bb36 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -50,3 +50,8 @@ One line per decision: date · decision · alternative · reason. | 2026-10-02 | HEIF `irot`/`imir` override Exif orientation (imir axis 0 = top↔bottom). | Exif first | HEIF decoders apply the transforms themselves; both would rotate twice. | | 2026-10-02 | Main image size comes from the container's own size field (SOF, IHDR, ispe, VP8X, RAF crop record, RW2 borders, CR3 CMP1) before raster IFDs. | Always the largest raster IFD | That is what each container defines and what decoders output. | | 2026-10-02 | Only MPF large-thumbnail entries count as previews; XMP date-only values are never used as capture times. | Every secondary image / midnight | Gain maps are not previews; midnight would be invented. | +| 2026-10-02 | Media Foundation interop uses `[GeneratedComInterface]` with explicit release; threads entering MF call `Win32Com.EnsureInitialized()` (MTA unless already STA). | `[ComImport]` like WIC | Hardware encoders stall when sample references wait for GC; source-generated COM does not initialise apartments, so it is done explicitly. | +| 2026-10-02 | MP4: 16-byte `free`+`mdat` placeholder rewritten to a 64-bit header past 4 GiB; negative composition offsets shifted to ctts v0 plus an edit list; parameter sets moved into avcC/hvcC; fast start on by default. | Always 64-bit mdat / ctts v1 | Small files stay maximally compatible; wider player support. | +| 2026-10-02 | GIF: Wu-criterion median cut, frame differencing against the source last drawn, identical frames merged by holding one back. | Plain median cut / diff against dithered output | Max palette error 37 → small; 945 KB → 52 KB at equal PSNR; exact delays. | +| 2026-10-02 | AVI always carries OpenDML indexes plus idx1 (1 GiB RIFF segments). | idx1 only | Files beyond 2 GB stay playable. | +| 2026-10-02 | MF encoder capabilities: software H.264 ≤ 4096×2304, hardware assumed 4096² (H.264) / 8192² (HEVC/AV1); an unsupported size fails at media-type negotiation and the next encoder is tried. | Querying limits | MF has no reliable capability query. | diff --git a/src/Titano.Core.Windows/MediaFoundation/MediaFoundationEncoderSession.cs b/src/Titano.Core.Windows/MediaFoundation/MediaFoundationEncoderSession.cs index f82354aa..7014417a 100644 --- a/src/Titano.Core.Windows/MediaFoundation/MediaFoundationEncoderSession.cs +++ b/src/Titano.Core.Windows/MediaFoundation/MediaFoundationEncoderSession.cs @@ -102,6 +102,7 @@ public sealed class MediaFoundationEncoderSession : IVideoEncoderSession public void WriteFrame(ImageBuffer frame, long duration90k) { + Interop.Win32Com.EnsureInitialized(); ObjectDisposedException.ThrowIf(_disposed, this); if (_completed) throw new InvalidOperationException("The session is complete"); if (frame.Width != _settings.Width || frame.Height != _settings.Height) throw new ArgumentException("Frame size differs from the encode size", nameof(frame)); @@ -136,6 +137,7 @@ public sealed class MediaFoundationEncoderSession : IVideoEncoderSession public void Complete() { + Interop.Win32Com.EnsureInitialized(); ObjectDisposedException.ThrowIf(_disposed, this); if (_completed) throw new InvalidOperationException("The session is already complete"); if (_framesIn == 0) throw new InvalidOperationException("No frames were written"); diff --git a/src/Titano.Core.Windows/MediaFoundation/MediaFoundationRuntime.cs b/src/Titano.Core.Windows/MediaFoundation/MediaFoundationRuntime.cs index a8cfb3a1..bf029fea 100644 --- a/src/Titano.Core.Windows/MediaFoundation/MediaFoundationRuntime.cs +++ b/src/Titano.Core.Windows/MediaFoundation/MediaFoundationRuntime.cs @@ -16,6 +16,8 @@ internal static class MediaFoundationRuntime public static IDisposable Acquire() { if (!IsAvailable) throw new PlatformNotSupportedException("Media Foundation is not available on this system"); + // Media Foundation requires COM on the calling thread; source-generated COM does not initialise it implicitly. + Interop.Win32Com.EnsureInitialized(); lock (Gate) { if (_references == 0) ComObjects.Check(MfNative.MFStartup(MfNative.Version, MfNative.StartupLite), "MFStartup");