Files
jellytau/specs/read-through-media-cache.html
T

443 lines
33 KiB
HTML

<!DOCTYPE HTML>
<html lang="en" class="navy" dir="ltr">
<head>
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
<title>Read-Through Media Cache - JellyTau Documentation</title>
<!-- Custom HTML head -->
<meta name="description" content="Requirements, traceability, and architecture for the JellyTau Jellyfin client.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#ffffff">
<link rel="icon" href="../favicon.svg">
<link rel="shortcut icon" href="../favicon.png">
<link rel="stylesheet" href="../css/variables.css">
<link rel="stylesheet" href="../css/general.css">
<link rel="stylesheet" href="../css/chrome.css">
<link rel="stylesheet" href="../css/print.css" media="print">
<!-- Fonts -->
<link rel="stylesheet" href="../FontAwesome/css/font-awesome.css">
<link rel="stylesheet" href="../fonts/fonts.css">
<!-- Highlight.js Stylesheets -->
<link rel="stylesheet" href="../highlight.css">
<link rel="stylesheet" href="../tomorrow-night.css">
<link rel="stylesheet" href="../ayu-highlight.css">
<!-- Custom theme stylesheets -->
</head>
<body class="sidebar-visible no-js">
<div id="body-container">
<!-- Provide site root to javascript -->
<script>
var path_to_root = "../";
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "navy";
</script>
<!-- Work around some values being stored in localStorage wrapped in quotes -->
<script>
try {
var theme = localStorage.getItem('mdbook-theme');
var sidebar = localStorage.getItem('mdbook-sidebar');
if (theme.startsWith('"') && theme.endsWith('"')) {
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
}
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
}
} catch (e) { }
</script>
<!-- Set the theme before any content is loaded, prevents flash -->
<script>
var theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
var html = document.querySelector('html');
html.classList.remove('navy')
html.classList.add(theme);
var body = document.querySelector('body');
body.classList.remove('no-js')
body.classList.add('js');
</script>
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
<!-- Hide / unhide sidebar before it is displayed -->
<script>
var body = document.querySelector('body');
var sidebar = null;
var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
} else {
sidebar = 'hidden';
}
sidebar_toggle.checked = sidebar === 'visible';
body.classList.remove('sidebar-visible');
body.classList.add("sidebar-" + sidebar);
</script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<div class="sidebar-scrollbox">
<ol class="chapter"><li class="chapter-item expanded affix "><a href="../index.html">Introduction</a></li><li class="chapter-item expanded affix "><li class="part-title">Requirements & Traceability</li><li class="chapter-item expanded "><a href="../requirements.html"><strong aria-hidden="true">1.</strong> Requirements Specification</a></li><li class="chapter-item expanded "><a href="../traceability.html"><strong aria-hidden="true">2.</strong> Traceability Matrix</a></li><li class="chapter-item expanded "><a href="../traceability-ci.html"><strong aria-hidden="true">3.</strong> Traceability CI</a></li><li class="chapter-item expanded "><a href="../traces-quick-ref.html"><strong aria-hidden="true">4.</strong> Traces Quick Reference</a></li><li class="chapter-item expanded affix "><li class="part-title">Architecture</li><li class="chapter-item expanded "><a href="../architecture/index.html"><strong aria-hidden="true">5.</strong> Overview</a><a class="toggle"><div></div></a></li><li><ol class="section"><li class="chapter-item "><a href="../architecture/01-rust-backend.html"><strong aria-hidden="true">5.1.</strong> Rust Backend</a></li><li class="chapter-item "><a href="../architecture/02-svelte-frontend.html"><strong aria-hidden="true">5.2.</strong> Svelte Frontend</a></li><li class="chapter-item "><a href="../architecture/03-data-flow.html"><strong aria-hidden="true">5.3.</strong> Data Flow</a></li><li class="chapter-item "><a href="../architecture/04-type-sync-and-threading.html"><strong aria-hidden="true">5.4.</strong> Type Sync & Threading</a></li><li class="chapter-item "><a href="../architecture/05-platform-backends.html"><strong aria-hidden="true">5.5.</strong> Platform Backends</a></li><li class="chapter-item "><a href="../architecture/06-downloads-and-offline.html"><strong aria-hidden="true">5.6.</strong> Downloads & Offline</a></li><li class="chapter-item "><a href="../architecture/07-connectivity.html"><strong aria-hidden="true">5.7.</strong> Connectivity</a></li><li class="chapter-item "><a href="../architecture/08-database-design.html"><strong aria-hidden="true">5.8.</strong> Database Design</a></li><li class="chapter-item "><a href="../architecture/09-security.html"><strong aria-hidden="true">5.9.</strong> Security</a></li></ol></li><li class="chapter-item expanded "><li class="part-title">UX</li><li class="chapter-item expanded "><a href="../ux-flows.html"><strong aria-hidden="true">6.</strong> UX Flows</a></li><li class="chapter-item expanded affix "><li class="part-title">Specs — Pending Work</li><li class="chapter-item expanded "><a href="../specs/index.html"><strong aria-hidden="true">7.</strong> Specs Index</a></li><li class="chapter-item expanded "><a href="../specs/SPEC-TEMPLATE.html"><strong aria-hidden="true">8.</strong> Spec Template</a></li><li class="chapter-item expanded "><a href="../specs/SPEC-REVIEW-CHECKLIST.html"><strong aria-hidden="true">9.</strong> Spec Review Checklist</a></li><li class="chapter-item expanded "><a href="../specs/playback-backend-unification.html"><strong aria-hidden="true">10.</strong> Playback Backend Unification</a></li><li class="chapter-item expanded "><a href="../specs/linux-native-video-spike.html"><strong aria-hidden="true">11.</strong> Linux Native Video Spike</a></li><li class="chapter-item expanded "><a href="../specs/backend-owned-stream-selection.html"><strong aria-hidden="true">12.</strong> Backend-Owned Stream Selection</a></li><li class="chapter-item expanded "><a href="../specs/player-facade-enforcement.html"><strong aria-hidden="true">13.</strong> Player Facade Enforcement</a></li><li class="chapter-item expanded "><a href="../specs/windows-native-audio-backend.html"><strong aria-hidden="true">14.</strong> Windows Native Audio Backend</a></li><li class="chapter-item expanded "><a href="../specs/libmpv2-migration.html"><strong aria-hidden="true">15.</strong> libmpv2 Migration</a></li><li class="chapter-item expanded "><a href="../specs/read-through-media-cache.html" class="active"><strong aria-hidden="true">16.</strong> Read-Through Media Cache</a></li><li class="chapter-item expanded "><a href="../specs/scoped-search.html"><strong aria-hidden="true">17.</strong> Scoped Search</a></li><li class="chapter-item expanded "><a href="../specs/scoped-search-boundary.html"><strong aria-hidden="true">18.</strong> Scoped Search Boundary</a></li><li class="chapter-item expanded "><a href="../specs/scoped-search-boundary-implementation.html"><strong aria-hidden="true">19.</strong> Scoped Search Boundary — Implementation</a></li><li class="chapter-item expanded "><a href="../specs/frontend-domain-model.html"><strong aria-hidden="true">20.</strong> Frontend Domain Model</a></li><li class="chapter-item expanded "><a href="../specs/build-provenance.html"><strong aria-hidden="true">21.</strong> Build Provenance</a></li><li class="chapter-item expanded affix "><li class="part-title">Build & Release</li><li class="chapter-item expanded "><a href="../build/build-release.html"><strong aria-hidden="true">22.</strong> Build & Release</a></li><li class="chapter-item expanded "><a href="../release-checklist.html"><strong aria-hidden="true">23.</strong> Release Checklist</a></li><li class="chapter-item expanded "><a href="../build/build-desktop-packages.html"><strong aria-hidden="true">24.</strong> Desktop Packaging</a></li><li class="chapter-item expanded "><a href="../build/build-windows.html"><strong aria-hidden="true">25.</strong> Windows Build</a></li><li class="chapter-item expanded "><a href="../defect-windows.html"><strong aria-hidden="true">26.</strong> Defect Windows</a></li><li class="chapter-item expanded "><a href="../build/docker.html"><strong aria-hidden="true">27.</strong> Docker</a></li><li class="chapter-item expanded "><a href="../build/build-builder-image.html"><strong aria-hidden="true">28.</strong> Builder Image</a></li><li class="chapter-item expanded affix "><li class="spacer"></li><li class="chapter-item expanded affix "><a href="../api-redirect.html">Rust API Reference (rustdoc)</a></li></ol>
</div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
</div>
</nav>
<!-- Track and set sidebar scroll position -->
<script>
var sidebarScrollbox = document.querySelector('#sidebar .sidebar-scrollbox');
sidebarScrollbox.addEventListener('click', function(e) {
if (e.target.tagName === 'A') {
sessionStorage.setItem('sidebar-scroll', sidebarScrollbox.scrollTop);
}
}, { passive: true });
var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll');
sessionStorage.removeItem('sidebar-scroll');
if (sidebarScrollTop) {
// preserve sidebar scroll position when navigating via links within sidebar
sidebarScrollbox.scrollTop = sidebarScrollTop;
} else {
// scroll sidebar to current active section when navigating via "next/previous chapter" buttons
var activeSection = document.querySelector('#sidebar .active');
if (activeSection) {
activeSection.scrollIntoView({ block: 'center' });
}
}
</script>
<div id="page-wrapper" class="page-wrapper">
<div class="page">
<div id="menu-bar-hover-placeholder"></div>
<div id="menu-bar" class="menu-bar sticky">
<div class="left-buttons">
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
<i class="fa fa-bars"></i>
</label>
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
<i class="fa fa-paint-brush"></i>
</button>
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
</ul>
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
<i class="fa fa-search"></i>
</button>
</div>
<h1 class="menu-title">JellyTau Documentation</h1>
<div class="right-buttons">
<a href="../print.html" title="Print this book" aria-label="Print this book">
<i id="print-button" class="fa fa-print"></i>
</a>
<a href="https://gitea.tourolle.paris/dtourolle/jellytau" title="Git repository" aria-label="Git repository">
<i id="git-repository-button" class="fa fa-github"></i>
</a>
<a href="https://gitea.tourolle.paris/dtourolle/jellytau/_edit/master/docs/../docs/specs/read-through-media-cache.md" title="Suggest an edit" aria-label="Suggest an edit">
<i id="git-edit-button" class="fa fa-edit"></i>
</a>
</div>
</div>
<div id="search-wrapper" class="hidden">
<form id="searchbar-outer" class="searchbar-outer">
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
</form>
<div id="searchresults-outer" class="searchresults-outer hidden">
<div id="searchresults-header" class="searchresults-header"></div>
<ul id="searchresults">
</ul>
</div>
</div>
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
<script>
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
});
</script>
<div id="content" class="content">
<main>
<h1 id="spec-two-path-media--selectable-playback-bitrate-independent-whole-file-download"><a class="header" href="#spec-two-path-media--selectable-playback-bitrate-independent-whole-file-download">Spec: Two-path media — selectable playback bitrate, independent whole-file download</a></h1>
<p><strong>Status:</strong> Partially implemented. Landed: the cache/download unification
(DR-126, DR-127 — a cache entry <em>is</em> a <code>downloads</code> row with a shorter life, and
eviction only reclaims the temporary tier), local playback of downloaded media
(DR-128), and the one-path/one-row invariants that followed (DR-133 … DR-138).
DR-123 is in progress. Still open: the <strong>player quality selector</strong> and the
read-through capture itself — DR-121, DR-122, DR-124, DR-125. The separate
settings-level bitrate cap (DR-162, shipped —
<a href="../architecture/01-rust-backend.html#streaming-quality-ladder">01-rust-backend.md</a>)
covers a <em>settings-level</em>
ceiling (DR-162), which serves part of UR-070 but is not the per-playback
selector specified here.
<strong>Requirements:</strong> UR-070, UR-071 → DR-121, DR-122, DR-123, DR-124, DR-125; IR-032
<strong>UX spec:</strong> player quality selector — needs a <code>ux-flows.md</code> section before build
<strong>Related:</strong> the locally-indexed search and downloaded-browse work, both
shipped — see
<a href="../architecture/03-data-flow.html">03-data-flow.md</a> and
<a href="../architecture/06-downloads-and-offline.html">06-downloads-and-offline.md</a></p>
<h2 id="summary"><a class="header" href="#summary">Summary</a></h2>
<p>Two things that are today tangled become explicitly separate:</p>
<ul>
<li><strong>The playback path</strong> streams at a bitrate the viewer can change from the
player. It is ephemeral and its rendition is volatile.</li>
<li><strong>The download path</strong> fetches the whole file at one canonical quality, in the
background, independently of whatever playback is doing.</li>
</ul>
<p>Bytes fetched for playback are kept <strong>only</strong> when the playback rendition happens
to be the same artifact the download path would produce — i.e. direct play.
Otherwise playback bytes are discarded and the download path does its own fetch.</p>
<h2 id="motivation"><a class="header" href="#motivation">Motivation</a></h2>
<p>The appealing version of this — "stream and download at once, switch when enough
has arrived" — breaks the moment the viewer can change bitrate. A capture taken
while the rendition changes underneath it is a splice of two encodings: not a
playable file, and not something that can be honestly recorded as a download.
Once bitrate is selectable, one stream cannot serve both jobs.</p>
<p>Separating the paths also removes the thing that made the original idea
expensive: there is no mid-playback source swap to engineer, because the download
never has to take over the live session. It lands on disk and is used at the next
natural boundary — next episode, or next time the item is played.</p>
<p>What exists already and is <em>not</em> this: <code>SmartCache</code> predictively downloads <em>other</em>
items, <code>player_preload_upcoming</code> warms the next one, and
<code>refresh_queue_local_sources</code> swaps queue entries to local at boundaries. All of
it concerns items you are not currently playing.</p>
<h2 id="layer-assignment"><a class="header" href="#layer-assignment">Layer assignment</a></h2>
<div class="table-wrapper"><table><thead><tr><th>Logic / responsibility</th><th>Layer</th><th>Why it belongs there</th></tr></thead><tbody>
<tr><td>Available bitrate options for an item</td><td><strong>Rust</strong></td><td>Derived from Jellyfin's media sources and playback-info negotiation; changes with the API.</td></tr>
<tr><td>Mapping a chosen bitrate to transcode parameters</td><td><strong>Rust</strong></td><td>Domain vocabulary. <code>get_video_download_url</code> already owns the quality→params mapping; playback must reuse it, not restate it.</td></tr>
<tr><td>Deciding whether playback bytes are keepable (direct play vs transcode)</td><td><strong>Rust</strong></td><td>Depends on the negotiated session.</td></tr>
<tr><td>Canonical download quality</td><td><strong>Rust</strong></td><td>Policy over domain data.</td></tr>
<tr><td>Cache eviction, storage budget, sparse-range bookkeeping</td><td><strong>Rust</strong></td><td>Storage policy.</td></tr>
<tr><td>Promotion to a <code>downloads</code> row, and what invalidates a cache entry</td><td><strong>Rust</strong></td><td>Domain state.</td></tr>
<tr><td>Rendering the quality selector; remembering the last choice</td><td><strong>Frontend</strong></td><td>Presentation and a view preference. The <em>list</em> comes from Rust.</td></tr>
<tr><td>WiFi-only / opt-in toggles</td><td><strong>Frontend collects, Rust enforces</strong></td><td>The control is UI; the gate must hold even if the UI never calls.</td></tr>
</tbody></table>
</div>
<p>Borderline, recorded: the <strong>default</strong> playback bitrate could look like a user
preference (frontend). It goes to Rust because it must be reconcilable with what
the server can actually produce for a given media source — a preference the
backend has to validate is not a preference the frontend can own alone. The
frontend stores the user's <em>choice</em>; Rust decides what that choice resolves to.</p>
<h2 id="design"><a class="header" href="#design">Design</a></h2>
<h3 id="dr-121--bitrate-selection-in-the-player"><a class="header" href="#dr-121--bitrate-selection-in-the-player">DR-121 — Bitrate selection in the player</a></h3>
<p>The player exposes the qualities Rust reports for the current item. Changing it
re-negotiates the stream URL at the new quality and resumes at the current
position. This is a deliberate, user-initiated interruption — a brief rebuffer is
expected and acceptable, unlike the involuntary swap the earlier design would
have needed.</p>
<p>Constraints that must not be broken:</p>
<ul>
<li>On Linux, video playback must keep using the HLS <code>master.m3u8</code> URL. CLAUDE.md
records that returning <code>stream.mp4</code> means transcoded playback never starts.
A quality change re-negotiates <em>within</em> HLS.</li>
<li>The quality→transcode-parameter mapping already exists in
<code>get_video_download_url</code> (<a href="../../src-tauri/src/repository/online.rs#L1702-L1717">online.rs:1702-1717</a>).
Playback must call into the same mapping. Two copies of that table will drift.</li>
<li>Track selection (audio/subtitle) already survives a stream re-negotiation
elsewhere in the player; a quality change must preserve it too.</li>
</ul>
<h3 id="dr-122--the-playback-path-is-ephemeral"><a class="header" href="#dr-122--the-playback-path-is-ephemeral">DR-122 — The playback path is ephemeral</a></h3>
<p>Playback bytes are not persisted unless DR-124 says they are keepable. No partial
capture is ever retained across a quality change: on change, any in-flight capture
for that session is abandoned and its partial file deleted.</p>
<h3 id="dr-123--the-download-path-is-independent"><a class="header" href="#dr-123--the-download-path-is-independent">DR-123 — The download path is independent</a></h3>
<p>Downloading the whole file is a separate operation through the existing download
manager, at one canonical quality (default <code>original</code>, the direct static copy),
using <code>/Videos/{id}/stream.mp4</code> — progressive and Range-capable, which is what
the resumable download worker relies on. It is unaffected by what playback is
doing, and playback is unaffected by it.</p>
<p>Once complete it becomes an ordinary download row, so everything already built on
top of downloads — offline browsing, <code>refresh_queue_local_sources</code>, the Downloads
page — picks it up with no further work.</p>
<p><strong>Prerequisite:</strong> downloaded <em>video</em> is currently never played locally.
<code>repository_get_video_stream_url</code> goes straight to the online repo and
<a href="../../src/routes/player/%5Bid%5D/+page.svelte#L316">player/[id]/+page.svelte:316</a>
calls it with no local check — so a completed video download is still streamed.
This must be fixed or the whole feature is invisible for video.</p>
<h3 id="dr-124--keep-playback-bytes-only-when-they-are-the-download"><a class="header" href="#dr-124--keep-playback-bytes-only-when-they-are-the-download">DR-124 — Keep playback bytes only when they <em>are</em> the download</a></h3>
<p>Capture is enabled only where the played bytes and the canonical download artifact
are the same thing — a <strong>direct-play</strong> session. Then:</p>
<div class="table-wrapper"><table><thead><tr><th>Path</th><th>Mechanism</th></tr></thead><tbody>
<tr><td>Android / ExoPlayer</td><td><code>SimpleCache</code> + <code>CacheDataSource</code>, keyed by item id <strong>and</strong> media-source id so renditions never collide. LRU evictor sharing the existing smart-cache budget — not a second budget over the same disk.</td></tr>
<tr><td>Linux audio / MPV</td><td><code>stream-record</code>, set through the existing <code>set_property</code> plumbing.</td></tr>
<tr><td>Linux video (HLS transcode)</td><td><strong>Not captured.</strong> Segments are not a file; assembling one needs ffmpeg, which is not a dependency and which CI is forbidden from installing at job time. The download path (DR-123) covers this case instead.</td></tr>
</tbody></table>
</div>
<p>Two abandonment rules, both of which must delete the partial rather than promote
it:</p>
<ul>
<li><strong>Seek during an mpv capture.</strong> <code>stream-record</code> is documented as intended for
linear streams; seeking breaks the recording. Straight-through listening
captures, scrubbing does not.</li>
<li><strong>Any quality change</strong> (DR-122).</li>
</ul>
<h3 id="dr-125--promotion-rendition-and-invalidation"><a class="header" href="#dr-125--promotion-rendition-and-invalidation">DR-125 — Promotion, rendition, and invalidation</a></h3>
<p>A capture is promoted to a <code>downloads</code> row (<code>status = 'completed'</code>) only when it
covers the whole resource. Partial captures stay cache and remain evictable.</p>
<p>A new <code>downloads.source_rendition</code> column records the negotiated
quality/container/codec of whatever produced the bytes; <code>NULL</code> for rows fetched by
the existing paths, which are always <code>original</code>. This is what makes an "upgrade to
original" action possible later, and what stops a 720p capture and a 4K download
being indistinguishable rows.</p>
<p><strong>Invalidation.</strong> A quality change never touches a file that already exists —
neither a permanent download nor a completed temporary one. Both remain valid
copies of the rendition they hold, and deleting either would throw away bytes
already paid for.</p>
<p>What a quality change <em>does</em> invalidate is an <strong>in-flight</strong> capture or background
download of cached media: it is abandoned and restarted at the newly chosen
quality, because a capture spanning a rendition change is a splice of two
encodings rather than a playable file (DR-122).</p>
<p>So the rule is about <em>ongoing</em> work, not stored files. Nothing in this spec
deletes user data.</p>
<h3 id="gating"><a class="header" href="#gating">Gating</a></h3>
<p>Capture and background download obey the existing WiFi-only gate and storage
budget, and are off unless opted in. Enforcement is in Rust.</p>
<h2 id="out-of-scope"><a class="header" href="#out-of-scope">Out of scope</a></h2>
<ul>
<li><strong>Mid-playback switch onto a completing download.</strong> Two independent paths make
it unnecessary; the download is used from the next boundary.</li>
<li><strong>Backfilling the unplayed remainder of a capture.</strong> Watch 40 minutes and you
have 40 minutes; completing it needs sparse-range bookkeeping and a resumable
tail fetch. The DR-123 download path already produces a complete file, which is
the reason this can wait.</li>
<li><strong>Bundling ffmpeg</strong> to make transcoded video capturable. Real option, large
packaging decision, its own proposal.</li>
<li><strong>Routing Linux video playback through <code>stream.mp4</code>.</strong> Regresses a documented,
hard-won fix.</li>
</ul>
<h2 id="acceptance-criteria"><a class="header" href="#acceptance-criteria">Acceptance criteria</a></h2>
<ul>
<li><input disabled="" type="checkbox"/>
The player offers the qualities Rust reports, and changing one resumes at
the same position with audio/subtitle selection preserved.</li>
<li><input disabled="" type="checkbox"/>
A quality change abandons any in-flight capture and leaves no partial file.</li>
<li><input disabled="" type="checkbox"/>
A quality change never deletes a <code>downloads</code> row.</li>
<li><input disabled="" type="checkbox"/>
A completed background download of a video is <em>played from disk</em> on the next
play (the DR-123 prerequisite).</li>
<li><input disabled="" type="checkbox"/>
A direct-play session played start-to-finish leaves a complete local file
with no second fetch; replaying it fetches no media bytes.</li>
<li><input disabled="" type="checkbox"/>
Seeking during an mpv capture abandons it; no truncated file is promoted.</li>
<li><input disabled="" type="checkbox"/>
A transcoded Linux video session is never captured, and never partially
promoted.</li>
<li><input disabled="" type="checkbox"/>
Promoted rows record their rendition; existing paths still record
<code>NULL</code>/<code>original</code>.</li>
<li><input disabled="" type="checkbox"/>
Gates hold with the setting off <em>and</em> with the frontend never sending it.</li>
<li><input disabled="" type="checkbox"/>
Eviction cannot delete bytes backing a promoted download row.</li>
<li><input disabled="" type="checkbox"/>
<code>bun run check</code>, <code>bun run test</code>, <code>cargo fmt</code>, <code>cargo clippy</code>,
<code>bun run test:rust</code>, <code>bun run check:boundary</code> pass; <code>bindings.ts</code>
regenerated if Rust types changed.</li>
</ul>
<h2 id="testing"><a class="header" href="#testing">Testing</a></h2>
<p>Rust, table-driven and pure where possible: quality→params resolution shared with
the download path; keepability (direct play vs transcode vs gate off); promotion
(complete → promoted, partial → not, seek-abandoned → not, quality-changed → not);
invalidation (evicts cache, never a download row); rendition round-trip.</p>
<p>Android: instrumented — a played direct-play item yields cache entries, and a
replay issues no media network request.</p>
<p>Frontend: the quality list renders from backend data with no item-type or
codec taxonomy in <code>src/</code>; the selector's remembered choice is a view preference.</p>
<h2 id="traces"><a class="header" href="#traces">TRACES</a></h2>
<div class="table-wrapper"><table><thead><tr><th>Piece</th><th>Tag</th></tr></thead><tbody>
<tr><td>Quality selector + re-negotiation</td><td><code>// TRACES: UR-070 | DR-121</code></td></tr>
<tr><td>Ephemeral playback / capture abandonment</td><td><code>// TRACES: UR-070 | DR-122</code></td></tr>
<tr><td>Independent whole-file download + local video playback fix</td><td><code>// TRACES: UR-071 | DR-123, IR-032</code></td></tr>
<tr><td>ExoPlayer cache / mpv stream-record / keepability</td><td><code>// TRACES: UR-071 | DR-124</code></td></tr>
<tr><td>Promotion, <code>source_rendition</code>, invalidation</td><td><code>// TRACES: UR-071 | DR-125</code></td></tr>
</tbody></table>
</div>
<h2 id="notes-for-the-implementer"><a class="header" href="#notes-for-the-implementer">Notes for the implementer</a></h2>
<ul>
<li><strong>A parallel Claude session is active in this repo.</strong> <code>git diff</code> before
"repairing" anything you did not write.</li>
<li>Do not duplicate the quality→transcode-parameter table. Call the existing one.</li>
<li>Reuse the smart-cache storage budget; two budgets over one disk is how devices
fill up.</li>
<li>The <code>downloads</code> FK to <code>items</code> is relaxed (migration 005) — exercise promotion
for an item that was never cached.</li>
<li>Build DR-123's local-playback fix first. Without it nothing in this spec is
observable for video.</li>
</ul>
</main>
<nav class="nav-wrapper" aria-label="Page navigation">
<!-- Mobile navigation buttons -->
<a rel="prev" href="../specs/libmpv2-migration.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<i class="fa fa-angle-left"></i>
</a>
<a rel="next prefetch" href="../specs/scoped-search.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
<div style="clear: both"></div>
</nav>
</div>
</div>
<nav class="nav-wide-wrapper" aria-label="Page navigation">
<a rel="prev" href="../specs/libmpv2-migration.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<i class="fa fa-angle-left"></i>
</a>
<a rel="next prefetch" href="../specs/scoped-search.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
</nav>
</div>
<script>
window.playground_copyable = true;
</script>
<script src="../elasticlunr.min.js"></script>
<script src="../mark.min.js"></script>
<script src="../searcher.js"></script>
<script src="../clipboard.min.js"></script>
<script src="../highlight.js"></script>
<script src="../book.js"></script>
<!-- Custom JS scripts -->
</div>
</body>
</html>