Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Fix AVAssetReader unwraps and add session notes
Richie McIlroya451f83a5b30
diff --git a/crates/editor/PLAYBACK-FINDINGS.md b/crates/editor/PLAYBACK-FINDINGS.mdindex d30b940f2..32d23fca0 100644--- a/crates/editor/PLAYBACK-FINDINGS.md+++ b/crates/editor/PLAYBACK-FINDINGS.md@@ -324,6 +324,37 @@ The CPU RGBA→NV12 conversion was taking 15-25ms per frame for 3024x1964 resolu---+### Session 2026-02-15 (Performance Check + AVAssetReader Fix)++**Goal**: Run playback benchmarks, fix panics in decoder fallback path++**What was done**:+1. Ran full playback validation on MP4 and fragmented recordings+2. Identified AVAssetReader panicking with `unwrap()` on directory paths (fragmented recordings)+3. Fixed by replacing `unwrap()` with proper error propagation++**Changes Made**:+- `crates/video-decode/src/avassetreader.rs`: Replaced `ffmpeg::format::input(&path).unwrap()` and `.ok_or(...).unwrap()` with `map_err()?` and `ok_or_else()?` for clean error propagation instead of panics++**Results** (MP4 Mode):+- ✅ Decoder: AVAssetReader (hardware), display init=114-123ms, camera init=25-33ms+- ✅ Playback: 637-640 fps effective, avg=1.6ms, p95=5.0ms, p99=6.3ms+- ✅ Camera sync: 0ms drift (perfect)+- ✅ Mic sync: 88-100ms (borderline on this run, normally 77-88ms)+- 🟡 System audio: 193-205ms (known issue, inherited from recording)++**Results** (Fragmented Mode):+- ✅ Decoder: FFmpeg (hardware) with VideoToolbox, display init=100-110ms, camera init=7ms+- ✅ Playback: 153-173 fps effective, avg=5.8-6.5ms, p95=9.0-12.4ms+- ✅ Camera sync: 0ms drift (perfect)+- ✅ Mic sync: 10-23ms (excellent)+- ✅ AVAssetReader now cleanly falls back to FFmpeg without panicking+- 🟡 System audio: 85-116ms (borderline, known issue)++**Stopping point**: All playback metrics healthy. AVAssetReader panic fixed. No further action needed.++---+## References- `PLAYBACK-BENCHMARKS.md` - Raw performance test data (auto-updated by test runner)diff --git a/crates/recording/FINDINGS.md b/crates/recording/FINDINGS.mdindex bcfd5586a..0b3d99f86 100644--- a/crates/recording/FINDINGS.md+++ b/crates/recording/FINDINGS.md@@ -415,6 +415,32 @@ System Audio ────┘ ├─► MP4 (macos.rs) ─---+### Session 2026-02-15 (Performance Check + AVAssetReader Fix)++**Goal**: Run recording and playback benchmarks, fix any issues++**What was done**:+1. Ran MP4 baseline benchmarks (cold + warm runs)+2. Ran fragmented baseline benchmark+3. Ran playback benchmark on resulting recordings+4. Fixed AVAssetReader panic on directory paths (fragmented recordings)++**Changes Made**:+- `crates/video-decode/src/avassetreader.rs`: Replaced two `unwrap()` calls with proper error propagation via `?` and `map_err`. Previously panicked when given a directory path (fragmented recordings); now returns clean error that triggers graceful FFmpeg fallback.++**Results**:+- ✅ MP4: 29.2fps, 10.4-10.7ms jitter, 2.7% dropped, 0ms A/V sync, 81-94ms mic timing+- ✅ Fragmented: 29.5-29.6fps, 4.6-5.9ms jitter, 1.3% dropped, 0ms A/V sync, 1-4ms mic timing+- ✅ Playback MP4: 637fps effective, 1.6ms avg, 5.0ms p95, 0ms camera drift+- ✅ Playback Fragmented: 153fps effective, 6.5ms avg, 12.4ms p95, 0ms camera drift+- ✅ AVAssetReader no longer panics on directory paths+- 🟡 System audio: 120-246ms (known lower-priority issue)+- 🟡 MP4 dropped frames at 2.7% (single 160ms spike from encoder warmup, not actionable)++**Stopping point**: All major metrics pass. AVAssetReader panic fixed. System audio timing remains as documented known issue.++---+## References- `BENCHMARKS.md` - Raw performance test data (auto-updated by test runner)diff --git a/crates/video-decode/src/avassetreader.rs b/crates/video-decode/src/avassetreader.rsindex 1a021151e..a8db3b606 100644--- a/crates/video-decode/src/avassetreader.rs+++ b/crates/video-decode/src/avassetreader.rs@@ -237,13 +237,13 @@ impl AVAssetReaderDecoder {keyframe_index: Option<Arc<KeyframeIndex>>,) -> Result<Self, String> {let (pixel_format, width, height) = {- let input = ffmpeg::format::input(&path).unwrap();+ let input = ffmpeg::format::input(&path)+ .map_err(|e| format!("Failed to open video input '{}': {e}", path.display()))?;let input_stream = input.streams().best(ffmpeg::media::Type::Video)- .ok_or("Could not find a video stream")- .unwrap();+ .ok_or_else(|| format!("No video stream in '{}'", path.display()))?;let decoder = avcodec::Context::from_parameters(input_stream.parameters()).map_err(|e| format!("decoder context / {e}"))?@@ -338,7 +338,11 @@ impl AVAssetReaderDecoder {height: u32,) -> Result<(R<av::AssetReaderTrackOutput>, R<av::AssetReader>), String> {let asset = av::UrlAsset::with_url(- &ns::Url::with_fs_path_str(path.to_str().unwrap(), false),+ &ns::Url::with_fs_path_str(+ path.to_str()+ .ok_or_else(|| format!("Invalid UTF-8 in path: {path:?}"))?,+ false,+ ),None,).ok_or_else(|| format!("UrlAsset::with_url{{{path:?}}}"))?;