Skip to content

fix(downloads): give offline playback a working loopback route and Do… - #129

Merged
Quick104 merged 1 commit into
Silo-Server:mainfrom
olivertgwalton:fix/offline-playback-parity
Aug 10, 2026
Merged

Quick104 merged 1 commit into
Silo-Server:mainfrom
olivertgwalton:fix/offline-playback-parity

Conversation

@olivertgwalton

@olivertgwalton olivertgwalton commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

…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

    • Offline playback now reads downloaded video metadata, including bitrate, frame rate, color settings, Dolby Vision details, and audio-track information.
    • Selected audio tracks and richer media metadata are preserved during offline playback.
    • Local offline media can play without being routed through the source proxy.
  • Bug Fixes

    • Improved audio stream selection when manifest indexes are stale or use ordinal values.
    • Added safer handling for missing or invalid media metadata.

…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).
@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Offline 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.

Changes

Offline playback metadata

Layer / File(s) Summary
Media metadata extraction
iosApp/iosApp/Downloads/DownloadModels.swift, iosApp/iosApp/Downloads/LocalMediaProbe.swift
OfflineAudioTrack decodes title, layout, bitrate, and sample rate. LocalMediaProbe extracts video metadata, including Dolby Vision, color, bit depth, bitrate, and frame rate, from local media with FFmpeg.
Offline playback mapping
iosApp/iosApp/Downloads/OfflinePlayback.swift, iosApp/Tests/OfflinePlaybackMappingTests.swift
Offline playback maps manifest tracks, probes video tracks, derives bitrate with fallback handling, preserves selected audio-track data, and populates FileVersion metadata. Tests cover these mappings and playback planning.
Loopback audio selection
iosApp/iosApp/Screens/Player/AVPlayerRoute/LoopbackSegmentWriter.swift
Loopback muxing uses one resolver for explicit audio stream indexes and selected audio ordinals.
Local source routing
iosApp/iosApp/Screens/Player/PlayerViewModel.swift
Non-HTTP(S) sources, including local files, bypass source-proxy preparation and use the original plan.

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
Loading

Possibly related PRs

Suggested reviewers: quick104

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main changes: fixing offline playback routing and adding Dolby Vision support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Restore the selected audio stream discard state.

A recycled demuxer can retain AVDISCARD_ALL on an audio stream selected by the new session. This branch keeps that stream disabled, so av_read_frame does not deliver its packets. The muxer can then produce video-only output or fail while waiting for audio.

Set stream.pointee.discard = AVDISCARD_DEFAULT when i == 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

📥 Commits

Reviewing files that changed from the base of the PR and between f33e674 and 4fa9dc0.

📒 Files selected for processing (6)
  • iosApp/Tests/OfflinePlaybackMappingTests.swift
  • iosApp/iosApp/Downloads/DownloadModels.swift
  • iosApp/iosApp/Downloads/LocalMediaProbe.swift
  • iosApp/iosApp/Downloads/OfflinePlayback.swift
  • iosApp/iosApp/Screens/Player/AVPlayerRoute/LoopbackSegmentWriter.swift
  • iosApp/iosApp/Screens/Player/PlayerViewModel.swift

@Quick104
Quick104 merged commit 9f850c5 into Silo-Server:main Aug 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants