perf(cast): cache-first resolver + offline tier + cheap quality (P1+P2)
The cast was slow because the resolver always did a full CMAF download (~10s for a 190MB hi-res FLAC) and never read the cache — unlike the fast last Tauri build, which resolved bytes cache-first. - P1 cache-first: Player::fetch_for_external_stream now checks L1 (in-memory) -> L2 (on-disk playback cache) before any download. The gapless prefetch already warms the next 2 tracks at UltraHiRes while casting, so next/advance/replay are now instant; only a cold track pays the download. - Offline tier: CoreBridge::fetch_for_external_stream_resolved gains offline + sink params and tries resolve_offline_bytes (local CMAF decrypt, no network) before the network path — a downloaded track casts fast with no connection (the same local-segments+decrypt path offline playback uses). Replaces the hard "Qobuz cast needs a connection" gate (offline-cached tracks now work). - P2 quality label: derived from the track's catalog metadata (bit_depth/sample_rate/hires) in cast_track — no extra API call, consistent whether bytes came from cache, offline, or network. cargo check -p qbz-slint: clean. cc
This commit is contained in:
3 files changed
+108
-48
No files matched your search
@@ -7,7 +7,7 @@ use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use qbz_models::{
|
||||
ExternalStreamAsset,
|
||||
AssetOrigin, ExternalStreamAsset, StreamQualityInfo,
|
||||
Album, Artist, ArtistAlbums, CoreEvent, DiscoverAlbum, DiscoverData, DiscoverPlaylistsResponse,
|
||||
DiscoverResponse, FrontendAdapter, GenreInfo, LabelExploreResponse, LabelGetListResponse,
|
||||
LabelListPage, LabelPageData, LabelStoryResponse, PageArtistResponse,
|
||||
@@ -665,16 +665,40 @@ impl<A: FrontendAdapter + Send + Sync + 'static> QbzCore<A> {
|
||||
self.player.fetch_for_gapless(client, track_id, quality).await
|
||||
}
|
||||
|
||||
/// Resolve a fully-materialized audio asset (bytes + MIME + delivered
|
||||
/// quality) for an EXTERNAL renderer (Chromecast / DLNA). The Cast service
|
||||
/// hands the bytes to the local media server and the quality to the UI.
|
||||
/// Attempts the best tier first (pass `Quality::UltraHiRes`); the resolver
|
||||
/// falls back down the chain and reports what was actually delivered.
|
||||
/// Resolve a fully-materialized audio asset (bytes + MIME + quality) for an
|
||||
/// EXTERNAL renderer (Chromecast / DLNA). Tier order mirrors
|
||||
/// `fetch_for_gapless_resolved`: L1/L2 player cache -> OFFLINE (local CMAF
|
||||
/// decrypt, no network) -> network. The offline tier is what makes a
|
||||
/// downloaded track cast fast with no connection (the same "local segments,
|
||||
/// decrypt on demand" path the offline cache uses for playback). On a cache
|
||||
/// or offline hit the precise delivered quality isn't known here — the Cast
|
||||
/// service derives the quality label from the track's catalog metadata.
|
||||
pub async fn fetch_for_external_stream_resolved(
|
||||
&self,
|
||||
track_id: u64,
|
||||
quality: Quality,
|
||||
offline: Option<&qbz_offline_cache::OfflineCacheState>,
|
||||
sink: Option<&qbz_offline_cache::CacheEventSink>,
|
||||
) -> Option<ExternalStreamAsset> {
|
||||
// L1/L2 player cache (decrypted FLAC) is handled inside
|
||||
// fetch_for_external_stream; only reach for the offline tier when the
|
||||
// track is not already cached (the CMAF decrypt is slow).
|
||||
if !self.player.is_track_cached(track_id) {
|
||||
if let Some(off) = offline {
|
||||
if let Some(bytes) =
|
||||
crate::offline_resolve::resolve_offline_bytes(track_id, off, sink).await
|
||||
{
|
||||
log::info!("[CAST-FETCH] track {track_id} served from OFFLINE cache");
|
||||
return Some(ExternalStreamAsset {
|
||||
bytes,
|
||||
content_type: "audio/flac".to_string(),
|
||||
quality: StreamQualityInfo::from_raw(0, None, None),
|
||||
duration_secs: None,
|
||||
origin: AssetOrigin::Offline,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
let guard = self.client.read().await;
|
||||
let client = guard.as_ref()?;
|
||||
self.player
|
||||
|
||||
Reference in new issue
Block a user