Skip to main content

Passthrough

Struct Passthrough 

Source
pub struct Passthrough<E: Catalog = Ext> { /* private fields */ }
Expand description

Publishes a transport stream verbatim, as one track of whole 188-byte packets.

Every packet goes out in input order, on the track the catalog’s mpegts section names in passthrough, with the multiplex rate in its mux_rate. It reads the PAT and PMT to find the program clock and the video stream, and reads nothing else past an adaptation field, so a scrambled multiplex groups and paces exactly like its clear twin.

§Objects and groups

An object runs from one PCR packet on the clock PID to the next, and is also cut wherever a group starts. A group starts at:

  • a packet with random_access_indicator on the video PID, or on the clock PID when the program has no video;
  • a PCR that breaks the count (see Timestamps): one with discontinuity_indicator, or a step not taken as elapsed time, since no group may hold a PCR discontinuity;
  • the first PCR at least one second after the group’s start, for a source that never marks random access;
  • the first object that would take the group past half of what moq-net caches of one group, in bytes or in frames, so a long GOP cannot outgrow what a relay caches. Objects are never split to meet the bound.

Only the first of these makes a group a random access point, so any other start publishes random_access false from then on, as does any group carried while the layout allows no random access (more than one program or video stream). A group the PCR discontinuity starts is behind a break even when it is also a random access point.

Bytes before the first group are dropped: until the PMT, a PCR, and a group start have all been seen there is no group to put them in. The track is byte-identical to the input from its first group on, and only from there. Bytes off the 188-byte packet grid are dropped too.

§Timestamps

An object’s timestamp is the PCR time of its first byte, interpolated at the rate between the PCRs either side of it, floored to microseconds. A PCR stamps the byte holding the last bit of its base, ten bytes into its packet, so even an object that starts at a PCR packet sits ten bytes of that rate before its own PCR.

Every timestamp is then shifted onto the catalog’s Clock by one offset, fixed through the reservation’s Timebase by the first object: zero when that object places the clock, and otherwise whatever lands it at now on a clock already in use.

PCRs are unwrapped into a 64-bit count of 27 MHz ticks that never goes back. A step forward of at most half the 2^33 * 300 tick period adds to the count, across the wrap included, unless it is more than 10 s without discontinuity_indicator. A PCR with the flag whose step is forward adds the step too. Every other step, back with or without the flag or that unflagged leap, is another timeline, such as a switch between two encoders whose clocks were never locked, and is spliced: the count carries on from the time the rate before the PCR gives it. Either way the bytes before it are timed at the rate before it, and the next group starts behind a break marker. The bytes still go out verbatim, so a decoder downstream sees the step as the source sent it. The timeline therefore depends only on the bytes since the importer’s first PCR and its shift, and two importers of one feed started at the same packet each placing its own catalog’s clock publish identical objects.

The catalog’s extension must carry the mpegts section (Catalog), such as Ext: new refuses one that does not.

Implementations§

Source§

impl<E: Catalog> Passthrough<E>

Source

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

A passthrough importer publishing one track on broadcast, listed in the catalog behind reserved.

Fails with NoMpegtsSection when the catalog’s extension carries no mpegts section to list the track in.

Source

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

Shift the multiplex’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_pcr_pid(self, pid: u16) -> Self

Pace the multiplex on pid rather than on the PCR_PID of the PAT’s first program.

Groups then start at random access points of the video stream of the first program whose PMT names pid as its clock. When no program does, they start at pid’s own random access points, which mark no program’s decoding boundary, so the track never claims random access.

Source

pub fn track(&self) -> &str

The name of the track carrying the packets.

Source

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

Append data and publish every whole packet it completes. A trailing partial packet is kept for the next call.

Source

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

Publish what is left at the end of the input, close the track, and return the Finished passthrough.

No later PCR will arrive, so the objects since the last one are timed at the rate of the interval before it. The catalog keeps listing the track until the Finished passthrough drops.

A finish that fails ends the track with an error, so it can’t be retried.

Source

pub fn abort(self, err: Error)

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

Auto Trait Implementations§

§

impl<E = Ext> !RefUnwindSafe for Passthrough<E>

§

impl<E = Ext> !Sync for Passthrough<E>

§

impl<E = Ext> !UnwindSafe for Passthrough<E>

§

impl<E> Freeze for Passthrough<E>

§

impl<E> Send for Passthrough<E>

§

impl<E> Unpin for Passthrough<E>

§

impl<E> UnsafeUnpin for Passthrough<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