Repository navigation
Description
What happened?
Following up on #168 — while root-causing the HEVC-in-MPEG-TS black screen, I hit three separate issues on the ingest/loopback live path. Grouping them since they surfaced together and two of them are on the exact path #168's reroute now funnels these streams down. I have all three implemented and field-verified on Apple TV 4K (tvOS 26);
-
HLSLiveIngestReader fetches segments serially → ingest capped near real-time.
The runIngest segment loop awaits each fetchSegment fully before starting the next, so every fetch pays a connection + TTFB round-trip with no bytes flowing, never overlapped. On a 4K50 HEVC/TS stream (~13 Mbps) the producer can't get ahead of the playhead (videoPtsAdvance ≈ 4.5s/10s; segment cache stuck at ~5). Fix: a bounded prefetch pipeline — N (≈4) fetches in flight concurrently, committed to the FIFO in order (in-flight bytes held in memory, decoupled from FIFO backpressure; ordered write still paces the demuxer). Cache built to 15+ on the same stream after this. -
HLSSegmentProducer no-cut watchdog force-retunes slow-but-healthy streams.
The watchdog retunes on wall-clock since last finalize (liveSegmentStallTimeoutSeconds 10 s once readRate ≥ liveWedgeProgressRateThreshold 40 pkt/s), regardless of whether video is still flowing. On a source delivering just below real-time, a 6 s segment simply hasn't fully arrived in 10 s — video PTS is still advancing — but it's classified a "cutter wedge" and retuned, which re-joins behind the live edge and can't catch up (repeated videoPtsAdvance=4.5s … cutter wedge … exiting for host retune, buffer drained each time). Fix: gate the retune on PTS advance — if PTS is advancing (≥ ~2 s in the window), hold and re-arm instead of retuning; only retune when PTS is genuinely frozen. Bounded by a max consecutive-holds count. -
Software decode path ignores SAR/PAR → anamorphic renders as a strip.
AVSampleBufferDisplayLayer reads display aspect from the CMVideoFormatDescription PAR extension, but the software path builds/caches the format description without it, so non-1:1 pixel-aspect content collapses to its coded dimensions (a thin strip); the AVPlayer/loopback path is fine. Aggravators: the format-desc cache key omits PAR (a PAR-less description is frozen and reused), and AVCodecContext.sample_aspect_ratio can be garbage (1088:1) or oscillate per-field on interlaced content. Fix: read SAR (frame → codec ctx → stream, first sane wins), attach it to the format description, add parH/parV to the cache key, latch it once per stream, and sanity-gate (reject num/den ≤ 0 or > 256).
Details, code references, and logs per issue available if useful
Steps to reproduce
The common repro stream is a single-variant live HLS master advertising CODECS="hvc1.2.2.L153.B0,mp4a.40.2", delivering MPEG-TS segments (.ts, no EXT-X-MAP), HEVC Main10 3840×2160 @50fps, ~13 Mbps. Since #168 now reroutes that onto the ingest/loopback path, tuning it exercises issues 1 and 2 directly. Where a stream like that isn't handy, a synthetic option is given.
Issue 1 — serial ingest fetch caps throughput
- Play a high-bitrate (≥ ~10 Mbps) live HLS/TS channel through the ingest path — either via the HDR10 4K HEVC 50fps live HLS via nativeRemoteHLS: AVPlayer exposes no video track (audio-only, black); no HDR display-criteria negotiation. VLC + Android decode it fine #168 reroute (HEVC-in-TS master) or directly with AetherEngine.load(source: .custom(HLSLiveIngestReader(playlistURL:…), formatHint: "mpegts"), options: ).
- Set LoadOptions.forwardBufferSegments = 30 to remove buffer-window as a variable.
- Watch the producer telemetry / memprobe: cacheCount and videoPtsAdvance.
Expected: on a link that can pull faster than real-time (a browser/VLC on the same box keeps well ahead), the cache fills toward the window. Actual: cacheCount plateaus at ~4–5 segments and videoPtsAdvance ≈ half of wall-clock — the reader never gets ahead, and playback rebuffers.
Synthetic (no IPTV needed): serve 6 s / ~12 Mbps TS segments from a local HTTP server that adds ~300 ms latency before the first byte of each segment response. Serial fetch caps throughput at segDuration / (segDuration + TTFB) of the link; a parallel-prefetch reader saturates it. The bug scales with TTFB ÷ segment duration.
Issue 2 — cutter retunes slow-but-healthy live
- Play a live HLS/TS stream whose delivery runs just below real-time (or where a source segment takes > 10 s wall-clock to fully arrive) while packets keep flowing — high-bitrate over a near-capacity link is the natural case; the 4K50 stream above does it on a typical home connection.
- Let it run and watch [HLSSegmentProducer].
Expected: it rides out the slow patch. Actual: repeated no-cut stall: no segment finalized for 10s … rate=40.0pkt/s, cutter wedge; videoPtsAdvance=4.5s; exiting for host retune — note videoPtsAdvance is positive (video is flowing), yet it's classified a wedge and retunes, re-joining behind the live edge and draining the buffer each cycle.
Synthetic: put a rate-limiting proxy in front of any live HLS/TS source and throttle segment delivery to ~90 % of real-time (so readRate stays above the 40 pkt/s wedge threshold but segments finalize slower than the 10 s timeout). The retune loop reproduces within a minute or two.
Issue 3 — SAR/anamorphic renders as a strip (deterministic)
- Prepare an anamorphic source with SAR ≠ 1:1, e.g. ffmpeg -i in.mp4 -vf "scale=720:576,setsar=64/45" -c:v libx264 -aspect 16:9 anamorphic.mp4 (720×576 coded, 16:9 display), or any 1440×1080→16:9 clip.
- Route it to the software path: either use interlaced content (goes software via AU live tv #107) or force it with AetherEngine.setForceSoftwarePathForTesting(true) (aetherctl … --sw).
- Play and observe the frame.
Expected: fills 16:9. Actual: renders at coded dimensions (a thin strip), because the CMVideoFormatDescription is built without the PAR extension. The AVPlayer/loopback path displays the same source correctly. Bonus: interlaced anamorphic content flickers size per-field, and some sources carry a garbage sample_aspect_ratio (1088:1) that must be sanity-gated.
AetherEngine version or commit SHA
5.17.0
Host app
Custom / my own integration
Platform
tvOS
OS version
tvOS 26.0
Device / chip
Apple TV 4K
Playback path
Native AVPlayer
Source media (for playback bugs)
No response
Error codes / log lines
Issue 1 — serial ingest throughput. No error code; it's a starvation symptom. The tell is the segment cache plateauing while the producer runs below real-time:
# serial fetch — cache stuck at ~5 segments, video arriving at ~45% of wall-clock:
memprobe … cacheCount=4 cacheMB=7
memprobe … cacheCount=5 cacheMB=15
[HLSSegmentProducer] … videoPtsAdvance=4.5s (≈ in a ~10 s window)
# same stream/box with parallel prefetch — cache fills:
memprobe … cacheCount=15 cacheMB=96
Issue 2 — cutter retunes slow-but-healthy live. The producer lines (note videoPtsAdvance is positive — video is flowing — yet it's called a wedge and retuned), plus the downstream AVPlayer error the retune/stall produces:
[HLSSegmentProducer] no-cut stall: no segment finalized for 10s (packetsRead=1743, sinceFinalize=420, rate=40.0pkt/s, cutter wedge); window video=216 key=3 audio=204 foreign=0 videoPtsAdvance=4.2s; exiting for host retune
[HLSSegmentProducer] pump finished: reason=segmentStall packetsRead=1743 packetsWritten=881 lastError=0 elapsed=10736ms cacheCount=4
# (also seen with rate=61.3pkt/s, videoPtsAdvance=9.4s — clearly progressing)
# downstream symptom on the loopback AVPlayer once the producer retunes/stalls:
[NativeAVPlayerHost] #6 errorLog code=-12888 domain=CoreMediaErrorDomain
'CoreMediaErrorDomain error -12888 - Playlist File unchanged for longer than 1.5 * target duration'
Key signal for the fix: rate ≥ 40 pkt/s and videoPtsAdvance > 0 = slow delivery, not a stuck cutter. After gating the retune on PTS advance, those lines become:
[HLSSegmentProducer] slow live delivery hold 1/6: video PTS +5.2s in 12s (rate=40.0pkt/s) — not a wedge, re-arming watchdog instead of retuning
Issue 3 — SAR ignored on software path. The decoder logs the garbage AVCodecContext.sample_aspect_ratio that must be sanity-gated (and shows why nothing sane gets attached to the format description):
[SWDecoder] SAR resolved=1:1 frame=1:1 ctx=1088:1 stream=1:1 buf=1920x1080
ctx=1088:1 is the out-of-range PAR from the codec context; frame/stream report 1:1, so no valid PAR is available to attach, and the frame collapses to buf=1920x1080 coded dims. (On a genuinely anamorphic source the sane SAR lives in frame/stream but is never written into the CMVideoFormatDescription.)
Relevant AVFoundation code for reference: -12888 = kCMBaseObjectError_.../CoreMedia "Playlist File unchanged" (the loopback HLS playlist went stale ≥ 1.5× target-duration — i.e. the producer stopped publishing segments), which is the observable AVPlayer-side consequence of Issue 2's retune loop, not a separate bug.
Anything else
No response
Activity
docs(formats): describe ingest prefetch and watchdog PTS-advance hold (…
Merge pull request #184 from superuser404notfound/fix/177-live-path-trio
superuser404notfound commentedon Jul 21, 2026
Superb report, thank you. All three reproduced exactly as described against main, and since your designs were already field-verified on the target hardware, the fixes follow them closely. All three landed in PR #184 and are released in 5.18.1:
Ingest prefetch:
HLSLiveIngestReadernow runs a bounded prefetch pipeline, up to 4 segment fetches (and AES-128 decrypts) in flight, committed to the FIFO strictly in playlist order. The window is anchored at the commit point, so in-flight bytes stay bounded to the window size even when the head segment is slow; first-segment classification and the blocking FIFO write that paces the demuxer are unchanged.No-cut watchdog: the decision is now gated on video PTS advance. A wedge-classified stall with >= 2 s of PTS advance in the window holds and re-arms the watchdog (window counters reset, bounded to 6 consecutive holds) instead of exiting for host retune; your suggested hold log line ships nearly verbatim. A genuine SSAI pod (full read rate, frozen video PTS) still exits immediately, so the Bursty-ingest detection trusts self-reported TARGETDURATION, not observed cadence -- LL-HLS blocking-reload stays enabled and stalls with -15410 #167 halt-latch and 503 behavior are preserved. The source-starvation classification (low read rate, 35 s) is deliberately untouched.
SAR: resolution order is frame -> codec context -> stream, first sane value wins, with both axes gated to 1...256 (your 1088:1 sample is exactly why), the first non-square SAR latches per stream so per-field oscillation cannot flicker the geometry, and the renderer's
CMVideoFormatDescriptioncache is now keyed on PAR as well, so a PAR-less first-frame description can no longer freeze for the whole stream.Each fix ships with regression tests (
Issue177IngestPrefetchTestswith a latency-controlled loopback origin,Issue177NoCutHoldTests,Issue177SARLatchTestsincluding the frozen-description case).Since you have your own implementations running: if a diff against 5.18.1 shows behavior your field testing covered that this version does not (window size, hold budget, gate bounds, anything else), please flag it here. Leaving this open for your retest.
Merge pull request #186 from superuser404notfound/test/177-ingest-fla…
kskchaitanya1993 commentedon Jul 22, 2026
Reply — retest of 5.18.1 (three live-path fixes, #177/#168)
Thanks for the fast turnaround, and for shipping all three with regression tests.
Bumped our vendored engine to 5.18.1 and dropped my three carried patches (SAR, ingest prefetch, no-cut hold) — they now conflict against
main(i.e. upstreamed), while our two unrelated local patches (anativePlayerLayeraccessor and asoftwareFramesEnqueuedgetter) still apply cleanly, so the bump was clean.Source-diffed each fix against my field-tested implementation — no divergence to flag:
maxConcurrentSegmentFetches = 4matches my depth-4 window; committed strictly in playlist order with the blocking FIFO write still pacing the demuxer, and the window anchored at the commit point so in-flight bytes stay bounded — exactly the behavior mine relied on. First-segment classification unchanged. ✓liveSlowDeliveryPtsAdvanceSeconds = 2+liveSlowDeliveryMaxHolds = 6, withconsecutiveNoCutHoldsreset to 0 on a real finalize — identical to my2.0 s/6/ refill-on-finalize. The wedge-vs-starvation rate gate (liveWedgeProgressRateThreshold = 40 pkt/s) and the source-starvation (low read rate / 35 s) path are untouched, which is what I wanted — the hold only reclassifies the slow-delivery case, and a frozen-PTS SSAI pod still exits immediately. ✓num/den <= 256gate on both axes (the1088:1garbage case),latchedSARper stream, resolution order frame → codec context → stream, andparH/parVfolded into theCMVideoFormatDescriptioncache key so a PAR-less first-frame description can't freeze the geometry. All match. ✓Retested on the target hardware — Apple TV 4K (3rd gen), tvOS 26.5 — via a deterministic stream-zoo harness that plays every codec/container/HDR case (and deliberately-broken ones) through the full ladder:
-15410Bursty-ingest detection trusts self-reported TARGETDURATION, not observed cadence -- LL-HLS blocking-reload stays enabled and stalls with -15410 #167 halt-latch / 503 behavior untouched (my patches never touched those paths; confirmed still intact).Nothing to flag — 5.18.1 is behavior-equivalent to the field-tested versions. Dropping the local patches. Thanks again.
Closing this as resolved in 5.18.1. 🙏
fix(ingest): bounded parallel segment prefetch on the live HLS path (s…
fix(producer): hold the no-cut watchdog while video PTS advances (sup…
fix(swdecode): latch SAR per stream and key the format cache on PAR (s…
docs(changelog): unreleased notes for the superuser404notfound#177 li…
test(ingest): harden superuser404notfound#177 prefetch tests against …
fix(decoder): a pixel aspect ratio is judged by the picture it produces
fix(decoder): a container-declared pixel aspect ratio reaches the dec…
feat(engine): publish the display size the software path settled on
fix(swpath): attach the pixel aspect ratio on the VT-backed decoder too
fix(engine): lift the no-cut watchdog off the read thread it watches (s…
fix(live): a join that never cut anything now has a deadline (AE#446)