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
1 change: 0 additions & 1 deletion quest/m1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ Catalog HLS field.
- [Moxygen minimal interop](/quest/m1/smoke-moxygen.md) - waiting on Moxygen to send a registered filter type, then the smoke lane stops hiding its failure
- [More tests under load](/quest/m1/test-flakes-2/README.md) - the second round of load-only failures, one quest per flake, fixed at the cause
- [Broadcast lifecycle](/quest/m1/broadcast-lifecycle/README.md) - broadcasts are online or offline with no finished state in moq-net, finished-broadcast retention is a fixed moq-mux policy, and each linger timer has one meaning
- [fMP4 passthrough sync start](/quest/m1/fmp4-passthrough-sync.md) - a passthrough video import that starts mid-GOP publishes nothing before its first sync sample
- [A smaller, safer API than release](/quest/m1/api-audit/README.md) - every surface added since release has a consumer or is gone, overlapping operations are collapsed, names mirror across Rust, JS, and the bindings, and every break says how to migrate
- [moq-transport 18 and 22 only](/quest/m1/ietf-drop/README.md) - drafts 14-17 and 19-21 are deleted from Rust, JS, tests, interop lanes, and docs, removing the legacy control-stream adapter and its request limit
- [moq-quic's API improves on quinn's](/quest/m1/quic-api/README.md) - moq-quic and both QUIC drivers ship one mirrored API: `send::`/`recv::` namespaces, one error per direction, consuming terminal operations, plain configs, no quinn baggage
Expand Down
20 changes: 0 additions & 20 deletions quest/m1/fmp4-passthrough-sync.md

This file was deleted.

38 changes: 18 additions & 20 deletions rs/moq-mux/src/container/fmp4/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ struct Fmp4Track<E: crate::catalog::hang::CatalogExt> {
/// The edit list, applied to every sample's presentation time.
edit: Edit,

/// The edit list dropped the last sync sample, so the samples decoding from it go too.
/// No sync sample precedes the next sample, since the import joined mid-GOP or the edit list
/// dropped the last one, so the samples decoding from it go too.
orphaned: bool,

// The decode time of the last fragment, which the next one has to advance past.
Expand Down Expand Up @@ -425,7 +426,8 @@ impl<E: crate::catalog::hang::CatalogExt> Import<E> {
defaults: sample::Defaults::from_moov(&moov, track_id),
timescale,
edit,
orphaned: false,
// Audio samples decode alone, whatever their sync flags say.
orphaned: kind == Kind::Video,
last_decode_time: None,
sample_duration: None,
segment: None,
Expand Down Expand Up @@ -966,7 +968,9 @@ impl<E: crate::catalog::hang::CatalogExt> Import<E> {
None => return Err(Error::UnknownTrack(track_id).into()),
};

// A fragment wholly before the edit, such as one holding only priming samples.
// A fragment wholly before the edit or the first sync sample, such as priming samples or
// a mid-GOP join. Skipped before the segment is counted as opened, or the next keyframe
// would roll a second segment.
let Some(run) = track.run(traf, moof_size, header_size, payload.len())? else {
continue;
};
Expand All @@ -988,19 +992,14 @@ impl<E: crate::catalog::hang::CatalogExt> Import<E> {
declared: new_segment && self.declared,
};

let opened = match &mut track.output {
match &mut track.output {
Output::Passthrough(passthrough) => {
let fragment = fragment(traf, &moof, &run, &payload, &track.defaults)?;
passthrough.write(fragment, &run, track.kind, placement)?;
true
}
output => unwrap(output, &run, &payload, track.timescale, placement)?,
};
// A video track joined mid-GOP skips samples until a sync sample, so its segment opens
// there; counting a skipped fragment would let the next keyframe roll a second segment.
if opened {
track.segment = Some(self.segment);
}
track.segment = Some(self.segment);
}

Ok(())
Expand Down Expand Up @@ -1359,15 +1358,13 @@ impl<E: crate::catalog::hang::CatalogExt> Passthrough<E> {
}

/// Write each sample of `run` as its own frame on an unwrapped track.
///
/// Returns whether the track now has a group open, which video lacks until its first sync sample.
fn unwrap<E: crate::catalog::hang::CatalogExt>(
output: &mut Output<E>,
run: &Run,
payload: &Bytes,
timescale: moq_net::Timescale,
placement: Placement,
) -> Result<bool> {
) -> Result<()> {
let earliest = placement.offset.apply(run.earliest)?;
let end = placement.offset.apply(run.end)?;
let video = matches!(output, Output::Video(_));
Expand Down Expand Up @@ -1398,16 +1395,12 @@ fn unwrap<E: crate::catalog::hang::CatalogExt>(
.map(|duration| Timestamp::new(duration as u64, timescale))
.transpose()?,
};
match producer.write(frame) {
// A source joined mid-GOP: skip ahead to the first sync sample.
Ok(()) | Err(crate::Error::MissingKeyframe(_)) => {}
Err(err) => return Err(err),
}
producer.write(frame)?;
}

// The fragment arrived at once, so a consumer has to buffer its whole span.
producer.burst(end.checked_sub(earliest)?.into())?;
Ok(!producer.needs_keyframe())
Ok(())
}, _ => unreachable!("passthrough tracks write whole fragments"))
}

Expand Down Expand Up @@ -1457,13 +1450,18 @@ impl<E: crate::catalog::hang::CatalogExt> Import<E> {
/// control is intentionally not exposed. Skipping sequences is not a new timeline, so the
/// next fragment must still advance past the last decode time; see
/// [`discontinuity`](Self::discontinuity). Text spends a group per cue, so a text track that
/// is already past `sequence` continues from its own next group instead.
/// is already past `sequence` continues from its own next group instead. Video resumes at its
/// next sync sample, dropping the samples before it.
pub fn seek(&mut self, sequence: u64) -> Result<()> {
for track in self.text.values_mut() {
let next = track.producer.next_sequence();
track.producer.seek(sequence.max(next))?;
}
for track in self.tracks.values_mut() {
// The next group opens on a sync sample, so video drops the samples before one.
if track.kind == Kind::Video {
track.orphaned = true;
}
media!(&mut track.output, producer => producer.seek(sequence)?, passthrough => {
passthrough.close()?;
passthrough.pending_sequence = Some(sequence);
Expand Down
52 changes: 52 additions & 0 deletions rs/moq-mux/src/container/fmp4/import_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,58 @@ async fn video_drops_the_samples_before_its_edit() {
}
}

/// A video track joined mid-GOP, at the start or after a `seek`, publishes nothing before its next
/// sync sample, passthrough or unwrapped, even when that sample sits inside a fragment, so no group
/// opens on a frame its decoder cannot use.
#[tokio::test]
async fn video_joined_mid_gop_starts_at_a_sync_sample() {
let (_, (video_id, video_scale), _) = bbb_init();
let tick = video_scale.as_u64() / 24;
let micros = |ticks: u64| u128::from(ticks) * 1_000_000 / u128::from(video_scale.as_u64());
let sample = |ticks: u64, keyframe: bool, byte: u8| (micros(ticks), keyframe, bytes::Bytes::from(vec![byte; 2]));
let non_sync = 0x0001_0000;

let init = bbb_init_with_edits(video_id, vec![media_edit(0)]);
let fragments = [
video_fragment(video_id, 0, tick, &[(0, non_sync, 0xA), (0, non_sync, 0xB)]),
video_fragment(
video_id,
2 * tick,
tick,
&[(0, non_sync, 0xC), (0, 0, 0xD), (0, non_sync, 0xE)],
),
video_fragment(video_id, 5 * tick, tick, &[(0, 0, 0xF), (0, non_sync, 0x10)]),
];
let after_seek = [
video_fragment(video_id, 7 * tick, tick, &[(0, non_sync, 0x11)]),
video_fragment(video_id, 8 * tick, tick, &[(0, non_sync, 0x12), (0, 0, 0x13)]),
];
let expected = vec![
sample(3 * tick, true, 0xD),
sample(4 * tick, false, 0xE),
sample(5 * tick, true, 0xF),
sample(6 * tick, false, 0x10),
sample(9 * tick, true, 0x13),
];
for passthrough in [false, true] {
let mut broadcast = moq_net::broadcast::Info::new().produce();
let consumer = broadcast.consume();
let catalog = crate::catalog::Producer::new(&mut broadcast, crate::catalog::Config::default()).unwrap();
let mut fmp4 = crate::container::fmp4::Import::new(broadcast, catalog.reserve()).with_passthrough(passthrough);
fmp4.decode(&init).unwrap();
for fragment in &fragments {
fmp4.decode(fragment).unwrap();
}
fmp4.seek(10).unwrap();
for fragment in &after_seek {
fmp4.decode(fragment).unwrap();
}
fmp4.finish().unwrap();
let [video, _] = published(&consumer, &catalog).await;
assert_eq!(video, expected, "passthrough {passthrough}");
}
}

#[test]
fn test_bbb_init_roundtrip() {
let data = include_bytes!("test_data/bbb.mp4");
Expand Down
Loading