Sample CodevisionOSReviewed 2026-07-21View on Apple Developer

Displaying low-latency connected video

At a glance

Item Summary
Purpose Render connected camera feeds in visionOS with minimal latency.
App architecture A Swift sample with the source-visible chain LowLatencyCameraStreamingAppCameraViewCameraCoordinatorLowLatencyRendererRealityKit APIs.
Main patterns Delegate or data-source callbacks, Coordinator, Actor isolation
Project style 12 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries.
Execution model Source-visible boundaries: Sendable or @Sendable, actor, DispatchQueue(label:), async declaration or closure, Task; none alone proves a background thread.
State/event model Source-visible mechanisms: @Observable, NotificationCenter, SwiftUI state property wrapper.
Key frameworks/packages os, SwiftUI, AVFoundation, RealityKit, Observation; these are source dependencies, not architecture labels.

Project structure

Source bundle/
└── RealityKit-LowLatencyCameraStreaming/
    ├── LowLatencyCameraStreamingApp.swift
    ├── CameraCapture/
    │   ├── CameraCaptureSession.swift
    │   ├── CameraCoordinator.swift
    │   └── VideoDeviceList.swift
    ├── Model/
    │   └── AppModel.swift
    ├── Rendering/
    │   ├── LowLatencyRenderer.swift
    │   └── CameraFeedSharedTexture.swift
    ├── Views/
    │   ├── CameraControlsView.swift
    │   ├── CameraResolutionView.swift
    │   ├── CameraTextureRealityView.swift
    │   └── CameraView.swift
    └── Extensions/
        └── Entity+CameraFeed.swift

Structure observations

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

Overall architecture

Reference code

RealityKit-LowLatencyCameraStreaming/LowLatencyCameraStreamingApp.swift:10 — architecture anchor

@main
struct LowLatencyCameraStreamingApp: App {

    @State private var appModel = AppModel()

    var body: some Scene {
        WindowGroup {
            CameraView()
                .environment(appModel)
        }
        .windowResizability(.contentSize)
     }
}

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 RealityKit.

Ownership and state

Ownership evidence

RealityKit-LowLatencyCameraStreaming/LowLatencyCameraStreamingApp.swift:13 — stored dependency or nearest verified ownership anchor

@main
struct LowLatencyCameraStreamingApp: App {
    // ...
    @State private var appModel = AppModel()
    // ...
}
Owner Object or state Relationship Mutation authority
LowLatencyCameraStreamingApp AppModel (appModel) owns wrapper-managed state Owning lexical scope
CameraConfiguration String (cameraID) owns value state Initialized by the owner; the binding is immutable
CameraConfiguration Double (targetFPS) owns value state Initialized by the owner; the binding is immutable
CameraCaptureSession Logger (logger) creates and retains Initialized by the owner; the binding is immutable

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.

Concern Source mechanism Verified placement or handoff Evidence
Transfer contract Sendable or @Sendable The source declares a sendability boundary; this alone does not synchronize mutable state. RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift:14
Actor isolation actor The cited type is actor-isolated; this does not select a background thread. RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift:40
Queue scheduling DispatchQueue(label:) The source constructs a dispatch queue; its label alone does not prove a thread. RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift:49
Suspension boundary async declaration or closure The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift:107
Task creation Task The source creates an unstructured task; surrounding context determines inherited actor isolation. RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift:120

@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.

Reference code

RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift:14 — representative execution boundary

enum CameraCaptureEvent: Sendable {
    case didOutputFrame(CMSampleBuffer)
    // ...
}

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 @Observable Observation macro publishes source-visible changes. RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCoordinator.swift:12
State propagation NotificationCenter NotificationCenter distributes named process-local events. RealityKit-LowLatencyCameraStreaming/CameraCapture/VideoDeviceList.swift:90
State propagation SwiftUI state property wrapper A SwiftUI property wrapper supplies or observes UI state. RealityKit-LowLatencyCameraStreaming/LowLatencyCameraStreamingApp.swift:13
Source import os The cited file imports this module; runtime use and architectural role are not inferred. RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift:9
Source import SwiftUI The cited file imports this module; runtime use and architectural role are not inferred. RealityKit-LowLatencyCameraStreaming/LowLatencyCameraStreamingApp.swift:8
Source import AVFoundation The cited file imports this module; runtime use and architectural role are not inferred. RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift:8
Source import RealityKit The cited file imports this module; runtime use and architectural role are not inferred. RealityKit-LowLatencyCameraStreaming/Extensions/Entity+CameraFeed.swift:8
Source import Observation The cited file imports this module; runtime use and architectural role are not inferred. RealityKit-LowLatencyCameraStreaming/CameraCapture/VideoDeviceList.swift:9

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

RealityKit-LowLatencyCameraStreaming/LowLatencyCameraStreamingApp.swift:11 — representative type boundary

@main
struct LowLatencyCameraStreamingApp: App {
    // ...
    @State private var appModel = AppModel()
    // ...
}
Type Responsibility Depends on or conforms to
LowLatencyCameraStreamingApp Application entry and top-level composition App
CameraCaptureSession Owns a session-scoped interaction NSObject
AppModel Feature data or observable state Concrete collaborators/imported frameworks
LowLatencyRenderer Owns drawing, GPU, or presentation processing Concrete collaborators/imported frameworks
CameraCoordinator Cross-object flow or session coordination Concrete collaborators/imported frameworks
CameraControlsView User-interface presentation and input forwarding View
CameraResolutionView User-interface presentation and input forwarding View
CameraTextureRealityView User-interface presentation and input forwarding View
CameraView User-interface presentation and input forwarding View
CameraCaptureEvent Defines a closed set of feature states or choices Sendable

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
logger (RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift:42) 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.
sessionQueue (RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift:49) 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.
eventContinuation (RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift:52) 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.
isRunning (RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift:55) 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

RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift:42 — representative boundary

actor CameraCaptureSession: NSObject {
    // ...
    private let logger = Logger(subsystem: "com.example.low-latency-streaming", category: "CameraCaptureSession")
    // ...
}

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 LowLatencyCameraStreamingApp The source’s App suffix makes this role explicit.
Cross-object flow or session coordination CameraCoordinator The source’s Coordinator suffix makes this role explicit.
Feature data or observable state AppModel The source’s Model suffix makes this role explicit.
Owns drawing, GPU, or presentation processing LowLatencyRenderer The source’s Renderer suffix makes this role explicit.
Owns a session-scoped interaction CameraCaptureSession The source’s Session suffix makes this role explicit.
User-interface presentation and input forwarding CameraControlsView, CameraResolutionView, CameraTextureRealityView, CameraView The source’s View suffix makes this role explicit.

Design patterns

Pattern Source evidence Purpose or tradeoff
Delegate or data-source callbacks RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift:239 Callback protocols invert event delivery back into the sample’s owner.
Coordinator RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCoordinator.swift:13 A role-named coordinator centralizes cross-object flow.
Actor isolation RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift:40 A declared actor creates an explicit isolation boundary; its executor is not described as a background thread.

Naming conventions

  • Types: App: LowLatencyCameraStreamingApp; Coordinator: CameraCoordinator; Model: AppModel; Renderer: LowLatencyRenderer; Session: CameraCaptureSession; View: CameraControlsView, CameraResolutionView, CameraTextureRealityView, CameraView.
  • Protocols: no local protocol declaration in the scanned source.
  • Methods: setupSession, configureOutput, start, stop, setRunning, configureCamera, configureExternalCamera, removeAllInputs.
  • Files: RealityKit-LowLatencyCameraStreaming/LowLatencyCameraStreamingApp.swift, RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift, RealityKit-LowLatencyCameraStreaming/Model/AppModel.swift, RealityKit-LowLatencyCameraStreaming/Rendering/LowLatencyRenderer.swift, RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCoordinator.swift, RealityKit-LowLatencyCameraStreaming/Rendering/CameraFeedSharedTexture.swift.

Architecture takeaways

  • LowLatencyCameraStreamingApp is the main source-visible entry or composition anchor for this sample.
  • Framework work reaches SwiftUI, AVFoundation, RealityKit, CoreImage 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
RealityKit-LowLatencyCameraStreaming/LowLatencyCameraStreamingApp.swift Cited implementation, LowLatencyCameraStreamingApp, SwiftUI state property wrapper, SwiftUI
RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCaptureSession.swift Cited implementation, CameraCaptureSession, Sendable or @Sendable, actor, DispatchQueue(label:), async declaration or closure, Task, os, AVFoundation, CameraCaptureEvent, CameraError, CameraConfiguration
RealityKit-LowLatencyCameraStreaming/CameraCapture/CameraCoordinator.swift CameraCoordinator, @Observable
RealityKit-LowLatencyCameraStreaming/CameraCapture/VideoDeviceList.swift NotificationCenter, Observation, VideoDeviceList, VideoDevice
RealityKit-LowLatencyCameraStreaming/Extensions/Entity+CameraFeed.swift RealityKit, Feature implementation
RealityKit-LowLatencyCameraStreaming/Model/AppModel.swift ResolutionPreset, AppModel
RealityKit-LowLatencyCameraStreaming/Rendering/LowLatencyRenderer.swift LowLatencyRenderer, RendererError
RealityKit-LowLatencyCameraStreaming/Rendering/CameraFeedSharedTexture.swift TextureConfiguration, TextureSet, SharedTextureError, CameraFeedSharedTexture
RealityKit-LowLatencyCameraStreaming/Views/CameraControlsView.swift CameraControlsView
RealityKit-LowLatencyCameraStreaming/Views/CameraResolutionView.swift CameraResolutionView
RealityKit-LowLatencyCameraStreaming/Views/CameraTextureRealityView.swift CameraTextureRealityView
RealityKit-LowLatencyCameraStreaming/Views/CameraView.swift CameraView