Repository navigation
fix(moq-mux): a padded TS export sheds when its sink falls behind #8449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,6 +126,8 @@ where | |
| active_program: u64, | ||
| follow_until: Option<kio::clock::Instant>, | ||
| follow_timer: Option<std::pin::Pin<Box<kio::clock::Sleep>>>, | ||
| /// When a read last found nothing more due: the output had caught up then ([`Self::shed`]). | ||
| caught_up: Option<kio::clock::Instant>, | ||
| } | ||
|
|
||
| /// Input and mux state belonging to one publisher instance. The release clock | ||
|
|
@@ -1661,6 +1663,7 @@ where | |
| active_program: 0, | ||
| follow_until: None, | ||
| follow_timer: None, | ||
| caught_up: None, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1704,6 +1707,14 @@ where | |
| /// muxer has no use for it. | ||
| #[cfg_attr(feature = "async", kio::wrapper)] | ||
| pub fn poll_next(&mut self, waiter: &kio::Waiter) -> Poll<crate::Result<Option<Frame>>> { | ||
| let poll = self.poll_frame(waiter); | ||
| if poll.is_pending() { | ||
| self.caught_up = Some(kio::clock::now()); | ||
| } | ||
| poll | ||
| } | ||
|
|
||
| fn poll_frame(&mut self, waiter: &kio::Waiter) -> Poll<crate::Result<Option<Frame>>> { | ||
| if self.pending.is_some() { | ||
| self.stop_old(waiter)?; | ||
| } | ||
|
|
@@ -1799,6 +1810,13 @@ where | |
|
|
||
| // 4. Mux each frame the jitter buffer lets go (the first carries the buffered | ||
| // PAT/PMT), then lay out every grid slot whose time has come ([`Self::lay_due`]). | ||
| // A shed makes room in each source's jitter window, so read them again. | ||
| if self.program.queue.is_empty() | ||
| && self.shed() | ||
| && let Err(err) = self.fill(waiter) | ||
| { | ||
| self.leave(err)?; | ||
| } | ||
| loop { | ||
| if let Some(out) = self.pop() { | ||
| return Poll::Ready(Ok(Some(out))); | ||
|
|
@@ -3887,6 +3905,35 @@ where | |
| self.program.delay / 2 | ||
| } | ||
|
|
||
| /// Shed what a padded output fell more than [`Self::budget`] behind on, as when its sink | ||
| /// blocks or drains slower than the multiplex rate. Every slot it missed would otherwise go | ||
| /// out at once, and the frames it left unread would reach the jitter buffer as late as a | ||
| /// source clock running far slow. Instead it drops what is due by now and resumes the grid | ||
| /// on the media still to come, flagging the jump as a PCR discontinuity. | ||
| /// | ||
| /// It is behind by how long the jitter buffer's front has been overdue since a read last | ||
| /// caught up: a frame held back while the output keeps up (for the program's tables, or a | ||
| /// generation still going out) is no lag of the sink's, and a source that fell silent leaves | ||
| /// nothing overdue. | ||
| /// Returns whether it shed. | ||
| fn shed(&mut self) -> bool { | ||
| // Once every source has ended, the tail goes out late if it must. | ||
| if self.program.mux_rate.is_none() || self.held.is_some() || self.program.schedule.ended() { | ||
| return false; | ||
| } | ||
| let (Some(due), Some(caught_up)) = (self.jitter.front_deadline(), self.caught_up) else { | ||
| return false; | ||
| }; | ||
| let behind = kio::clock::now().saturating_duration_since(due.max(caught_up)); | ||
| if behind <= self.budget() { | ||
| return false; | ||
|
Comment on lines
+3927
to
+3929
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| tracing::warn!(?behind, "MPEG-TS output fell behind its multiplex rate, shedding"); | ||
| self.jitter.shed(kio::clock::now()); | ||
| self.rewind(); | ||
| true | ||
| } | ||
|
|
||
| /// Lay out every grid slot whose time has come, and wake when the next one is due. | ||
| fn lay_due(&mut self, waiter: &kio::Waiter) -> anyhow::Result<()> { | ||
| while let Some((known, at)) = self.slot_due() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A
--delay 0 --mux-rateexport now sheds on any positive read latency.budget()isdelay / 2, i.e. zero here, sobehind = now - max(due, caught_up)is positive whenever the reader wakes even a microsecond after a frame lands; the front (typically the group's sync frame) is dropped and the grid is rewound.Technical details