Skip to content

Declare sidecar subtitles as renditions on the nativeRemoteHLS bypass (#316) - #330

Merged
superuser404notfound merged 2 commits into
mainfrom
feat/issue-316-remote-hls-external-subtitle-renditions
Aug 7, 2026
Merged

superuser404notfound merged 2 commits into
mainfrom
feat/issue-316-remote-hls-external-subtitle-renditions

Conversation

@superuser404notfound

Copy link
Copy Markdown
Owner

Addresses #316. Two things were wrong, and the smaller one was invisible.

The declaration was dropped without a trace

load() routes nativeRemoteHLS into loadRemoteHLS and returns before the probe path registers LoadOptions.externalSubtitles, so a host that declared sidecars on a remote HLS source got an empty subtitleTracks back: no error, no log line, nothing to distinguish a dropped option from a source that simply has no subtitles. The AE#154 reroute onto the same bypass dropped them too. And the legible-group discovery would have undone the registration anyway: it assigned subtitleTracks wholesale rather than merging, so on any source carrying its own renditions the sidecars would have been delisted a beat after they appeared.

Both branches now register the declaration, and the discovery merges.

Renditions

The report suggested AVMutableMediaSelectionGroup. That route does not exist: media selection on an HLS asset comes from the playlist and from nowhere else, and there is no API to add an option to a remote AVURLAsset. So addExternalSubtitleTrack really is overlay-only by construction, and the only way to a rendition is a master the engine writes.

For a VOD source the engine now fetches the origin master, absolutises every variant, audio, I-frame and key URI against it, adds one EXT-X-MEDIA:TYPE=SUBTITLES per text sidecar, and serves that master from the loopback origin. The media never moves. AVPlayer still fetches every A/V byte straight from the origin, which is exactly the property the bypass exists for, so E-AC-3 / Atmos passthrough is untouched; only the master and the WebVTT renditions are local.

Details that turned out to matter:

  • Groups. A variant can reference exactly one SUBTITLES group, so the injected renditions join the origin's own group when it has one, and every distinct group when it has several. A variant that references none is pointed at the engine's.
  • Names. NAME must be unique within a group or AVFoundation collapses the options; a sidecar repeating an origin name gets a numeric disambiguator.
  • Attributes. DEFAULT=NO,AUTOSELECT=NO, no FORCED, the same discipline as the loopback master (fix(native): apply externalMetadata on iOS too #15 / Sodalite#38). Nothing self-engages; the host that declared the sidecar decides when it plays.
  • Selection. The track keeps the external id it was registered under, but selecting it drives AVMediaSelection rather than the sidecar decode. Doing both would draw the same cues twice, and only the rendition survives PiP / AirPlay / an external display.
  • AirPlay. Rendition URIs stay relative, so the AirPlay: Use en0 WiFi IP address instead of 127.0.0.1 #86 / Native subtitles cannot reach a wireless AirPlay receiver: renditions live in the master playlist, but the AirPlay path forces the media playlist #227 swap to the device's LAN IP carries them along; a session mounted while already AirPlaying hands out the LAN address immediately.
  • Degradation. Live playlists (no EXT-X-ENDLIST), bitmap sidecars, a playlist that will not rewrite, a server that will not bind and an origin slower than the 5 s budget all keep the origin URL and overlay-only subtitles, with one log line naming the reason. The load is never failed over a subtitle feature.

One measurement worth recording

AVMediaSelectionOption.displayName is not the rendition's NAME. AVFoundation derives a localized language name from LANGUAGE and ignores NAME entirely: against Apple's own CMAF master, an injected NAME="DE" reads back as "German" and the origin's NAME="简体中文" as "Chinese". The verbatim attribute does survive, in commonMetadata under the m3u8/NAME identifier, and that is what both the selection lookup and the dedupe key on now. The first implementation keyed on displayName, matched nothing, and published the sidecar twice.

Verification

Full suite 1595/1595, tvOS and iOS Simulator builds green.

End to end against devstreaming-cdn.apple.com/.../cmaf.m3u8 with an .srt sidecar:

#316: serving 1 external subtitle rendition(s) over a rewritten master at http://127.0.0.1:58436/master.m3u8; media stays at the origin
AE#154: remote-HLS legible group surfaced 8 subtitle rendition(s), 1 of them engine-injected (#316)
SELECT subtitle id=100000 codec=subrip lang=de
#316: selected injected rendition "DE" for external id=100000
[HLSLocalServer] GET /subs_0.m3u8
[HLSLocalServer] GET /subs_0_0.vtt

subtitle tracks (* = external): #100000 DE(de)*, #200001 English(en), #200002 Chinese(zh), ... #200007 Portuguese(pt)
active subtitle: 100000
final t=17.70s state=playing

HEVC 1080p playing from the CDN throughout, no duplicate entry for the sidecar, and the origin's seven renditions keep their group ordinals.

aetherctl play --sidecar <lang>=<path> is new so the whole chain is reproducible without a device, and the run summary now prints the settled track list.

Vincent Herbst and others added 2 commits August 7, 2026 17:55
…LS bypass (#316)

The nativeRemoteHLS branch returns from load() well before the probe path
registers LoadOptions.externalSubtitles, so a host that declared sidecars at
load time got an empty subtitleTracks back: no error, no log line, and no way
to tell a dropped declaration from a source that simply has no subtitles. The
AE#154 reroute onto the same bypass dropped them too.

Both branches now register the declaration themselves, and the AE#154 legible
discovery merges instead of assigning: it used to overwrite subtitleTracks
wholesale, which would have delisted the sidecars again a beat after they were
registered on any source that carries its own renditions.

Also lands the pure master rewriter the rendition work needs. Media selection
on an HLS asset comes from the playlist and nowhere else, so a sidecar can only
become a legible rendition if the engine writes the master. The rewriter
absolutises every variant, audio and key URI against the origin, so the media
still comes straight from the origin and E-AC-3/Atmos passthrough is untouched;
only the master moves. Rendition URIs stay relative so the #86/#227 AirPlay swap
to the LAN IP carries them along.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE
…e-HLS bypass (#316)

Media selection on an HLS asset comes from the playlist and nowhere else.
There is no API that adds an AVMediaSelectionOption to a remote AVURLAsset, so
addExternalSubtitleTrack could only ever drive the host overlay, which is not
drawn once the picture leaves the host's view hierarchy. PiP, AirPlay and a
wired external display lost the subtitle, and for a Plex or Jellyfin transcode
told subtitles=none the sidecar is the only copy there is.

For a VOD source the engine now writes the master itself: it fetches the
origin's, absolutises every variant, audio and key URI against it, adds one
EXT-X-MEDIA:TYPE=SUBTITLES per text sidecar (joining the origin's own group
when it has one, so a variant's group choice cannot lose them) and serves that
from the loopback origin. The media never moves: AVPlayer still fetches all A/V
bytes from the origin, which is the property the bypass exists for. Rendition
URIs stay relative so the #86/#227 AirPlay swap to the LAN IP carries them.

The tracks keep their external ids, and selecting one drives AVMediaSelection
instead of the sidecar decode, or the overlay would draw the same cues on top
of the ones AVPlayer renders. Live playlists, bitmap sidecars, an unrewritable
playlist and an origin slower than the 5 s budget all keep the origin URL and
overlay-only subtitles; the load is never failed over this.

Measured against Apple's own CMAF master rather than assumed:
AVMediaSelectionOption.displayName is NOT the rendition's NAME. AVFoundation
derives a localized language name from LANGUAGE and drops NAME entirely, so
NAME="DE" reads back as "German" and the origin's "简体中文" as "Chinese". The
verbatim attribute survives in commonMetadata under m3u8/NAME, which is what
both the selection lookup and the dedupe key on. Keying on displayName matched
nothing and published the sidecar twice.

Verified on that master end to end: 8 legible renditions surfaced (7 origin +
1 injected, no duplicate), HEVC 1080p playing straight from the CDN, selecting
external id 100000 fetches subs_0.m3u8 and subs_0_0.vtt from the loopback.

aetherctl gains `play --sidecar <lang>=<path>` so the chain is observable
without a device, and the run summary prints the settled track list.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01HX5zV3Fcf7Nzq4DYGdXvQE
@superuser404notfound
superuser404notfound merged commit 36fabdd into main Aug 7, 2026
3 checks passed
@superuser404notfound
superuser404notfound deleted the feat/issue-316-remote-hls-external-subtitle-renditions branch August 7, 2026 16:38
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