Referencia Zigmedia-core: motor de medios

media-core/engine/contract.zig

Declaraciones públicas de media-core/engine/contract.zig (media-core: motor de medios).

ImplementadoSin versión del tren todavía· generada desde apps/docs/generated/zig/media-engine.json

Página generada desde native/zig/media-core/media_engine.zig. No se edita a mano: bun run docs:gen la regenera y bun run docs:check falla si difiere.

MediaEngine — the contract both media engines implement (dec-0110 §1).

engine = zig demux in media-core (ISOBMFF/fMP4, Matroska/WebM) + the fMP4-CMAF fragment muxer of native/zig/transmux. engine = libav FFmpeg 8 as a LIBRARY (libavformat), native/zig/libav-bridge.

The surface is the same for both, so the HLS/CMAF packager (segment plan, playlists, segment cutting) is common code that only varies what differs: demux and fragment mux. Rules every implementation keeps:

  • Bytes come ONLY through ByteSource (the daemon's SeekableMediaSource); an engine never opens paths, URLs or sockets.
  • Errors are EngineError: no engine-specific code (AVERROR) leaks out.
  • Cancellation is per request (CancelToken, r04 / r20 §3.6).
  • Every Packet carries PTS and DTS in its track time base, and DTS is strictly increasing per track (Matroska stores no DTS: the engine synthesizes it). Keyframe indexes are in PTS (dec-0110 §6.7 of the libav spike: libav's MP4 index is DTS; the engine converts).
  • The fragment muxer is built from facts (TrackSpec), not from a demuxer, so one engine's demux can feed the other's mux.

contract.EngineKind

type · línea 32

pub const EngineKind = enum

Sin ///.

contract.EngineKind.parse

fn · línea 36

pub fn parse(s: []const u8) ?EngineKind

Sin ///.

contract.EngineError

const · línea 43

pub const EngineError = error{ UnknownFormat, Malformed, Truncated, TooLarge, /// Valid input the engine does not handle (codec, container feature, /// missing index), or an engine not built in (`-Dli …

Common error set of both engines. The Zig parsers speak bytes.Error; fromParser translates at the engine boundary.

contract.fromParser

fn · línea 60

pub fn fromParser(e: bytes.Error) EngineError

A parser error (bytes.Error: the zkit.safety reader vocabulary plus the container's own) as an EngineError.

contract.Packet

type · línea 77

pub const Packet = struct

One compressed access unit. data is borrowed from the demuxer until the next nextPacket/seek/deinit.

contract.Packet.ptsUs

fn · línea 91

pub fn ptsUs(self: Packet) i64

Sin ///.

contract.Packet.checkTimeline

fn · línea 99

pub fn checkTimeline(self: Packet) EngineError!void

ZC6-P1-01: PTS, DTS and duration inside the engine timeline (timebase.inTimeline). Checked on every packet that crosses the contract, from either engine: the packager's timeline arithmetic never sees a value a hostile container pushed to the i64 limits.

contract.Demuxer

type · línea 105

pub const Demuxer = struct

Sin ///.

contract.Demuxer.VTable

type · línea 109

pub const VTable = struct

Sin ///.

contract.Demuxer.info

fn · línea 131

pub fn info(self: Demuxer) *const facts.ContainerInfo

Sin ///.

contract.Demuxer.select

fn · línea 134

pub fn select(self: Demuxer, streams: []const u32) void

Sin ///.

contract.Demuxer.keyframes

fn · línea 137

pub fn keyframes(self: Demuxer, stream: u32) EngineError![]const facts.Keyframe

Sin ///.

contract.Demuxer.nextPacket

fn · línea 140

pub fn nextPacket(self: Demuxer) EngineError!?Packet

Sin ///.

contract.Demuxer.seek

fn · línea 145

pub fn seek(self: Demuxer, ts_us: i64) EngineError!void

Sin ///.

contract.Demuxer.stats

fn · línea 148

pub fn stats(self: Demuxer) ReadStats

Sin ///.

contract.Demuxer.deinit

fn · línea 151

pub fn deinit(self: Demuxer) void

Sin ///.

contract.TrackSpec

type · línea 159

pub const TrackSpec = struct

A source track to mux, described by its facts. first_packet is the payload of the track's first packet: AC-3/E-AC-3 configuration (dac3, dec3) only exists in the bitstream when the source is Matroska.

contract.OutputTrack

type · línea 172

pub const OutputTrack = struct

Output track as announced to the packager (HLS CODECS, RESOLUTION).

contract.TrackSamples

type · línea 185

pub const TrackSamples = struct

Samples of one output track inside one fragment, in decode order, with DTS already mapped to the canonical output timeline (see DtsMap).

contract.Remuxer

type · línea 192

pub const Remuxer = struct

Sin ///.

contract.Remuxer.VTable

type · línea 196

pub const VTable = struct

Sin ///.

contract.Remuxer.tracks

fn · línea 208

pub fn tracks(self: Remuxer) []const OutputTrack

Sin ///.

contract.Remuxer.initSegment

fn · línea 211

pub fn initSegment(self: Remuxer) []const u8

Sin ///.

contract.Remuxer.writeFragment

fn · línea 214

pub fn writeFragment(self: Remuxer, gpa: std.mem.Allocator, sequence: u32, samples: []const TrackSamples, out: *std.ArrayList(u8)) EngineError!void

Sin ///.

contract.Remuxer.deinit

fn · línea 217

pub fn deinit(self: Remuxer) void

Sin ///.

contract.Capabilities

type · línea 224

pub const Capabilities = struct

Versioned engine capabilities (r23): what each engine declares it handles. Selection consults them; it never assumes.

contract.Capabilities.supportsFormat

fn · línea 230

pub fn supportsFormat(self: Capabilities, f: facts.Format) bool

Sin ///.

contract.Capabilities.supportsCodec

fn · línea 234

pub fn supportsCodec(self: Capabilities, c: facts.Codec) bool

Sin ///.

contract.ProbeOptions

type · línea 239

pub const ProbeOptions = struct

Sin ///.

contract.MediaEngine

type · línea 244

pub const MediaEngine = struct

Sin ///.

contract.MediaEngine.VTable

type · línea 248

pub const VTable = struct

Sin ///.

contract.MediaEngine.kind

fn · línea 258

pub fn kind(self: MediaEngine) EngineKind

Sin ///.

contract.MediaEngine.capabilities

fn · línea 261

pub fn capabilities(self: MediaEngine) Capabilities

Sin ///.

contract.MediaEngine.describe

fn · línea 264

pub fn describe(self: MediaEngine) []const u8

Sin ///.

contract.MediaEngine.probe

fn · línea 267

pub fn probe(self: MediaEngine, gpa: std.mem.Allocator, src: ByteSource, cancel: *const CancelToken, opts: ProbeOptions) EngineError!facts.ContainerInfo

Sin ///.

contract.MediaEngine.openDemuxer

fn · línea 270

pub fn openDemuxer(self: MediaEngine, gpa: std.mem.Allocator, src: ByteSource, cancel: *const CancelToken) EngineError!Demuxer

Sin ///.

contract.MediaEngine.openRemuxer

fn · línea 273

pub fn openRemuxer(self: MediaEngine, gpa: std.mem.Allocator, specs: []const TrackSpec) EngineError!Remuxer

Sin ///.

MediaEngine

type · línea 244

pub const MediaEngine = struct

Sin ///.

MediaEngine.VTable

type · línea 248

pub const VTable = struct

Sin ///.

MediaEngine.kind

fn · línea 258

pub fn kind(self: MediaEngine) EngineKind

Sin ///.

MediaEngine.capabilities

fn · línea 261

pub fn capabilities(self: MediaEngine) Capabilities

Sin ///.

MediaEngine.describe

fn · línea 264

pub fn describe(self: MediaEngine) []const u8

Sin ///.

MediaEngine.probe

fn · línea 267

pub fn probe(self: MediaEngine, gpa: std.mem.Allocator, src: ByteSource, cancel: *const CancelToken, opts: ProbeOptions) EngineError!facts.ContainerInfo

Sin ///.

MediaEngine.openDemuxer

fn · línea 270

pub fn openDemuxer(self: MediaEngine, gpa: std.mem.Allocator, src: ByteSource, cancel: *const CancelToken) EngineError!Demuxer

Sin ///.

MediaEngine.openRemuxer

fn · línea 273

pub fn openRemuxer(self: MediaEngine, gpa: std.mem.Allocator, specs: []const TrackSpec) EngineError!Remuxer

Sin ///.

EngineKind

type · línea 32

pub const EngineKind = enum

Sin ///.

EngineKind.parse

fn · línea 36

pub fn parse(s: []const u8) ?EngineKind

Sin ///.

EngineError

const · línea 43

pub const EngineError = error{ UnknownFormat, Malformed, Truncated, TooLarge, /// Valid input the engine does not handle (codec, container feature, /// missing index), or an engine not built in (`-Dli …

Common error set of both engines. The Zig parsers speak bytes.Error; fromParser translates at the engine boundary.

Packet

type · línea 77

pub const Packet = struct

One compressed access unit. data is borrowed from the demuxer until the next nextPacket/seek/deinit.

Packet.ptsUs

fn · línea 91

pub fn ptsUs(self: Packet) i64

Sin ///.

Packet.checkTimeline

fn · línea 99

pub fn checkTimeline(self: Packet) EngineError!void

ZC6-P1-01: PTS, DTS and duration inside the engine timeline (timebase.inTimeline). Checked on every packet that crosses the contract, from either engine: the packager's timeline arithmetic never sees a value a hostile container pushed to the i64 limits.

Demuxer

type · línea 105

pub const Demuxer = struct

Sin ///.

Demuxer.VTable

type · línea 109

pub const VTable = struct

Sin ///.

Demuxer.info

fn · línea 131

pub fn info(self: Demuxer) *const facts.ContainerInfo

Sin ///.

Demuxer.select

fn · línea 134

pub fn select(self: Demuxer, streams: []const u32) void

Sin ///.

Demuxer.keyframes

fn · línea 137

pub fn keyframes(self: Demuxer, stream: u32) EngineError![]const facts.Keyframe

Sin ///.

Demuxer.nextPacket

fn · línea 140

pub fn nextPacket(self: Demuxer) EngineError!?Packet

Sin ///.

Demuxer.seek

fn · línea 145

pub fn seek(self: Demuxer, ts_us: i64) EngineError!void

Sin ///.

Demuxer.stats

fn · línea 148

pub fn stats(self: Demuxer) ReadStats

Sin ///.

Demuxer.deinit

fn · línea 151

pub fn deinit(self: Demuxer) void

Sin ///.

Remuxer

type · línea 192

pub const Remuxer = struct

Sin ///.

Remuxer.VTable

type · línea 196

pub const VTable = struct

Sin ///.

Remuxer.tracks

fn · línea 208

pub fn tracks(self: Remuxer) []const OutputTrack

Sin ///.

Remuxer.initSegment

fn · línea 211

pub fn initSegment(self: Remuxer) []const u8

Sin ///.

Remuxer.writeFragment

fn · línea 214

pub fn writeFragment(self: Remuxer, gpa: std.mem.Allocator, sequence: u32, samples: []const TrackSamples, out: *std.ArrayList(u8)) EngineError!void

Sin ///.

Remuxer.deinit

fn · línea 217

pub fn deinit(self: Remuxer) void

Sin ///.