Skip to content

MPEG-DASH SegmentBase VOD performs unnecessary midpoint cue-prewarm seek before first frame #1075

Open

Description

@nulltuple

What happened?

AetherEngine supports static, single-period MPEG-DASH SegmentBase presentations by opening the MPD through DASHSourceOpener and exposing the representations as a seekable virtual fragmented MP4. The native HLS-remux route prepares its segment plan in HLSVideoEngine.prepare().

That route currently applies the generic cue/index prewarm policy:

// Sources/AetherEngine/Video/HLSVideoEngine+SegmentPlanning.swift
static func cuePrewarmMayRun(
    hasSegmentedReader: Bool,
    isSourceSeekable: Bool
) -> Bool {
    !hasSegmentedReader && isSourceSeekable
}

For a seekable DASH virtual MP4 with no timeSeekableReader, this policy permits the midpoint seek:

// Sources/AetherEngine/Video/HLSVideoEngine.swift (existing behavior)
let prewarmOK = dem.seekBounded(
    to: durationSeconds * 0.5,
    timeout: Self.cuePrewarmTimeout
)

On a remote origin, that seek may cause an extra HTTP Range read before first frame. The optimization opportunity is to avoid it when the seek does not improve keyframe index coverage or the HLS segment plan.

Important correctness condition: sidx describes subsegments; it is not interchangeable with a complete MP4 stss sync-sample index. A blanket assumption that DASH always has the necessary keyframes is not justified. Ordinary MP4 and MKV prewarming must remain intact, and the DASH fix should be made only after comparing the segment plan, index quality, and seek behavior with and without prewarm. This issue requests a measured, DASH-aware optimization—not an unconditional skip or a claim of broken playback.

Steps to reproduce

The source-level reproduction uses only files already checked into this public repository. It does not require any other repository, account, external fixture ZIP, YouTube stream, or independently running HTTP server.

  1. On macOS with a suitable Xcode/Swift toolchain, check out a version known to contain the behavior:

    git clone https://github.com/superuser404notfound/AetherEngine.git
    cd AetherEngine
    git checkout 7.68.0
    swift test --filter DASHOverHTTPTests
    swift test --filter Issue550CuePrewarmPolicyTests

    Relevant checked-in files:

    The pre-existing tests establish DASH opening and stream correctness. By themselves they do not demonstrate a midpoint seek in HLSVideoEngine.

  2. To make the policy eligibility deterministic, append this test inside the existing DASHOverHTTPTests struct in Tests/AetherEngineTests/DASHSourceTests.swift:

    @Test("DASH virtual MP4 currently qualifies for the generic index prewarm")
    func dashQualifiesForGenericPrewarm() throws {
        let origin = try Self.origin(manifestPath: "/movie.mpd")
        defer { origin.stop() }
    
        let demuxer = Demuxer()
        try demuxer.open(url: URL(string: "\(origin.baseURL)/movie.mpd")!)
        defer { demuxer.close() }
    
        #expect(demuxer.isSourceSeekable)
        #expect(demuxer.timeSeekableReader == nil)
        #expect(HLSVideoEngine.cuePrewarmMayRun(
            hasSegmentedReader: demuxer.timeSeekableReader != nil,
            isSourceSeekable: demuxer.isSourceSeekable
        ))
    }

    Then rerun:

    swift test --filter DASHOverHTTPTests

    This test only proves that DASH is eligible under the current source-agnostic prewarm policy. It does not count network requests, show startup delay, or establish that skipping prewarm is safe.

  3. To trace the actual native HLS-remux preparation, append this second diagnostic test to the same suite. It uses the same existing fixture and HTTP origin, and has no external dependencies:

    @Test("trace Range requests while preparing native HLS from DASH")
    func dashNativeHLSRangeTrace() throws {
        let origin = try Self.origin(manifestPath: "/movie.mpd")
        defer { origin.stop() }
    
        let hls = HLSVideoEngine(
            url: URL(string: "\(origin.baseURL)/movie.mpd")!
        )
        defer { hls.stop() }
    
        try hls.prepare()
    
        print("DASH video Range requests:",
              origin.requests(to: "/media/v.mp4")
                    .map { $0.range ?? "unranged" })
    }

    This diagnostic test is a proposed integration reproducer, not a test run attached to this issue. The fixture is very small; use it to inspect the path/requests, not to claim a significant latency improvement. If the full prepare() route requires additional fixture preparation, document that separately and retain the source-level reproduction.

  4. Measure the index and plan on both sides of the prewarm in HLSVideoEngine.prepare(): dem.indexedKeyframeEntries(streamIndex: videoIndex), keyframeIndexIsTrustworthy, planned segment boundaries, any fallback-to-uniform-stride decision, and the time/Range requests consumed by the midpoint seek.

  5. A/B-test a long static SegmentBase presentation (ideally with variable GOP placement) with prewarm enabled vs. disabled; validate startup, first frame, audio/video sync, seeks at 5% / 50% / 95%, and HLS segment-plan/restart correctness. Include ordinary seekable MKV/MP4 and HLS sources as controls. Report exact fixture details and run counts.

AetherEngine version or commit SHA

7.68.0 (also observed in 7.67.1); the relevant prewarm policy and HLS preparation path are present in both.

Host app

Custom / my own integration. No custom app is needed for the tests above; they run inside the upstream package.

Platform

macOS

OS version

macOS 15+ (supported package test environment; physical-device performance verification outstanding).

Device / chip

Not device-specific for the source-level reproduction. Physical device and OS for any benchmark should be supplied in a PR.

Playback path

Native AVPlayer (HLSVideoEngine's HLS-remux preparation, rather than the software decode host).

Source media (for playback bugs)

Included public fixture: 12-second static MPEG-DASH SegmentBase with separate fragmented MP4 H.264 video (16×16 at 4 fps) and AAC audio representations; global sidx; no DRM or credentials. See DASHFixture.swift. The 12-second fixture is a logic/diagnostic fixture, not a realistic timing benchmark.

Error codes / log lines

No thrown error is needed. The following are existing diagnostic log formats from the code, not verbatim logs captured for this issue:

[HLSVideoEngine] cue prewarm: seek to <time>s took <elapsed>ms
[HLSVideoEngine] cue prewarm: capped at <elapsed>ms (...)

Anything else

Suggested PR scope and tests

  • Introduce a reliable internal indicator of a successfully opened DASH virtual source (set after successful openDASH, clear on subsequent opens); avoid inferring source origin solely from an mp4 container format.

  • Compare indexed keyframe entries, plan trust, plan type and segment boundaries before deciding that DASH can safely skip prewarm. Treat the sidx/stss distinction as part of the correctness review.

  • If measurements validate a DASH-wide skip, extend cuePrewarmMayRun with a defaulted internal isDASHSource input. Add tests for both the DASH and normal-seekable cases. Otherwise scope the optimization to the narrower subset actually validated.

  • The following is a suggested post-fix unit test, appropriate only if the chosen policy genuinely excludes all DASH virtual sources:

    // Add to Tests/AetherEngineTests/Issue550CuePrewarmPolicyTests.swift
    @Test("DASH and ordinary seekable sources retain their appropriate policy")
    func dashPolicyPreservesOrdinaryIndexWarmup() {
        #expect(!HLSVideoEngine.cuePrewarmMayRun(
            hasSegmentedReader: false,
            isSourceSeekable: true,
            isDASHSource: true
        ))
        #expect(HLSVideoEngine.cuePrewarmMayRun(
            hasSegmentedReader: false,
            isSourceSeekable: true,
            isDASHSource: false
        ))
        #expect(!HLSVideoEngine.cuePrewarmMayRun(
            hasSegmentedReader: true,
            isSourceSeekable: true,
            isDASHSource: false
        ))
    }
  • Add integration coverage for a longer DASH source with nontrivial GOPs proving no loss of usable segment boundaries, plus an MKV/regular MP4 control. Document repeated, isolated prewarm-only timing comparisons before making a speed claim.

Evidence status: There was an earlier observation of roughly 0.5 seconds spent in a midpoint prewarm for one remote DASH source in a custom iOS application, but no independent, single-variable benchmark is attached. Other startup optimizations occurred simultaneously. This issue does not attribute the full app startup improvement to AetherEngine.

Related: #859 (DASH SegmentBase support), AE#550 prewarm policy, and native architecture / segment-plan documentation.

PR acceptance criteria: A/B measurements show redundant Range fetches or time saved; index coverage and segment plans remain valid; DASH seek/restart behavior stays correct; all existing AE#550 tests pass; ordinary MP4/MKV behavior is unchanged; no public API change; docs/changelog updated if required.

Activity

  1. added
    bug
    on Nov 16, 2026
  2. quint-aether commented on Nov 16, 2026

    @quint-aether

    This is related to #859 (which added DASH SegmentBase VOD) and to the AE#550 cue prewarm policy. On current main, HLSVideoEngine.cuePrewarmMayRun still checks only for a segmented reader and source seekability, so a seekable DASH source still gets the midpoint seek you describe.

    One thing to weigh: docs/architecture-native.md says the prewarm is also how MP4 sources load their index (the stss sync-sample table), not only Matroska Cues. Before it is skipped for DASH, it needs confirming that segment planning for the virtual MP4 does not depend on that seek. The repeatable prewarm-only timing you mention would also help with that.

    Automated triage by Quint (Claude). A maintainer reads every issue and will follow up.

  3. superuser404notfound commented on Nov 16, 2026

    @superuser404notfound
    Owner

    Thanks for the careful report. I measured it, and you were right: for a DASH source the midpoint seek buys nothing. It is skipped now on main (95ee3ce) and will be in the next release.

    Why it can't help. The virtual MP4 is fragmented and its moov sample tables are empty, so there is no stss for the seek to load. libavformat only adds index entries for the fragments it actually parses, so the seek indexes exactly one fragment, the one at the middle. That also settles the sidx/stss question from the triage comment: the plan never got a usable keyframe index from DASH, with or without the seek.

    Measurement. A 10 minute static SegmentBase presentation (H.264 720p24, keyframes every 7.33 s, AAC, built with ffmpeg + MP4Box), served by a Range origin with 80 ms latency per request and a shared 4 MB/s limit. aetherctl play, 5 alternating runs per arm:

    prewarm (before) skipped (after)
    readyToPlay 6.16 to 6.76 s 4.24 to 4.70 s
    origin requests before first frame 25 12
    extra bytes about 5.7 MB from the middle of the file none
    index after the step 2 IRAPs 1 IRAP
    segment plan uniform stride 7.333 s, 82 segments identical

    Seeks to 30 s, 300 s and 570 s (5 / 50 / 95 %) landed at the same clock on both builds (30.00, 306.01, 568.85), and both runs ended VERDICT: OK. Loopback timing is not a device number, so treat the 2 s as "one segment's worth of fetch on this link", not a promise.

    What changed. cuePrewarmMayRun takes an isDASHSource input (defaulted, internal). The flag comes from the open path (the reader is a DASHVirtualMP4Reader), not from the mp4 container name, so a plain MP4 keeps its prewarm. Tests cover both: Issue550CuePrewarmPolicyTests for the policy, and a DASHOverHTTPTests case that opens the same fixture once as DASH and once as a plain MP4 over HTTP. Docs: formats.md (MPEG-DASH section) and architecture-native.md (segment plan).

    One thing this does not fix: DASH still ends up on the uniform-stride plan, because the keyframe index stays empty. The sidx entries carry starts_with_SAP per subsegment, so the plan could be cut on those declared random-access points instead, the way HLS ingest already does. That is a separate change. If your sources have irregular GOPs and you see restarts after seeks, tell me and I'll take it on.

    If you can, please check the startup on your remote source once a release with this is out.

  4. superuser404notfound commented on Nov 16, 2026

    @superuser404notfound
    Owner

    Follow-up on the open point from my last comment: DASH now gets a segment plan from the video sidx instead of the uniform grid. It's on main (6b7ac7e) and goes out with the prewarm skip in the next release.

    How it works. The video sidx marks each subsegment that starts with a SAP and gives its time. When every subsegment starts with a type 1 or 2 SAP (closed GOP), those points feed the same declared-boundary planner the HLS VOD ingest already uses, with its 0.5 s backoff for rounding. Type 3 and up, or one subsegment without a SAP, and the source declares nothing, so the old fallback applies.

    One catch I hit on the way. The virtual MP4 interleaves subsegments by start time, so an audio subsegment that starts just before a video one is read whole first, and audio runs ahead of video by up to one audio subsegment. A plan segment shorter than that loses its keyframe: the audio crosses the next boundary first and the keyframe lands in the next segment. With the hls muxer's cut rule, 3 of 30 segments failed that way (the 2.25 s and 3.75 s ones). So the plan keeps no segment shorter than the target length, or the longest audio subsegment plus the backoff, whichever is larger.

    Measurement, two 5 minute SegmentBase fixtures (H.264 720p24 + AAC, MP4Box -dash 4000 -rap), aetherctl segverify decoding each served segment on its own:

    fixture uniform grid (before) sidx plan (after)
    keyframes 1.5 to 9 s apart 25 of 40 independent 35 of 35
    keyframes every 7.3 s 37 of 40 (the 7.333 s grid drifts off) 40 of 40

    Seeks to 15, 150 and 285 s on the irregular fixture land at 15.00, 150.00 and 285.00. The grid landed at 15.00, 151.83 and 288.33. No extra requests: the plan comes from the sidx the open already fetched.

    Tests: SAP parsing (types 1, 2 with a delta, 3, missing), the thinning rule, and the fixture's declared points over HTTP. Docs: architecture-native.md (segment plan, declared boundaries) and formats.md (MPEG-DASH).

  5. superuser404notfound commented on Nov 16, 2026

    @superuser404notfound
    Owner

    Released in 7.69.0 (a7aaa8d), both parts: the prewarm skip for DASH sources and the segment plan from the sidx SAPs. If you get a chance to retest against your SegmentBase streams, I'd like to hear how the first frame and the seeks look on your side.

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

    area: iobug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions