Skip to content

fix(files): stream side-panel videos in byte ranges and stop 2-second full-file re-reads - #1854

Merged
bvsr365 merged 1 commit into
masterfrom
fix-files-video-player-lag
Nov 25, 2026
Merged

bvsr365 merged 1 commit into
masterfrom
fix-files-video-player-lag

Conversation

@bvsr365

@bvsr365 bvsr365 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Problem

Playing a video in the Files side panel lags and stutters heavily, freezes briefly on open, and fails on files over 100 MB.

Two causes compound:

  1. Every 2 seconds, FilesPanel re-reads the entire video file through the daemon (files.readAsset in 8 MiB base64 chunks), reassembles it in the main process, clones the full buffer over Electron IPC into the renderer, hashes it, and discards it. With no in-flight guard and polling continuing while the panel is hidden, slow transfers pile up and stall playback.
  2. Opening a video buffers the entire file into memory, copies it byte-by-byte via Uint8Array.from on the renderer main thread, and hands <video> an in-memory blob: URL instead of streaming byte ranges on demand.

Expected behavior: videos open promptly, stream and seek smoothly without periodic stalls or large renderer memory spikes, and keep playing cleanly while unchanged on disk.

Change

  • Byte-range media streaming (mousse-media://): Registered a privileged streaming scheme (stream: true) on the main window's default session (src/main/ipc/mediaStream.ts, src/main/index.ts, src/main/ipc/registerGuiIpc.ts, src/preload/index.ts). Opening a video calls fs:openMediaUrl, which validates the file via one 1-byte files.readAsset call through the daemon and returns an opaque per-window, per-profile mousse-media://asset/<token> URL. Chromium's <video> streams HTTP 206 Partial Content byte ranges in 1 MiB chunks on demand and cancels cleanly on seek or close; handles are released when a tab closes, reloads, or the window closes.
  • Stop 2-second full-asset re-reads: FilesPanel now checks fs:assetStamp (size + write time via 1 byte) only for the active preview tab while the panel is showing and the window is visible, guards against overlapping in-flight polls, and reloads a video or image only when its stamp changes.
  • Avoid renderer main-thread copy and fit video viewport: Replaced Uint8Array.from with a zero-copy Uint8Array view for Blob URL creation (images/PDFs), added preload="metadata" and playsInline to <video>, and constrained .files-video-preview with flexbox (overflow: hidden) so high-resolution videos fit inside the panel without scrollbars.
  • Large video range limit: FileService.readAssetRange allows streaming video files up to 4 GiB while readAsset and readAssetInPieces keep the 100 MiB cap for whole-file reads.

Verification

Tier 4 (cross-area: daemon FileService, main process protocol and IPC, preload, renderer FilesPanel).

  • Automated tests and typechecks (current for published commit 16804ce6e):
    • PASS tests: 9 file(s), 104 test(s)
      • $ npx vitest run tests/mediaStream.test.ts tests/fileServiceAssets.test.ts tests/mainFolderAccess.test.ts tests/filesByThread.test.ts tests/renderer/filesPanelVideo.test.ts tests/renderer/filesPanelFinalClose.test.ts tests/renderer/filesPanelEmpty.test.ts tests/renderer/filesPanelSearch.test.ts tests/renderer/fileLinksHeld.test.ts
      • Covers parseByteRange, MediaStreamRegistry 200/206/416/HEAD/cancel/profile-binding/cleanup (tests/mediaStream.test.ts), >100 MB video range reads vs 100 MB cap on whole reads and images (tests/fileServiceAssets.test.ts, tests/mainFolderAccess.test.ts), and FilesPanel streaming open, 2-second stamp-only polling, in-flight deduplication, hidden-panel pause, disk-change reload, and unmount cleanup (tests/renderer/filesPanelVideo.test.ts).
    • PASS typecheck:node: no errors
      • $ tsc --noEmit -p tsconfig.node.json
    • PASS typecheck:web: no errors
      • $ tsc --noEmit -p tsconfig.web.json
    • eslint on all modified/added source files: 0 errors.
  • Direct real-Electron check: Ran Electron 43 with MOUSSE_MEDIA_SCHEME_PRIVILEGES, MediaStreamRegistry, attachMediaProtocol, and FileService.readAssetRange against a generated 6-second 1280×720 30fps WebM in a 480×400 window styled with .files-video-preview. Verified loadedmetadata (duration: 6, 1280×720), HTTP 206 byte-range seek to 4.0s (Chromium fetched the tail seek index at offset 2981888), playback to 4.6s with 143 frames decoded and 0 dropped frames, and hasScrollbars: false / fitsInsideBox: true.
  • Not checked live: Remote Bridge video playback and Windows/macOS real-window playback (the range protocol uses the existing routed files.readAsset(offset, length) method unchanged).

Notes

No issue

@bvsr365
bvsr365 merged commit 71786f0 into master Nov 25, 2026
9 checks passed
@bvsr365
bvsr365 deleted the fix-files-video-player-lag branch November 25, 2026 10:20
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