Reading multiview 3D video files
At a glance
| Item | Summary |
|---|---|
| Purpose | Render single images for the left eye and right eye from a multiview High Efficiency Video Coding format file by reading individual video frames. |
| App architecture | A Swift sample with the source-visible chain StereoViewerApp → LaunchView → MediaDetailViewModel → AVFoundation APIs. |
| Main patterns | Model-View-ViewModel |
| Project style | 6 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: @MainActor, Task closure isolated to MainActor, Task, await suspension point, Sendable or @Sendable; none alone proves a background thread. |
| State/event model | Source-visible mechanisms: SwiftUI state property wrapper, @Observable. |
| Key frameworks/packages | SwiftUI, AVFoundation, VideoToolbox; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── StereoViewer/
│ ├── StereoViewerApp.swift
│ ├── StereoViewModel.swift
│ ├── MediaDetailViewModel.swift
│ ├── LaunchView.swift
│ ├── MediaDetailView.swift
│ ├── StereoView.swift
│ └── StereoViewer.entitlements
├── Configuration/
│ └── SampleCode.xcconfig
└── StereoViewer.xcodeproj/
├── .xcodesamplecode.plist
└── project.pbxproj
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 7 source declaration(s).
Overall architecture
flowchart LR
N1["StereoViewerApp"]
N2["LaunchView"]
N3["MediaDetailViewModel"]
N4["AVFoundation APIs"]
N1 --> N2
N2 --> N3
N3 --> N4
Reference code
StereoViewer/StereoViewerApp.swift:10 — architecture anchor
@main
struct StereoViewerApp: App {
var body: some Scene {
WindowGroup {
LaunchView()
}
}
}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 AVFoundation.
Ownership and state
classDiagram
StereoViewModel o-- StereoViewModelState : state
StereoViewModel *-- NSImage : leftEye
StereoViewModel *-- NSImage : rightEye
StereoViewModel o-- AVURLAsset : asset
Ownership evidence
StereoViewer/StereoViewModel.swift:22 — stored dependency or nearest verified ownership anchor
@Observable
class StereoViewModel: @unchecked Sendable {
// ...
@MainActor var state: StereoViewModelState = .loading
// ...
}| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
StereoViewModel |
StereoViewModelState (state) |
stores or receives | App/module collaborators |
StereoViewModel |
NSImage (leftEye) |
creates and retains | App/module collaborators |
StereoViewModel |
NSImage (rightEye) |
creates and retains | App/module collaborators |
StereoViewModel |
AVURLAsset (asset) |
stores or receives | 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 |
|---|---|---|---|
| Main isolation | @MainActor |
The cited annotation marks its attached declaration or closure as main-actor isolated. | StereoViewer/MediaDetailView.swift:11 |
| Main isolation | Task closure isolated to MainActor |
The cited operation explicitly enters a main-actor-isolated region. | StereoViewer/MediaDetailViewModel.swift:22 |
| Task creation | Task |
The source creates an unstructured task; surrounding context determines inherited actor isolation. | StereoViewer/MediaDetailViewModel.swift:22 |
| Suspension boundary | await suspension point |
The source declares or crosses an asynchronous boundary; it does not by itself establish background execution. | StereoViewer/MediaDetailViewModel.swift:24 |
| Transfer contract | Sendable or @Sendable |
The source declares a sendability boundary; this alone does not synchronize mutable state. | StereoViewer/StereoViewModel.swift:20 |
@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
StereoViewer/MediaDetailView.swift:11 — representative execution boundary
@MainActor
struct MediaDetailView: View {
var mediaDetailViewModel: MediaDetailViewModel
// ...
}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. | StereoViewer/LaunchView.swift:11 |
| State propagation | @Observable |
Observation macro publishes source-visible changes. | StereoViewer/MediaDetailViewModel.swift:12 |
| Source import | SwiftUI |
The cited file imports this module; runtime use and architectural role are not inferred. | StereoViewer/LaunchView.swift:8 |
| Source import | AVFoundation |
The cited file imports this module; runtime use and architectural role are not inferred. | StereoViewer/MediaDetailView.swift:9 |
| Source import | VideoToolbox |
The cited file imports this module; runtime use and architectural role are not inferred. | StereoViewer/StereoViewModel.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
StereoViewer/StereoViewerApp.swift:11 — representative type boundary
@main
struct StereoViewerApp: App {
// ...
LaunchView()
// ...
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
StereoViewerApp |
Application entry and top-level composition | App |
StereoViewModel |
UI-facing state and feature coordination | @unchecked Sendable |
MediaDetailViewModel |
UI-facing state and feature coordination | Concrete collaborators/imported frameworks |
LaunchView |
User-interface presentation and input forwarding | View |
MediaDetailView |
User-interface presentation and input forwarding | View |
StereoView |
User-interface presentation and input forwarding | View |
StereoViewModelState |
Represents mutable feature state | Concrete collaborators/imported frameworks |
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 |
|---|---|---|---|
filename (StereoViewer/LaunchView.swift:11) |
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. |
stereoViewModel (StereoViewer/StereoView.swift:13) |
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. |
sampleNum (StereoViewer/StereoView.swift:14) |
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. |
isEditing (StereoViewer/StereoView.swift:15) |
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
StereoViewer/LaunchView.swift:11 — representative boundary
struct LaunchView: View {
@State private var filename: URL?
// ...
}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 | StereoViewerApp |
The source’s App suffix makes this role explicit. |
| User-interface presentation and input forwarding | LaunchView, MediaDetailView, StereoView |
The source’s View suffix makes this role explicit. |
| UI-facing state and feature coordination | MediaDetailViewModel, StereoViewModel |
The source’s ViewModel suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Model-View-ViewModel | StereoViewer/MediaDetailViewModel.swift:13 |
Role-named view models keep UI-facing state or coordination outside view declarations. |
Main application flow
sequenceDiagram
actor User
participant View as SwiftUI views
participant Metadata as MediaDetailViewModel
participant Decoder as StereoViewModel
participant AVF as AVFoundation
User->>View: Select MV-HEVC file
View->>Metadata: Create with URL
Metadata->>AVF: Load metadata
User->>View: Continue / choose frame
View->>Decoder: Create or readBuffer(at:)
Decoder->>AVF: Discover track and read tagged buffers
AVF-->>Decoder: Left/right pixel buffers
Decoder-->>View: Ready state and eye images
Reference code
StereoViewer/StereoViewModel.swift:35 — init
init(asset: AVURLAsset) {
self.asset = asset
Task.detached {
do {
if let track = try await asset.loadTracks(withMediaCharacteristic: .containsStereoMultiviewVideo).first {
self.track = track
self.framePresentationTimes = try presentationTimesFor(track: track, asset: asset)
self.duration = try await asset.load(.duration)
self.videoLayerIds = try await loadVideoLayerIdsForTrack(track)
if self.readBufferFromAsset(at: 0) {
self.publishState(.ready(times: self.framePresentationTimes))
}
} else {
self.publishState(.error(message: "NO STEREO MULTIVIEW VIDEO TRACK IN ASSET"))
}
} catch {
self.publishState(.error(message: error.localizedDescription))
}
}
}StereoViewer/StereoViewModel.swift:118 — readNextBufferFromAsset
func readNextBufferFromAsset() {
guard let assetReader, let trackOutput else {
return
}
// ...
}Naming conventions
- Types: App: StereoViewerApp; View: LaunchView, MediaDetailView, StereoView; ViewModel: MediaDetailViewModel, StereoViewModel.
- Protocols: no local protocol declaration in the scanned source.
- Methods:
publishState,readBufferFromAsset,readNextBufferFromAsset,presentationTimesFor,loadVideoLayerIdsForTrack,ready,error,loading. - Files:
StereoViewer/StereoViewerApp.swift,StereoViewer/StereoViewModel.swift,StereoViewer/MediaDetailViewModel.swift,StereoViewer/LaunchView.swift,StereoViewer/MediaDetailView.swift,StereoViewer/StereoView.swift.
Architecture takeaways
StereoViewerAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches SwiftUI, AVFoundation, VideoToolbox 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 |
|---|---|
StereoViewer/StereoViewerApp.swift |
Cited implementation, StereoViewerApp |
StereoViewer/StereoViewModel.swift |
Cited implementation, Sendable or @Sendable, VideoToolbox, StereoViewModelState, StereoViewModel |
StereoViewer/LaunchView.swift |
Cited implementation, SwiftUI state property wrapper, SwiftUI, LaunchView |
StereoViewer/StereoView.swift |
Cited implementation, StereoView |
StereoViewer/MediaDetailViewModel.swift |
MediaDetailViewModel, Task closure isolated to MainActor, Task, await suspension point, @Observable |
StereoViewer/MediaDetailView.swift |
@MainActor, AVFoundation, MediaDetailView |