Skip to content

fix(playback): stop claiming m2ts/mts direct play - #452

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/drop-m2ts-container-claim
Oct 5, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/drop-m2ts-container-claim

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #449
Validation tasks: none (no passed v1.0 case plays Blu-ray .m2ts files on Android)

Android claims it can directly play m2ts and mts, but Media3's TsExtractor only reads 188-byte transport-stream packets. Blu-ray and AVCHD .m2ts/.mts files use 192-byte BDAV packets, so no extractor recognises them: direct play fails with ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED, and playback only starts after a failure_recovery replan to an HLS remux. An offline download of such a file would fetch the raw .m2ts, which then can't play with no server to fall back to.

Today the server never catalogs .m2ts, so this is latent. Silo-Server/silo-server#1809 makes the scanner catalog them (recorded container m2ts), after which every .m2ts episode would hit this. This change should land before or with that PR.

Solution

Drop m2ts and mts from media3OriginalVideoContainers in PlaybackContainerPolicy.kt, with a comment explaining why and when to add them back (Media3 support for 192-byte packets plus a device test). That one list feeds the top-level client_capabilities.containers, original_http.containers and the download capabilities, so the server now remuxes these files from the start and downloads single titles and season episodes as a remux. A whole-series download at Original quality still fetches the original file, because the server does not check device capabilities for that batch; that needs a server-side fix. ts, mpegts and mpeg-ts stay. The m2ts/mts → video/mp2t MIME mapping in SiloPlayerFactory.kt stays as a correct hint for servers that still send the original file.

Validation

  • ./gradlew :android-shared:testDebugUnitTest :android-shared:lintDebug passes (1656 tests). PlaybackContainerPolicyTest gains a check that m2ts/mts are not claimed.
  • Emulator (Silo_Phone, API 36) against a local server built from silo-server main plus #1809, with a real BDAV .m2ts episode (H.264 + AC-3, 192-byte packets):
    • Before: startPlayback → direct GET /api/v2/stream/{id} → UnrecognizedInputFormatException / ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED in logcat → replanPlayback → HLS; about 2.6 s to a ready player.
    • After: startPlayback → HLS manifest directly (play_method=remux, output_container=fmp4, output_protocol=hls), no failed attempt or replan; about 1.2 s to a ready player.
    • Control: an MP4 episode still direct-plays on both builds.
  • Downloads: with downloads enabled on the local server, POST /api/v2/downloads for the same .m2ts file returned delivery_format: original with the old claimed containers and delivery_format: remux with the new ones. The in-app download flow was not exercised.

Risks

None identified. A .m2ts file now always goes through a server-side remux (a codec copy, no transcode) instead of a failed direct-play attempt. If a future Media3 release reads 192-byte packets, the containers can be claimed again after a device test.

Checklist

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

AI disclosure

  • Harness: Claude Code (running in T3 Code)
  • Tool(s): Claude Code (Bash, Read, Edit, sub-agents), Android emulator and adb, Gradle, GitHub CLI, Docker, FFmpeg
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: n/a; a two-line capability change, verified on an emulator before and after.

Note

Remove m2ts/mts from Media3 direct-play containers in PlaybackContainerPolicy

  • Media3's TsExtractor reads 188-byte TS packets, but m2ts/mts use 192-byte BDAV packets, so these formats were being misclassified as directly playable. They now fall back to server remux/adaptation.
  • Updates the direct-play policy in PlaybackContainerPolicy.kt and adds a test covering lowercase, uppercase, and padded m2ts/mts exclusion in PlaybackContainerPolicyTest.kt.
  • Documents the change in the compatibility fixture matrix, with a BDAV-specific validation row requiring server adaptation checks.
  • Behavioral Change: m2ts/mts files take the server remux path instead of direct playback.

Macroscope summarized 6f5913d.

@silo-kody

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

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 013fce72-e3ec-4c29-8219-a5b2d252eb65
📥 Commits

Reviewing files that changed from the base of the PR and between 52b5c59 and 6f5913d.

📒 Files selected for processing (2)
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/video/PlaybackContainerPolicy.kt
  • docs/playback/02-migration-compatibility-validation.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/video/PlaybackContainerPolicy.kt

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The Media3 original playback container list no longer includes m2ts or mts. The policy describes the packet-size distinction. Unit tests check normalized forms of both extensions, and migration validation expects server remux for BDAV files.

Changes

BDAV container playback policy

Layer / File(s) Summary
Update container policy and validate BDAV remux behavior
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/video/PlaybackContainerPolicy.kt, android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/video/PlaybackContainerPolicyTest.kt, docs/playback/02-migration-compatibility-validation.md
The Media3 original playback container list omits m2ts and mts. The policy comment describes Media3’s 188-byte packet handling and the 192-byte BDAV packets. Unit tests verify that normalized forms of both extensions are excluded. Migration validation expects server remux for M2TS/MTS while retaining the existing direct-play checks for MOV/QT and TS.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: quick104

Merge Risk: ⚪ Minimal · up to 6f591

M2TS/MTS are no longer advertised for original playback, while other listed TS formats remain eligible. The whole-series Original-quality download exception is documented. No concrete issue in the reviewed change warrants blocking merge; normal checks remain.

Architecture Summary

Architecture risk: 🔵 Low · up to 6f591

The change affects 2 systems.

Changed systems: android-shared, docs

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — android-shared (service) was modified; 2 changed files map to changed impact.
  • observed — docs (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/video/PlaybackContainerPolicyTest.kt: Imports assertFalse for the new exclusion assertions.
  • observed — Modified behavior in android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/video/PlaybackContainerPolicyTest.kt: Removes m2ts and mts from the list expected to belong to media3OriginalPlaybackContainers.
  • observed — Modified behavior in android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/player/video/PlaybackContainerPolicyTest.kt: Adds a test asserting normalized m2ts and mts values—including uppercase and whitespace-padded inputs—are excluded; its comment describes the 192-byte Blu-ray/AVCHD transport-stream distinction from Media3’s 188-byte packet handling.
  • observed — Modified behavior in android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/video/PlaybackContainerPolicy.kt: The container list removes m2ts and mts. The added comment describes the 192-byte BDAV versus 188-byte packet limitation, the resulting remuxing for playback and single-title or season downloads, and the Original-quality whole-series download exception.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely states the main change: stop claiming m2ts/mts direct-play support.
Description check ✅ Passed The description explains the playback issue, the container-policy change, its expected effects, and the reported validation.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Media3's TsExtractor reads only 188-byte transport-stream packets.
Blu-ray and AVCHD .m2ts/.mts files use 192-byte BDAV packets, so no
Media3 extractor recognizes them and direct play fails with
ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED before recovering through a
failure replan to an HLS remux.

Drop m2ts and mts from the advertised direct-play containers. The same
list feeds the top-level client capabilities, the original_http
delivery capability and the download capabilities, so the server now
remuxes these files from the start and a download no longer fetches
original bytes the player cannot open. ts, mpegts and mpeg-ts stay.

The video/mp2t MIME mapping for m2ts/mts in SiloPlayerFactory stays: it
is only a hint used when the server still serves original bytes (for
example an older server that ignores the capability list), it is the
correct MIME type for the format, and it does not change the outcome.

Related to Silo-Server#449
@Rhainland
Rhainland force-pushed the fix/drop-m2ts-container-claim branch from 442d24b to 52b5c59 Compare October 2, 2026 20:37
@silo-kody

silo-kody Bot commented Oct 2, 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 Quick104 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.

Superseded: this pass missed two findings. See the later review: #452 (review)

AI disclosure: written by Claude Code (claude-opus-5-5) via a /silo code-review pass.

@Quick104 Quick104 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.

The earlier "no issues" review on this PR was posted in error; these are the code review findings.

Code review found two issues. The fix itself is sound: the server records .m2ts and .mts as m2ts, matches containers by exact name, and on a replan drops the route that failed, so playback and single-title downloads now go through a remux as described.

  1. Series downloads still fetch the original BDAV bytes (inline comment). Needs your call on where to fix it.
  2. Low: the playback validation doc is out of date. docs/playback/02-migration-compatibility-validation.md line 213 still reads | MOV/QT and TS/M2TS | Test direct, seeking, tracks, subtitles, and recovery; do not force remux solely from the extension. |. After this change, every .m2ts/.mts file is remuxed because of its extension-derived m2ts label. Someone running the hardware gates would expect M2TS to direct play, report the remux as a regression, or add m2ts back. Suggested repair: split the row so TS stays direct play and M2TS/MTS (BDAV, 192-byte packets) is expected to use server adaptation.

Validation tasks: none, matching the PR body.

AI disclosure: reviewed by claude-opus-5-5 in Claude Code via T3 Code (/silo code-review).

* 192-byte BDAV packets, and Media3's `TsExtractor` reads only 188-byte
* transport-stream packets, so no extractor recognizes them and direct play
* fails with `ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED`. Leaving them out
* makes the server remux these files instead, which also keeps a download

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.

Medium, needs your call: Download series still fetches unplayable originals.

This comment says that leaving m2ts out stops a download from fetching original bytes. That holds for single titles and for season downloads (startSeason downloads one episode at a time). It does not hold for whole-series downloads.

  • Trigger: on phone, tap Download series on a show stored as Blu-ray .m2ts. DownloadEnqueuer.startSeries forces DownloadQuality.Original and sends a series batch.
  • Why: on the server, createSeriesScoped (internal/downloads/service.go) sets decision := originalDecision() and only looks at req.Caps when quality != QualityOriginal. Every episode is registered as a raw original, whatever containers the device claims. Single-item downloads go through DownloadQualityResolver.Resolve, which checks caps and picks a remux.
  • Impact: each episode downloads as raw BDAV. Offline playback opens it as direct video/mp2t, TsExtractor rejects the 192-byte packets, and with no server session there is no remux to fall back to.
  • Suggested repair: fix it on the server by having series batches at Original quality resolve each episode with the device caps, the same way Resolve does for one item. This comment can stay as written once that lands. Until then, narrow it to playback and single-item downloads. Series monitors at the default original quality may use the same path; I didn't check that.

I found this by tracing the code; I didn't reproduce it on a device.

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.

Narrowed the comment in 6f5913d: it now says the remux covers playback and single-title and season downloads, and that a whole-series download at Original quality still fetches the original bytes because the server skips the capability check for that batch. The server-side fix (resolve each episode in a series batch against the device caps) belongs in silo-server and is a separate change.

The container policy comment said dropping m2ts/mts keeps every download
from fetching the original bytes. Whole-series downloads at Original
quality still do, because the server does not check device capabilities
for that batch. Say so, and split the M2TS row in the playback validation
gates so M2TS/MTS is expected to use server adaptation rather than direct
play.
@Rhainland

Copy link
Copy Markdown
Contributor Author

Split the stale MOV/QT and TS/M2TS row in docs/playback/02-migration-compatibility-validation.md in 6f5913d: TS keeps the direct-play expectation, and M2TS/MTS (BDAV, 192-byte packets) is now expected to use server adaptation.

@silo-kody

silo-kody Bot commented Oct 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 ❌
⚠️ 1 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Validate download ownership before publishing subtitle bytes

@Quick104
Quick104 merged commit b0e3fc3 into Silo-Server:main Oct 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants