Skip to content

fix(native): declare the HLS MIME type on the #154 reroute so a mis-typed playlist plays - #1040

Merged
superuser404notfound merged 2 commits into
superuser404notfound:mainfrom
yucelokan:fix/hls-mime-on-playlist-reroute
Nov 12, 2026
Merged

superuser404notfound merged 2 commits into
superuser404notfound:mainfrom
yucelokan:fix/hls-mime-on-playlist-reroute

Conversation

@yucelokan

Copy link
Copy Markdown
Contributor

Summary

The #154 reroute moves a VOD load onto the AVPlayer bypass because the engine read #EXTM3U in the body, but AVFoundation types a URL by its path extension and Content-Type, never by its body. A playlist at /movie.mp4 served as video/mp4 or application/octet-stream (a common shape for IPTV VOD links) therefore failed on the bypass within a third of a second with AVFoundation -11829 / -11828, after the engine had already found the route that plays it. The rerouted asset now declares application/vnd.apple.mpegurl with AVURLAssetOverrideMIMETypeKey.

What changed

  • LoadOptions gets an engine-internal hlsPlaylistProvenByBody (not settable from the public initializer, like isLiveRejoin). The Support remote HLS external WebVTT subtitles in loopback mode (non-nativeRemoteHLS) #154 reroute and the AE#246 second-open reroute set it next to nativeRemoteHLS = true. It rides loadedOptions, so reloadAtCurrentPosition and the other rebuilds of a rerouted session, which go straight onto the bypass without a probe, keep it. Added to SessionOptionCorrection.knownFields.
  • NativeAVPlayerHost.SessionLoadContract.declaresHLSPlaylistMIMEType, set by loadRemoteHLS from that flag. Session-wide like httpHeaders, so in-place swaps keep it.
  • assetCreationOptions(httpHeaders:declaresHLSPlaylist:) adds the override key; the load log line gains mime=hls(body) when it is set.
  • A host-set nativeRemoteHLS load and the loopback path declare nothing; AVFoundation types those URLs as before.
  • New MisTypedPlaylistRerouteTests; CHANGELOG.md (Fixed) and docs/guide.md (the Support remote HLS external WebVTT subtitles in loopback mode (non-nativeRemoteHLS) #154 paragraph).

Test plan

  • Device / OS: MacBook (arm64), macOS 27.0.1, Xcode 27.2.
  • Source media: synthetic only. ffmpeg testsrc2 + sine, H.264 Main / AAC, 6 x 2 s MPEG-TS segments, VOD playlist, behind a local origin that serves the playlist at /movie/<case>.mp4, directly or through a 302, with a chosen Content-Type. Plus the suite's own 32 s H.264 / AAC TS fixture.
  • aetherctl play --seconds 6 per case, with the override disabled and then enabled, same build otherwise:
Case (final URL, Content-Type) Without With
/movie/x.mp4, video/mp4 exit 2, AVFoundation -11829 plays, first frame t+0.07 s
/movie/x.mp4, application/octet-stream exit 2, -11829 plays, t+0.07 s
302 to /hls/play (no extension), video/mp4 exit 2, -11829 plays, t+0.07 s
302 to /hls/play, application/octet-stream exit 2, -11828 plays, t+0.07 s
302 to /hls/stream.mp4, video/mp4 exit 2, -11829 plays, t+0.08 s
/movie/x.mp4, application/vnd.apple.mpegurl plays plays
302 to /hls/index.m3u8, HLS type plays plays
a real progressive MP4 plays on loopback plays on loopback, nothing declared
  • MisTypedPlaylistRerouteTests (7 tests): the asset option seam; a playlist at /vod/movie.mp4 typed video/mp4 and application/octet-stream reaches readyToPlay through engine.load; reloadAtCurrentPosition mounts a new item that still declares the type and plays; a host-set nativeRemoteHLS .m3u8 load and a real MP4 at the same URL shape declare nothing. With the override disabled the two playback tests and the rebuild test fail (failure != nil, isReady == false), the others pass.
  • On this branch (upstream main + this commit): swift build --build-tests, then MisTypedPlaylistRerouteTests, Issue119RemoteHLSHeaderTests, Issue460ReloadWithOptionsTests (field inventory), Issue246SecondOpenRerouteTests, Issue440LiveJoinRollTests, Issue316BypassExternalSubtitleTests, PublicAPIDocumentationTests, DocumentedConstantsTests: XCTest 34/34, swift-testing 100 passed. Scripts/check-doc-links.py and Scripts/check-test-hygiene.py clean.
  • The full default suite ran on the same change applied to 7.58.0: XCTest green; swift-testing 5731 tests with 5 issues, none in the code this touches. Two (ItemSwapStillTests 500 ms bound, SourceFailureDiagnosticsTests live connection error) pass when rerun alone; three (Issue220SoftwareDecoderDrainTests, APACEncodePipelineTests, LiveAudioProgressTests.test_videoDelivery_sourceReadHeld_drainsReadyVideo) fail the same way on 7.58.0 without this change on this Mac, so I read them as local environment, not this PR.
  • Not tested: tvOS / iOS devices. The override key is public API since iOS / tvOS 17 and macOS 14, below the package minimums.

Checklist

  • CHANGELOG.md updated
  • Commit messages follow Conventional Commits (feat(...), fix(...), chore(...))
  • The fix lives in the engine, not in a host-side workaround
  • Public API changes are intentional and documented (no public API change; the new LoadOptions field is internal)

🤖 Generated with Claude Code

…reroute so a mis-typed playlist plays

The superuser404notfound#154 reroute moves a load onto the AVPlayer bypass because the engine read
#EXTM3U in the body, but AVFoundation types a URL by its path extension and
Content-Type only. A VOD playlist at /movie.mp4 served as video/mp4 or
application/octet-stream therefore failed on the bypass with AVFoundation
-11829 / -11828 within a third of a second.

The reroute (and the AE#246 second-open reroute) now marks the options with
engine-internal body evidence, and the bypass creates the asset with
AVURLAssetOverrideMIMETypeKey = application/vnd.apple.mpegurl. The flag rides
loadedOptions and the session contract, so rebuilds and in-place swaps of the
rerouted session keep it. A host-set nativeRemoteHLS load and the loopback path
declare nothing.

Co-Authored-By: Paperclip <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
yucelokan added a commit to yucelokan/AetherEngine that referenced this pull request Nov 12, 2026
…laration as fork-only until upstream superuser404notfound#1040

Co-Authored-By: Paperclip <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

@quint-aether quint-aether Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review

Status: 🟡 Minor follow-ups. Only small touch-ups left.

When the engine has read the body and found an HLS playlist (the AE#154 reroute and the AE#246 second-open reroute), the bypass asset now declares application/vnd.apple.mpegurl through AVURLAssetOverrideMIMETypeKey. Without it, a playlist behind an .mp4 or extensionless URL, served as video/mp4 or application/octet-stream, fails on AVFoundation's own typing. The direction is right. The fix is in the engine, it goes only where the engine has evidence, and a host-set nativeRemoteHLS load keeps AVFoundation's typing.

Things I checked that hold up:

  • Flag lifetime. The flag cannot be set from the public initializer, so every host load() starts at false. It rides loadedOptions, so reloadAtCurrentPosition (which goes straight onto the bypass without a probe) keeps it. A correction closure cannot reach it from outside the module.
  • Field order. hlsPlaylistProvenByBody is the last stored property of LoadOptions and the last entry in knownFields. That keeps the ordered fieldInventoryIsComplete comparison green.
  • Contract. declaresHLSPlaylistMIMEType sits on SessionLoadContract, so in-place swaps reuse it the same way they reuse httpHeaders. The loopback route builds its own contract, where the value defaults to false.
  • Stand-in URL. On the #316 / AE#495 stand-in path the declaration lands on the loopback master instead of the origin URL. That URL is a playlist too, so this does no harm.
  • API. No public API change. The new field and the static are internal.
  • Availability. The override key's minimum OS versions are below the package's minimums.

Findings

  • Nit: The guide's #154 paragraph now covers two unrelated topics: subtitle media selection and MIME typing on the reroute. CLAUDE.md asks for one idea per paragraph, with new facts not appended to an existing one. A short paragraph of its own (for example "Mis-typed playlists on the reroute (#154)") would fit the house style better. (docs/guide.md:418)

Checklist: CHANGELOG yes, docs yes, tests yes, traits both ways n.a.

Needs a device run: whether tvOS and iOS honour the override the same way on a real IPTV origin (the measurements are macOS-only). The same goes for a master playlist whose variant playlists are themselves served under .mp4 paths with a video type: the override applies only to the asset's top-level URL.

Thanks for the careful measurement table and for keeping the declaration limited to the cases the engine has proven.

Automated review by Quint (Claude) of 70010f1. It reads the code, it does not build or run it; a maintainer reviews and merges.

Comment thread docs/guide.md Outdated
**Live `m3u8` on the loopback path** (#363). The raw live path reads bytes, not playlists. It used to reject an `.m3u8` with a typed `hlsPlaylistOnRawLivePath` error that named the reader the host should have built. Now it builds that reader itself, with `LoadOptions.httpHeaders` on the playlist, every segment and every AES key, which is what a tokenized IPTV origin checks per request. Credential headers stay with the playlist's own origin: a segment or key on another host, or on http:// behind an https:// playlist, gets the other headers but not the token. A custom `IOReader` with the same mistake still gets the typed error, because it has no playlist URL to ingest from.

**Non-live `m3u8` on the loopback path** (#154). The bundled FFmpeg is built without network support, so the playlist can never be demuxed locally, and remote HLS is AVPlayer's job anyway. On the bypass, the engine lists the stream's external WebVTT renditions (the legible `AVMediaSelectionGroup`) as `subtitleTracks`. `selectSubtitleTrack(index:)` and `clearSubtitle()` drive AVPlayer's media selection, and AVPlayer draws the cues.
**Non-live `m3u8` on the loopback path** (#154). The bundled FFmpeg is built without network support, so the playlist can never be demuxed locally, and remote HLS is AVPlayer's job anyway. On the bypass, the engine lists the stream's external WebVTT renditions (the legible `AVMediaSelectionGroup`) as `subtitleTracks`. `selectSubtitleTrack(index:)` and `clearSubtitle()` drive AVPlayer's media selection, and AVPlayer draws the cues. The reroute is decided by the body (`#EXTM3U`), not by the URL, so the engine tells AVFoundation what it found: the asset declares `application/vnd.apple.mpegurl` (`AVURLAssetOverrideMIMETypeKey`). A playlist behind a URL without `.m3u8` that the origin serves as `video/mp4` or `application/octet-stream` plays instead of failing with AVFoundation -11829 / -11828. A host that sets `nativeRemoteHLS` itself gets no declaration; AVFoundation types that URL as it always has.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this paragraph now covers two separate topics: AVPlayer media selection for WebVTT renditions, and declaring the MIME type on the reroute. CLAUDE.md asks for one idea per paragraph and for new facts not to be appended to an existing one. Consider moving the new sentences into a short paragraph of their own right after this one, for example Mis-typed playlists on the reroute (#154), keeping the same three facts: the reroute is decided by #EXTM3U, the asset declares application/vnd.apple.mpegurl, and a host-set nativeRemoteHLS load gets no declaration.

…wn paragraph

The superuser404notfound#154 paragraph covered two topics: AVPlayer media selection for WebVTT
renditions and the MIME declaration on the reroute. The declaration now has
its own paragraph with the same three facts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@quint-aether quint-aether Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review

Status: 🟢 Clean. Nothing left to fix, ready for a maintainer.

I checked the new head (feae34a). The earlier nit is fixed: the guide now gives mis-typed playlists their own paragraph, Mis-typed playlists on the reroute (#154), at docs/guide.md:420. Nothing else in this push affects the review. There are no open findings.

Checklist: CHANGELOG yes, docs yes, tests yes, traits both ways n.a.

Needs a device run: whether tvOS and iOS honour the override the same way against a real IPTV origin, since all the measurements are from macOS.

Thanks for the quick follow-up.

Automated review by Quint (Claude) of feae34a. It reads the code, it does not build or run it; a maintainer reviews and merges.

@yucelokan

Copy link
Copy Markdown
Contributor Author

Thanks. feae34a moves the MIME declaration into its own paragraph, Mis-typed playlists on the reroute (#154), right after the media selection paragraph, with the same three facts. Scripts/check-doc-links.py passes. No code or test changed.

On the device run: the before/after numbers are from macOS only. We have not run this on tvOS or iOS hardware yet, and we will not test against a real provider URL here. We are arranging a run of the same synthetic fixture on an Apple TV and an iPhone: a playlist behind an .mp4 URL and an extensionless one, served as video/mp4 and application/octet-stream. We will post the result on this PR, or say here if we cannot do the run.

On variant playlists under .mp4 paths: right, the declaration reaches only the asset's own URL. AVFoundation fetches and types the variant playlists itself, and this PR does not change that. We have not measured that case yet. We will add it to the same fixture run: a master reached through the reroute whose variant playlists sit under .mp4 paths served as video/mp4. We will report what AVFoundation does with it.

@superuser404notfound
superuser404notfound merged commit 50bae75 into superuser404notfound:main Nov 12, 2026
6 checks passed
@superuser404notfound

Copy link
Copy Markdown
Owner

Merged in 50bae75, thanks! The before/after table made this an easy one to follow, and keeping the declaration to the cases where the engine has read the body is exactly the right scope.

Two small things changed in the merge: the CHANGELOG entry moved to [Unreleased], and the docs paragraph now sits in docs/formats.md right after the #154 paragraph, because main had moved that section out of the guide in the meantime.

It ships with the next engine release. I'm looking forward to the Apple TV / iPhone run, including the master whose variant playlists sit under .mp4 paths.

superuser404notfound pushed a commit that referenced this pull request Nov 12, 2026
CLAUDE.md, the PR template and Quint's review checklist now say it outright: each changed behaviour,
option, format or CLI flag goes to the docs page that owns the topic, in plain short sentences, and
the CHANGELOG entry does not count. Quint checks placement against the current docs, because a branch
that predates a restructure can write into a file that no longer holds the topic (PR #1040).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SeT6NgMt1vv32kPBhUmsUz
yucelokan added a commit to yucelokan/AetherEngine that referenced this pull request Nov 12, 2026
…laration as fork-only until upstream superuser404notfound#1040

Co-Authored-By: Paperclip <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[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