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: 1 addition & 1 deletion dart/moq/lib/src/aliases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Subscription defaultSubscription() => Subscription._(moqSubscriptionDefaults());
/// A span of a track to deliver: from `start` up to `end`, or onward when `end` is null.
typedef Range = MoqRange;

/// Where one end of a [Range] falls: absolute, relative to the latest group, or the group containing a time.
/// Where one end of a [Range] falls: the oldest group (a start only), absolute, relative to the latest group, or the group containing a time.
typedef Anchor = MoqAnchor;

/// Which pending group the publisher sends first.
Expand Down
36 changes: 36 additions & 0 deletions dart/moq_ffi/lib/src/moq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import "dart:ffi";
import "dart:io" show Platform, File, Directory;
import "dart:isolate";
import "dart:typed_data";

import "package:ffi/ffi.dart";

import "uniffi_runtime.dart";
export "uniffi_runtime.dart";

Expand Down Expand Up @@ -5506,6 +5508,12 @@ class FfiConverterMoqAnchor {
lifted.value,
lifted.bytesRead - subview.offsetInBytes + 4,
);
case 4:
final lifted = OldestMoqAnchor.read(subview);
return LiftRetVal<MoqAnchor>(
lifted.value,
lifted.bytesRead - subview.offsetInBytes + 4,
);
default:
throw UniffiInternalError(
UniffiInternalError.unexpectedEnumCase,
Expand Down Expand Up @@ -5641,6 +5649,34 @@ class TimeMoqAnchor extends MoqAnchor {
}
}

class OldestMoqAnchor extends MoqAnchor {
OldestMoqAnchor();
OldestMoqAnchor._();
static LiftRetVal<OldestMoqAnchor> read(Uint8List buf) {
int new_offset = buf.offsetInBytes;
return LiftRetVal(OldestMoqAnchor._(), new_offset);
}

@override
RustBuffer lower() {
final buf = Uint8List(allocationSize());
write(buf);
return toRustBuffer(buf);
}

@override
int allocationSize() {
return 4;
}

@override
int write(Uint8List buf) {
buf.buffer.asByteData(buf.offsetInBytes).setInt32(0, 4);
int new_offset = buf.offsetInBytes + 4;
return new_offset;
}
}

enum MoqOrder { ascending, descending }

class FfiConverterMoqOrder {
Expand Down
4 changes: 3 additions & 1 deletion go/wrapper/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ type (
// A relative start is the first frame of its group, a relative end includes its whole
// group, and an absolute end is exclusive.
Range = ffi.MoqRange
// Anchor is where one end of a Range falls: AnchorAbsolute, AnchorRelative, or AnchorTime.
// Anchor is where one end of a Range falls: AnchorOldest, AnchorAbsolute, AnchorRelative, or AnchorTime.
Anchor = ffi.MoqAnchor
// AnchorOldest is the oldest group still around, as far back as the max delay allows. A start only.
AnchorOldest = ffi.MoqAnchorOldest
// AnchorAbsolute is a group, delivered from its first frame.
AnchorAbsolute = ffi.MoqAnchorAbsolute
// AnchorRelative is the group Groups before the latest one, clamped to group 0: 0 is the latest.
Expand Down
8 changes: 7 additions & 1 deletion kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Aliases.kt
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,15 @@ fun uniffi.moq.MoqSubscription.Companion.default(): Subscription =
/** A span of a track to deliver: from `start` up to `end`, or onward when `end` is null. */
typealias Range = uniffi.moq.MoqRange

/** Where one end of a [Range] falls: [AnchorAbsolute], [AnchorRelative], or [AnchorTime]. */
/**
* Where one end of a [Range] falls: [AnchorOldest], [AnchorAbsolute], [AnchorRelative], or
* [AnchorTime].
*/
typealias Anchor = uniffi.moq.MoqAnchor

/** The oldest group still around, as far back as the max delay allows. A start only. */
typealias AnchorOldest = uniffi.moq.MoqAnchor.Oldest
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

/** A group, delivered from its first frame. */
typealias AnchorAbsolute = uniffi.moq.MoqAnchor.Absolute

Expand Down
16 changes: 13 additions & 3 deletions py/moq-rs/moq/_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,28 @@ def _from_ffi(datagram: MoqDatagram) -> Datagram:
class Anchor:
"""Where one end of a :class:`Range` falls, mirroring moq-net's ``track::Anchor``.

Build one with ``Anchor.ABSOLUTE(group=...)``, ``Anchor.RELATIVE(groups=...)``, or
``Anchor.TIME(timestamp=...)``.
Build one with ``Anchor.OLDEST()``, ``Anchor.ABSOLUTE(group=...)``,
``Anchor.RELATIVE(groups=...)``, or ``Anchor.TIME(timestamp=...)``.
"""

OLDEST: ClassVar[type[_AnchorOldest]]
ABSOLUTE: ClassVar[type[_AnchorAbsolute]]
RELATIVE: ClassVar[type[_AnchorRelative]]
TIME: ClassVar[type[_AnchorTime]]

def _ffi(self) -> MoqAnchor:
raise TypeError("build an Anchor with Anchor.ABSOLUTE, Anchor.RELATIVE, or Anchor.TIME")
raise TypeError("build an Anchor with Anchor.OLDEST, Anchor.ABSOLUTE, Anchor.RELATIVE, or Anchor.TIME")


# The generated variants subclass MoqAnchor only at runtime, so each _ffi casts for pyright.
@dataclass(frozen=True)
class _AnchorOldest(Anchor):
"""The oldest group still around, as far back as the max delay allows. A start only."""

def _ffi(self) -> MoqAnchor:
return cast(MoqAnchor, MoqAnchor.OLDEST())


@dataclass(frozen=True)
class _AnchorAbsolute(Anchor):
"""This group, delivered from its first frame."""
Expand Down Expand Up @@ -185,6 +194,7 @@ def _ffi(self) -> MoqAnchor:
return cast(MoqAnchor, MoqAnchor.TIME(timestamp=self.timestamp._ffi()))


Anchor.OLDEST = _AnchorOldest
Anchor.ABSOLUTE = _AnchorAbsolute
Anchor.RELATIVE = _AnchorRelative
Anchor.TIME = _AnchorTime
Expand Down
1 change: 0 additions & 1 deletion quest/m2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ quests that require them.
- [Small API fixes before the cut](/quest/m2/api-shape/README.md) - one path and one spelling per item, names by role, and no dead or wrong-role public surface across net, transport, media, native, apps, JS, and bindings
- [MoQ on rind](/quest/m1/rind/README.md) - every MoQ crate takes its crypto from rind, a pure-Rust graviola fork, so no build compiles C crypto (held in m1 by an open claim)
- [A recreated or restarted track cannot reuse group sequences](/quest/m2/sequence-reuse.md) - recreating a track or restarting an instance cannot give new content an old group identity unless the app seeds past it, and datagrams are documented as exempt
- [Subscriptions name the oldest group without a u64::MAX sentinel](/quest/m2/anchor-oldest.md) - `Anchor` gets an explicit oldest variant, decoded the same way on every wire
- [moq auth serve bounds what a leaked token or public caller can do](/quest/m2/auth-serve-policy.md) - tokens need an `exp` unless the operator opts out, and a public listener authenticates relays
- [Cut readiness](/quest/m2/cut-gate/README.md) - the checks the cut needs that break nothing: main no slower than release, vendored fixes ported, and moq-c at parity
- [Probe](/quest/m2/probe/README.md) - a session probes up to the bitrate it wants to send or receive, so a stopped simulcast rendition resumes and a viewer up-switches; browser padding is parked in m3 (held in m2 by open claims; moves to m3)
Expand Down
13 changes: 0 additions & 13 deletions quest/m2/anchor-oldest.md

This file was deleted.

1 change: 1 addition & 0 deletions rs/moq-c/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const ENUMS: &[&str] = &[
"moq_protocol_kind",
"moq_demand",
"moq_decode_start",
"moq_anchor_kind",
];

fn main() {
Expand Down
3 changes: 3 additions & 0 deletions rs/moq-c/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,8 @@ pub enum moq_anchor_kind {
MOQ_ANCHOR_RELATIVE = 1,
/// The group containing a presentation time. An untimed track refuses it.
MOQ_ANCHOR_TIME = 2,
/// The oldest group still around, as far back as `delay.max_us` allows. A start only.
MOQ_ANCHOR_OLDEST = 3,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

/// Which of a subscription's pending groups the publisher sends first. Zero is the default.
Expand All @@ -848,6 +850,7 @@ fn parse_anchor(anchor: &moq_anchor) -> Result<moq_net::track::Anchor, Error> {
v if v == moq_anchor_kind::MOQ_ANCHOR_ABSOLUTE as u32 => moq_net::track::Anchor::Absolute(anchor.group),
v if v == moq_anchor_kind::MOQ_ANCHOR_RELATIVE as u32 => moq_net::track::Anchor::Relative(anchor.group),
v if v == moq_anchor_kind::MOQ_ANCHOR_TIME as u32 => moq_net::track::Anchor::Time(anchor.timestamp.try_into()?),
v if v == moq_anchor_kind::MOQ_ANCHOR_OLDEST as u32 => moq_net::track::Anchor::Oldest,
_ => return Err(Error::InvalidCode),
})
}
Expand Down
3 changes: 3 additions & 0 deletions rs/moq-ffi/src/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub enum MoqAnchor {
/// The presentation time.
timestamp: MoqTimestamp,
},
/// The oldest group still around, as far back as the max delay allows. A start only.
Oldest,
}

/// Which of a subscription's pending groups the publisher sends first, mirroring
Expand All @@ -143,6 +145,7 @@ impl TryFrom<MoqAnchor> for moq_net::track::Anchor {

fn try_from(anchor: MoqAnchor) -> Result<Self, MoqError> {
Ok(match anchor {
MoqAnchor::Oldest => Self::Oldest,
MoqAnchor::Absolute { group } => Self::Absolute(group),
MoqAnchor::Relative { groups } => Self::Relative(groups),
MoqAnchor::Time { timestamp } => Self::Time(timestamp.try_into()?),
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-net/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ pub enum Error {
#[error("invalid joining request ID")]
InvalidJoiningRequestId,

/// A FETCH range is empty or lies beyond the published objects.
/// A range is empty, lies beyond the published objects, or ends at the oldest group.
#[error("invalid fetch range")]
InvalidRange,

Expand Down
5 changes: 2 additions & 3 deletions rs/moq-net/src/ietf/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14233,9 +14233,8 @@ fn has_time(subscription: &track::Subscription) -> bool {
fn needs_resolution(subscription: &track::Subscription) -> bool {
subscription.ranges.iter().any(|range| {
let start = match range.start {
track::Anchor::Absolute(_) => false,
track::Anchor::Relative(back) => back != 0 && back != u64::MAX,
track::Anchor::Time(_) => true,
track::Anchor::Oldest | track::Anchor::Absolute(_) | track::Anchor::Relative(0) => false,
track::Anchor::Relative(_) | track::Anchor::Time(_) => true,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
};
start || matches!(range.end, Some(track::Anchor::Time(_) | track::Anchor::Relative(_)))
})
Expand Down
21 changes: 15 additions & 6 deletions rs/moq-net/src/lite/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{

use crate::{
Error, Path, Timescale, Timestamp, bandwidth,
coding::{Decode as _, Reader, Stream, varint::MAX_QUIC},
coding::{Decode as _, Reader, Stream},
lite,
track::{Anchor, Position, Subscription},
};
Expand Down Expand Up @@ -7710,6 +7710,17 @@ mod tests {
..Default::default()
};
assert!(matches!(wire_ranges(&timed, None), Err(Error::TimestampMismatch)));

// Only the oldest start goes out without an anchor; any count back stays one.
let start = |start| {
let subscription = Subscription::default().with_ranges([track::Range { start, end: None }]);
wire_ranges(&subscription, None).unwrap().unwrap()[0].start
};
assert_eq!(start(Anchor::Oldest), None);
assert_eq!(
start(Anchor::Relative(u64::MAX)),
Some(lite::Anchor::Relative(u64::MAX))
);
}

/// A wire without ranges asks from group 0 when no single start covers both a count
Expand Down Expand Up @@ -9319,9 +9330,7 @@ fn wire_ranges(subscription: &Subscription, timescale: Option<Timescale>) -> Res
continue;
}
let start = match range.start {
// Past the varint's reach, a count back clamps to group 0 just as the oldest
// start does, which only that start can spell.
Anchor::Relative(back) if back > MAX_QUIC => None,
Anchor::Oldest => None,
Anchor::Relative(back) => Some(lite::Anchor::Relative(back)),
Anchor::Absolute(group) => Some(lite::Anchor::Absolute(Position::group(group))),
Anchor::Time(pts) => Some(time(pts)?),
Expand All @@ -9331,7 +9340,7 @@ fn wire_ranges(subscription: &Subscription, timescale: Option<Timescale>) -> Res
// nothing names a resolved end, so one resolved upstream would leave the copy short.
let end = match range.end {
Some(Anchor::Absolute(group)) => Some(lite::Anchor::Absolute(Position::group(group))),
None | Some(Anchor::Relative(_) | Anchor::Time(_)) => None,
None | Some(Anchor::Oldest | Anchor::Relative(_) | Anchor::Time(_)) => None,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
};
ranges.push(lite::Range { start, end });
}
Expand Down Expand Up @@ -10144,7 +10153,7 @@ impl TrackServe {
|| subscription
.ranges
.iter()
.all(|range| range.end.is_none() && matches!(range.start, Anchor::Relative(0 | u64::MAX))));
.all(|range| range.end.is_none() && matches!(range.start, Anchor::Oldest | Anchor::Relative(0))));
if opening && idle {
subscription = subscription.with_start(newest);
}
Expand Down
67 changes: 58 additions & 9 deletions rs/moq-net/src/model/resume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,9 +1108,7 @@ impl Reader {
let end = previous.and_then(|previous| previous.end).or(resolved.end);
track::Range {
start: match range.start {
// The farthest offset reaches back to the oldest group, which names no floor.
Anchor::Relative(back) if back != u64::MAX => Anchor::Absolute(start),
Anchor::Time(_) => Anchor::Absolute(start),
Anchor::Relative(_) | Anchor::Time(_) => Anchor::Absolute(start),
start => start,
},
// A time end the copy has not settled stays one: its cap is not the end.
Expand Down Expand Up @@ -1317,6 +1315,20 @@ impl Reader {
}
}

/// Why the reader can read nothing more: copies contradicted the track's end, or its
/// ranges hold an [`Anchor::Oldest`] end. That end is refused here, before waiting on a
/// copy to refuse it, since the demand asked upstream leaves it out.
fn refusal(&self) -> Option<Error> {
if self.refused {
return Some(Error::ProtocolViolation);
}
self.mirrored
.ranges
.iter()
.any(|range| range.end == Some(Anchor::Oldest))
.then_some(Error::InvalidRange)
}

/// Whether `at` is past the declared end, which refuses the track: another copy
/// contradicts the copy that declared it.
fn past_end(&mut self, at: Position) -> bool {
Expand Down Expand Up @@ -1497,8 +1509,8 @@ impl Reader {
waiter: &kio::Waiter,
) -> Option<Poll<Result<Option<Candidate>>>> {
self.sync(waiter);
if self.refused {
return Some(Poll::Ready(Err(Error::ProtocolViolation)));
if let Some(err) = self.refusal() {
return Some(Poll::Ready(Err(err)));
}
self.groups_read = true;
self.backfill_gaps(delivered);
Expand Down Expand Up @@ -1706,8 +1718,8 @@ impl Reader {
loop {
self.sync(waiter);
self.learn_end(Some(waiter));
if self.refused {
return Poll::Ready(Err(Error::ProtocolViolation));
if let Some(err) = self.refusal() {
return Poll::Ready(Err(err));
}
if let Some(end) = self.declared {
return Poll::Ready(Ok(end));
Expand Down Expand Up @@ -2186,8 +2198,8 @@ impl Recover {
if let Some(reader) = self.reader.as_ref().and_then(Weak::upgrade) {
let mut reader = reader.lock().unwrap_or_else(PoisonError::into_inner);
reader.sync(waiter);
if reader.refused {
return Poll::Ready(Err(Error::ProtocolViolation));
if let Some(err) = reader.refusal() {
return Poll::Ready(Err(err));
}
}
loop {
Expand Down Expand Up @@ -7044,6 +7056,43 @@ mod test {
assert_eq!(sub.floor(), Some(0));
}

/// No hop can place an oldest end: a routed reader refuses it, with or without a copy,
/// rather than its own window panicking on it.
#[test]
#[cfg(feature = "async")]
fn a_routed_reader_refuses_an_oldest_end() {
for served in [true, false] {
a_routed_reader_refuses_an_oldest_end_when(served);
}
}

#[cfg(feature = "async")]
fn a_routed_reader_refuses_an_oldest_end_when(served: bool) {
let routes = Producer::new();
let logical = logical(&routes);
let a = copy();
write(&a, 0);
if served {
routes.serve(a.consume());
}
let subscription = Subscription::default().with_ranges([track::Range {
start: Anchor::Absolute(0),
end: Some(Anchor::Oldest),
}]);
let mut sub = logical
.consume()
.subscribe(subscription)
.now_or_never()
.unwrap()
.unwrap();
let result = sub.poll_recv_group(&kio::Waiter::noop());
assert!(
matches!(result, Poll::Ready(Err(Error::InvalidRange))),
"served={served}: {:?}",
result.map(|r| r.map(|g| g.map(|g| g.sequence)))
);
}

/// A time end resolves on the serving copy even when the start is already absolute.
#[test]
#[cfg(feature = "async")]
Expand Down
Loading
Loading