Sample CodemacOSReviewed 2026-07-21View on Apple Developer

Playing and editing Cinematic mode video

At a glance

Item Summary
Purpose Play and edit Cinematic mode video with an adjustable depth of field and focus points.
App architecture A Metal, Swift sample with the source-visible chain CinematicVideoPlaybackAndEditingAppContentViewCinematicPlayerCinematic APIs.
Main patterns Protocol-oriented abstraction, Binding-based state propagation, Actor-isolated state
Project style 15 scanned source file(s) across Metal, Swift, organized around ranked entry, type, and file boundaries.

Project structure

Source bundle/
└── CinematicVideoPlaybackAndEditing/
    ├── CinematicVideoPlaybackAndEditingApp.swift
    ├── ContentView.swift
    ├── AssetView.swift
    ├── CinematicPlayer.swift
    ├── PlayerLayerView.swift
    ├── SampleCustomCompositor.swift
    ├── CinematicAssetReader.swift
    ├── CinematicAsset.swift
    ├── CinematicAssetData.swift
    ├── CinematicEditHelper.swift
    ├── CinematicEditor.swift
    └── PlayerLayerContainer.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 4 project/configuration file(s) and 18 source declaration(s).

Overall architecture

Reference code

CinematicVideoPlaybackAndEditing/CinematicVideoPlaybackAndEditingApp.swift:10 — architecture anchor

@main
struct CinematicVideoPlaybackAndEditingApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

Interpretation

The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into Cinematic.

Ownership and state

Ownership evidence

CinematicVideoPlaybackAndEditing/ContentView.swift:13 — stored dependency or nearest verified ownership anchor

struct ContentView: View {
    // ...
    @State private var selectedPickerItem: PhotosPickerItem?
    // ...
}
Owner Object or state Relationship Mutation authority
ContentView PhotosPickerItem (selectedPickerItem) owns wrapper-managed state Owning lexical scope
ContentView CinematicAsset (selectedAsset) owns wrapper-managed state Owning lexical scope
ContentView AsyncStream (continuation) owns wrapper-managed state Owning lexical scope
AssetView CinematicAsset (asset) borrows mutable state The upstream binding owner is authoritative

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.

Class and protocol design

CinematicVideoPlaybackAndEditing/ViewRepresentable.swift:21 — representative type boundary

public protocol ViewRepresentable: PlatformViewRepresentable {
    // ...
}
Type Responsibility Depends on or conforms to
CinematicVideoPlaybackAndEditingApp Application entry and top-level composition App
ContentView User-interface presentation and input forwarding View
AssetView User-interface presentation and input forwarding View
CinematicPlayer Owns media or timeline playback View
PlayerLayerView User-interface presentation and input forwarding PlatformView
ViewRepresentable Defines a capability or collaboration contract PlatformViewRepresentable
SampleCompositionInstruction Owns feature behavior and collaborator lifecycle NSObject
SampleCustomCompositor Owns feature behavior and collaborator lifecycle NSObject, AVVideoCompositing
SourceFrame Represents a feature value or composable behavior Concrete collaborators/imported frameworks
CinematicAssetSampleBuffer Represents a feature value or composable behavior Concrete collaborators/imported frameworks

The source explicitly defines local protocol relationships: PlayerLayerContainerViewRepresentable.

Access control

Symbol Access Verified effect Likely rationale
texture (CinematicVideoPlaybackAndEditing/CinematicEditHelper.swift:54) private Use is restricted to the lexical declaration and same-file extensions allowed by Swift. Inference: hide an implementation step that is not part of the collaboration surface.
imageFetch (CinematicVideoPlaybackAndEditing/CinematicEditor.swift:17) 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.
focusChangeInProgress (CinematicVideoPlaybackAndEditing/CinematicEditor.swift:19) 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.
objectTrackingInProgress (CinematicVideoPlaybackAndEditing/CinematicEditor.swift:21) 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

CinematicVideoPlaybackAndEditing/CinematicEditHelper.swift:54 — representative boundary

    private func texture(from outputBuffer: CVPixelBuffer) -> MTLTexture? {
        // ...
    }

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
Application entry and top-level composition CinematicVideoPlaybackAndEditingApp The source’s App suffix makes this role explicit.
Owns media or timeline playback CinematicPlayer The source’s Player suffix makes this role explicit.
User-interface presentation and input forwarding AssetView, ContentView, PlayerLayerView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Protocol-oriented abstraction CinematicVideoPlaybackAndEditing/PlayerLayerContainer.swift:11 A local protocol and concrete conformance create an explicit capability boundary.
Binding-based state propagation CinematicVideoPlaybackAndEditing/AssetView.swift:14 A binding exposes controlled read/write access while the upstream owner remains authoritative.
Actor-isolated state CinematicVideoPlaybackAndEditing/CinematicEditor.swift:271 Actor annotations make the concurrency ownership boundary explicit.

Naming conventions

  • Types: App: CinematicVideoPlaybackAndEditingApp; Player: CinematicPlayer; View: AssetView, ContentView, PlayerLayerView.
  • Protocols: ViewRepresentable.
  • Methods: refreshPlayer, setVideoComposition, refreshFrame, renderContextChanged, startRequest, drawFocusDetections, setupForReading, cancelReading.
  • Files: CinematicVideoPlaybackAndEditing/CinematicVideoPlaybackAndEditingApp.swift, CinematicVideoPlaybackAndEditing/ContentView.swift, CinematicVideoPlaybackAndEditing/AssetView.swift, CinematicVideoPlaybackAndEditing/CinematicPlayer.swift, CinematicVideoPlaybackAndEditing/PlayerLayerView.swift, CinematicVideoPlaybackAndEditing/SampleCustomCompositor.swift.

Architecture takeaways

  • CinematicVideoPlaybackAndEditingApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches AVFoundation, SwiftUI, Cinematic, CoreMedia 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.
  • Local protocol relationships provide an explicit substitution boundary.

Source map

Source file Relevant symbols
CinematicVideoPlaybackAndEditing/CinematicVideoPlaybackAndEditingApp.swift CinematicVideoPlaybackAndEditingApp
CinematicVideoPlaybackAndEditing/ContentView.swift ContentView, ContentView_Previews
CinematicVideoPlaybackAndEditing/AssetView.swift AssetView
CinematicVideoPlaybackAndEditing/CinematicPlayer.swift CinematicPlayer
CinematicVideoPlaybackAndEditing/PlayerLayerView.swift PlayerLayerView
CinematicVideoPlaybackAndEditing/SampleCustomCompositor.swift SampleCompositionInstruction, SampleCustomCompositor, SourceFrame
CinematicVideoPlaybackAndEditing/CinematicAssetReader.swift CinematicAssetSampleBuffer, CinematicAssetReader
CinematicVideoPlaybackAndEditing/CinematicAsset.swift CinematicAsset
CinematicVideoPlaybackAndEditing/CinematicAssetData.swift CinematicAssetData
CinematicVideoPlaybackAndEditing/CinematicEditHelper.swift CinematicEditHelper