open-standards/wai/wai-sink-swift
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Transaction Science 850eeefe64
Some checks failed
wai-web wasm32 / does this change touch it (pull_request) Has been cancelled
wai-web wasm32 / wai-web wasm32 build · corpus, menu and writers (pull_request) Has been cancelled
wai-web reach builds / wai-web reach · does this change touch it (pull_request) Has been cancelled
wai-web reach builds / wai-web reach builds · the package of record, every output as recorded (pull_request) Has been cancelled
wai-web reach builds / wai-web reach builds · this tree's wai-web, every rung on its engine line (pull_request) Has been cancelled
WAI mbt2018_mean integer decode (regenerated vectors) / does this change touch it (pull_request) Has been cancelled
WAI mbt2018_mean integer decode (regenerated vectors) / regenerate mbt2018_mean integer vectors → Rust decode, required (pull_request) Has been cancelled
wai-sink-swift native sink package / does this change touch it (pull_request) Has been cancelled
wai-sink-swift native sink package / libwai slices, desktop tests, simulator tests · macos (pull_request) Has been cancelled
wai-quantum WebGPU member / does this change touch it (pull_request) Has been cancelled
wai-quantum WebGPU member / shader checks · browser build · wasip2 inertness · MSRV (pull_request) Has been cancelled
wai-quantum WebGPU member / member · software Vulkan (linux) (pull_request) Has been cancelled
wai-quantum WebGPU member / member · Metal (macos) (pull_request) Has been cancelled
wai-quantum WebGPU member / member · discrete GPU, Vulkan (jetson-hub) (pull_request) Has been cancelled
wai-quantum WebGPU member / member · integrated GPU, Vulkan (framework-128gb) (pull_request) Has been cancelled
wai-quantum WebGPU member / member · browser WebGPU (macos) (pull_request) Has been cancelled
wai-quantum studio and desktop / does this change touch it (pull_request) Has been cancelled
wai-quantum studio and desktop / studio · browser (pull_request) Has been cancelled
wai-quantum studio and desktop / desktop app · macos (pull_request) Has been cancelled
wai-quantum WebGPU member / member · DX12 and Vulkan (cbio-windows) (pull_request) Has been cancelled
wai-pack / wai-pack · does this change touch it (pull_request) Has been cancelled
wai-pack / wai-pack · linux (pull_request) Has been cancelled
wai-pack / wai-pack · linux-arm64 (pull_request) Has been cancelled
wai-pack / wai-pack · macos (pull_request) Has been cancelled
wai-pack / wai-pack · independent verifier (Python) (pull_request) Has been cancelled
wai-pack / wai-pack · the floor through a media prober (pull_request) Has been cancelled
wai-pack / wai-pack · dependency licences (pull_request) Has been cancelled
wai-ops-gpu integer operators on GPUs / does this change touch it (pull_request) Has been cancelled
wai-ops-gpu integer operators on GPUs / builds · no adapter is not a pass (linux) (pull_request) Has been cancelled
wai-ops-gpu integer operators on GPUs / Metal GPU and browser WebGPU (macos) (pull_request) Has been cancelled
WAI neural sink gates / does this change touch it (pull_request) Has been cancelled
WAI neural sink gates / model-free refusals of the neural sink (pull_request) Has been cancelled
WAI JPEG-AI whole decode (pinned inputs, required) / does this change touch it (pull_request) Has been cancelled
WAI JPEG-AI whole decode (pinned inputs, required) / fetch pinned JPEG-AI inputs → whole decode + pixel hash, required (pull_request) Has been cancelled
WAI energy receipts / does this change touch it (pull_request) Has been cancelled
WAI energy receipts / energy receipts · linux (pull_request) Has been cancelled
WAI energy receipts / energy receipts · linux-arm64 (pull_request) Has been cancelled
WAI energy receipts / energy receipts · macos (pull_request) Has been cancelled
WAI conformance / does this change touch it (pull_request) Has been cancelled
WAI conformance / cargo-class corpora · linux (pull_request) Has been cancelled
WAI conformance / cargo-class corpora · linux-arm64 (pull_request) Has been cancelled
WAI conformance / cargo-class corpora · macos (pull_request) Has been cancelled
WAI conformance / quantum core and corpus under wasm32-wasip2 (wasmtime) (pull_request) Has been cancelled
WAI conformance / v2 vocabulary · manifests validate as stated (pull_request) Has been cancelled
WAI conformance / independent verifiers · claims, JWP, key discovery and integer payloads (Python) (pull_request) Has been cancelled
WAI conformance / delivery telemetry · CMCD and CMSD against an independent library (pull_request) Has been cancelled
WAI conformance / cross-arch byte-equality · linux (pull_request) Has been cancelled
WAI conformance / cross-arch byte-equality · linux-arm64 (pull_request) Has been cancelled
WAI conformance / cross-arch byte-equality · macos (pull_request) Has been cancelled
WAI conformance / codec wrappers · fuzz smoke, text decode limits, C entry points, provenance, the semantic path (pull_request) Has been cancelled
WAI conformance / C2PA manifest emission · signed, read back, validated (pull_request) Has been cancelled
wai-audit collector and player integration / collector · linux (pull_request) Has been cancelled
wai-audit collector and player integration / collector, player integration and the browser end to end · macos (pull_request) Has been cancelled
standards workspaces build + test / macOS energy backends (pull_request) Has been cancelled
joule-moq-web browser client / joule-moq-web · does this change touch it (pull_request) Has been cancelled
joule-moq-web browser client / joule-moq-web · browser end-to-end (macos) (pull_request) Has been cancelled
joule-moq-room room service / joule-moq-room · does this change touch it (pull_request) Has been cancelled
joule-moq-room room service / joule-moq-room, every target (pull_request) Has been cancelled
wai-audit collector and player integration / does this change touch it (pull_request) Has been cancelled
standards workspaces build + test / which workspaces this change touches (pull_request) Has been cancelled
repository checks / lockfiles, advisories, tests in CI, workflow hygiene, spec and section references, public text (pull_request) Has been cancelled
wai-sink-swift: simulator tests hosted in TestHost, in a fresh simulator, every step bounded
scripts/test-simulator.sh no longer spawns the XCTest agent through simctl, which hangs
once the host's simulator service is current. It runs the tests the way a device does:
it creates a fresh simulator (the newest installed runtime of the platform, the first
device type of its family), boots it, builds the test host for it (build-for-testing)
and runs the tests hosted in it (test-without-building), then shuts the simulator down
and deletes it however the run ends. Each step has a hard limit (boot 300 s, build 900 s,
tests 600 s by default) and fails, naming the step, when it passes it. TestHost now
builds for phones, tablets and televisions, so the television simulator runs the same
tests. wai-sink-swift.yml bounds each step as well.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 15:35:48 -04:00
..
scripts wai-sink-swift: simulator tests hosted in TestHost, in a fresh simulator, every step bounded 2026-10-26 15:35:48 -04:00
Sources/WaiSink wai: the Swift package of the native sink, and a log that keeps its order 2026-10-25 22:55:08 -04:00
TestHost wai-sink-swift: simulator tests hosted in TestHost, in a fresh simulator, every step bounded 2026-10-26 15:35:48 -04:00
Tests/WaiSinkTests wai-sink-swift: TestHost, an application the tests run inside on a phone or tablet 2026-10-26 09:59:34 -04:00
.gitignore wai-sink-swift: TestHost, an application the tests run inside on a phone or tablet 2026-10-26 09:59:34 -04:00
Package.swift wai-sink-swift: the tests read the corpus from their bundle, so they run on a device 2026-10-26 08:56:23 -04:00
README.md wai-sink-swift: simulator tests hosted in TestHost, in a fresh simulator, every step bounded 2026-10-26 15:35:48 -04:00

wai-sink-swift — the native sink for the platform player, in Swift

The native sink of extensions/native-sink.md for phones and tablets, televisions and set-top boxes, and desktops whose native player an application reaches from Swift. The player is not changed and decodes on the platform's media engine; the sink sits on the path of its requests and, for one playback session:

  • verifies a media playlist against its playlist receipt and the chain of its live revisions (http-delivery §8.6), and every object whose name states its content hash against that hash, and withholds from the player whatever does not verify;
  • signs, under a fresh key per session, stream-audit's acknowledgements of every object received, a presentation claim for each marked ad, and the session record, and posts the bundle to the owner's collector (wai-audit serve), with its Event-mode CMCD while it plays;
  • ends a session nobody can see, or whose viewer has gone idle, and stops the player's requests.

Everything that decides is libwai's C interface (native-sink §9), the same on every native platform; this package is the platform's half: the loopback relay, the player, and the signals of who can see it.

Layout

path what
Package.swift the package: library WaiSink, binary target WaiFFI (the C interface)
Sources/WaiSink/Sink.swift WaiSink: one session, every call of the C interface, JSON in and out
Sources/WaiSink/Relay.swift WaiRelay: the loopback server the player is given (native-sink §4.4)
Sources/WaiSink/PlayerSession.swift WaiPlayerSession: the platform player through the relay, observed every 200 ms (§5, §6)
Sources/WaiSink/Attention.swift WaiViewAttention: whether the application is shown, the player view's area in view, the viewer's input (§6.2); WaiFixedAttention for hosts that decide it themselves
Sources/WaiSink/Collector.swift WaiCollector: v1/sessions and v1/cmcd (stream-audit §12)
scripts/build-xcframework.sh builds build/WaiFFI.xcframework from ../wai-rs
scripts/test-simulator.sh runs the tests hosted in TestHost/ in a fresh simulator it creates, boots and deletes, every step under a hard limit
Tests/WaiSinkTests the corpus through the wrapper; the relay over the reference package's floor; the player end to end
TestHost/ a minimal application the same tests run inside on a phone or tablet, where no tool-hosted test bundle runs: an Xcode project that depends on this package by its path; consumers never see it

Use

import WaiSink

let cfg = WaiSink.Config(channel: "news-east", owner: "<the collector's key, 64 hex>")
let session = try WaiPlayerSession(url: URL(string: "https://media.example/ch/7/v.m3u8")!,
                                   config: cfg,
                                   attention: WaiViewAttention(view: playerView),
                                   collector: WaiCollector(base: URL(string: "https://collector.example/")!))
playerLayer.player = session.player     // the host shows the player as it always has
session.onEnd = { bundle, ended in /* posted already; kept here if the host wants it */ }
session.start()

For a stream the owner's packager seals (playlist receipts, segments named by their SHA-256, packaging §7), set requireSigned: true (or contentAddressed: true), and nothing the publisher did not sign reaches the decoder. For a stream another service delivers, leave both off: it is acknowledged and evidenced, never refused for what its names look like.

Build and test

On the build host (Xcode with the phone, television and desktop SDKs; Rust with the targets scripts/build-xcframework.sh names):

cd wai/wai-sink-swift
scripts/build-xcframework.sh                 # every slice; WAI_SINK_SLICES="macos ios-sim" for some
swift test                                   # the desktop: corpus, relay, player end to end
scripts/test-simulator.sh ios                # the same tests, hosted in TestHost, in a fresh phone simulator
scripts/test-simulator.sh tvos               # and in a fresh television simulator

On a phone or tablet, the tests run hosted in TestHost/ (signed with the team configured in Xcode):

xcodebuild build-for-testing -project TestHost/WaiSinkTestHost.xcodeproj -scheme WaiSinkTestHost \
  -destination 'generic/platform=iOS' -allowProvisioningUpdates DEVELOPMENT_TEAM=<team>
xcodebuild test-without-building -xctestrun <the .xctestrun it wrote> -destination 'platform=iOS,id=<device>'

The player tests make their presentation at run time with the platform's own encoder (AVC, ISO/IEC 14496-10, in fragmented MP4, a segment a second), serve it from an origin on loopback, and play it through the relay with a video output attached, since no layer is on screen in a test.

Distribution

A release builds WaiFFI.xcframework with every slice, zips it, and names it in Package.swift by URL and checksum (.binaryTarget(name: "WaiFFI", url: …, checksum: …), the checksum from swift package compute-checksum), so an application adds the package by its repository URL and a version tag. The library holds no codec: the platform's player decodes, and its codecs are the platform's, licensed with it.

Energy

The platform's player decodes in a process of the platform's, on its fixed-function decoder, which no counter an application can read covers. The session therefore states the sink decode and the display as the unmetered marker (native-sink §7), never the application's own counter as either.