Skip to content

Software path: presentation timebase + per-frame times (#311) - #322

Merged
superuser404notfound merged 1 commit into
mainfrom
feat/issue-311-software-frame-times
Aug 7, 2026
Merged

superuser404notfound merged 1 commit into
mainfrom
feat/issue-311-software-frame-times

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Both halves of #311, which are only useful together: a bitmap overlay (libass) over software-decoded video needs a clock to pace against and the frame boundaries to land on.

What is public now

player.softwarePresentationTimebase               // CMTimebase?, the master clock
player.setSoftwareVideoFrameTimeObserver { frame in
    frame.presentation                            // CMTime, source axis
    frame.generation                              // UInt64, moves on every renderer flush
}

The timebase is the render synchronizer's, which drives the audio renderer and the display layer both, and it is created unconditionally, so it exists for the whole session even on a source with no audio track. It reads the source axis, the same axis as the cues the engine emits, so nothing needs converting between them.

Why a separate type instead of NativeVideoFrameTime

The reporter asked for the existing callback, and the honest answer is that three of that type's five fields have no meaning here. source and item exist because the native path muxes what it demuxes and the axes differ; here the engine enqueues the source timestamp unchanged. segmentIndex indexes segments this path does not produce. epoch keys a producer restart that does not happen.

Filling those with placeholders would put a value in a field a consumer cannot distinguish from a measurement, so SoftwareVideoFrameTime carries what this path actually knows. generation keeps the one job epoch really does: entries recorded under an older generation describe frames the compositor has thrown away, which is exactly what a seek does. A backward seek makes that concrete, since the same timestamp comes round again and the timestamps alone cannot separate the two runs.

Where it is reported

At the handover in flushFrame, not at admission. A frame refused for an unschedulable timestamp (#298), skipped after a seek, or lost to a failed sample-buffer creation never reaches that line, so it is never reported as a boundary that exists. Being past the reorder buffer also means these arrive in ascending presentation order, unlike the native path's decode-order stream.

Verification

aetherctl play --frame-times installs the observer before load() (the documented usage: the engine re-arms each new host) and reads the timebase. Real VP9 session over a rate-limited origin, with a seek at t=12:

  timebase: present, time=0.000s rate=0.00
  t=05 ... ft=30 ftLast=5.100s  ftGen=0 ooo=0 tb=5.049s
  t=12 ... ft=30 ftLast=12.200s ftGen=0 ooo=0 tb=12.153s
  SEEKLANDED target=6.01 in 2ms
  t=13 ... ft=32 ftLast=7.067s  ftGen=1 ooo=0 tb=7.015s
frame times: frames=490 outOfOrder=0 generations=[0, 1]

30 to 33 frames per second on 30 fps content, ftLast running about 50 ms ahead of the timebase (that gap is the decode cushion, and its size is why the two have to be on one axis), the generation stepping at the seek, and ooo=0 over 490 frames, which measures the ascending-order claim rather than asserting it.

Unit coverage in Issue311SoftwareFrameTimesTests: reported in ascending order past a B-frame run, unschedulable and post-seek-skipped frames never reported, generation stepping across a flush with the same timestamp on both sides, observer removal, and both surfaces nil without a software session. Full suite green (1537 tests).

Out of scope, as the reporter framed it: the remote-HLS bypass, where AVPlayer owns decode and the engine never sees a frame.

…timebase (#311)

A host compositing a bitmap overlay (libass) over software-decoded video
needs two things the engine had but did not expose: the clock the frames
are presented against, and where the frame boundaries are. Neither was
reachable, so an ASS presenter that works on the native path could not
run on the one path that carries VP9, AV1 without hardware decode and
MPEG-4 Part 2.

`softwarePresentationTimebase` hands out the render synchronizer's
timebase. It is the master clock for both renderers, and it reads the
source axis, the same axis as the cues, so an overlay paced against it
needs no conversion.

`setSoftwareVideoFrameTimeObserver` reports every enqueued frame. It
takes its own value type rather than reusing `NativeVideoFrameTime`:
three of that type's five fields answer questions this path does not
have (two axes, a segment index, a producer epoch), and a placeholder is
indistinguishable from a measurement at the call site. What this path
does have is the presentation time and a flush generation, which carries
the epoch's actual job: entries recorded under an older generation
describe frames the compositor has discarded, which is what a seek does.

Reported at the handover, not at admission, so a frame refused for an
unschedulable timestamp, skipped after a seek, or lost to a failed
sample-buffer creation is never reported as a boundary that exists. Past
the reorder buffer, so unlike the native path's decode-order stream these
arrive in ascending presentation order.

`aetherctl play --frame-times` exercises both against real media. On a
VP9 session over a rate-limited origin: 490 frames reported, 0 out of
order, the timebase tracking ftLast about 50 ms behind (that gap is the
decode cushion), and a seek at t=12 moving the generation 0 -> 1.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE
@superuser404notfound
superuser404notfound merged commit c67c239 into main Aug 7, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the feat/issue-311-software-frame-times branch August 7, 2026 08:12
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