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_indicatoron 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-netcaches 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>
impl<E: Catalog> Passthrough<E>
Sourcepub fn new(broadcast: Producer, reserved: Reserved<E>) -> Result<Self>
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.
Sourcepub fn with_timebase(self, timebase: Timebase<E>) -> Self
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.
Sourcepub fn with_pcr_pid(self, pid: u16) -> Self
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.
Sourcepub fn decode(&mut self, data: &[u8]) -> Result<()>
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.
Sourcepub fn finish(self) -> Result<Finished<E>>
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.