Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 0 additions & 66 deletions quest/m1/export-delay-wire.md

This file was deleted.

2 changes: 1 addition & 1 deletion rs/moq-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ pub struct BufferedFragmented {
pub struct Transport {
/// How far behind the source the output runs (e.g. `2s`), like an SRT receiver's latency,
/// including how far ahead of its decode time each frame is sent. A frame that arrives
/// later than this is dropped, and a stalled group is skipped once it falls half this
/// later than this is dropped, and a stalled group is skipped once it falls this far
/// behind the newest content.
#[usage(long, default = "1s")]
pub delay: moq_tokio::cli::Duration,
Expand Down
25 changes: 20 additions & 5 deletions rs/moq-mux/src/container/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,15 +1414,11 @@ impl<F: Container> Consumer<F> {
/// a missing group is waited for from now on. A min past the max starts at the max, since the
/// publisher serves nothing older.
pub fn set_delay(&mut self, delay: Delay) {
self.set_skip(delay);
// An ended reader has no subscription left to tune.
let (Reader::Reading(track) | Reader::Failed(track, _)) = &mut self.reader else {
return;
};
self.min_delay = delay.min;
self.max_delay = delay
.max
.unwrap_or(std::time::Duration::MAX)
.min(track.info().max_age.unwrap_or(std::time::Duration::MAX));
// The transport enforces the same budget on the subscription itself, so a
// tolerance set here has to reach it: otherwise moq-net skips the very groups
// this consumer was told to wait for, before they ever get here. It keeps the
Expand All @@ -1434,6 +1430,25 @@ impl<F: Container> Consumer<F> {
}
}

/// Skip at `delay`, clamped like [`set_delay`](Self::set_delay), leaving the subscription's
/// delay as it is. A delay past the subscription's skips nothing later, since the transport
/// drops a group first.
pub(crate) fn skipping_at(mut self, delay: Delay) -> Self {
self.set_skip(delay);
self
}

// Wait and skip at `delay`, its max clamped to the track's max age.
fn set_skip(&mut self, delay: Delay) {
if let Reader::Reading(track) | Reader::Failed(track, _) = &self.reader {
self.min_delay = delay.min;
self.max_delay = delay
.max
.unwrap_or(std::time::Duration::MAX)
.min(track.info().max_age.unwrap_or(std::time::Duration::MAX));
}
}

/// Skip a missing group once `playhead`, the playout clock this reader feeds, reaches where the
/// first group past it begins (default: no clock), rather than waiting out the whole
/// [`Delay::min`]. Suits media where a late item is worthless once the next is due, such as
Expand Down
15 changes: 15 additions & 0 deletions rs/moq-mux/src/container/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ pub(crate) struct ExportSource {
state: SourceState,
/// Where the subscription starts behind the live edge, and how late a group may fall.
delay: moq_net::track::Delay,
/// The delay the consumer skips and starts at, if not the one the subscription states.
skip: Option<moq_net::track::Delay>,
transform: Option<VideoTransform>,
/// Resolved codec configuration record (avcC / hvcC / AudioSpecificConfig /
/// OpusHead). Some once the codec config is available - from the catalog
Expand Down Expand Up @@ -321,6 +323,7 @@ impl ExportSource {
state: target.request(source, media),
target,
delay,
skip: None,
transform: None,
description: None,
video_codec: None,
Expand Down Expand Up @@ -396,6 +399,14 @@ impl ExportSource {
self
}

/// Skip and start at `delay` instead of the subscription's own, which still tells the
/// publisher how long to keep a group: for a reader that asks the publisher for more than
/// it plays out itself.
pub(crate) fn skipping_at(mut self, delay: moq_net::track::Delay) -> Self {
self.skip = Some(delay);
self
}

/// The subscription options a builder sets. Each builder consumes a source no poll has
/// moved out of [`SourceState::Requesting`], since only the constructors hand one out.
fn start(&mut self) -> &mut Start {
Expand Down Expand Up @@ -622,6 +633,10 @@ impl ExportSource {
None => track,
};
let consumer = Consumer::new(track, media).continuing(reached);
let consumer = match self.skip {
Some(delay) => consumer.skipping_at(delay),
None => consumer,
};
let consumer = match live {
true => consumer.live(),
false => consumer,
Expand Down
124 changes: 55 additions & 69 deletions rs/moq-mux/src/container/ts/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1640,10 +1640,12 @@ where
/// 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. A stalled group is
/// skipped once it falls half the delay behind the newest content (see
/// [`Consumer`](crate::container::Consumer)), so the group after it still arrives with
/// the other half to spare.
/// the delay, where a brief network stall only drops what it made late. Every track is
/// subscribed with the whole delay as its min and max, so a relay resets a group only once it
/// is that old. The export skips a stalled group once it falls the whole delay behind the
/// newest content (see [`Consumer`](crate::container::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.
Expand Down Expand Up @@ -2576,17 +2578,14 @@ where
.filter(|track| track.source.reads(&self.program.source, name, config));
let mut track = match reused {
Some(track) => track,
None => match ExportSource::for_video(
&self.program.source,
name,
config,
moq_net::track::Delay::default().with_min(None).with_max(self.budget()),
)?
.map(|s| at_edge(s, self.program.replay))
{
Some(source) => Track::new(source, kind.clone()),
None => continue,
},
None => {
match ExportSource::for_video(&self.program.source, name, config, subscribed(self.program.delay))?
.map(|s| at_edge(skipping(s, self.program.delay), self.program.replay))
{
Some(source) => Track::new(source, kind.clone()),
None => continue,
}
}
};
track.kind = kind;
track.timing.configure(config, name)?;
Expand All @@ -2602,17 +2601,14 @@ where
.filter(|track| track.source.reads(&self.program.source, name, config));
let mut track = match reused {
Some(track) => track,
None => match ExportSource::for_audio(
&self.program.source,
name,
config,
moq_net::track::Delay::default().with_min(None).with_max(self.budget()),
)?
.map(|s| at_edge(s, self.program.replay))
{
Some(source) => Track::new(source, kind.clone()),
None => continue,
},
None => {
match ExportSource::for_audio(&self.program.source, name, config, subscribed(self.program.delay))?
.map(|s| at_edge(skipping(s, self.program.delay), self.program.replay))
{
Some(source) => Track::new(source, kind.clone()),
None => continue,
}
}
};
track.buffer = Some(audio_buffer(config, &kind));
track.kind = kind;
Expand All @@ -2635,11 +2631,10 @@ where
Some(track) => track,
None => Track::new(
stream_edge(
ExportSource::for_stream(
&self.program.source,
name,
moq_net::track::Delay::default().with_min(None).with_max(self.budget()),
)?,
skipping(
ExportSource::for_stream(&self.program.source, name, subscribed(self.program.delay))?,
self.program.delay,
),
&kind,
self.program.replay,
),
Expand Down Expand Up @@ -2681,38 +2676,24 @@ where
/// old one stopped, so its first frame counts as a skip: late frames drop, and a leap
/// ahead opens a new generation.
fn resubscribe(&mut self, catalog: &Catalog<S::Ext>, mpegts: &catalog::Mpegts) -> Result<()> {
let budget = self.budget();
let delay = self.program.delay;
for (name, track) in self.program.tracks.iter_mut() {
if track.read != Read::Stale {
continue;
}
let source = if let Some(config) = catalog.video.renditions.get(name) {
ExportSource::for_video(
&self.program.source,
name,
config,
moq_net::track::Delay::default().with_min(None).with_max(budget),
)?
.map(|s| at_edge(s, self.program.replay))
ExportSource::for_video(&self.program.source, name, config, subscribed(delay))?
.map(|s| at_edge(skipping(s, delay), self.program.replay))
} else if let Some(config) = catalog.audio.renditions.get(name) {
ExportSource::for_audio(
&self.program.source,
name,
config,
moq_net::track::Delay::default().with_min(None).with_max(budget),
)?
.map(|s| at_edge(s, self.program.replay))
ExportSource::for_audio(&self.program.source, name, config, subscribed(delay))?
.map(|s| at_edge(skipping(s, delay), self.program.replay))
} else if mpegts
.tracks
.get(name)
.is_some_and(|t| t.verbatim.is_some() || t.pes_packet.is_some())
{
let source = ExportSource::for_stream(
&self.program.source,
name,
moq_net::track::Delay::default().with_min(None).with_max(budget),
)?;
Some(stream_edge(source, &track.kind, self.program.replay))
let source = ExportSource::for_stream(&self.program.source, name, subscribed(delay))?;
Some(stream_edge(skipping(source, delay), &track.kind, self.program.replay))
} else {
None
};
Expand All @@ -2739,29 +2720,21 @@ where
/// source continues the old one ([`ExportSource::continuing`]), and the frames the old one
/// left held for their DTS go out first.
fn rebind(&mut self, catalog: &Catalog<S::Ext>) -> Result<()> {
let budget = self.budget();
let delay = self.program.delay;
for (name, track) in self.program.tracks.iter_mut().filter(|(_, track)| track.listed) {
let (source, kind) = if let Some(config) = catalog.video.renditions.get(name) {
if track.source.reads(&self.program.source, name, config) {
continue;
}
let source = ExportSource::for_video(
&self.program.source,
name,
config,
moq_net::track::Delay::default().with_min(None).with_max(budget),
)?;
let source = ExportSource::for_video(&self.program.source, name, config, subscribed(delay))?
.map(|s| skipping(s, delay));
(source, video_kind(config, name)?)
} else if let Some(config) = catalog.audio.renditions.get(name) {
if track.source.reads(&self.program.source, name, config) {
continue;
}
let source = ExportSource::for_audio(
&self.program.source,
name,
config,
moq_net::track::Delay::default().with_min(None).with_max(budget),
)?;
let source = ExportSource::for_audio(&self.program.source, name, config, subscribed(delay))?
.map(|s| skipping(s, delay));
(source, audio_kind(config, name)?)
} else {
continue;
Expand Down Expand Up @@ -3969,10 +3942,8 @@ where
Ok(())
}

/// How far a stalled group may fall behind the newest content before each source skips it:
/// half the delay. A skip comes once the next group's start is that far behind, and its
/// frames are only read then, so with the whole delay they would arrive at their deadline.
/// Sources state it with no min delay, so a missing group is waited for it too.
/// Half the delay: how long a PES of packed frames may span, and how far a padded output may
/// fall behind before it sheds.
fn budget(&self) -> Duration {
self.program.delay / 2
}
Expand Down Expand Up @@ -4575,6 +4546,21 @@ fn video_kind(config: &VideoConfig, name: &str) -> Result<Kind> {
}
}

/// The delay a track subscription states for an export running `delay` behind: all of it, as both
/// bounds, so a relay resets a group only once it is that old.
pub(super) fn subscribed(delay: Duration) -> moq_net::track::Delay {
moq_net::track::Delay::default().with_min(delay).with_max(delay)
}

/// Skip a stalled group once the group after it runs `delay` past it, and wait that long for a
/// missing one, so a stall shorter than the delay loses nothing. The reader delivers in order, so a
/// group whose tail never arrives holds the next one for the whole delay, and the next group's
/// first frames go out late. No min, unlike [`subscribed`], so a live start begins at the newest
/// group rather than reach back the delay.
pub(super) fn skipping(source: ExportSource, delay: Duration) -> ExportSource {
source.skipping_at(moq_net::track::Delay::default().with_min(None).with_max(delay))
}

/// Start a media track's source at the live edge, the newest group, so the export does not
/// begin on a group up to a delay old and carry that lag ever after; unless `replay`.
/// Verbatim streams are sparse, and anything of theirs ahead of the first keyframe is
Expand Down
Loading