Repository navigation
feat(web): direct play reads a file over parallel range connections - #4497
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Related issue: #4439
Validation tasks: changes #1177 C2, C3; changes #1178 C2
Other clients: Apple N/A (does not send
parallel_range_origin_v1, so its plans do not change; a direct play through a proxy node stays counted on the node for up to 60 s after its last request, on every client); Android N/A (same); Roku N/A (same)In the web app, a direct-play file is read over one HTTP connection. On a long or lossy link, one connection moves only a fraction of what the link can carry, so playback stalls while the link has spare room. This affects viewers far from the server, and the administrators who serve them. This change reads the file as several byte ranges at once, over separate connections, in the browser's decode engine. The engine plays files the browser's media element cannot take as they are. The proposal is in #4435.
Approach
The reader. A Mediabunny source keeps Mediabunny's read orchestrator, cache and prefetch profile and changes only how bytes arrive. Each read worker sends closed ranges of 2 MiB, with at most 4 in flight per source. The first 16 MiB of each read (the warm head) comes from the plan's own URL while the extra connections warm up. A range that finds the stripe URL busy goes to the plan's URL. The first answer from the stripe URL that is not a readable 206, or the first transport failure there, sends the rest of that range and every later range to the plan's URL, with no retry spent on the stripe URL. A stripe body that runs past its range moves the read to the plan's URL the same way.
The engine stripes only when the plan names a stripe URL in
stream.parallel_range_url, and it uses that URL exactly as given. The server names one of three:stream.urlalready carries. With the default routing (playback.routing.direct_play_egress=prefer_proxy) this is the usual case on a deployment with proxy nodes, and it needs no setting.server.web_media_urlis set: the same stream on that media origin, an https address that serves the same API over HTTP/1.1 only. It is for a deployment whose main address speaks HTTP/2.HTTP/2 and HTTP/3 put every request to an origin on one connection, so parallel ranges there add requests and no connections. After a completed range the reader asks the browser which protocol the striped URL answered over, and returns to Mediabunny's stock
UrlSourcewhen it was HTTP/2 or HTTP/3. A browser that does not say leaves it striping. When the stripe URL is the plan's own URL (a node, or the page's origin) there is one URL: every range uses it, up to 4 at once, and a transport failure is retried there like any read's. Without a stripe URL the engine reads the plan's URL through the stockUrlSource, over one connection, as before. A plan URL that ignoresRangeand answers the open with the whole file also plays through the stock reader, in order. The reader wraps the prefetch profile it finds and takes the larger of its own read-ahead end and the inner profile's end, so a read-ahead change on the plainUrlSourcepath composes with it in either order. Mediabunny is pinned to1.62.1instead of^1.62.1, because the source readsUrlSourceand orchestrator internals.The server.
New admin setting
server.web_media_url: an https origin that serves the same API over HTTP/1.1 only. Empty names no media origin, and a change applies without a restart. It is named only for a client that arrived by the default access path; one that came through a network access provider gets the plan's own stream.New client feature
parallel_range_origin_v1: the client's promise to usestream.parallel_range_urlexactly as given, adding no account token to it, when the plan has one, and to readstream.urlotherwise. The server sets the field on anoriginal_httpplan as listed above. The two API forms carryst, which authorizes only an attempt a login session started, so only such an attempt gets them.stream.urlstays valid either way.GET,HEADandOPTIONSon/api/v2/stream/{session_id}answer withAccess-Control-Allow-Origin: *, allow theRangeheader and exposeContent-Range, with no credentials.GETandHEADcarry these headers on every answer, refusals included, so the page can read a refusal. The preflight is answered before authentication. It carriesAccess-Control-Max-Age: 600and writes no activity-log row. Authorization stays in the URL's token andst. No other route gains CORS. The API's and a node's stream answers carryTiming-Allow-Origin: *, so the reader can learn the connection's protocol.On the native stream routes, a request from byte 0 or with no
Rangeheader writes an activity-log row, as before. A range that continues a play (it starts past byte 0) writes a row only when it fails; one that succeeds, or that the client abandons (499), writes none. AGETanswered200keeps its row whatever its range: a progressive remux started again from its origin is a new stream. The Jellyfin stream routes still write one row per request; matching them is a possible follow-up.On a proxy node, a direct-play session stays counted between range requests: the last request to end keeps it for the 60 s session TTL when it delivered media. A
HEAD, a refusal or an unsatisfiable range adds no such hold and ends none that is running, and the session's record expires with its count. A plain hold for the session, as a remux after a replan takes, ends a running linger; while holds of both kinds overlap, the latest one decides. Without this a striped play dropped out of the node's capacity count and the admin's node-session list in every gap between ranges.Credentials. The stripe URL always authorizes itself:
ston the API forms, the token in the path of a node's URL. The player uses it as given and adds no account token, header or cookie; an earlier revision had it append the access token to a URL withoutst, which would have sent a login token to a node. The server never names a node's header-authorized route, and an attempt that negotiatedheader_authenticated_media_v1gets no stripe URL. An attempt with no login session, such as one an API key started, gets none on the API routes. It readsstream.url, which keepsstand the token and can still rebuild an evicted session. Every other playback URL keeps the token it carries today.The contract change is one optional field (a URL reference) and one feature name.
docs/playback-api.md,docs/architecture/playback-protocol-v3.mdanddocs/architecture/api-contract.mddescribe them, and the OpenAPI document, the web types and the playback fixtures are regenerated.The meter. The engine's throughput meter now counts the time each response was receiving, from its first body chunk to its latest, and counts overlapping time once. Bytes from parallel ranges are divided by that union, not by the sum of each range's time. The striped source counts all its ranges into one request and keeps that union as merged stretches, so a long play does not grow the list by one entry per range. A stock read stays a request of its own, so the meter's 1,000 ms rule applies to it as before.
Seeks. A seek that finds both read workers busy no longer waits for their read-ahead. At the seek, each queued read is cut to the bytes Mediabunny still waits for. When the seek's first read then finds both workers running, each older worker is cut to the bytes its waiting reads need, and its ranges that hold none of those bytes are cancelled. The older worker that owes the fewest bytes stops at once, its unmet bytes go back on the queue, and the seek's read takes its place and the first free connection. In a Node run of four seek patterns on two Matroska files over a 2 MiB/s throttled link, the wait from the last seek to its first request fell from 5.27-7.84 s to at most 0.01 s, and the first video packet came 1.04-2.72 s after the seek instead of 7.31-10.97 s. A read the replaced playback makes after the seek still counts as new. A seek whose first read asks for the same hole as a read queued before it (near the end of the file) retires a worker like any other, and the new worker takes the queued reads it covers.
HTTP/2 multiplexing was not an option, since it puts every request on the one connection this change needs to get away from. Adaptive range sizes and four fixes for faults found in a real-browser test follow in the next pull request.
The web changes add no user-visible text, and the setting has no settings-page label, so there are no
silo-translationskeys.Validation
e775bf9, including the database pins and the Prometheus rules test. The last commit changes only comments; its focused tests, lint, size and local-path checks pass.stand no token, and each 206 allowed the origin and exposedContent-Range. Playback reached 30 s with no alert. A seek to 70 s and then back to 50 s played on from 50 s. The play left one activity-log row on the stream route, a206.eff92e0d2a(fd99395415,0647945ded): each new or changed test fails ond8f12d469c. On a dev deployment built from that head, Chrome on the engine route sent 148 ranges to an HTTP/1.1 media origin (up to 3 at once, each withstand no token) and 24 to the plan's URL, three seeks sent their first range within about 100 ms, a seek into the last 20 s played on, the credits Skip control worked, the play left one activity-log row, and an explicit preflight answered204withAccess-Control-Max-Age: 600and left no row. The maintainer's summary comment links that run's evidence page.83deb583f2(afd2ef25df,9dfa390083,a53a9bea38,faea666732,9c10b806a6,4b0c0693f5,b179fb9d16,a9b35d052f,bfc766b3a6,83deb583f2): restores striping on a proxy node's URL and on the page's own origin, which round 1 had asked to remove. Each new or changed test fails on the earlier head. On a dev deployment with proxy nodes, in Chrome on the engine route (the node runs on a build of83deb583f2, the API-served runs on9c10b806a6): through a node over HTTP/2 the reader sent a few ranges and returned to the stock reader (19 requests); through a node over HTTP/1.1 it striped for the whole play (164 closed ranges, up to 4 in flight, no account token), and the node listed the session during play and 30 s after the browser closed, and not at 75 s; API-served over HTTP/1.1 it striped on the page's origin (164 ranges, one activity-log row); API-served over HTTP/2 it used the stock reader (19 requests); with a media origin it striped there (132 ranges withstand no token). Three seeks worked in every run. The maintainer's summary comment links that run's evidence page.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-4497/
Surface and build: web player, browser engine route. The page names the build of each result. It holds the first round's gate, Chromium request lists and a lab measurement of startup, stalls and throughput against the single-connection reader on a 350 ms, 1% loss link; its
h1cell measured the same-origin rule this round removes. Its last section holds this round's gate, the browser request list with the seek check, and the Node seek table.Risks
stin the URL.max_jobs, and shows in the admin's node-session list, for up to 60 s after its last request. That is the reason for theValidation tasks:line: Distributed transcode nodes — Server #1177 C2 and C3 and Distributed transcode nodes — Web admin #1178 C2 should be walked again. The planner's own admission has older gaps this does not close (it drops a reservation when a newer health report arrives, and reservations are per API server).server.web_media_urlis classed as a server-specific setting, so a restore onto another server does not carry it.Checklist
AI Disclosure
claude-opus-5-5,claude-sonnet-5-5(Claude Code);gpt-6.1-sol(Codex CLI)claude-opus-5-5in Claude Code,gpt-6.1-solin Codex CLI) read the change twice, on the rebased branch and on the finished stack, and aclaude-sonnet-5-5seat merged each pair's findings. They ran mutation checks on the tests they relied on. The first round found two High defects in the lingering session hold, and both were fixed and re-run. The second found a Medium defect, a failing media origin failed the read instead of falling back to the plan's URL, and a few documentation and comment errors. All were fixed and checked by a separateclaude-sonnet-5-5seat. For the maintainers' second round, agpt-6.1-solseat reviewed the plan before any code was written, the same two-model pair reviewed the result (one Low finding, fixed), and a separateclaude-sonnet-5-5seat checked each change against the code. The seek fix went through the same steps: the pair compared designs and reviewed the plan, then reviewed the result (three Low comment findings, fixed), and a separate seat checked the change against the plan. The maintainer's review fixes and rework (fd99395415,0647945ded,3c4b1edc2b, and the commits fromafd2ef25dfto83deb583f2) were written in Claude Code withclaude-fable-5-2.gpt-6.2-solandclaude-opus-5-5reviewed the fix plan first;gpt-6.2-astra,gemini-4-neonand an independentclaude-fable-5-2reviewed the design of the proxy-node rework before it was written, and each changed it.Note
Add parallel range connections for direct play of original files
parallel_range_origin_v1playback feature and optionalstream.parallel_range_url. The server publishes it for eligible original-HTTP deliveries (playback_v3.go), and the web player reads the file through a newParallelRangeSourcethat stripes requests over the plan URL and optional stripe URL (parallelRangeSource.ts).Timing-Allow-Originhandling for the original-file stream route, including unauthenticated OPTIONS preflights (playback_delivery.go).nodesessions.Tracker.HoldLingering, which keeps a direct-play session alive across the gaps between striped range requests when at least one request delivered media (tracker.go).createMeteredFetchreports merged receiving-time spans, and throughput now uses unioned receiving time instead of each request's full first-to-last interval (mediaFetch.ts, media-data-meter.ts).server.web_media_urladmin setting (bare HTTPS origin) and a new stream-path filter that omits range-continuation and preflight requests from activity logging.mediabunnyis now pinned to exactly1.62.1becauseParallelRangeSourcedepends on Mediabunny internals (mediabunnyInternals.ts); upgrading requires re-checking that internal surface.MediaDataMeter.throughputKbpschanges how throughput is computed for striped reads.Macroscope summarized 83deb58.