Sample CodeiOS, iPadOS, Mac Catalyst, macOSReviewed 2026-07-21View on Apple Developer

Editing and playing HDR video

At a glance

Item Summary
Purpose Support high-dynamic-range (HDR) video content in your app by using the HDR editing and playback capabilities of AVFoundation.
App architecture A Metal, Swift sample bundle with entry-bearing project variants CIFilter-iOS, CommonUI-macOS, each leading to AVFoundation APIs.
Main patterns Delegate or data-source callbacks, Coordinator, Builder, Binding-based state propagation
Project style 10 scanned source file(s) across Metal, Swift, organized around ranked entry, type, and file boundaries.
Execution model No structured execution marker indexed; callback threading requires source review.
State/event model Source-visible mechanisms: SwiftUI state property wrapper, NotificationCenter.
Key frameworks/packages AVFoundation, AVKit, CoreImage, Foundation, SwiftUI; these are source dependencies, not architecture labels.

Project structure

Source bundle/
├── CommonUI-macOS/
│   ├── ContentView.swift
│   └── AppDelegate.swift
├── CIFilter-iOS/
│   ├── AppDelegate.swift
│   ├── ContentView.swift
│   └── SceneDelegate.swift
├── CustomCompositor/
│   └── AVVideoCompositionBuilder.swift
├── CommonSource/
│   ├── Composition.swift
│   └── HDRIndicator.ci.metal
├── BuiltInCompositor/
│   ├── AVVideoCompositionBuilder.swift
│   ├── Base.lproj/
│   │   └── Main.storyboard
│   └── BuiltInCompositor.entitlements
└── CIFilter/
    └── AVVideoCompositionBuilder.swift

Structure observations

  • Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
  • Primary languages: Metal, Swift.
  • The verified tree contains 14 project/configuration file(s) and 21 source declaration(s).

Overall architecture

Reference code

CIFilter-iOS/AppDelegate.swift:10 — architecture anchor

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        return true
    }

    // MARK: UISceneSession Lifecycle

    func application(_ application: UIApplication,
                     configurationForConnecting connectingSceneSession: UISceneSession,
                     options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

}

Interpretation

The branches represent separate entry-bearing project variants in the downloaded bundle, not runtime calls between those variants. Each branch is intentionally collapsed at the documented framework boundary; the detailed target-local flow remains in the cited files. Ownership is claimed only where the next section cites a stored property or assignment.

Ownership and state

Ownership evidence

CommonUI-macOS/ContentView.swift:30 — stored dependency or nearest verified ownership anchor

class PlayerView: AVPlayerView {
    // ...
        self.player = player
    // ...
}
Owner Object or state Relationship Mutation authority
PlayerView Player (player) stores or receives App/module collaborators
Coordinator PlayerView (playerView) stores or receives App/module collaborators
ContentView AlertReason (alertReason) owns wrapper-managed state Owning lexical scope
ContentView ProgressChecker (exportProgressChecker) owns wrapper-managed state Owning lexical scope

Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.

Concurrency, scheduling, and thread safety

Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.

No source-visible execution, scheduling, or synchronization boundary was found in the indexed source.

@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.

State propagation, frameworks, and dependencies

Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.

Category Mechanism or module Verified role Evidence
State propagation SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. CommonUI-macOS/AppDelegate.swift:20
State propagation NotificationCenter NotificationCenter distributes named process-local events. CommonUI-macOS/AppDelegate.swift:38
Source import AVFoundation The cited file imports this module; runtime use and architectural role are not inferred. BuiltInCompositor/AVVideoCompositionBuilder.swift:12
Source import AVKit The cited file imports this module; runtime use and architectural role are not inferred. BuiltInCompositor/AVVideoCompositionBuilder.swift:11
Source import CoreImage The cited file imports this module; runtime use and architectural role are not inferred. CIFilter/AVVideoCompositionBuilder.swift:12
Source import Foundation The cited file imports this module; runtime use and architectural role are not inferred. BuiltInCompositor/AVVideoCompositionBuilder.swift:10
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. CIFilter-iOS/ContentView.swift:9
Source import UIKit The cited file imports this module; runtime use and architectural role are not inferred. CIFilter-iOS/AppDelegate.swift:8

receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.

Class and protocol design

CIFilter-iOS/AppDelegate.swift:11 — representative type boundary

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    // ...
        return true
    // ...
}
Type Responsibility Depends on or conforms to
AppDelegate Receives callback-driven events UIResponder, UIApplicationDelegate
AppDelegate Receives callback-driven events NSObject, NSApplicationDelegate
PlayerView User-interface presentation and input forwarding AVPlayerView
Coordinator Cross-object flow or session coordination Concrete collaborators/imported frameworks
ContentView User-interface presentation and input forwarding View
ContentView User-interface presentation and input forwarding View
AVVideoCompositionBuilder Incrementally constructs a framework value or graph Concrete collaborators/imported frameworks
AssetLoader Loads and prepares feature data or resources Concrete collaborators/imported frameworks
AVVideoCompositionBuilder Incrementally constructs a framework value or graph Concrete collaborators/imported frameworks
SceneDelegate Receives callback-driven events UIResponder, UIWindowSceneDelegate

No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.

Access control

Symbol Access Verified effect Likely rationale
exportSession (CommonSource/Composition.swift:37) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: keep state mutation or dependency lifetime inside the owning implementation.
exportAsset (CommonUI-macOS/AppDelegate.swift:13) public The symbol is visible to importing modules. Inference: make the declaration available across a module or target boundary.
showingExportDone (CommonUI-macOS/AppDelegate.swift:20) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: keep state mutation or dependency lifetime inside the owning implementation.
showingAlert (CommonUI-macOS/ContentView.swift:73) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: keep state mutation or dependency lifetime inside the owning implementation.

Reference code

CommonSource/Composition.swift:37 — representative boundary

    struct ProgressChecker {
        private var exportSession: AVAssetExportSession? = nil
        // ...
    }

Swift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.

Logic ownership and placement

Logic Owning type or file Placement rationale
Incrementally constructs a framework value or graph AVVideoCompositionBuilder The source’s Builder suffix makes this role explicit.
Cross-object flow or session coordination Coordinator The source’s Coordinator suffix makes this role explicit.
Receives callback-driven events AppDelegate, SceneDelegate The source’s Delegate suffix makes this role explicit.
Loads and prepares feature data or resources AssetLoader The source’s Loader suffix makes this role explicit.
User-interface presentation and input forwarding ContentView, PlayerView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Delegate or data-source callbacks CIFilter-iOS/AppDelegate.swift:11 Callback protocols invert event delivery back into the sample’s owner.
Coordinator CommonUI-macOS/ContentView.swift:42 A role-named coordinator centralizes cross-object flow.
Builder BuiltInCompositor/AVVideoCompositionBuilder.swift:14 A builder-named type owns incremental construction.
Binding-based state propagation CommonUI-macOS/ContentView.swift:161 A binding exposes controlled read/write access while the upstream owner remains authoritative.

Naming conventions

  • Types: Builder: AVVideoCompositionBuilder; Coordinator: Coordinator; Delegate: AppDelegate, SceneDelegate; Loader: AssetLoader; View: ContentView, PlayerView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: play, pause, updateNSView, makeNSView, makeCoordinator, triggerAlert, exportAsset, getProgressPercentage.
  • Files: CommonUI-macOS/ContentView.swift, CIFilter-iOS/AppDelegate.swift, CommonUI-macOS/AppDelegate.swift, CIFilter-iOS/ContentView.swift, CustomCompositor/AVVideoCompositionBuilder.swift, BuiltInCompositor/AVVideoCompositionBuilder.swift.

Architecture takeaways

  • AppDelegate is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches AVFoundation, AVKit, CoreImage, SwiftUI through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
  • Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
  • Access-control conclusions separate verified language visibility from the likely design rationale.
  • The source does not justify labeling the design protocol-oriented.

Source map

Source file Relevant symbols
CIFilter-iOS/AppDelegate.swift Cited implementation, AppDelegate, UIKit
CommonUI-macOS/ContentView.swift Cited implementation, Coordinator, PlayerView, PlayerViewRepresentable, ContentView, AlertReason, ProgressPopup, ContentView_Previews
CommonSource/Composition.swift Cited implementation, AssetLoader, AssetExporter, ProgressChecker, FilterError, HDRIndicatorFilter
CommonUI-macOS/AppDelegate.swift Cited implementation, SwiftUI state property wrapper, NotificationCenter, AppDelegate
BuiltInCompositor/AVVideoCompositionBuilder.swift AVVideoCompositionBuilder, AVFoundation, AVKit, Foundation
CIFilter/AVVideoCompositionBuilder.swift CoreImage, AVVideoCompositionBuilder
CIFilter-iOS/ContentView.swift SwiftUI, AVPlayerViewControllerRepresentable, ContentView, ContentView_Previews
CustomCompositor/AVVideoCompositionBuilder.swift CustomCompositorError, SampleCustomCompositor, AVVideoCompositionBuilder
CIFilter-iOS/SceneDelegate.swift SceneDelegate
CommonSource/HDRIndicator.ci.metal Feature implementation