PrismCore / API reference / Probing and input

Protocol

PrismCoreInput

protocol PrismCoreInput : Sendable

Declared in Sources/PrismCore/Probe/PrismCoreInput.swift · PrismCore 3.5.4

Bytes supplied by the host instead of by libavformat's own protocols.

The engine can natively open whatever libavformat can (file:, http:, …), which leaves out every source whose bytes only the host can reach: an SMB share mounted through the host's own client, a debrid or torrent session, an encrypted local store, a file inside a disc image. Those hosts used to have no way in at all; this is it.

Implementations are read-only and position-based. read fills as much of buffer as it can and returns how many bytes it wrote — 0 means end of stream, never "nothing available right now": libavformat treats a zero return as EOF, so an implementation that would otherwise return 0 has to block until it has a byte or throw.

Errors thrown from either method reach FFmpeg as a negative return code and are re-surfaced to the caller as PrismCoreInputError.readFailed / .seekFailed, wrapping the host's own error — a failing transport must come back as a typed failure, not as a session that hangs waiting for a playlist that will never be written.

Sendable because the engine reads on whichever thread owns the context that open produced (a probe thread, the producer thread, the preview actor's). Each open gets its own instance from the factory, so an implementation never has to be safe for concurrent use — only for use from a thread that is not the one that created it.

Instance properties

var length: Int64? { get }

Total byte count, or nil for a stream whose size is unknown.

nil also means not seekable: a size is what the demuxer's index load, the segment plan and every scrub need, and an input that cannot say how long it is cannot answer a seek either. See PrismCoreInputError.notSeekable for what the engine does with one.

Instance methods

func read(into buffer: UnsafeMutableRawBufferPointer) throws -> Int

Fill buffer from the current position, advancing it by the number of bytes written. Returns 0 at end of stream.

func seek(to offset: Int64) throws

Move the read position. offset is always absolute and non-negative, and may legitimately be at or past length (the demuxer probes the tail); the next read from there returns 0.

Generated from the public symbols of PrismCore 3.5.4. All types