pub struct Export<S: Stream>{ /* 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>
impl<S: Stream> Export<S>
Sourcepub fn new(source: Source, catalog: S, delay: Duration) -> Self
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.
Sourcepub fn with_mux_rate(self, mux_rate: u64) -> Self
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.
Sourcepub fn poll_next(&mut self, waiter: &Waiter) -> Poll<Result<Option<Frame>>>
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.
Sourcepub async fn next(&mut self) -> Result<Option<Frame>>
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.
Sourcepub fn stats(&self) -> Export
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.
Sourcepub fn discontinuity(&self) -> u64
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.
Sourcepub fn follow(self, broadcast: Consumer, catalog: S) -> Result<Self, Error>
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.