~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0

Videos play Bluesky's HLS, and the blob proxy serves them as they arrive

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/hud:video/hls-and-streaming

A post's video buffered so slowly on the web and iOS that it was hard to watch. Bluesky's videos now play its own adaptive HLS from its CDN wherever the platform plays HLS itself. The blob proxy, still the fallback and still what plays other apps' video and audio, now serves a blob as it arrives, downloaded once.

Claude Opus 5.5 · low

What changes

Bluesky's HLS. The resolved video embed has hls, the post's playlist, only where it is https://video.bsky.app/watch/… (blobs::VIDEO_ORIGINS). The web's <video> lists it first, typed application/vnd.apple.mpegurl, then the proxy, so Firefox, which plays no HLS, falls back to the proxy. iOS's AVPlayer plays hls ?? src. A video with an hls but no src plays too, and gets no "Play on Bluesky" link. Both CSPs already allowed video.bsky.app and video.cdn.bsky.app through the bundled Bluesky views' origins; tests now hold them to it. place.hud.ui grows an optional hls. The AGENTS.md rule on what the view loads now names Bluesky's video service and CDN.

The proxy serves audio and video as they arrive. BlobCache::fill downloads a blob once per DID and CID, in a task of its own that keeps going after the requester leaves. Every request for it, the first and any that come while it downloads, reads the scratch file as it grows (Filling::read), against the length the PDS said. A blob's last byte is held back until the whole hashes to its CID, so no read of it completes unverified. A PDS that gives no length is answered once all of it is kept, as before. BlobCache::put is gone. Cached blobs are read in 64 KiB chunks rather than ReaderStream's default 4 KiB.

Why

Measured against hud.place:

  • A cold blob sent nothing until the proxy had all of it from the PDS and its hash matched: 2 s for a 10 MB video, and each parallel cold request downloaded it again.
  • Warm, every byte came from one server in Falkenstein at the upload's own bitrate: ~180 ms RTT from here, 1.2–3.8 MB/s, ~1.7 s per 1 MB range. In Chrome the buffer stayed ~2 s ahead of playback.

Bluesky's HLS is adaptive (360p/720p, 6 s segments) and served from BunnyCDN's edge. It needs no hls.js: AVPlayer, Safari and Chrome 150 play it natively.

Sharing a download only within one DID keeps one PDS's bytes from being served for another account's URL before they are verified.

How it was checked

just check passed, with lines and functions at 100%. New tests:

  • blobcache: readers follow a download; the last byte waits for the hash; reads end in why for a mismatch or for a blob shorter than said.
  • blob.rs: a video served in ranges before its second half arrived, from one PDS request.
  • embed.rs: when hls is set.

A local hud serve proxying a real 10 MB Bluesky video answered bytes=0-1 cold in 0.93 s; a joined bytes=0- started in 2 ms and streamed at PDS speed. Kept bytes hash to the CID.

In headless Chromium 150, under the workspace's media-src:

  • With the HLS source, currentSrc was the playlist and it played at 360p.
  • Without it, it played from the proxy.

The iOS app builds for the simulator.

Shortcomings

  • Not played on an iOS device or simulator, and not in Firefox. The fallback was proven only by leaving the HLS source out.
  • Bytes before a blob's last one reach a player before they are verified, as images' bytes always did.
  • Two requests that miss at the same instant can still each start a download.
  • The CSPs rely on the bundled Bluesky views naming the two video origins.

Review

Start at Filling::read and Download::run in crates/hud-core/src/blobcache.rs.

Approved

This pull plays Bluesky's HLS (hls) where the platform plays it. It also makes the blob proxy download each audio or video blob once per DID and CID, and serve it while it arrives. I read every changed file and found nothing that must change.

  • Filling::read and Download::run: readable holds back the last byte until the hash matches. If a blob is shorter than the PDS said, a read ends in an error. If it fails, the scratch file is removed and the in-flight entry is dropped before done is sent, so a later request starts a fresh download. The readers' open file handle survives both the rename into the cache and eviction.
  • Stalled PDS: the PDS request already carries .timeout(BODY_WAIT), which covers the body. A stalled PDS can therefore hold a detached download for 120 s at most.
  • hls gating: the resolver accepts a playlist only on https://video.bsky.app under /watch/. The tests cover http, another host, another path and a bad URL. The schema, the types, the web player and the iOS player all carry the field, and the CSP tests check the two video origins.

Two small things you may already know:

  • On iOS, if the HLS stream fails, AVPlayer has no fallback to src. The web has one through the second <source>.
  • The same-instant double download is a gap you already list.
Merged as 7b6e57d