Repository navigation
fix(playback): stop a broken Dolby Vision RPU from hanging playback - #485
Conversation
A Profile 7 source whose RPU ffmpeg cannot parse took the whole session
down. The dovi_rpu bitstream filter does not fail cleanly — it rejects
every packet while ffmpeg runs on, so one observed session emitted
376,316 stderr lines before the process was killed, no manifest was ever
built, and the client got a 503 after ~10 seconds that it showed as an
endless spinner:
[dovi_rpu] Failed to read unit 1 (type 39).
[vost#0:0/copy] Error applying bitstream filters to a packet:
Invalid data found ... Invalid SEI message: payload_size too large
Whether the strip works is a property of the file, not of ffmpeg, so
SupportsDoviRPUFilter cannot answer it — but asking ffmpeg to strip two
seconds to the null muxer can, in about a second. Profile 7 sources are
probed once each on the start path and the result is cached; a source
that fails is copied without the filter, which leaves the base layer and
plays. Refusing to play at all does not.
The probe reads stderr rather than trusting the exit code: ffmpeg treats
a per-packet bitstream-filter error as non-fatal and exits 0, which is
exactly how a stream that could never start reached a live session.
Cache is keyed on path plus size so a replaced file is re-probed, and
bounded like the letterbox cache. A nil probe keeps stripping, since most
Profile 7 sources need it.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Db4dSxN9tH8yN7uUP549tK
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughPlayback now probes Dolby Vision Profile 7 sources before applying RPU stripping. Planning, remuxing, and playback restart paths avoid unsupported strip filters, while caching and concurrency behavior are covered by tests. ChangesDolby Vision strip capability
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant PlaybackHandler
participant PlanPlaybackV3
participant DVRPUProbe
participant FFmpeg
PlaybackHandler->>PlanPlaybackV3: Build playback plan with deferred probe
PlanPlaybackV3->>DVRPUProbe: Check source RPU stripability
DVRPUProbe->>FFmpeg: Probe DV7-to-HDR10 filter
FFmpeg-->>DVRPUProbe: Probe output and verdict
DVRPUProbe-->>PlanPlaybackV3: Stripability result
PlanPlaybackV3-->>PlaybackHandler: Plan, warning, or terminal result
Possibly related PRs
Suggested labels: 🚥 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 |
The probe answered the right question in the wrong place. Suppressing the
bitstream filter as the transport was being built left the plan still
promising DynamicRange "hdr10", Claims.Video.HDR10 and the
dolby_vision_metadata_removed / hdr10_base_layer_preserved validated
claims, and left session.RemuxDVMode persisted as strip_to_hdr10 — so the
client was told it was getting clean HDR10 while receiving Profile 7 with
dangling RPUs, and every path that re-derives the filter from the durable
session put the hanging filter straight back:
- HandleStartTranscode (quality change, seek, burn-in restart), which
also re-derives it from file.PrimaryDVProfile() == 7 with no plan at all
- the remote audio-switch restart, from updatedSession.RemuxDVMode
- the progressive-remux transport, which plan_v3 evaluates *before* the
HLS branches, so for many clients the broken file never reached the
probe in the first place
The verdict is now a planner input alongside the transformation
registries: the registries answer whether the executor carries the
transformation, this answers whether the file does. A source that fails it
is never planned onto a strip route, so the plan's claims, RemuxDVMode and
every restart derived from them agree with what the pipeline can produce.
With no tone-map recipe in this tree an HDR10-only client has no route
left, so it gets a dv_conversion_unsupported terminal naming the real
cause rather than a generic HDR message; a client that can run its own DV
transformation still gets that route, with a degradation warning
explaining why the server route was dropped.
The two paths that bypass the plan entirely are gated at the executor:
legacy/auto remux neutralizes the profile exactly as it already does for a
missing dovi_rpu filter, and the explicit v3 strip recipe fails loudly
rather than emit dangling RPUs under an HDR10 claim.
The probe itself:
- Tri-state verdict. Only a stderr-confirmed rejection is cached. A
timeout, a cancelled request or an ffmpeg that will not start is
inconclusive: the strip is kept and nothing is written, so one client
disconnecting can no longer disable the strip for a file permanently.
- Singleflight, so concurrent or retried starts of a title share one run.
- Timeout cut to 6s, inside the budget a client waits on the manifest,
and off the session lifecycle lock now that it runs at planning time.
- Keyed on size and mtime as well as path and binary, so a file replaced
in place with the same length is re-probed.
- stderr capture bounded at 64 KiB; the markers are in the first lines
and a rejecting filter emits a pair per frame.
- The head-only coverage is stated rather than asserted: this catches a
source that rejects from the first access unit, not one that breaks an
hour in.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Pushed The core change: the decision moved into the plannerThe original patch answered the right question in the wrong place. Suppressing the bitstream filter while building the transport left everything upstream of it still believing the strip was happening:
The verdict is now a One consequence worth calling outI'd assumed the fallback would be a transcode. It isn't — I think that's the honest answer, and better than either alternative: the original behaviour was a 10s spinner, and copying without the strip is not reliably playable for dual-layer P7 (dangling RPUs on the base layer) while also being a silent lie about the format. So the planner returns Happy to revisit if you'd rather it degrade to something playable, but I don't think there's a playable option for that combination today. Probe fixes
Executor-level gatingThe two paths that bypass the plan entirely are handled where they are, rather than left to a plan they never consult: legacy/auto remux neutralizes the profile exactly as it already does for a missing Verification
New tests cover the planner gating and terminal, the client-transformation route surviving, a non-DV source never paying for a probe, both executor paths, and the probe's tri-state caching, singleflight, follower cancellation and output bounding. 🤖 Generated with Claude Code |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
internal/playback/dovi_rpu_probe_test.go (1)
47-68: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTest doesn't actually exercise the "same size, different mtime" case it documents.
"original" (8 bytes) vs "replaced, same length" (21 bytes) differ in size, so size alone would already change the key — the mtime-matters claim in the comment isn't exercised.
♻️ Use equal-length replacement content
- if err := os.WriteFile(path, []byte("replaced, same length"), 0o600); err != nil { + if err := os.WriteFile(path, []byte("changed!!"), 0o600); err != nil { t.Fatalf("replace probe fixture: %v", err) }🤖 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 `@internal/playback/dovi_rpu_probe_test.go` around lines 47 - 68, Update TestProbeKeyChangesWithTheFile to replace the probe fixture with content exactly matching the original file’s length while still differing in contents, so the assertion exercises key invalidation from a changed modification time rather than a size change.internal/playback/remux.go (1)
230-231: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winSilent DV7-strip fallback: add the warning log already used elsewhere. Both sites gate the Dolby Vision strip on the new per-source RPU probe and silently fall back when it fails, while the equivalent gate in
internal/api/handlers/playback.go#L3107-L3122logs a warning ("restart dropped the dolby vision rpu strip: source cannot be stripped") on the same failure. Without a log, operators lose the one signal that would explain why a given file lost DV handling.
internal/playback/remux.go#L230-L231: log (e.g. viaslog.Warn) whensharedDVRPUProbe.CanStripreturns false for a profile-7 source, mirroringsupportsDoviRPUFilter's existing warning for the missing-filter case.internal/api/handlers/playback.go#L2612-L2618: add anelsebranch that logs a warning (matching the message/fields used atplayback.go#L3119-L3120) whenplayback.DVRPUStrippable(...)returns false, instead of silently omittingnodeReq.VideoBitstreamFilter.♻️ Proposed fix for remux.go
case "", RemuxDVLegacyAutoV3: - effectiveProfile = remuxDVProfile(dvProfile, supportsDoviRPUFilter(bin) && - (dvProfile != 7 || sharedDVRPUProbe.CanStrip(ctx, bin, filePath))) + filterAvailable := supportsDoviRPUFilter(bin) + canStrip := filterAvailable + if dvProfile == 7 && filterAvailable { + canStrip = sharedDVRPUProbe.CanStrip(ctx, bin, filePath) + if !canStrip { + slog.Warn("source's Dolby Vision RPU cannot be parsed; dropping the strip for this remux", "ffmpeg", bin, "file", filePath) + } + } + effectiveProfile = remuxDVProfile(dvProfile, canStrip)♻️ Proposed fix for playback.go
- if updatedSession.RemuxDVMode == playback.RemuxDVStripToHDR10V3 && strings.EqualFold(nodeReq.TargetCodecVideo, "copy") && - playback.DVRPUStrippable(r.Context(), h.playbackConfig().FFmpegPath, file.FilePath) { - nodeReq.VideoBitstreamFilter = playback.DV7ToHDR10BitstreamFilter - } + if updatedSession.RemuxDVMode == playback.RemuxDVStripToHDR10V3 && strings.EqualFold(nodeReq.TargetCodecVideo, "copy") { + if playback.DVRPUStrippable(r.Context(), h.playbackConfig().FFmpegPath, file.FilePath) { + nodeReq.VideoBitstreamFilter = playback.DV7ToHDR10BitstreamFilter + } else { + slog.WarnContext(r.Context(), "audio-switch restart dropped the dolby vision rpu strip: source cannot be stripped", + "component", "api", "playback_session_id", sessionID, "file_id", file.ID) + } + }🤖 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 `@internal/playback/remux.go` around lines 230 - 231, Log a warning when DV RPU stripping is skipped by the per-source probe: in internal/playback/remux.go at lines 230-231, detect a profile-7 source where sharedDVRPUProbe.CanStrip returns false and mirror the existing supportsDoviRPUFilter warning; in internal/api/handlers/playback.go at lines 2612-2618, add an else branch for playback.DVRPUStrippable returning false and use the warning message and fields already used around lines 3119-3120.
🤖 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 `@internal/playback/dovi_rpu_probe.go`:
- Around line 108-166: Update CanStrip so the shared runDVRPUProbe call uses a
context detached from caller cancellation via context.WithoutCancel(ctx), while
preserving the existing dvRPUProbeTimeout and timeout handling inside the probe.
Keep follower waiting and caching behavior unchanged, so cancellation of the
leader does not force an unknown fail-open result for the in-flight probe.
---
Nitpick comments:
In `@internal/playback/dovi_rpu_probe_test.go`:
- Around line 47-68: Update TestProbeKeyChangesWithTheFile to replace the probe
fixture with content exactly matching the original file’s length while still
differing in contents, so the assertion exercises key invalidation from a
changed modification time rather than a size change.
In `@internal/playback/remux.go`:
- Around line 230-231: Log a warning when DV RPU stripping is skipped by the
per-source probe: in internal/playback/remux.go at lines 230-231, detect a
profile-7 source where sharedDVRPUProbe.CanStrip returns false and mirror the
existing supportsDoviRPUFilter warning; in internal/api/handlers/playback.go at
lines 2612-2618, add an else branch for playback.DVRPUStrippable returning false
and use the warning message and fields already used around lines 3119-3120.
🪄 Autofix (Beta)
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: 46bdb1f4-9b2f-4315-a9e9-b910fa2ae4ac
📒 Files selected for processing (8)
internal/api/handlers/playback.gointernal/api/handlers/playback_v3.gointernal/playback/dovi_rpu_probe.gointernal/playback/dovi_rpu_probe_test.gointernal/playback/plan_v3.gointernal/playback/protocol_v3_test.gointernal/playback/remux.gointernal/playback/remux_dv_test.go
The probe rode the caller's context, so a leader whose client disconnected returned dvRPUUnknown — and CanStrip then handed that fail-open to every follower already blocked on the shared call, even though their own requests were still alive. One client walking away was enough to give a live session the strip the source cannot survive, which is the hang this whole change exists to prevent. The work was also thrown away, so the next start paid for the probe again. Run it under context.WithoutCancel instead. dvRPUProbeTimeout still bounds it, so nothing is left running; a verdict reached after the leader has gone is still correct and still worth caching. Follower behaviour is unchanged: a follower whose own request is cancelled still leaves immediately rather than waiting on someone else's probe. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Pushed The leader was probing on the caller's context, so if its client disconnected the run returned
🤖 Generated with Claude Code |
Problem
A Dolby Vision Profile 7 source whose RPU ffmpeg cannot parse takes the whole playback session down. The
dovi_rpubitstream filter does not fail cleanly — it rejects every packet while ffmpeg keeps running:One observed session emitted 376,316 stderr lines before the process was killed. No manifest was ever built,
master.m3u8returned 503 after 9.7 seconds, and the client sat on a spinner. From the user's side the title simply never starts, with no error.Approach
Whether the strip works is a property of the file, not of the ffmpeg build, so
supportsDoviRPUFiltercannot answer it. Asking ffmpeg to strip two seconds to the null muxer can, in about a second.The probe reads stderr, not the exit code. ffmpeg treats a per-packet bitstream-filter error as non-fatal and exits
0— which is precisely how a stream that could never start reached a live session in the first place. There is a test pinning that behaviour.The verdict is a planning input, not a transport patch. It sits in
PlannerInputV3alongside the transformation registries: the registries answer whether the executor carries the transformation, this answers whether the file does. A source that fails it is never planned onto a strip route at all.That placement is what makes the fix hold. The plan is where
DynamicRange = "hdr10",Claims.Video.HDR10and thedolby_vision_metadata_removed/hdr10_base_layer_preservedvalidated claims are set, and it is whatsession.RemuxDVModeis derived from and persisted as. Suppressing the filter further downstream would leave all of those describing a stream the server is no longer producing, and would leave every path that re-derives the filter from the durable session free to put it straight back:HandleStartTranscode— the client-driven restart behind quality changes, seeks and burn-in — which also re-derives the filter fromfile.PrimaryDVProfile() == 7with no plan involved at allupdatedSession.RemuxDVModeplan_v3evaluates before the HLS branchesWhat the client gets
With no tone-map recipe in this tree, an HDR10-only client on an unstrippable P7 source has no route left. Rather than the generic
hdr_transcode_unsupported(which sends the user looking for a missing encoder), the planner returnsdv_conversion_unsupported— the terminal reason theserver_dv7_to_hdr10spec already declares — with a message naming the real cause. A client that advertises its own DV→HDR10 or DV→DV8.1 transformation still gets that route, carrying adolby_vision_strip_unsupported_by_sourcedegradation warning so the server-side drop is not silent.The two paths that bypass the plan
Gated at the executor instead:
dovi_rpufilter, so it still starts and still plays.The probe
Testing
Unit tests for the stderr detection (using the real log lines above), the tri-state caching rules, cache-key invalidation, eviction, singleflight, follower cancellation, and the nil/unprobeable paths. Planner tests that an unstrippable source is never planned onto the strip, that the terminal names the Dolby Vision cause, that a client-side transformation still wins, and that a non-DV source never pays for a probe. Executor tests that legacy/auto drops the filter and the explicit recipe refuses.
go build ./...,go vet ./internal/...and-raceclean.internal/playbackandinternal/api/handlersgreen apart from two failures that reproduce identically on the parent commit:TestServeDirectPlayChangedEntityRejectsOldIfRangeandTestHandleReplanPlaybackV3SeekFailureRecoveryNeverChangesMediaVersion.Caveat stated plainly: the logic and the fallback paths are verified; that the specific file which triggered this now plays is not. Its RPU is malformed enough that the base layer may have problems of its own. The guaranteed improvement is a fast, definite, honestly-labelled outcome instead of a ten-second hang and a spinner.
Follow-up not in scope
Even with this, a bitstream filter that fails at runtime for some other reason still spews unbounded stderr until the process is killed. Failing fast on repeated per-packet filter errors would be worth doing on its own.
AI-use disclosure
Written by Claude Opus 5 (Claude Code) working with @RXWatcher, who hit this on his own library and directed the investigation. Root cause came from the server logs of the failing session. The revision moving the decision into the planner was made by Claude Opus 5 in response to maintainer review.
Summary by CodeRabbit
Bug Fixes
Tests