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/explicit-state/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ which collapses that state and waits on [Drop set](/quest/m1/drop-set.md).
- [Track and group end-of-life](/quest/m1/explicit-state/track-end.md) - moq-net's track and group outcomes are one enum each, in Rust and JS
- [moq-net phase data](/quest/m1/explicit-state/net-phases.md) - moq-net's session and subscription state machines keep each phase's data in its variant
- [moq-mux and moq-gst lifecycles](/quest/m1/explicit-state/mux-gst.md) - export sources, TS and fMP4 export tracks, and gst pads are explicit state
- [A failed catalog finish is final](/quest/m1/explicit-state/catalog-finish.md) - the catalog producer never reports closed with a catalog track left open
- [Video's declared-end freeze is not a stall](/quest/m1/explicit-state/video-declared-end.md) - video holding its last picture through a declared end counts no stall, like audio's declared silence

## Related
Expand Down
24 changes: 0 additions & 24 deletions quest/m1/explicit-state/catalog-finish.md

This file was deleted.

78 changes: 70 additions & 8 deletions rs/moq-mux/src/catalog/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,20 +1059,39 @@ impl<E: CatalogExt> Producer<E> {
self.outputs.abort(&reason);
}

/// The terminal outcome once the catalog tracks are closed.
pub(crate) fn closed(&self) -> Option<crate::Error> {
take(&self.current).closed.clone()
}

/// Finish publishing to this catalog.
///
/// An estimate rise still held by the once-a-second limit is not published: media has ended.
///
/// A failure is final: both catalog tracks end (the other one aborted with that error), and every
/// later call reports it.
pub fn finish(&mut self) -> crate::Result<()> {
{
let mut state = take(&self.current);
if let Some(err) = &state.closed {
return Err(err.clone());
let mut state = take(&self.current);
if let Some(err) = &state.closed {
return Err(err.clone());
}
let result = self
.outputs
.hang
.finish()
.map_err(crate::Error::from)
.and_then(|_| self.outputs.msf_track.finish().map_err(crate::Error::from));
match result {
Ok(()) => {
state.closed = Some(moq_net::Error::Closed.into());
Ok(())
}
Err(err) => {
self.outputs.abort(&err);
state.closed = Some(err.clone());
Err(err)
}
state.closed = Some(moq_net::Error::Closed.into());
}
self.outputs.hang.finish()?;
self.outputs.msf_track.finish()?;
Ok(())
}
}

Expand Down Expand Up @@ -1545,6 +1564,49 @@ mod test {
));
}

#[tokio::test(start_paused = true)]
async fn a_failed_finish_is_final_and_ends_both_tracks() {
let mut broadcast = moq_net::broadcast::Info::default().produce();
let mut catalog = Producer::<()>::new(&mut broadcast, Config::default()).unwrap();
let mut msf = broadcast
.consume()
.track(moq_msf::DEFAULT_NAME)
.unwrap()
.subscribe(None)
.await
.unwrap();
catalog
.outputs
.hang
.clone()
.abort(moq_net::Error::Unauthorized)
.unwrap();
let err = catalog.finish().unwrap_err();
loop {
match msf.recv_group().await {
Ok(Some(_)) => continue,
Ok(None) => panic!("the MSF track ended cleanly after a failed finish"),
Err(moq_net::Error::Unauthorized) => break,
Err(other) => panic!("the MSF track ended with {other} instead of the finish cause"),
}
}
assert_eq!(catalog.finish().unwrap_err().to_string(), err.to_string());
assert_eq!(catalog.modify().err().unwrap().to_string(), err.to_string());

// A handle made after the failure reports it too, not `NotPublished`.
let net = broadcast
.create_track("late", catalog.track_info(hang::catalog::PRIORITY.video))
.unwrap();
let mut late = catalog
.video(
net,
crate::catalog::hang::Container::Legacy(crate::container::Kind::Video),
None,
)
.unwrap();
assert_eq!(late.modify().err().unwrap().to_string(), err.to_string());
}

/// The catalog and its MSF twin both rank above media. They're the index a player reads
/// before any media is useful, and they're small enough that sitting above media can't starve
/// it. Regression: the MSF track was minted with no `Info` at all, so one broadcast advertised
Expand Down
10 changes: 8 additions & 2 deletions rs/moq-mux/src/catalog/tracks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,16 @@ impl<E: CatalogExt, C: RenditionConfig<E>> Rendition<E, C> {
Ok(())
}

/// Why an unpublished rendition can't be edited: the catalog's terminal error once it is closed,
/// since a handle made after a failed finish must report that failure, else `NotPublished`.
fn unpublished(&self) -> crate::Error {
self.catalog.closed().unwrap_or(crate::Error::NotPublished)
}

/// Refine the rendition, refusing an unserializable edit before retaining it.
pub(crate) fn config(&self) -> crate::Result<C> {
if !self.present {
return Err(crate::Error::NotPublished);
return Err(self.unpublished());
}
self.catalog.config::<C>(&self.name).ok_or(crate::Error::NotPublished)
}
Expand Down Expand Up @@ -822,7 +828,7 @@ impl<E: CatalogExt, C: RenditionConfig<E>> Rendition<E, C> {
/// Write `config` into the catalog, leaving the caller to choose how the guard publishes it.
fn stage(&mut self, config: C) -> crate::Result<super::Guard<'_, E>> {
if !self.present {
return Err(crate::Error::NotPublished);
return Err(self.unpublished());
}
Self::check_decrease(&self.config()?.estimate(), &config.estimate())?;
let mut guard = self.catalog.modify()?;
Expand Down
Loading