Skip to content

Commit 20a81e5

Browse files
committed
test(player): playbench reports how far the picture after a cut runs behind the playhead
1 parent d6a9950 commit 20a81e5

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎packages/player/tests/playbench/analyze.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ export type Metrics = {
4646
/** Problem 4 */
4747
secondFrameGapMedianMs: number | null;
4848
secondFrameGapMaxMs: number | null;
49+
/** How far the incoming picture sits behind the playhead over its take's first 0.5 s, median per cut. */
50+
cutPictureLagMedianMs: number | null;
51+
cutPictureLagMaxMs: number | null;
4952
playheadHoldMedianMs: number | null;
5053
playheadHoldP90Ms: number | null;
5154
holdsOver100: number;
@@ -222,7 +225,13 @@ export function analyze(run: Run): Metrics {
222225
// ---- Problem 4: what a cut costs
223226
const gaps: number[] = [];
224227
const holds: number[] = [];
228+
const lags: number[] = [];
225229
for (const t of takes.slice(1)) {
230+
const opening = byId(samples, `v${t.index}`).filter(
231+
(s) => s[3] === 0 && s[7] !== null && s[7] >= t.start && s[7] <= t.start + 0.5,
232+
);
233+
const lag = median(opening.map((s) => (t.inPoint + s[7]! - t.start - s[2]) * 1000));
234+
if (lag !== null) lags.push(lag);
226235
const fr = comp.frames
227236
.filter((f) => f[1] === `v${t.index}` && f[4] === 1)
228237
.sort((a, b) => a[0] - b[0]);
@@ -234,6 +243,8 @@ export function analyze(run: Run): Metrics {
234243
m.cuts = takes.length - 1;
235244
m.secondFrameGapMedianMs = round(median(gaps));
236245
m.secondFrameGapMaxMs = round(gaps.length ? Math.max(...gaps) : null);
246+
m.cutPictureLagMedianMs = round(median(lags));
247+
m.cutPictureLagMaxMs = round(lags.length ? Math.max(...lags) : null);
237248
m.playheadHoldMedianMs = round(median(holds));
238249
m.playheadHoldP90Ms = round(pct(holds, 0.9));
239250
m.holdsOver100 = holds.filter((h) => h > 100).length;

‎packages/player/tests/playbench/playbench.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,27 @@ describe("analyze", () => {
121121
expect(analyze(run).playheadHoldMedianMs).toBeCloseTo(30, 0);
122122
});
123123

124+
it("reports an incoming picture that runs 50 ms behind the playhead after its cut", () => {
125+
const run = base();
126+
for (const t of edit.takes.slice(1))
127+
for (let i = 0; i <= 50; i++) {
128+
const ph = t.start + i * 0.01;
129+
run.comp.samples.push([
130+
1000 + ph * 1000,
131+
`v${t.index}`,
132+
t.inPoint + ph - t.start - 0.05,
133+
0,
134+
0,
135+
1,
136+
1,
137+
ph,
138+
]);
139+
}
140+
const m = analyze(run);
141+
expect(m.cutPictureLagMedianMs).toBeCloseTo(50, 0);
142+
expect(m.cutPictureLagMaxMs).toBeCloseTo(50, 0);
143+
});
144+
124145
it("counts a take as heard only when the audio reaching the output comes from that take's stretch of the file", () => {
125146
const run = base();
126147
run.ownership = [[1000, "parent"]];

‎packages/player/tests/playbench/run.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,16 @@ const ROWS: [string, string, (m: Metrics) => number | boolean | null][] = [
229229
["4", "cuts", (m) => m.cuts],
230230
["4", "incoming second-frame gap median (ms)", (m) => m.secondFrameGapMedianMs],
231231
["4", "incoming second-frame gap max (ms)", (m) => m.secondFrameGapMaxMs],
232+
[
233+
"4",
234+
"incoming picture behind the playhead, first 0.5 s, median over cuts (ms)",
235+
(m) => m.cutPictureLagMedianMs,
236+
],
237+
[
238+
"4",
239+
"incoming picture behind the playhead, first 0.5 s, worst cut (ms)",
240+
(m) => m.cutPictureLagMaxMs,
241+
],
232242
["4", "playhead hold per cut median (ms)", (m) => m.playheadHoldMedianMs],
233243
["4", "playhead hold per cut p90 (ms)", (m) => m.playheadHoldP90Ms],
234244
["4", "cuts with a hold over 100 ms", (m) => m.holdsOver100],

0 commit comments

Comments
 (0)