test(windows): MediaPlayer playback check of the Media Foundation output

BRIEF §20.2 lists a MediaPlayer playback check after the Media Foundation encode
smoke test; the encoder tests stopped at the MP4 inspector. The new test encodes
two seconds of software H.264, opens the file with WPF's MediaPlayer and checks
its natural size and duration (failing on MediaFailed or a timeout), then
decodes the first frame with a Media Foundation source reader and checks its
size, the file's duration and the picture that was encoded. Without Windows Media
Player (Windows Server, "N" editions) the source reader decode is the check.
Core.Windows.Tests references WPF through its framework reference only, so its
implicit usings stay as they are.

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-12 10:05:58 +00:00
1 parent e583b6ed74
commit a8cf92b4a4
3 files changed
+283

No files matched your search

@@ -65,6 +65,48 @@ public sealed class MediaFoundationEncoderTests(TestContext context)
Assert.Count(1, Directory.GetFiles(dir)); // no temporary file left behind
}
/// <summary>
/// BRIEF §20.2: what the encoder writes plays in Windows. MediaPlayer (Windows Media Player's pipeline) opens it at
/// the encoded size and length; a Media Foundation source reader decodes its first frame to the picture that was
/// encoded, which is the whole check where Windows Media Player is not installed (Windows Server, "N" editions).
/// </summary>
[Test]
[WindowsOnly]
[Timeout(120_000)]
public void SoftwareH264OutputPlaysBack()
{
RequireEncoder(VideoCodec.H264, hardware: false, tenBit: false);
var dir = context.CreateTempDirectory();
var settings = Settings(Path.Combine(dir, "playback.mp4"), VideoCodec.H264, 8) with { PreferHardware = false };
using (var session = new MediaFoundationEncoderProvider().Open(settings))
{
WriteFrames(session, 60, 8);
session.Complete();
}
if (Mp4Playback.HasMediaPlayer)
{
var opened = Mp4Playback.OpenWithMediaPlayer(settings.OutputPath, TimeSpan.FromSeconds(60));
context.Log($"MediaPlayer: {opened}");
Assert.Equal(1280, opened.Width);
Assert.Equal(720, opened.Height);
Assert.Approximately(2.0, opened.Duration.TotalSeconds, 0.05);
}
else
{
context.Log("Windows Media Player is not installed: the source reader decode is the playback check");
}
var frame = Mp4Playback.DecodeFirstFrame(settings.OutputPath);
context.Log($"source reader: {frame.Width}×{frame.Height}, {frame.Duration}, luma square {frame.LumaAt(100, 360)}, corner {frame.LumaAt(4, 4)}");
Assert.Equal(1280, frame.Width);
Assert.Equal(720, frame.Height);
Assert.Approximately(2.0, frame.Duration.TotalSeconds, 0.05);
// Frame 0 as WriteFrames drew it: the white square centred at (100, 360) on a dark blue corner.
Assert.Greater(frame.LumaAt(100, 360), 200);
Assert.Less(frame.LumaAt(4, 4), 60);
}
[Test]
[WindowsOnly]
[Timeout(60_000)]