Skip to content

feat(disc): play a Blu-ray BDMV folder over HTTP - #734

Merged
superuser404notfound merged 2 commits into
superuser404notfound:mainfrom
yipengfei329:feat/bdmv-folder-over-http
Oct 11, 2026
Merged

superuser404notfound merged 2 commits into
superuser404notfound:mainfrom
yipengfei329:feat/bdmv-folder-over-http

Conversation

@yipengfei329

Copy link
Copy Markdown
Contributor

Summary

A Blu-ray ripped as a BDMV folder can only reach the engine one file at a time, so a host has to remux the selected title on its origin before playback (on MovieClaw's origin that remux also cost the Dolby Vision enhancement layer, TrueHD and the PGS tracks). This lets a host hand the folder itself to load(source: .custom(reader)), and the engine recognizes it the way it recognizes a Blu-ray ISO. It is the remote BDMV reader from #703 (MovieClaw P5) that you named as a candidate; VIDEO_TS folders (P26) would follow on top of it.

Nothing changes for a host that does not pass a folder reader. The second commit fixes a declared-bandwidth bug that the first multi-clip folder hit, which custom-source ISOs share; I can split it into its own PR if you prefer.

What changed

  • DiscDirectoryReader (public protocol, an IOReader that carries no bytes itself): discFiles lists root-relative paths and sizes, openDiscFile(_:) opens one file as an independent reader, and an optional preferredPlaylist names the title's .mpls. HTTPDiscDirectoryReader is the ready-made one: one File(path:size:url:) per file, each read through its own HTTPDiscIOReader, with httpHeaders on every request.
  • Recognition. DiscReader.wrap recognizes the conformance before it reads a byte, ahead of the recognition cache, which rebuilds a reader from extents of a single image. wrapBluRayFolder is wrapBluRay with files in place of UDF extents: scanPlaylists and assembleBluRayTitle are generalized over their entries, so the folder gets the same NET-103 bounds, title selection, decoy filtering and AE#105 clip timeline. The image path calls them exactly as before.
  • MultiFileConcatIOReader presents the title's clips in playlist order as one seekable stream. A clip's file opens when the read reaches it, at most three stay open, and closed readers keep counting toward SourceTransferCounting. It declares discImageProbeEnabled = false.
  • Fewer requests. A playlist-sized file (up to maxSmallFileBytes) opens with its listed size instead of the bytes=0-0 range probe. It is read whole, so a range-blind origin costs nothing there; a clip keeps the probe, which is what refuses an origin that would answer a range with the whole file. On a real folder with 81 playlists this took recognition from 162 playlist requests to 81. HTTPDiscIOReader's convenience init gained an internal knownSize: for it.
  • Bandwidth (second commit). Demuxer.bitRate was libavformat's bit_rate, which it estimates as the source size over the duration it reads off the timestamps. Over a title whose clips restart their clock that duration is as wrong as duration (AE#105): a 6537 s UHD title whose two clips both start at 11.6 s probed as 388 s, so 54.6 GB declared BANDWIDTH=2253434656, and AVPlayer waited with AVPlayerWaitingWithNoItemToPlayReason forever. A disc title now takes its size over its playlist duration whenever libavformat produced a rate (66.9 Mbit/s there, and it starts). When libavformat gives no rate, as for a remote ISO opened by URL (bitrate=0 in the probe), the over-declared fallback is unchanged.
  • Documented in docs/formats.md (Disc) and docs/api.md (Loading), CHANGELOG under Unreleased.

Not covered yet: a controlled probe (limits / cancellation) wraps the reader in ProbeIOReader and does not recognize a folder; an uncontrolled probe(source:) and load(source:) do. This is in the docs and the CHANGELOG.

Test plan

  • Device / OS: MacBook Pro (Mac14,5, M2 Max), macOS 27.0.1, Xcode 27.0 (27A266a).

  • Real folders: a local Range origin serving each disc's folder from a NAS mount. A temporary aetherctl command (not part of this PR) listed the folder into HTTPDiscDirectoryReader, ran load(source: .custom(reader)), sampled currentTime for 6 s, then sought to 50 %, 90 % and 20 % of the duration and sampled 6 s after each seek:

    Disc Main title Path Start Seeks (landing, then 6 s of advance)
    Brokeback Mountain 1 clip, 8068 s, 1080p, DTS software plays 3 of 3 land and advance (0.30-0.41 s)
    Jobs 1 clip, 7694 s, 1080p VC-1, DTS + AC-3 software plays 3 of 3 (0.61-1.23 s)
    Joker 1 clip, 7309 s, 1080p HEVC PQ, TrueHD + AC-3 native plays 3 of 3 (1.33-2.94 s)
    The Equalizer 3 2 clips, both from 11.6 s, 6537 s, 2160p HEVC PQ, TrueHD + AC-3 native before the second commit: never starts (2.25 Gbit/s declared); after: plays fail, see below

    Titles and STN track languages came through on all four (for example dca:deu, dca:eng and pgssub:zho on the first).

  • Known limitation, unchanged from ISO: on The Equalizer 3 a seek to 3000 s lands in the second clip, because both clips cover overlapping timestamps and the timestamp search cannot tell them apart. Stock 7.33.2 has the same failure on an ISO of this shape: Kotonoha no Niwa (2 clips with AE#105 spans), opened by URL with aetherctl play --seek-pattern 1500,3000, ends the session with Demuxer: read failed (-1) at the first seek. Seeking by the clips' CLPI EP maps (feat(engine): contribute MovieClaw VOD and remote-disc extensions #703, P7) is what fixes it for both, and would be the next PR.

  • New BluRayFolderTests (12): main-title concatenation byte for byte; AE#105 spans for clips that restart their clock; preferredPlaylist reads only that playlist, and a missing one scans all; selectTitleID and clamping; missing clips; reads across files and every seek origin; at most three files open, with transfer counting across eviction; a file shorter than listed; the same folder over loopback HTTP, plus its independent reader; AetherEngine.probe(source: .custom(folder)); and the bandwidth test, which fails without the second commit.

  • Full swift test --jobs 8: 4,210 Swift Testing cases in 584 suites and the XCTest suite. One issue: ItemSwapStillTests "a playing native item hands over the frame on screen" (frame != nil), which fails the same way on an untouched 7.33.2 checkout on this machine. Scripts/check-doc-links.py passes.

Checklist

  • CHANGELOG.md updated
  • Commit messages follow Conventional Commits (feat(...), fix(...), chore(...))
  • The fix lives in the engine, not in a host-side workaround
  • Public API changes are intentional and documented (DiscDirectoryReader, HTTPDiscDirectoryReader)

🤖 Generated with Claude Code

yipengfei329 and others added 2 commits October 11, 2026 02:25
A Blu-ray ripped as a folder rather than an image could only reach the engine as
one file at a time, so a host had to remux the selected title on its origin
before playback. A host now hands the folder to load(source: .custom(reader)) as
a DiscDirectoryReader (the listing of root-relative paths and sizes, and a way
to open one file), or as the ready-made HTTPDiscDirectoryReader with one URL per
file.

DiscReader.wrap recognizes the conformance before it reads a byte and takes the
image path with files in place of UDF extents: the same bounded playlist scan
(NET-103) and title selection, the selected title's clips concatenated in
playlist order by a reader that opens a clip's file on demand and keeps at most
three open, and the same AE#105 clip timeline. scanPlaylists and
assembleBluRayTitle are generalized over their entries for this; the image path
is unchanged. An optional preferredPlaylist names the main title so only that
playlist is read. A playlist file opens with its listed size instead of a range
probe, which halved the requests recognition made on a real folder (162 to 81
for 81 playlists); a clip keeps the probe.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…bandwidth

libavformat estimates bit_rate as the source size over the duration it read off
the timestamps, and over a multi-clip disc title whose clips restart their clock
that duration is as wrong as it is for `duration` (AE#105). A 6537 s UHD title
whose two clips both start at 11.6 s probed as 388 s, so its 54.6 GB declared
BANDWIDTH=2253434656; AVPlayer never chose the variant and waited with no item
to play. Demuxer.bitRate now takes a disc title's rate as its size over its
playlist duration whenever libavformat produced one (66.9 Mbit/s there, and the
title starts). A title with no libavformat rate, such as a remote ISO opened by
URL, keeps the over-declared fallback.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
superuser404notfound pushed a commit that referenced this pull request Oct 11, 2026
MultiFileConcatIOReader held one lock across the network read and took
the same lock in cancel(), so the cancel meant to unblock a parked read
waited for that read to finish on its own (up to the HTTP timeout times
its retries). The lock is now split: ioLock serializes read, seek and
close and is held across the network; stateLock guards the open-file
table and is only held briefly, and cancel() takes only that one. A
cancel that arrives while a clip is still opening (its range probe) is
remembered and cancels that clip's reader once it exists. Evicted
readers close outside the lock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
@superuser404notfound
superuser404notfound merged commit bc50c91 into superuser404notfound:main Oct 11, 2026
4 checks passed
@superuser404notfound

Copy link
Copy Markdown
Owner

Merged, thank you! This is exactly the focused shape that works well here: an opt-in path that leaves every existing source untouched, the shared scan and assembly generalized instead of copied, and a test plan against real discs. The bandwidth fix is welcome in the same PR. The full suite was green on the PR merged with current main (4,295 Swift Testing cases plus XCTest).

One follow-up landed on top in 600fb6a: MultiFileConcatIOReader.cancel() took the same lock that read holds across the network, so a stop could not unblock a read parked on a stalled clip, and it waited for the HTTP timeout and its retries instead. The lock is now split (ioLock for read, seek and close, a short stateLock for the open-file table, which is all cancel takes), and a cancel that arrives while a clip is still running its range probe cancels that clip once it is open. Two new tests cover both cases; without the change they hang until the time limit.

Still open, as you noted: a controlled probe does not recognize a folder yet, and seeking across clips with overlapping timestamps needs the CLPI EP maps. Recognition itself is also not interruptible yet (the folder's own cancel() is a no-op while the playlist scan runs), which is bounded by the NET-103 caps but worth covering when the EP-map PR touches this code. This ships with the next release.

@superuser404notfound

Copy link
Copy Markdown
Owner

Released in 7.35.0, together with the follow-up that lets a stop unblock a read parked in a folder clip (600fb6a0). Thanks again for the reader.

superuser404notfound pushed a commit that referenced this pull request Oct 12, 2026
#736 built the EP-map seek table only on the image path; the BDMV folder
recognition from #734 landed first and still sought by timestamp, which is
the shape (two clips both from 11.6 s) that motivated the change. The folder
now reads BDMV/CLIPINF/<clip>.clpi through its DiscDirectoryReader, bounded by
the same readAll cap, and falls back to the timestamp search without it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
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