Skip to content

Three live-path fixes from the #168 investigation (#177) - #184

Merged
superuser404notfound merged 5 commits into
mainfrom
fix/177-live-path-trio
Jul 21, 2026
Merged

superuser404notfound merged 5 commits into
mainfrom
fix/177-live-path-trio

Conversation

@superuser404notfound

@superuser404notfound superuser404notfound commented Jul 21, 2026 •

Copy link
Copy Markdown
Owner

Addresses #177 (left open for the reporter retest). All three issues verified against main and fixed at the layer the reporter identified; each fix ships with regression tests.

1. Bounded parallel segment prefetch (ingest)

HLSLiveIngestReader.runIngest awaited each fetchSegment fully before starting the next, so every segment paid a connection + TTFB round-trip with no bytes flowing. On a 4K50 HEVC/TS stream (~13 Mbps) the producer could not get ahead of the playhead (cache stuck at ~5 segments).

Segment fetches now run through a bounded prefetch pipeline: up to 4 fetches (and AES-128 decrypts) in flight, committed to the FIFO strictly in playlist order. Classification-before-first-FIFO-byte, discontinuity logging, and demuxer pacing via the blocking FIFO write are unchanged; the window is anchored at the commit point, bounding in-memory bytes to the window size. Covered by Issue177IngestPrefetchTests (loopback origin asserting both the concurrency high-water mark and byte-exact playlist ordering under out-of-order completion).

2. No-cut watchdog gated on video PTS advance (producer)

The watchdog retuned on wall-clock since last finalize alone; a slow-but-healthy source (segments finalize slower than the 10 s timeout while video PTS keeps advancing) was classified a cutter wedge and force-retuned, re-joining behind the live edge and draining the buffer each cycle.

New pure decision noCutStallAction: wedge-classified stalls with >= 2 s video PTS advance in the window hold and re-arm (bounded to 6 consecutive holds) instead of exiting for host retune. A genuine SSAI ad-pod wedge (full read rate, frozen video PTS) still exits immediately, so the #167 halt-latch and 503 behavior are preserved; the source-starvation classification is unchanged. Covered by Issue177NoCutHoldTests.

3. SAR latch + PAR-keyed format-description cache (software path)

The decoder attached SAR to each pixel buffer (#23), but the renderer's CMVideoFormatDescription cache key omitted PAR, so the first frame's state was frozen for the whole stream and anamorphic content collapsed to coded dimensions. Garbage AVCodecContext SARs (1088:1) and per-field oscillation had no gate.

The decoder now resolves SAR frame -> codec context -> stream (first sane wins, axes gated to 1...256), latches the first non-square SAR per stream, and clears stale attachments on recycled pool buffers; the renderer keys its format cache on PAR. Covered by Issue177SARLatchTests (including the frozen-description regression against a live renderer instance).

Verification

  • 924/924 tests pass (swift test)
  • swift build -Xswiftc -strict-concurrency=complete clean
  • tvOS Simulator xcodebuild clean (CI parity)

🤖 Generated with Claude Code

https://claude.ai/code/session_01NAPCg4tCDdSqkK6tPkNptw

Vincent Herbst and others added 5 commits July 21, 2026 19:53
…177)

The ingest segment loop awaited each fetch fully before starting the
next, so every segment paid a connection + TTFB round-trip with no bytes
flowing and the producer could not get ahead of the playhead on
high-bitrate live streams (4K50 HEVC/TS at ~13 Mbps: cache stuck at ~5
segments, videoPtsAdvance at roughly half of wall-clock).

Segment fetches now run through a bounded prefetch pipeline: up to 4
fetches (and AES-128 decrypts) in flight concurrently, committed to the
FIFO strictly in playlist order. First-segment classification,
discontinuity logging, and demuxer pacing via the blocking FIFO write
are unchanged; the window is anchored at the commit point so in-memory
segment bytes stay bounded to the window size even when the head
segment is slow.

Reported with a field-verified design by kskchaitanya1993.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NAPCg4tCDdSqkK6tPkNptw
The live no-cut watchdog retuned on wall-clock since the last finalized
segment alone. A source delivering just below real time (a 6 s segment
that simply has not fully arrived inside the 10 s timeout while packets
keep flowing) was classified a cutter wedge and force-retuned, which
re-joins behind the live edge, drains the buffer, and loops.

The wedge classification is now gated on PTS advance via the pure
decision noCutStallAction: when video PTS advanced at least 2 s in the
window, the watchdog holds and re-arms (window counters and anchor
reset, bounded to 6 consecutive holds) instead of exiting for host
retune. A genuine SSAI ad-pod wedge reads at full rate with frozen
video PTS and still exits immediately, so the #167 halt-latch behavior
is preserved; the source-starvation classification is unchanged.

Reported with a field-verified design by kskchaitanya1993.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NAPCg4tCDdSqkK6tPkNptw
…177)

Anamorphic (SAR != 1:1) content on the software path rendered at coded
dimensions (a thin strip): AVSampleBufferDisplayLayer reads display
aspect from the CMVideoFormatDescription PAR extension, and while the
decoder attached SAR to each pixel buffer (#23), the renderer's
format-description cache key omitted PAR, so whatever the first frame
carried was frozen for the whole stream. Garbage AVCodecContext SARs
(1088:1 seen in the field) and per-field oscillation on interlaced
content had no gate.

The decoder now resolves SAR frame -> codec context -> stream (first
sane value wins, both axes gated to 1...256), latches the first
non-square SAR per stream so field-alternating sources cannot flicker
the display geometry, and clears stale attachments on recycled pool
buffers. The renderer keys its format-description cache on the PAR
attachment, so a PAR change at identical geometry creates a fresh
description instead of reusing the frozen one.

Reported with a field-verified design by kskchaitanya1993.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NAPCg4tCDdSqkK6tPkNptw
@superuser404notfound
superuser404notfound merged commit 9118bbc into main Jul 21, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the fix/177-live-path-trio branch July 21, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant