Skip to content

Software VOD resume: preroll audio re-anchors the clock backwards after load(startPosition:) on 7.31.1 #724

Closed

Description

@alsoeoe

What happened?

On AetherEngine 7.31.1, a seekable, zero-origin H.264/AAC VOD loaded with startPosition: 17.3 initially reports 17.3 seconds, but the software path re-anchors its clock to 9.984 seconds when playback begins. About three seconds later engine.clock.currentTime is only 12.8–12.9 seconds. This reproduces both with autoplay = false followed by play() and with autoplay = true.

Expected: the initial resume retains the requested position, discards/handles necessary decode preroll, and advances from approximately 17.3 seconds. A caller should not need a second transport seek to establish the initial resume anchor.

This is reproduced using only the engine API and generated media. There is no application session logic, network source, audio-track switch or timestamp-origin offset involved.

Engine version and environment

  • Unmodified upstream tag 7.31.1, commit b085eee1bdd426d50be9dd770d49cecb60e08cb8, the latest stable release at retest.
  • FFmpegBuild 3.6.0, LibDovi 2.1.0.
  • macOS 27.0.1 (26A434), Apple M1 / arm64, Xcode 27.0 (27A266a), Apple Swift 6.4.
  • Software path forced through the engine's debug testing switch; native controls verify playbackBackend == .native.
  • Headless engine-clock measurements, muted volume. These results do not claim physical-device or audible/visual-output validation.

Steps to reproduce

Generate a completely synthetic, 30-second MP4 with ten-second GOPs:

ffmpeg -hide_banner -loglevel error \
  -f lavfi -i testsrc2=size=320x180:rate=24 \
  -f lavfi -i sine=frequency=440:sample_rate=48000 \
  -t 30 -c:v libx264 -preset ultrafast -b:v 180k \
  -g 240 -keyint_min 240 -sc_threshold 0 \
  -c:a aac -b:a 32k -movflags +faststart -y resume-long-gop.mp4

Media: H.264 Constrained Baseline, 320×180, 24 fps, yuv420p, AAC-LC mono 48 kHz. Both streams and the container start at 0.000 seconds; container duration is 30.000 seconds. No HDR/Dolby Vision, disc, live or external subtitles.

Minimal engine API sequence (run in a macOS debug executable linked to the exact upstream tag):

import AetherEngine
import Foundation

@MainActor
func reproduce(url: URL, software: Bool = true,
               autoplay: Bool = false, seekBeforePlay: Bool = false) async throws {
    AetherEngine.setForceSoftwarePathForTesting(software)
    defer { AetherEngine.setForceSoftwarePathForTesting(false) }
    let engine = try AetherEngine()
    defer { engine.stop() }
    engine.volume = 0
    var options = LoadOptions()
    options.autoplay = autoplay
    options.suppressDisplayCriteria = true
    _ = try await engine.load(url: url, startPosition: 17.3, options: options)
    let deadline = ContinuousClock.now.advanced(by: .seconds(15))
    while engine.state == .loading, ContinuousClock.now < deadline {
        try await Task.sleep(for: .milliseconds(20))
    }
    print("load", engine.playbackBackend, engine.state, engine.clock.currentTime)
    if seekBeforePlay { await engine.seek(to: 17.3) }
    if !autoplay { engine.play() }
    for tick in 1...6 {
        try await Task.sleep(for: .milliseconds(500))
        print(tick, engine.state, engine.clock.currentTime)
    }
}

Call with the local generated file URL and defaults for the failing paused-load case, or with autoplay: true for the other failing case. Use a fresh engine per run. For the workaround control, use seekBeforePlay: true and keep autoplay false; the measured control also subscribed to seekEvents and observed a matching landed(17.3) before Play. Use software: false for the native controls.

Repeated measurements

Each cell below represents three fresh-engine runs, sampled after six 500 ms sleeps (approximately 3.0–3.2 seconds after Play or the autoplay load).

Fixture API sequence / route Clock at final sample Result
10 s GOP software paused load → Play 12.811–12.917 s 3/3 reproduce
10 s GOP software autoplay load 12.912–12.921 s 3/3 reproduce
10 s GOP software paused load → seek(17.3) → Play 20.301–20.303 s 3/3 advance correctly
10 s GOP native paused load → Play about 20.300 s 3/3 advance correctly
10 s GOP native autoplay load 20.200–20.400 s 3/3 advance correctly
2 s GOP software paused load → Play 20.178–20.239 s 3/3 advance correctly
2 s GOP software autoplay load 20.234–20.241 s 3/3 advance correctly

The two-second GOP twin uses the same generation command with -g 48 -keyint_min 48; all five modes were repeated three times and advanced correctly. Thus the long-GOP failure is repeatable rather than a general failure to start the headless engine.

Relevant log lines

One failing run:

LOAD run=1 mode=sw-paused backend=software state=paused clock=17.3
[SWHost] clock re-anchored to first sample: anchor=9.984s (load anchor 17.300s, sessionZero=0.000s)
RESULT run=1 mode=sw-paused actual=12.810517625 jumpedBack=true advanced=false

The paused-seek control, on the same source and target:

seek#1 programmatic began target=17.30
seek#1 programmatic landed rendered=17.30 target=17.30
RESULT run=1 mode=sw-seek-control actual=20.302830208 jumpedBack=false advanced=true

ffprobe -read_intervals '17.3%+0.2' on the generated ten-second-GOP source confirms the necessary backward demux landing:

codec_type,pts_time,dts_time,flags
 audio,9.984000,9.984000,K__
 video,10.000000,10.000000,K__
 audio,10.005333,10.005333,K__

Likely mechanism / requested engine behavior

The observed re-anchor is direct engine evidence. The following explanation is a source-based inference:

  • Initial software load performs the backward demux reposition and sets the video skip threshold plus initialClockTime to 17.3.
  • First decoded audio arming passes the preroll buffer PTS into SWClockAnchorPolicy.resolve.
  • The anchor policy treats any absolute deviation greater than two seconds as a re-anchor. Here the first sample is earlier, not a mid-stream join ahead of the load anchor; it chooses 9.984, and max(0, firstSample - initialSeconds) leaves sessionZero at zero. The published clock therefore moves backward.

Could the initial software VOD resume preserve its requested anchor while consuming/discarding preroll, with the existing intentional mid-stream-join behavior retained? The paused transport seek already establishes the requested clock correctly on the same source, so the extra seek is a workaround rather than the desired load contract.

I searched existing Issues/PRs and comments before reporting. #337 addresses a cold-start unarmed-clock deadlock; #573 addresses a non-zero-origin seek-axis conversion. This fixture starts at zero, has ordinary promptly interleaved audio, and reproduces without either condition. If there is an existing report for this exact initial-resume/preroll case, please link it and this can be consolidated.

Activity

  1. superuser404notfound commented on Oct 8, 2026

    @superuser404notfound
    Owner

    Thanks for the precise report, the fixture and the exact API sequence made this a one-step repro. Released in 7.32.2.

    Your reading of the mechanism was right. SWClockAnchorPolicy compared the absolute deviation, so a first sample behind the anchor (the audio that comes with the keyframe before the target) was treated like a mid-stream join. It now re-anchors only on a sample ahead of the anchor; preroll behind it is discarded as on a transport seek (a20c4fb).

    Two related defects turned up while measuring, both in the same release:

    • Paused load reading 0.00. With autoplay = false and no play(), currentTime fell from 17.3 to 0.00 within 250 ms: the host's 4 Hz publisher wrote the still unarmed synchronizer over the anchor. Your harness probably sampled before the first tick, which is why it printed 17.3. VOD now publishes nothing until the clock is armed (same commit).
    • Resume on a source whose timestamps do not start at zero. The same 17.3 s resume on your fixture remuxed with -output_ts_offset 600 landed on the first packet (600.000) while publishing 17.3, because load() handed the session-axis position to the demuxer unconverted. The resume now carries the source origin first; the first picture lands at 617.292, matching the native path (9d246d8).

    Measured with aetherctl play --sw on your 10 s GOP fixture, 3 runs per arm:

    arm 7.32.1 7.32.2
    autoplay load 10.8 s to 15.1 s, re-anchor to 9.984 18.2 s to 21.2 s, no re-anchor
    paused load, then play() 10.9 s to 15.1 s 18.2 s to 22.2 s
    paused load only 0.00 17.30
    2 s GOP twin correct unchanged

    aetherctl play --start-position now also fails a run whose clock settles more than a second behind the anchor, so this case cannot pass the harness again unnoticed (874e9b4).

    This was verified headless on macOS only. A retest with your harness on 7.32.2 would be very welcome, and I'll leave the issue open until then.

  2. alsoeoe commented on Oct 9, 2026

    @alsoeoe
    Author

    Thanks for the fix. I retested the unmodified 7.32.2 tag (59355d973cfe35d34a19d85d33b7b1ae88e11115) using the original harness and byte-identical 10 s / 2 s GOP fixtures. The original five modes were unchanged, with three fresh engines per mode and fixture. Target: 17.3 s; six samples at 500 ms intervals after Play or the autoplay load.

    I also reran the original 7.31.1 binary against the long-GOP fixture in the same environment as a negative control.

    Mode 7.31.1, 10 s GOP 7.32.2, 10 s GOP 7.32.2, 2 s GOP
    Software paused load → Play 12.228–12.910 s; 3/3 reproduce 20.179–20.229 s; 3/3 pass 20.211–20.236 s; 3/3 pass
    Software autoplay 12.914–12.926 s; 3/3 reproduce 20.236–20.241 s; 3/3 pass 20.232–20.241 s; 3/3 pass
    Software paused load → seek(17.3) → Play 20.302–20.304 s 20.302–20.304 s 20.303–20.304 s
    Native paused load → Play 20.301–20.403 s 20.300–20.300 s 20.300–20.400 s
    Native autoplay 20.200–20.300 s 20.200–20.300 s 20.300–20.300 s

    Values are final clock ranges after approximately three seconds; the seek and native controls also passed 3/3 per cell. The two previously failing software modes pass without an additional seek.

    Additional checks, also three fresh engines per mode:

    • Paused load only: software and native clocks remained exactly 17.300 s across six 500 ms samples, with state paused. Software also retained 17.300 s during a 1.5 s dwell sampled every 250 ms, then advanced normally after Play.
    • Non-zero-origin source: remuxed the same long-GOP file with -c copy -output_ts_offset 600. ffprobe reports video start 600.000000 s and audio/container start 599.978667 s. Software paused-load/Play and autoplay both logged the first decoded video frame at 617.292 s in all six runs; final session clocks were 20.199–20.211 s and 20.233–20.238 s respectively. Native controls advanced normally, and software paused-only retained 17.300 s. This checks the decoded frame PTS as well as the published clock.

    54/54 fresh-engine runs on 7.32.2 passed. No sampled playback clock fell behind 17.3 s, and no clock re-anchor was logged. Same macOS 27.0.1 / Apple M1 arm64 / Xcode 27.0 / Swift 6.4 environment; FFmpegBuild 3.6.0 and LibDovi 2.1.0 unchanged.

    These are muted, headless macOS engine tests only; no physical-device, audible-output or on-screen rendering validation is claimed. From this retest, I consider the reported engine issue resolved. Thanks for fixing the two related cases as well.

  3. superuser404notfound commented on Oct 9, 2026

    @superuser404notfound
    Owner

    Thank you for the thorough retest, including the 7.31.1 negative control and the decoded-frame PTS check on the offset source. 54/54 on 7.32.2 settles it, closing as resolved in 7.32.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions