Repository navigation
feat(native): serve VOD loopback segments while they are written - #721
Merged
superuser404notfound merged 1 commit intoOct 8, 2026
Conversation
yipengfei329
marked this pull request as ready for review
October 7, 2026 14:13
yipengfei329
force-pushed
the
feat/progressive-segment-delivery
branch
from
October 7, 2026 17:07
767c5af to
44eacba
Compare
LoadOptions.progressiveSegmentDelivery (off by default) lets AVPlayer use a segment's first fragments instead of waiting for its cut, which on a slow link is the time to first frame. - The producer registers each VOD segment's staging file with the cache as it opens it, and the muxer flushes a fragment every 0.5 s instead of holding up to 8 s. - SegmentCache.fetchSource answers a segment being written with a ProgressiveSegmentReader over its staging file; the file is only appended to and renamed as it stands on adoption, so the reader sees a growing prefix of the final segment. - HLSLocalServer sends each read as a chunk and ends at the seal; an abandoned segment closes the connection without the final chunk so AVPlayer asks for it again. - Each chunk sent counts as fetch activity for the superuser404notfound#65 wedge watchdog, which otherwise reads one long transfer as AVPlayer no longer fetching. - aetherctl play --progressive-segments drives the option. Co-Authored-By: Claude Opus 5.5 <[email protected]>
yipengfei329
force-pushed
the
feat/progressive-segment-delivery
branch
from
October 7, 2026 17:14
44eacba to
e49f8c5
Compare
superuser404notfound
merged commit Oct 8, 2026
6263d42
into
superuser404notfound:main
4 checks passed
superuser404notfound
pushed a commit
that referenced
this pull request
Oct 8, 2026
…hat races their stat (#721) The cache remembered sealed staging files keyed by segment index and evicted the lowest indices first, so once 64 segments were adopted every later adoption below them evicted itself at once: after a backward seek each progressive reader read its own seal as abandoned, closed without the final chunk, and AVPlayer fetched every segment a second time. The memory is now keyed by staging file and evicted in adoption order. The reader judged a seal against the stat it took before asking for the state, so a last fragment written together with the seal in between read as abandoned. It stats again before giving up. Also moves sendChunkedBody's doc comment back onto it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
Owner
|
Thanks a lot for this, merged as 6263d42. It is exactly the focused, opt-in shape we discussed in #703, and the measurements in the test plan made it easy to review. I merged current main in on my side (only CHANGELOG conflicted) and the full suite passed on the result. Two things I found in review and fixed right after in 2c2b892:
Not released yet; it goes out with the next engine release. |
4 tasks done
superuser404notfound
pushed a commit
that referenced
this pull request
Oct 8, 2026
…hausted for a full segment volume (#720, #721) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
Owner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Summary
AVPlayer cannot use a loopback segment until it has the whole of it, and the producer only hands a segment over at its cut. On a slow link that is a whole segment at the link's rate before the first frame, and again after every seek outside the buffer. This adds an opt-in
LoadOptions.progressiveSegmentDeliverythat serves each VOD segment while it is being written. Off by default, so no host's behaviour changes. This is the progressive-delivery piece of #703 (MovieClaw P57) that you named as a candidate.What changed
SegmentCache.beginInProgress) and the muxer flushes a fragment every 0.5 s instead of holding up to 8 s. A failed cut, a failed final finalize and a discarded muxer abandon the segment (abandonInProgress).MP4SegmentMuxer.stagingURLexposes the current staging file.fetchSource(index:timeout:progressive:)answers a segment being written with aProgressiveSegmentReaderover its staging file. The muxer only appends to that file and adoption renames it as it stands, so an open descriptor reads a growing prefix of the final segment and the rename does not disturb it. The reader ends at the byte count recorded for the adoption, and reports.abandonedwhen the producer gives the segment up or writes nothing for 60 s. The cache remembers which staging file each recent adoption came from, so a reader never takes the same index produced again by a later epoch for its own.HLSSegmentProvider.mediaSegmentSource(at:onSlow:)(defaulted frommediaSegment) lets the provider return that reader;HLSLocalServersends each read as a chunk over the existing chunked response and the final chunk at the seal. An abandoned segment closes the connection without the final chunk, so AVPlayer retries the segment instead of taking a partial body for a whole one.didDeliverProgressiveChunk); a player that really stops reading fills the socket, and the count stops.nativeRemoteHLSor the software path, which serve no loopback segments. The option is a tuning field forreloadAtCurrentPosition(applying:).aetherctl play --progressive-segments, documented indocs/cli.md; the option is documented indocs/api.md.Test plan
Device / OS: MacBook Pro (Mac14,5, M2 Max), macOS 27.0.1, Xcode 27.0 (27A266a).
Source media: 1080p HEVC Main MKV, 2.7 Mbit/s, keyframes every 3-9 s, served over HTTP with byte ranges from a local origin paced to 6 Mbit/s (738 KB/s measured with curl).
aetherctl play --seconds 30, three runs each:PHASE playing--progressive-segmentsFragment cadence: at 1 s fragments the same runs played after 1.90 / 1.90 / 1.87 s, so 0.5 s was kept.
Seeks on the same origin (
--seek-every 8 --seek-count 3 --seek-pattern 1800,1790,3600): landings 561 / 6512 / 1265 ms with the option against 1199 / 6992 / 2253 ms without; no wedge declared, verdict OK in both.Local file (H.264 4:2:2 10-bit MKV) with the option: same first frame (0.20 s vs 0.19 s) and seek landing (69 ms vs 70 ms) as without, and no segment was served while written, as expected when the producer is ahead of AVPlayer.
A 25.5 Mbit/s 4K title over a link well below its rate never showed a frame within 40 s without the option and showed one at 3.5 s with it; it cannot play through there either way.
New
ProgressiveSegmentDeliveryTests(8): the reader follows a growing staging file to the seal, survives the adoption rename, reports an abandoned segment and an idle producer; the option off waits for the cut; over real sockets the server sends the head before the cut and the complete chunked body at the seal, and ends an abandoned segment without the final chunk; the option defaults off and is a tuning field.Full
swift test --jobs 8: 718 XCTest cases (1 skipped) and 4,092 Swift Testing cases in 568 suites, all passing.Scripts/check-doc-links.pypasses.Checklist
CHANGELOG.mdupdatedfeat(...),fix(...),chore(...))LoadOptions.progressiveSegmentDelivery)🤖 Generated with Claude Code