Repository navigation
Description
Summary
When the source URL is fronted by an origin that rejects HEAD, AVIOReader.probeFileSize() logs:
[AVIOReader] HEAD failed (HTTP 405) → streaming mode
…and falls back to streaming mode (sequential GET, no Range). In streaming mode AVIOReader.seek returns -1 for SEEK_SET / SEEK_END whenever fileSize < 0, which means:
- Containers whose demuxer seeks on open fail to load. MKV / WebM place
Cues(seek index) at the end; non-faststart MP4 / MOV placemoovat the end; AVI places its index at the end. FFmpeg's demuxer issuesavio_seek(SEEK_END)insideavformat_open_inputfor these, so the open fails (or degrades). - Even containers that open successfully (fragmented MP4 with
moovat front, HLS-style sources, MPEG-TS) become unscrubbable —SEEK_SETreturns-1, so any user-initiated timeline seek is rejected.
So streaming mode is a strict regression for any source that's actually seekable on the server — which the HEAD-rejecting origins observed here are.
Reproduction
Observed with an AIOStreams URL that 307-redirects to a tb-cdn.st origin. The origin rejects HEAD but accepts Range GET:
$ curl -I '<aiostreams URL>'
HTTP/2 307 # redirects to origin
$ curl -r 0-0 -I '<redirected origin URL>'
HTTP/1.1 405 Method Not Allowed # origin rejects HEAD
$ curl -L -r 0-0 -s -o /dev/null -D - '<aiostreams URL>'
HTTP/1.1 206 Partial Content # but accepts Range GET
Content-Range: bytes 0-0/<TOTAL>
Likely affects any other source that proxies to the same origin family. Progressive / fragmented MP4 sources (YouTube etc.) still open and play, but the user loses the ability to scrub.
Fix
Replace the HEAD probe with a Range: bytes=0-0 GET that cancels in didReceive response (so the body never streams). Fall back to HEAD if the Range probe doesn't yield a size. Three details matter, all of which were necessary to make this work end-to-end against a real Cloudflare-fronted CDN:
-
Explicit redirect handler that preserves the
Rangeheader. URLSession's defaultwillPerformHTTPRedirectionbehavior drops custom request headers on cross-host redirects. Without an explicit handler the redirected GET arrives at the origin withoutRange, and the origin (here AIOStreams' Express proxy) returns400 Bad Request. Implement the delegate method and copytask.originalRequest?.value(forHTTPHeaderField: "Range")onto the new request. -
Per-task delegate on the existing
URLSession, not a freshURLSessionper probe. Creating an ephemeral session per probe forces a new TLS handshake every call and varies the TLS fingerprint, which makes Cloudflare-fronted origins intermittently slow or bot-flagged on repeat probes. iOS 15+ allowstask.delegate = ...for per-task delegate callbacks while reusing the session's connection pool. -
Generous timeout. The redirect chain (proxy → CDN) plus a cold TLS handshake can take 5–10 s under load. A 5 s
request.timeoutIntervalrejects healthy responses; 20 s leaves comfortable headroom.
This is also how AVPlayer / QuickTime probe file size, and matches the existing StreamingDelegate pattern in the same file (stateless let-only delegate, satisfies strict concurrency).
Optional follow-up
AetherEngine.load(url:) opens a probe Demuxer and an HLSVideoEngine Demuxer against the same URL, so probeFileSize() runs twice per load. Caching the result keyed by URL would halve the probe traffic and reduce the chance of hitting upstream rate-limits on retried playback attempts.
Happy to open a PR.
Activity
feat: publish activeVideoDecoder + activeAudioDecoder for diagnostic UIs
superuser404notfound commentedon May 22, 2026
Fixed in
83a6d21, shipped to Sodalite pin in5d36129f. Implemented the spec end-to-end:bytes=0-0GET cancelled indidReceive responseso the body never streams. Parses total size fromContent-Range: bytes 0-0/<TOTAL>on 206, also accepts plain 2xx with positiveContent-Lengthfor origins that ignore Range entirely.willPerformHTTPRedirectionhandler on the task delegate that re-setsRangeand the caller-supplied extra headers on the redirected request. Without this URLSession's default strips them on cross-host redirect.probeSession(separate from the per-request session pattern used insyncRequestfor chunk-fetch leak control).AetherEngine.load()probes twice per call (probe Demuxer + session Demuxer); the shared session keeps the TLS connection warm + fingerprint stable across the pair, which avoids the bot-flag scenario you described.The follow-up about double-probing per
load: still on my list. I want to cache the size keyed by URL + extra-headers hash insideAetherEngineso the secondDemuxer.open(url:)skips the probe entirely. Probably ships in a separate commit after I review the lifecycle ofextraHeaders(they can change mid-session for auth-token refresh on long-form Jellyfin sessions, and the cache key needs to invalidate cleanly when they do).Thanks for the detailed writeup, the three-part requirement set saved a lot of debugging the Cloudflare interactions from scratch.
fix(avio): replace HEAD probe with Range bytes=0-0 GET, fall back to …
feat(engine): publish sourceVideoFormat alongside videoFormat
fix(avio): stop replaying credential headers on cross-origin redirects (
fix(prewarm): a warm hands over its resolved target, its Matroska tai…
feat(audio): TrueHD object decoder and allocentric renderer for Atmos (…
feat(sw-decode): keep native chroma subsampling and bit depth in the …
fix(sw-decode): build the swscale context with the buffer's range and…
perf(sw-decode): copy planar 4:2:2 / 4:4:4 into the bi-planar buffer …
chore(report): name the 4:2:2 / 4:4:4 / 16-bit display buffers; docum…
feat(sw-decode): keep native chroma subsampling and bit depth in the …
fix(sw-decode): build the swscale context with the buffer's range and…
perf(sw-decode): copy planar 4:2:2 / 4:4:4 into the bi-planar buffer …
chore(report): name the 4:2:2 / 4:4:4 / 16-bit display buffers; docum…
feat(hls): segment N is the same bytes however playback reached it