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
3 changes: 1 addition & 2 deletions quest/m2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ removal, a rename, or a wire, catalog, or format change that is free until
(the `sync` section, a version per entry, no video `warmup`, `m2ts` under
`mpegts`, one strict rule);
[declared ends](/quest/m2/time-addressing/consumers.md), back from m3;
[finish](/quest/m2/finish-sweep.md), and
[moq-json writes](/quest/m2/json-write-at.md).
and [moq-json writes](/quest/m2/json-write-at.md).
- **Native media and gateways.** [The video producer](/quest/m2/video-producer.md),
[the hole wait](/quest/m2/delay-hole-wait.md),
[moq-vaapi's exports](/quest/m2/vaapi-exports.md),
Expand Down
76 changes: 0 additions & 76 deletions quest/m2/finish-sweep.md

This file was deleted.

5 changes: 2 additions & 3 deletions quest/m2/video-producer.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ For the PR:
(`publish_capture`'s `Driver`), which then runs on it, so the capture path
and a caller's own frames share one encode loop and one grant follower.
Shape it after audio: an `Options` with `bandwidth`, `write(&Frame)`, and
`finish(self) -> Result<Finished, Error>` from the start (the
[finish sweep](/quest/m2/finish-sweep.md) converts the renamed type).
`finish(self) -> Result<Finished, Error>`, as the encoded publisher
being renamed already has.
- Move moq-boy, moq-ffi, and moq-c onto it and delete their copies of the
grant follower. A binding option the lifted type cannot express (moq-ffi's
`lower` rendition for the simulcast ladder, `rs/moq-ffi/src/video.rs:370`)
Expand All @@ -69,5 +69,4 @@ publisher is renamed). moq-ffi and moq-c keep their names. Wire: none.

## Related

- [Terminal operations consume](/quest/m2/finish-sweep.md) - gives the renamed type `finish(self)`; whichever lands second rebases
- [A published capture exposes its grant](/quest/m3/video-publish-grant.md) - adds a getter to the capture handle this runs on
29 changes: 12 additions & 17 deletions rs/moq-c/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,6 @@ impl Abort for Data<moq_mux::json::Stream<serde_json::Value>> {
}
}

/// The cause a failed import ends its tracks with, so a reader sees the publisher fail rather than
/// `Dropped`. Only a moq-net error has a wire code; any other reaches readers as `Internal`.
fn cause(err: &moq_mux::Error) -> moq_net::Error {
match err {
moq_mux::Error::Moq(err) => err.clone(),
_ => moq_net::StreamError::Internal.into(),
}
}

impl<T> std::ops::Deref for Kept<T> {
type Target = T;

Expand Down Expand Up @@ -686,15 +677,19 @@ impl Publish {
}

pub fn media_finish(&mut self, media: Id) -> Result<(), Error> {
let mut track = self.media.remove(media).ok_or(Error::MediaNotFound)?;
if let Err(err) = track.finish() {
track.children.forget(Child::Media(media));
let cause = cause(&err);
track.abort(cause);
return Err(err.into());
let Kept { inner, children } = self.media.remove(media).ok_or(Error::MediaNotFound)?;
match inner.track.finish() {
// The broadcast keeps the finished track, so its finish still holds it.
Ok(finished) => {
children.keep(Child::Media(media), finished);
Ok(())
}
// A failed finish already ended the track with its cause.
Err(err) => {
children.forget(Child::Media(media));
Err(err.into())
}
}
track.keep(Child::Media(media));
Ok(())
}

/// Write a whole chunk of container bytes.
Expand Down
18 changes: 12 additions & 6 deletions rs/moq-c/src/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,18 +539,24 @@ fn surface(_frame: &moq_video::Frame) -> *const c_void {
/// anyway would leave a truncated stream indistinguishable from a complete one,
/// and only the local caller would ever learn otherwise.
fn finalize(
mut producer: moq_video::encode::Producer,
producer: moq_video::encode::Producer,
drained: Result<(), moq_video::Error>,
children: &crate::publish::Children,
child: crate::publish::Child,
) -> Result<(), Error> {
match drained {
Ok(()) => {
producer.finish()?;
Ok(()) => match producer.finish() {
// The broadcast keeps the finished track, so its finish still holds it.
children.keep(child, producer);
Ok(())
}
Ok(finished) => {
children.keep(child, finished);
Ok(())
}
// A failed finish already ended the track with its cause.
Err(err) => {
children.forget(child);
Err(err.into())
}
},
Err(err) => {
children.forget(child);
producer.abort(moq_net::Error::Transport(err.to_string()));
Expand Down
5 changes: 2 additions & 3 deletions rs/moq-cli/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ impl PublishDecoder {
Self::Avc3 { mut split, mut import } => {
let tail = split.flush(None)?;
import.decode(tail)?;
import.finish()?;
FinishedDecoder::Avc3(import)
FinishedDecoder::Avc3(Box::new(import.finish()?))
}
Self::Fmp4(d) => FinishedDecoder::Fmp4(Box::new(d.finish()?)),
Self::Ts(d) => FinishedDecoder::Ts(Box::new(d.finish()?)),
Expand All @@ -253,7 +252,7 @@ impl PublishDecoder {

/// A [`PublishDecoder`] whose tracks finished, holding them so they stay servable.
enum FinishedDecoder {
Avc3(Box<moq_mux::codec::h264::Import>),
Avc3(Box<moq_mux::container::Finished<moq_mux::catalog::hang::Container, hang::catalog::VideoConfig>>),
Fmp4(Box<fmp4::Finished>),
Ts(Box<ts::republish::Finished>),
TsPrograms(Box<ts::programs::Finished>),
Expand Down
37 changes: 12 additions & 25 deletions rs/moq-ffi/src/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1278,14 +1278,12 @@ impl MoqMediaTrackProducer {
pub fn finish(&self) -> Result<(), MoqError> {
let _guard = crate::ffi::enter();
let mut guard = self.inner.lock().unwrap();
let mut media = guard.take().ok_or(MoqError::Closed)?;
if let Err(err) = media.import.finish() {
media.import.abort(cause(&err));
return Err(MoqError::Codec {
reason: format!("finish failed: {err}"),
});
}
self.children.keep(media);
let media = guard.take().ok_or(MoqError::Closed)?;
// A failed finish already ended the track with its cause.
let finished = media.import.finish().map_err(|err| MoqError::Codec {
reason: format!("finish failed: {err}"),
})?;
self.children.keep(finished);
Ok(())
}
}
Expand Down Expand Up @@ -1442,27 +1440,16 @@ impl MoqMediaTrackStreamProducer {
pub fn finish(&self) -> Result<(), MoqError> {
let _guard = crate::ffi::enter();
let mut guard = self.inner.lock().unwrap();
let mut media = guard.take().ok_or(MoqError::Closed)?;
if let Err(err) = media.import.finish() {
media.import.abort(cause(&err));
return Err(MoqError::Codec {
reason: format!("finish failed: {err}"),
});
}
self.children.keep(media);
let media = guard.take().ok_or(MoqError::Closed)?;
// A failed finish already ended the track with its cause.
let finished = media.import.finish().map_err(|err| MoqError::Codec {
reason: format!("finish failed: {err}"),
})?;
self.children.keep(finished);
Ok(())
}
}

/// The cause a failed import ends its tracks with, so a reader sees the publisher fail rather than
/// `Dropped`. Only a moq-net error has a wire code; any other reaches readers as `Internal`.
fn cause(err: &moq_mux::Error) -> moq_net::Error {
match err {
moq_mux::Error::Moq(err) => err.clone(),
_ => moq_net::StreamError::Internal.into(),
}
}

/// Reserve the named track, or a unique one named after the format.
fn reserve_track(
broadcast: &moq_net::broadcast::Producer,
Expand Down
5 changes: 2 additions & 3 deletions rs/moq-ffi/src/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,13 @@ fn drain(
/// anyway would leave a truncated stream indistinguishable from a complete one,
/// and only the local caller would ever learn otherwise.
fn finalize(
mut producer: moq_video::encode::Producer,
producer: moq_video::encode::Producer,
drained: Result<(), moq_video::Error>,
children: &crate::producer::Children,
) -> Result<(), MoqError> {
match drained {
Ok(()) => {
producer.finish()?;
children.keep(producer);
children.keep(producer.finish()?);
Ok(())
}
Err(err) => {
Expand Down
12 changes: 8 additions & 4 deletions rs/moq-gst/src/sink/pad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ impl Names {
#[derive(Default)]
pub(super) struct Closed {
_track: Option<Sink>,
/// A finished audio or video track, which no longer has a [`Sink`].
_media: Option<import::track::Finished>,
/// A finished text track, which no longer has a [`Sink`].
_text: Option<moq_mux::container::Finished<moq_mux::catalog::hang::Container, hang::catalog::TextConfig>>,
/// The catalog `_track` published in, kept open until the owner drops.
Expand Down Expand Up @@ -986,11 +988,12 @@ impl Pad {
self.names.end(track.name());
}
let mut text = None;
let mut media = None;
let (result, track) = match track {
Sink::Media(mut media) => (
media.track.finish().map_err(anyhow::Error::from),
Some(Sink::Media(media)),
),
Sink::Media(sink) => {
let result = sink.track.finish().map(|finished| media = Some(finished));
(result.map_err(anyhow::Error::from), None)
}
Sink::Text(sink) => {
let result = sink.producer.finish().map(|finished| text = Some(finished));
(result.map_err(anyhow::Error::from), None)
Expand All @@ -1007,6 +1010,7 @@ impl Pad {
};
let closed = Closed {
_track: track,
_media: media,
_text: text,
_catalog: Some(catalog),
};
Expand Down
27 changes: 18 additions & 9 deletions rs/moq-mux/benches/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,19 @@ fn import_cmaf_chunks(
}

struct Annexb {
_broadcast: moq_net::broadcast::Producer,
broadcast: moq_net::broadcast::Producer,
catalog: moq_mux::catalog::Producer,
import: h264::Import,
split: h264::Split,
}

/// What a finished [`Annexb`] import keeps published, returned so the timed run drops none of it.
struct Imported {
_broadcast: moq_net::broadcast::Producer,
catalog: moq_mux::catalog::Producer,
_track: moq_mux::container::Finished<moq_mux::catalog::hang::Container, hang::catalog::VideoConfig>,
}

impl Annexb {
fn new() -> Self {
let mut broadcast = moq_net::broadcast::Info::new().produce();
Expand All @@ -166,29 +173,32 @@ impl Annexb {
.unwrap();
let import = h264::Import::new(track, catalog.reserve(), Default::default()).unwrap();
Self {
_broadcast: broadcast,
broadcast,
catalog,
import,
split: h264::Split::new(),
}
}

fn decode(&mut self, payload: &Bytes, frames: usize) {
fn decode(mut self, payload: &Bytes, frames: usize) -> Imported {
for index in 0..frames {
let pts = timestamp(index);
let mut complete = self.split.decode(payload, pts).unwrap();
complete.extend(self.split.flush(pts).unwrap());
self.import.decode(complete).unwrap();
}
self.import.finish().unwrap();
Imported {
_broadcast: self.broadcast,
catalog: self.catalog,
_track: self.import.finish().unwrap(),
}
}
}

// Collect only timed import work, excluding the output validation in setup.
#[inline(never)]
fn profiled_import(mut import: Annexb, payload: &Bytes, frames: usize) -> Annexb {
import.decode(payload, frames);
import
fn profiled_import(import: Annexb, payload: &Bytes, frames: usize) -> Imported {
import.decode(payload, frames)
}

/// `fragments` moofs whose `tracks` trafs each split their samples into `runs` one-sample runs,
Expand Down Expand Up @@ -414,8 +424,7 @@ fn containers(c: &mut Criterion) {
}
assert_eq!(fragments, tracks * frames);
} else {
let mut import = Annexb::new();
import.decode(&payload, frames);
let import = Annexb::new().decode(&payload, frames);
assert_eq!(import.catalog.snapshot().video.renditions.len(), 1);
}
assert!(!data.is_empty());
Expand Down
17 changes: 13 additions & 4 deletions rs/moq-mux/src/codec/aac/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,19 @@ impl Import {
self.track.track().demand()
}

/// Finish the track, flushing the current group.
pub fn finish(&mut self) -> crate::Result<()> {
self.track.end_with(None)?;
Ok(())
/// Finish the track, flushing the current group, and return the [`Finished`](crate::container::Finished)
/// track, which keeps it and its catalog rendition published.
///
/// A finish that fails ends the track with the cause instead, so it can't be retried.
pub fn finish(
self,
) -> crate::Result<crate::container::Finished<crate::catalog::hang::Container, hang::catalog::AudioConfig>> {
self.track.finish()
}

/// [`finish`](Self::finish) the track in place, for an owner that keeps this importer.
pub(crate) fn finish_in_place(&mut self) -> crate::Result<()> {
self.track.end_with(None)
}

/// Abort the track with `err` instead of finishing it cleanly, so subscribers
Expand Down
Loading