feat(playback): let Rust decide what stream to play, and say so
Playing a video meant asking the server to re-encode it, always. That
decision was made nowhere and written down nowhere, so whoever needed it
re-derived it downstream — the player worked out whether it had been handed
a playlist by looking for ".m3u8" in the URL, in two places. A viewer paid
for a transcode of a file their device could have played untouched, and the
app could not tell them which it was.
One negotiation now produces one self-describing StreamSelection — direct
play, remux or transcode; over a playlist, a plain HTTP file, or a local one
— and every renderer consumes that same answer.
Measured against the development server (Jellyfin 10.11.5), 400 items
sampled for codec mix and 40 put through a real PlaybackInfo negotiation
per profile:
Linux / WebKitGTK (h264 only, 2ch) 3/40 — 7% direct play
Android / ExoPlayer (hevc, ac3/eac3, 6ch) 34/40 — 85% direct play
The library is ~80% hevc, which is why the two diverge so hard. The payoff
is overwhelmingly Android, where 85% of plays were starting a transcode
nobody needed. Linux stays near 7% until libmpv decodes the picture — the
h264-only profile is a WebKitGTK constraint, not a JellyTau choice.
DR-219 StreamSelection: url + tagged Transport (hls/progressive/localFile)
+ PlaybackKind (directPlay/directStream/transcode) + the negotiated
rendition + this source's ladder + a needs_transcoding flag derived
in Rust so the rule is answered once. Both enums are serde-tagged
so the frontend matches a discriminant, not a substring. The paths
that never negotiate get the same shape from Rust rather than
assembling one — media_local_selection for a downloaded file,
LiveStreamInfo.transport for a live channel — so there is no second
place where a transport is decided.
DR-220 The ceiling becomes two levels: a durable device default (Settings,
persisted) and a per-playback override the in-player picker sets.
The picker had called itself a "this film, this connection" control
since it was written but wrote the process-wide default, so dropping
one awkward film to 2 Mbps silently capped every video played
afterwards for the rest of the process, with Settings still showing
the old value. The override is cleared whenever playback moves to a
new item, which stops it surviving into an autoplayed next episode.
effective_streaming_quality() is the single resolution point.
DR-221 The quality picker is filled from what this media source can offer.
Rust marks a rung exceeds_source when its ceiling is at or above the
source's own bitrate — such a rung is another way to spell Original
— and the frontend does not draw those. Original is never marked; a
source whose bitrate the server does not report marks nothing, which
keeps every rung offered.
DR-222 Direct play and direct stream are negotiated, with two client-side
overrides on top because the server's answer is right about the file
and wrong about what this app will do with it: undecodable audio
(Jellyfin 10.11.5 honours a DirectPlayProfile's container and video
codec but ignores its audio codec, so it offers direct play for an
E-AC-3 track the webview renders in silence) and a viewer-pinned
audio track the file does not default to. A direct stream is a remux
and is deliberately not counted as transcoding.
DR-223 Dropped on measurement, not deferred. A master playlist from this
server carries exactly one EXT-X-STREAM-INF: Jellyfin builds it from
the single rendition the request asked for rather than publishing a
ladder. So there is no adaptation for hls.js to be preserving and
none mpv would lose — the claim that there was, in
playback-backend-unification.md, does not hold. Recorded rather than
deleted because it is a measurement: a server that does publish a
ladder would change the answer.
DR-224 Every backend consumes the same selection. The queue item carries
the transport, so player_seek_video picks its seek strategy from the
backend's decision instead of the last stream_url.contains(".m3u8")
in the codebase. Items queued by a path that never negotiated carry
None and fall back to needs_transcoding, which is exact rather than
a guess because every transcode this app requests is HLS (DR-140).
The frontend loader decision moves to streamTransport.ts so it can be
tested: the two cases that pin it are the ones that failed against the old
implementation — a progressive stream whose URL contains ".m3u8" must not
get an HLS loader, and an HLS stream whose URL contains none must.
Also verified the URL the direct-play branch builds actually serves playable
bytes: 206, video/mp4, valid ISO-BMFF, and a mid-file range works, so
seeking a direct play works.
The spec is folded into docs/architecture/{01,02,03} and deleted, per the
rule that docs/specs holds only work that has not shipped. DR-121 leaves
read-through-media-cache.md with a pointer; that spec keeps its capture half.
Not verified: real playback on a device. Direct play changes what actually
gets played, and neither fixtures nor curl prove the WebKitGTK and ExoPlayer
paths render it.
This commit is contained in:
@@ -377,6 +377,8 @@ mod tests {
|
||||
|
||||
// Create a test media item
|
||||
let media = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: "test_media".to_string(),
|
||||
title: "Test Track".to_string(),
|
||||
name: Some("Test Track".to_string()),
|
||||
@@ -436,6 +438,8 @@ mod tests {
|
||||
let mut backend = NullBackend::new();
|
||||
|
||||
let media = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: "test_media".to_string(),
|
||||
title: "Test Track".to_string(),
|
||||
name: Some("Test Track".to_string()),
|
||||
@@ -489,6 +493,8 @@ mod tests {
|
||||
let mut backend = NullBackend::new();
|
||||
|
||||
let media = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: "test_media".to_string(),
|
||||
title: "Test Track".to_string(),
|
||||
name: Some("Test Track".to_string()),
|
||||
|
||||
@@ -115,6 +115,18 @@ pub struct MediaItem {
|
||||
/// Whether the video requires server-side transcoding
|
||||
#[serde(default)]
|
||||
pub needs_transcoding: bool,
|
||||
/// How this item's stream is fetched, as the backend decided it.
|
||||
///
|
||||
/// Carried on the queue item so a later seek/reload does not have to guess.
|
||||
/// `None` for items queued by a path that never negotiated (audio tracks,
|
||||
/// direct URLs) and for anything queued before this field existed, where the
|
||||
/// caller falls back to `needs_transcoding` — every transcode this app
|
||||
/// requests is HLS (DR-140), so that fallback is exact rather than a guess.
|
||||
///
|
||||
/// TRACES: UR-003, UR-004, UR-079 | DR-224, DR-229
|
||||
#[serde(default)]
|
||||
pub transport: Option<crate::repository::Transport>,
|
||||
|
||||
/// Video width in pixels
|
||||
#[serde(default)]
|
||||
pub video_width: Option<u32>,
|
||||
@@ -360,6 +372,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_media_item_creation_minimal() {
|
||||
let item = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: "item-1".to_string(),
|
||||
title: "Test Item".to_string(),
|
||||
name: None,
|
||||
@@ -396,6 +410,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_media_item_jellyfin_id() {
|
||||
let item = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: "item-2".to_string(),
|
||||
title: "Test".to_string(),
|
||||
name: None,
|
||||
@@ -431,6 +447,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_media_item_jellyfin_id_local() {
|
||||
let item = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: "item-3".to_string(),
|
||||
title: "Local".to_string(),
|
||||
name: None,
|
||||
@@ -466,6 +484,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_media_item_jellyfin_id_direct_url() {
|
||||
let item = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: "item-4".to_string(),
|
||||
title: "Direct".to_string(),
|
||||
name: None,
|
||||
@@ -508,6 +528,8 @@ mod tests {
|
||||
};
|
||||
|
||||
let item = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: "item-subs".to_string(),
|
||||
title: "With Subs".to_string(),
|
||||
name: None,
|
||||
@@ -543,6 +565,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_media_item_serialization() {
|
||||
let item = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: "serial-item".to_string(),
|
||||
title: "Serial Test".to_string(),
|
||||
name: Some("Name".to_string()),
|
||||
|
||||
@@ -1897,6 +1897,8 @@ impl PlayerController {
|
||||
.map_err(|e| format!("Failed to build audio-only URL for next episode: {}", e))?;
|
||||
|
||||
let media_item = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: next.id.clone(),
|
||||
title: next.name.clone(),
|
||||
name: Some(next.name.clone()),
|
||||
@@ -2580,6 +2582,8 @@ mod tests {
|
||||
fn create_test_items(count: usize) -> Vec<MediaItem> {
|
||||
(0..count)
|
||||
.map(|i| MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: format!("item_{}", i),
|
||||
title: format!("Track {}", i + 1),
|
||||
name: Some(format!("Track {}", i + 1)),
|
||||
@@ -3792,6 +3796,8 @@ mod tests {
|
||||
|
||||
// Queue holds the episode that just finished playing
|
||||
let episode = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
media_type: MediaType::Video,
|
||||
source: MediaSource::Remote {
|
||||
stream_url: "http://example.com/ep1.mkv".to_string(),
|
||||
@@ -3827,6 +3833,8 @@ mod tests {
|
||||
|
||||
// Mirrors what player_enter_background_audio builds: the episode as AUDIO.
|
||||
let episode = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
item_type: Some("Episode".to_string()),
|
||||
media_type: MediaType::Audio, // audio-only handoff, not Video
|
||||
series_id: Some("series1".to_string()),
|
||||
@@ -3943,6 +3951,8 @@ mod tests {
|
||||
|
||||
// Currently playing: ep2 handed off to audio-only background playback.
|
||||
let episode = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: "ep2".to_string(),
|
||||
item_type: Some("Episode".to_string()),
|
||||
media_type: MediaType::Audio,
|
||||
@@ -3978,6 +3988,8 @@ mod tests {
|
||||
/// URL carrying the handoff position.
|
||||
fn audio_only_episode(runtime_seconds: f64) -> MediaItem {
|
||||
MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: "ep2".to_string(),
|
||||
item_type: Some("Episode".to_string()),
|
||||
media_type: MediaType::Audio,
|
||||
@@ -3998,6 +4010,8 @@ mod tests {
|
||||
/// handoff point.
|
||||
fn local_audio_only_episode(runtime_seconds: f64) -> MediaItem {
|
||||
MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
source: MediaSource::Local {
|
||||
file_path: std::path::PathBuf::from("/downloads/ep2.mkv"),
|
||||
jellyfin_item_id: Some("ep2".to_string()),
|
||||
@@ -4682,6 +4696,8 @@ mod tests {
|
||||
controller.set_repository(Arc::new(MockEpisodeRepo::season(3)));
|
||||
|
||||
let episode = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: "ep2".to_string(),
|
||||
item_type: Some("Episode".to_string()),
|
||||
media_type: MediaType::Video,
|
||||
@@ -4717,6 +4733,8 @@ mod tests {
|
||||
let controller = PlayerController::default();
|
||||
|
||||
let episode = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
media_type: MediaType::Video,
|
||||
source: MediaSource::Remote {
|
||||
stream_url: "http://example.com/ep1.mkv".to_string(),
|
||||
|
||||
@@ -541,6 +541,8 @@ mod tests {
|
||||
fn create_test_items(count: usize) -> Vec<MediaItem> {
|
||||
(0..count)
|
||||
.map(|i| MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: format!("item_{}", i),
|
||||
title: format!("Track {}", i + 1),
|
||||
name: Some(format!("Track {}", i + 1)),
|
||||
|
||||
@@ -232,6 +232,8 @@ mod tests {
|
||||
|
||||
fn create_test_audio_item(title: &str) -> MediaItem {
|
||||
MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: title.to_string(),
|
||||
title: title.to_string(),
|
||||
name: Some(title.to_string()),
|
||||
@@ -263,6 +265,8 @@ mod tests {
|
||||
|
||||
fn create_test_movie_item(title: &str) -> MediaItem {
|
||||
MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: title.to_string(),
|
||||
title: title.to_string(),
|
||||
name: Some(title.to_string()),
|
||||
|
||||
@@ -316,6 +316,8 @@ mod tests {
|
||||
// Helper function to create test MediaItem instances
|
||||
fn create_test_media_item(id: &str, title: &str) -> MediaItem {
|
||||
MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: id.to_string(),
|
||||
title: title.to_string(),
|
||||
name: None,
|
||||
|
||||
@@ -258,6 +258,8 @@ mod tests {
|
||||
/// `StartTimeTicks` is the handoff point.
|
||||
fn handoff_item() -> MediaItem {
|
||||
MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
id: "ep2".to_string(),
|
||||
title: "Episode 2".to_string(),
|
||||
name: None,
|
||||
@@ -303,6 +305,8 @@ mod tests {
|
||||
// `/Audio/{id}/stream?Static=true` — a real Content-Length and byte
|
||||
// ranges, so ExoPlayer resumes it where the load failed.
|
||||
let track = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
item_type: Some("Audio".to_string()),
|
||||
..handoff_item()
|
||||
};
|
||||
@@ -314,6 +318,8 @@ mod tests {
|
||||
// An HLS playlist declares its segments, so a failed segment load is
|
||||
// retried at that segment, not at the start of the episode.
|
||||
let video = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
media_type: MediaType::Video,
|
||||
..handoff_item()
|
||||
};
|
||||
@@ -324,6 +330,8 @@ mod tests {
|
||||
fn test_downloaded_episode_keeps_the_players_retry() {
|
||||
// A local file has no length problem and no network to lose.
|
||||
let local = MediaItem {
|
||||
// Audio and direct-URL items never negotiate a transport.
|
||||
transport: None,
|
||||
source: MediaSource::Local {
|
||||
file_path: PathBuf::from("/data/ep2.mkv"),
|
||||
jellyfin_item_id: Some("ep2".to_string()),
|
||||
|
||||
Reference in New Issue
Block a user