moonmedia Reel 04 · The catalogue

Reel 04 · The catalogue

Reference

Every public type, method, function and value, grouped by package. The signatures are the ones the compiler sees; the prose is the comment the source carries.

m3u8 HLS playlists

Master and media playlists: every tag of RFC 8216, and the low-latency additions of RFC 8216bis.

struct pub(all) struct ByteRange

A byte range inside a resource (RFC 8216 §4.3.2.2).

offset absent means "immediately after the previous range", which is what the tag itself means when the @ clause is left out. Keeping the two apart matters: a reader that filled in zero would fetch the wrong bytes.

  • mut lengthInt64
  • mut offsetInt64?
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn ByteRange::new(length : Int64, offset? : Int64) -> ByteRange

One range, length@offset.

enum pub(all) enum Cipher

The encryption method EXT-X-KEY names (RFC 8216 §4.3.2.4).

Other carries a method this release does not implement, so a playlist that uses one is read and written back unchanged rather than refused.

  • None
  • Aes128
  • SampleAes
  • Other(String)
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Cipher::code(self : Cipher) -> String

The method as it appears on the wire.

pub fn Cipher::of(code : StringView) -> Cipher

The method a wire value names; Other for one this release does not know.

struct pub(all) struct DateRange

A wall-clock interval the stream marks, EXT-X-DATERANGE (RFC 8216 §4.3.2.7).

  • mut idString
  • mut class_String?
  • mut start_dateString?
  • mut end_dateString?
  • mut durationDouble?
  • mut planned_durationDouble?
  • mut scte35_cmdString?
  • mut scte35_outString?
  • mut scte35_inString?
  • mut end_on_nextBool
  • mut extraArray[String]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn DateRange::new(id : String, start_date? : String) -> DateRange

The interval named id.

struct pub(all) struct Define

A variable the playlist defines, EXT-X-DEFINE (RFC 8216bis §4.4.2.3).

  • mut nameString?
  • mut valueString?
  • mut import_String?
  • mut queryparamString?
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Define::new(name : String, value : String) -> Define

A variable set to value.

struct pub(all) struct IFrameStream

An I-frame only rendition, EXT-X-I-FRAME-STREAM-INF (RFC 8216 §4.3.4.3).

  • mut uriString
  • mut bandwidthInt32?
  • mut average_bandwidthInt32?
  • mut codecsString?
  • mut resolutionResolution?
  • mut hdcp_levelString?
  • mut video_rangeString?
  • mut pathway_idString?
  • mut stable_variant_idString?
  • mut extraArray[String]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn IFrameStream::new(uri : String, bandwidth? : Int32) -> IFrameStream

I-frame streams served from uri.

struct pub(all) struct InitSection

The initialisation section a segment needs before it can be decoded, the EXT-X-MAP tag (RFC 8216 §4.3.2.5).

  • mut uriString
  • mut byte_rangeByteRange?
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn InitSection::new(uri : String, byte_range? : ByteRange) -> InitSection

An initialisation section served from uri.

struct pub(all) struct Key

A key a segment is encrypted with (RFC 8216 §4.3.2.4).

Segments carry the key that was in force when they were written, not the tag that introduced it: a tag applies to every following segment until it is replaced, and a caller hunting for "what encrypts this segment" should not have to replay the file to find out.

  • mut cipherCipher
  • mut uriString?
  • mut ivString?
  • mut key_formatString?
  • mut key_format_versionsString?
  • mut extraArray[String]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Key::is_plain(self : Key) -> Bool

Whether the key leaves the stream in the clear.

pub fn Key::new(uri : String, cipher? : Cipher, iv? : String, key_format? : String, key_format_versions? : String) -> Key

A key, with the URI that serves it.

struct pub(all) struct Master

A master playlist: which renditions exist and how to reach them (RFC 8216 §4.3.4).

  • mut versionInt32?
  • mut independent_segmentsBool
  • mut startStart?
  • mut definesArray[Define]
  • mut session_dataArray[SessionData]
  • mut session_keysArray[Key]
  • mut renditionsArray[Rendition]
  • mut variantsArray[Variant]
  • mut i_frame_streamsArray[IFrameStream]
  • mut unknownArray[String]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Master::encode(self : Master) -> String
pub fn Master::new() -> Master

An empty master playlist.

enum pub(all) enum MediaKind

What an EXT-X-MEDIA rendition carries (RFC 8216 §4.3.4.1).

  • Audio
  • Video
  • Subtitles
  • ClosedCaptions
  • Other(String)
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn MediaKind::code(self : MediaKind) -> String

The kind as it appears on the wire.

pub fn MediaKind::of(code : StringView) -> MediaKind

The kind a wire value names.

struct pub(all) struct MediaPlaylist

A media playlist: the segments of one rendition (RFC 8216 §4.3.3).

  • mut versionInt32?
  • mut target_durationInt32
  • mut media_sequenceInt64
  • mut discontinuity_sequenceInt64
  • mut playlist_typePlaylistType?
  • mut i_frames_onlyBool
  • mut independent_segmentsBool
  • mut allow_cacheBool?
  • mut end_listBool
  • mut startStart?
  • mut server_controlServerControl?
  • mut part_infDouble?
  • mut skipInt32?
  • mut definesArray[Define]
  • mut date_rangesArray[DateRange]
  • mut segmentsArray[Segment]
  • mut next_partsArray[Part]
  • mut preload_hintPreloadHint?
  • mut rendition_reportsArray[RenditionReport]
  • mut unknownArray[String]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn MediaPlaylist::encode(self : MediaPlaylist) -> String
pub fn MediaPlaylist::new(target_duration : Int32) -> MediaPlaylist

An empty media playlist whose segments are at most target_duration seconds long, which the specification requires to be present.

struct pub(all) struct Part

A partial segment, the unit low-latency HLS publishes before a segment is complete (RFC 8216bis §4.4.4.9).

  • mut uriString
  • mut durationDouble
  • mut independentBool
  • mut byte_rangeByteRange?
  • mut gapBool
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Part::new(uri : String, duration : Double, independent? : Bool, byte_range? : ByteRange, gap? : Bool) -> Part

A part of the segment at uri lasting duration seconds.

enum pub(all) enum Playlist

A playlist, of one kind or the other.

  • MasterPlaylist(Master)
  • MediaPlaylist(MediaPlaylist)
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Playlist::encode(self : Playlist) -> String

Write a playlist back out.

Tags are written in the order the specification lists them rather than the order they were read, except inside a segment, where the order the file had is the order players expect to see: the key and the map apply to the segment that follows, so they come first, and #EXTINF immediately precedes its URI.

pub fn Playlist::is_master(self : Playlist) -> Bool

Whether this is a master playlist.

pub fn Playlist::master(self : Playlist) -> Master?

The master playlist, when this is one.

pub fn Playlist::media(self : Playlist) -> MediaPlaylist?

The media playlist, when this is one.

pub fn Playlist::parse(text : StringView) -> Playlist raise PlaylistError

Read a playlist.

A master playlist and a media playlist are told apart by what the file contains, not by a declaration: the presence of a variant stream or a rendition makes it a master. Anything the release does not model is kept in unknown and written back, so a playlist using a tag from a later revision survives a round trip.

error pub(all) suberror PlaylistError

Why a playlist could not be read.

at is the line the parser stopped on, counting from one; got is what was there and want what the grammar allows.

  • Malformed(at~ : Int32, want~ : String, got~ : String)
output

Written by #derive or the trait written for the type.

pub fn PlaylistError::to_string(Self) -> String

The message, as the error prints it.

enum pub(all) enum PlaylistType

What kind of playlist a media playlist is (RFC 8216 §4.3.3.5).

  • Event
  • Vod
  • Other(String)
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

struct pub(all) struct PreloadHint

What to fetch next before it is listed, EXT-X-PRELOAD-HINT (RFC 8216bis §4.4.4.10).

  • mut kindString
  • mut uriString
  • mut byte_rangeByteRange?
  • mut startInt64?
  • mut extraArray[String]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn PreloadHint::new(kind : String, uri : String, byte_range? : ByteRange, start? : Int64) -> PreloadHint

A hint that uri will hold the next kind (PART or MAP).

struct pub(all) struct Rendition

An alternative rendition a variant can switch to (RFC 8216 §4.3.4.1).

  • mut kindMediaKind
  • mut group_idString
  • mut nameString
  • mut uriString?
  • mut languageString?
  • mut assoc_languageString?
  • mut characteristicsString?
  • mut channelsString?
  • mut instream_idString?
  • mut stable_rendition_idString?
  • mut pathway_idString?
  • mut defaultBool
  • mut autoselectBool
  • mut forcedBool
  • mut extraArray[String]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Rendition::new(kind : MediaKind, group_id : String, name : String, uri? : String) -> Rendition

A rendition called name in the group group_id.

struct pub(all) struct RenditionReport

How far along a sibling rendition is, EXT-X-RENDITION-REPORT (RFC 8216bis §4.4.4.11).

  • mut uriString
  • mut last_msnInt64?
  • mut last_partInt32?
  • mut extraArray[String]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn RenditionReport::new(uri : String, last_msn? : Int64, last_part? : Int32) -> RenditionReport

A report on the rendition at uri.

struct pub(all) struct Resolution

A frame size, 1920x1080.

  • mut widthInt32
  • mut heightInt32
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Resolution::new(width : Int32, height : Int32) -> Resolution

A video size in pixels.

struct pub(all) struct Segment

One media segment: the URI a player fetches and everything the playlist says about it.

  • mut uriString
  • mut durationDouble
  • mut titleString?
  • mut byte_rangeByteRange?
  • mut discontinuityBool
  • mut program_date_timeString?
  • mut gapBool
  • mut keyKey?
  • mut mapInitSection?
  • mut partsArray[Part]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Segment::new(uri : String, duration : Double, title? : String) -> Segment

A segment at uri lasting duration seconds.

struct pub(all) struct ServerControl

The reload advice a low-latency server gives, EXT-X-SERVER-CONTROL (RFC 8216bis §4.4.3.8).

  • mut can_skip_untilDouble?
  • mut can_skip_date_rangesBool
  • mut hold_backDouble?
  • mut part_hold_backDouble?
  • mut can_block_reloadBool
  • mut extraArray[String]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn ServerControl::new() -> ServerControl

The reload advice with nothing set.

struct pub(all) struct SessionData

A piece of session metadata, EXT-X-SESSION-DATA (RFC 8216 §4.3.4.4).

  • mut data_idString
  • mut valueString?
  • mut uriString?
  • mut languageString?
  • mut extraArray[String]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn SessionData::new(data_id : String, value? : String, uri? : String, language? : String) -> SessionData

The metadata named data_id, carried inline as value or by uri.

struct pub(all) struct Start

Where playback should start, EXT-X-START (RFC 8216 §4.3.5.2).

  • mut time_offsetDouble
  • mut preciseBool
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Start::new(time_offset : Double, precise? : Bool) -> Start

Start time_offset seconds from the beginning.

struct pub(all) struct Variant

One rendition of a master playlist, the body of EXT-X-STREAM-INF (RFC 8216 §4.3.4.2).

  • mut uriString
  • mut bandwidthInt32?
  • mut average_bandwidthInt32?
  • mut codecsString?
  • mut resolutionResolution?
  • mut frame_rateDouble?
  • mut hdcp_levelString?
  • mut audioString?
  • mut videoString?
  • mut subtitlesString?
  • mut closed_captionsString?
  • mut video_rangeString?
  • mut pathway_idString?
  • mut stable_variant_idString?
  • mut extraArray[String]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Variant::new(uri : String, bandwidth? : Int32, codecs? : String) -> Variant

A variant streaming uri, using bandwidth bits per second.

mp4 ISO base media

Files and fragments: the box tree, the sample tables, and a file written back byte for byte.

struct pub(all) struct Box

One box: a type, a size and its content.

large remembers that the size was written as a 64-bit field rather than the usual 32-bit one, because writing it back the other way would change the file even though it would still be readable.

  • type_String
  • usertypeBytes?
  • largeBool
  • contentContent
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Box::boxes(self : Box) -> Array[Box]

The child boxes, or an empty array for a box that holds bytes.

pub fn Box::byte_length(self : Box) -> Int32

How many bytes this box occupies, header included.

pub fn Box::bytes(type_ : StringView, raw : Bytes) -> Box

A box of type_ holding bytes.

pub fn Box::child(self : Box, type_ : StringView) -> Box?

The first child of this box with the given type.

pub fn Box::children(type_ : StringView, boxes : Array[Box]) -> Box

A box of type_ holding smaller boxes.

pub fn Box::children_of(self : Box, type_ : StringView) -> Array[Box]

Every child of this box with the given type, in order.

pub fn Box::encode(self : Box) -> Bytes

Write one box.

pub fn Box::fourcc(self : Box) -> StringView

The four character code as a view.

pub fn Box::is_type(self : Box, type_ : StringView) -> Bool

Whether this box is of the given type.

pub fn Box::raw(self : Box) -> Bytes

The bytes this box holds itself, without its children.

enum pub(all) enum Content

What a box holds.

A box either contains smaller boxes or a run of bytes. The boxes that hold both — a sample description entry is a fixed header followed by child boxes — keep the fixed part in prefix and the children after it, so the tree stays generic without losing a byte.

  • Children(prefix~ : Bytes, boxes~ : Array[Box])
  • Bytes(raw~ : Bytes)
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

struct pub(all) struct FileType

The brands a file declares in ftyp.

  • majorString
  • minorInt32
  • compatibleArray[String]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn FileType::encode(self : FileType) -> Bytes

Write a file type box.

pub fn FileType::of(raw : Bytes) -> FileType raise Mp4Error

Read a file type box.

struct pub(all) struct Fragment

One movie fragment: the moof that describes it and the media data that follows, up to the next fragment.

  • sequenceInt32
  • startInt32 Offset of the moof in the file.
  • endInt32 Offset just past the fragment's last byte.
  • runsArray[Run]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

struct pub(all) struct FragmentTrack

One track's contribution to a fragment.

  • track_idInt32
  • base_decode_timeInt64
  • samplesArray[SampleData]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

struct pub(all) struct IndexReference

One piece of a segment index: how big the next piece is and how long it plays, or a pointer to another index.

  • reference_typeBool Whether this points at another index rather than at media.
  • referenced_sizeInt64 How many bytes the piece takes, or how large the index it points at is.
  • subsegment_durationInt64
  • starts_with_sapBool
  • sap_typeInt32
  • sap_delta_timeInt64
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

struct pub(all) struct MovieFragment

A movie fragment ready to be written: moof and the mdat it points at.

  • sequenceInt32
  • tracksArray[FragmentTrack]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn MovieFragment::duration(self : MovieFragment, timescale : Int64) -> Double

How long the fragment plays, in the timescale of its longest track.

pub fn MovieFragment::encode(self : MovieFragment) -> Bytes

The fragment as bytes: the moof and then the mdat, which is the order a player needs them in when both arrive in one request.

pub fn MovieFragment::new(sequence : Int32, tracks : Array[FragmentTrack]) -> MovieFragment

A fragment of tracks carrying fragment number sequence.

pub fn MovieFragment::sample_bytes(self : MovieFragment) -> Bytes

The sample bytes of every track, in track order, which is the order the data offsets describe.

struct pub(all) struct MovieHeader

A track's timescale: how many units make a second.

  • timescaleInt64
  • durationInt64
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

struct pub(all) struct Mp4

A file and the boxes it was read into.

The bytes are kept because sample data is described by offsets into them: a sample is a view, not a copy, so a track of a hundred thousand frames costs nothing to list.

  • dataBytes
  • boxesArray[Box]
pub fn Mp4::box(self : Mp4, type_ : StringView) -> Box?

The first box of a type at the top level.

pub fn Mp4::encode(self : Mp4) -> Bytes

Write the file back. A file read and written again is the same bytes.

pub fn Mp4::file_type(self : Mp4) -> FileType? raise Mp4Error

The brand a file declares, ftyp.

pub fn Mp4::fragments(self : Mp4) -> Array[Fragment] raise Mp4Error

The fragments of a fragmented file, in order.

A fragment runs from its moof to the next one, so a segment cut on a fragment boundary is a run of whole boxes.

pub fn Mp4::init_section(self : Mp4) -> Bytes raise Mp4Error

The boxes a player needs before the first fragment: a file type, and a movie header whose sample tables are empty and whose mvex describes what is to come.

The durations in the header are set to zero, because a live stream does not know how long it is; a fragment says when it starts, and that is what a player uses.

pub fn Mp4::is_fragmented(self : Mp4) -> Bool

Whether the file describes its media in fragments rather than in a sample table, which is what a stream cut into segments looks like.

pub fn Mp4::movie(self : Mp4) -> Box?

The movie header, moov.

pub fn Mp4::parse(data : BytesView) -> Mp4 raise Mp4Error

Read a file.

pub fn Mp4::tracks(self : Mp4) -> Array[Track] raise Mp4Error

The samples of every track, in the order the tracks appear.

error pub(all) suberror Mp4Error

Why a file could not be read.

at is the offset in the file the reader had reached, want what the format requires there and got what was actually there.

  • Malformed(at~ : Int32, want~ : String, got~ : String)
output

Written by #derive or the trait written for the type.

pub fn Mp4Error::to_string(Self) -> String

The message, as the error prints it.

struct pub(all) struct Run

The samples one track contributes to a fragment.

  • track_idInt32
  • base_decode_timeInt64
  • samplesArray[Sample]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

struct pub(all) struct Sample

One sample: where its bytes are, when it plays, and whether a player may start here.

  • offsetInt32 Offset into the file.
  • sizeInt32
  • dtsInt64 Decode time, in the track's timescale.
  • durationInt64
  • composition_offsetInt64 How far presentation time runs ahead of decode time, for reordered video.
  • syncBool
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Sample::pts(self : Sample) -> Int64

When the sample is shown, in the track's timescale.

pub fn Sample::seconds(self : Sample, timescale : Int64) -> Double

How long the sample is in seconds.

struct pub(all) struct SampleData

A sample as it is written into a fragment: its bytes and what the fragment has to say about it.

  • dataBytes
  • durationInt64
  • composition_offsetInt64
  • syncBool
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

struct pub(all) struct SegmentIndex

A segment index, sidx (ISO/IEC 14496-12 §8.16.3).

It says where the pieces of a fragmented stream are, in a form a player can read without downloading them, which is how a DASH client knows what to fetch next.

  • reference_idInt32
  • timescaleInt64
  • earliest_presentation_timeInt64
  • first_offsetInt64
  • referencesArray[IndexReference]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn SegmentIndex::encode(self : SegmentIndex) -> Bytes

Write a segment index back as a sidx box.

The version is chosen from the values: a presentation time or an offset past what 32 bits hold needs the wide form, and a reader that assumed the narrow one would run into the next field.

struct pub(all) struct Track

A track and the samples it holds, read from the sample table or from the fragments.

  • idInt32
  • kindTrackKind
  • timescaleInt64
  • durationInt64
  • languageString
  • codecString The codec as a player names it: avc1.64001f, mp4a.40.2, hvc1.
  • widthInt32
  • heightInt32
  • sample_rateInt32
  • channelsInt32
  • edit_timeInt64 The media time at which presentation starts, from the track's edit list. A codec that primes its decoder keeps the priming samples in the file and asks the player to start the presentation later; that is an edit list, and a track without one starts where its media starts. Subtract it from a sample's decode time to get the time the sample is played at relative to the start of the presentation.
  • samplesArray[Sample]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

enum pub(all) enum TrackKind

What a track carries, from the handler hdlr names.

  • Video
  • Audio
  • Subtitle
  • Hint
  • Other(String)
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

functions
function pub fn encode(boxes : Array[Box]) -> Bytes

Write boxes back out.

function pub fn ftyp(major : StringView, compatible : Array[String]) -> Box

A file type box.

function pub fn mdat(data : Bytes) -> Box

A media data box holding data.

function pub fn mfhd(sequence : Int32) -> Box

A fragment header: the fragment's number.

function pub fn movie_header(moov : Box) -> MovieHeader raise Mp4Error

Read a mvhd.

function pub fn parse(data : BytesView) -> Array[Box] raise Mp4Error

Read the boxes at the start of data.

Reading stops at the first byte that is not a box; a file whose last box was cut short is refused rather than half-read.

function pub fn segment_index(box : Box) -> SegmentIndex raise Mp4Error

Read a sidx box.

function pub fn tfdt(base_decode_time : Int64) -> Box

The decode time the fragment starts at, so a player can place it without having seen the ones before it.

function pub fn tfhd(track_id : Int32) -> Box

A track fragment header that says where this track's data is: in this fragment, which is what default-base-is-moof means.

function pub fn trun(samples : Array[SampleData], data_offset : Int32) -> Box

A track run: every sample, with its duration, size, flags and composition offset written out rather than defaulted, so the fragment needs nothing from the header to be read.

ts MPEG-TS

Packets, the programme tables, PES, and the clock that times them.

struct pub(all) struct Adaptation

The adaptation field: the extra room a packet uses when its payload is shorter than 184 bytes, and where the programme clock reference travels.

The field is kept as the bytes it was, because half of it is flags for features that are rare enough to be worth not modelling; the accessors read the parts that matter and a caller that needs more reads raw.

  • rawBytes The field after its length byte, stuffing included.
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Adaptation::discontinuity(self : Adaptation) -> Bool

Whether the stream is discontinuous at this packet.

pub fn Adaptation::length(self : Adaptation) -> Int32

The field's length in bytes, the length byte not counted.

pub fn Adaptation::new(stuffing? : Int32) -> Adaptation

An adaptation field with nothing set, long enough to hold stuffing bytes.

pub fn Adaptation::pcr(self : Adaptation) -> Int64?

The programme clock reference, in units of 1/27000000 second, when the packet carries one.

The format stores 33 bits of a 90 kHz clock and nine bits of extension, which together count a 27 MHz clock: dividing by 27_000_000 gives seconds, and dividing by 300 gives the 90 kHz count that timestamps use.

pub fn Adaptation::random_access(self : Adaptation) -> Bool

Whether a decoder may start here.

pub fn Adaptation::stuffing(self : Adaptation) -> Int32

How many bytes of the field are stuffing.

pub fn Adaptation::with_pcr(pcr : Int64, stuffing? : Int32) -> Adaptation

An adaptation field carrying a programme clock reference.

The clock is 33 bits of 90 kHz plus a 9 bit extension, so that a decoder can line up several streams to a fraction of a frame.

struct pub(all) struct Packet

One transport stream packet: a fixed 188 bytes, of which four or more are header, and the rest either adaptation field or payload.

  • errorBool The packet had an error crossing the network.
  • starts_unitBool A new unit of the stream starts in this packet's payload.
  • priorityBool
  • pidInt32
  • scramblingInt32
  • counterInt32
  • adaptationAdaptation?
  • payloadBytes The payload as it sits in the packet, which for a partial packet is a piece of a unit and not the unit itself.
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Packet::encode(self : Packet) -> Bytes

Write the packet back as 188 bytes.

pub fn Packet::is_null(self : Packet) -> Bool

Whether this packet carries nothing.

pub fn Packet::is_pat(self : Packet) -> Bool

Whether this packet carries the programme association table.

pub fn Packet::new(pid : Int32, payload : Bytes, counter? : Int32, starts_unit? : Bool) -> Packet

A packet of pid carrying payload, with no adaptation field.

pub fn Packet::parse(data : BytesView) -> Packet raise TsError

Read the packet at the start of data.

pub fn Packet::parse_at(data : BytesView, at : Int32, origin : Int32) -> Packet raise TsError

Read the packet at at, with origin the offset of data in the stream so that an error names a place the caller can find.

struct pub(all) struct Pat

The programme association table: which programme is on which identifier.

  • transport_streamInt32
  • versionInt32
  • programsArray[Program]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Pat::encode(self : Pat) -> Bytes

Write a programme association table.

pub fn Pat::new(transport_stream? : Int32, version? : Int32, programs? : Array[Program]) -> Pat

A table of programs for the stream transport_stream.

pub fn Pat::of(section : Section) -> Pat raise TsError

Read a programme association table.

pub fn Pat::section(self : Pat) -> Section

The section a programme association table is written as.

struct pub(all) struct Pes

A packetised elementary stream packet: the frame, or the piece of a frame, that a stream carries (ISO/IEC 13818-1 §2.4.3.7).

The optional header is kept as bytes. It carries the timestamps a player needs and a dozen flags about how the frame may be decoded, which it does not; keeping the bytes means a packet read and written again is the same packet, and a caller that wants a timestamp reads it with pts.

  • stream_idInt32
  • packet_lengthInt32 The length the packet declares, header included. Zero means "until the next packet begins", which is what a video frame larger than a packet uses.
  • flagsInt32 The bits of the first flags byte: scrambling, priority, alignment.
  • timestamp_flagsInt32 The bits of the second flags byte: which timestamps are present.
  • headerBytes The optional fields, verbatim: timestamps and the rarer flags.
  • dataBytes
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Pes::dts(self : Pes) -> Int64?

The decode time of the packet, when it differs from the presentation time.

pub fn Pes::encode(self : Pes) -> Bytes

Write the packet back.

pub fn Pes::new(stream_id : Int32, data : Bytes, pts? : Int64, dts? : Int64) -> Pes

A packet carrying data on stream_id, timed by pts and, when frames are reordered, dts.

A timestamp is in units of 1/90000 second and is written as 33 bits, which wraps after about 26 hours: a stream that runs longer counts in circles, which is why players compare timestamps rather than sort by them.

pub fn Pes::parse(data : BytesView, at? : Int32) -> Pes raise TsError

Read the packet that starts at at.

pub fn Pes::pts(self : Pes) -> Int64?

The presentation time of the packet, in units of 1/90000 second.

struct pub(all) struct Pmt

The programme map table: what a programme is made of, and which packet carries its clock.

  • programInt32
  • pcr_pidInt32
  • versionInt32
  • descriptorsBytes
  • streamsArray[Stream]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Pmt::encode(self : Pmt) -> Bytes

Write a programme map table.

pub fn Pmt::new(program? : Int32, pcr_pid? : Int32, version? : Int32, descriptors? : Bytes, streams? : Array[Stream]) -> Pmt

A table of streams for programme program, timed by pcr_pid.

pub fn Pmt::of(section : Section) -> Pmt raise TsError

Read a programme map table.

pub fn Pmt::section(self : Pmt) -> Section

The section a programme map table is written as.

struct pub(all) struct Program

One entry of a programme association table.

  • numberInt32
  • pidInt32 The identifier of the packet that carries this programme's map table, or the network information table when number is zero.
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Program::new(number : Int32, pid : Int32) -> Program

A programme of number whose map table is on pid.

struct pub(all) struct Section

A section: what the tables are made of (ISO/IEC 13818-1 §2.4.4).

The body is kept as bytes because a table's shape is fixed but its contents are not, and a reader that wants the parsed form asks for Pat::of or Pmt::of.

  • table_idInt32
  • table_id_extensionInt32 The identifier of the stream the table describes.
  • versionInt32
  • currentBool
  • numberInt32
  • last_numberInt32
  • bodyBytes
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Section::encode(self : Section) -> Bytes

Write the section back, checksum included.

pub fn Section::is_intact(self : Section) -> Bool

Whether the section's checksum matches its contents.

pub fn Section::new(table_id? : Int32, extension? : Int32, version? : Int32, number? : Int32, last_number? : Int32, body? : Bytes) -> Section

A section built from its parts, with one section in the set.

pub fn Section::packets(self : Section, pid : Int32, counter? : Int32) -> Array[Packet]

The packets that carry this section on pid.

A section longer than a packet is split, which a programme map table with many streams does; the rest of the last packet is filled with the null byte, as the format asks.

pub fn Section::parse(data : BytesView, at : Int32) -> (Section, Int32) raise TsError

Read the section that starts at at, and say how long it was.

struct pub(all) struct Stream

One elementary stream a programme carries.

  • stream_typeInt32 What the stream is: 0x1B is H.264, 0x0F is AAC in ADTS, 0x24 is HEVC.
  • pidInt32
  • descriptorsBytes The descriptors as they came, tag, length and payload together.
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Stream::new(stream_type : Int32, pid : Int32, descriptors? : Bytes) -> Stream

A stream of stream_type on pid, with the descriptors that describe it.

error pub(all) suberror TsError

Why a stream could not be read.

at is the offset of the packet the reader was in, want what the format requires there and got what was there.

  • Malformed(at~ : Int32, want~ : String, got~ : String)
output

Written by #derive or the trait written for the type.

pub fn TsError::to_string(Self) -> String

The message, as the error prints it.

functions
function pub fn continues(from : Packet, to : Packet) -> Bool

Whether packet follows previous without a gap.

function pub fn crc32(data : BytesView) -> Int32

The checksum every section ends with: MPEG-2's CRC-32, which differs from the one Ethernet uses in not inverting the input or the output.

function pub fn next_counter(previous : Int32, packet : Packet) -> Int32

The continuity counter of the next packet of a stream identifier, which is how a demultiplexer notices that a packet was lost.

A counter only advances on packets that carry a payload, and repeats when a packet is repeated, so the rule is a function of the packet rather than of the count.

function pub fn parse(data : BytesView) -> Array[Packet] raise TsError

Read every packet of data.

A stream that loses its sync is refused: the reader could search for the next 0x47, but a transport stream that lost its alignment is a stream whose packets have already been dropped, and guessing hides that.

function pub fn pes_packets(packets : Array[Packet], pid : Int32) -> Array[Pes] raise TsError

The elementary stream packets a PID carries, reassembled from its transport packets.

A packet begins at a transport packet whose payload starts a unit, and ends where its own length says or, when the length is zero, where the next one begins.

function pub fn sections(packets : Array[Packet], pid : Int32) -> Array[Section] raise TsError

The sections a PID carries, with the pointer fields taken out.

values
value pub let audio_stream_base : Int32

The identifier of an audio stream, 0xC0 to 0xDF.

value pub let null_pid : Int32

No packet carries this identifier: it is the null packet, put in to keep the bit rate up when there is nothing to send.

value pub let packet_size : Int32

The size of every transport stream packet. The format has no other size.

value pub let pat_pid : Int32

The programme association table always arrives on this identifier.

value pub let sync_byte : Int32

The byte every packet starts with.

value pub let table_pat : Int32

The identifier of the programme association table.

value pub let table_pmt : Int32

The identifier of a programme map table.

value pub let video_stream_base : Int32

The identifier of a video stream, 0xE0 to 0xEF.

rtmp RTMP

The publish side: handshake, chunk streams, AMF0, and the session a publisher drives.

enum pub(all) enum Amf0

The value types AMF0 defines, which is what a command is written in.

A command is a name followed by arguments, and the arguments are objects: connect carries an object of application and version, publish a stream name. The variants here are the ones a publish session meets; the rest of the encoding — references, records, XML — is not used by any publisher and is refused rather than guessed at.

  • Number(Double)
  • Boolean(Bool)
  • String(String)
  • Null
  • Undefined
  • Object(Array[(String, Amf0)]) An anonymous object: ordered key and value pairs.
  • EcmaArray(Array[(String, Amf0)]) An object that announced its size first, which JavaScript sends for event data.
  • StrictArray(Array[Amf0])
  • Date(Double, Int32)
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Amf0::as_boolean(self : Amf0) -> Bool?

The value as a boolean, when it is one.

pub fn Amf0::as_number(self : Amf0) -> Double?

The value as a number, when it is one.

pub fn Amf0::as_string(self : Amf0) -> String?

The value as a string, when it is one.

pub fn Amf0::decode(data : BytesView, at? : Int32) -> (Amf0, Int32) raise RtmpError

Read a value, and say how many bytes it took.

pub fn Amf0::encode(self : Amf0) -> Bytes

Write the value.

pub fn Amf0::field(self : Amf0, key : StringView) -> Amf0?

The value under key, when this is an object.

pub fn Amf0::number(value : Double) -> Amf0

A number.

pub fn Amf0::pairs(self : Amf0) -> Array[(String, Amf0)]

The pairs of an object, empty for anything else.

pub fn Amf0::text(value : String) -> Amf0

A string.

struct pub(all) struct ChunkReader

Reads chunks back into messages.

A chunk stream is stateful: after the first chunk of a message, the ones that follow only carry a few bytes of header, because the type, length and stream are still what they were. The reader keeps that state per chunk stream, which is why it has to see the bytes in order.

  • pending@buffer.Buffer
  • streamsArray[Stream]
  • mut chunk_sizeInt32
pub fn ChunkReader::new() -> ChunkReader

A reader that knows nothing yet.

pub fn ChunkReader::push(self : ChunkReader, data : BytesView) -> Array[Message]

Add bytes and take out the messages they complete.

A message split across several reads is held until its last chunk arrives; a message larger than the chunk size is split by the sender and put back together here.

The chunk size is framing rather than content, so it is applied here, as the bytes are read: a message that announces a new size is followed by chunks that already use it, and a reader that waited for its caller to notice would mis-read every one of them.

pub fn ChunkReader::set_chunk_size(self : ChunkReader, size : Int32) -> Unit

Set the chunk size the peer announced, which applies to the chunks after the message that announced it.

struct pub(all) struct ChunkWriter

Writes messages as chunks.

  • mut chunk_sizeInt32
pub fn ChunkWriter::new() -> ChunkWriter

A writer that splits at the default chunk size.

pub fn ChunkWriter::write(self : ChunkWriter, message : Message, chunk_id? : Int32) -> Bytes

The chunks one message becomes: a full header, then a continuation header for each chunk after the first.

struct pub(all) struct Handshake

A handshake as the receiving side sees it.

The server answers with its own block and an echo of the client's, and the client answers with an echo of the server's. The two echoes are what tells each side that the other can read what it writes.

  • randomBytes
  • mut s1Bytes
  • mut c1Bytes
  • mut completeBool
pub fn Handshake::answer(self : Handshake, c0c1 : BytesView, time? : Int32) -> Bytes raise RtmpError

Answer a client's opening: what to send back, which is a version byte, the server's own block, and the client's block echoed.

pub fn Handshake::complete_with(self : Handshake, c2 : BytesView) -> Unit raise RtmpError

Check the client's answer, which has to be the server's block echoed.

pub fn Handshake::is_complete(self : Handshake) -> Bool

Whether the handshake has finished.

pub fn Handshake::new(random? : Bytes) -> Handshake

A handshake with a block of random bytes, zeros when none are given.

struct pub(all) struct Message

A message: what a chunk stream carries once its chunks are put back together.

  • type_Int32
  • stream_idInt32
  • timestampInt32 Milliseconds, and the same for every chunk of the message.
  • payloadBytes
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Message::new(type_ : Int32, stream_id : Int32, payload : Bytes, timestamp? : Int32) -> Message

A message of type_ on stream_id, carrying payload.

enum pub(all) enum Phase

Where a session is.

  • Opening Waiting for the client's opening.
  • Answering Waiting for the client to echo the server's block.
  • Connected Handshaken, and waiting for the commands that set up a stream.
  • Publishing A stream is being pushed.
  • Closed The stream ended.
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

error pub(all) suberror RtmpError

Why a stream could not be read.

  • Malformed(at~ : Int32, want~ : String, got~ : String)
output

Written by #derive or the trait written for the type.

pub fn RtmpError::to_string(Self) -> String

The message, as the error prints it.

struct pub(all) struct Session

The receiving half of a publish: it answers the handshake, answers the commands that set up a stream, and hands the caller the audio, video and metadata that arrives.

A session has no socket. Bytes go in and bytes come out, which is what lets it be tested without one and left to a server to drive.

  • handshakeHandshake
  • readerChunkReader
  • writerChunkWriter
  • pending@buffer.Buffer
  • mut phasePhase
  • mut applicationString
  • mut nameString
  • mut stream_idInt32
  • mut mediaArray[Message]
  • mut metadataArray[(String, Amf0)]
  • mut bytes_inInt32
pub fn Session::app(self : Session) -> String

The application name the client asked for, from connect.

pub fn Session::bytes_received(self : Session) -> Int32

How many bytes have been received.

pub fn Session::metadata(self : Session) -> Array[(String, Amf0)]

The metadata the publisher sent, in the order it sent it.

pub fn Session::new() -> Session

A session that has not heard anything yet.

pub fn Session::phase(self : Session) -> Phase

Where the session is.

pub fn Session::push(self : Session, data : BytesView) -> Array[Bytes] raise RtmpError

Feed the session what arrived, and send back what it has to say.

The answer is a list of writes rather than one buffer because a handshake happens at a different moment from a reply: a caller that wants them together concatenates them, and a caller on a socket sends them one by one.

pub fn Session::stream_name(self : Session) -> String

The stream name the client is publishing to, from publish.

pub fn Session::take_media(self : Session) -> Array[Message]

Take the media messages received so far, which leaves the session with none.

functions
function pub fn acknowledgement(sequence : Int32) -> Message

The message that acknowledges a peer's bytes, which a publisher sends when it has received the window it announced.

function pub fn client_finish(s0s1s2 : BytesView) -> Bytes raise RtmpError

What a client has to answer once the server has answered it.

function pub fn client_start(time : Int32, random? : Bytes) -> Bytes

The bytes a client sends before anything else: a version, a time, four zero bytes, and a block that is meant to be random.

The block is not a secret and nothing is derived from it in the simple handshake, which is why a publisher that fills it with zeros is accepted by every server in use. A caller that would rather not can pass its own.

function pub fn control(type_ : Int32, payload : Bytes) -> Message

A protocol control message: a payload of four bytes in most cases, on stream zero, which is where control messages live.

function pub fn decode_all(data : BytesView) -> Array[Amf0] raise RtmpError

Read values until the data runs out.

function pub fn encode_all(values : Array[Amf0]) -> Bytes

Write values one after another, which is how a command's arguments are laid out.

function pub fn pong(timestamp : Int32) -> Message

The user control event that answers a ping with a pong.

function pub fn set_chunk_size(size : Int32) -> Message

The message that sets the chunk size, which applies to the chunks that follow it and not to itself.

function pub fn set_peer_bandwidth(size : Int32, limit : Int32) -> Message

The message that tells the peer how much bandwidth it may use, and how it should react when it goes over.

function pub fn window_ack_size(size : Int32) -> Message

The message that says how many bytes may be in flight.

values
value pub let default_chunk_size : Int32

The default chunk size, before either side says otherwise.

value pub let msg_abort : Int32

The message that says a stream was abandoned part way through a message.

value pub let msg_acknowledgement : Int32

The message that acknowledges how much has been received.

value pub let msg_audio : Int32

An audio message.

value pub let msg_command : Int32

A command, which is how a session is set up.

value pub let msg_data : Int32

A message of data, which is how metadata is sent.

value pub let msg_set_chunk_size : Int32

The message that sets how large a chunk may be.

value pub let msg_set_peer_bandwidth : Int32

The message that sets how much bandwidth the peer may use.

value pub let msg_user_control : Int32

The message that carries a user control event, such as a ping.

value pub let msg_video : Int32

A video message.

value pub let msg_window_ack_size : Int32

The message that says how large the sender's window is.

value pub let random_size : Int32

How many bytes each of the two random blocks is.

value pub let version : Int32

The version byte every peer sends first. Three is the only version in use.

mpd DASH

Manifests: periods, adaptation sets, segment templates and timelines.

struct pub(all) struct AdaptationSet

A group of representations a player chooses between: the video renditions of one period, or the audio ones.

  • mut idInt32?
  • mut content_typeString?
  • mut mime_typeString?
  • mut langString?
  • mut codecsString?
  • mut segment_alignmentBool?
  • mut start_with_sapInt32?
  • mut widthInt32?
  • mut heightInt32?
  • mut frame_rateDouble?
  • mut audio_sampling_rateInt32?
  • mut base_urlString?
  • mut templateTemplate?
  • mut segment_listSegmentList?
  • mut segment_baseSegmentBase?
  • mut protectionArray[ContentProtection]
  • mut representationsArray[Representation]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn AdaptationSet::new(content_type? : String, mime_type? : String, lang? : String) -> AdaptationSet

A set carrying content_type, mime_type and a language.

struct pub(all) struct ContentProtection

One ContentProtection entry: the scheme that names a key system, the value that scheme gives the rendition, and the protection header the key system is handed.

A manifest does not encrypt anything itself; it says which key system opens a rendition and gives that system the box it needs. The box travels base64 in the manifest and is kept here as the bytes it decodes to, so a caller hands it on without decoding anything a second time.

  • mut scheme_id_uriString The scheme that names what protects the rendition, often a UUID.
  • mut valueString? The value the scheme gives this entry, when it gives one.
  • mut psshBytes? The pssh box, decoded.
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn ContentProtection::new(scheme_id_uri : String, value? : String, pssh? : Bytes) -> ContentProtection

An entry for scheme_id_uri, optionally carrying a value and a header.

struct pub(all) struct Initialization

Where the initialisation segment is: a URL, a range inside one, or both.

  • mut source_urlString?
  • mut rangeRange?
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Initialization::new(source_url? : String) -> Initialization

An initialisation section at source_url, with nothing else set.

enum pub(all) enum Kind

Whether a presentation is a file to play or a stream still being written.

  • Static A presentation that is complete.
  • Dynamic A presentation that keeps growing, where the manifest is reloaded.
  • Other(String)
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Kind::code(self : Kind) -> String

The kind as it is written.

pub fn Kind::of(code : StringView) -> Kind

The kind a written value names.

struct pub(all) struct Manifest

A media presentation description: what a DASH client reads before it fetches anything.

  • mut kindKind
  • mut profilesString?
  • mut min_buffer_timeDouble?
  • mut durationDouble?
  • mut minimum_update_periodDouble?
  • mut availability_startString?
  • mut publish_timeString?
  • mut time_shift_buffer_depthDouble?
  • mut suggested_delayDouble?
  • mut base_urlString?
  • mut periodsArray[Period]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Manifest::encode(self : Manifest) -> String

Write the manifest.

pub fn Manifest::new(kind? : Kind) -> Manifest

A manifest for a complete presentation, with nothing set but the kind.

pub fn Manifest::parse(text : StringView) -> Manifest raise MpdError

Read a manifest.

error pub(all) suberror MpdError

Why a manifest could not be read.

at is the byte offset the reader had reached, want what the grammar requires there and got what was there.

  • Malformed(at~ : Int32, want~ : String, got~ : String)
output

Written by #derive or the trait written for the type.

pub fn MpdError::to_string(Self) -> String

The message, as the error prints it.

struct pub(all) struct Period

A stretch of the presentation that is played on its own: a title, or the part of a live stream between two ad breaks.

  • mut idString?
  • mut startDouble?
  • mut durationDouble?
  • mut base_urlString?
  • mut templateTemplate?
  • mut segment_listSegmentList?
  • mut segment_baseSegmentBase?
  • mut protectionArray[ContentProtection]
  • mut adaptationsArray[AdaptationSet]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Period::new(id? : String, start? : Double) -> Period

A period that starts at start seconds.

struct pub(all) struct Range

A range of bytes in a file, as a manifest writes it: 1389-15304, both ends counted.

The end may be left out, which means "to the end of the file".

  • mut startInt64
  • mut endInt64?
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Range::length(self : Range) -> Int64?

How many bytes the range covers, when its end is known.

pub fn Range::new(start : Int64, end? : Int64) -> Range

A range starting at start, ending at end when there is one.

pub fn Range::of(text : StringView) -> Range?

The range a written value names, start-end or start-.

pub fn Range::text(self : Range) -> String

The text a range is written as.

struct pub(all) struct Representation

One encoding of the presentation: a single quality a player can choose.

  • mut idString
  • mut bandwidthInt32?
  • mut codecsString?
  • mut mime_typeString?
  • mut widthInt32?
  • mut heightInt32?
  • mut frame_rateDouble?
  • mut audio_sampling_rateInt32?
  • mut base_urlString?
  • mut templateTemplate?
  • mut segment_listSegmentList?
  • mut segment_baseSegmentBase?
  • mut protectionArray[ContentProtection]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Representation::new(id : String, bandwidth? : Int32) -> Representation

A representation of id costing bandwidth bits per second.

struct pub(all) struct SegmentBase

A single file addressed by byte ranges, with an index a player reads first.

The on-demand profile: one request for the index tells a player where every segment is, so it can fetch the ones it needs without the others.

  • mut timescaleInt64?
  • mut presentation_time_offsetInt64?
  • mut index_rangeRange?
  • mut index_range_exactBool?
  • mut initializationInitialization?
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn SegmentBase::new() -> SegmentBase

A segment base with nothing set.

struct pub(all) struct SegmentList

Segments written out one by one, each with its own URL or its own range.

This is how a packager addresses a stream it wrote into a single file: the manifest lists where each piece starts and ends, so a player fetches a range instead of a file.

  • mut timescaleInt64?
  • mut durationInt64?
  • mut start_numberInt64?
  • mut presentation_time_offsetInt64?
  • mut initializationInitialization?
  • mut urlsArray[SegmentUrl]
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn SegmentList::length(self : SegmentList) -> Int32

How many segments the list holds.

pub fn SegmentList::new() -> SegmentList

A list with nothing in it.

struct pub(all) struct SegmentUrl

One segment of a list: the whole file, or a range inside the file the representation's base URL names.

  • mut mediaString?
  • mut media_rangeRange?
  • mut index_rangeRange?
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn SegmentUrl::new(media? : String) -> SegmentUrl

A segment named media, with no range: the whole file.

struct pub(all) struct Template

How the segments of a representation are addressed: a template with the numbers filled in, which is what almost every manifest uses.

  • mut timescaleInt64?
  • mut durationInt64? The length of a segment in timescale units, when they are all the same.
  • mut start_numberInt64?
  • mut presentation_time_offsetInt64?
  • mut initializationString? Where the initialisation segment is, with $RepresentationID$ in it.
  • mut mediaString? Where the segments are, with $Number$ or $Time$ in it.
  • mut timelineArray[Timeline] The segments' times and lengths, when they are not all the same.
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Template::count(self : Template, seconds : Double) -> Int32

How many segments this template addresses, when the presentation lasts seconds.

A template with one duration repeats it until the presentation ends; a template with a timeline answers with the entries it lists.

pub fn Template::initialization_url(self : Template, representation_id? : StringView, bandwidth? : Int32) -> String

The URL of the initialisation section this template names.

pub fn Template::new() -> Template

A template with nothing set.

pub fn Template::segment_url(self : Template, number? : Int64, representation_id? : StringView, time? : Int64, bandwidth? : Int32) -> String

The URL a segment of this template is fetched from.

A template is a name with the numbers filled in: $RepresentationID$ for which rendition, $Number$ for which segment, $Time$ for a segment addressed by the time it starts, and $Bandwidth$ for what it costs. A number may carry a width, $Number%05d$, which is how a list of segments stays in order when it is listed.

An identifier this release does not know is written back as it was written, so a caller comparing names can see that the template asked for something else rather than fetching the wrong one.

struct pub(all) struct Timeline

Where a segment starts and how long it runs, for a stream whose segments do not have one length.

  • mut timeInt64? The start, in timescale units; absent means "where the last one ended".
  • mut durationInt64
  • mut repeatInt32 How many times the entry repeats, -1 for "until the next entry".
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

pub fn Timeline::new(duration : Int64, repeat? : Int32, time? : Int64) -> Timeline

A run of segments of duration in timescale units.

pub fn Timeline::span(self : Timeline) -> Int64

How long the entry lasts, in timescale units: a repeat of negative one means the run lasts until the next entry, which only the next entry can say.

functions
function pub fn format_duration(seconds : Double) -> String

A duration in seconds written the way a manifest writes it.

Fractions are kept to three places, which is finer than any frame rate and short enough to read.

function pub fn parse_duration(text : StringView) -> Double?

An ISO 8601 duration in seconds: PT2S, PT1M30.5S, PT1H.

A manifest writes the length of a presentation this way rather than as a count of seconds, and the reader has to take it back apart. Years and months have no fixed length, so a duration that uses them is refused rather than given a length it might not have.

moonmedia Packager

An MP4 in, key-frame segments and the playlists that name them out.

struct pub(all) struct Packager

A stream cut into segments a player can fetch one at a time.

The packager is HLS packaging without the files: it turns a movie into an initialisation section and a list of segments, and writes the playlists that name them. Writing them out and answering HTTP requests is the caller's job, and deliberately so — nothing here touches a socket.

  • initBytes
  • segmentsArray[Segment]
  • tracksArray[Track]
  • target_durationDouble
pub fn Packager::audio_track(self : Packager) -> Track?

The first audio track, when there is one.

pub fn Packager::duration(self : Packager) -> Double

How long the packaged stream plays, in seconds.

pub fn Packager::init_segment(self : Packager) -> Bytes

The bytes a player needs before it can decode any segment.

pub fn Packager::master_playlist(self : Packager, uri? : StringView, bandwidth? : Int32) -> @m3u8.Master

A master playlist offering the packaged stream as one variant.

bandwidth is what the variant costs per second. When it is left out the packager measures what it produced, which is close enough for a player choosing between renditions and pointless as a description of the source.

There is no EXT-X-I-FRAME-STREAM-INF: a list of key frames only is a different playlist, with different segments, and pointing this one at that tag would describe it as something it is not.

pub fn Packager::media_playlist(self : Packager, prefix? : StringView, init_name? : StringView) -> @m3u8.MediaPlaylist

The media playlist for these segments.

prefix is what a player puts in front of a segment name; leaving it out serves the segments from the same directory as the playlist.

pub fn Packager::new(file : @mp4.Mp4, target_duration? : Double) -> Packager raise @mp4.Mp4Error

Cut file into segments of about target_duration seconds, each starting on a key frame.

A segment starts on a video key frame and takes the audio that plays over it, so a player that switches rendition or seeks lands on something it can decode without waiting for the next key frame. Cuts fall on the first key frame at or after the target, which is what keeps segments independent: cutting at the exact duration would leave a key frame in the middle of the previous segment.

pub fn Packager::segments(self : Packager) -> Array[Segment]

The segments, in presentation order.

pub fn Packager::video_track(self : Packager) -> Track?

The first video track, when there is one.

struct pub(all) struct Sample

One sample, already cut out of the file it came from.

  • dataBytes
  • dtsInt64
  • durationInt64
  • composition_offsetInt64
  • syncBool
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

struct pub(all) struct Segment

A segment of a packaged stream: the bytes a player fetches, and how long they play.

  • dataBytes The fragment as bytes, a moof followed by its mdat.
  • durationDouble
  • startDouble Where the segment starts, in seconds from the beginning of the stream.
  • keyframeBool Whether a player may start here. Every segment the packager cuts starts on a key frame, and is kept as a field because a caller assembling its own segments may want to know.
  • samplesArray[Int32] How many samples each track contributes, in track order.
equal, not_equal, to_repr

Written by #derive or the trait written for the type.

struct pub(all) struct Track

A track as the packager needs it: what it is, its timescale, and where its samples are.

  • idInt32
  • kindTrackKind
  • codecString
  • timescaleInt64
  • widthInt32
  • heightInt32
  • samplesArray[Sample]
enum pub(all) enum TrackKind

What a track carries.

  • Video
  • Audio
  • Subtitle
  • Other(String)
equal, not_equal, to_repr

Written by #derive or the trait written for the type.