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 areSendin the sense that a thread creates and owns them β mark typesunsafe impl Sendif needed, see ARCHITECTURE.md).
StructsΒ§
- MfAudio π
- MfVideo π
- Resamp π
- Linear resampler state carried across decoded buffers.
- Shared
Device πManager IMFDXGIDeviceManageris 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).- Stream
Info π
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/ysare the source edges per destination column/row (len = n+1). - codec_
name π - MF subtype -> ffmpeg-style codec name (cheap; ββ when unknown).
- convert_
rows π β - Copy
hrows ofwBGRX pixels starting attop(row stridepitch, 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.
Nonewhen 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(interleavedchchannels atrate) tofifoas 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).