pub trait CodecResolver: Sync {
// Required method
fn resolve_tag(&self, ctx: &ProbeContext<'_>) -> Option<CodecId>;
// Provided method
fn resolve_payload_magic(&self, first_bytes: &[u8]) -> Option<CodecId> { ... }
}Expand description
Resolve a CodecTag (FourCC / WAVEFORMATEX / Matroska id / …) to a
CodecId. The oxideav-codec
registry implements this, but defining the trait here lets
containers consume tag resolution via &dyn CodecResolver without
pulling in the codec crate as a direct dependency.
Inverse direction (codec_id → wire tag) is intentionally NOT a
method on this trait. Wire tags are per-stream state: different
mpeg4video streams correctly identify as DIVX / XVID /
MP4V / FMP4, different h264 streams as H264 vs AVC1,
and so on. The stream’s CodecParameters::tag field is the
canonical home for that data — set by the demuxer when reading
existing media and by the encoder via its output_params() at
configure-time. A registry-level “give me the canonical tag for
this codec_id” lookup walks registration order and returns
whichever tag was declared first, which is arbitrary and breaks
round-trip preservation.
Required Methods§
Sourcefn resolve_tag(&self, ctx: &ProbeContext<'_>) -> Option<CodecId>
fn resolve_tag(&self, ctx: &ProbeContext<'_>) -> Option<CodecId>
Resolve the tag in ctx.tag to a codec id. Implementations walk
every registration whose tag set contains the tag, call each
probe (treating None as “always 1.0”), and return the id with
the highest resulting confidence. Ties are broken by
registration order.
Provided Methods§
Sourcefn resolve_payload_magic(&self, first_bytes: &[u8]) -> Option<CodecId>
fn resolve_payload_magic(&self, first_bytes: &[u8]) -> Option<CodecId>
Resolve a codec from a stream’s leading payload bytes, for carriage formats that announce the codec in the payload itself rather than through a container tag.
The canonical case is Ogg, which has no numeric codec tag at
all: a logical stream announces its codec purely through a
magic byte prefix at the start of the first packet
(\x01vorbis, OpusHead, \x80theora, \x7fFLAC,
Speex , …); raw elementary streams identified by a file
head are the same shape. That identification model is
prefix-shaped rather than exact-key-shaped, so it gets its own
resolution entry point instead of a CodecTag form: codec
crates declare the magic prefixes they answer to at
registration time, and the caller hands the stream’s leading
payload bytes (an Ogg demuxer: the first packet of a logical
stream; a raw-stream prober: the file head — or however much of
it is available) to this method. Implementations return the
codec whose declared magic is a prefix of first_bytes,
preferring the longest
matching magic (most specific claim) and breaking remaining
ties by registration order.
The default implementation resolves nothing, so existing
resolver implementations (and NullCodecResolver) are
unaffected.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl CodecResolver for CodecRegistry
Implement the shared CodecResolver interface so container
demuxers can accept &dyn CodecResolver without depending on
this crate directly — the trait lives in oxideav-core.