This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
- Build for simulator:
xcodebuild -scheme NutshellPlayer -destination 'platform=com.apple.platform.visionOS-simulator' build - Build for device:
xcodebuild -scheme NutshellPlayer -destination 'platform=com.apple.platform.visionOS' build - Run tests:
xcodebuild test -scheme NutshellPlayer -destination 'platform=com.apple.platform.visionOS-simulator' - Open in Xcode: Open
NutshellPlayer.xcodeprojin Xcode 15+ with visionOS SDK
NutshellPlayer is a visionOS VR video player for Apple Vision Pro that specializes in 180° stereoscopic content (Side-By-Side format) with advanced color space support and Metal rendering pipeline.
The application follows MVVM with Protocol-Oriented Design:
AppModel: Central state management for window states and immersive space transitionsVideoModel: Core media playback logic implementingPlayableprotocol, handles AVFoundation integration, metadata parsing, color space detection (BT.601/BT.709/BT.2020/P3), 8/10-bit video support, and resource cleanupSettings: User preferences and spatial translations
NutshellPlayerApp: Multi-window architecture with main content, reality, and immersive space windowsImmersiveVRView: Primary VR interface using RealityKit with hemisphere mesh rendering, spatial gestures, and head trackingVRPlayerView: Alternative VR player interfaceContentView: File selection and basic UI
Renderer: Metal command buffer management, YUV/RGB texture processing, multi-pipeline states for different color spacesVRPlayerEntity: RealityKit entity implementingDrawableProvidingandTextureProvidingprotocols, integrates Metal rendering with spatial content- Custom shaders: Located in RealityKit-assets package for tone mapping and color conversion
Playable: Defines media playback interface (video properties, controls, texture access)TextureProviding: Metal texture access protocolDrawableProviding: Render target management protocol
- Main Window: File selection and playback controls
- Reality Window: Spatial interactions with RealityKit entities
- Immersive Space: Full VR playback environment with hemisphere mesh
- Asset Loading: AVURLAsset with security-scoped resource access
- Metadata Parsing: Color space (YCbCr matrix, color primaries), bit depth, HDR detection, transfer functions
- Player Setup: AVQueuePlayerWithOutput, AVPlayerItemVideoOutput configuration with proper color properties
- Texture Extraction: Real-time pixel buffer extraction via CADisplayLink
- Metal Rendering: Custom shaders for color space conversion and stereoscopic mapping
- BT.601: Legacy SD video color space (recently added to fix banding)
- BT.709: Standard HD video color space
- BT.2020: UHD/HDR color space
- P3: Display P3 wide color gamut
- Automatic detection from video metadata with fallback to BT.601 for legacy content
- Side-By-Side (SBS): Current implementation for 180° VR content
- Over-Under (OU): Planned support (enum defined but not implemented)
- Mono/Stereo toggle: User-selectable display modes in Settings
- visionOS SDK: Minimum v26, requires Xcode 15+
- RealityKit-assets: Custom package with Metal shaders and materials
- Frameworks: SwiftUI, RealityKit, AVFoundation, Metal, CoreVideo
- Target Platforms: visionOS (device and simulator)
- Protocol-first design: Use
Playable,TextureProviding,DrawableProvidingprotocols - Observable pattern: Use
@Observablefor state management classes - Metal integration: Keep Metal rendering code in dedicated Renderer classes
- Async/await: Use for media loading and metadata parsing
- Resource cleanup: Implement proper cleanup methods with security-scoped resource management
- Current: VR 180° SBS (Side-By-Side) video and images, AVFoundation-supported codecs
- Bit depths: 8-bit and 10-bit with full/limited range detection
- Pixel formats: YUV bi-planar formats for Metal compatibility
- Color spaces: Automatic detection and proper handling
- Use
weak varfor delegate patterns and display link targets - Implement
cleanup()methods for proper resource deallocation - Handle security-scoped resources with
start/stopAccessingSecurityScopedResource() - Proper observer invalidation on deinit
- Main app:
NutshellPlayerApp.swift - Models:
Models/AppModel.swift,Models/VideoModel.swift - Views:
Views/ImmersiveVRView.swift,Views/VRPlayerView.swift - Renderer:
Renderer/Renderer.swift - Protocols:
Protocols/Playable.swift - RealityKit integration:
Views/Entities/VRPlayerEntity+TextureProviding.swift
- ImmersiveSpace: Configured for mixed immersion style in Info.plist
- Spatial interactions: Hand tracking and gaze input via RealityKit
- Multi-window: Leverages visionOS multiple scene capabilities
- Metal compatibility: Optimized for visionOS GPU architecture
- Over-Under (OU) stereoscopic format support
- Full 360° video playback
- mpvkit integration for broader codec/container support
- Advanced Metal shaders for tone mapping
- Streaming and DRM support