Skip to content

fix(core): a clip that has fully downloaded stays loaded and plays on time - #6787

Closed
miguel-heygen wants to merge 2 commits into
mainfrom
fix/keep-fully-buffered-clips
Closed

miguel-heygen wants to merge 2 commits into
mainfrom
fix/keep-fully-buffered-clips

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

A short clip that has already downloaded in full stays loaded when the playhead moves away from it, so it plays on time when its turn comes. Before, a b-roll clip in a long edit could show its first frame over a second late.

Why

Studio's preview releases a clip that leaves the look-ahead window (drops its src and reloads it) so it stops holding one of the browser's six connections to the server. A clip armed by the clip before it on its track loads early. When that earlier clip ends, the arm lapses and the clip is released, even when its whole file had already arrived and it held no connection. It then had to fetch again just before its start, queued behind long video downloads on the same host. On a long edit with b-roll over two camera files, that request waited 1.2-3.2 s, and one b-roll per run showed its first frame about 1.2 s late.

Related work

#6033 bounds open-ended media ranges in the file servers, which shortens how long the camera downloads hold connections. This PR is independent: a clip that is already in memory should not be fetched again at all.

How

releaseMedia returns early when the element's buffered range covers the whole file. Its only caller is the look-ahead window in init.ts.

Test plan

  • Unit tests in preloadMedia.test.ts: a clip with its whole file buffered is not reloaded; a clip with only part of a long file buffered still is.
  • fails without the fix: removing the early return fails keeps a clip whose whole file is buffered; treating any range that reaches the end as whole fails releases a clip with only 430-2642 s of a long file buffered; treating any range from the start as whole fails releases a clip with only 0-15 s of a long file buffered. Each mutation fails only that test.
  • vitest run src/runtime in packages/core: 108 files, 2647 tests passed. oxfmt, oxlint, core tsc and the comment ratchet clean.
  • Manual testing in Studio preview, Chrome 156 on an M4 Pro MacBook Pro, a long edit with b-roll over two camera files (synthetic 1080p media), 3 runs of 50 s per side:
per run, main → this branch
b-roll clips whose first frame came over 100 ms late 1, 1, 1 (1.20 s, 1.21 s, 1.27 s) → 0, 0, 0
latest first frame after the playhead reached a clip 1211 ms, 1215 ms, 1280 ms → 33 ms, 29 ms, 26 ms
frames held 2+ periods 4, 3, 2 → 1, 2, 1

Some b-roll requests still wait 1.2-1.9 s for a connection, but none of them now delays a clip's first frame.

  • Documentation updated (not applicable)
  • Comments follow CONTRIBUTING.md "Comments"

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 137 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

Unstable (2)

  • seqplainkeys-none-px-r0-root-z100: tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo false, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true
  • seqplainkeys-none-pct-r0-nested-z100: tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo false, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

@heygengenesis heygengenesis Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE · 0 blocker · 0 important · 0 nits · head 93d52593

Scope
  • releaseMedia has one caller (init.ts look-ahead). A kept clip that comes near again goes through startPrefetch. preloadMedia skips load() at readyState ≥ 3, and the slot isn't taken, so the buffered data is reused. A clip at readyState < 3 still gets the old reload.
  • The edge test needs one range covering [≤0.1 s, ≥duration−0.1 s]. A partly buffered long file, or one with a gap, is still released, so the connection-freeing path is unchanged.
  • fails without the fix: confirmed locally. Restoring main's preloadMedia.ts fails only keeps a clip whose whole file is buffered.
  • 93d52593 vs 2f3e7fbf only removes a comment. CI, Windows, regression, Comments and edit accuracy are green.

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Folded into #6785 with its tests and numbers, so the three preview fixes for long cut-list edits review and land as one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant