Skip to content

fix(native): the media fallback comes back where the refused item was placed (#98) - #621

Merged
superuser404notfound merged 1 commit into
superuser404notfound:mainfrom
brandomoore:fix/master-fallback-recovery-position
Sep 24, 2026
Merged

superuser404notfound merged 1 commit into
superuser404notfound:mainfrom
brandomoore:fix/master-fallback-recovery-position

Conversation

@brandomoore

@brandomoore brandomoore commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What goes wrong

When AVPlayer refuses the served master (-11868 / -11848 / -1002), fallBackToMediaPlaylist reloads the media playlist at lastNativeVideoStartPosition. That value is written once, by the session's first mount in loadNative.

The #93/#65 stage-2 recovery (reloadStalledConsumerItem) swaps a fresh item in with host.swapItem(startPosition: anchor) at the position playback held, but does not update that value. So when the recovery item is the one refused at startup, the fallback rewinds the session to wherever it was first loaded. A title started from its beginning goes back to its first frame.

Field log

Apple TV 4K (3rd gen), tvOS 27.0, HDR10+ HEVC Matroska, loopback HLS, opened with a resume at 1844 s:

03:06:54  paused at 2099.69 s
03:08:59  [NativeAVPlayerHost] #1 failedToPlayToEndTime AVFoundationErrorDomain/-11868 'Cannot open'
03:09:02  [AetherEngine] #93 item death (failedToPlayToEndTime) at 2099.69s; reloading item through stage-2 recovery (attempt 1, pause guard bypassed)
03:09:03  [NativeAVPlayerHost] #2 item.status=failed err=AVFoundationErrorDomain/-11868 'Cannot open'
03:09:03  [NativeAVPlayerHost] #2 startup .failed is a master rejection (code=-11868); signalling engine for media fallback instead of surfacing
03:09:03  [DisplayCriteria] panel refused an HDR master (code=-11868); ...
03:09:07  playback resumes at 1834.79 s  (the keyframe before the first mount's 1844 s)

The item died behind the screensaver while paused, the recovery put a new item at 2099.69 s, and the fallback for that item came back at 1844 s, four minutes behind the pause.

The change

  • NativeAVPlayerHost records mountedStartPosition on every mount, in-place swaps included: the start seek load makes, or nil for a live rejoin, which makes none.
  • fallBackToMediaPlaylist reloads VOD at the host's mountedStartPosition, i.e. where the refused item was placed.
  • lastNativeVideoStartPosition is removed; the fallback was its only reader.

The fallback now replays exactly the start position the host last mounted with, so it stays on the same axis as that mount by construction. For a session's first mount the recorded value is the same as before (startPosition ?? 0), so the ordinary startup refusal is unchanged. Live is unchanged: it still rejoins at the edge and ignores the position.

Not changed

Both the stage-2 recovery and the fallback call host.play() even when the viewer had paused (the recovery log says "pause guard bypassed"). That can start playback behind a screensaver. It is a separate question from where the session comes back, so it is left out of this PR.

Tests

MasterFallbackPositionTests (in MasterFallbackDecisionTests.swift, next to the #98 decision tests):

swift test on macOS, rebased on 079d74b9 (7.15.2 prep): 3392 Swift Testing tests in 459 suites and 629 XCTest tests (1 skipped) pass.

Test plan

  • Unit tests above, plus the full suite.
  • On device, Apple TV 4K (3rd gen), tvOS 27.0, same HDR10+ HEVC Matroska over Jellyfin, host app Plozz. Pausing an HDR title and letting the tvOS screensaver start (2 minutes idle) reproduces the sequence above: the paused item dies with -11868 as the screensaver takes the display, the stage-2 recovery item is refused, and the media fallback runs.
    • Without this change (7.15.1): session opened at 3600 s, paused at 5474.82 s, fallback resumed at 3595.23 s.
    • With this change (this branch): session opened at 3595 s, paused at 6004.67 s, same item death / refusal / fallback sequence, position held at 6004.66 s.

🤖 Generated with Claude Code

… placed (superuser404notfound#98)

The superuser404notfound#98 media fallback replayed the start position of the session's first
mount. The superuser404notfound#93/superuser404notfound#65 stage-2 recovery swaps a fresh item in at the position
playback held, so when that recovery item was refused at startup, the
fallback rewound the session to wherever it had first been loaded.

Field log, Apple TV 4K 3rd gen, tvOS 27.0, HDR10+ HEVC Matroska opened with
a resume at 1844 s: paused at 2099.69 s, the item died behind the
screensaver, the recovery item was refused with -11868, and playback
resumed at 1834.79 s. A title started from its beginning resumes at its
first frame.

NativeAVPlayerHost now records where each mount places its item, in-place
swaps included, and the fallback reads that instead of the engine's
first-mount copy. The first mount records the same value as before, so a
fallback of a first mount is unchanged.
@superuser404notfound
superuser404notfound merged commit 4d7c60d into superuser404notfound:main Sep 24, 2026
7 checks passed
@superuser404notfound

Copy link
Copy Markdown
Owner

Merged, thank you. The fix is in the right place: recording the placement on the host covers every mount, the recovery swaps included, so the fallback stays on the same axis as the item it replaces without the engine having to track it separately. The field log and the before/after device run made this easy to verify. It will ship with the next engine release.

The pause-guard bypass you point out (stage-2 recovery and the fallback both calling play() on a paused session behind the screensaver) is a fair separate question and is noted.

@superuser404notfound

Copy link
Copy Markdown
Owner

Released in 7.16.1 (4ef5ef95). Thank you again.

Rhainland pushed a commit to Rhainland/AetherEngine that referenced this pull request Oct 9, 2026
Takes upstream main through dd1d5f8: 7.14.0 to 7.28.3 plus the
unreleased transport, audio-selection and subtitle-delay changes.

Retired fork changes, now covered upstream:
- In-place handover (dfe11a0, 745de1c): upstream superuser404notfound#483, already in
  the merge base.
- Media fallback position (a48b2bb): upstream superuser404notfound#621.
- Item-death and media-fallback pause handling (fork Silo-Server#10, Silo-Server#11):
  upstream superuser404notfound#623's play intent. The fork's AVPlayer rate stamps are
  removed. A Play or Pause pressed in iOS PiP while an item dies is no
  longer counted.

Kept, and fitted onto upstream's code:
- Refreshable HTTPRequestAuthorization on upstream's sealed relay and
  CredentialScope. Static headers follow upstream's anchor scoping.
  Resolver output stays the host's per-URL decision.
- Bounded resource fetches use upstream's held-body limit, and the
  resolver preflight keeps the 2 MB playlist cap.
- Native subtitle 503 while extraction is pending,
  nativeTimelineOffsetSeconds, ASS for local primary rendering, and
  sidecar decode off the cooperative pool.
- 16-thread software decode cap; TrueHD Atmos to APAC.

New:
- The premature-end recovery keeps a pause made during its re-seek.
- An overlay-drawn injected ASS track keeps its rendition selected
  behind a suppressing legible output, so AE#616 keeps measuring
  sourceTime.
- The APAC bridge reports an object decoder that produces nothing
  (AE#641).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.

2 participants