Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ Changes this fork carries on top of upstream.
DTS:X keep the channel bridge whatever `objectAudioRendering` asks, and
`DualLayerDolbyVision` and `DolbyVisionStillReshaping` stay off.

- **Silo fork: a load-declared sidecar is fetched once per selection (silo-apple#600).** Selecting a
track declared in `LoadOptions.externalSubtitles` while its native-store fill was still reading the
file started a second decode of the same URL, and a server that extracts an embedded track reads the
whole source once per request. The selection now waits for that fill, showing the track as loading,
and backfills from it. A styled ASS track (`preserveASSMarkup`) backfills too: the fill decodes it
once with its markup and gives the store the plain-text reading of the same packets. A fill that
ends early or fails still hands the selection to its own decode and refetches, and so does a
bitmap sidecar the store cannot keep images for (VobSub, DVB; a `.sup` is an OCR track and never
joins the fill). Secondary selections and tracks added after load keep their own decode. A text
sidecar (`.srt`, `.ass`, `.ssa`, `.vtt`) is now read with one unranged request, in the fill and in
every selection's own decode: an origin that ignores Range and sends no length answered the ranged
open's tail, range and check requests with the whole body each time. That request has no
reconnect or retry, so one cut mid-file, refused, or unanswered falls back to the ranged open,
which resumes or retries it.

- **Silo fork: a secondary ASS sidecar stays plain text.** Upstream #826 publishes raw ASS events and
`secondarySidecarASSHeader` for a secondary sidecar when `preserveASSMarkup` is on. The fork keeps
raw ASS on the primary overlay only, as it already does for an embedded secondary track, so a host
Expand Down
228 changes: 191 additions & 37 deletions Sources/AetherEngine/AetherEngine+Subtitles.swift

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions Sources/AetherEngine/AetherEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2838,11 +2838,29 @@ public final class AetherEngine: ObservableObject {
/// Absolute AVStream index in this container, nil for its first subtitle stream.
let streamIndex: Int32?
let store: NativeSubtitleCueStore
/// #600: the registered track this target fills, so a selection waiting on it resumes.
var externalID: Int? = nil
}
let url: URL
let headers: [String: String]
var httpRequestAuthorization: HTTPRequestAuthorization? = nil
let targets: [Target]
/// #600: decode with `LoadOptions.preserveASSMarkup`, so the one fetch also yields the raw
/// event lines a styled overlay needs. The stores still get the plain-text reading.
var preserveASSMarkup = false
/// Every track this job fills `readsSequentially`, so its one decode is one unranged GET.
var sequentialSource = false
}

/// #600: what one target's store fill leaves for a selection of its track.
struct ExternalSubtitleFillOutcome: Sendable {
let externalID: Int
/// Whether the store holds the whole track (`fillHoldsWholeTrack`). Anything less sends a
/// waiting selection to a decode of its own, which refetches a truncated download and
/// decodes a bitmap track's images.
let complete: Bool
/// The raw-markup decode of a styled ASS track, which the plain-text store cannot serve.
let styled: SidecarDecodeResult?
}

/// Native WebVTT rendition store for the in-band CEA-608 track (#98). The CC tap feeds it (via
Expand All @@ -2859,6 +2877,20 @@ public final class AetherEngine: ObservableObject {

/// Whole-file decode tasks filling native stores for load-declared external tracks (#88).
var externalNativeStoreFillTask: Task<Void, Never>? = nil
/// #600: external tracks whose load-time store fill is reading the sidecar right now (the fill
/// runs one job at a time). Selecting one waits for that fill rather than fetching the same file a
/// second time; a track still queued behind another job decodes on its own, as before.
var runningExternalStoreFillIDs: Set<Int> = []
/// #600: completed fills' raw-markup decodes of styled ASS tracks, by track id.
var externalStoreFillStyledResults: [Int: SidecarDecodeResult] = [:]
/// #600: tracks whose fill read the whole sidecar this run. Such a store is
/// the whole track even when it holds no cues, so it backfills empty
/// instead of fetching the file again.
var completedExternalStoreFillIDs: Set<Int> = []
/// #600: the primary selection waiting for its track's store fill.
var primaryAwaitingExternalStoreFillID: Int?
/// #600: tags a fill run so a superseded run's completions are ignored.
var externalStoreFillGeneration: UInt64 = 0

/// Phase D: OCR worker state. Armed while the active subtitle is a needsOCR table entry;
/// cursors/pending persist across deselect/reselect (no re-recognition of covered regions)
Expand Down Expand Up @@ -4801,6 +4833,7 @@ public final class AetherEngine: ObservableObject {
pendingNativeRenderingRequest = nil
externalNativeStoreFillTask?.cancel()
externalNativeStoreFillTask = nil
resetExternalStoreFillState() // #600
resetSubtitleOCRState() // Phase D: new session, new axis
remoteHLSSubtitleDiscoveryTask?.cancel()
remoteHLSSubtitleDiscoveryTask = nil
Expand Down Expand Up @@ -7430,6 +7463,7 @@ public final class AetherEngine: ObservableObject {
pendingNativeRenderingRequest = nil // #170: the session the latched request targeted is gone
externalNativeStoreFillTask?.cancel()
externalNativeStoreFillTask = nil
resetExternalStoreFillState() // #600
Comment thread
Quick104 marked this conversation as resolved.
Resolved
resetSubtitleOCRState() // Phase D: new session, new axis
remoteHLSSubtitleDiscoveryTask?.cancel()
remoteHLSSubtitleDiscoveryTask = nil
Expand Down Expand Up @@ -8804,6 +8838,9 @@ public final class AetherEngine: ObservableObject {
cancelSidecarTask()
stopSubtitleDrainer(reason: .sessionStopped) // #112 rework: both channels
resetSubtitleOCRState() // Phase D
// #600: a software reroute or a background teardown rebuilds without a new fill run, so no
// selection may wait on, or backfill from, the one this session started.
resetExternalStoreFillState()
subtitleDrainTargets.removeAll()
softwareSubtitlePacketStore = nil
activeEmbeddedSubtitleStreamIndex = -1
Expand Down
Loading