Mixed clear/encrypted HLS audio fails across MSE discontinuity — verified Shaka fix

GitHub source

Reproduced. This page is generated from GitHub Issue #52; GitHub remains the canonical authoring and discussion source.

Local reproduction and solution — 18 November 2026#

Status: MP4 source patch verified; longer current-Safari playback still exposes a recovered decode error.

Source and evidence#

Upstream case · local report and evidence · portable reproduction instructions

Observed results are Reproduced only within the stated seam. Implementation explanations remain Inferred, not Apple Confirmed.

Reconstruct the scene#

The original public mixed playlists splice encrypted→clear around 120 s and clear→encrypted around 372.35 s. Safari 26.3.1 with Shaka 4.10.0/MSE reports 3016 and media error 3. A same-base actual MediaSourceEngine/MP4 test isolates missing sample-description signaling.

The isolated patch changes the actual tfhd sample-description flag from absent to description 2, repairs sizes/trun offsets, and preserves mdat bytes; 84 tests pass. Shaka 5.2.12 crosses the encrypted→clear boundary. A longer clear→encrypted MSE run still emits media error 3, stalls, then automatically recovers. Its historical playback-progress label is not a clean pass.

Solution / guideline#

The five-file production patch from upstream #8354 is supplied. Do not describe it as eliminating the newer Safari residual MSE decoder issue. A tested opt-in native-HLS plus explicit legacy FairPlay control crosses the boundary without errors in 30 s, with startup/key-transition delay and the provider-compatible license adapter.

Selected production patch · longer MSE trace · native legacy control

Limits / remaining work#

4.10.0 versus 5.2.12 changes multiple components; only the same-base byte-level regression isolates #8354. Native legacy is not a seamless-playback guarantee. Original Safari 18.3 and audible continuity were not tested.

This update supersedes earlier no-local-run statements below only within the stated scope. Historical source reports are retained; no unresolved issue is closed by this publication.


Earlier investigation and source history

Verification update — 17 November 2026#

Status: reproduced and solution confirmed upstream; fix merged. PR #8354 merged on 2025-04-03 as 5f182319fccb9a9c9b66ea964a9d3c319288d5cb.

  • Reproduction: Safari 18.3, Shaka 4.10 MSE, audio enabled, play through clear→encrypted and encrypted→clear discontinuities. The original issue supplies test playlists; disabling audio avoids the failure.
  • Confirmed outcome: a maintainer reports the merged change fixes both the public reproduction and internal streams.
  • Solution: the complete MP4 encryption-signaling workaround in #8354, including clear-media sample-description selection and tfhd/trun adjustments on affected Apple audio paths. Use a build containing this patch and validate both transition directions.
  • Scope: upstream reproduction and successful workaround; no local Safari/device playback was run in this review. The private Safari/AVFoundation mechanism and applicability to native AVPlayer are not established by this fix.

This update supersedes older statements below about missing fix verification; the historical investigation and prompt are retained.


Source: shaka-project/shaka-player#8335
Upstream fix: shaka-project/shaka-player#8354
Merged commit: 5f182319fccb9a9c9b66ea964a9d3c319288d5cb

Problem and observed behavior#

On Safari 18.3, Shaka Player 4.10 using MSE (useNativeHlsForFairPlay: false) reported error 3016 when crossing an HLS discontinuity between clear and FairPlay-encrypted media. The reporter tested both clear → encrypted and encrypted → clear. Disabling audio avoided the failure; native Safari playback reportedly worked. Maintainers also observed that license requests could be missing during ordinary cross-boundary playback, although seeking directly into the encrypted region behaved differently.

These are upstream reports, not measurements performed for this article.

Evidence and verdict#

Shaka merged PR #8354, titled “fix: Mixed clear/encrypted playback on Safari MSE.” A maintainer reported that the change fixed both the public reproduction and internal streams. The merged patch and its tests provide implementation-level evidence of a successful client workaround, but do not independently prove the underlying private Safari decoder/DRM mechanism.

The patch is more specific than a generic FairPlay license retry: it adjusts ISO BMFF signaling for clear media when encryption is expected on Apple audio paths.

First causal boundary#

HLS discontinuity: encrypted <-> clear
  -> new init/media segment and audio sample description
  -> Shaka MSE append path
  -> encryption-compatible sample-entry metadata
  -> tfhd sample_description_index / trun offset
  -> SourceBuffer append / key lifecycle / decoder
  -> playback or 3016

The original report establishes a boundary-dependent failure, not the exact failing internal Safari operation. The merged patch narrows the relevant client-controlled boundary to MP4 encryption signaling and sample-description selection.

Verified upstream patch#

In PR #8354, the diff:

  • Adds ContentWorkarounds.fakeMediaEncryption() and a per-chunk rewrite that selects sample description index 2, updating tfhd and trun metadata as needed.
  • Extends MediaSourceEngine.workAroundBrokenPlatforms_ to inspect the segment reference, encryption state and MP4 container, applying the workaround to media segments as well as init segments.
  • Applies Apple-specific encryption-info requirements to audio in Platform.requiresEncryptionInfoInAllInitSegments and requiresTfhdFix.
  • Removes the unconditional Apple RESET_ON_ENCRYPTION_CHANGE configuration override and adds integration coverage for mixed clear/encrypted playback.

The source diff is direct evidence of what changed. The public issue comments report successful playback after merging; this run did not reproduce the stream independently.

Competing hypotheses and falsification#

  1. Incorrect sample-description/encryption signaling on the MSE audio path: compare stsd, sinf, tenc, tfhd and trun before/after the patch; validate box sizes, offsets and audio output.
  2. Missing FairPlay key acquisition at the transition: correlate encrypted, SPC/license request and key status; do not assume a missing HTTP request is the primary cause.
  3. Incorrect byte-range or media bytes: preserve manifest/segment hashes and compare request ranges and returned bytes.
  4. Native Safari vs MSE behavior: run the same authorized asset through both paths; avoid extrapolating WebKit internals to AVPlayer.

Verification plan and client-only guidance#

Compare affected Shaka 4.10 and a build containing PR #8354 on the same Safari build with byte-identical assets. Run both boundary directions, audio+video versus video-only, and native src= versus MSE; collect monotonic event traces, network transactions, parsed MP4 box structures, error chains and actual playback progress.

For Shaka clients, prefer a maintained release that includes the merged fix, or validate a controlled backport with regression tests. Do not use unconditional player recreation, DRM license retries, or a packaging change as a presumed fix. Packager/KSM changes remain separate proposals.

Reusable engineering rule#

A clear-to-encrypted HLS discontinuity is not only a playlist event: for MSE/fMP4 it can change the sample-entry and DRM expectations of the active SourceBuffer. Inspect the actual init and fragment metadata before blaming the license server or decoder.

Evidence limits#

Upstream source and merged PR were inspected; no local Safari/iPhone reproduction, raw segment validation or AVFoundation trace was performed. Shaka-level workaround verified upstream; deeper Safari internal root cause unverified.

Extended investigation prompt#

Copy the full second-AI reverse-engineering prompt
Act as a senior iOS/tvOS reverse engineer, AVFoundation/CoreMedia investigator, ISO BMFF/HLS forensic engineer, WebKit EME analyst, and FairPlay DRM specialist.

CASE: https://github.com/shaka-project/shaka-player/issues/8335
PATCH: https://github.com/shaka-project/shaka-player/pull/8354

OBJECTIVE: Independently identify the first proven causal divergence when Safari 18.3 Shaka MSE crosses clear/encrypted HLS audio boundaries. Separate the confirmed upstream workaround from unverified private Safari/AVFoundation internals.

STRICT EVIDENCE HIERARCHY:
T1: Apple Developer Documentation, FairPlay Streaming SDK, HLS Authoring Specification, W3C MSE/EME, ISO BMFF/CENC and IETF standards. Quote precise contracts and versions.
T2: Pinned Shaka commit/diff, verified WebKit source, Apple open-source code, symbolicated AVFoundation/CoreMedia/CFNetwork traces, independently verified security research. For EVERY source-level claim include repository URL, SHA, file, function, exact lines, and actual control flow. WebKit is not native AVPlayer source.
T3: Byte-hashed playlists, init/media segments, box-level parsing, authorized KSM metadata, network/EME timelines, repeatable controlled Safari and physical-device tests.
T4: Clearly labeled falsifiable hypotheses. Never elevate reporter assumptions or proposed mechanisms into facts.

TRACE: EXT-X-DISCONTINUITY and EXT-X-KEY -> rendition selection -> init sample entries (stsd: mp4a/enca, sinf/tenc) -> moof/traf/tfhd sample_description_index -> trun data_offset -> SourceBuffer.appendBuffer -> encrypted/initData event -> SPC/license/CKC -> key status -> decoded audio/video output.

AUDIT PR #8354: fakeEncryption, fakeMediaEncryption, media_source_engine workAroundBrokenPlatforms_, requiresEncryptionInfoInAllInitSegments, requiresTfhdFix, and tests. Explain why encrypted-compatible sample-description signaling and tfhd offsets matter. Check that transformations preserve sample payloads, box sizes, offsets and valid track selection. Do not assert all Safari builds require this workaround.

CONTROLLED TESTS: encrypted->clear and clear->encrypted, audio+video vs video-only, native src= vs MSE, affected vs fixed Shaka, same media and OS. Capture monotonic timestamps, encrypted/message/keystatuseschange, HTTP and KSM transaction metadata, SourceBuffer append errors, exact segment hashes, audio continuity, and full errors. Repeat trials; change one variable at a time. Independently compare native AVPlayer without assuming the same MSE bug.

SECURITY: Authorized FairPlay assets only. Never disclose keys, certificates, tokens, SPC/CKC bytes or bypass DRM.

ROOT CAUSE: Distinguish verified Shaka patch and upstream test outcomes from the deeper Safari mechanism, which needs independent evidence. Declare a root cause only with reproducible failure, first divergence, controlled reversal and competing hypotheses tested. Otherwise mark ROOT CAUSE UNVERIFIED.

OUTPUT: executive finding; evidence ledger (claim, tier, source, counterevidence, confidence, falsification); manifest/box audit; failing vs fixed timelines; exact pinned source analysis; first divergence; AVPlayer boundary; experiments; client-only mitigation; separately labeled packaging/KSM proposals; regression tests; unknowns; source URLs; and publication-ready concise article. Never invent measurements or citations.