mux: track skipped bytes for accurate loss estimation

DiscStream skips a whole AACS unit (3 sectors = 6144 bytes) per
read-error event, but only the skip-event count was exposed. Loss
estimates built from errors*2048 therefore undercounted AACS loss ~3x.

Add a lost_bytes field that accumulates the actual zero-filled byte
count at each skip, expose it via a new Stream::lost_bytes() accessor
(default 0; DiscStream and CountingStream override), so consumers can
scale lost-video time by real bytes lost rather than the event count.

Regression tests assert the AACS path records 6144 B/event (and
exceeds the errors*2048 undercount) while the align=1 path records
2048 B/event.
This commit is contained in:
Matthew Jackson
2026-06-23 00:12:56 -07:00
parent c3c5259f84
commit 980eeb3de9
2 changed files with 54 additions and 0 deletions
+15
View File
@@ -180,6 +180,17 @@ pub trait Stream: Send {
fn errors(&self) -> u64 {
0
}
/// Cumulative bytes actually skipped (zero-filled) past read errors.
/// Distinct from [`errors`](Self::errors), which counts skip *events*:
/// a single AACS skip event covers a whole 6144-byte unit, so
/// `errors * 2048` understates real loss. Consumers estimating lost
/// video time must scale by this byte count, not the event count.
/// Default `0` for streams with no skip-on-error notion; `DiscStream`
/// overrides.
fn lost_bytes(&self) -> u64 {
0
}
}
/// Wraps any output stream and counts bytes written.
@@ -242,6 +253,10 @@ impl Stream for CountingStream {
fn errors(&self) -> u64 {
self.inner.errors()
}
fn lost_bytes(&self) -> u64 {
self.inner.lost_bytes()
}
}
#[cfg(test)]