Repository navigation
perf(player): bound network demux probes, cache settings freshness, and defer startup metadata #1360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(player): bound network demux probes, cache settings freshness, and defer startup metadata #1360
Changes from all commits
7c44f74
65daf67
bb1787d
838b31f
2a0aacc
1561d5e
38a324b
8b530df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -177,6 +177,36 @@ struct AetherLoadSpec { | |
| /// selection, and none needs a sidecar. | ||
| let hlsSubtitleRenditions: [Int64: HLSSubtitleRenditionSlot] | ||
|
|
||
| /// Bounded demux probe limits for network VOD loads (4 MiB / 2 s). Keeps | ||
| /// `avformat_find_stream_info` from scanning up to 50 MiB / 60 s chasing | ||
| /// sparse bitmap subtitle tracks before first frame. | ||
| static let networkProbeSizeBytes: Int64 = 4 * 1024 * 1024 | ||
| static let networkMaxAnalyzeDurationMicros: Int64 = 2 * 1_000_000 | ||
|
|
||
| /// Whether a load may take the bounded probe. Only a network source whose | ||
| /// container header describes every stream (Matroska, MP4/MOV) does: an | ||
| /// MPEG-TS or M2TS source states its stream parameters only in packets, | ||
| /// and a local file has no network cost to save. An unknown container | ||
| /// keeps the engine default. | ||
| static func boundsDemuxProbe(sourceURL: URL, container: String?) -> Bool { | ||
| guard !sourceURL.isFileURL, let container else { return false } | ||
| return ["mkv", "matroska", "webm", "mp4", "m4v", "mov"].contains(container.lowercased()) | ||
| } | ||
|
|
||
| /// Whether an original-file load may need container-embedded font | ||
| /// attachments for ASS/SSA rendering. When false, opening with | ||
| /// `skipsContainerAttachments` avoids reading embedded fonts and cover art | ||
| /// before the first video packet. | ||
| static func needsContainerFontAttachments(for plan: PlaybackV3Plan) -> Bool { | ||
| guard plan.delivery == PlaybackProtocolV3.PlanDelivery.originalHTTP else { return false } | ||
| return plan.subtitle.inventory.contains { item in | ||
| guard item.source == "embedded" else { return false } | ||
| let codec = (item.codec ?? "").lowercased() | ||
| let isASS = codec == "ass" || codec == "ssa" || codec == "substation" | ||
| return isASS && item.fontBundleUrl == nil | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve a fallback when the font bundle fails. For a selected embedded ASS track with a bundle URL, this skips the container fonts. If the bundle request fails, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When original-file playback starts with subtitles off (or a non-ASS track selected), an embedded ASS track with a Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
|
|
||
| /// The bridge for codecs Aether cannot stream-copy, when a caller does not | ||
| /// name one. Lossless rather than Aether's `.surroundCompat` default; | ||
| /// `PlayerSettings.losslessAudioEnabled` overrides it. | ||
|
|
@@ -298,6 +328,7 @@ struct AetherLoadSpec { | |
| preferredSubtitleLanguages: preferredSubtitleLanguages, | ||
| externalSubtitles: externalSubtitles, | ||
| forwardBufferSegments: forwardBufferSegments, | ||
| progressiveSegmentDelivery: !audioOnly, | ||
| autoplay: false, | ||
| deinterlaceMode: deinterlaceMode, | ||
| deinterlaceFieldRate: deinterlaceFieldRate | ||
|
|
@@ -369,6 +400,7 @@ struct AetherLoadSpec { | |
| externalSubtitleAppTrackIDs = sidecars.map { sidecar -> Int64? in | ||
| SubtitleTrackIdSpace.makeSidecarTrackId(urlIndex: sidecar.index) | ||
| } | ||
| // No container is known here (online loads take a v3 plan); keep the default probe. | ||
| options = LoadOptions( | ||
| httpHeaders: headers, | ||
| dolbyVisionHandling: dolbyVisionHandling, | ||
|
|
@@ -384,6 +416,7 @@ struct AetherLoadSpec { | |
| preferredSubtitleLanguages: preferredSubtitleLanguages, | ||
| externalSubtitles: externalSubtitles, | ||
| forwardBufferSegments: forwardBufferSegments, | ||
| progressiveSegmentDelivery: !audioOnly, | ||
| autoplay: false, | ||
| deinterlaceMode: deinterlaceMode, | ||
| deinterlaceFieldRate: deinterlaceFieldRate | ||
|
|
@@ -560,6 +593,10 @@ struct AetherLoadSpec { | |
| delivery: plan.delivery, hasVideo: plan.effectiveRecipe.videoCodec != nil | ||
| ) | ||
| self.requestHeaderResolver = resolvesRequestCredentials && !isServerHLS ? requestHeaderResolver : nil | ||
| let hasVideo = plan.effectiveRecipe.videoCodec != nil | ||
| // Server HLS is opened by AVPlayer, not probed by Aether's demuxer. | ||
| let boundsProbe = !isServerHLS | ||
| && Self.boundsDemuxProbe(sourceURL: sourceURL, container: plan.stream.container) | ||
| var loadOptions = LoadOptions( | ||
| httpHeaders: effectiveHeaders, | ||
| httpRequestAuthorization: resolvesRequestCredentials ? requestAuthorization : nil, | ||
|
|
@@ -568,7 +605,7 @@ struct AetherLoadSpec { | |
| panelIsInHDRMode: panelIsInHDRMode ?? AetherDisplayContext.panelIsInHDRMode, | ||
| audioBridgeMode: audioBridgeMode, | ||
| objectAudioRendering: objectAudioRendering, | ||
| audioOnly: plan.effectiveRecipe.videoCodec == nil, | ||
| audioOnly: !hasVideo, | ||
| nativeRemoteHLS: isServerHLS, | ||
| preserveASSMarkup: true, | ||
| prepareNativeSubtitles: true, | ||
|
|
@@ -577,10 +614,14 @@ struct AetherLoadSpec { | |
| // planning input, not permission for the engine to select a | ||
| // different embedded or inventory track after the plan arrives. | ||
| nativeSubtitlePreferredLanguages: [], | ||
| probesize: boundsProbe ? Self.networkProbeSizeBytes : nil, | ||
| maxAnalyzeDuration: boundsProbe ? Self.networkMaxAnalyzeDurationMicros : nil, | ||
| skipsContainerAttachments: !Self.needsContainerFontAttachments(for: plan), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Register font bundles for later embedded ASS selections before skipping attachments. If subtitles start off and an embedded ASS track has When the viewer later selects that ASS track, Register the bundle on native embedded selection, or retain container attachments until that path supports bundles. |
||
| preferredAudioLanguages: preferredAudioLanguages, | ||
| preferredSubtitleLanguages: [], | ||
| externalSubtitles: externalSubtitles, | ||
| forwardBufferSegments: forwardBufferSegments, | ||
| progressiveSegmentDelivery: !isServerHLS && hasVideo, | ||
| autoplay: false, | ||
| deinterlaceMode: deinterlaceMode, | ||
| deinterlaceFieldRate: deinterlaceFieldRate | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep attachments for sidecar ASS tracks without bundles.
For an original Matroska file with attached fonts and an external ASS track without a bundle, this guard skips the attachments.
ASSSubtitleSession.prepareFontspreviously used those attachments for sidecars too. The sidecar now loses its authored fonts. Include such tracks when deciding whether to keep attachments.