diff --git a/packages/core/package-subpaths.json b/packages/core/package-subpaths.json index d617a33d8d..e05711b0fd 100644 --- a/packages/core/package-subpaths.json +++ b/packages/core/package-subpaths.json @@ -392,6 +392,12 @@ "types": "./dist/runtime/mediaClock.d.ts", "environments": ["browser", "bun", "node"] }, + "./runtime/media-steer": { + "source": "./src/runtime/mediaSteer.ts", + "runtime": "./dist/runtime/mediaSteer.js", + "types": "./dist/runtime/mediaSteer.d.ts", + "environments": ["browser", "bun", "node"] + }, "./runtime/clip-reveal": { "source": "./src/runtime/clipReveal.ts", "runtime": "./dist/runtime/clipReveal.js", diff --git a/packages/core/package.json b/packages/core/package.json index 403b876810..f4ad5aa476 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -399,6 +399,12 @@ "import": "./src/runtime/mediaClock.ts", "types": "./src/runtime/mediaClock.ts" }, + "./runtime/media-steer": { + "bun": "./src/runtime/mediaSteer.ts", + "node": "./dist/runtime/mediaSteer.js", + "import": "./src/runtime/mediaSteer.ts", + "types": "./src/runtime/mediaSteer.ts" + }, "./runtime/clip-reveal": { "bun": "./src/runtime/clipReveal.ts", "node": "./dist/runtime/clipReveal.js", @@ -845,6 +851,10 @@ "import": "./dist/runtime/mediaClock.js", "types": "./dist/runtime/mediaClock.d.ts" }, + "./runtime/media-steer": { + "import": "./dist/runtime/mediaSteer.js", + "types": "./dist/runtime/mediaSteer.d.ts" + }, "./runtime/clip-reveal": { "import": "./dist/runtime/clipReveal.js", "types": "./dist/runtime/clipReveal.d.ts" diff --git a/packages/core/src/runtime/audioFx.test.ts b/packages/core/src/runtime/audioFx.test.ts index b1d110083c..46a1263b99 100644 --- a/packages/core/src/runtime/audioFx.test.ts +++ b/packages/core/src/runtime/audioFx.test.ts @@ -656,7 +656,7 @@ describe("attachElementFxChain", () => { } }); - it("clears a limiter's state when a persistent chain is re-anchored for a new pass", async () => { + it("clears a limiter's state for a new pass, not when the same pass is re-timed", async () => { const messages: unknown[] = []; class RecordingWorkletStub extends WorkletNodeStub { override port = { postMessage: (...sent: unknown[]) => void messages.push(...sent) }; @@ -679,6 +679,7 @@ describe("attachElementFxChain", () => { timing, ); await settle(); + fx?.retime({ scheduledAt: 1, elapsed: 0.9, rate: 1.03 }); expect(messages).not.toContainEqual({ __hfReset: true }); fx?.reanchor(timing); expect(messages).toContainEqual({ __hfReset: true }); diff --git a/packages/core/src/runtime/audioFx.ts b/packages/core/src/runtime/audioFx.ts index 452d48c214..1abefe55d1 100644 --- a/packages/core/src/runtime/audioFx.ts +++ b/packages/core/src/runtime/audioFx.ts @@ -112,6 +112,8 @@ export interface ElementFxHandle { * stuck value, which for a fade-out is silence for the rest of the session. */ reanchor(timing: AutomationTiming): void; + /** Re-aim every booked envelope at `timing` without clearing effect state: the same pass, re-measured. */ + retime(timing: AutomationTiming): void; /** * Re-aim every booked envelope at a new playback rate. * @@ -343,15 +345,21 @@ export function attachElementFxChain( }); } + const retime = (next: AutomationTiming): void => { + if (disposed) return; + const at = timingNow(); + if (at) cancelParamLane(automated, at.scheduledAt); + frame = { ...next }; + scheduleFor(readChain(el).chain, frame); + }; + return { reanchor: (next: AutomationTiming) => { if (disposed) return; - const at = timingNow(); - if (at) cancelParamLane(automated, at.scheduledAt); - frame = { ...next }; handle?.reset(); - scheduleFor(readChain(el).chain, frame); + retime(next); }, + retime, setRate: (rate: number) => { const at = timingNow(); if (disposed || !at || !Number.isFinite(rate) || rate <= 0 || rate === at.rate) return; diff --git a/packages/core/src/runtime/init.ts b/packages/core/src/runtime/init.ts index 4ad661ba07..6e558ba776 100644 --- a/packages/core/src/runtime/init.ts +++ b/packages/core/src/runtime/init.ts @@ -90,7 +90,7 @@ import { resolveNaturalMediaTimelineDuration, resolveRuntimeMediaClipDuration, syncRuntimeMedia, - VIDEO_PRESEEK_SECONDS, + MEDIA_PRESEEK_SECONDS, type RuntimeMediaClip, } from "./media"; import { @@ -3493,14 +3493,14 @@ export function initSandboxRuntimeModular(): void { visiting.add(clip.el); } if (state.isPlaying && !window.__HF_EXPORT_RENDER_SEEK_CONFIG) { - // An endpoint-only pass reaches trimmed video too late: its first visible tick starts a seek. + // An endpoint-only pass reaches a trimmed clip too late: its first active tick starts a seek. for (const clip of clipsWithEndpointBetween( index.byStart, (c) => c.start, toSeconds, - toSeconds + VIDEO_PRESEEK_SECONDS * state.playbackRate, + toSeconds + MEDIA_PRESEEK_SECONDS * state.playbackRate, )) { - if (clip.el.tagName === "VIDEO") visiting.add(clip.el); + visiting.add(clip.el); } } return [...visiting]; @@ -3659,6 +3659,7 @@ export function initSandboxRuntimeModular(): void { webAudio.setElementVolume(el, authorVolume, clipGain, unfadedVolume), isWebAudioOwned: (el) => webAudio.ownsElement(el), isWebAudioRouted: (el) => webAudio.routesElement(el), + seekUnderDip: (el, target) => webAudio.seekUnderDip(el, target), onAutoplayBlocked: () => { if (state.mediaAutoplayBlockedPosted) return; state.mediaAutoplayBlockedPosted = true; diff --git a/packages/core/src/runtime/init.videoPreseek.test.ts b/packages/core/src/runtime/init.videoPreseek.test.ts index ca9d6db548..61b77efbbf 100644 --- a/packages/core/src/runtime/init.videoPreseek.test.ts +++ b/packages/core/src/runtime/init.videoPreseek.test.ts @@ -3,56 +3,58 @@ import { mediaElementTime } from "./mediaClock"; import { initSandboxRuntimeModular } from "./init"; import { createMockTimeline, resetRuntimeFixtureDom } from "./runtimeSeekFixture.test-helpers"; -it("prepares a hidden video when playback enters its lookahead, after metadata arrives", () => { - resetRuntimeFixtureDom(); - let now = 0; - let id = 0; - const callbacks = new Map(); - vi.spyOn(performance, "now").mockImplementation(() => now); - vi.spyOn(window, "requestAnimationFrame").mockImplementation((callback) => { - callbacks.set(++id, callback); - return id; - }); - vi.spyOn(window, "cancelAnimationFrame").mockImplementation((key) => { - callbacks.delete(key); - }); - const step = () => { - now += 100; - const pending = [...callbacks.values()]; - callbacks.clear(); - for (const callback of pending) callback(now); - }; - document.body.innerHTML = - '
'; - const video = document.querySelector("video")!; - Object.defineProperty(video, "duration", { value: 20, configurable: true }); - Object.defineProperty(video, "readyState", { value: 0, configurable: true }); - Object.defineProperty(video, "paused", { value: true, writable: true, configurable: true }); - const play = vi.fn(() => { - Object.assign(video, { paused: false }); - return Promise.resolve(); - }); - video.play = play; - video.pause = vi.fn(() => { - Object.assign(video, { paused: true }); - }); - video.load = vi.fn(); - const seek = vi.spyOn(video, "currentTime", "set"); - window.__timelines = { main: createMockTimeline(6) }; - initSandboxRuntimeModular(); - window.__player!.play(); - for (let i = 0; i < 28; i++) step(); - expect(seek).not.toHaveBeenCalled(); - Object.defineProperty(video, "readyState", { value: 4, configurable: true }); - step(); - expect(video.style.visibility).toBe("hidden"); - expect(video.currentTime).toBe(mediaElementTime(8)); - expect(play).not.toHaveBeenCalled(); - for (let i = 0; i < 11; i++) step(); - expect(video.style.visibility).toBe("visible"); - expect(seek).toHaveBeenCalledTimes(1); - expect(play).toHaveBeenCalledTimes(1); -}); +it.each(["video", "audio"])( + "prepares an upcoming %s when playback enters its lookahead, after metadata arrives", + (tag) => { + resetRuntimeFixtureDom(); + let now = 0; + let id = 0; + const callbacks = new Map(); + vi.spyOn(performance, "now").mockImplementation(() => now); + vi.spyOn(window, "requestAnimationFrame").mockImplementation((callback) => { + callbacks.set(++id, callback); + return id; + }); + vi.spyOn(window, "cancelAnimationFrame").mockImplementation((key) => { + callbacks.delete(key); + }); + const step = () => { + now += 100; + const pending = [...callbacks.values()]; + callbacks.clear(); + for (const callback of pending) callback(now); + }; + document.body.innerHTML = `
<${tag} id="incoming" data-start="4" data-duration="2" data-media-start="8" src="/movie.mp4">
`; + const video = document.querySelector(tag)!; + Object.defineProperty(video, "duration", { value: 20, configurable: true }); + Object.defineProperty(video, "readyState", { value: 0, configurable: true }); + Object.defineProperty(video, "paused", { value: true, writable: true, configurable: true }); + const play = vi.fn(() => { + Object.assign(video, { paused: false }); + return Promise.resolve(); + }); + video.play = play; + video.pause = vi.fn(() => { + Object.assign(video, { paused: true }); + }); + video.load = vi.fn(); + const seek = vi.spyOn(video, "currentTime", "set"); + window.__timelines = { main: createMockTimeline(6) }; + initSandboxRuntimeModular(); + window.__player!.play(); + for (let i = 0; i < 28; i++) step(); + expect(seek).not.toHaveBeenCalled(); + Object.defineProperty(video, "readyState", { value: 4, configurable: true }); + step(); + if (tag === "video") expect(video.style.visibility).toBe("hidden"); + expect(video.currentTime).toBe(mediaElementTime(8)); + expect(play).not.toHaveBeenCalled(); + for (let i = 0; i < 11; i++) step(); + if (tag === "video") expect(video.style.visibility).toBe("visible"); + expect(seek).toHaveBeenCalledTimes(1); + expect(play).toHaveBeenCalledTimes(1); + }, +); afterEach(() => { window.__hfRuntimeTeardown?.(); diff --git a/packages/core/src/runtime/media.preseek.test.ts b/packages/core/src/runtime/media.preseek.test.ts index f259bcc574..16bd0e10d9 100644 --- a/packages/core/src/runtime/media.preseek.test.ts +++ b/packages/core/src/runtime/media.preseek.test.ts @@ -38,19 +38,22 @@ afterEach(() => { vi.restoreAllMocks(); }); -describe("hidden incoming video preparation", () => { - it("lands the in-point before the cut without playing or seeking it again at activation", () => { - const { el, seek, tick } = fixture(); - tick(0); - expect(seek).not.toHaveBeenCalled(); - tick(2.5); - expect(el.currentTime).toBe(mediaElementTime(8)); - expect(el.play).not.toHaveBeenCalled(); - tick(3); - tick(4); - expect(seek).toHaveBeenCalledTimes(1); - expect(el.play).toHaveBeenCalledTimes(1); - }); +describe("incoming media preparation", () => { + it.each(["video", "audio"])( + "lands a %s clip's in-point before the cut without playing or seeking it again at activation", + (tag) => { + const { el, seek, tick } = fixture({}, tag); + tick(0); + expect(seek).not.toHaveBeenCalled(); + tick(2.5); + expect(el.currentTime).toBe(mediaElementTime(8)); + expect(el.play).not.toHaveBeenCalled(); + tick(3); + tick(4); + expect(seek).toHaveBeenCalledTimes(1); + expect(el.play).toHaveBeenCalledTimes(1); + }, + ); it("retries after metadata arrives without interrupting an outstanding seek", () => { const { el, seek, tick } = fixture(); @@ -84,10 +87,10 @@ describe("hidden incoming video preparation", () => { expect(el.currentTime).toBe(mediaElementTime(8)); }); - it.each(["audio", "paused", "past", "export", "injected", "playing", "disconnected"])( + it.each(["paused", "past", "export", "injected", "playing", "disconnected"])( "leaves %s media untouched", (kind) => { - const { el, tick, seek } = fixture({}, kind === "audio" ? "audio" : "video"); + const { el, tick, seek } = fixture(); if (kind === "export") window.__HF_EXPORT_RENDER_SEEK_CONFIG = {}; if (kind === "injected") { el.id = "incoming"; diff --git a/packages/core/src/runtime/media.test.ts b/packages/core/src/runtime/media.test.ts index d5007530cb..c7f15d118a 100644 --- a/packages/core/src/runtime/media.test.ts +++ b/packages/core/src/runtime/media.test.ts @@ -1984,9 +1984,13 @@ describe("syncRuntimeMedia", () => { expect(clip.el.currentTime).toBe(mediaElementTime(5)); }); - describe("playing video drift", () => { - function playingVideoAt(currentTime: number, playbackRate = 1) { - const clip = createMockClip({ start: 0, end: 20, duration: 20 }); + describe("playing media drift", () => { + function playingVideoAt( + currentTime: number, + playbackRate = 1, + tag: "audio" | "video" = "video", + ) { + const clip = createMockClip({ start: 0, end: 20, duration: 20 }, tag); Object.defineProperty(clip.el, "paused", { value: false, writable: true }); Object.defineProperty(clip.el, "currentTime", { value: currentTime, writable: true }); clip.el.playbackRate = playbackRate; @@ -2001,13 +2005,15 @@ describe("syncRuntimeMedia", () => { getCompositionDuration: () => 20, }); - it("runs a video lagging past the sync tolerance 3% fast instead of seeking it", () => { - const clip = playingVideoAt(4.908); - tick(clip, 5); - tick(clip, 5); - expect(clip.el.playbackRate).toBeCloseTo(1.03, 9); - expect(clip.el.currentTime).toBe(4.908); - }); + it.each(["video", "audio"] as const)( + "runs a playing %s lagging past the sync tolerance 3% fast instead of seeking it", + (tag) => { + const clip = playingVideoAt(4.908, 1, tag); + for (let i = 0; i < 4; i++) tick(clip, 5); + expect(clip.el.playbackRate).toBeCloseTo(1.03, 9); + expect(clip.el.currentTime).toBe(4.908); + }, + ); it("runs a video that is ahead 3% slow", () => { const clip = playingVideoAt(5.06); @@ -2107,6 +2113,53 @@ describe("syncRuntimeMedia", () => { expect(clip.el.playbackRate).toBeCloseTo(1.03, 9); }); + describe("sounding audio past a gentle nudge", () => { + const tickDipping = (clip: RuntimeMediaClip, timeSeconds: number, dips: boolean) => { + const seekUnderDip = vi.fn(() => dips); + syncRuntimeMedia({ + clips: [clip], + timeSeconds, + playing: true, + playbackRate: 1, + getCompositionDuration: () => 20, + seekUnderDip, + }); + return seekUnderDip; + }; + + it("never nudges audio past 10% while its lag still grows", () => { + const clip = playingVideoAt(4.6, 1, "audio"); + tickDipping(clip, 5, true); + const seekUnderDip = tickDipping(clip, 5.02, true); + expect(clip.el.playbackRate).toBeCloseTo(1.1, 9); + expect(seekUnderDip).not.toHaveBeenCalled(); + }); + + it("seeks audio that holds a lag past 100 ms under a dip, at its authored rate", () => { + const clip = playingVideoAt(4.85, 1, "audio"); + tickDipping(clip, 5, true); + const seekUnderDip = tickDipping(clip, 5, true); + expect(seekUnderDip).toHaveBeenCalledWith(clip.el, 5); + expect(clip.el.currentTime).toBe(4.85); + expect(clip.el.playbackRate).toBe(1); + }); + + it("seeks it plainly when it has no dip to hide the seek under", () => { + const clip = playingVideoAt(4.85, 1, "audio"); + tickDipping(clip, 5, false); + tickDipping(clip, 5, false); + expect(clip.el.currentTime).toBe(mediaElementTime(5)); + }); + + it("leaves video on its steps", () => { + const clip = playingVideoAt(4.85); + tickDipping(clip, 5, true); + const seekUnderDip = tickDipping(clip, 5, true); + expect(seekUnderDip).not.toHaveBeenCalled(); + expect(clip.el.playbackRate).toBeCloseTo(1.1, 9); + }); + }); + it("steers a video that is far ahead slower, by the same steps", () => { const clip = playingVideoAt(5.2); tick(clip, 5); diff --git a/packages/core/src/runtime/media.ts b/packages/core/src/runtime/media.ts index 4eb4a295b6..8cd5447db7 100644 --- a/packages/core/src/runtime/media.ts +++ b/packages/core/src/runtime/media.ts @@ -13,6 +13,13 @@ import { findInjectedRenderFrame } from "./renderFrameSibling.js"; import { isRenderFrameVideo } from "./preloadMedia.js"; import { registerSeekCompletion } from "./adapters/seek-dispatch.js"; import { cutToHostSlots, type HostSlot } from "../mediaTiming.js"; +import { + forgetSteering, + isSteering, + MEDIA_SYNC_TOLERANCE_SECONDS, + steerMedia, +} from "./mediaSteer.js"; +export { MEDIA_SYNC_TOLERANCE_SECONDS } from "./mediaSteer.js"; export { readElementPlaybackRate, readElementRateSpec, @@ -250,7 +257,7 @@ export function evictMediaSyncState(el: HTMLMediaElement): void { strictDriftSamples.delete(el); seekLoadRetried.delete(el); lastRuntimeAppliedVolume.delete(el); - videoSteering.delete(el); + forgetSteering(el); } /** Test-only seam: whether any per-source sync state is still tracked for `el`. */ @@ -261,12 +268,12 @@ export function hasMediaSyncStateForTest(el: HTMLMediaElement): boolean { strictDriftSamples.has(el) || seekLoadRetried.has(el) || lastRuntimeAppliedVolume.has(el) || - videoSteering.has(el) + isSteering(el) ); } export const MEDIA_HARD_SYNC_SECONDS = 0.5; -export const VIDEO_PRESEEK_SECONDS = 1.5; +export const MEDIA_PRESEEK_SECONDS = 1.5; export function mediaSourceTimeAt(clip: RuntimeMediaClip, timeSeconds: number): number { const elapsed = Math.max(0, Math.min(timeSeconds, clip.end) - (clip.origin ?? clip.start)); @@ -280,7 +287,7 @@ export function mediaSourceTimeAt(clip: RuntimeMediaClip, timeSeconds: number): return target; } -function prepareUpcomingVideo( +function prepareUpcomingMedia( clip: RuntimeMediaClip, time: number, playing: boolean, @@ -290,9 +297,8 @@ function prepareUpcomingVideo( const dueIn = clip.start - time; if ( !playing || - el.tagName !== "VIDEO" || dueIn <= 0 || - dueIn > VIDEO_PRESEEK_SECONDS * rate || + dueIn > MEDIA_PRESEEK_SECONDS * rate || !el.paused || el.seeking || el.readyState < el.HAVE_METADATA || @@ -303,7 +309,7 @@ function prepareUpcomingVideo( const target = mediaSourceTimeAt(clip, clip.start); if (!Number.isFinite(target) || target < 0 || Math.abs(el.currentTime - target) <= 0.001) return; try { - // A trimmed video exposed during its in-point seek has no current frame at the cut. + // A trimmed clip seeked as it opens shows no frame and plays late, then is seeked again while it sounds. // Hidden preparation must not hold the visible-frame seek barrier. el.currentTime = mediaElementTime(target); } catch (err) { @@ -311,39 +317,9 @@ function prepareUpcomingVideo( } } -/** Drift a playing audio element may carry before sync pulls it back onto the playhead. */ -export const MEDIA_SYNC_TOLERANCE_SECONDS = 0.04; - // Chromium refuses a slower playbackRate (NotSupportedError). const MIN_NATIVE_PLAYBACK_RATE = 1 / 16; -// A playing video is steered back by rate, not seeked (a seek resets its decoder). -// Its rate is written only when steering starts or stops: every write costs a frame. -const VIDEO_STEER = 0.03; -// A video that starts a cut late closes its lag over one clip at 3%; a bigger lag steers harder, in steps so the rate is written rarely. -const VIDEO_STEER_STEPS: readonly (readonly [lag: number, steer: number])[] = [ - [0.3, 0.25], - [0.1, 0.1], -]; -const VIDEO_STEER_RELEASE_SECONDS = 0.01; - -/** Direction (+1 fast, -1 slow) a video is being steered in; absent when it plays at its authored rate. */ -const videoSteering = new WeakMap(); - -/** Rate for a playing video `offset` seconds behind (+) or ahead (-) of the playhead. */ -function steeredVideoRate(el: HTMLMediaElement, offset: number, baseRate: number): number { - const direction = Math.sign(offset); - const steering = videoSteering.get(el); - if (Math.abs(offset) > MEDIA_SYNC_TOLERANCE_SECONDS) videoSteering.set(el, direction); - else if (steering !== direction || Math.abs(offset) <= VIDEO_STEER_RELEASE_SECONDS) { - videoSteering.delete(el); - return baseRate; - } - const lag = Math.abs(offset); - const steer = VIDEO_STEER_STEPS.find(([from]) => lag > from)?.[1] ?? VIDEO_STEER; - return baseRate * (1 + direction * steer); -} - // fallow-ignore-next-line complexity export function syncRuntimeMedia(params: { clips: RuntimeMediaClip[]; @@ -389,6 +365,8 @@ export function syncRuntimeMedia(params: { forceSync?: boolean; /** How far the next tick will move the playhead: an audio clip due within it starts now. */ cueAheadSeconds?: number; + /** Seeks a sounding element under a gain dip; false when it has no dip stage and the sync seeks it plainly. */ + seekUnderDip?: (el: HTMLMediaElement, target: number) => boolean; /** Lets a video clip that runs to the composition end hold its last frame at the terminal time. * A thunk, because deriving the duration is only worth it for a clip past its own end. */ getCompositionDuration: () => number; @@ -589,12 +567,11 @@ export function syncRuntimeMedia(params: { (el.ended && canSeekEndedMediaBackward && drift > 0.001) || staleAudioOnFirstTick || (drift > MEDIA_HARD_SYNC_SECONDS && (firstTickOfClip || offsetJumped || catastrophicDrift)); - // Playing videos use the browser's decoder for timing. Seeking one resets the decoder: a - // ~150ms freeze while it re-buffers, as the monotonic clock advances, which loops into a - // seek→freeze→drift→seek stutter. So a playing video skips strict and force sync; only hard - // sync (>0.5s) warrants the decoder-reset cost. A paused transport pauses this video below, - // so a seek that pauses mid-playback still lands it. - const isPlayingVideo = el.tagName === "VIDEO" && !el.paused && playing; + // Seeking playing media resets a video's decoder (a ~150ms freeze that loops into a + // seek→freeze→drift→seek stutter) and jumps sounding audio (a click). So playing media skips + // strict and force sync and is steered by rate; hard sync (>0.5s) and audio past its steer + // limit seek. A paused transport pauses it below, so a seek that pauses mid-playback lands it. + const isPlayingMedia = !el.paused && playing; // Only apply strict sync when offset has stabilized (not growing). // During initial buffering, offset grows ~16ms/tick as the timeline // advances while media stays at 0. Accumulated drift from pause/play @@ -604,7 +581,7 @@ export function syncRuntimeMedia(params: { heldBelowFloor || (prevOffset !== undefined && Math.abs(offset - prevOffset) < 0.004); let strictSync = false; if ( - !isPlayingVideo && + !isPlayingMedia && !hardSync && !firstTickOfClip && offsetStabilized && @@ -619,21 +596,22 @@ export function syncRuntimeMedia(params: { } else if (drift <= MEDIA_SYNC_TOLERANCE_SECONDS) { strictDriftSamples.set(el, 0); } - const forceSync = !isPlayingVideo && params.forceSync && drift > 0.02; + const forceSync = !isPlayingMedia && params.forceSync && drift > 0.02; + const steered = + isPlayingMedia && !hardSync ? steerMedia(el, offset, baseRate, offsetStabilized) : null; + const steerSeeks = steered?.seek === true; + const dipped = steerSeeks && params.seekUnderDip?.(el, relTime) === true; try { - // A hard sync lands the video on the playhead, so its pre-seek offset says nothing. - if (!isPlayingVideo || hardSync) videoSteering.delete(el); - const rate = Math.max( - MIN_NATIVE_PLAYBACK_RATE, - isPlayingVideo && !hardSync ? steeredVideoRate(el, offset, baseRate) : baseRate, - ); + // A hard sync lands the element on the playhead, so its pre-seek offset says nothing. + if (!steered) forgetSteering(el); + const rate = Math.max(MIN_NATIVE_PLAYBACK_RATE, steered?.rate ?? baseRate); // Some engines read a rate back at lower precision; an equal-enough rate is not rewritten. if (Math.abs(el.playbackRate - rate) > 1e-6) el.playbackRate = rate; } catch (err) { // ignore unsupported playbackRate swallow("runtime.media.site1", err); } - if (hardSync || strictSync || forceSync) { + if (hardSync || strictSync || forceSync || (steerSeeks && !dipped)) { // Skip the per-tick seek (and the `el.load()` drift-recovery retry // below) for `