SPB Git

Repository Public License

overview.md 5.3 KB

# Architecture Overview

ORIX Camera is one app target and one local Swift package.

  • Packages/ORIXCameraKit holds everything that does not need a capture session: the design system (ORIXDesign) and the imaging engines (ORIXImaging). It builds for iOS 18 and macOS 15, so every engine is tested on the Mac with swift test.
  • App/ holds what needs iOS: the AVFoundation session, the frame pipeline, the observable model and the SwiftUI screens.

Status reminder: the app-side AVFoundation code (DeviceCameraBackend) compiles for iOS and has never executed on a device. See the README's Release Status.

# Layers

flowchart TD
    UI[SwiftUI screens<br/>CameraScreen · Library · Editor · Settings] --> MODEL[CameraModel · LibraryModel · EditorSession<br/>@Observable, main actor]
    MODEL --> BACKEND{{CameraBackend protocol}}
    BACKEND --> DEVICE[DeviceCameraBackend<br/>AVFoundation, device builds]
    BACKEND --> VIRTUAL[VirtualCameraBackend<br/>synthetic scene, Simulator builds]
    DEVICE --> PIPE[FramePipeline]
    VIRTUAL --> PIPE
    PIPE --> KIT[ORIXImaging engines]
    MODEL --> KIT
    KIT --> DISK[(CaptureStorage files<br/>+ SwiftData index)]
Layer Isolation Responsibility
Views main actor layout and gestures only; no AVFoundation import in any view
CameraModel main actor, @Observable lifecycle, modes, clamping requests to capabilities, capture flows, saving
CameraBackend nonisolated, Sendable the only door to hardware
FramePipeline capture queue + its own analysis queue, lock-protected routing frames, analysis, audio levels
ORIXImaging plain value types and lock-protected classes algorithms, files, index

The app target sets SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor; types that work off the main thread are marked nonisolated explicitly. Strict concurrency checking is complete.

# The frame format

One format flows through the whole pipeline: 32BGRA, 8-bit, in the sensor's native orientation. The monitor, the histogram, the focus analysis, the accumulators and the movie writer all consume the same buffers. This is the decision with the widest consequences; see video-engine.md for what it buys and what it costs.

# Where things are decided

Question Decided in
Can this camera do X? DeviceCameraBackend.resolveCapabilities → CameraCapabilities; explanations in CameraCapabilities.explanation(for:)
What value did the camera really take? LiveCameraState, published by the backend ten times per second
How is the frame rotated for display? AVCaptureDevice.RotationCoordinator → CameraEvent.rotation → MonitorSettings.rotationDegrees
What does the shutter do? CameraModel.shutter() in CameraModel+Capture.swift
Where does a capture go? CaptureStorage.write / adopt, then MediaLibrary.add via finishIndexing
What is an edit? EditRecipe, rendered by EditPipeline

# Documents

# Decision records

# Decision Alternative rejected Why Cost accepted
1 Protocol between UI and hardware views calling AVFoundation capability checks cannot be bypassed; the app runs in the Simulator; the device layer can be replaced an indirection
2 Engines in a package that also builds for macOS everything in the app target fast tests on the host, including Metal and AVAssetWriter capture-session code cannot live there
3 Sensor-orientation frames, rotation in shader / track / EXIF rotating on the data-output connection the SDK notes that this physically rotates buffers and reconfigures the pipeline geometry helpers and tests
4 Physical cameras driven individually virtual multi-camera devices predictable per-lens capabilities; Bayer RAW stays available no automatic lens switching while zooming
5 AVAssetWriter for movies AVCaptureMovieFileOutput one stream for monitor, analysis and recording; retiming; testable; fragments 8-bit SDR only in 1.0
6 Aids drawn in the monitor's Metal pass SwiftUI or Core Animation overlays pixel-exact alignment, one pass shader compiled at run time from source
7 Files are truth, SwiftData is an index database as truth a damaged index cannot lose captures reconcile at launch
8 Capture look / aspect / mirror stored as recipe baking them into the file the original is always complete other apps see the unedited file until export
9 Simulator backend is a clearly marked test double no Simulator support the pipeline and interface can be tested end to end without hardware it must never be mistaken for device validation; it is compiled out of device builds
Files main
Menu

Theme