Skip to content

fix(playback): convert to E-AC-3 5.1 when the sink can't bitstream the source - #2015

Merged
Quick104 merged 5 commits into
mainfrom
fix/issue-2010-surround-bitstream-conversion
Nov 19, 2026
Merged

Quick104 merged 5 commits into
mainfrom
fix/issue-2010-surround-bitstream-conversion

Conversation

@Quick104

@Quick104 Quick104 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2010
Related issue: N/A
Validation tasks: unavailable (the validation board could not be read: the gh token lacks the read:project scope)
Other clients: Apple N/A (does not send layout_aware_passthrough); Android N/A (plays the converted plan with its existing E-AC-3/AC-3 passthrough handling); Roku N/A (does not attest exact audio evidence); Web N/A (does not send layout_aware_passthrough)

On an Android TV whose HDMI/eARC output passes AC-3 and E-AC-3 to a receiver but not TrueHD or DTS, those tracks reach the receiver as stereo. The app decodes them to PCM with FFmpeg, and the TV's own output mixes app PCM down to 2.0. This was reported on a Sony Bravia with a 5.1 receiver; Plex on the same TV sends 5.1 because its server converts the track to E-AC-3 or AC-3.

This change does the same. When the sink can't take the source codec as a bitstream but validates E-AC-3 or AC-3 5.1, the server converts the selected track to that codec at 5.1 on a copy-video HLS remux instead of letting the client decode it to PCM.

Approach

The conversion is a candidate route in the v3 planner that ranks ahead of the original file. The planner offers it only when all of these hold:

  • the client attests exact audio evidence and layout_aware_passthrough (Android does; Apple and web don't);
  • the track would be decoded locally (client_decode_supported), has more than two channels, and its codec is not in the sink's passthrough list;
  • the sink validates E-AC-3 (preferred) or AC-3 at six channels with a 5.1 layout, and the HLS delivery can pass it through. The conversion uses the first of the two that an HLS executor offers and the HLS delivery accepts;
  • the picture and subtitles stay as they are: native dynamic range, no Dolby Vision Profile 7 handling, the same subtitle mode and claims as the original route, and no server bitrate cap.

Two new server transformations, audio_to_eac3@1 and audio_to_ac3@1, encode 48 kHz 5.1 at 640 kbps. Each is advertised only after an FFmpeg smoke test encodes that recipe into fragmented MP4, and node dispatch already rejects a worker that doesn't advertise a plan's transformations. A failed or missing probe only removes these recipes.

The conversion only improves on a route the client can already play, so it never blocks playback:

  • the planner skips it when no executor offers the recipe or the client already tried it;
  • when session admission or route preparation refuses it on a start or replan, the server re-plans without any conversion and plays the route it improved on, with the same warnings and labels. The refused start's session is discarded without a watch-history row or scrobble. A session that ended during route preparation stays ended;
  • a seek reanchor keeps its frozen recipe.

/api/v2 advertises the behavior as the surround_bitstream_conversion_v1 server feature, and the plan carries decision_reason: surround_bitstream_conversion with an audio_converted warning. Android needs no update: it already plays HLS remuxes with an AC-3/E-AC-3 passthrough claim.

There is no setting and no Android capability probe. Android can't tell a stereo app mixer from one that carries multichannel PCM, because a failed direct multichannel PCM probe doesn't prove a stereo mixer. So a device whose output does carry multichannel PCM now gets E-AC-3 5.1 instead of lossless PCM for codecs its sink can't take, as on Plex.

Validation

  • Sandbox built from 3bcce7fd7, Android-TV-shaped /api/v2/playback/start for an H.264 file with a DTS 5.1 track:
    • Sink validates E-AC-3 and AC-3: server_remux_hls with audio_to_eac3@1. ffprobe of the init and first segment shows the H.264 copied and E-AC-3, 6 channels, 5.1(side), 48 kHz, 640 kbps.
    • Same sink, HLS delivery passes only AC-3: audio_to_ac3@1, AC-3 with the same layout and rate.
    • Sink also validates DTS: the original file with DTS passthrough, as on main.
  • Tests that failed before their fix: TestPlanPlaybackV3ConvertsToAC3WhenTheHLSDeliveryRefusesEAC3, the AC-3-only-executor case of TestPlanPlaybackV3ConvertsDecodedSurroundToSinkBitstream, TestReplanWithoutSurroundConversionV3SkipsTheOtherCodec, and the session_expired case of TestReplanWithoutSurroundConversionV3LeavesOtherFailuresAlone.
  • go test for the playback, handlers, API v2, API, transcode-node, and tonemap packages and make lint-changed pass. TestCopyRemuxSubtitleRenditionRealFFmpeg fails locally with FFmpeg 6.1.1, on main too.
  • Not verified: 5.1 at the receiver on a real TV with a stereo app mixer (none available), and the admission fallback live (the sandbox admin account is exempt from the audio-transcoding policy). Handler tests cover the fallback paths.

Evidence: https://evidence.siloserver.org/r/silo-server/pr-2015/

Risks

  • Behavior change for Android devices that carry multichannel PCM to a receiver and can't bitstream the source codec: lossless PCM becomes E-AC-3 5.1 on an HLS remux, and TrueHD/DTS-HD 7.1 becomes 5.1. Sinks that pass the source codec through, including Shield-class boxes with TrueHD, are unaffected.
  • The new recipe has no stream-token or node attestation fence. During a rolling upgrade or rollback, an older binary that reconstructs one of these sessions would encode with the legacy E-AC-3 arguments for the rest of the session. For a 7.1 source that gives E-AC-3 5.0(side) at 384 kbps, so the LFE channel is lost, not only bitrate.
  • Any other failed v3 start still records a watch-history row for its initialized position, as before. Only the refused surround start is discarded quietly.

Follow-ups:

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code subagents (code-review finders and verifier), Codex via T3 Code delegated tasks (design and adversarial review)
  • Model(s): claude-opus-5-5 (implementation and review subagents), claude-sonnet-5-5 (review subagents), gpt-6.1-sol (Codex reviews)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: Codex (gpt-6.1-sol) reviewed the design before implementation and the diff in two rounds. Round 1 found that replans couldn't fall back after route preparation failed, that local transport setup errors bypassed the start fallback, and that a refused start recorded a watch-history row before falling back; all three are fixed. Round 2 found nothing new and re-ran those failure scenarios against the fixes. After the merge with main, a maintainer review (Claude Code subagents, claude-opus-5-5 and claude-sonnet-5-5, and Codex gpt-6.1-sol) found six more defects in the fallback, the session discard, codec selection, and the capability probe budget; all are fixed. An internal multi-agent review also led to fixes: fallback on routing-policy refusals, no conversion when the sink lists the source codec, optional recipe probes, no fallback during a seek reanchor or after the attempt is saved, and escalation of the fallback route.

🤖 Generated with Claude Code

Note

Convert multichannel audio to E-AC-3/AC-3 5.1 when the sink can't bitstream the source

  • Adds a surround-bitstream route to the protocol v3 planner. When the client would decode multichannel audio to PCM and the sink validates E-AC-3 (preferred) or AC-3 5.1 but not the source codec, planning returns a copy-video HLS remux that encodes audio at 48 kHz, 5.1, 640 kbps in surround_conversion_v3.go.
  • The transformation registry probes FFmpeg for both encoders with a silent one-frame 5.1 encode in transformations_v3.go; missing encoders mark the recipe unavailable instead of failing the probe.
  • Start and replan flows gain a one-time fallback in playback_v3_surround.go: when a surround-conversion plan is refused for transcode limits, disabled transcoding, or route-preparation failure, the server replans without conversion and retries once. Refused sessions are discarded via a new non-user-initiated cleanup path.
  • appendAudioArgs in transcode.go uses the fixed surround recipe for six-channel E-AC-3/AC-3 requests; other channel counts keep their prior arguments. The tone-map probe endpoint slack grows from 45s to 51s for the two new registry probes.
  • Behavioral Change: the planner now tries the surround-bitstream route before direct play, so clients with exact audio evidence and layout-aware passthrough can receive a converted-audio plan instead of client-side PCM decode. Fixtures and feature lists include the new surround-bitstream-conversion token.

Macroscope summarized de5e131.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 24 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b44a8185-51fa-4b77-b856-1ebce28c59fd
Commits

Reviewing files that changed from the base of the PR and between bd40bd9 and de5e131.

Files selected for processing: 20

  • docs/architecture/playback-protocol-v3.md
  • docs/design/schemas/playback-v3/v3/fixtures/valid/hls-subtitle-rendition-decision_response.json
  • docs/design/schemas/playback-v3/v3/fixtures/valid/hls-subtitle-renditions-all-decision_response.json
  • docs/design/schemas/playback-v3/v3/fixtures/valid/learned-limit-decision_response.json
  • internal/api/handlers/playback_realtime.go
  • internal/api/handlers/playback_v3.go
  • internal/api/handlers/playback_v3_surround.go
  • internal/api/handlers/playback_v3_surround_test.go
  • internal/playback/candidate_planner_v3.go
  • internal/playback/candidate_video_v3.go
  • internal/playback/capabilities_v3.go
  • internal/playback/protocol_v3.go
  • internal/playback/surround_conversion_v3.go
  • internal/playback/surround_conversion_v3_test.go
  • internal/playback/testdata/protocol_v3/hls-subtitle-rendition-decision_response.json
  • internal/playback/testdata/protocol_v3/hls-subtitle-renditions-all-decision_response.json
  • internal/playback/testdata/protocol_v3/learned-limit-decision_response.json
  • internal/playback/transcode.go
  • internal/playback/transformations_v3.go
  • internal/tonemap/probe.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-kody

silo-kody Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Comment thread internal/playback/plan_v3.go Outdated
Comment on lines +448 to +451
if target := surroundBitstreamTargetV3(source, input.Request, audioOK, passthrough, audioClaims); target != "" &&
source.DVProfile != 7 && rangeOK && quality.PreservesSource && originalSubtitleOK {
if result, ok := planSurroundBitstreamRemuxV3(input, base, source, target, subtitle, hlsSubtitle, high10Quirk); ok {
return result

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Bug high

API compatibility regression allows the surround-conversion branch to execute for frozen /api/v1 playback because its prerequisites include layout_aware_passthrough, which ServerFeaturesV3 already advertises, while startPlaybackApplicationV3 strips only subrip_sidecar_v1. Gate this operation by API surface in both start and replan planning to prevent existing /api/v1 requests from switching from original playback to lossy server HLS conversion for a feature documented as native-/api/v2-only.

Prompt for LLM

File internal/playback/plan_v3.go:

Line 448 to 451:

API compatibility regression allows the surround-conversion branch to execute for frozen /api/v1 playback because its prerequisites include layout_aware_passthrough, which ServerFeaturesV3 already advertises, while startPlaybackApplicationV3 strips only subrip_sidecar_v1. Gate this operation by API surface in both start and replan planning to prevent existing /api/v1 requests from switching from original playback to lossy server HLS conversion for a feature documented as native-/api/v2-only.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This no longer applies. Main has since retired /api/v1 behind a 410 tombstone (#3200), so only /api/v2 starts reach the planner, and this branch now includes that change.

🤖 Claude Code in T3 Code (claude-opus-5-5)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agreed—the suggestion is outdated. The router sends /api/v1 and its descendants to the tombstone, except for the retained health and readiness probes (internal/api/router.go:3398–3403). The tombstone returns 410 Gone without running the old handler (internal/api/v1_tombstone.go:15–22).

That means /api/v1 playback starts and replans cannot reach the planner, so an API-surface gate is not needed to address the compatibility concern I raised. I withdraw the suggestion.

Comment on lines +74 to +82
for _, codec := range []string{surroundBitstreamCodecEAC3V3, surroundBitstreamCodecAC3V3} {
if !containsFoldV3(caps.PassthroughCodecs, codec) {
continue
}
for _, entry := range caps.Entries {
if strings.EqualFold(entry.Codec, codec) &&
containsIntV3(entry.ChannelCounts, surroundBitstreamChannelsV3) &&
containsFoldV3(entry.Layouts, audioLayoutSurround51V3) {
return codec

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Bug high

Codec selection returns E-AC-3 before checking executor availability, preventing surround conversion for a sink that supports both codecs when the HLS registry offers AC-3 but not E-AC-3. Try preferred codecs in order, checking recipe availability and delivery eligibility for each candidate instead of abandoning conversion after the first rejected target.

Prompt for LLM

File internal/playback/surround_conversion_v3.go:

Line 74 to 82:

Codec selection returns E-AC-3 before checking executor availability, preventing surround conversion for a sink that supports both codecs when the HLS registry offers AC-3 but not E-AC-3. Try preferred codecs in order, checking recipe availability and delivery eligibility for each candidate instead of abandoning conversion after the first rejected target.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 74b8906. The planner now converts to the first of E-AC-3 and AC-3 that the sink validates and an HLS executor offers. A new case in TestPlanPlaybackV3ConvertsDecodedSurroundToSinkBitstream (sink validates both, only the AC-3 executor exists) fails on the earlier head and passes now. A related gap, the HLS delivery refusing the E-AC-3 plan, is in my review on this PR.

🤖 Claude Code in T3 Code (claude-opus-5-5)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the update. The AC-3-only executor test addresses the executor-availability gap in the original suggestion. The separate case where HLS delivery rejects the preferred E-AC-3 plan remains under review. I haven’t independently verified the fix.

…e source

An Android TV whose HDMI/eARC output passes AC-3 and E-AC-3 but not TrueHD
or DTS decodes those tracks to PCM, and the TV's own output mixes app PCM
to stereo, so a 5.1 receiver gets 2.0.

When the client attests exact sink evidence, would decode a track with more
than two channels locally, and its sink validates E-AC-3 (or AC-3) 5.1 but
not the source codec, the v3 planner now prefers a copy-video HLS remux that
converts the track to that codec at 48 kHz, 5.1, 640 kbps
(audio_to_eac3@1 / audio_to_ac3@1). Only routes that keep the original
picture and subtitles qualify. When the recipe is unavailable, already
tried, or refused by admission or route preparation, playback falls back
to the route it improved on, and the refused start records no history.
/api/v2 advertises surround_bitstream_conversion_v1.

Closes #2010

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Quick104
Quick104 force-pushed the fix/issue-2010-surround-bitstream-conversion branch from d358772 to 377d442 Compare November 5, 2026 03:42
@silo-kody

silo-kody Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

// failed to start. It releases the same resources as a stop but writes no
// watch history and sends no scrobble: nothing played.
func (h *PlaybackHandler) discardRefusedStartSessionV3(ctx context.Context, sessionID string) {
if err := h.dropLiveSessionByID(ctx, sessionID); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Kody Rules high

Refused-session release depends on the request context

A canceled request can prevent cleanup of the refused session and leave it allocated. Call h.dropLiveSessionByID with a timeout derived from context.WithoutCancel(ctx), cancel it afterward, handle release failures, and share the cleanup helper with equivalent release paths.

Also found in:

  • internal/api/handlers/playback_v3.go:2439-2439
  • internal/api/handlers/playback_v3_surround.go:79-79

Kody rule violation: Detach mandatory cleanup from request cancellation and bound its lifetime

Prompt for LLM
File internal/api/handlers/playback_v3_surround.go, line 75:

Refused-session release depends on the request context

The refused start still requires session cleanup after the request is canceled. Start cleanup with a timeout derived from `context.WithoutCancel(ctx)`, cancel it when finished, and handle any release failure rather than silently returning. Share the cleanup helper with equivalent session-release paths.

**Also found in:**
- `internal/api/handlers/playback_v3.go:2439-2439`
- `internal/api/handlers/playback_v3_surround.go:79-79`

Kody rule violation: [Detach mandatory cleanup from request cancellation and bound its lifetime](https://kodus.siloserver.org/settings/code-review/1247142351/kody-rules/b3c20cf3-6a41-4161-9af6-2bef16b674e9?teamId=ba9922fc-c0ea-4cf8-87bb-9d4f42ffc73e)

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This doesn't hold. The only caller passes context.WithoutCancel(r.Context()) (the abort closure in startPlannedPlaybackV3), so a cancelled request doesn't stop the cleanup. That's the same context main's ordinary start abort uses. A different problem in this function, where a failed node cancel left the session registered, is in my review on this PR.

🤖 Claude Code in T3 Code (claude-opus-5-5)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You’re right. If the only caller passes context.WithoutCancel(r.Context()), request cancellation does not prevent this cleanup. The suggestion’s cancellation claim was incorrect, and it should not have flagged that as a defect.

The failed node-cancel path you identified is a separate issue: it can leave the session registered even with a detached context.

plan := cloneRemuxPlanCandidateV3(base)
plan.Delivery = DeliveryRemuxHLSV3
plan.Stream = StreamV3{Protocol: StreamHLSV3, Container: containerHLSV3, MIMEType: mimeTypeHLSV3, Headers: map[string]string{}, HeaderRefresh: HeaderRefreshNoneV3}
if deliverySupportsFeatureV3(input.Request, DeliveryClassHLSV3, FeatureHLSCopyMPEGTSV3) && HLSCopyFitsMPEGTS(source.VideoCodec, "") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Kody Rules high

MPEG-TS selection skips converted audio compatibility

Passing an empty audio codec to HLSCopyFitsMPEGTS can select MPEG-TS for an incompatible converted stream. Pass target to check the converted audio codec.

Kody rule violation: Validate playback decisions against the actual output target

Prompt for LLM
File internal/playback/surround_conversion_v3.go, line 109:

MPEG-TS selection skips converted audio compatibility

Check the converted audio codec when deciding whether the output fits MPEG-TS. Passing an empty audio codec skips that part of the container compatibility check and can select MPEG-TS for a converted audio stream the container check would reject.

Kody rule violation: [Validate playback decisions against the actual output target](https://kodus.siloserver.org/settings/code-review/1247142351/kody-rules/54d74e3a-b6e9-46dc-9703-92c33a2caeeb?teamId=ba9922fc-c0ea-4cf8-87bb-9d4f42ffc73e)

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This has no effect on the output. HLSCopyFitsMPEGTS only checks the audio codec against the HLS-native list (AAC, AC-3, E-AC-3, MP3), and the conversion always produces E-AC-3 or AC-3, so passing the target returns the same answer as passing "". The code now passes the target anyway, so the check reads correctly.

🤖 Claude Code in T3 Code (claude-opus-5-5)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agreed. Given the current conversion targets, passing "" or target produces the same compatibility result, so my suggestion overstated the risk of an incompatible MPEG-TS output.

Passing target is still clearer and makes the check accurate if the set of conversion targets changes later.

Quick104 and others added 3 commits November 15, 2026 00:30
Main replaced the planner's route walk with a candidate list (#3948), so
the surround conversion moves from a branch in the walk to a candidate
route that ranks ahead of the original file. It stays one candidate: it
converts to the first of E-AC-3 and AC-3 that the sink validates and an
HLS executor offers, so a tried conversion falls back to the route it
improved on, and an AC-3-only executor pool still converts. The start
and replan fallbacks take main's shared planner input (#3947).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Try AC-3 when the HLS delivery refuses the E-AC-3 conversion plan,
  not only when no executor offers E-AC-3.
- Drop a refused conversion session the way the start's ordinary abort
  ends it, without the user-stop steps that can fail before the session
  stops, and log a failed discard.
- Leave a session that ended during route preparation stopped instead of
  starting the fallback route in a new one.
- Give a replan's fallback the same pinned renditions, downloaded
  subtitle listing, learned-limit label, and degradation warnings as the
  plan it replaces.
- Budget the capability endpoint for the two new 3 s recipe probes, and
  correct the protocol doc and the appendAudioArgs comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each codec is its own attempt key, and the fallback plans from a fresh
capability snapshot. When that snapshot offered the other codec, the
fallback found another conversion and gave up, though the original
route still played. It now excludes each conversion it is offered.

The fallback also takes the refused plan's settled bandwidth-limit
label instead of re-marking it: both deliver the same file at the
source bitrate, and re-marking skipped the check that clears a label
the limit didn't cause.

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

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review of 74b8906, the branch after merging main. Main replaced the planner's route walk with a candidate list (#3948), so the merge re-implements the conversion as a candidate route that ranks ahead of the original file. It converts to the first of E-AC-3 and AC-3 that the sink validates and an HLS executor offers.

Six findings below are fixed in commits on this branch, and one is left as a maintainer decision. Also fixed: the protocol doc's feature table had no surround_bitstream_conversion_v1 row, its eligibility text omitted the bitrate-cap and source-quality conditions, and the appendAudioArgs comment still said E-AC-3 and AC-3 can't go in MPEG-TS.

🤖 Claude Code in T3 Code (claude-opus-5-5)

Comment thread internal/api/handlers/playback_v3.go Resolved
Comment thread internal/api/handlers/playback_v3.go Resolved
Comment thread internal/playback/transformations_v3.go Resolved
// Legacy Dolby Digital; universal AVR support.
args = append(args, "-c:a", "ac3", "-b:a", "448k")
case audioCodecEAC3, audioCodecAC3:
if opts.TargetAudioChannels == surroundBitstreamChannelsV3 {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maintainer decision: no rolling-upgrade fence for the new recipe. The PR body discloses this risk; this adds the measured impact. The recipe is selected only by TargetAudioChannels == 6. Reconstruction tokens, cards, and executor attestation carry nothing an older binary would reject. An older replica that reconstructs one of these sessions during a rolling upgrade or rollback runs the legacy -c:a eac3 -b:a 384k arguments. A direct FFmpeg comparison on 7.1 input gave E-AC-3 5.0(side) at 384 kbps with the legacy arguments and 5.1(side) at 640 kbps with the frozen ones. So the layout changes and LFE is dropped mid-session, not just the bitrate. A fence would need a discriminator older binaries reject, carried through tokens, cards, and attestation. I'm not changing this here; it's left for the maintainers to decide.

@Quick104

Quick104 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Review summary (head de5e131)

Fit: 8/10 · Readiness: 8/10 — conditional

The branch was 353 commits behind main, and main had replaced the planner's route walk with a candidate list (#3948). I merged main and moved the conversion into a candidate route that ranks ahead of the original file. That merge also fixed Kody's finding about AC-3 when no executor offers E-AC-3.

Update for de5e131: main had moved 216 commits ahead and the branch conflicted. I merged it again. The one conflict was in the replan's reused-HLS-transport block: main now copies the replan's adaptation reasons onto the reused recipe (#4315), and this branch had moved that block into reuseActiveHLSTransportV3, so the copy moved with it. Main's new adaptation reasons already label the conversion audio_codec_unsupported, so the admin Activity page explains it with no change here.

Fixed on this branch (details in the review threads):

  • A refused start's discard could leave a node-executed session registered (1f87213).
  • A replan's fallback dropped the replaced plan's warnings, learned-limit label, and pinned renditions (1f87213, 3bcce7f).
  • A session stopped during route preparation was restarted on the fallback route (1f87213).
  • The fallback gave up when a fresh capability snapshot offered the other codec (3bcce7f).
  • AC-3 wasn't tried when the HLS delivery refused the E-AC-3 plan (1f87213).
  • The capability endpoint's probe budget didn't cover the two new 3 s probes (1f87213).
  • The protocol doc's feature table and eligibility conditions, and a stale appendAudioArgs comment (1f87213).

Verified: on sandboxes built from 3bcce7f and again from de5e131, Android-TV-shaped starts for an H.264/DTS 5.1 file got audio_to_eac3@1 with a sink that takes both Dolby codecs, audio_to_ac3@1 when the HLS delivery passes only AC-3, and the original file when the sink also takes DTS. ffprobe of the delivered segments showed the video copied and 6-channel 5.1(side) audio at 48 kHz and 640 kbps. On de5e131, GET /api/v2/admin/sessions reported audio_codec_unsupported for both conversions. The new tests each failed before their fix, and the playback, handler, node, proxy, and API tests pass on de5e131. Not verified: a real TV with a stereo app mixer, and the admission fallback live.

Left for the maintainers to settle:

  • Default for devices whose output carries multichannel PCM. They now get lossy E-AC-3 5.1 instead of lossless PCM for codecs the sink can't take, with no setting or client opt-out. This is the PR's stated trade-off, and it's why Fit is 8 rather than higher.

Declined: the rolling-upgrade fence the Codex review asked for. An older binary that rebuilds one of these sessions keeps encoding with the legacy E-AC-3 arguments, which drops the LFE channel on a 7.1 source. That only happens while two versions run side by side, and the result is degraded audio, not a failed stream. A fence would need a new play method that every remux check accepts, and one missed check would break these sessions on the current binary. The reasoning is in the transcode.go thread.

Validated features: unavailable. The validation board couldn't be read with the token used for this review.

User manual: Silo-Server/siloserver.org#111 and draft docs PR Silo-Server/siloserver.org#112 already describe this behavior, including the AC-3 case; the fixes don't change them.

Other clients: Apple and web don't send layout_aware_passthrough, so they keep their current routes. Roku doesn't attest exact audio evidence. Jellyfin-protocol transcodes still target AAC and are unchanged. On Android, check what happens when passthrough setup fails on a converted plan: the app's local-PCM retry would decode the lossy E-AC-3, where a replan back to the original would keep the lossless track. That needs an Android follow-up.

Evidence: https://evidence.siloserver.org/r/silo-server/pr-2015/

🤖 Claude Code in T3 Code (claude-opus-5-5)

@Quick104
Quick104 marked this pull request as ready for review November 15, 2026 01:47
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T16:19:03.658071Z de5e131 New commits
🔒 Security Review ✅ Completed 2026-11-19T16:22:42.056144Z de5e131 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3bcce7fd70

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1954 to +1958
case audioCodecEAC3, audioCodecAC3:
if opts.TargetAudioChannels == surroundBitstreamChannelsV3 {
// The frozen audio_to_eac3 / audio_to_ac3 recipe the v3 planner
// promises: 48 kHz 5.1 at 640 kbps.
args = append(args, surroundBitstreamAudioArgsV3(codec)...)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fence the surround recipe at reconstruction boundaries

During a rolling upgrade or rollback, an older binary can reconstruct a newly created surround-conversion session using the existing recipe-card/token discriminator. RecipeCard.ToClaims does not distinguish this recipe, and transcodenode.spawnReconstruct rebuilds its encoder options without checking the plan's advertised transformations. The previous appendAudioArgs implementation accepts E-AC-3/AC-3 but ignores TargetAudioChannels and uses the legacy bitrate, so reconstruction silently stops honoring the promised 48 kHz, six-channel, 640 kbps output. Add a reconstruction discriminator or version fence that older binaries reject, as the existing downmix and copy-fMP4 recipes do, rather than relying only on capability validation at initial dispatch.

AGENTS.md reference: AGENTS.md:L18-L22

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The finding is accurate, and we're keeping the branch as it is. An older binary that rebuilds one of these sessions would keep encoding E-AC-3 with the legacy arguments, and on a 7.1 source that drops the LFE channel. The PR body discloses this.

That can only happen while old and new binaries serve the same cluster during an upgrade or rollback, and the result is degraded audio for the rest of that session, not a failed stream. A downmix-style fence would add a new play method that each remux check in the proxy, node control, and handlers has to accept. Missing one of those would break these sessions on the current binary, which is a worse failure than the one the fence prevents. Silo is pre-1.0 and ships server upgrades as one switchover, so we're not adding the fence.

🤖 Claude Code in T3 Code (claude-opus-5-5)

Main copies a replan's adaptation reasons onto a reused HLS transport's
recipe (#4315); the branch moved that block into reuseActiveHLSTransportV3,
so the copy moves with it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Quick104
Quick104 merged commit d203b9f into main Nov 19, 2026
18 of 20 checks passed
@Quick104
Quick104 deleted the fix/issue-2010-surround-bitstream-conversion branch November 19, 2026 17:12
Quick104 added a commit that referenced this pull request Nov 19, 2026
…spath (#4583)

probeSurroundBitstreamRecipeV3 (from #2015) runs FFmpeg only on a
generated lavfi anullsrc input and writes to pipe:1, so it never opens a
media input. Listing it with that reason lets
TestEveryMediaLaunchGoesThroughCommandContext pass on main again.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

[bug] Android TV sends stereo to a 5.1 receiver for TrueHD/DTS the sink can't bitstream

1 participant