Repository navigation
fix(downloads): give offline playback a working loopback route and Do… - #129
Conversation
…lby Vision A downloaded MKV could only ever play through playerCoreDirect. When VideoToolbox rejected the stream, the recovery planner routed to siloPlayerLoopback, whose proxy guard rejected the file:// source and failed the load with "loopback source URL is not HTTP(S)" — so a decode failure surfaced as an unrelated proxy error with no working fallback. Fixing the routing then exposed two more offline-only gaps behind it. Let file:// sources skip the source proxy rather than fail the load. The proxy exists to give the segment writer a cached, resumable HTTP origin; a local file needs neither, and LoopbackSegmentWriter already opens the path directly. A nil loopback session is still caught downstream by PlaybackEngine, so no coverage is lost with the throw removed. Resolve the selected audio stream through a single helper in LoopbackSegmentWriter. The demuxer discard pass trusted an explicit ffIndex without checking it named an audio stream, while the mux setup validated it and fell back to an ordinal scan. When they disagreed the discard pass dropped the audio the muxer then waited forever to receive, which surfaced as vodMoovBlocked naming nothing about audio. Carry the manifest's audio track detail — title, layout, bitrate, sample rate — into the synthesized FileVersion, and derive the overall bitrate from the delivered file so the loopback stops advertising a placeholder BANDWIDTH and logging source_bitrate_unknown. The manifest's per-track index is an ordinal within its own list, not an ffmpeg stream index, so it is deliberately not forwarded: doing so named the video stream. Probe the downloaded file for its video parameters. The manifest describes no video stream at all, so Dolby Vision, colour transfer, colour range and frame rate had nowhere to come from and DV downloads planned as plain HEVC. Reading the delivered file rather than catalog metadata also keeps transcoded downloads honest, since a stripped RPU reports no DV instead of inheriting the source's claim. Verified on iOS; tvOS and macOS were not built (no tvOS simulator runtime installed, and the macOS scheme fails at HEAD on unrelated FFmpeg framework errors).
📝 WalkthroughWalkthroughOffline playback now extracts local video metadata, maps manifest audio metadata, preserves selected audio tracks, derives bitrate, and routes local loopback sources without proxy errors. Loopback muxing centralizes audio-stream selection. ChangesOffline playback metadata
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant OfflinePlayback
participant LocalMediaProbe
participant FFmpeg
participant FileVersion
participant PlayerViewModel
OfflinePlayback->>LocalMediaProbe: Probe downloaded media
LocalMediaProbe->>FFmpeg: Scan local streams
FFmpeg-->>LocalMediaProbe: Return video metadata
LocalMediaProbe-->>OfflinePlayback: Return video tracks
OfflinePlayback->>FileVersion: Store mapped tracks and bitrate
OfflinePlayback->>PlayerViewModel: Provide local playback plan
PlayerViewModel-->>OfflinePlayback: Return original unproxied plan
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
iosApp/iosApp/Screens/Player/AVPlayerRoute/LoopbackSegmentWriter.swift (1)
2436-2440: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winRestore the selected audio stream discard state.
A recycled demuxer can retain
AVDISCARD_ALLon an audio stream selected by the new session. This branch keeps that stream disabled, soav_read_framedoes not deliver its packets. The muxer can then produce video-only output or fail while waiting for audio.Set
stream.pointee.discard = AVDISCARD_DEFAULTwheni == keepAudioIndex.Proposed fix
if mediaType == AVMEDIA_TYPE_AUDIO { if i == keepAudioIndex { + stream.pointee.discard = AVDISCARD_DEFAULT keptAudio += 1 } else { stream.pointee.discard = AVDISCARD_ALL🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@iosApp/iosApp/Screens/Player/AVPlayerRoute/LoopbackSegmentWriter.swift` around lines 2436 - 2440, In the audio-stream selection branch around the keepAudioIndex check, explicitly restore the selected stream’s discard state to AVDISCARD_DEFAULT before incrementing keptAudio; retain AVDISCARD_ALL for non-selected streams.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@iosApp/iosApp/Downloads/OfflinePlayback.swift`:
- Around line 203-213: Update averageBitrateKbps(from:) in
iosApp/iosApp/Downloads/OfflinePlayback.swift#L203-L213 to read the downloaded
byte count from mediaURL rather than manifest.fileSize, using targetBitrateKbps
only when the local file or duration is unavailable or invalid. Update
iosApp/Tests/OfflinePlaybackMappingTests.swift#L174-L179 to provide an actual
local file size or inject the bitrate input, and stop asserting behavior based
on manifest file_size.
---
Outside diff comments:
In `@iosApp/iosApp/Screens/Player/AVPlayerRoute/LoopbackSegmentWriter.swift`:
- Around line 2436-2440: In the audio-stream selection branch around the
keepAudioIndex check, explicitly restore the selected stream’s discard state to
AVDISCARD_DEFAULT before incrementing keptAudio; retain AVDISCARD_ALL for
non-selected streams.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 007f6c53-ba56-48c5-9689-21799826cf2f
📒 Files selected for processing (6)
iosApp/Tests/OfflinePlaybackMappingTests.swiftiosApp/iosApp/Downloads/DownloadModels.swiftiosApp/iosApp/Downloads/LocalMediaProbe.swiftiosApp/iosApp/Downloads/OfflinePlayback.swiftiosApp/iosApp/Screens/Player/AVPlayerRoute/LoopbackSegmentWriter.swiftiosApp/iosApp/Screens/Player/PlayerViewModel.swift
…lby Vision
A downloaded MKV could only ever play through playerCoreDirect. When VideoToolbox rejected the stream, the recovery planner routed to siloPlayerLoopback, whose proxy guard rejected the file:// source and failed the load with "loopback source URL is not HTTP(S)" — so a decode failure surfaced as an unrelated proxy error with no working fallback. Fixing the routing then exposed two more offline-only gaps behind it.
Let file:// sources skip the source proxy rather than fail the load. The proxy exists to give the segment writer a cached, resumable HTTP origin; a local file needs neither, and LoopbackSegmentWriter already opens the path directly. A nil loopback session is still caught downstream by PlaybackEngine, so no coverage is lost with the throw removed.
Resolve the selected audio stream through a single helper in LoopbackSegmentWriter. The demuxer discard pass trusted an explicit ffIndex without checking it named an audio stream, while the mux setup validated it and fell back to an ordinal scan. When they disagreed the discard pass dropped the audio the muxer then waited forever to receive, which surfaced as vodMoovBlocked naming nothing about audio.
Carry the manifest's audio track detail — title, layout, bitrate, sample rate — into the synthesized FileVersion, and derive the overall bitrate from the delivered file so the loopback stops advertising a placeholder BANDWIDTH and logging source_bitrate_unknown. The manifest's per-track index is an ordinal within its own list, not an ffmpeg stream index, so it is deliberately not forwarded: doing so named the video stream.
Probe the downloaded file for its video parameters. The manifest describes no video stream at all, so Dolby Vision, colour transfer, colour range and frame rate had nowhere to come from and DV downloads planned as plain HEVC. Reading the delivered file rather than catalog metadata also keeps transcoded downloads honest, since a stripped RPU reports no DV instead of inheriting the source's claim.
Verified on iOS; tvOS and macOS were not built (no tvOS simulator runtime installed, and the macOS scheme fails at HEAD on unrelated FFmpeg framework errors).
Summary by CodeRabbit
New Features
Bug Fixes