Skip to content

feat(playback): package copy remuxes as MPEG-TS on request - #3026

Merged
Quick104 merged 4 commits into
mainfrom
feat/roku-ts-copy-remux
Oct 25, 2026
Merged

Quick104 merged 4 commits into
mainfrom
feat/roku-ts-copy-remux

Conversation

@Quick104

@Quick104 Quick104 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none

Roku's player plays the audio of some fragmented MP4 copy remuxes silently, but plays the same remux when it is packaged as MPEG-TS. Protocol v3 always packages a video-copy HLS remux (server_remux_hls) as fMP4, so the Roku client has no way to ask for MPEG-TS. This change adds an opt-in hls delivery feature, hls_copy_mpegts_v1. A client that sends it gets its H.264 and HEVC copy remuxes as MPEG-TS segments. Other clients see no change.

The executor already supports MPEG-TS copy packaging (TranscodeOpts.CopyVideoMPEGTS) for jellycompat; protocol v3 could not request it.

Approach

  • hls_copy_mpegts_v1 is advertised on /api/v2 only (NativeServerFeaturesV3). The client sends it in client_playback_context.deliveries.hls.features, not client_features. /api/v1 drops it on start and replan.
  • With the feature, a server_remux_hls plan that copies H.264 or HEVC carries effective_recipe.segment_container: "mpegts" and no video_sample_entry. Its video claims and dynamic range are unchanged. HLS carries only those two codecs in MPEG-TS, so a copy of any other codec, such as VP9 or AV1, keeps fMP4. Encoded video (server_transcode_hls) keeps its packaging too.
  • The container is part of the plan ID and attempt key, so an MPEG-TS plan never shares an output directory or attempted-plan key with the fMP4 plan for the same source. Plans without it keep their existing IDs. The frozen executable recipe records copy_video_mpegts at recipe version 5, and a recipe validates only for a plan with the same container. A seek reanchor treats a container change as an identity change.
  • Local and remote transports both set CopyVideoMPEGTS. A transcode node now echoes copy_video_mpegts in its start response. On a start, a missing echo stops the transport and returns a retryable transcode_start_failed. Moving the transport off an unreachable node refuses a candidate node without the echo in the same way. Recipe cards carry the flag, so reconstruction and moves keep the packaging, and the session's stream state reports mpegts as its output container.
  • .ts is pinned to video/mp2t in Go's MIME table. The server image's shared-mime-info database lists .ts as text/vnd.trolltech.linguist before video/mp2t. As a result, this also changes the Content-Type of segments that were already MPEG-TS, namely H.264 HLS transcodes on both the native API and jellycompat, from text/vnd.trolltech.linguist; charset=utf-8 to video/mp2t.
  • Contract artifacts are regenerated: the /api/v2 OpenAPI document, web/src/api/v2/schema.ts, the playback v3 decision-response schema and fixtures. docs/architecture/playback-protocol-v3.md and docs/transcode-node-api.md describe the feature.

Surfaces: the Roku client (silo-roku) is the intended caller. silo-apple and silo-android don't send the feature, so their plans and plan IDs are unchanged and they need no follow-up. jellycompat keeps its own MPEG-TS selection and needs no parity change.

Design decisions a reviewer should weigh:

  • Rolling upgrades. A transcode node from before this change can already produce MPEG-TS but doesn't echo copy_video_mpegts. Until it is upgraded, the API refuses it for MPEG-TS starts and moves. An API server from before this change refuses a version-5 frozen recipe instead of reopening the transport as fMP4.
  • Dolby Vision. A Dolby Vision Profile 7 source that the plan strips to HDR10 is also packaged as MPEG-TS when the client asks. A preserved Profile 5 or 8 copy keeps FFmpeg's -strict unofficial, under which the MPEG-TS muxer writes the DOVI video stream descriptor.
  • Not pinned per attempt. The feature is not in AttemptStickyFeaturesV3. Each start or replan reads it from that request's hls delivery. A replan that drops it gets a separate fMP4 plan with its own plan ID, and never a reused MPEG-TS transport.

Validation

  • Go: make embed-stub, go build ./..., gofmt -l . (clean), go vet ./..., make lint-changed (0 issues), make lint-router-recovery (0 issues), and make test-go all pass.
  • Web: pnpm install --frozen-lockfile, pnpm run lint (0 errors), pnpm run format:check, pnpm run build, pnpm run budget:check, and make test-web all pass.
  • Contracts and hygiene: the settings-bindings, playback-fixtures, route-inventory, migration-ledger, scenario-catalog, offline-route, apiv2 openapi/contract/fixtures, local-paths, case-collisions, size-ratchet, bidi, migrations, v1-route-freeze, and prometheus-rules targets all pass, as does TestCommittedArtifactMatchesRouter.
  • actionlint 1.7.12 passes when run directly. The make verify-actionlint guard rejected the v1.7.12 version string that a go install build prints. make verify-shellcheck was not run: the local ShellCheck is 0.9.0 and the target requires 0.11.0. This branch changes no workflow or shell files.
  • The tests cover these behaviors:
    • Planning: MPEG-TS and fMP4 plans get separate identities, for both Dolby Vision 8.1 and SDR HEVC copies. A VP9 copy and encoded video keep their packaging.
    • Frozen recipe: version 5, valid only for a matching plan.
    • /api/v2 start: runs an MPEG-TS transport, and a seek reanchor keeps it.
    • /api/v1: ignores the feature.
    • Transcode node: the start-response echo, the API-side check of that echo, a fresh remote start that refuses and stops a node without it, and a move that refuses such a node.
    • Dolby Vision in MPEG-TS: the FFmpeg arguments keep -strict unofficial.
    • Segments: .ts is served as video/mp2t.
  • The tests don't cover playback on Roku hardware or a mixed-version rollout.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/roku-ts-copy-remux/

Risks

  • During a rolling upgrade, the API refuses transcode nodes that have not been upgraded yet for MPEG-TS copy starts, with a retryable error, and for moves. Only clients that send the feature are affected.
  • The .ts MIME pin changes the Content-Type header on existing H.264 HLS transcode segments for every client, including web and jellycompat clients. The new value is correct; a client that relied on the old header would notice.
  • Existing clients get the same plan IDs and recipe versions as before, because the identity and version change only when the feature is present.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated; the maintainer requested it and has not yet reviewed the code
  • Adversarial review: a separate Claude Code agent (claude-opus-5-5) reviewed the full diff read-only. Findings: moving a transport to a node without the MPEG-TS echo was not refused (fixed, with a test); the session stream state reported fmp4 for MPEG-TS sessions (fixed); a VP9 or AV1 copy could be packaged as MPEG-TS (now limited to H.264 and HEVC, with a test). No other issues found.

🤖 Generated with Claude Code

Note

Add MPEG-TS packaging for HLS copy-remux playback on request

Clients that advertise the HLS copy-MPEG-TS delivery feature now get copied H.264/HEVC video packaged as MPEG-TS segments instead of fragmented MP4. The planner selects the container in PlanPlaybackV3 (plan_v3.go), and the choice is persisted through executable recipe version 5 and the effective recipe's new segment-container field (executable_recipe_v3.go, protocol_v3.go).

  • Transcode nodes attest MPEG-TS copy packaging in the start response, and the playback handler rejects and stops nodes that do not confirm it; this check also applies to rehomed transports (server.go, playback_transcode_rehome.go).
  • The frozen v1 request surface strips the v2-only feature on start and replan, so v1 clients never select MPEG-TS packaging (playback_v3.go).
  • Plan IDs and attempt keys now include the normalized segment container, so MPEG-TS and fMP4 variants of the same plan cannot share state (plan_key_v3.go).
  • Risk: recipes with the MPEG-TS flag are rejected below version 5 and on non-copy or non-HLS targets — check ExecutableRecipeV3.Valid; older persisted recipes without the field keep their previous identity and versions.

Macroscope summarized 1cd341b.

Add the hls delivery feature hls_copy_mpegts_v1, advertised on /api/v2
only. A client that lists it in client_playback_context.deliveries.hls
.features gets its server_remux_hls plans that copy H.264 or HEVC
packaged as MPEG-TS instead of fragmented MP4; other copied codecs keep
fMP4. Roku's player plays the audio of some muxed fMP4 copies silently
but plays the same remux in MPEG-TS.

The plan carries effective_recipe.segment_container "mpegts" and no
video_sample_entry. The container is part of the plan id and attempt
key, and the frozen executable recipe records it at version 5. Remote
transcode nodes echo copy_video_mpegts in the start response; a start
or a move to another node refuses a node without it. .ts segments are
served as video/mp2t. /api/v1 ignores the feature.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Oct 25, 2026
@silo-kody

silo-kody Bot commented Oct 25, 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 ❌

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T02:48:01.907185Z 1cd341b New commits
🔒 Security Review ✅ Completed 2026-10-25T02:49:27.545052Z 1cd341b 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.

@silo-triage silo-triage Bot added enhancement New feature or request go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish labels Oct 25, 2026
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

The /api/v2 playback protocol adds negotiated MPEG-TS packaging for eligible H.264 and HEVC HLS copy-remux plans. The change records the container in plan identity and executable recipes, configures transcode starts, and validates node attestation. The frozen /api/v1 surface retains default packaging.

Changes: HLS MPEG-TS copy packaging

Layer / File(s) Summary
Feature contract and plan selection
contracts/api/v2/openapi.json, internal/playback/protocol_v3.go, internal/playback/plan_v3.go, internal/playback/protocol_v3_test.go, internal/playback/testdata/protocol_v3/*, docs/architecture/playback-protocol-v3.md, docs/design/schemas/playback-v3/v3/*, web/src/api/v2/schema.ts
The protocol and schemas describe the negotiated hls_copy_mpegts_v1 feature and optional segment_container. Eligible H.264 and HEVC HLS copy-remux plans select MPEG-TS without an fMP4 video sample entry. Tests and fixtures cover feature negotiation and plan behavior.
Frozen recipe and plan identity
internal/playback/executable_recipe_v3.go, internal/playback/plan_key_v3.go
Executable recipes record MPEG-TS copy packaging at recipe version 5 and validate the choice against the plan. Plan IDs and attempt keys include the normalized segment container.
Transcode packaging and attestation
internal/api/handlers/playback_v3.go, internal/api/handlers/playback_v3_test.go, internal/api/handlers/playback_transcode_rehome.go, internal/api/handlers/playback_transcode_rehome_test.go, internal/transcodenode/server.go, internal/transcodenode/server_test.go, internal/playback/transcode.go, internal/playback/transcode_args_test.go, docs/transcode-node-api.md, docs/architecture/playback-protocol-v3.md
Playback handlers pass the packaging choice to transcodes and preserve it across seek reanchoring and rehoming. Nodes report the choice, and handlers reject starts without matching attestation. Tests cover MPEG-TS output, MIME type, Dolby Vision handling, /api/v1 defaults, and rehoming validation.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant PlaybackV3
  participant transcodenode.handleStart
  participant ValidateCopyVideoMPEGTSAttestation
  PlaybackV3->>transcodenode.handleStart: start request with CopyVideoMPEGTS
  transcodenode.handleStart-->>PlaybackV3: start response with packaging attestation
  PlaybackV3->>ValidateCopyVideoMPEGTSAttestation: validate request and response
  ValidateCopyVideoMPEGTSAttestation-->>PlaybackV3: validation result
Loading

Possibly related issues

Possibly related PRs

  • Silo-Server/silo-server#2987 — Adds MPEG-TS packaging for eligible HLS video-copy streams through a Roku-specific API surface.
  • Silo-Server/silo-server#2350 — Rebuilds transcodes after executor moves; this change preserves the MPEG-TS packaging choice in recipes and validates it during starts and rehoming.

Suggested reviewers: rhainland

Merge Risk: Low · up to 6695b

The feature is mergeable with awareness that a fresh remote-node refusal is not covered by an integration test. Add that test to protect against accepting a node that does not confirm MPEG-TS packaging.

Security architecture risk: Low · up to 6695b

The opt-in behavior preserves existing access checks and rejects incompatible output before accepting it. Remaining uncertainty concerns mixed-version operation and failure recovery that have not been fully validated.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Within the inspected flow, the new client-controlled effect is bounded to packaging eligible playback plans and their associated execution work. The evidence does not establish a new mechanism for selecting another profile's session or gaining additional media authority.

Trust Boundaries and Controls

  • observed — The node remains a trusted executor: its response reports the active session option rather than independently proving segment contents. The API checks that response before accepting the prepared transport or committing a rehome route.

Resilience and Maintainability Implications

  • observed — Failed rehome attestation follows the existing speculative-start rollback path before route commit. Cleanup uses non-fencing release, stored recipes are restored when required, and route compare-and-swap rejects stale replacement ownership.
Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 58.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 36 functions across 13 files. (9 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title "feat(playback): package copy remuxes as MPEG-TS on request" names the main change: an opt-in path that packages H.264/HEVC copy remuxes as MPEG-TS when a client asks. The changeset implemen…
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.
Description check Passed The description is specific and on-topic. It explains the Roku MPEG-TS copy-remux problem, the opt-in hls_copy_mpegts_v1 feature, the /api/v1 vs /api/v2 split, plan identity and recipe versioning, tra…
Full details: Title check

Explanation

The title "feat(playback): package copy remuxes as MPEG-TS on request" names the main change: an opt-in path that packages H.264/HEVC copy remuxes as MPEG-TS when a client asks. The changeset implements this across the playback planner, recipes, transcode node attestation, and contracts. The title is specific and concise, and it omits only secondary items such as the .ts MIME pin.

Full details: Description check

Explanation

The description is specific and on-topic. It explains the Roku MPEG-TS copy-remux problem, the opt-in hls_copy_mpegts_v1 feature, the /api/v1 vs /api/v2 split, plan identity and recipe versioning, transcode-node attestation, the .ts MIME pin, regenerated contract artifacts, validation results, and risks. It matches the changeset in the raw summary and the PR objectives.

Full details: Docstring Coverage

Explanation

Docstring coverage is 58.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 36 functions across 13 files. (9 skipped: 8 unsupported, 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Comment thread internal/playback/plan_v3.go Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments: 1
internal/api/handlers/playback_v3_test.go: 1

2481-2542: Trivial · Maintainability & Code Quality · Quick win

Add fresh-remote MPEG-TS refusal coverage.

No existing test combines a fresh remote start, CopyVideoMPEGTS: true, and a missing copy_video_mpegts attestation. The stale-node test exercises the caller path but requests MPEG-TS false. The attestation test exercises only the validator, and the MPEG-TS refusal test covers rehome. Add a fresh-start test that asserts refusal and remote cleanup, or at least that no successful transport is returned.


Review info
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: e4792f3d-63b1-4bb9-9f98-c14cc06cb532
Commits

Reviewing files that changed from the base of the PR and between d2c12db and 6695b46.

Files selected for processing: 22
  • contracts/api/v2/openapi.json
  • docs/architecture/playback-protocol-v3.md
  • docs/design/schemas/playback-v3/v3/decision-response.schema.json
  • docs/design/schemas/playback-v3/v3/fixtures/valid/hls-subtitle-rendition-decision_response.json
  • docs/design/schemas/playback-v3/v3/fixtures/valid/learned-limit-decision_response.json
  • docs/transcode-node-api.md
  • internal/api/handlers/playback_transcode_rehome.go
  • internal/api/handlers/playback_transcode_rehome_test.go
  • internal/api/handlers/playback_v3.go
  • internal/api/handlers/playback_v3_test.go
  • internal/playback/executable_recipe_v3.go
  • internal/playback/plan_key_v3.go
  • internal/playback/plan_v3.go
  • internal/playback/protocol_v3.go
  • internal/playback/protocol_v3_test.go
  • internal/playback/testdata/protocol_v3/hls-subtitle-rendition-decision_response.json
  • internal/playback/testdata/protocol_v3/learned-limit-decision_response.json
  • internal/playback/transcode.go
  • internal/playback/transcode_args_test.go
  • internal/transcodenode/server.go
  • internal/transcodenode/server_test.go
  • web/src/api/v2/schema.ts

Included review availability: This review used your included allowance. 3 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 8 reviews per hour.

@silo-triage silo-triage Bot added size/XL 500–999 added + deleted lines (all files); change volume, not priority. and removed size/L 200–499 added + deleted lines (all files); change volume, not priority. labels Oct 25, 2026
@silo-kody

silo-kody Bot commented Oct 25, 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 ❌

@Quick104

Copy link
Copy Markdown
Contributor Author

Added a test for CodeRabbit's "fresh-remote MPEG-TS refusal coverage" nitpick in 10f7198. TestPrepareRemoteTransportV3RefusesUnattestedMPEGTSCopy (internal/api/handlers/playback_v3_test.go) runs a fresh worker-only remote start of an MPEG-TS copy remux. It asserts that the node is asked for copy_video_mpegts and that a node attesting it succeeds. A node that omits the attestation is refused with transcode_start_failed, the cause is ErrCopyVideoMPEGTSAttestationMismatch, and the job gets exactly one stop request. The refusal case fails when the start-path validation is disabled.

Quick104 and others added 2 commits October 25, 2026 02:45
# Conflicts:
#	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/learned-limit-decision_response.json
#	internal/api/handlers/playback_v3.go
#	internal/playback/protocol_v3.go
#	internal/playback/testdata/protocol_v3/hls-subtitle-rendition-decision_response.json
#	internal/playback/testdata/protocol_v3/learned-limit-decision_response.json

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A client that sends hls_copy_mpegts_v1 and hls_remux_subtitle_renditions_v1
gets both on one plan. The test pins the TS segment container, the
rendition, the version-5 frozen recipe carrying both flags, the MPEG-TS
cue offset, and a plan identity distinct from the fMP4 rendition plan.

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

silo-kody Bot commented Oct 25, 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 ❌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish size/XL 500–999 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant