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
2 changes: 2 additions & 0 deletions js/hang/api/container.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export interface ConsumerProps {
warmup?: Net.Clock.Duration;
}

export const DELAY_MAX: Net.Clock.Duration;

export interface Format {
decode(payload: Uint8Array, timestamp: Net.Time.Timestamp | undefined): Frame[];
end?(frame: Frame): Net.Clock.Duration | undefined;
Expand Down
8 changes: 7 additions & 1 deletion js/hang/src/container/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import type { Format } from "./format";
import { Jitter } from "./jitter";
import type { BufferedRanges, Frame, ReceivedFrame } from "./types";

/**
* The longest playout delay: it caps a reader's latency and how far catalog `warmup` reaches back,
* so a publisher cannot hold a reader's media without bound. Mirrors `moq_mux::container::DELAY_MAX`.
*/
export const DELAY_MAX = Duration.secs(10);

/** Options for constructing a {@link Consumer}. */
export interface ConsumerProps {
/** The container format used to decode each MoQ frame. */
Expand Down Expand Up @@ -259,7 +265,7 @@ export class Consumer {
this.#delay = getter(props.delay ?? {});
this.#wait = getter(props.wait);
this.#maxBuffer = props.maxBuffer ?? DEFAULT_MAX_BUFFER;
this.#warmup = props.warmup ?? Duration.ZERO;
this.#warmup = (props.warmup ?? Duration.ZERO).min(DELAY_MAX);
this.#jitter = props.predecessor ? props.predecessor.#jitter.fork() : new Jitter();
this.#spread = new Signal(Duration.millis(this.#jitter.measured));
this.spread = this.#spread;
Expand Down
2 changes: 1 addition & 1 deletion js/hang/src/container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/** Re-export of {@link https://www.npmjs.com/package/@moq/loc | @moq/loc}, the LOC container. */
export * as Loc from "@moq/loc";
export { Consumer, type ConsumerProps, type Read } from "./consumer";
export { Consumer, type ConsumerProps, DELAY_MAX, type Read } from "./consumer";
export type { Format } from "./format";
/** The legacy varint container. */
export * as Legacy from "./legacy";
Expand Down
9 changes: 3 additions & 6 deletions js/watch/src/sync.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Duration, Instant, now, sleep } from "@moq/clock";
import { Container } from "@moq/hang";
import { Derived, Effect, type Getter, getter, type Inputs, type Readonlys, readonlys, Signal } from "@moq/signals";

/**
Expand All @@ -18,12 +19,8 @@ export type Delay = "instant" | "auto" | Duration;
/** The default {@link SyncInput.stretch}: how far live audio may trail the clock before it skips. @internal */
export const STRETCH = Duration.secs(2);

/**
* The most an `"auto"` delay holds. The publisher advertises the jitter and delay it is measured
* from, so the clock bounds them here, whatever the catalog says. Matches
* `moq_audio::playback::Input::LATENCY_MAX`, which bounds `moq play`'s `--delay`. @internal
*/
export const DELAY_MAX = Duration.secs(10);
/** The most an `"auto"` delay holds, and how far catalog `warmup` reaches back. @internal */
export const DELAY_MAX = Container.DELAY_MAX;

/** Signals the sync reads. */
export type SyncInput = {
Expand Down
34 changes: 0 additions & 34 deletions quest/m1/audio-jitter-target/delay-ceiling.md

This file was deleted.

6 changes: 3 additions & 3 deletions rs/moq-audio/src/decode/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl Consumer {
}

let name = name.into();
let warmup = catalog.warmup.unwrap_or_default().min(moq_mux::container::WARMUP_MAX);
let warmup = catalog.warmup.unwrap_or_default().min(moq_mux::container::DELAY_MAX);
let playout = moq_mux::container::Playout::new(options.delay, warmup);
let track = broadcast.track(hang::catalog::Reference::track(catalog, &name))?;
// The whole delay from the start, as the container keeps it: the transport enforces the
Expand Down Expand Up @@ -1378,7 +1378,7 @@ mod tests {
moq_mux::catalog::hang::Container::Legacy(moq_mux::container::Kind::Audio),
);
producer.seek(1).unwrap();
let ceiling = moq_mux::container::WARMUP_MAX.as_micros() as u64;
let ceiling = moq_mux::container::DELAY_MAX.as_micros() as u64;
// Contiguous, so no gap re-arms the warmup.
for micros in (0..=ceiling).step_by(20_000) {
producer
Expand All @@ -1394,7 +1394,7 @@ mod tests {
let _finished = producer.finish().unwrap();
let options = Options {
delay: Delay {
max: Some(moq_mux::container::WARMUP_MAX),
max: Some(moq_mux::container::DELAY_MAX),
..Delay::default()
},
..Options::new()
Expand Down
18 changes: 6 additions & 12 deletions rs/moq-audio/src/playback/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ impl Default for Input {
}

impl Input {
/// The longest [`latency`](Self::latency) a sink accepts. Well past any
/// playout delay worth presenting, and it bounds the ring the device thread
/// walks. Public so a caller taking the depth from its own configuration can
/// refuse an impossible one before it opens a device.
pub const LATENCY_MAX: Duration = Duration::from_secs(10);

fn validate(&self) -> Result<(), Error> {
if self.sample_rate == 0 {
return Err(Error::Unsupported("sample rate must be > 0".into()));
Expand All @@ -87,10 +81,10 @@ impl Input {
self.layout
)));
}
if self.latency.is_zero() || self.latency > Self::LATENCY_MAX {
if self.latency.is_zero() || self.latency > moq_mux::container::DELAY_MAX {
return Err(Error::Unsupported(format!(
"playback latency must be non-zero and at most {:?} (got {:?})",
Self::LATENCY_MAX,
moq_mux::container::DELAY_MAX,
self.latency
)));
}
Expand Down Expand Up @@ -261,7 +255,7 @@ impl Sink {
/// what it holds runs short of it, and speeds up past it only to catch up
/// with the clock [`due`](Self::due) anchors it to.
///
/// Must be non-zero, at most [`Input::LATENCY_MAX`], and fit in the current
/// Must be non-zero, at most [`moq_mux::container::DELAY_MAX`], and fit in the current
/// ring. Each device open or rebuild allocates the then-current target plus
/// three seconds, less a 30 ms processing window reserved as headroom.
/// Does not resize or reset the device.
Expand Down Expand Up @@ -980,7 +974,7 @@ mod tests {
/// device could ever drain is a delay nobody asked for.
#[test]
fn rejects_a_latency_it_cannot_buffer() {
for latency in [Duration::ZERO, Input::LATENCY_MAX + Duration::from_secs(1)] {
for latency in [Duration::ZERO, moq_mux::container::DELAY_MAX + Duration::from_secs(1)] {
let input = Input {
latency,
..Default::default()
Expand All @@ -989,7 +983,7 @@ mod tests {
}

Input {
latency: Input::LATENCY_MAX,
latency: moq_mux::container::DELAY_MAX,
..Default::default()
}
.validate()
Expand All @@ -1006,7 +1000,7 @@ mod tests {
for latency in [
Duration::ZERO,
Duration::from_secs(4),
Input::LATENCY_MAX + Duration::from_secs(1),
moq_mux::container::DELAY_MAX + Duration::from_secs(1),
] {
assert!(sink.set_latency(latency).is_err());
assert_eq!(sink.input().latency, LATENCY);
Expand Down
12 changes: 1 addition & 11 deletions rs/moq-cli/src/play/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ use moq_mux::catalog::CatalogFormat;

use crate::subscribe::{CatalogFormatArg, Mode, SelectArgs};

/// The longest delay the speaker can hold, which is what bounds `--delay`.
///
/// Duplicated from `moq_audio::playback::Input::LATENCY_MAX` because this module
/// compiles without the `play` feature, and so without that crate. The test
/// below pins the two together in a build that has both.
const DELAY_MAX: Duration = Duration::from_secs(10);
use moq_mux::container::DELAY_MAX;

/// How far playback trails the live edge under `auto` while audio holds no
/// estimate, as when there is none: video has no estimator of its own.
Expand Down Expand Up @@ -307,11 +302,6 @@ mod tests {
assert!(err.contains("--delay must be at most"), "{err}");
parse(&["--delay", "10s"]).validate().unwrap();
parse(&["--delay", "auto"]).validate().unwrap();

// The bound has to be the sink's own, which only a build carrying the sink
// can say.
#[cfg(feature = "play")]
assert_eq!(DELAY_MAX, moq_audio::playback::Input::LATENCY_MAX);
}

/// The suffix picks the format, and the flag overrides it.
Expand Down
14 changes: 7 additions & 7 deletions rs/moq-cli/src/play/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl<O: Output> Media<O> {
// An intra-refresh rendition also runs a decoder with one more sweep
// of budget, joining a group earlier so its pictures stay clean, as
// `moq_video::decode::Consumer` does. Both share one upstream request.
let warmup = config.warmup.unwrap_or_default().min(moq_mux::container::WARMUP_MAX);
let warmup = config.warmup.unwrap_or_default().min(moq_mux::container::DELAY_MAX);
let refresh = if warmup.is_zero() {
None
} else {
Expand Down Expand Up @@ -531,7 +531,7 @@ impl Demand {
// playback retain media without bound.
let delay = delay
.filter(|_| args.fixed_delay().is_none())
.map(|delay| delay.min(moq_audio::playback::Input::LATENCY_MAX));
.map(|delay| delay.min(moq_mux::container::DELAY_MAX));
self.delay.send_if_modified(|held| {
let raised = delay > *held;
if raised {
Expand Down Expand Up @@ -635,7 +635,7 @@ async fn play_audio<O: Output>(
let cap = max_delay
.max(AUDIO_BUFFER_MIN)
.min(latency + SINK_ROOM)
.min(moq_audio::playback::Input::LATENCY_MAX);
.min(moq_mux::container::DELAY_MAX);

// The longest hole worth playing through, in samples. A hole this player would
// rather sit through is one it is already willing to buffer, which is what the
Expand Down Expand Up @@ -719,7 +719,7 @@ async fn play_audio<O: Output>(
// The jitter target and the catalog delay are each capped, and so is their sum,
// so one ceiling bounds the clock however the publisher splits its advertisement.
let capped = |jitter: Duration, delay: Option<Duration>| {
(jitter + delay.unwrap_or_default()).min(moq_audio::playback::Input::LATENCY_MAX)
(jitter + delay.unwrap_or_default()).min(moq_mux::container::DELAY_MAX)
};
let retarget = |delay: Option<Duration>| {
let Some(jitter) = *jitter.lock().unwrap() else { return };
Expand Down Expand Up @@ -1011,7 +1011,7 @@ async fn play_audio<O: Output>(
// make playback retain media without bound.
let held = latency
.max(delay.max(AUDIO_BUFFER_MIN))
.min(moq_audio::playback::Input::LATENCY_MAX);
.min(moq_mux::container::DELAY_MAX);
*jitter.lock().unwrap() = Some(held);
moved |= role.set_target(capped(held, *stated.borrow()));
// The consumer releases media due further out than the sink holds only
Expand Down Expand Up @@ -1246,7 +1246,7 @@ mod tests {
/// jitter's, holds the clock at that depth instead.
#[tokio::test]
async fn audio_caps_a_target_past_the_deepest_delay() {
let latency = moq_audio::playback::Input::LATENCY_MAX;
let latency = moq_mux::container::DELAY_MAX;
assert_on_time(
first_sound(Duration::from_secs(20), Duration::from_secs(5), None, None).await,
latency,
Expand All @@ -1257,7 +1257,7 @@ mod tests {
/// one ceiling, the same the browser holds.
#[tokio::test]
async fn audio_caps_a_target_plus_catalog_delay_at_the_deepest_delay() {
let latency = moq_audio::playback::Input::LATENCY_MAX;
let latency = moq_mux::container::DELAY_MAX;
let hour = Duration::from_secs(3600);
assert_on_time(first_sound(latency, latency, Some(hour), None).await, latency);
}
Expand Down
4 changes: 2 additions & 2 deletions rs/moq-gst/src/source/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ impl OpusClip {
.unwrap_or(0);
// Rounded up, so presentation never starts inside the warmup. Capped like the delay it widens,
// so an advertised warmup can't hold playback silent past the ceiling.
let warmup = warmup.min(moq_mux::container::WARMUP_MAX);
let warmup = warmup.min(moq_mux::container::DELAY_MAX);
let warmup = u64::try_from((warmup.as_nanos() * 48_000).div_ceil(1_000_000_000)).unwrap_or(u64::MAX);
(total > 0 || warmup > 0).then_some(Self {
total,
Expand Down Expand Up @@ -2436,7 +2436,7 @@ mod tests {
let hour = super::OpusClip::new(&bare, Duration::from_secs(3600)).unwrap();
assert_eq!(
hour.warmup,
moq_mux::container::WARMUP_MAX.as_secs() * 48_000,
moq_mux::container::DELAY_MAX.as_secs() * 48_000,
"an hour of warmup clips only up to the ceiling"
);

Expand Down
14 changes: 7 additions & 7 deletions rs/moq-mux/src/container/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ pub struct Playout {
pub warmup: std::time::Duration,
}

/// The most catalog `warmup` a reader reaches back for, so a publisher cannot hold a reader's media
/// without bound. Matches `moq_audio::playback::Input::LATENCY_MAX` and `@moq/watch`'s cap.
pub const WARMUP_MAX: std::time::Duration = std::time::Duration::from_secs(10);
/// The longest playout delay: it caps a reader's latency and how far catalog `warmup` reaches back,
/// so a publisher cannot hold a reader's media without bound. Mirrored by `@moq/hang`'s `DELAY_MAX`.
pub const DELAY_MAX: std::time::Duration = std::time::Duration::from_secs(10);

impl Playout {
/// Play at `delay`, starting `warmup` further back.
Expand Down Expand Up @@ -361,9 +361,9 @@ impl Playout {
.with_max(self.delay.max.map(|max| max.saturating_add(self.reach())))
}

/// The warmup, capped at [`WARMUP_MAX`].
/// The warmup, capped at [`DELAY_MAX`].
fn reach(&self) -> std::time::Duration {
self.warmup.min(WARMUP_MAX)
self.warmup.min(DELAY_MAX)
}
}

Expand Down Expand Up @@ -3946,9 +3946,9 @@ mod tests {
);
assert_eq!(
subscribed(&consumer).subscription().delay.max,
Some(Duration::from_millis(200) + WARMUP_MAX)
Some(Duration::from_millis(200) + DELAY_MAX)
);
assert_eq!(consumer.warmup, WARMUP_MAX);
assert_eq!(consumer.warmup, DELAY_MAX);
}

/// An unlimited max delay keeps the subscription unlimited, and the min delay still sets the
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-mux/src/container/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub mod mkv;
pub mod mp4;
pub mod ts;

pub use consumer::{Consumer, Playout, WARMUP_MAX};
pub use consumer::{Consumer, DELAY_MAX, Playout};
pub use group::GroupConsumer;
pub(crate) use input::Input;
pub use producer::{Finished, Guard, Producer};
Expand Down
4 changes: 2 additions & 2 deletions rs/moq-video/src/decode/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl Consumer {
let name = name.into();
let min = Reader::open(broadcast, catalog, &name, &options, options.delay, 0).await?;

let warmup = catalog.warmup.unwrap_or_default().min(moq_mux::container::WARMUP_MAX);
let warmup = catalog.warmup.unwrap_or_default().min(moq_mux::container::DELAY_MAX);
let max = if warmup.is_zero() {
None
} else {
Expand Down Expand Up @@ -1296,7 +1296,7 @@ mod tests {
.unwrap();
assert_eq!(
published.subscription().and_then(|sub| sub.delay.max),
Some(moq_mux::container::WARMUP_MAX)
Some(moq_mux::container::DELAY_MAX)
);
}

Expand Down