Repository navigation
fix(mux): bound what the decode clock holds in MKV and TS export #6417
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| //! The decode clock swept over how many frames it holds and how their PTS run: draining what | ||
| //! it holds, and settling frames as they are read until the overdue rule bounds them. | ||
| use std::time::Duration; | ||
|
|
||
| use bytes::Bytes; | ||
| use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main}; | ||
| use moq_clock::Instant; | ||
|
|
||
| #[path = "../src/container/decode.rs"] | ||
| #[allow(dead_code)] | ||
| mod decode; | ||
|
|
||
| /// A 40 ms frame in 90 kHz ticks. | ||
| const FRAME: u64 = 3_600; | ||
|
|
||
| /// The `index`-th frame's PTS in decode order: stuck, running backward, or a valid B-pyramid. | ||
| fn pts(shape: &str, index: u64) -> u64 { | ||
| let base = 1_000 * 90_000; | ||
| match shape { | ||
| "flat" => base, | ||
| "backward" => base - index, | ||
| _ => { | ||
| const PYRAMID: [u64; 9] = [0, 4, 2, 1, 3, 8, 6, 5, 7]; | ||
| base + (index / 9 * 9 + PYRAMID[(index % 9) as usize]) * FRAME | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Flush `held` frames read with nothing settled, as at a track's end. | ||
| fn drain(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("decode_clock_drain"); | ||
| group.measurement_time(Duration::from_secs(1)); | ||
| group.warm_up_time(Duration::from_millis(200)); | ||
| group.sample_size(10); | ||
| for shape in ["flat", "backward", "pyramid"] { | ||
| for held in [1_000u64, 10_000, 100_000] { | ||
| for size in [64usize, 4_096] { | ||
| let payload = Bytes::from(vec![0; size]); | ||
| group.throughput(Throughput::Elements(held)); | ||
| group.bench_function(BenchmarkId::new(format!("{shape}/{size}B"), held), |b| { | ||
| b.iter(|| { | ||
| let mut clock = decode::DecodeClock::default(); | ||
| for index in 0..held { | ||
| clock.push(payload.clone(), pts(shape, index), Instant::ZERO); | ||
| } | ||
| let mut drained = 0; | ||
| while clock.pop(decode::MAX_REORDER, 0, decode::Settle::All).is_some() { | ||
| drained += 1; | ||
| } | ||
| assert_eq!(drained, held); | ||
| }) | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| group.finish(); | ||
| } | ||
|
|
||
| /// Read `frames` frames 1 ms apart, a 120 ms lookahead and 500 ms delay, settling each as an | ||
| /// exporter does: flat or backward PTS holds what the overdue rule lets through. | ||
| fn read(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("decode_clock_read"); | ||
| group.measurement_time(Duration::from_secs(1)); | ||
| group.warm_up_time(Duration::from_millis(200)); | ||
| group.sample_size(10); | ||
| let lookahead = 120 * 90; | ||
| let delay = Duration::from_millis(500); | ||
| for shape in ["flat", "backward", "pyramid"] { | ||
| for frames in [1_000u64, 10_000, 100_000] { | ||
| group.throughput(Throughput::Elements(frames)); | ||
| group.bench_function(BenchmarkId::new(shape, frames), |b| { | ||
| b.iter(|| { | ||
| let mut clock = decode::DecodeClock::default(); | ||
| let (mut held, mut most) = (0, 0); | ||
| for index in 0..frames { | ||
| let latest = Instant::ZERO + Duration::from_millis(index); | ||
| clock.push(index, pts(shape, index), latest); | ||
| held += 1; | ||
| loop { | ||
| let settle = clock.settle(lookahead, latest, delay); | ||
| if clock.pop(lookahead, 0, settle).is_none() { | ||
| break; | ||
| } | ||
| held -= 1; | ||
| } | ||
| most = most.max(held); | ||
| } | ||
| // What arrives in the deepest lookahead and the delay, a frame a millisecond. | ||
| assert!(most <= 2_501, "{shape}: {most} held"); | ||
| }) | ||
| }); | ||
| } | ||
| } | ||
| group.finish(); | ||
| } | ||
|
|
||
| criterion_group!(benches, drain, read); | ||
| criterion_main!(benches); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.