Referencia Zigtransmux

transmux/packager.zig

Declaraciones públicas de transmux/packager.zig (transmux).

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

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

HLS/CMAF packager common to both engines (dec-0110 §1): a Session owns one engine's demuxer and fragment muxer for one asset and produces, on demand and in any order, the init segment, media segment N and the playlists. What a segment holds is decided here, identically for both engines:

  • Segment N = the reference (video) track's packets in decode order from the keyframe at plan[N].start_us up to (excluding) the keyframe at plan[N].end_us; every other track's packets with PTS in [start, end) (segment 0 also takes anything before its start: codec priming, Opus pre-skip).
  • Output timeline (DtsMap): PTS' = PTS - origin and DTS' = DTS + (PTS0 - DTS0) - origin per track, where PTS0/DTS0 are the track's first packet in the file and origin = min(0, earliest first PTS). The first sample of every track decodes at its presentation time, nothing is negative (tfdt is unsigned), A/V offsets are kept, and every engine maps a packet to the same output tick whatever DTS convention its demuxer uses (libav shifts DTS by the edit list; Matroska has none).

Thread safety: one segment at a time per session; any thread may call in, a second caller waits (and stops waiting when its request is cancelled). Segments are produced into the caller's buffer; between requests a session holds no media bytes.

packager.Options

type · línea 35

pub const Options = struct

Sin ///.

packager.Options.maxSegmentBytes

fn · línea 79

pub fn maxSegmentBytes(self: Options) u64

Largest media segment Session.segment hands out: the payload budget plus room for the fragment's boxes (moof: ~16 B of trun per sample with either muxer, doubled). Past it, TooLarge: the HTTP/3 pump reserves this much of its send budget per segment being produced, so the bound is enforced, not estimated.

packager.Options.segmentCap

fn · línea 84

pub fn segmentCap(self: Options, file_size: u64) usize

The most segments a plan for a file of file_size bytes may have.

packager.Options.maxPlaylistBytes

fn · línea 91

pub fn maxPlaylistBytes(self: Options) u64

Bound of the media playlist of any session opened with these options (enforced at open).

packager.Options.maxAssetBytes

fn · línea 98

pub fn maxAssetBytes(self: Options) u64

Bound of any asset of a session besides its media segments (the playlists and the init segment): what the HTTP/3 pump reserves of its send budget for one (PackagingLimits.max_asset_bytes).

packager.playlist_header_max

const · línea 105

pub const playlist_header_max: u64 = 512

Media playlist bytes besides its segment lines (writeMediaPlaylist: ~170 B of tags, a target duration of at most 13 digits).

packager.playlist_line_max

const · línea 109

pub const playlist_line_max: u64 = 40

One segment's #EXTINF:<s>.<us>,\nseg-<n>.m4s\n: a duration within plan.max_span_us (7 digits of seconds) and an index below plan.max_segments (7 digits) take 40 B.

packager.master_playlist_max

const · línea 111

pub const master_playlist_max: u64 = 1024

Master playlist (writeMasterPlaylist): one variant, two codec strings.

packager.PayloadStore

type · línea 142

pub const PayloadStore = struct

Payload bytes one request collected, in chunks that never move (no growth by reallocation) and are trimmed to what they hold when sealed. Memory is the bytes pulled from the demuxer, not a growth-rounded capacity: in safety-checked builds (the daemon runs parsers in ReleaseSafe) the allocator writes undefined over a whole allocation when it is made and when it is freed, so any unused capacity is resident memory too.

packager.PayloadStore.chunk_size

const · línea 148

pub const chunk_size = 1 << 20

Sin ///.

packager.PayloadStore.put

fn · línea 151

pub fn put(self: *PayloadStore, gpa: std.mem.Allocator, data: []const u8) error{OutOfMemory}![]const u8

Copies data in and returns the stable copy.

packager.PayloadStore.reset

fn · línea 177

pub fn reset(self: *PayloadStore, gpa: std.mem.Allocator) void

Sin ///.

packager.PayloadStore.allocated

fn · línea 185

pub fn allocated(self: *const PayloadStore) u64

Bytes allocated (resident in safety-checked builds).

packager.Stats

type · línea 210

pub const Stats = struct

Sin ///.

packager.Session

type · línea 217

pub const Session = struct

Sin ///.

packager.Session.open

fn · línea 244

pub fn open(gpa: std.mem.Allocator, engine: contract.MediaEngine, src: contract.ByteSource, cancel: *contract.CancelToken, opts: Options) EngineError!*Session

Opens src with engine: header pass, track choice, first packet of each track (timeline + AC-3 configuration), keyframe index, plan and fragment muxer. cancel must outlive the session.

packager.Session.deinit

fn · línea 357

pub fn deinit(self: *Session) void

Sin ///.

packager.Session.pick

fn · línea 378

pub fn pick(info: *const facts.ContainerInfo, kind: facts.Kind, want: ?u32) ?u32

The stream of kind to package: want when it names one of that kind, else the first known one. A want that names nothing packable is null (the caller refuses the session: an explicit choice is never replaced).

packager.Session.segmentCount

fn · línea 412

pub fn segmentCount(self: *const Session) usize

Sin ///.

packager.Session.initSegment

fn · línea 417

pub fn initSegment(self: *Session) []const u8

ftyp + moov, owned by the session.

packager.Session.outputTracks

fn · línea 421

pub fn outputTracks(self: *Session) []const contract.OutputTrack

Sin ///.

packager.Session.segment

fn · línea 428

pub fn segment(self: *Session, index: usize, gpa: std.mem.Allocator, out: *std.ArrayList(u8), request: ?*const contract.CancelToken) EngineError!void

Appends media segment index (one CMAF fragment) to out, grown with gpa (the caller's buffer, the caller's allocator). request (optional) cancels just this segment.

packager.Session.segmentName

fn · línea 552

pub fn segmentName(buf: []u8, index: usize) []const u8

Sin ///.

packager.Session.mediaPlaylist

fn · línea 558

pub fn mediaPlaylist(self: *const Session) []const u8

VOD media playlist (fMP4 segments, EXT-X-MAP = init.mp4), owned by the session; at most Options.maxPlaylistBytes.

packager.Session.masterPlaylist

fn · línea 564

pub fn masterPlaylist(self: *const Session) []const u8

Master playlist with one variant (CODECS from the facts), owned by the session; at most master_playlist_max.

packager.writeMediaPlaylist

fn · línea 569

pub fn writeMediaPlaylist(w: *std.Io.Writer, plan: plan_mod.Plan) std.Io.Writer.Error!void

Sin ///.

packager.writeMasterPlaylist

fn · línea 579

pub fn writeMasterPlaylist(w: *std.Io.Writer, tracks: []const contract.OutputTrack, avg_bps: u64) std.Io.Writer.Error!void

Sin ///.

Session

type · línea 217

pub const Session = struct

Sin ///.

Session.open

fn · línea 244

pub fn open(gpa: std.mem.Allocator, engine: contract.MediaEngine, src: contract.ByteSource, cancel: *contract.CancelToken, opts: Options) EngineError!*Session

Opens src with engine: header pass, track choice, first packet of each track (timeline + AC-3 configuration), keyframe index, plan and fragment muxer. cancel must outlive the session.

Session.deinit

fn · línea 357

pub fn deinit(self: *Session) void

Sin ///.

Session.pick

fn · línea 378

pub fn pick(info: *const facts.ContainerInfo, kind: facts.Kind, want: ?u32) ?u32

The stream of kind to package: want when it names one of that kind, else the first known one. A want that names nothing packable is null (the caller refuses the session: an explicit choice is never replaced).

Session.segmentCount

fn · línea 412

pub fn segmentCount(self: *const Session) usize

Sin ///.

Session.initSegment

fn · línea 417

pub fn initSegment(self: *Session) []const u8

ftyp + moov, owned by the session.

Session.outputTracks

fn · línea 421

pub fn outputTracks(self: *Session) []const contract.OutputTrack

Sin ///.

Session.segment

fn · línea 428

pub fn segment(self: *Session, index: usize, gpa: std.mem.Allocator, out: *std.ArrayList(u8), request: ?*const contract.CancelToken) EngineError!void

Appends media segment index (one CMAF fragment) to out, grown with gpa (the caller's buffer, the caller's allocator). request (optional) cancels just this segment.

Session.segmentName

fn · línea 552

pub fn segmentName(buf: []u8, index: usize) []const u8

Sin ///.

Session.mediaPlaylist

fn · línea 558

pub fn mediaPlaylist(self: *const Session) []const u8

VOD media playlist (fMP4 segments, EXT-X-MAP = init.mp4), owned by the session; at most Options.maxPlaylistBytes.

Session.masterPlaylist

fn · línea 564

pub fn masterPlaylist(self: *const Session) []const u8

Master playlist with one variant (CODECS from the facts), owned by the session; at most master_playlist_max.