Skip to main content

Import

Struct Import 

Source
pub struct Import<E: Catalog = ()> { /* private fields */ }
Expand description

Demuxes an MPEG-TS byte stream into a MoQ broadcast.

Decodes H.264 (stream type 0x1B), H.265 (0x24), ADTS AAC (0x0F), MP2 (0x03/0x04), AC-3 (0x81), and E-AC-3 (0x87). Each codec stream is fed to its importer, which manages the track, catalog config, and keyframe-based group boundaries. MPEG-1/2 video (0x01/0x02) is not decoded but still paces the program: its PTS anchors the timebase while its PES ride whole as below.

Video access units can span PES packets, and one PES can contain several. Its PTS stamps the AU whose required start-code prefix begins there, once. Later AUs need anchored POC and proportional timing: AVC’s TS timing descriptor plus fixed-rate SPS VUI, or HEVC’s poc_proportional_to_timing_flag. Missing timing ends the import; it is not recoverable packet damage. Raw elementary-stream import keeps its caller-supplied timestamp mode.

Partial header contents hold at most 264 bytes per PID. PES payloads, retained video AUs, and sections awaiting a timestamp share a 16 MiB budget, and at most 4096 units are buffered, the raw TS accumulator’s group roll triggers. Exceeding either limit refuses the input instead of retaining more bytes.

Elementary streams we don’t decode are carried verbatim, one MoQ track per PID, when the catalog E carries the mpegts section: section-framed streams (private sections 0x05, the ISO 13818-6 DSM-CC types 0x0A to 0x0D, and SCTE-35 0x86 marked by a program-level ‘CUEI’ registration descriptor) are reassembled as sections, and any other stream travels as whole PES packets (PesPacket), LATM/LOAS AAC (0x11) included. A 0x86 stream without ‘CUEI’, which may be DTS audio or SCTE-35, is not carried. With a base Catalog<()> no undecoded stream is carried.

Every PID is accounted for. A listed stream that is not carried counts once in stats::Stream::refused with a warning, and so does each TS-scrambled packet on a carried one and each PES-scrambled PES on a decoded one. Once the PMT is in, a packet on a PID no table claims (the null PID aside) counts in its own row: see stats::Snapshot::streams. That holds when the PAT lists only the imported program; a with_program import of a multiplex cannot tell another program’s PIDs from unclaimed ones, so it leaves them to Programs.

A whole PES or section is timestamped with its placement: the program clock at its first byte, interpolated between the PCRs either side of it (ISO 13818-1 2.4.2.2) and shifted onto the catalog clock as the media is. It waits for the PCR after it, and for the first media PTS to anchor the timebase, or the first PCR when the PMT declares no media stream, within the staging bound below; one that starts past the last PCR before a clock break or the end of input is extrapolated from the last two. One before the first PCR, or with no interval to extrapolate from, is dropped and counted in stats::Stream::unplaced. A section’s SCTE-35 splice times absorb the media’s offset in pts_adjustment; a whole PES’s PTS and DTS move by that offset, and every other byte is kept. A stream whose PES carry a clock only the PTS and DTS of are rebased (ESCR, a pack_header_field, a TREF), PES-level scrambling, an unbounded non-video PES, or a header export would refuse is refused rather than altered. A program with no PCR refuses both whole PES and section streams: stats::Stream::refused. A PMT that moves the PCR PID ends the placement timebase, as a clock break does; one that drops the PCR refuses those streams, and one that names it again carries them.

The PAT and every PMT are reassembled the same way, so a table that spans packets or sits behind a nonzero pointer_field is read whole. A PAT or PMT section whose CRC-32 fails is dropped and counted in stats::Snapshot::crc_error; the last good table stays in force.

With the mpegts catalog extension, the catalog goes out with the first media and gains mpegts.muxRate as an update once a two-second PCR window measures a constant rate, which a variable-rate source never does. An export that pads waits for that update. A restarted import’s catalog carries its predecessor’s measurement of the same multiplex (Republish), which the measurement then refines as usual.

The selected container applies only to decoded media renditions. Verbatim tracks in the mpegts catalog section continue to use the legacy Hang container.

PTS values follow the program’s timestamp history across their 33-bit wrap, including the PCR history before a data-only program gains media.

Implementations§

Source§

impl<E: Catalog> Import<E>

Source

pub fn new(broadcast: Producer, reserved: Reserved<E>) -> Self

Import a byte stream into the broadcast using its reserved catalog producer.

Source

pub fn with_timebase(self, timebase: Timebase<E>) -> Self

Shift this program’s timestamps through timebase, a timestamp base of the catalog reserved belongs to, instead of a fresh one: importers of one source share its offset.

Set it before the first decode, which may anchor the timebase.

Source

pub fn with_program(self, program: u16) -> Self

Import only the program numbered program in the PAT, ignoring the rest of the multiplex.

Without this, a PAT that lists more than one program fails the import with MultiplePrograms rather than merging them onto one clock. A PAT that does not list program fails it too. The SI describes only this program’s service: other services’ EIT actual is dropped and the SDT actual lists this service alone.

Source

pub fn with_container(self, container: Container) -> Self

Select the container this importer wraps decoded media renditions in.

Legacy unless selected. It applies to every rendition this input demuxes, since the tracks are discovered rather than named by the caller.

Source

pub fn decode(&mut self, data: &[u8]) -> Result<(), Error>

Append buf to the internal scratch and demux every whole TS packet it now completes. The buffer is fully consumed; a trailing partial packet (< 188 bytes) is retained for the next call.

A step of the source’s clock onto another timeline ends the identity, failing with Restarted: the program clock and every timed stream stepping together without discontinuity_indicator, forward by more than 10 s or back, or the streams stepping back after a flagged break. Until the streams have spoken, which a cadenced one does within 0.7 s, the input after a suspected step is held rather than published, up to half a group’s bytes. A PAT naming another transport_stream_id or program number restarts too, at that PAT. Every later call fails the same way; finish ends the identity before the step.

A PAT listing several programs fails with MultiplePrograms unless with_program picked one. Input after finish is refused with Finished, or with the cause of a finish that failed.

Republish carries on past each restart into a new identity, on a path of an origin.

Source

pub fn finish(self) -> Result<Finished<E>, Error>

Flush any buffered PES, finish every track, and return the Finished import.

Input held while a step was judged is read first, failing with Restarted if it reaches one, since this import would drop the broadcast after it. A step decode already reported ends the identity there instead. A finish that fails aborts every track with the cause, so it can’t be retried.

Source

pub fn stats(&self) -> Snapshot

Snapshot what every elementary stream has delivered, the audio frame sync lost on the way, damaged units refused, and the PAT and PMT sections dropped for a bad CRC.

Cheap: it reads counters the demuxer already keeps, so a caller can poll it per chunk and report the delta.

Source

pub fn abort(self, err: Error)

Abort every track with err instead of finishing, so subscribers see the real cause rather than [moq_net::Error::Dropped]. Buffered PES is discarded. Consumes the importer.

Unlike a drop, this leaves the tracks’ HLS records to the catalog, whose abort fails them rather than ending them as a complete recording.

Trait Implementations§

Source§

impl<E: Catalog> Drop for Import<E>

Source§

fn drop(&mut self)

End the input unless it already ended.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<E = ()> !Freeze for Import<E>

§

impl<E = ()> !RefUnwindSafe for Import<E>

§

impl<E = ()> !Sync for Import<E>

§

impl<E = ()> !UnwindSafe for Import<E>

§

impl<E> Send for Import<E>

§

impl<E> Unpin for Import<E>

§

impl<E> UnsafeUnpin for Import<E>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more