moq-mux: add seek(sequence) on importers for explicit group boundaries#1515
Conversation
Lets callers join mid-stream or signal discontinuities by opening the next group at a chosen sequence instead of always starting at 0. The default auto-rotate behavior on every importer is unchanged when seek is not invoked. `container::Producer<C>::seek` stashes a pending sequence used by the next group opened in `write`. fmp4/mkv `Import::seek` fans out across every track so all renditions advance together. Framed and Stream dispatchers forward to the underlying importer. https://claude.ai/code/session_01E5uGooj9DFQm7Hc1fy9PYL
WalkthroughThis PR adds a 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rs/moq-mux/src/container/fmp4/import_test.rs`:
- Line 10: The test helper is silently swallowing errors by turning Err into
None using .now_or_never().and_then(|r| r.ok().flatten()); update the loop to
explicitly handle the Result from consumer.recv_group(): call
consumer.recv_group().now_or_never(), match on Some(Ok(Some(group))) to
continue, Some(Ok(None)) to break, and treat Some(Err(e)) as a test-failure
(panic or propagate) so recv_group errors fail fast instead of being hidden.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 99340bf4-8eb6-42db-be3b-244c3add73df
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (11)
rs/moq-mux/Cargo.tomlrs/moq-mux/src/codec/aac/import.rsrs/moq-mux/src/codec/av1/import.rsrs/moq-mux/src/codec/h264/import.rsrs/moq-mux/src/codec/h265/import.rsrs/moq-mux/src/codec/opus/import.rsrs/moq-mux/src/container/fmp4/import.rsrs/moq-mux/src/container/fmp4/import_test.rsrs/moq-mux/src/container/mkv/import.rsrs/moq-mux/src/container/producer.rsrs/moq-mux/src/import.rs
| #[cfg(test)] | ||
| fn drain_group_sequences(consumer: &mut moq_net::TrackConsumer) -> Vec<u64> { | ||
| let mut sequences = Vec::new(); | ||
| while let Some(group) = consumer.recv_group().now_or_never().and_then(|r| r.ok().flatten()) { |
There was a problem hiding this comment.
Don’t silently swallow recv_group errors in the test helper.
Line 10 converts Err into None, which can hide real failures and let tests pass for the wrong reason. Fail fast on Some(Err(_)).
Suggested fix
fn drain_group_sequences(consumer: &mut moq_net::TrackConsumer) -> Vec<u64> {
let mut sequences = Vec::new();
- while let Some(group) = consumer.recv_group().now_or_never().and_then(|r| r.ok().flatten()) {
- sequences.push(group.sequence);
- }
+ loop {
+ match consumer.recv_group().now_or_never() {
+ Some(Ok(Some(group))) => sequences.push(group.sequence),
+ Some(Ok(None)) | None => break,
+ Some(Err(err)) => panic!("recv_group failed: {err:?}"),
+ }
+ }
sequences
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@rs/moq-mux/src/container/fmp4/import_test.rs` at line 10, The test helper is
silently swallowing errors by turning Err into None using
.now_or_never().and_then(|r| r.ok().flatten()); update the loop to explicitly
handle the Result from consumer.recv_group(): call
consumer.recv_group().now_or_never(), match on Some(Ok(Some(group))) to
continue, Some(Ok(None)) to break, and treat Some(Err(e)) as a test-failure
(panic or propagate) so recv_group errors fail fast instead of being hidden.
…drasekhar-da73a5 Conflicts in moq-mux Import structs where main (#1515) added a `seek` method using anyhow::Result; reconciled to return the per-module crate::Result/Result variant matching the rest of this branch's refactor. The h264/h265/av1 seek variants swap `.context("not initialized")` for `.ok_or(Error::NotInitialized)?` using each module's NotInitialized variant. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Adds
seek(sequence: u64)to everymoq-muximporter (and to the underlyingcontainer::Producer<C>) so callers can open the next group at an explicit sequence instead of always starting at 0. Useful for joining mid-stream and signalling discontinuities.Default auto-rotate behavior (video → new group on keyframe, AAC/Opus → one frame per group, fMP4 → new group when a
trafcontains a sync sample) is unchanged whenseekis not invoked, so existing callers (moq-cli, moq-gst, libmoq, moq-ffi, moq-boy, hang) are unaffected.The standalone AAC/Opus "one-frame-per-group" finalize stays as-is for now. A multi-frame-per-group knob for LL-HLS-style import was discussed and deferred;
seekalone solves the join/discontinuity case.How it works
container::Producer<C>gains apending_sequence: Option<u64>field.seek(n)flushes + finishes the current group and storesSome(n). The nextwriteopens the new group viaTrackProducer::create_group(Group { sequence: n })instead ofappend_group(), then clears the pending slot so subsequent groups auto-increment fromn.h264,h265,av1,aac,opus) forwardseekto their innercontainer::Producer.container::fmp4::Importandcontainer::mkv::Importfanseekout across every per-track entry so all renditions advance together. (Broadcast-wide by design; per-track control intentionally not exposed.)import::Framedandimport::Streamdispatchers forward to the contained importer.Test plan
cargo test -p moq-mux(144/144 passing, including 2 new unit tests oncontainer::Producerand 1 new end-to-end test onfmp4::Import).cargo check --all-targets --workspace(excludingmoq-boy/moq-gstwhich need system ffmpeg/gstreamer in this sandbox).cargo clippy --all-targets --workspace -- -D warnings(same exclusions).cargo fmt --all --check.(Written by Claude)
https://claude.ai/code/session_01E5uGooj9DFQm7Hc1fy9PYL
Generated by Claude Code