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
VideoBackendper app (system,nullorfake::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 aFrameSourcelike any other. - Sources, encoders and decoders work by submit and poll, with a
Wakecallback 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§
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/VideoDecoderwith 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§
- Android
Context - 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.
- Camera
Info - A camera.
- Capabilities
- The whole capability answer of a backend.
- Capture
Constraints - 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. - Capture
Mode - One mode a camera offers.
- Codec
Capability - What one backend can do with one codec in one direction. One entry per (codec, direction, implementation).
- Decoder
Config - One decoder per remote track (or per file, in
DecodeMode::File). - Decoder
Stats - A decoder’s counters.
- Encode
Options - Options for one
submit. - Encoded
Frame - One encoded frame, plaintext.
- Encoded
Input - One complete, decrypted, verified frame from the depacketiser.
- Encoder
Config - One encoder instance, one simulcast layer.
- Encoder
Info - What an encoder actually runs.
- Encoder
Stats - An encoder’s counters.
- Event
Hub - 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::subscribegets every event. - FrameIn
- The source side of
frame_in(): an ordinaryFrameSource. - Frame
InOptions - Settings for
frame_in(). - Frame
InSender - The host’s side of a
frame_in()source. Clone it freely; the source ends when the last clone is dropped. - H264
Capability - H.264 abilities of one codec entry.
- H264
Level - An H.264
level_idc(31 = 3.1, 40 = 4.0). - Layer
Info - Where an encoded frame sits in the temporal and spatial structure.
- Native
Buffer - A shared native buffer.
- Pick
Options - Options for the OS picker.
- Planes
- CPU planes.
dataholds every plane; planeistarts atoffsets[i]with row stridestrides[i]. Unused planes have stride 0 (NV12 uses 2; BGRA and RGBA use 1). - Rates
- A runtime rate change. Never causes a keyframe.
- Screen
Capability - Screen capture support.
- Screen
Source Info - A display or window from
screen_sources. - Source
Stats - A source’s counters since open.
- System
Config - Backend settings.
- Video
Frame - One raw video frame. Always upright: the backend applies the camera’s rotation before handing it out.
Enums§
- Backend
Event - Machine-wide events.
- Codec
Config - Per-codec settings.
- Codec
Direction - Encode or decode.
- Color
Space - Colour description (v1 is BT.601/709 limited range).
- Content
Hint - What the content is.
- Decode
Error - Decoder failures. All but
BusyandEndOfStreammean: send a PLI and callreset(the decoder already drops input until a keyframe). InDecodeMode::Filethere is no PLI to send: go on from the next keyframe. - Decode
Mode - How a decoder treats its input and output.
- EndReason
- Why a source ended.
- Facing
- Which way a camera faces.
- Frame
Buffer - A frame’s pixels.
- H264
Profile - H.264 profiles. Never with B-frames.
- Impl
Preference - 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.
- Pixel
Format - Pixel layouts.
- Rotation
- How far a pushed frame must turn clockwise to stand upright.
- Screen
Kind - Display or window.
- Screen
Selection - A chosen screen source: from the list, or the OS picker’s opaque handle.
- Source
Event - A source’s events, in order.
- Thermal
Level - Thermal pressure.
- Video
Codec - A video codec. More variants (VP9, AV1) are added as minor versions.
- Video
Error - Every error kessel-video returns or reports.
Constants§
- EVENT_
QUEUE - Event queue depth.
Traits§
- Frame
Source - A running camera or screen source. Frames come at the source’s pace; the queue is 2 deep, oldest dropped. Drop it to stop.
- Native
Frame - 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.
- Video
Backend - The video side of one app. One per process; shared as
Arc<dyn VideoBackend>. - Video
Decoder - A video decoder (one remote track, or one file in
DecodeMode::File). - Video
Encoder - 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
framescaled towidthxheightand converted toformat(I420, NV12, BGRA or RGBA), as tight planes. The same size and format: a cheap clone.- fit_
within - The size that fits
widthxheightinsidebox_wxbox_hkeeping 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::codecsis empty and every open answersUnsupported. 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).Unsupportedon 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.