Module mf

Source
Expand description

Windows Media Foundation backend (IMFSourceReader). Native software decode, no external deps, instant seeks.

Contract (see media/mod.rs):

  • probe(path) -> Asset with duration, size, fps, every audio stream (language/title if available).
  • open_video(path) -> VideoSource producing top-down RGBA8 at the requested size (RGB32 output type + MF_SOURCE_READER_ENABLE_ADVANCED_VIDEO_PROCESSING; handle negative stride / bottom-up; scale to (w,h) β€” either via the reader’s output type or a simple resize in Rust).
  • open_audio(path, stream) -> AudioSource producing stereo f32 @ 48 kHz (PCM float output type; stream = Nth audio stream in container order; resample/upmix in Rust if MF refuses). Seeking: SetCurrentPosition then decode forward until pts >= t. Sequential reads must not seek. COM: MFStartup / CoInitializeEx per thread (decoders live on the thread that created them; they are Send in the sense that a thread creates and owns them β€” mark types unsafe impl Send if needed, see ARCHITECTURE.md).

StructsΒ§

MfAudio πŸ”’
MfVideo πŸ”’
Resamp πŸ”’
Linear resampler state carried across decoded buffers.
SharedDeviceManager πŸ”’
IMFDXGIDeviceManager is documented as safe to share and call from multiple threads (that’s its purpose: every decoder MFT on every thread opens a handle to the same device through it).
StreamInfo πŸ”’

ConstantsΒ§

AUDIO_FWD_FRAMES πŸ”’
Audio: read forward (no seek) when the target is less than this many output frames past the FIFO.
AUDIO_PREROLL_FRAMES πŸ”’
Audio: seek this many output frames early (imprecise MP3 seeks), discard by timestamp.
DXVA_MIN_PIXELS πŸ”’
DXVA pays for itself only on big frames: a hardware decode is a GPU round-trip per frame (submit, decode, video-process, sync, copy back), which costs more than just software-decoding anything SD-sized. Attach the D3D manager at 720p and up.
GUID_NULL πŸ”’
HNS πŸ”’
100 ns ticks per second (MF time base).
MAX_READS πŸ”’
Safety cap on ReadSample calls per request (no busy loops on a misbehaving source).
STABLE_REQS πŸ”’
Consecutive identical size requests before the decoder’s output type follows them (see ensure_decode_size).
VIDEO_FWD_HNS πŸ”’
Video: read forward (no seek) when the target is less than this far ahead of the cached frame.

FunctionsΒ§

audio_format πŸ”’
(sample rate, channels) of the reader’s current output type.
bilinear πŸ”’
box_down πŸ”’
Area-average downscale. xs/ys are the source edges per destination column/row (len = n+1).
codec_name πŸ”’
MF subtype -> ffmpeg-style codec name (cheap; β€œβ€ when unknown).
convert_rows πŸ”’ ⚠
Copy h rows of w BGRX pixels starting at top (row stride pitch, signed) into top-down RGBA.
duration_secs πŸ”’
dxgi_device_manager πŸ”’
D3D11 device + DXGI device manager for hardware-accelerated decode (DXVA). Built once per process; every source reader attaches to the same manager. None when the adapter/driver can’t do it β€” callers fall back to the source reader’s normal software decode, so this is purely a speed opt-in.
err πŸ”’
frame_rate πŸ”’
get_string πŸ”’
hns πŸ”’
init πŸ”’
Process-wide MFStartup + per-thread COM init. Cheap; called on every open.
is_mp4 πŸ”’
MF’s MPEG-4 source (mp4/mov/m4a: MIME */mp4, video/quicktime).
open_audio
open_reader πŸ”’
open_video
probe
push_audio πŸ”’
Append src (interleaved ch channels at rate) to fifo as interleaved stereo @ SAMPLE_RATE. Mono is duplicated, >2 channels keep L/R. Non-48k input is linearly resampled.
streams πŸ”’
Every stream in container order (ffmpeg’s 0:v:N / 0:a:N). Language/title are best effort via the presentation descriptor (descriptor index == reader stream index).