feat(core): shared external-stream asset resolver for Cast (Phase 0)

Add a frontend-agnostic API to resolve a track's bytes + MIME + actually-
delivered quality for an external renderer (Chromecast / DLNA), so the Slint
Cast port does not need an improvised downloader (ADR-006).

- qbz-models: ExternalStreamAsset { bytes, content_type, quality, duration,
  origin }, StreamQualityInfo (kHz-normalized via from_raw, handles the
  kHz-vs-Hz endpoint ambiguity), AssetOrigin.
- qbz-qobuz/cmaf: download_full_with_quality(_progress) returns the resolved
  format_id/sampling_rate/bit_depth alongside the FLAC bytes; download_full is
  now a thin wrapper (no duplicated segment assembly).
- qbz-player: Player::fetch_for_external_stream — CMAF-first (FLAC, accurate
  quality) with legacy stream-URL fallback; never reads the local playback
  cache (casting attempts the best tier and must report the real delivered
  quality); never serves an empty content type (external_content_type helper).
- qbz-core: CoreBridge::fetch_for_external_stream_resolved wrapper.

Decision D3 (attempt UltraHiRes first + surface delivered quality) is satisfied
by passing Quality::UltraHiRes and returning StreamQualityInfo. Unit-tested:
content-type fallback by format id, sampling-rate unit normalization.

cc
This commit is contained in:
vicrodh committed 2026-06-18 09:19:38 -06:00
1 parent c974b8a973
commit fdf2fec3bb
5 files changed
+278 -3

No files matched your search

+34 -2
View File
@@ -35,7 +35,7 @@
use std::sync::Arc;
use qbz_models::Quality;
use qbz_models::{Quality, StreamQualityInfo};
use crate::client::QobuzClient;
use crate::error::Result;
@@ -205,6 +205,31 @@ pub async fn download_full_with_progress(
quality: Quality,
on_progress: Option<CmafProgressCallback>,
) -> std::result::Result<Vec<u8>, String> {
download_full_with_quality_progress(client, track_id, quality, on_progress)
.await
.map(|(bytes, _quality)| bytes)
}
/// Like [`download_full`] but also returns the quality actually resolved from
/// the CMAF init segment (`format_id` / `sampling_rate` / `bit_depth`). Used
/// by the external-stream (Cast / DLNA) path, which must surface the real
/// delivered quality. The CMAF path always yields decrypted FLAC, so the
/// caller's content type is `audio/flac`.
pub async fn download_full_with_quality(
client: &QobuzClient,
track_id: u64,
quality: Quality,
) -> std::result::Result<(Vec<u8>, StreamQualityInfo), String> {
download_full_with_quality_progress(client, track_id, quality, None).await
}
/// [`download_full_with_quality`] + a per-segment progress callback.
pub async fn download_full_with_quality_progress(
client: &QobuzClient,
track_id: u64,
quality: Quality,
on_progress: Option<CmafProgressCallback>,
) -> std::result::Result<(Vec<u8>, StreamQualityInfo), String> {
let setup = setup_streaming(client, track_id, quality).await?;
let http = build_cdn_client()?;
@@ -230,7 +255,14 @@ pub async fn download_full_with_progress(
output.len() as f64 / (1024.0 * 1024.0),
total_size as f64 / (1024.0 * 1024.0),
);
Ok(output)
// `from_raw` normalizes the rate unit (kHz vs Hz) defensively.
let quality_info = StreamQualityInfo::from_raw(
setup.format_id,
setup.sampling_rate.map(|v| v as f64),
setup.bit_depth,
);
Ok((output, quality_info))
}
/// Download a track's complete CMAF stream and return it as a raw (still