fix(windows): initialise COM on threads entering Media Foundation; record video decisions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 10:11:17 +00:00
1 parent f74ca54b33
commit a15cecd658
3 files changed
+9

No files matched your search

@@ -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");
@@ -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");