SPB Git

Repository Public License

overview.md 5.3 KB 78 lines markdown

1<!--2ORIX Camera3File: docs/architecture/overview.md4Author: Simon-Pierre Boucher5Contact: contact@spboucher.ai6-->78# Architecture Overview910ORIX Camera is one app target and one local Swift package.1112- **`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`.13- **`App/`** holds what needs iOS: the AVFoundation session, the frame pipeline, the observable model and the SwiftUI screens.1415Status reminder: the app-side AVFoundation code (`DeviceCameraBackend`) compiles for iOS and has never executed on a device. See the README's Release Status.1617## Layers1819```mermaid20flowchart TD21    UI[SwiftUI screens<br/>CameraScreen · Library · Editor · Settings] --> MODEL[CameraModel · LibraryModel · EditorSession<br/>@Observable, main actor]22    MODEL --> BACKEND{{CameraBackend protocol}}23    BACKEND --> DEVICE[DeviceCameraBackend<br/>AVFoundation, device builds]24    BACKEND --> VIRTUAL[VirtualCameraBackend<br/>synthetic scene, Simulator builds]25    DEVICE --> PIPE[FramePipeline]26    VIRTUAL --> PIPE27    PIPE --> KIT[ORIXImaging engines]28    MODEL --> KIT29    KIT --> DISK[(CaptureStorage files<br/>+ SwiftData index)]30```3132| Layer | Isolation | Responsibility |33|---|---|---|34| Views | main actor | layout and gestures only; no AVFoundation import in any view |35| `CameraModel` | main actor, `@Observable` | lifecycle, modes, clamping requests to capabilities, capture flows, saving |36| `CameraBackend` | `nonisolated`, `Sendable` | the only door to hardware |37| `FramePipeline` | capture queue + its own analysis queue, lock-protected | routing frames, analysis, audio levels |38| `ORIXImaging` | plain value types and lock-protected classes | algorithms, files, index |3940The app target sets `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor`; types that work off the main thread are marked `nonisolated` explicitly. Strict concurrency checking is `complete`.4142## The frame format4344One 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](video-engine.md) for what it buys and what it costs.4546## Where things are decided4748| Question | Decided in |49|---|---|50| Can this camera do X? | `DeviceCameraBackend.resolveCapabilities` → `CameraCapabilities`; explanations in `CameraCapabilities.explanation(for:)` |51| What value did the camera really take? | `LiveCameraState`, published by the backend ten times per second |52| How is the frame rotated for display? | `AVCaptureDevice.RotationCoordinator` → `CameraEvent.rotation` → `MonitorSettings.rotationDegrees` |53| What does the shutter do? | `CameraModel.shutter()` in `CameraModel+Capture.swift` |54| Where does a capture go? | `CaptureStorage.write` / `adopt`, then `MediaLibrary.add` via `finishIndexing` |55| What is an edit? | `EditRecipe`, rendered by `EditPipeline` |5657## Documents5859- [camera-engine.md](camera-engine.md): backend protocol, session queue, rotation and display geometry, monitor, analysis.60- [raw-processing.md](raw-processing.md): RAW and ProRAW capture and development.61- [computational-photography.md](computational-photography.md): accumulation, night stack, registration, fusion.62- [video-engine.md](video-engine.md): the movie writer and why it is not `AVCaptureMovieFileOutput`.63- [storage.md](storage.md): files, index, recovery, recipes, export.6465## Decision records6667| # | Decision | Alternative rejected | Why | Cost accepted |68|---|---|---|---|---|69| 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 |70| 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 |71| 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 |72| 4 | Physical cameras driven individually | virtual multi-camera devices | predictable per-lens capabilities; Bayer RAW stays available | no automatic lens switching while zooming |73| 5 | `AVAssetWriter` for movies | `AVCaptureMovieFileOutput` | one stream for monitor, analysis and recording; retiming; testable; fragments | 8-bit SDR only in 1.0 |74| 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 |75| 7 | Files are truth, SwiftData is an index | database as truth | a damaged index cannot lose captures | reconcile at launch |76| 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 |77| 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 |78
Files main
Menu

Theme