Skip to main content

Export

Struct Export 

Source
pub struct Export<S: Stream>
where S::Ext: Catalog,
{ /* private fields */ }
Expand description

Subscribe to a broadcast and produce an MPEG-TS byte stream.

Use poll_next to pull one Frame per PCR grid slot: its payload is the TS packets belonging to that slot, stamped at the slot’s boundary. The leading PAT/PMT rides on the first frame (so it inherits a real timestamp), and is re-emitted at video keyframes and periodically for mid-stream tune-in. SI and whole PES or sections wait until a PCR interval has followed it, since a reader places them on the program clock and the PMT is what names it. Returns None once the catalog ends and its media drains. Finishing only the media tracks keeps it waiting for catalog updates. A publisher that leaves instead fails the export with its cause once what was already buffered has gone out on schedule.

A rendition the catalog moves to another track (a new track or broadcast) goes on out of its PID from the new track’s first sync frame past what was read, when the PMT can announce it unchanged; one that goes back in time fails the export.

Implementations§

Source§

impl<S: Stream> Export<S>
where S::Ext: Catalog,

Source

pub fn new(source: Source, catalog: S, delay: Duration) -> Self

Export source as MPEG-TS, driving track subscriptions from catalog.

The caller chooses the catalog format and rendition selection on any Stream. The stream remains owned until the export is dropped or follows another broadcast; concrete catalog consumers release their subscription and decoder when they end.

Mux each frame delay after its release time, like an SRT receiver’s TSBPD: its decode time less its send-ahead.

The send-ahead comes out of the same budget. A frame may go out up to the delay ahead of its decode time, as far as its PID’s decoder buffer holds and as early as the receiver’s buffers admit, so a heavy passage rides the slots before it. Its release time is that far before its decode time, so it is muxed just as the first slot it may ride is laid, and each slot goes out the delay after its own time on the source’s clock rather than a delay later still.

The clock is acquired before anything goes out: frames are held until every expected track has delivered (two delays at most) and a track starts a new group, or for a delay at most once all have. The track sent latest against its release time sets the clock, so a joiner runs at the delay from its first output and every frame has the whole delay to arrive in. A source that sends its video its send-ahead early, as a TS mux does, is trailed by the delay; one that sends every track at its decode time, by the delay and the video’s send-ahead. The output then keeps the source’s pace and muxes every track in (release time, PID) order whatever the arrival skew between them. A frame that arrives after its deadline is dropped, and a video track that dropped one resumes at its next keyframe. A source whose clock runs further off ours than 13818-1 lets the PCR follow fails the export once it has used half the delay, where a brief network stall only drops what it made late. Every track is subscribed with the whole delay as its max, so a relay resets a group only once it is that old; a live export joins at the edge, and a replay reaches back the whole delay. The export skips a stalled group once it falls the whole delay behind the newest content (see Consumer), so a stall shorter than the delay loses nothing, while a group whose tail never arrives makes the start of the next one late.

With a multiplex rate, a frame that cannot arrive by its decode time fails the export, as does video whose HRD declares a buffer delay past the delay.

A zero delay holds nothing and sends each frame by its decode time.

Source

pub fn with_mux_rate(self, mux_rate: u64) -> Self

Pad the output with null packets to mux_rate bits per second, whatever the catalog records, which is used as given. Without this the catalog’s mpegts.muxRate decides, a packet a slot faster for the export’s own clock and framing, and a catalog without one leaves the output unpadded.

Zero and absurd rates are refused with a warning, leaving the output unpadded rather than allocating unbounded nulls.

Source

pub fn poll_next(&mut self, waiter: &Waiter) -> Poll<Result<Option<Frame>>>

Get the next muxed frame.

Each Frame carries one slice of the PCR grid in payload: the clock packets that slice opens with, followed by the muxed bytes belonging to it. With a delay, each slice is handed over at its time on the jitter buffer’s clock, which follows the source’s, so a sink writes it as it comes. It is stamped with the media time that slice starts at, for a transport that stamps its own delivery, and keyframe marks the slice a video keyframe begins in. The leading PAT/PMT rides on the first slice, and is re-emitted at video keyframes and periodically for mid-stream tune-in. Returns None when the broadcast ends. duration is always None: the muxer has no use for it.

Source

pub async fn next(&mut self) -> Result<Option<Frame>>

Get the next muxed frame.

Each Frame carries one slice of the PCR grid in payload: the clock packets that slice opens with, followed by the muxed bytes belonging to it. With a delay, each slice is handed over at its time on the jitter buffer’s clock, which follows the source’s, so a sink writes it as it comes. It is stamped with the media time that slice starts at, for a transport that stamps its own delivery, and keyframe marks the slice a video keyframe begins in. The leading PAT/PMT rides on the first slice, and is re-emitted at video keyframes and periodically for mid-stream tune-in. Returns None when the broadcast ends. duration is always None: the muxer has no use for it.

Awaits poll_next.

Source

pub fn stats(&self) -> Export

Snapshot the access units each elementary stream has written, how long each has been quiet on the PCR the output carries, and how the release clock is keeping up with the source.

A track stalled upstream stops advancing its row while the PSI and the other PIDs keep flowing, which nothing graded on the output bytes alone can see. The rows are empty until the program tables are built. Cheap enough to poll per frame.

Source

pub fn discontinuity(&self) -> u64

The discontinuity counter of the most recently returned output frame. Compare across reads and re-anchor pacing when it changes. Renditions have independent source counters; this counter describes the emitted program.

Source

pub fn follow(self, broadcast: Consumer, catalog: S) -> Result<Self, Error>

Carry on into broadcast, using the caller’s replacement catalog stream.

The same stream (an equal identity) continues: the program and its PSI carry on, and its catalog resubscribes each track as it lists it, so a gap is a skip like any other. A track it adds or drops revises the PMT, as any catalog update does.

Another identity, or a broadcast without one, opens a fresh jitter generation. Follower keeps feeding the old program until the new clock and first media are usable, bounded by its follow window. Then what the old program already released goes out before the new PMT, and what it still buffers is dropped, so the new program keeps its own delay. The new PMT has advanced table versions, every PID’s first packet flags the break, and each stream starts on a keyframe. No timestamps are aligned.

Auto Trait Implementations§

§

impl<S> !Freeze for Export<S>

§

impl<S> !RefUnwindSafe for Export<S>

§

impl<S> !UnwindSafe for Export<S>

§

impl<S> Send for Export<S>
where <S as Stream>::Ext: Sized,

§

impl<S> Sync for Export<S>
where <S as Stream>::Ext: Sized + Sync, S: Sync,

§

impl<S> Unpin for Export<S>
where <S as Stream>::Ext: Sized, S: Unpin,

§

impl<S> UnsafeUnpin for Export<S>
where <S as Stream>::Ext: Sized + UnsafeUnpin, S: UnsafeUnpin,

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> Followed for T
where T: Followed,

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