Skip to main content

Crate kessel_video

Crate kessel_video 

Source
Expand description

§kessel-video

Cameras, screen capture, pixels and video codecs for apps that carry live video over their own transport. No RTP, no keys, no ciphertext and no signalling: the app does those, and hands kessel-video only plaintext frames it has already decrypted and verified.

  • One VideoBackend per app (system, null or fake::FakeBackend): capabilities, cameras, permissions, screens and windows, encoders, decoders, conversion, and machine-wide events.
  • Frame-in sources (frame_in()): the host pushes frames it already has (an iPhone’s broadcast upload extension, through the app) into a FrameSource like any other.
  • Sources, encoders and decoders work by submit and poll, with a Wake callback and small bounded queues that never block the producer. No async runtime: kessel-video runs its own threads.
  • Codec-neutral: VP8 as raw RFC 6386 frames, H.264 as one Annex B access unit (4-byte start codes, SPS and PPS before every IDR). H.264 comes only from the operating system’s codecs (VideoToolbox on macOS and iOS, Media Foundation on Windows, MediaCodec on Android); no codec library is linked or shipped.

§Example

use kessel_video::{fake, no_wake, EncodeOptions, EncoderConfig, VideoBackend};

let backend = fake::FakeBackend::new(fake::FakeConfig::default());
let mut camera = backend.open_camera(None, Default::default(), no_wake())?;
let mut encoder = backend.encoder(EncoderConfig::h264(640, 360, 30, 600_000), no_wake())?;
let frame = loop {
    if let Some(f) = camera.try_recv() {
        break f;
    }
    std::thread::sleep(std::time::Duration::from_millis(5));
};
encoder.submit(&frame, EncodeOptions::default())?;
let encoded = loop {
    if let Some(r) = encoder.poll() {
        break r?;
    }
    std::thread::sleep(std::time::Duration::from_millis(1));
};
assert!(encoded.keyframe && encoded.data.starts_with(&[0, 0, 0, 1]));

Re-exports§

pub use kit::now_us;
pub use bytes;

Modules§

fake
A scripted backend for tests on any machine: cameras and screens that draw a readable frame code, scripted permissions, hot-plug and events, a structural H.264 codec, and faults.
h264
H.264 bitstream helpers: Annex B and AVCC framing, NAL unit types, parameter sets and the codec strings for SDP and WebCodecs.
kit
Building blocks for backends: they turn a synchronous codec core into the submit + poll VideoEncoder / VideoDecoder with threads of their own, bounded queues and wake-ups, and give capture code one place to queue frames and events. The OS backends here use them; codec crates and phone backends can too.

Structs§

AndroidContext
The host app’s Android handles and lifecycle, and the MediaProjection for screen capture, for the Android backend. Other platforms ignore it.
Bytes
A cheaply cloneable and sliceable chunk of contiguous memory.
CameraInfo
A camera.
Capabilities
The whole capability answer of a backend.
CaptureConstraints
What to ask of a capture source. The backend picks the nearest mode at or above the size (then scales down) and at or above fps (then drops frames evenly). None: the device’s default.
CaptureMode
One mode a camera offers.
CodecCapability
What one backend can do with one codec in one direction. One entry per (codec, direction, implementation).
DecoderConfig
One decoder per remote track (or per file, in DecodeMode::File).
DecoderStats
A decoder’s counters.
EncodeOptions
Options for one submit.
EncodedFrame
One encoded frame, plaintext.
EncodedInput
One complete, decrypted, verified frame from the depacketiser.
EncoderConfig
One encoder instance, one simulcast layer.
EncoderInfo
What an encoder actually runs.
EncoderStats
An encoder’s counters.
EventHub
The sending side of every subscriber’s queue. Public so backends in other crates fan out events the same way.
EventRx
A machine-wide event queue (32 deep, oldest dropped). Each VideoBackend::subscribe gets every event.
FrameIn
The source side of frame_in(): an ordinary FrameSource.
FrameInOptions
Settings for frame_in().
FrameInSender
The host’s side of a frame_in() source. Clone it freely; the source ends when the last clone is dropped.
H264Capability
H.264 abilities of one codec entry.
H264Level
An H.264 level_idc (31 = 3.1, 40 = 4.0).
LayerInfo
Where an encoded frame sits in the temporal and spatial structure.
NativeBuffer
A shared native buffer.
PickOptions
Options for the OS picker.
Planes
CPU planes. data holds every plane; plane i starts at offsets[i] with row stride strides[i]. Unused planes have stride 0 (NV12 uses 2; BGRA and RGBA use 1).
Rates
A runtime rate change. Never causes a keyframe.
ScreenCapability
Screen capture support.
ScreenSourceInfo
A display or window from screen_sources.
SourceStats
A source’s counters since open.
SystemConfig
Backend settings.
VideoFrame
One raw video frame. Always upright: the backend applies the camera’s rotation before handing it out.

Enums§

BackendEvent
Machine-wide events.
CodecConfig
Per-codec settings.
CodecDirection
Encode or decode.
ColorSpace
Colour description (v1 is BT.601/709 limited range).
ContentHint
What the content is.
DecodeError
Decoder failures. All but Busy and EndOfStream mean: send a PLI and call reset (the decoder already drops input until a keyframe). In DecodeMode::File there is no PLI to send: go on from the next keyframe.
DecodeMode
How a decoder treats its input and output.
EndReason
Why a source ended.
Facing
Which way a camera faces.
FrameBuffer
A frame’s pixels.
H264Profile
H.264 profiles. Never with B-frames.
ImplPreference
The caller’s preference when creating a codec.
Implementation
Who runs the codec.
Interruption
Why a source paused without ending.
Permission
The state of an OS permission.
PixelFormat
Pixel layouts.
Rotation
How far a pushed frame must turn clockwise to stand upright.
ScreenKind
Display or window.
ScreenSelection
A chosen screen source: from the list, or the OS picker’s opaque handle.
SourceEvent
A source’s events, in order.
ThermalLevel
Thermal pressure.
VideoCodec
A video codec. More variants (VP9, AV1) are added as minor versions.
VideoError
Every error kessel-video returns or reports.

Constants§

EVENT_QUEUE
Event queue depth.

Traits§

FrameSource
A running camera or screen source. Frames come at the source’s pace; the queue is 2 deep, oldest dropped. Drop it to stop.
NativeFrame
An OS-native frame buffer (CVPixelBuffer/IOSurface, an IMFSample or D3D11 texture, an AHardwareBuffer, a DMA-BUF). Opaque to the caller: hand it from a source of a backend to an encoder of the same backend (zero copy), or ask for CPU planes.
VideoBackend
The video side of one app. One per process; shared as Arc<dyn VideoBackend>.
VideoDecoder
A video decoder (one remote track, or one file in DecodeMode::File).
VideoEncoder
A video encoder (one layer). Outputs come in submit order, at most one per input (no reordering, no B-frames); rate control may skip an input.

Functions§

convert
frame scaled to width x height and converted to format (I420, NV12, BGRA or RGBA), as tight planes. The same size and format: a cheap clone.
fit_within
The size that fits width x height inside box_w x box_h keeping the aspect ratio, rounded to even numbers (at least 2).
frame_in
A frame-in source and the sender that feeds it.
nearest_mode
Pick the mode for c: the smallest at or above the wanted size and rate, else the largest. Ties go to the higher rate.
no_wake
A wake that does nothing (for callers that poll on a timer).
null
No cameras, no screens, no codecs: Capabilities::codecs is empty and every open answers Unsupported. For hosts without video and for “video off” builds.
psnr_y
The luma PSNR between two frames of the same size, in dB (100 for identical frames). For tests and quality checks.
system
The OS backend for this target (feature system, or the per-OS feature). Unsupported on a target whose backend isn’t built.
tight_layout
Strides and offsets of tightly packed planes.

Type Aliases§

Done
A one-shot completion (permission prompts, system pickers). Called exactly once, from any thread; dropped uncalled only after VideoBackend::shutdown.
Wake
Called from any thread after something was queued (a frame, an encoded frame, an event). Must be cheap and never block; never call back into kessel-video from it, and never drop the source, encoder or decoder it belongs to there: it can run on that object’s own thread or queue. Send a message to the thread that owns the object instead.