Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
- name: Ensure Media Foundation is installed
shell: pwsh
run: ./build/EnsureMediaFoundation.ps1
- name: Restore, build, ABI tests, pack, and consume packages
shell: pwsh
run: ./build.ps1 -Configuration ${{ matrix.configuration }}
Expand Down Expand Up @@ -85,6 +88,10 @@ jobs:
env:
DXSHARP_FLEET_EVIDENCE: artifacts/sample-results/fleet-system.ppm
run: ./build/VerifyInterop.ps1 -Configuration Release -RuntimeMajor ${{ matrix.runtime }} -PublishAot
- name: Ensure Media Foundation is installed
if: runner.os == 'Windows'
shell: pwsh
run: ./build/EnsureMediaFoundation.ps1
- name: WARP sample qualification
if: runner.os == 'Windows'
shell: pwsh
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ jobs:
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
- name: Ensure Media Foundation is installed
shell: pwsh
run: ./build/EnsureMediaFoundation.ps1
- name: Check the requested version and source branch
id: version
shell: pwsh
Expand Down
30 changes: 30 additions & 0 deletions DXSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DXSharp.Framework.WinUI", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CharacterLab.WinUI", "samples\CharacterLab.WinUI\CharacterLab.WinUI.csproj", "{0BE7F2F5-66C9-4F48-B0EA-412BC17FC649}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DXSharp.Media", "src\DXSharp.Media\DXSharp.Media.csproj", "{CAED65E0-B5AD-4AB3-BB4B-A35AFC8152FF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VideoPlayer", "samples\VideoPlayer\VideoPlayer.csproj", "{87FBB6E0-0B1E-4616-BD9E-B547832286F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -538,6 +542,30 @@ Global
{0BE7F2F5-66C9-4F48-B0EA-412BC17FC649}.Release|x64.Build.0 = Release|x64
{0BE7F2F5-66C9-4F48-B0EA-412BC17FC649}.Release|x86.ActiveCfg = Release|x64
{0BE7F2F5-66C9-4F48-B0EA-412BC17FC649}.Release|x86.Build.0 = Release|x64
{CAED65E0-B5AD-4AB3-BB4B-A35AFC8152FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CAED65E0-B5AD-4AB3-BB4B-A35AFC8152FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CAED65E0-B5AD-4AB3-BB4B-A35AFC8152FF}.Debug|x64.ActiveCfg = Debug|Any CPU
{CAED65E0-B5AD-4AB3-BB4B-A35AFC8152FF}.Debug|x64.Build.0 = Debug|Any CPU
{CAED65E0-B5AD-4AB3-BB4B-A35AFC8152FF}.Debug|x86.ActiveCfg = Debug|Any CPU
{CAED65E0-B5AD-4AB3-BB4B-A35AFC8152FF}.Debug|x86.Build.0 = Debug|Any CPU
{CAED65E0-B5AD-4AB3-BB4B-A35AFC8152FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CAED65E0-B5AD-4AB3-BB4B-A35AFC8152FF}.Release|Any CPU.Build.0 = Release|Any CPU
{CAED65E0-B5AD-4AB3-BB4B-A35AFC8152FF}.Release|x64.ActiveCfg = Release|Any CPU
{CAED65E0-B5AD-4AB3-BB4B-A35AFC8152FF}.Release|x64.Build.0 = Release|Any CPU
{CAED65E0-B5AD-4AB3-BB4B-A35AFC8152FF}.Release|x86.ActiveCfg = Release|Any CPU
{CAED65E0-B5AD-4AB3-BB4B-A35AFC8152FF}.Release|x86.Build.0 = Release|Any CPU
{87FBB6E0-0B1E-4616-BD9E-B547832286F3}.Debug|Any CPU.ActiveCfg = Debug|x64
{87FBB6E0-0B1E-4616-BD9E-B547832286F3}.Debug|Any CPU.Build.0 = Debug|x64
{87FBB6E0-0B1E-4616-BD9E-B547832286F3}.Debug|x64.ActiveCfg = Debug|x64
{87FBB6E0-0B1E-4616-BD9E-B547832286F3}.Debug|x64.Build.0 = Debug|x64
{87FBB6E0-0B1E-4616-BD9E-B547832286F3}.Debug|x86.ActiveCfg = Debug|x64
{87FBB6E0-0B1E-4616-BD9E-B547832286F3}.Debug|x86.Build.0 = Debug|x64
{87FBB6E0-0B1E-4616-BD9E-B547832286F3}.Release|Any CPU.ActiveCfg = Release|x64
{87FBB6E0-0B1E-4616-BD9E-B547832286F3}.Release|Any CPU.Build.0 = Release|x64
{87FBB6E0-0B1E-4616-BD9E-B547832286F3}.Release|x64.ActiveCfg = Release|x64
{87FBB6E0-0B1E-4616-BD9E-B547832286F3}.Release|x64.Build.0 = Release|x64
{87FBB6E0-0B1E-4616-BD9E-B547832286F3}.Release|x86.ActiveCfg = Release|x64
{87FBB6E0-0B1E-4616-BD9E-B547832286F3}.Release|x86.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -586,6 +614,8 @@ Global
{CA095DE4-9BC3-49E4-A764-D4406AA4D795} = {29411031-4490-4542-B2D1-02D223BFD605}
{A466B395-6AE2-4EA8-8AE7-576F60182FC0} = {29411031-4490-4542-B2D1-02D223BFD605}
{0BE7F2F5-66C9-4F48-B0EA-412BC17FC649} = {AEE84FD5-7441-42CF-AA6C-5805B759E1F8}
{CAED65E0-B5AD-4AB3-BB4B-A35AFC8152FF} = {29411031-4490-4542-B2D1-02D223BFD605}
{87FBB6E0-0B1E-4616-BD9E-B547832286F3} = {AEE84FD5-7441-42CF-AA6C-5805B759E1F8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7C4990EC-248E-49D5-A254-EA8AD214C338}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The first command presents four frames and exits. The second verifies GPU comput
| `DXSharp.Assets` | Static glTF/GLB models, materials, transforms, and decoded textures |
| `DXSharp.Core` | D3D12, DXGI, DXC, and generated COM interop |
| `DXSharp.Framework.Desktop` | WinForms presentation loop, swap-chain resize, and frame-slot retirement |
| `DXSharp.Media` | Media Foundation frame-server playback and precompiled D3D12 video-texture rendering; [media contract](doc/Media-Playback.md) |
| `DXSharp.Framework.WinUI` | Optional WinUI 3 composition viewport and XAML overlays; [hosting contract](doc/WinUI-Hosting.md) |
| `DXSharp.Framework.Wpf` | Optional WPF child-HWND viewport using the shared frame renderer; [hosting contract](doc/Wpf-Hosting.md) |
| `DXSharp.DirectML` | Device and operator ownership, tensor binding, and DirectML execution |
Expand Down
11 changes: 11 additions & 0 deletions build/EnsureMediaFoundation.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[CmdletBinding()]
param()
$ErrorActionPreference = 'Stop'
if (-not $IsWindows) { return }
if (Get-Command Get-WindowsFeature -ErrorAction SilentlyContinue) {
$feature = Get-WindowsFeature -Name Server-Media-Foundation
if ($feature -and -not $feature.Installed) {
$result = Install-WindowsFeature -Name Server-Media-Foundation
if (-not $result.Success -or $result.RestartNeeded -eq 'Yes') { throw 'Media Foundation installation did not complete without a reboot.' }
}
}
6 changes: 3 additions & 3 deletions build/VerifyPackages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ try {
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($version)) {
throw 'Unable to evaluate the package version.'
}
foreach ($name in @('DXSharp', 'DXSharp.Dxc', 'DXSharp.Framework', 'DXSharp.Framework.Desktop', 'DXSharp.Framework.Wpf', 'DXSharp.Framework.WinUI', 'DXSharp.Native', 'DXSharp.Assets', 'DXSharp.Core', 'DXSharp.DirectML')) {
foreach ($name in @('DXSharp', 'DXSharp.Dxc', 'DXSharp.Framework', 'DXSharp.Framework.Desktop', 'DXSharp.Framework.Wpf', 'DXSharp.Framework.WinUI', 'DXSharp.Media', 'DXSharp.Native', 'DXSharp.Assets', 'DXSharp.Core', 'DXSharp.DirectML')) {
$path = Join-Path $packageDirectory "$name.$version.nupkg"
if (-not (Test-Path $path)) { throw "Missing package: $path" }
$archive = [System.IO.Compression.ZipFile]::OpenRead($path)
Expand All @@ -32,13 +32,13 @@ try {
('Microsoft.WindowsDesktop.App.WPF' -notin $frameworkReferences -or 'Microsoft.WindowsDesktop.App.WindowsForms' -in $frameworkReferences)) {
throw 'The WPF package must declare WPF without acquiring Windows Forms.'
}
if ($name -in @('DXSharp.Native', 'DXSharp.Core', 'DXSharp.Framework', 'DXSharp.Assets') -and
if ($name -in @('DXSharp.Native', 'DXSharp.Core', 'DXSharp.Framework', 'DXSharp.Assets', 'DXSharp.Media') -and
@($frameworkReferences | Where-Object { $_ -like 'Microsoft.WindowsDesktop*' }).Count -gt 0) {
throw "Optional desktop framework leaked into $name."
}
$assemblies = @($archive.Entries | Where-Object FullName -CLike "lib/*/$name.dll")
if ($assemblies.Count -eq 0) { throw "No library assembly found in $path" }
if ($name -in @('DXSharp.Native', 'DXSharp.Core', 'DXSharp.DirectML', 'DXSharp.Framework.Desktop', 'DXSharp.Framework.Wpf', 'DXSharp.Framework.WinUI', 'DXSharp.Assets', 'DXSharp.Framework')) {
if ($name -in @('DXSharp.Native', 'DXSharp.Core', 'DXSharp.DirectML', 'DXSharp.Framework.Desktop', 'DXSharp.Framework.Wpf', 'DXSharp.Framework.WinUI', 'DXSharp.Assets', 'DXSharp.Framework', 'DXSharp.Media')) {
foreach ($major in '10', '11') {
# NuGet normalizes the trailing zero of the Windows platform version.
$framework = if ($name -eq 'DXSharp.Assets') { "net$major.0" } else { "net$major.0-windows10.0.26100" }
Expand Down
1 change: 1 addition & 0 deletions build/VerifySamples.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ try {
Invoke-Sample 'CharacterLab-wpf-host' @('run', '--project', 'samples/CharacterLab.Wpf', '-c', 'Debug', '--', '--warp', '--host-test')
Invoke-Sample 'CharacterLab-winui' @('run', '--project', 'samples/CharacterLab.WinUI', '-c', 'Debug', '--', '--warp', '--frames=9')
Invoke-Sample 'CharacterLab-winui-host' @('run', '--project', 'samples/CharacterLab.WinUI', '-c', 'Debug', '--', '--warp', '--host-test')
Invoke-Sample 'VideoPlayer' @('run', '--project', 'samples/VideoPlayer', '-c', 'Debug', '--', '--warp', '--test')
Invoke-Sample 'DepthStencil' @('run', '--project', 'samples/DepthStencil', '-c', 'Debug', '--', '--warp')

Invoke-Sample 'ModernTriangle' @('run', '--project', 'samples/ModernTriangle', '-c', 'Debug', '--',
Expand Down
2 changes: 1 addition & 1 deletion build/release_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import xml.etree.ElementTree as ET
from zipfile import ZipFile

PACKAGE_IDS = ("DXSharp.Native", "DXSharp.Assets", "DXSharp.Core", "DXSharp.DirectML", "DXSharp.Framework", "DXSharp.Framework.Desktop", "DXSharp.Framework.Wpf", "DXSharp.Framework.WinUI", "DXSharp.Tools.Builds")
PACKAGE_IDS = ("DXSharp.Native", "DXSharp.Assets", "DXSharp.Core", "DXSharp.DirectML", "DXSharp.Framework", "DXSharp.Framework.Desktop", "DXSharp.Framework.Wpf", "DXSharp.Framework.WinUI", "DXSharp.Media", "DXSharp.Tools.Builds")
PREVIEW = re.compile(r"(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)-(?:net10-)?preview\.[1-9][0-9]*")


Expand Down
8 changes: 7 additions & 1 deletion build/verify_sample_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import tempfile
import xml.etree.ElementTree as ET

SDK_PACKAGES = ("DXSharp.Native", "DXSharp.Core", "DXSharp.DirectML", "DXSharp.Framework.Desktop", "DXSharp.Framework.Wpf", "DXSharp.Framework.WinUI", "DXSharp.Assets", "DXSharp.Framework")
SDK_PACKAGES = ("DXSharp.Native", "DXSharp.Core", "DXSharp.DirectML", "DXSharp.Framework.Desktop", "DXSharp.Framework.Wpf", "DXSharp.Framework.WinUI", "DXSharp.Assets", "DXSharp.Framework", "DXSharp.Media")
EXCLUDED = {"bin", "obj", "artifacts", ".vs"}


Expand Down Expand Up @@ -134,6 +134,12 @@ def qualify(configuration, runtime_major):
raise RuntimeError(f'WinUI precompiled consumer deployed {name}')
run([str(winui), '--warp', '--frames=9'], consumer, evidence / 'character-winui-runtime.log', executable=True)
run([str(winui), '--warp', '--host-test'], consumer, evidence / 'character-winui-host.log', executable=True)
media_project = consumer / 'samples/VideoPlayer/VideoPlayer.csproj'
media = Path(subprocess.check_output(['dotnet', 'msbuild', str(media_project), f'-p:Configuration={configuration}', '-p:Platform=Any CPU', '-getProperty:TargetPath', '-nologo'], cwd=consumer, text=True).strip()).with_suffix('.exe')
for name in ('dxcompiler.dll', 'dxil.dll'):
if (media.parent / name).exists():
raise RuntimeError(f'Media precompiled consumer deployed {name}')
run([str(media), '--warp', '--test'], consumer, evidence / 'video-player.log', executable=True)
(evidence / "samples.json").write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
print(f"PASS: all {len(manifest)} runnable samples consume packaged SDK {version} outside the checkout.")

Expand Down
1 change: 1 addition & 0 deletions doc/API-Coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ApiCoverage reads the pinned WinMD and built assembly with System.Reflection.Met
| Direct2D | 359 / 359 | 1600 / 1600 |
| DirectWrite | 207 / 207 | 1287 / 1287 |
| WIC | 139 / 139 | 948 / 948 |
| Media Foundation, including pinned D3D12 video declarations | 1650 / 1650 | 8484 / 8484 |
| Audio, including XAudio2 and DirectSound | 474 / 474 | 3647 / 3647 |
| Raw input | 20 / 20 | 91 / 91 |
| DirectInput and HID | 141 / 141 | 5546 / 5546 |
Expand Down
39 changes: 39 additions & 0 deletions doc/Media-Playback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Media playback

Preview 4 development adds the optional `DXSharp.Media` assembly and one `samples/VideoPlayer` application. The application reuses the existing WinUI composition host. CharacterLab remains the shared host-regression scene; media functionality is implemented in a reusable library.

## Native declarations and ownership

DXSharp.Native projects the complete pinned `Windows.Win32.Media.MediaFoundation` namespace. The name/member/IID gate measures 1,650 top-level types and 8,484 member names against Win32Metadata 71.0.45-preview and the selected Agility metadata. This includes the pinned Direct3D 12 video interfaces located in that namespace. Declaration coverage does not establish every ABI shape, driver capability, codec or video-queue workflow.

`MediaNative` supplies raw owned-output overloads for MF attribute creation, in-process COM activation and writable WIC section bitmaps. Each successful output transfers one native reference. Media uses Core's `NativeInterface<T>` leases and a source-generated factory shim so output references and private projections are deterministically released. Media Engine callbacks use a generated managed COM class; native callback threads record errors, while the application thread owns playback, presentation and disposal.

## Playback contract

Create `MediaPlayer` on the application thread, call `Open` with an existing local file, then `Play`. Pause, seek, volume, mute and looping are exposed. Media Engine supplies the native playback pipeline, audio output and A/V presentation clock. No custom decode thread or unbounded managed frame queue is created.

`TryGetFrame` polls `OnVideoStreamTick` and transfers one due frame through an explicitly writable WIC bitmap. It returns borrowed tightly packed BGRA bytes, native video PTS and a source/seek generation. The bytes remain valid until the next frame transfer, Open or Dispose on that player. Copy them if retaining them. Missing frames and in-progress seeks return false. Open and Seek invalidate the renderer's old-generation display. Source and display aspect ratios remain distinct.

This initial backend is **Media Foundation → WIC BGRA → CPU staging → D3D12 upload**. It supplies SDR 8-bit presentation and does not claim zero-copy interop, HDR handling, or direct D3D12 decoding. Hardware acceleration is reported as unmeasured, not inferred from successful playback. Codec availability depends on installed Windows media components. Network/protected sources are outside the local-file wrapper.

`VideoTextureRenderer.Draw(RenderFrame)` uses persistent per-slot textures and the shared upload ring. The host must retire the supplied frame slot before reuse. Every slot receives the newest CPU frame before it is sampled, avoiding alternating stale frames when display and video rates differ. The source display aspect is fitted to the target with letterboxing. Shaders are precompiled and embedded in Media; the sample excludes runtime DXC DLLs.

Stop and await the viewport, dispose the video renderer, then dispose the player and device. MediaPlayer shuts down the engine before releasing its interfaces, callback owner, bitmap and mapping, and balances MF/COM initialization on the creating thread. Dispose is idempotent; other calls after disposal fail. The sample uses explicit WinUI dispatcher shutdown so asynchronous cleanup and post-close checks complete before the message loop exits.

## Sample and evidence

Run:

```powershell
dotnet run --project samples/VideoPlayer -c Release
dotnet run --project samples/VideoPlayer -c Release -- --file="C:\Media\clip.mp4"
dotnet run --project samples/VideoPlayer -c Release -- --warp --test
```

The sample provides local file selection, seek, play/pause/restart, loop, volume/mute and transfer diagnostics. The default original H.264/AAC fixture contains a color/motion pattern, white flashes and synchronized 880 Hz pulses. `Assets/generate_fixture.py` records the reproducible FFmpeg source and updates SHA-256 hashes. FFmpeg is a development-only fixture-generation tool, not a runtime/package dependency.

The `--test` fixture has no audio stream so hosted Windows machines without audio endpoints can execute the real video decoder and playback clock. Add `--diagnostics` when investigating the reported hardware startup crash; lifecycle/HRESULT logs are written under `%LOCALAPPDATA%/DXSharp/logs`. The bounded tests check BGRA colors/geometry, duration, pause, seek generation, video PTS/clock offset, resize bursts, end-of-stream, looping, reopening, missing paths, repeated engine creation/disposal and post-close callback inactivity. They join source and isolated package consumption on .NET 10/11. Windows Server CI installs its Media Foundation feature if absent.

The displayed PTS-minus-clock offset is not a measurement of physical speaker latency or independent A/V drift. Audible synchronization, endpoint/device changes and actual hardware decode behavior need separate workstation review using the audio-bearing fixture. A silent CI pass does not qualify audible output. Media JIT playback is the first runtime target; NativeAOT media callbacks need a dedicated playback qualification before an AOT media claim. SDK COM ownership/AOT gates remain independent.

References: [Media Engine](https://learn.microsoft.com/windows/win32/api/mfmediaengine/nn-mfmediaengine-imfmediaengine), [frame transfer](https://learn.microsoft.com/windows/win32/api/mfmediaengine/nf-mfmediaengine-imfmediaengine-transfervideoframe), [frame-server ticks](https://learn.microsoft.com/windows/win32/api/mfmediaengine/nf-mfmediaengine-imfmediaengine-onvideostreamtick), [D3D12 video](https://learn.microsoft.com/windows/win32/medfound/direct3d-12-video-overview).
17 changes: 17 additions & 0 deletions doc/Preview4-Candidate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Preview 4 candidate cutoff

The intended package version is `0.4.0-preview.4`. The feature cutoff combines the modern Framework/character workload, texture transfers, shader build tooling, native/WinForms/WPF/WinUI hosts and the first reusable Media Foundation playback path. CharacterLab variants remain shared host regression tests. DirectStorage, current GameInput, X3DAudio and the visual DXR scene continue in later bounded iterations.

The release manifest contains ten modern package IDs, including the optional `DXSharp.Media`, for twenty package/symbol archives. Public release preparation must retain the exact qualifying commit and archive hashes. Legacy packages remain separate compatibility artifacts.

Before publication:

- Complete Windows Debug/Release source and isolated package qualification on .NET 10/11, including VideoPlayer.
- Pass native COM JIT/NativeAOT gates, native API coverage and shader package checks.
- Retest both WinUI samples on affected hardware: no VideoPlayer `0xC000027B` startup/activation failure, no CharacterLab move/resize freeze, successful repeated close/reopen and monitor DPI changes. Preserve diagnostic logs for any recurrence.
- Review Media Lab on hardware with its audio-bearing fixture: play/pause/seek/loop, correct audio/video alignment, resize and repeated open/close. Record actual decoder/transfer behavior and unsupported cases.
- Document Framework's breaking migration and the JIT-only qualification of optional desktop/media workloads.
- Finalize matching versioned release notes only when the candidate is approved for publication; merging a versioned release-note file triggers the release workflow.
- Qualify and publish the immutable candidate, then verify every public NuGet package with a fresh public-feed consumer.

The generated Media Foundation/D3D12 video inventory is distinct from runtime-qualified playback. Direct D3D12 video commands, zero-copy video transfer and independently measured audio-output latency are not claims of this candidate.
Loading
Loading