Crate styx_codec

Crate styx_codec 

Source
Expand description

§styx-codec

Unified codec trait plus a registry for pluggable encoders/decoders. Includes MJPEG decoding and raw color converters; optional features enable FFmpeg and alternate JPEG implementations.

§Documentation

§Install

[dependencies]
styx-codec = "0.1.0"

§Codec trait

use styx_codec::prelude::*;

pub struct Passthrough {
    desc: CodecDescriptor,
}

impl Codec for Passthrough {
    fn descriptor(&self) -> &CodecDescriptor { &self.desc }
    fn process(&self, input: FrameLease) -> Result<FrameLease, CodecError> {
        if input.meta().format.code != self.desc.input {
            return Err(CodecError::FormatMismatch { expected: self.desc.input, actual: input.meta().format.code });
        }
        Ok(input)
    }
}

CodecDescriptor describes the kind (encoder/decoder), input/output FourCc, algorithm family, and implementation name.

§Registry

CodecRegistry installs codecs and returns a CodecRegistryHandle for lookups:

use styx_codec::prelude::*;
use std::sync::Arc;

let registry = CodecRegistry::new();
let handle = registry.handle();
registry.register(FourCc::new(*b"MJPG"), Arc::new(MjpegDecoder::new(FourCc::new(*b"RG24"))));

let frame = /* FrameLease carrying MJPG data */;
let decoded = handle.process(FourCc::new(*b"MJPG"), frame)?;

Selection can be influenced via:

  • set_policy(CodecPolicy): ordered impls, priorities, and hardware bias per FourCc.
  • set_impl_priority / enable_only / disable_impl: granular control over implementations.
  • lookup_preferred / process_preferred: choose by ordered impl names and hardware bias.

CodecStats tracks processed/errors/backpressure counters via the handle.

§Built-in codecs

  • MJPEG decoder (default feature set).
  • Raw color converters: YUYV/NV12/I420 → RGB, RGBA/BGRA/BGR → RGB, passthrough.
  • Optional FFmpeg (codec-ffmpeg): H264/H265/MJPEG encoders/decoders.
  • Optional JPEG (codec-mozjpeg, codec-turbojpeg, codec-zune): alternate MJPEG backends.
  • Optional image feature: ImageAnyDecoder and helpers for DynamicImage conversions.

See crates/styx/examples/mjpeg_decode.rs for an end-to-end registry/decode usage example.

Modules§

decoder
Decoder namespace with per-format modules.
encoder
Encoder namespace with per-format modules.
mjpeg
prelude

Structs§

CodecDescriptor
Descriptor for a codec implementation.
CodecPolicy
Typed policy for choosing codecs (impl priorities + hardware bias).
CodecPolicyBuilder
Builder for codec selection policy.
CodecRegistry
Registry used to install codecs.
CodecRegistryHandle
Thread-safe handle for codec registration/lookups.
CodecStats
Basic stats for codec processing.
Preference
Preference for selecting codecs by FourCc.

Enums§

CodecError
Errors emitted by codecs.
CodecKind
Encoders/decoders share the same entry-point; the kind distinguishes behavior.
RegistryError
Errors surfaced by the registry.

Traits§

Codec
Unified codec trait for zero-copy processing.