# visioforge/mediafoundationnet architecture

> Architecture diagram of the GitHub repository visioforge/mediafoundationnet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/visioforge/mediafoundationnet
- Repository: https://github.com/visioforge/mediafoundationnet

## Overview

##### Project type and purpose
- This is a .NET class-library project (MediaFoundationNet) whose sole purpose is to expose the Windows Media Foundation COM APIs to managed (.NET) clients.  It consists of two Visual Studio projects:
- MediaFoundation-2010 (the core wrapper)
- MediaFoundation.Extension-2010 (extension methods and helper classes)
- The library sits between a .NET application and the native Media Foundation pipeline on Windows, allowing .NET code to instantiate COM objects, build media topologies, process streams, do capture, playback, etc.

##### File structure
- Top level
- README, Docs/, license files, solution (.sln) and project (.csproj)
- src/
- Core wrapper types (Alt.cs, Externs.cs, MFObjects.cs, MFPlay.cs, MFReadWrite.cs, MFTransform.cs, MFUtils.cs, OpmApi.cs, WMContainer.cs, etc.)
- feature-specific wrappers: e.g. mfmediaengine.cs, mfcaptureengine.cs, mfsharingengine.cs, mfmp2dlna.cs
- src/mfext/
- mfext/*.cs: hundreds of extension-method classes for every IMFXXX interface
- mfext/Interop/: the low-level COM interop helper classes (ComClass, GCPin, MemoryBuffer, RuntimeCallableStream, PropVariantExtensions, etc.)
- mfext/MFPlayer and mfext/Transform: higher-level managed helpers for players and transforms
- No frontend, no database—this is strictly a library.

##### Main components
1. .NET Client (any .NET application referencing the library)
2. MediaFoundationNet Core Assembly
– Wrappers for all MF COM interfaces (src/*.cs)
– Feature groups: CaptureEngine, MediaEngine, Container, MP2DLNA, SharingEngine
3. MediaFoundationNet Extension Assembly
– Extension methods (mfext/*.cs)
– COM interop helpers (mfext/Interop)
– High-level helpers (MFPlayer, MFT)
4. COM Interop Layer
– RCW/CCW plumbing created by .NET runtime
– Low-level COM calls into native DLLs
5. Native Media Foundation components
– MediaSources, MediaSinks, MediaTransforms, MediaSession, Topology
– Windows system DLLs (mf.dll, mfplat.dll, mfreadwrite.dll, dxvahd.dll, etc.)

##### Relationships and interactions
- The .NET Client calls methods on the Core Assembly’s interface classes (for example, IMFMediaSource, IMFTransform, IMFMediaSession).
- Core Assembly types defer to Extension methods and interop helpers for convenience or missing functionality.
- Both assemblies ultimately invoke COM calls (CoCreateInstance, QueryInterface, InvokeMethod) through the Interop layer.
- The COM layer dispatches into native Media Foundation DLLs, creating a pipeline: source → topology → transform → sink.
- Data flow: managed calls → wrappers → COM → native pipeline → back to managed callbacks or streams.

##### Architectural patterns and principles
- Wrapper/Adapter pattern: each COM interface gets a thin C# proxy class.
- Extension methods: augment interface classes without inheritance.
- Separation of concerns:
- Core interfaces vs. helpers/extensions vs. interop plumbing
- Feature modules (Capture, Playback, Transforms, DLNA, Sharing)
- COM interop boundary is explicit (Interop folder).

##### Technologies and frameworks
- .NET Framework / .NET Standard class libraries
- Visual Studio 2010 solution format
- C# 3.0+ extension methods
- Windows COM & Media Foundation native APIs

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layers
    Client[".NET Client"]:::client

    subgraph "MediaFoundationNet Core Assembly"
        PrjCore["MediaFoundation-2010.csproj"]:::managed
        CoreWrappers["Core Wrappers\n(src/)"]:::managed
        FeatureWrap["Feature Wrappers\nCaptureEngine, MediaEngine, MP2DLNA, SharingEngine"]:::managed
    end

    subgraph "MediaFoundationNet Extension Assembly"
        PrjExt["MediaFoundation.Extension-2010.csproj"]:::managed
        ExtMethods["Extension Methods\n(src/mfext/)"]:::managed
        HighHelpers["High-Level Helpers\nMFPlayer, MFT"]:::managed
        IntHelpers["COM Interop Helpers\n(src/mfext/Interop/)"]:::interop
    end

    subgraph "COM Interop Boundary" 
        Boundary[".NET Runtime RCW/CCW\n(low-level COM calls)"]:::interop
    end

    subgraph "Native Media Foundation" 
        NativeComp["Native COM Components\nmf.dll, mfplat.dll, mfreadwrite.dll, dxvahd.dll"]:::native
    end

    %% Connections
    Client --> CoreWrappers
    CoreWrappers --> ExtMethods
    CoreWrappers --> IntHelpers
    ExtMethods --> IntHelpers
    IntHelpers --> Boundary
    Boundary --> NativeComp

    PrjCore --> CoreWrappers
    PrjExt --> ExtMethods

    %% Click Events
    click CoreWrappers "https://github.com/visioforge/mediafoundationnet/tree/main/src/"
    click PrjCore "https://github.com/visioforge/mediafoundationnet/blob/main/src/MediaFoundation-2010.csproj"
    click ExtMethods "https://github.com/visioforge/mediafoundationnet/tree/main/src/mfext/"
    click IntHelpers "https://github.com/visioforge/mediafoundationnet/tree/main/src/mfext/Interop/"
    click PrjExt "https://github.com/visioforge/mediafoundationnet/blob/main/src/mfext/MediaFoundation.Extension-2010.csproj"

    %% Styles
    classDef managed fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef interop fill:#90EE90,stroke:#333,stroke-width:1px
    classDef native fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef client fill:#DDA0DD,stroke:#333,stroke-width:1px
```
