Starweb dev log #9
Media streams now instead of downloading the whole file first.
A big MP4 used to sit there until every byte landed. Now there’s a MediaSource: a seekable view of the remote file that fills in as it’s read, so the decoder starts on the first megabyte while the rest is still downloading.
It runs on Range requests. The server advertises Accept-Ranges: bytes and answers bytes=a-b, bytes=a-, or bytes=-n (trailing bytes, how a player finds an MP4’s moov atom) with 206. Bad or multi-range requests get 416. It streams the file out in chunks rather than loading it into memory, so the server side is cheap too.
On the browser, chunks land in a sparse cache file in 64KB pieces, and a read only blocks on the chunks it touches. A .ranges sidecar tracks what’s present; once it’s all there, the file is the cache entry. Seeking doesn’t wait behind the sequential download; hint_seek steers the prefetcher to where you jumped. Both backends got wired in: FFmpeg through custom IO, macOS through AVAssetResourceLoader.
Cache pruning counts real bytes on disk now and cleans up the .ranges sidecars, and there are range tests on the Python side (bytes=a-b, EOF, suffix, 416, clamping).
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.