From e54dcc70ef0e104fc533cff2d063cf6ed0eb611d Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 15:59:30 +0300 Subject: [PATCH 1/3] The platform supplies the media composition, and the app publishes it once Platform gains a MediaBoot: early_init runs at the old acb_init line, before the first adapter, and compose installs the platform's drivers on the adapter and returns a Composition, the resolver and nothing else. Compose takes no session and publishes nothing. The boot then calls one function, publish_composition, which gives the route session the resolver and then the set the adapter's installed drivers form, every boot, a zero-driver platform included, and logs one "compose: backends= resolver=" line. The set and the resolver can no longer disagree: a refused URI install returns no resolver, and the adapter holds no URI driver. The webOS port fills the table with backends::acb_init and backends::compose_native; the desktop installs the Feed over the host sink and no URI driver, with a no-op early_init; the host-test platform composes nothing. The bodies stay in adapters/backends.rs until W11a: dev and the tests name UriProduct and its siblings, and the layer fence forbids them naming port. compose_backends is gone, split into compose_feed (shared), compose_native and the compose_with core the host rig drives over its own ports. install_uri_product(_with_ports) now return the resolver instead of writing it into a session. The ten play-uri gates in playback.rs and run.rs that only read what the installed drivers do at run time are removed; the 41 that name ACB or the URI product stay. install_uri_preflight_port takes a bare port or an Option, and the session has a reader for it. The 18 URI boot rig tests now publish through the same function as the boot instead of installing the resolver by hand; none changed its outcome. New tests cover a composed URI driver, a refused install, a controlled boot and a platform that composed nothing, each asserting the session's set and resolver agree. Co-Authored-By: Claude --- docs/platform-ports.md | 37 +++- rust-modules/media/src/route/decision.rs | 16 +- .../media/src/route/decision_version_tests.rs | 19 ++ rust-modules/src/app/adapters/backends.rs | 173 +++++++++++++----- rust-modules/src/app/boot.rs | 9 +- rust-modules/src/app/platform.rs | 107 ++++++++++- rust-modules/src/app/playback.rs | 6 - rust-modules/src/app/run.rs | 4 - rust-modules/src/app/run_uri_boot_tests.rs | 52 +++--- rust-modules/src/dev/uriprobe.rs | 2 +- rust-modules/src/dev/uriprobe_tests.rs | 2 +- rust-modules/src/platform_desktop.rs | 29 ++- rust-modules/src/port.rs | 15 +- 13 files changed, 363 insertions(+), 108 deletions(-) diff --git a/docs/platform-ports.md b/docs/platform-ports.md index 45f9329ff..fa05e6eba 100644 --- a/docs/platform-ports.md +++ b/docs/platform-ports.md @@ -992,26 +992,38 @@ Ecore names to `remote_token_key` pairs". ### 6. Media, as four things - a. Composition and the two boot phases (review M5, C3; critic F7). `Platform.media` is `MediaBoot { early_init: - fn(&MainThread), compose: fn(&mut PlayerAdapter, &PlaybackSession, controlled: bool) -> Composition }`, with - `Composition { resolver: Option }`: + fn(&MainThread), compose: fn(&mut PlayerAdapter, controlled: bool) -> Composition }`, with + `Composition { resolver: Option }` (W6b landed this shape; the `&PlaybackSession` parameter this + paragraph first named is dropped, see the deviation below): - `early_init` runs at today's `acb_init` site (`app/boot.rs:2043`, inside `if !controlled`, before `ffi::boot()`, F32). webOS fills it with `acb_init`, the others with a no-op. - `compose` runs where `compose_backends` runs (`:2323`). webOS fills it with today's function (`backends.rs:64,141-164`) minus both publications; the desktop installs HostSink Feed; Tizen installs nothing (W9), then its URI driver (W10). It returns the resolver of a URI product only when the physical install succeeded (today's `install_uri_product_with_ports`, `:418-421`); `None` on a refused install, a - controlled boot or no URI driver. It reads the session (`&PlaybackSession`: a driver may need a snapshot) and - publishes nothing. + controlled boot or no URI driver. It publishes nothing. Deviation, W6b: it takes no `&PlaybackSession`. The + session was read by nothing in the composition (the only session use was the resolver publication that moved + out), so the parameter would have been dead; W10 adds a read-only session parameter if a Tizen driver needs + one. - After `compose` returns, the APP publishes both facts in one function, once, always: the resolver (`install_uri_preflight_port`) if present, then `install_backends(adapter.composed_backends())`, - `BackendSet::NONE` included (`backends.rs:163` and `:421` moved app-side, F43). The session starts at `FEED` + `BackendSet::NONE` included (`backends.rs:163` and `:421` moved app-side, F43; landed in W6b as + `app::platform::publish_composition`, which also logs the one `compose: backends= resolver=` + line). The session starts at `FEED` (F31), so a zero-driver platform that forgot the call would offer Feed, and a set that advertised URI without its resolver would reach the planner as `NoPort`. No platform keeps adapter and session in step. - The Cargo feature `play-uri` (`rust-modules/Cargo.toml:81`) keeps meaning "the webOS ACB URI driver" and is - webOS-only. `PLAYBACK_BACKENDS` maps per platform (Tizen: its own `uri` feature; `play-uri` never). The 37 - `feature = "play-uri"` sites in `rust-modules/src` are sorted in W6b: composition and `acb_init` go to the - webOS platform; `playback.rs`, `run.rs` and `dev.rs` read `adapter.composed_backends()` at run time, or stay - webOS-platform code if they name ACB. + webOS-only. `PLAYBACK_BACKENDS` maps per platform (Tizen: its own `uri` feature; `play-uri` never). The + `feature = "play-uri"` sites in `rust-modules/src` (37 when this was written, 51 at W6b: #1478 added 14 to + `backends.rs`) are sorted in W6b: the 10 in `playback.rs` and `run.rs` read the installed drivers at run + time (the attempt's backend, the adapter's queues, the resolver's offer) and lost their gate; the other 41 name + ACB or the URI product (`backends.rs` 35, `dev.rs`, `lib.rs`'s ARM guard, two test files) and keep theirs. + Composition is a SEAM until W11a, not a move: `port.rs` fills `Platform.media` with + `backends::acb_init` and `backends::compose_native`, and the bodies stay in `app/adapters/backends.rs`. They + cannot go to `port` yet, because `dev/uri_product.rs`, `dev/uri_exported.rs`, `run_uri_boot_tests.rs` and + `backends.rs`'s own tests name `UriProduct`, `UriDriverSettings` and `install_uri_product_with_ports`, and the + layer fence forbids anything outside the webOS platform naming `port`. W11a moves the file whole, with its + callers. - b. Evidence is the driver's, in three separate decisions (review B3, C5; critic M1, F12). - Display readiness: `UriDriver::display() -> DisplayEvidence { readiness: Ready | NotReady(DisplayUnavailable), preview_rectangle, tag }`, beside the capabilities and certification its offers carry. `Binding` leaves the @@ -1582,6 +1594,13 @@ W3d. Neutral types (L15b item 2 prerequisites; part of item 3). shows `acb_init` at the same point. - Risk: `acb_init`'s order relative to `ffi::boot()` and the first frame; moving it into `compose` would change its timing (review M5). +- As landed: the seam, not the move (Target shape 6a, "Composition is a SEAM until W11a"). `port.rs` fills + `Platform.media` with `backends::acb_init` and `backends::compose_native`; the bodies stay in + `app/adapters/backends.rs` until W11a, because dev and the tests name `UriProduct` and its siblings and the fence + forbids them naming `port`. `early_init` is called at the old `acb_init` line and `compose` at the old + `compose_backends` line, so neither phase moved. `dev.rs`, `lib.rs`, `dev/uriprobe_tests.rs` and the `sink` + rule are unchanged (`backends.rs` stays an allowed path). The desktop composes the Feed over the host sink and no + URI driver; its `early_init` is a no-op. ### W6c (N). A URI-only and a two-driver composition play an ordinary title (host tests, before W10) - Goal (review B3, M8, C5; critic M1): through the real planner, with `FakeUriDriver` (`test_support.rs:143`) carrying diff --git a/rust-modules/media/src/route/decision.rs b/rust-modules/media/src/route/decision.rs index d150d6b92..4713c9c56 100644 --- a/rust-modules/media/src/route/decision.rs +++ b/rust-modules/media/src/route/decision.rs @@ -1342,8 +1342,20 @@ impl PlaybackSession { self.source_selection = Some(selection); } - pub fn install_uri_preflight_port(&mut self, port: super::uri_preflight::ResolvePort) { - self.uri_preflight_port = Some(port); + /// Publish the composition's resolver, or its absence: a boot whose URI install was refused (or + /// that composed no URI driver) passes `None`, and the planner then answers `UriDecline::NoPort`. + /// Takes `Some(port)` or a bare port, so the set of installed drivers and this resolver are + /// published by the one call the boot makes (`app::platform::publish_composition`). + pub fn install_uri_preflight_port( + &mut self, + port: impl Into>, + ) { + self.uri_preflight_port = port.into(); + } + + /// The resolver the composition published, `None` when it published none. + pub fn uri_preflight_port(&self) -> Option<&super::uri_preflight::ResolvePort> { + self.uri_preflight_port.as_ref() } /// The playback backends the composition supplies. Boot installs the set its drivers form diff --git a/rust-modules/media/src/route/decision_version_tests.rs b/rust-modules/media/src/route/decision_version_tests.rs index 641361715..0f0c39621 100644 --- a/rust-modules/media/src/route/decision_version_tests.rs +++ b/rust-modules/media/src/route/decision_version_tests.rs @@ -1271,3 +1271,22 @@ fn the_picked_version_rides_the_request_and_the_landing() { test_support::apply_plan(&mut ps, Plan { media_index: 1, ..Default::default() }, "rk-v"); assert_eq!(cur_media_index(&ps), 1); } + +/// The composition's resolver is published as a value, absence included: a bare port installs it, +/// `None` clears it, and the reader says which. The boot's one publisher relies on all three +/// (`app::platform::publish_composition` passes the compose's `Option` straight through). +#[test] +fn the_published_resolver_is_readable_and_an_absence_clears_it() { + use crate::route::uri_preflight::{CarrierQualifier, ProductEvidence, ResolvePort}; + let port = || ResolvePort::new( + ProductEvidence::unqualified_on(plx_playback_contract::uri::DisplayEvidence::ready("test")), + std::sync::Arc::new(CarrierQualifier)); + let mut ps = crate::route::PlaybackSession::IDLE; + assert!(ps.uri_preflight_port().is_none(), "a session nobody published to holds none"); + ps.install_uri_preflight_port(port()); + assert!(ps.uri_preflight_port().is_some(), "a bare port installs"); + ps.install_uri_preflight_port(Some(port())); + assert!(ps.uri_preflight_port().is_some(), "so does a `Some`"); + ps.install_uri_preflight_port(Option::::None); + assert!(ps.uri_preflight_port().is_none(), "an absence clears it"); +} diff --git a/rust-modules/src/app/adapters/backends.rs b/rust-modules/src/app/adapters/backends.rs index d82b91c03..522d03ea9 100644 --- a/rust-modules/src/app/adapters/backends.rs +++ b/rust-modules/src/app/adapters/backends.rs @@ -10,9 +10,13 @@ //! to it (`PlaneOwner::ensure_handle`, run by `UriDriver::ready_to_start`), so a viewer who //! never plays through it never has a second ACB core (#1394), while a normal boot still //! composes the URI driver `Acb` with no `ptype` trigger. -//! - [`compose_backends`] installs the product URI driver and then tells the route session which -//! backends the installed drivers form, so policy offers what is physically there instead of -//! what Cargo features happened to be on. +//! - [`compose_feed`] and [`compose_native`] install what a platform's drivers are: the Feed (or, with +//! none, the platform's display sink) for every platform, and on webOS the product URI driver +//! too. They publish nothing: they return what they composed, and the application's one +//! publisher (`app::platform::publish_composition`) tells the route session the set the +//! installed drivers form, so policy offers what is physically there instead of what Cargo +//! features happened to be on. `port.rs` and `platform_desktop.rs` name these two through +//! `Platform::media`; the bodies stay here until the webOS platform owns this file. //! - [`install_uri_product`] builds the product URI driver (`plx_play_uri::backend::UriBackend`) //! from the installed display and URI bus and hands it to the player adapter, which holds it //! only as a `UriDriver`. The player crate names neither the driver nor its settings. @@ -21,8 +25,9 @@ use plx_base::task::MainThread; use plx_media::player::adapter::PlayerAdapter; #[cfg(feature = "play-feed")] use plx_media::player::adapter::StartHooks; -use plx_media::route::PlaybackSession; +use plx_media::route::uri_preflight::ResolvePort; use plx_os::tv::plane::{self, PlaneFacts, PlaneOwner}; +use crate::app::platform::Composition; #[cfg(feature = "play-feed")] use plx_os::tv::plane::DEFAULT_PLAYER_TYPE; #[cfg(feature = "play-feed")] @@ -41,7 +46,7 @@ use plx_play_feed::{control::FeedBackend, feed_resources::{FeedResources, LoadRe use plx_os::tv::sink::{RefusingSink, UnloadTicket, VideoSink}; #[cfg(feature = "play-uri")] use plx_media::route::uri_preflight::{KnownSource, OriginalQualifier, OriginalRequest, - ProductEvidence, ResolvePort, UriDecline, Verdict, SOURCE_VERDICT_TTL}; + ProductEvidence, UriDecline, Verdict, SOURCE_VERDICT_TTL}; #[cfg(feature = "play-uri")] use plx_play_uri::backend::{Binding as UriBinding, Config as UriConfig, MonotonicClock, UriBackend}; #[cfg(feature = "play-uri")] @@ -139,12 +144,10 @@ fn acb_init_acb(mt: &MainThread, display: &dyn DisplaySink, owner: &PlaneOwner) owner.boot(PlaneFacts::ABSENT); } -/// Compose the backends this boot supplies. A normal boot installs the product URI driver first -/// (a refused install leaves URI out of the set); a controlled run (replay, scripted Home) touches -/// no native port and so installs none. Then the session is told the set the installed drivers -/// form. -pub(crate) fn compose_backends(adapter: &mut PlayerAdapter, session: &mut PlaybackSession, - controlled: bool) { +/// Compose the Feed into the adapter, or, in a build with no Feed, hand the adapter the platform's +/// own display sink: the part of a composition every platform shares (the television's and the +/// desktop's alike). Installs no URI driver and tells no session anything. +pub(crate) fn compose_feed(adapter: &mut PlayerAdapter) { #[cfg(feature = "play-feed")] if !adapter.composed_backends().feed && !install_feed(adapter, &TV_HOOKS) { log("feed: physical set installation refused"); @@ -155,17 +158,34 @@ pub(crate) fn compose_backends(adapter: &mut PlayerAdapter, session: &mut Playba if !adapter.install_display_sink(sink::installed) { log("player: display sink installation refused"); } +} + +/// The webOS composition, [`Platform::media`](crate::app::platform::Platform)'s `compose` for the +/// television: [`compose_with`] over the product URI driver this build has (none in a build without +/// `play-uri`). +pub(crate) fn compose_native(adapter: &mut PlayerAdapter, controlled: bool) -> Composition { #[cfg(feature = "play-uri")] - if !controlled && !install_uri_product(adapter, session) { - log("uri: product driver installation refused"); - } + let install_uri = install_uri_product; #[cfg(not(feature = "play-uri"))] - let _ = controlled; + let install_uri = |_: &mut PlayerAdapter| None; + compose_with(adapter, controlled, install_uri) +} + +/// Compose the backends a television boot supplies, with the URI driver installed by `install_uri`. +/// The Feed first; then, on a normal boot only, the URI driver (a refused install leaves URI out of +/// the set and yields no resolver); a controlled run (replay, scripted Home) touches no native port +/// and so installs none. What the adapter holds afterwards is the set the session is told, and the +/// resolver returned is `Some` only when `install_uri` installed the driver the resolver describes. +/// The boot passes the product installer; a host rig passes one over its own ports. +pub(crate) fn compose_with(adapter: &mut PlayerAdapter, controlled: bool, + install_uri: impl FnOnce(&mut PlayerAdapter) -> Option) -> Composition { + compose_feed(adapter); + let resolver = if controlled { None } else { install_uri(adapter) }; // The URI-mode probe (issue #1064) rides every boot, controlled or not: it reads its trigger // file only when a play starts. #[cfg(all(feature = "devtriggers", feature = "play-uri"))] crate::dev::uriprobe::install(adapter); - session.install_backends(adapter.composed_backends()); + Composition { resolver } } /// The hooks table the Feed's native executor runs over, built over the raw sink, the slice @@ -447,7 +467,7 @@ impl UriProduct { /// `dev::uri_product`. A debug build's exported-window override, `dev::uri_exported`, is read here /// too but certifies nothing: it only composes the display path.) #[cfg(feature = "play-uri")] -pub(crate) fn install_uri_product(adapter: &mut PlayerAdapter, session: &mut PlaybackSession) -> bool { +pub(crate) fn install_uri_product(adapter: &mut PlayerAdapter) -> Option { let display = sink::display_installed(); let binding = uri_product_binding(display, plx_os::tv::device::info().major, plx_play_uri::backend::EXPORTED_STRATA); @@ -463,19 +483,23 @@ pub(crate) fn install_uri_product(adapter: &mut PlayerAdapter, session: &mut Pla // product is returned as built. #[cfg(feature = "devtriggers")] let product = crate::dev::uri_product::compose(product, crate::dev::uri_product::trigger()); - install_uri_product_with_ports(adapter, session, product, plx_os::tv::uri::installed(), display) + let resolver = install_uri_product_with_ports(adapter, product, plx_os::tv::uri::installed(), display); + if resolver.is_none() { + log("uri: product driver installation refused"); + } + resolver } /// One boot composition for both real and injected ports. The driver is configured with the binding /// and the capabilities an opted-in viewer certifies ([`UriProduct::driver_capabilities`]); the -/// resolver receives the product's evidence joined to the display the installed driver reports, only -/// after physical installation succeeds. The boot log names that display, so a television's log -/// shows what the driver reported without a trigger. +/// resolver, returned for the caller to publish, receives the product's evidence joined to the +/// display the installed driver reports, only after physical installation succeeds: `None` is a +/// refused install, and the adapter then holds no URI driver. The boot log names that display, so a +/// television's log shows what the driver reported without a trigger. #[cfg(feature = "play-uri")] -pub(crate) fn install_uri_product_with_ports(adapter: &mut PlayerAdapter, - session: &mut PlaybackSession, product: UriProduct, +pub(crate) fn install_uri_product_with_ports(adapter: &mut PlayerAdapter, product: UriProduct, transport: &'static dyn plx_os::tv::uri::UriMedia, - display: &'static dyn DisplaySink) -> bool { + display: &'static dyn DisplaySink) -> Option { let settings = UriDriverSettings { clock: Box::new(ProductUriClock(plx_media::player::adapter::MonotonicMs::start())), app_id: plx_base::paths::app_id().to_owned(), @@ -485,9 +509,7 @@ pub(crate) fn install_uri_product_with_ports(adapter: &mut PlayerAdapter, release_allowance_ms: 10_000, source_ttl_ms: 30_000, }; - let Some(path) = install_uri_backend_with_ports(adapter, settings, transport, display) else { - return false; - }; + let path = install_uri_backend_with_ports(adapter, settings, transport, display)?; let state = match path.readiness { DisplayReadiness::Ready => "ready".to_owned(), DisplayReadiness::NotReady(why) => format!("unavailable ({})", why.log_name()), @@ -495,8 +517,22 @@ pub(crate) fn install_uri_product_with_ports(adapter: &mut PlayerAdapter, log(&format!("uri: display path={} {state}", path.tag)); let evidence = ProductEvidence { display: path, callable: product.callable, certified: product.certified }; - session.install_uri_preflight_port(ResolvePort::new(evidence, product.qualifier)); - true + Some(ResolvePort::new(evidence, product.qualifier)) +} + +/// A host rig's composition of the product URI driver over its own ports, published as the boot +/// publishes: the install, then [`publish_composition`](crate::app::platform::publish_composition) +/// with the resolver it returned (the session learns the adapter's whole set, Feed included). +/// Whether the driver installed. +#[cfg(all(test, feature = "play-uri"))] +pub(crate) fn install_and_publish_uri_product(adapter: &mut PlayerAdapter, + session: &mut plx_media::route::PlaybackSession, product: UriProduct, + transport: &'static dyn plx_os::tv::uri::UriMedia, + display: &'static dyn DisplaySink) -> bool { + let resolver = install_uri_product_with_ports(adapter, product, transport, display); + let installed = resolver.is_some(); + crate::app::platform::publish_composition(session, adapter, Composition { resolver }); + installed } /// Build the URI driver from `settings` over the captured platform ports and install it into @@ -787,18 +823,74 @@ mod tests { assert!(acb.contains(" major=4 evidence=none\n"), "{acb}"); } + /// The composition the boot runs, over a fresh adapter and session, published as the boot + /// publishes it. `install_uri` stands for the platform's URI installer. + #[cfg(feature = "play-uri")] + fn composed_and_published(controlled: bool, + install_uri: impl FnOnce(&mut PlayerAdapter) -> Option) + -> (PlayerAdapter, plx_media::route::PlaybackSession) { + let mut adapter = PlayerAdapter::new(unsafe { MainThread::assume() }); + let mut session = plx_media::route::PlaybackSession::IDLE; + let composed = compose_with(&mut adapter, controlled, install_uri); + crate::app::platform::publish_composition(&mut session, &adapter, composed); + (adapter, session) + } + + /// The URI installer a normal boot runs, over ports that take any driver: the product with no + /// window path, which installs and answers a resolver. + #[cfg(feature = "play-uri")] + fn product_over_null_ports(adapter: &mut PlayerAdapter) -> Option { + install_uri_product_with_ports(adapter, UriProduct::production(UriBinding::Unbound), + &plx_os::tv::uri::NoUriMedia, &sink::NoSink) + } + + #[test] + #[cfg(feature = "play-uri")] + fn a_composed_uri_driver_is_published_with_its_resolver() { + let (adapter, session) = composed_and_published(false, product_over_null_ports); + assert!(adapter.composed_backends().uri, "the product driver installed"); + assert_eq!(session.backends(), adapter.composed_backends(), "the session is told the adapter's set"); + assert!(session.uri_preflight_port().is_some(), "and the resolver that driver comes with"); + } + + #[test] + #[cfg(feature = "play-uri")] + fn a_refused_uri_install_publishes_neither_the_driver_nor_a_resolver() { + // The physical install refuses a driver that claims the packet feed; the composition yields + // no resolver for it, and the adapter holds no URI driver. + let ports = (&plx_os::tv::uri::NoUriMedia, &sink::NoSink); + let (adapter, session) = composed_and_published(false, |adapter| { + install_uri_backend_with_ports(adapter, settings(true), ports.0, ports.1) + .map(|_| unreachable!("a packet-feed driver is refused")) + }); + assert!(!adapter.composed_backends().uri); + assert!(!session.backends().uri, "the session offers no URI backend"); + assert!(session.uri_preflight_port().is_none(), "and holds no resolver for one"); + assert_eq!(session.backends(), adapter.composed_backends()); + } + #[test] #[cfg(feature = "play-uri")] - fn the_session_set_gains_uri_only_when_the_product_driver_is_installed() { + fn a_controlled_boot_composes_no_uri_driver_and_never_asks_for_one() { + let (adapter, session) = composed_and_published(true, |_| { + panic!("a controlled run touches no native port, so it installs no URI driver") + }); + assert!(!adapter.composed_backends().uri); + assert!(!session.backends().uri); + assert!(session.uri_preflight_port().is_none()); + assert_eq!(session.backends(), adapter.composed_backends(), + "the Feed is composed as in a normal boot (or the build has none)"); + } + + #[test] + fn the_desktop_composition_is_the_feed_and_no_resolver() { let mut adapter = PlayerAdapter::new(unsafe { MainThread::assume() }); - let mut session = PlaybackSession::IDLE; - // A controlled run installs no driver: the set is what the drivers form, not what - // Cargo features were on. - compose_backends(&mut adapter, &mut session, true); - assert!(!session.backends().contains(plx_playback_contract::BackendKind::Uri)); - compose_backends(&mut adapter, &mut session, false); - assert!(session.backends().contains(plx_playback_contract::BackendKind::Uri), - "an installed product driver is offered"); + let mut session = plx_media::route::PlaybackSession::IDLE; + compose_feed(&mut adapter); + crate::app::platform::publish_composition(&mut session, &adapter, Composition::NONE); + assert_eq!(session.backends(), adapter.composed_backends()); + assert!(!session.backends().uri); + assert!(session.uri_preflight_port().is_none()); } #[cfg(feature = "play-uri")] @@ -971,9 +1063,8 @@ mod tests { fn the_boot_log_names_the_display_the_installed_driver_reports() { let line = |binding| plx_base::eventlog::with_private_log(|| { let mut adapter = PlayerAdapter::new(unsafe { MainThread::assume() }); - let mut session = PlaybackSession::IDLE; - assert!(install_uri_product_with_ports(&mut adapter, &mut session, - UriProduct::production(binding), &plx_os::tv::uri::NoUriMedia, &sink::NoSink)); + assert!(install_uri_product_with_ports(&mut adapter, + UriProduct::production(binding), &plx_os::tv::uri::NoUriMedia, &sink::NoSink).is_some()); std::fs::read_to_string(plx_base::eventlog::events_log()).unwrap_or_default() }); let acb = line(UriBinding::Acb); diff --git a/rust-modules/src/app/boot.rs b/rust-modules/src/app/boot.rs index 1645c2d47..121f476f9 100644 --- a/rust-modules/src/app/boot.rs +++ b/rust-modules/src/app/boot.rs @@ -1974,7 +1974,7 @@ pub(crate) unsafe fn construct( activate_session(&mut bridge, &mut pages, &mut super::recorder::Recplay::Off) }; if !controlled { - super::adapters::backends::acb_init(&mt); // every backend set: the plane owner's boot facts + (platform.media.early_init)(&mt); // every backend set: the platform's boot facts (webOS: the plane owner's) plx_media_codecs::ffi::boot(); // Codec resource boot; controlled Home cannot invoke ABI probes. } // dev: /tmp/plxnative-logintest validates the plex.tv account path end-to-end on the device — a @@ -2249,12 +2249,13 @@ pub(crate) unsafe fn construct( let adapters = super::Adapters { player: plx_media::player::adapter::PlayerAdapter::new(mt), }; - // The session's backend set is the one the installed drivers form (after the product URI driver - // is installed, and for every build, not only a URI one). + // The platform installs its drivers, and the session is told what they form: the set and the + // resolver, together, for every platform (`platform::publish_composition`). let (player, adapters) = { let mut player = player; let mut adapters = adapters; - super::adapters::backends::compose_backends(&mut adapters.player, &mut player.session, controlled); + let composed = (platform.media.compose)(&mut adapters.player, controlled); + super::platform::publish_composition(&mut player.session, &adapters.player, composed); (player, adapters) }; let repause_at = 0i64; diff --git a/rust-modules/src/app/platform.rs b/rust-modules/src/app/platform.rs index d9ffd985a..785ce0a87 100644 --- a/rust-modules/src/app/platform.rs +++ b/rust-modules/src/app/platform.rs @@ -1,7 +1,7 @@ //! The platform the application runs on, as only the loop reads it. //! //! [`Platform`] is the one value a platform's entry hands `run_application`, so an entry that forgot -//! it does not compile. It carries three things, split by who reads them: +//! it does not compile. It carries four things, split by who reads them: //! //! - `services`: [`plx_os::tv::Services`], what the LOWER layers read through the private `tv` //! accessors (identity, the secure store, Home and the toast, the legacy webOS media verbs). @@ -12,11 +12,20 @@ //! hooks. //! - `diag`: the six frame probes, [`FrameProbe`], read by the loop. The renderer's clear hook takes //! plain functions, so the platform's entry installs it (`gfx::install_clear_probe`). +//! - `media`: [`MediaBoot`], the platform's two boot-time playback steps. `early_init` runs once before +//! the first adapter exists; `compose` installs the platform's drivers on the adapter and hands +//! back what it composed as a [`Composition`]. The boot then tells the route session what the +//! platform composed through [`publish_composition`], the one function that does, so the set of +//! installed drivers and the resolver the planner reads cannot disagree. //! //! `Shell`, `FrameProbe` and `Platform` are app-private on purpose: no type a platform's shell has //! to match leaves the application crate until the platform contract is settled. The webOS value is //! built by `port.rs`; `ci/check-deps.sh`'s `frame` gate pins the call text of the three //! privileged calls (`pump_bus`, `opaque_route`, `clear_opaque_region`) to `app/run.rs`. +use plx_base::task::MainThread; +use plx_media::player::adapter::PlayerAdapter; +use plx_media::route::uri_preflight::ResolvePort; +use plx_media::route::PlaybackSession; use plx_os::tv::Services; use std::os::raw::c_void; @@ -60,6 +69,55 @@ pub(crate) trait FrameProbe: Sync { fn fields(&self) -> String; } +/// What a platform's composition installed that the route session also has to know: the resolver the +/// planner asks before it offers a URI source. `Some` only when the physical URI install succeeded, +/// so it is present exactly when the composed set holds a URI driver. +pub(crate) struct Composition { + pub(crate) resolver: Option, +} + +impl Composition { + /// A platform that composed no URI driver: Feed or nothing, and no resolver. + pub(crate) const NONE: Composition = Composition { resolver: None }; +} + +/// A platform's two playback steps at boot. Both are plain functions: the platform's entry states +/// them once, in its `static`, and the boot calls them through [`Platform::media`]. +pub(crate) struct MediaBoot { + /// Before the first adapter exists, once per process. The caller runs it only on a boot that + /// touches the television (not a controlled one), so a platform's body never asks. + pub(crate) early_init: fn(&MainThread), + /// Install this platform's drivers on the adapter, and return what the session must also be told. + /// `controlled` is a replay or scripted Home, which touches no native port and so installs no + /// native driver. It takes no session and publishes nothing: [`publish_composition`] does that. + pub(crate) compose: fn(&mut PlayerAdapter, controlled: bool) -> Composition, +} + +/// Tell the route session what the platform composed: the resolver first, then the backend set the +/// adapter's installed drivers form, and log what it published in the one `compose:` line (the +/// television's boot log shows it). One call, every boot, for every platform: a platform that +/// composed nothing still publishes `BackendSet::NONE` (and no resolver), instead of leaving the +/// session on the Feed-only default, which would offer a backend nothing installed. +pub(crate) fn publish_composition( + session: &mut PlaybackSession, + adapter: &PlayerAdapter, + composed: Composition, +) { + let set = adapter.composed_backends(); + let named = match (set.uri, set.feed) { + (true, true) => "uri+feed", + (true, false) => "uri", + (false, true) => "feed", + (false, false) => "none", + }; + plx_base::eventlog::log(&format!( + "compose: backends={named} resolver={}", + if composed.resolver.is_some() { "yes" } else { "no" } + )); + session.install_uri_preflight_port(composed.resolver); + session.install_backends(set); +} + /// Everything the application needs from its platform. Built by the platform's entry (`port.rs` for /// webOS) with [`Platform::new`] and passed to `run_application`, which keeps it as `App::platform`. /// @@ -71,16 +129,18 @@ pub(crate) struct Platform { services: &'static Services, pub(crate) shell: &'static dyn Shell, pub(crate) diag: &'static dyn FrameProbe, + pub(crate) media: MediaBoot, } impl Platform { - /// A platform's entry states its three parts once, in a `static`. + /// A platform's entry states its four parts once, in a `static`. pub(crate) const fn new( services: &'static Services, shell: &'static dyn Shell, diag: &'static dyn FrameProbe, + media: MediaBoot, ) -> Self { - Platform { services, shell, diag } + Platform { services, shell, diag, media } } /// Hand the lower layers the platform's `tv` services, once: `run_application` does it before @@ -124,12 +184,27 @@ impl FrameProbe for HostProbe { } } +#[cfg(test)] +impl MediaBoot { + /// The media boot of a process with no platform: nothing to initialize and no driver to install. + pub(crate) const HOST_TEST: MediaBoot = MediaBoot { early_init: host_test_early_init, compose: host_test_compose }; +} + +#[cfg(test)] +fn host_test_early_init(_mt: &MainThread) {} + +#[cfg(test)] +fn host_test_compose(_adapter: &mut PlayerAdapter, _controlled: bool) -> Composition { + Composition::NONE +} + #[cfg(test)] impl Platform { /// No platform: the loop's host tests, which build an `App` without an entry and say so by passing /// this to it. Every entry is what the no-port defaults answered before the shell and the probe /// left `tv`. It exists in test builds only: a production entry that passes it does not compile. - pub(crate) const HOST_TEST: Platform = Platform::new(&Services::HOST_TEST, &HostShell, &HostProbe); + pub(crate) const HOST_TEST: Platform = + Platform::new(&Services::HOST_TEST, &HostShell, &HostProbe, MediaBoot::HOST_TEST); } #[cfg(test)] @@ -142,7 +217,7 @@ mod tests { /// call text of the loop's own receiver, and this is the no-op one. #[test] fn the_host_test_platform_answers_nothing_and_says_so() { - let Platform { services, shell: s, diag: p } = Platform::HOST_TEST; + let Platform { services, shell: s, diag: p, media } = Platform::HOST_TEST; assert!( matches!((services.identity.system_locale)(), plx_os::tv::LocaleReply::NoPlatform), @@ -165,5 +240,27 @@ mod tests { p.waiting(); p.acquired(); assert_eq!(p.fields(), "", "an unarmed probe has nothing to log"); + + // SAFETY: a host test owns the one thread it runs the media boot on. + let mt = unsafe { MainThread::assume() }; + (media.early_init)(&mt); + let mut adapter = PlayerAdapter::new(mt); + let composed = (media.compose)(&mut adapter, false); + assert!(composed.resolver.is_none(), "the host platform composes no URI driver"); + assert_eq!(adapter.composed_backends(), plx_playback_contract::BackendSet::NONE, + "and installs no driver of any kind"); + } + + /// **The one publisher.** A platform that composed nothing still publishes: the session leaves + /// its Feed-only default for `NONE`, and the resolver is the absence the compose returned. + #[test] + fn publishing_a_composition_that_installed_nothing_replaces_the_feed_default_with_none() { + let mut session = PlaybackSession::IDLE; + assert_eq!(session.backends(), plx_playback_contract::BackendSet::FEED, + "the session starts on the Feed-only default"); + let adapter = PlayerAdapter::new(unsafe { MainThread::assume() }); + publish_composition(&mut session, &adapter, Composition::NONE); + assert_eq!(session.backends(), plx_playback_contract::BackendSet::NONE); + assert!(session.uri_preflight_port().is_none()); } } diff --git a/rust-modules/src/app/playback.rs b/rust-modules/src/app/playback.rs index c8196e575..9ebc5ce0d 100644 --- a/rust-modules/src/app/playback.rs +++ b/rust-modules/src/app/playback.rs @@ -532,7 +532,6 @@ pub(crate) fn close_player_overlays(pages: &mut plx_ui::dispatch::Dispatcher { - #[cfg(feature = "play-uri")] if ps.attempt_view().backend() == Some(plx_media::player::attempt_view::Backend::Uri) { if pa.uri_maps_track(ps, plx_playback_contract::TrackKind::Audio, carried.sid) == Some(false) @@ -664,7 +660,6 @@ pub(crate) fn commit_track( // The route commits the pick and performs the sidecar half of it too // (`route::commit_subtitle_and_sidecar`): the sidecar policy lives beside the track memory's. TrackCommit::Subtitle { render_ordinal, stream_id, sidecar_key, sidecar_codec, memo } => { - #[cfg(feature = "play-uri")] if ps.attempt_view().backend() == Some(plx_media::player::attempt_view::Backend::Uri) { if render_ordinal < 0 || sidecar_key.is_some() || pa.uri_maps_track(ps, plx_playback_contract::TrackKind::Subtitle, @@ -683,7 +678,6 @@ pub(crate) fn commit_track( // the route holds the mode and remembers `ForcedOnly { lang }` when it changed, and drops // any sidecar (`route::commit_forced_only_and_sidecar`). TrackCommit::SubtitleForcedOnly { render_ordinal, stream_id, lang, changed } => { - #[cfg(feature = "play-uri")] if ps.attempt_view().backend() == Some(plx_media::player::attempt_view::Backend::Uri) { let memo = changed.then(|| plx_plex::plex::session::prefs::SubtitleMemo::ForcedOnly { diff --git a/rust-modules/src/app/run.rs b/rust-modules/src/app/run.rs index c0d8025e3..dd5ba848b 100644 --- a/rust-modules/src/app/run.rs +++ b/rust-modules/src/app/run.rs @@ -2288,7 +2288,6 @@ pub(crate) unsafe fn playback_tick(app: &mut App, fr: &mut Frame) { let _ = app.adapters.player.backend_set_foreground_at(&mut app.player.session, foreground, backend_at); // A playback the server ended is retired whichever backend plays it; the Feed's `pump` opens // with the same door. - #[cfg(feature = "play-uri")] if foreground { plx_media::player::retire_if_server_stopped(&mut app.player.session, &mut app.adapters.player); } @@ -2316,10 +2315,8 @@ pub(crate) unsafe fn playback_tick(app: &mut App, fr: &mut Frame) { // Engine and is polled here on every frame as well. let backend_at = app.adapters.player.backend_tick(); let _ = app.adapters.player.backend_poll_session_at(&mut app.player.session, backend_at); - #[cfg(feature = "play-uri")] super::playback::drain_uri_track_fallbacks(&mut app.player.session, &mut app.adapters.player, app.runtime.metadata_mut()); - #[cfg(feature = "play-uri")] if let Some(recovery) = app.adapters.player.take_released_uri_recovery() { // The driver has proved this exact URI owner Released and the adapter has retired // its reporter. Re-resolve the same source episode before generic report::tick can @@ -2957,7 +2954,6 @@ pub(crate) unsafe fn update(app: &mut App, fr: &mut Frame) { app.note_presentation_damage(plx_machine::present::Provenance::Lifecycle); // The resolved URI locator is an owned IO result. Install it against the // route ticket before the common start door chooses a physical backend. - #[cfg(feature = "play-uri")] if let Some(offer) = r.uri_offer { let offer_id = offer.offer_id(); if app.adapters.player.offer_qualified_uri(&mut app.player.session, offer).is_err() { diff --git a/rust-modules/src/app/run_uri_boot_tests.rs b/rust-modules/src/app/run_uri_boot_tests.rs index 94cd0151f..06c12a822 100644 --- a/rust-modules/src/app/run_uri_boot_tests.rs +++ b/rust-modules/src/app/run_uri_boot_tests.rs @@ -212,7 +212,7 @@ mod uri_boot_tests { subtitle_track: true, audio_off: false, subtitle_off: false }; let product = UriProduct { binding: Binding::Exported { canvas: (1920, 1080) }, callable: caps, certified: caps, qualifier: Arc::new(QualifiedOriginal) }; - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, product, bus, display)); rig.request(); let metric_request = rig.app.player.session.metric_request().expect("accepted URI request"); @@ -278,7 +278,7 @@ mod uri_boot_tests { .set_link(plx_plex::plex::probe::Location::Local); let bus: &'static Bus = Box::leak(Box::new(Bus::new())); let display: &'static Display = Box::leak(Box::new(Display)); - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, composed_product(true, display), bus, display)); rig.request(); @@ -315,7 +315,7 @@ mod uri_boot_tests { .set_link(plx_plex::plex::probe::Location::Local); let bus: &'static Bus = Box::leak(Box::new(Bus::new())); let display: &'static Display = Box::leak(Box::new(Display)); - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, composed_product(false, display), bus, display)); rig.request(); @@ -343,7 +343,7 @@ mod uri_boot_tests { let display: &'static Display = Box::leak(Box::new(Display)); let product = UriProduct { binding: Binding::Unbound, callable: ProductEvidence::CALLABLE, certified: ProductEvidence::UNCERTIFIED, qualifier: Arc::new(QualifiedOriginal) }; - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, product, bus, display)); rig.request(); rig.release.send(()).unwrap(); @@ -380,7 +380,7 @@ mod uri_boot_tests { subtitle_track: false, audio_off: false, subtitle_off: false }; let product = UriProduct { binding: Binding::Exported { canvas: (1920, 1080) }, callable: caps, certified: caps, qualifier: Arc::new(QualifiedOriginal) }; - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, product, bus, display)); rig.request(); rig.release.send(()).unwrap(); @@ -435,7 +435,7 @@ mod uri_boot_tests { subtitle_track: false, audio_off: false, subtitle_off: false }; let product = UriProduct { binding: Binding::Exported { canvas: (1920, 1080) }, callable: caps, certified: caps, qualifier: Arc::new(QualifiedOriginal) }; - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, product, bus, display)); rig.request(); assert!(plx_media::route::arm_play_resume(&mut rig.app.player.session, 12_000_000_000), @@ -499,7 +499,7 @@ mod uri_boot_tests { .set_link(plx_plex::plex::probe::Location::Local); let bus: &'static Bus = Box::leak(Box::new(Bus::new())); let display: &'static Display = Box::leak(Box::new(Display)); - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, acb_product(trigger), bus, display)); rig.request(); @@ -637,7 +637,7 @@ mod uri_boot_tests { subtitle_track: true, audio_off: false, subtitle_off: false }; let product = UriProduct { binding: Binding::Exported { canvas: (1920, 1080) }, callable: caps, certified: caps, qualifier: Arc::new(QualifiedOriginal) }; - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, product, bus, display)); rig.request(); let request = rig.app.player.session.metric_request().expect("logical request"); @@ -718,7 +718,7 @@ mod uri_boot_tests { subtitle_track: true, audio_off: false, subtitle_off: false }; let product = UriProduct { binding: Binding::Exported { canvas: (1920, 1080) }, callable: caps, certified: caps, qualifier: Arc::new(QualifiedOriginal) }; - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, product, bus, display)); rig.request(); let request = rig.app.player.session.metric_request().expect("logical request"); @@ -783,7 +783,7 @@ mod uri_boot_tests { subtitle_track: true, audio_off: false, subtitle_off: false }; let product = UriProduct { binding: Binding::Exported { canvas: (1920, 1080) }, callable: caps, certified: caps, qualifier: Arc::new(QualifiedOriginal) }; - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, product, bus, display)); rig.request(); let request = rig.app.player.session.metric_request().expect("logical request"); @@ -892,7 +892,7 @@ mod uri_boot_tests { subtitle_track: true, audio_off: false, subtitle_off: false }; let product = UriProduct { binding: Binding::Exported { canvas: (1920, 1080) }, callable: caps, certified: caps, qualifier: Arc::new(QualifiedOriginal) }; - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, product, bus, display)); rig.request(); rig.release.send(()).unwrap(); @@ -1017,7 +1017,7 @@ mod uri_boot_tests { subtitle_track: true, audio_off: false, subtitle_off: false }; let product = UriProduct { binding: Binding::Exported { canvas: (1920, 1080) }, callable: caps, certified: caps, qualifier: Arc::new(QualifiedTwoAudio) }; - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, product, bus, display)); rig.request(); rig.release.send(()).unwrap(); @@ -1098,7 +1098,7 @@ mod uri_boot_tests { subtitle_track: true, audio_off: false, subtitle_off: false }; let product = UriProduct { binding: Binding::Exported { canvas: (1920, 1080) }, callable: caps, certified: caps, qualifier: Arc::new(QualifiedOriginal) }; - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, product, bus, display)); rig.request(); rig.release.send(()).unwrap(); @@ -1154,7 +1154,7 @@ mod uri_boot_tests { subtitle_track: true, audio_off: false, subtitle_off: false }; let product = UriProduct { binding: Binding::Exported { canvas: (1920, 1080) }, callable: caps, certified: caps, qualifier: Arc::new(QualifiedTwoAudio) }; - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, product, bus, display)); rig.request(); rig.release.send(()).unwrap(); @@ -1213,7 +1213,7 @@ mod uri_boot_tests { subtitle_track: true, audio_off: false, subtitle_off: false }; let product = UriProduct { binding: Binding::Exported { canvas: (1920, 1080) }, callable: caps, certified: caps, qualifier: Arc::new(QualifiedOriginal) }; - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, product, bus, display)); rig.request(); rig.release.send(()).unwrap(); @@ -1286,7 +1286,7 @@ mod uri_boot_tests { subtitle_track: true, audio_off: false, subtitle_off: false }; let product = UriProduct { binding: Binding::Exported { canvas: (1920, 1080) }, callable: caps, certified: caps, qualifier: Arc::new(QualifiedOriginal) }; - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, product, bus, display)); rig.request(); rig.release.send(()).unwrap(); @@ -1349,7 +1349,7 @@ mod uri_boot_tests { subtitle_track: true, audio_off: false, subtitle_off: false }; let product = UriProduct { binding: Binding::Exported { canvas: (1920, 1080) }, callable: caps, certified: caps, qualifier: Arc::new(QualifiedOriginal) }; - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, product, bus, display)); rig.request(); rig.release.send(()).unwrap(); @@ -1468,9 +1468,10 @@ mod uri_boot_tests { const WINDOW_STARTUP_MS: u64 = 1_000; const WINDOW_RELEASE_MS: u64 = 500; - /// Compose the URI driver as the boot does (`install_uri_product_with_ports`: the opted-in - /// viewer's capabilities over an exported canvas), but on `clock` with short allowances, over - /// `display`, so a startup timeout and an unreleased close are reachable by moving the clock. + /// Compose the URI driver as the boot does (the opted-in viewer's capabilities over an exported + /// canvas, published through `platform::publish_composition`), but on `clock` with short + /// allowances, over `display`, so a startup timeout and an unreleased close are reachable by + /// moving the clock. fn install_exported_uri(rig: &mut Rig, bus: &'static Bus, display: &'static CountingDisplay, clock: Arc) { let caps = Capabilities { progressive_uri: true, hls_uri: false, @@ -1490,10 +1491,11 @@ mod uri_boot_tests { let path = crate::app::adapters::backends::install_uri_backend_with_ports( &mut rig.app.adapters.player, settings, bus, display) .expect("the URI driver installs"); - rig.app.player.session.install_uri_preflight_port( - plx_media::route::uri_preflight::ResolvePort::new( - ProductEvidence { display: path, callable: product.callable, - certified: product.certified }, product.qualifier)); + let resolver = plx_media::route::uri_preflight::ResolvePort::new( + ProductEvidence { display: path, callable: product.callable, + certified: product.certified }, product.qualifier); + crate::app::platform::publish_composition(&mut rig.app.player.session, + &rig.app.adapters.player, crate::app::platform::Composition { resolver: Some(resolver) }); } /// One frame of the app loop's playback half, as the other URI fixtures run it. @@ -1635,7 +1637,7 @@ mod uri_boot_tests { packet_feed: false, pause: true, seek: true, audio_track: true, subtitle_track: true, audio_off: false, subtitle_off: false }; let product = UriProduct { binding: Binding::Acb, callable: caps, certified: caps, qualifier }; - assert!(crate::app::adapters::backends::install_uri_product_with_ports( + assert!(crate::app::adapters::backends::install_and_publish_uri_product( &mut rig.app.adapters.player, &mut rig.app.player.session, product, bus, display)); assert!(display.created_player_types().is_empty(), "composing the driver creates no handle"); (bus, display) diff --git a/rust-modules/src/dev/uriprobe.rs b/rust-modules/src/dev/uriprobe.rs index 4889830fd..9cf142e84 100644 --- a/rust-modules/src/dev/uriprobe.rs +++ b/rust-modules/src/dev/uriprobe.rs @@ -19,7 +19,7 @@ use plx_media::route::RouteStartAttempt; use plx_play_uri::uriprobe::{AbrBps, Firmware, Kind, Settle, Trigger, Variant}; use plx_play_uri::uriprobe_drive::{DriverConfig, UriSession as CoreSession}; -/// Install the probe on the player adapter, once, at boot (`compose_backends`). +/// Install the probe on the player adapter, once, at boot (`backends::compose_with`). pub(crate) fn install(adapter: &mut PlayerAdapter) { adapter.install_uri_probe(Box::new(Probe)); } diff --git a/rust-modules/src/dev/uriprobe_tests.rs b/rust-modules/src/dev/uriprobe_tests.rs index 95bf499d7..5ddd8183e 100644 --- a/rust-modules/src/dev/uriprobe_tests.rs +++ b/rust-modules/src/dev/uriprobe_tests.rs @@ -924,7 +924,7 @@ mod hostsim { plx_media::route::CandidatePurpose::NewCandidate), "the prepared fixture source must qualify its stable Feed recipe"); let mut pa = crate::app::adapters::backends::test_adapter(); - // The composition installs the probe at boot (`compose_backends`); the fork is a boot. + // The composition installs the probe at boot (`backends::compose_with`); the fork is a boot. super::super::install(&mut pa); Fork { ps, pa, pms, _host: host } } diff --git a/rust-modules/src/platform_desktop.rs b/rust-modules/src/platform_desktop.rs index b4cb8f580..c13ea0852 100644 --- a/rust-modules/src/platform_desktop.rs +++ b/rust-modules/src/platform_desktop.rs @@ -25,7 +25,7 @@ //! made one of them reachable would fail to link for want of libwayland, glib or luna-service2, on //! a Mac and on Linux alike. `simulators.yml` links the shapes the simulator ships in to guard that //! until the platform crates split (`docs/platform-ports.md`, W7). -use crate::app::platform::{FrameProbe, Platform, Shell}; +use crate::app::platform::{Composition, FrameProbe, MediaBoot, Platform, Shell}; use plx_os::devcaps::dv::{self, DvCapability, DvProbe, ProbeSource}; use plx_os::tv::toast::{Identity, Outcome, Sent}; use plx_os::tv::{IdentityHooks, LegacyWebosMedia, SecureHooks, Services, SystemHooks}; @@ -124,8 +124,24 @@ impl FrameProbe for DesktopProbe { } } +/// The desktop's media boot: nothing to initialize before the first adapter (the plane owner's +/// default facts are the absent ones the host sink's `VP_EXPORTED`/`VP_NONE` boot would state), and +/// the Feed over the host sink as its only driver. It composes no URI driver (that is the +/// television's ACB driver), so it returns no resolver and the session is published the Feed alone. +fn media_early_init(_mt: &plx_base::task::MainThread) {} + +fn media_compose(adapter: &mut plx_media::player::adapter::PlayerAdapter, _controlled: bool) -> Composition { + crate::app::adapters::backends::compose_feed(adapter); + Composition::NONE +} + /// The desktop platform: what [`run`] hands `app::run_application`. -static PLATFORM: Platform = Platform::new(&SERVICES, &DesktopShell, &DesktopProbe); +static PLATFORM: Platform = Platform::new( + &SERVICES, + &DesktopShell, + &DesktopProbe, + MediaBoot { early_init: media_early_init, compose: media_compose }, +); /// The desktop entry: boot the application on [`PLATFORM`] and return the status it ended with. /// Ending the process is the executable's (`src/bin/sim.rs`), which owns it, like the television's @@ -141,13 +157,12 @@ pub fn run(pms_host: &CStr, pms_port: u16) -> c_int { mod tests { use super::*; - /// The app's plane boot resolves the display through `display_installed()` (this table's - /// `display_sink`), where media's old `acb_init` resolved it through `player::display()`. In - /// the simulator both must be the host sink, never `NoSink`: a boot that read `NoSink` would - /// report no plane to every backend and nothing in a simulator run would say so. + /// The Feed's sink and the display the plane reads (`display_installed()`, this table's + /// `display_sink`) are the one host sink in the simulator, never `NoSink`: a Feed that read + /// `NoSink` would report no plane and nothing in a simulator run would say so. #[cfg(feature = "play-feed")] #[test] - fn the_simulator_port_display_is_the_host_sink_the_acb_init_reads() { + fn the_simulator_port_display_is_the_host_sink() { let host = std::ptr::from_ref(&crate::app::adapters::hostsim::HOST_SINK).cast::<()>(); let media = &SERVICES.legacy_webos_media; assert_eq!(std::ptr::from_ref(media.display_sink).cast::<()>(), host, diff --git a/rust-modules/src/port.rs b/rust-modules/src/port.rs index 7f717ca52..58dac38ed 100644 --- a/rust-modules/src/port.rs +++ b/rust-modules/src/port.rs @@ -6,7 +6,8 @@ //! video sink together. The simulator and the macOS app are not on these tables: they are their own //! platform (`platform_desktop`), which never names this module, so a desktop build compiles the //! television's code and the linker drops it. -use crate::app::platform::{FrameProbe, Platform, Shell}; +use crate::app::adapters::backends; +use crate::app::platform::{FrameProbe, MediaBoot, Platform, Shell}; use std::os::raw::{c_char, c_int, c_void}; #[cfg(all(not(test), feature = "play-feed"))] @@ -102,8 +103,16 @@ impl FrameProbe for WebosProbe { } /// The webOS platform: what `plex_main` hands `app::run_application`, which installs its services -/// for the lower layers and keeps it for the loop. -static PLATFORM: Platform = Platform::new(&SERVICES, &WebosShell, &WebosProbe); +/// for the lower layers and keeps it for the loop. Its media boot is the television's: the plane +/// owner's boot, and the Feed plus the product URI driver. The bodies are the application's +/// `adapters::backends` until the webOS platform owns that file: the dev surface and the tests name the +/// URI product there, and nothing outside this module may name `port`. +static PLATFORM: Platform = Platform::new( + &SERVICES, + &WebosShell, + &WebosProbe, + MediaBoot { early_init: backends::acb_init, compose: backends::compose_native }, +); /// The C shim's entry (`src/main.c`). The `-> c_int` is only the C signature: `plex_main` never /// returns, so neither does this. From b951d2ae454ae1ce90963fe4e84677ac12a79eb3 Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 16:10:54 +0300 Subject: [PATCH 2/3] Composition has a Default instead of a NONE constant, and the prose follows the desktop change A platform that composed no URI driver returns Composition::default(). The NONE constant was read only by the simulator's platform, so a television build that does not compile the simulator saw it as dead code and refused to build. Three sentences that the desktop change made false are corrected: the module-layers note that every play-uri build resolves the URI media pipe at boot, the desktop DISPLAY constant's note about a plane boot the simulator no longer runs, and the per-file counts of the play-uri sites that remain. Co-Authored-By: Claude --- docs/module-layers.md | 4 ++-- docs/platform-ports.md | 7 ++++--- rust-modules/src/app/adapters/backends.rs | 2 +- rust-modules/src/app/platform.rs | 12 +++++------- rust-modules/src/platform_desktop.rs | 11 ++++++----- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/module-layers.md b/docs/module-layers.md index 06df7a3e2..7e1191a36 100644 --- a/docs/module-layers.md +++ b/docs/module-layers.md @@ -358,8 +358,8 @@ Only `tv`'s own modules read the table. Two things leave it: the sink, through `tv::sink::installed()` (rule `sink` of `ci/check-deps.sh` fences naming `VideoSink` or `installed` to `media`'s `player/`, `play-uri/`, `os`'s `tv/`, `tv.rs` and `webos/`, `port.rs`, `platform_desktop.rs` (each platform's table names its own sink) and `app/adapters/backends.rs`; `play-feed/` may name the trait but never resolves `installed`), and the URI media pipe through -`tv::uri::installed()`, resolved once by the composition (`app/adapters/backends.rs::install_uri_product`, every build with the -`play-uri` feature) and, in a `devtriggers` build, again by the media wrapper `player::uriprobe_drive` for the developer probe. The independent +`tv::uri::installed()`, resolved once by the webOS platform's composition (`app/adapters/backends.rs::compose_native`, which calls +`install_uri_product`, in a build with the `play-uri` feature; the desktop platform composes the Feed only and never resolves it) and, in a `devtriggers` build, again by the media wrapper `player::uriprobe_drive` for the developer probe. The independent `play-uri` driver receives that transport and a shared `DisplaySink` as injected ports; it does not read the webOS port registry or the feed-only `VideoSink` itself. Lazily computed facts (device identity, the sandbox verdict, the Dolby Vision capability) are diff --git a/docs/platform-ports.md b/docs/platform-ports.md index fa05e6eba..cd4c23684 100644 --- a/docs/platform-ports.md +++ b/docs/platform-ports.md @@ -1016,8 +1016,9 @@ Ecore names to `remote_token_key` pairs". webOS-only. `PLAYBACK_BACKENDS` maps per platform (Tizen: its own `uri` feature; `play-uri` never). The `feature = "play-uri"` sites in `rust-modules/src` (37 when this was written, 51 at W6b: #1478 added 14 to `backends.rs`) are sorted in W6b: the 10 in `playback.rs` and `run.rs` read the installed drivers at run - time (the attempt's backend, the adapter's queues, the resolver's offer) and lost their gate; the other 41 name - ACB or the URI product (`backends.rs` 35, `dev.rs`, `lib.rs`'s ARM guard, two test files) and keep theirs. + time (the attempt's backend, the adapter's queues, the resolver's offer) and lost their gate; every site that + remains names ACB or the URI product and keeps it (`git grep -n 'feature = "play-uri"' -- rust-modules/src` + lists them: `backends.rs`, `dev.rs`, `lib.rs`'s ARM guard and two test files). Composition is a SEAM until W11a, not a move: `port.rs` fills `Platform.media` with `backends::acb_init` and `backends::compose_native`, and the bodies stay in `app/adapters/backends.rs`. They cannot go to `port` yet, because `dev/uri_product.rs`, `dev/uri_exported.rs`, `run_uri_boot_tests.rs` and @@ -1598,7 +1599,7 @@ W3d. Neutral types (L15b item 2 prerequisites; part of item 3). `Platform.media` with `backends::acb_init` and `backends::compose_native`; the bodies stay in `app/adapters/backends.rs` until W11a, because dev and the tests name `UriProduct` and its siblings and the fence forbids them naming `port`. `early_init` is called at the old `acb_init` line and `compose` at the old - `compose_backends` line, so neither phase moved. `dev.rs`, `lib.rs`, `dev/uriprobe_tests.rs` and the `sink` + `compose_backends` line, so neither phase moved. `dev.rs`, `lib.rs` and the `sink` rule are unchanged (`backends.rs` stays an allowed path). The desktop composes the Feed over the host sink and no URI driver; its `early_init` is a no-op. diff --git a/rust-modules/src/app/adapters/backends.rs b/rust-modules/src/app/adapters/backends.rs index 522d03ea9..2fb5d8e50 100644 --- a/rust-modules/src/app/adapters/backends.rs +++ b/rust-modules/src/app/adapters/backends.rs @@ -887,7 +887,7 @@ mod tests { let mut adapter = PlayerAdapter::new(unsafe { MainThread::assume() }); let mut session = plx_media::route::PlaybackSession::IDLE; compose_feed(&mut adapter); - crate::app::platform::publish_composition(&mut session, &adapter, Composition::NONE); + crate::app::platform::publish_composition(&mut session, &adapter, Composition::default()); assert_eq!(session.backends(), adapter.composed_backends()); assert!(!session.backends().uri); assert!(session.uri_preflight_port().is_none()); diff --git a/rust-modules/src/app/platform.rs b/rust-modules/src/app/platform.rs index 785ce0a87..87765c0e7 100644 --- a/rust-modules/src/app/platform.rs +++ b/rust-modules/src/app/platform.rs @@ -72,15 +72,13 @@ pub(crate) trait FrameProbe: Sync { /// What a platform's composition installed that the route session also has to know: the resolver the /// planner asks before it offers a URI source. `Some` only when the physical URI install succeeded, /// so it is present exactly when the composed set holds a URI driver. +/// +/// `Composition::default()` is a platform that composed no URI driver (the Feed or nothing): no resolver. +#[derive(Default)] pub(crate) struct Composition { pub(crate) resolver: Option, } -impl Composition { - /// A platform that composed no URI driver: Feed or nothing, and no resolver. - pub(crate) const NONE: Composition = Composition { resolver: None }; -} - /// A platform's two playback steps at boot. Both are plain functions: the platform's entry states /// them once, in its `static`, and the boot calls them through [`Platform::media`]. pub(crate) struct MediaBoot { @@ -195,7 +193,7 @@ fn host_test_early_init(_mt: &MainThread) {} #[cfg(test)] fn host_test_compose(_adapter: &mut PlayerAdapter, _controlled: bool) -> Composition { - Composition::NONE + Composition::default() } #[cfg(test)] @@ -259,7 +257,7 @@ mod tests { assert_eq!(session.backends(), plx_playback_contract::BackendSet::FEED, "the session starts on the Feed-only default"); let adapter = PlayerAdapter::new(unsafe { MainThread::assume() }); - publish_composition(&mut session, &adapter, Composition::NONE); + publish_composition(&mut session, &adapter, Composition::default()); assert_eq!(session.backends(), plx_playback_contract::BackendSet::NONE); assert!(session.uri_preflight_port().is_none()); } diff --git a/rust-modules/src/platform_desktop.rs b/rust-modules/src/platform_desktop.rs index c13ea0852..017b99f6b 100644 --- a/rust-modules/src/platform_desktop.rs +++ b/rust-modules/src/platform_desktop.rs @@ -39,7 +39,8 @@ const SINK: &dyn plx_os::tv::sink::VideoSink = &crate::app::adapters::hostsim::H #[cfg(not(feature = "play-feed"))] const SINK: &dyn plx_os::tv::sink::VideoSink = &plx_os::tv::sink::NoSink; -/// The display binding the player's plane boot resolves: the same sink, so the plane is the host's. +/// The display binding the table must state. The desktop runs no plane boot, so nothing reads it in +/// production; it is the host sink only so that the hook is never `NoSink`. const DISPLAY: &dyn plx_os::tv::sink::DisplaySink = SINK; /// What the lower layers read from the desktop platform. Every hook is stated, as `tv` requires: a @@ -132,7 +133,7 @@ fn media_early_init(_mt: &plx_base::task::MainThread) {} fn media_compose(adapter: &mut plx_media::player::adapter::PlayerAdapter, _controlled: bool) -> Composition { crate::app::adapters::backends::compose_feed(adapter); - Composition::NONE + Composition::default() } /// The desktop platform: what [`run`] hands `app::run_application`. @@ -157,9 +158,9 @@ pub fn run(pms_host: &CStr, pms_port: u16) -> c_int { mod tests { use super::*; - /// The Feed's sink and the display the plane reads (`display_installed()`, this table's - /// `display_sink`) are the one host sink in the simulator, never `NoSink`: a Feed that read - /// `NoSink` would report no plane and nothing in a simulator run would say so. + /// The video sink the Feed runs over and the display binding the table states are the one host + /// sink in the simulator, never `NoSink`: a Feed that ran over `NoSink` would show no picture + /// and nothing in a simulator run would say so. #[cfg(feature = "play-feed")] #[test] fn the_simulator_port_display_is_the_host_sink() { From 036034fe749d912ad25f930bc28b9fbc8f9f28bb Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Fri, 20 Nov 2026 16:44:01 +0300 Subject: [PATCH 3/3] The one-publisher rig helper is gated like its caller, and the composition tests run the production seams `install_and_publish_uri_product` is used only by the lifecycle rig, which `run.rs` builds under `hostsim` and `play-feed`; a plain lib-test build found it dead. It carries the rig's own cfg now. The success and controlled composition tests ran an injected installer, so after the move no test reached `compose_native`, `install_uri_product` (with the refusal line that moved into it) or the desktop's `media_compose`. The two tests call `compose_native`, as the base test called `compose_backends`; the desktop's shape is asserted through `PLATFORM.media.compose` in `platform_desktop.rs`, where it used to be a copy of that function's body; `compose_with` keeps the refused-install case, the one outcome that needs an injected failure. Co-Authored-By: Claude Sonnet 5.5 --- rust-modules/src/app/adapters/backends.rs | 50 ++++++++++------------- rust-modules/src/platform_desktop.rs | 17 ++++++++ 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/rust-modules/src/app/adapters/backends.rs b/rust-modules/src/app/adapters/backends.rs index 2fb5d8e50..6c22f7cb3 100644 --- a/rust-modules/src/app/adapters/backends.rs +++ b/rust-modules/src/app/adapters/backends.rs @@ -523,8 +523,9 @@ pub(crate) fn install_uri_product_with_ports(adapter: &mut PlayerAdapter, produc /// A host rig's composition of the product URI driver over its own ports, published as the boot /// publishes: the install, then [`publish_composition`](crate::app::platform::publish_composition) /// with the resolver it returned (the session learns the adapter's whole set, Feed included). -/// Whether the driver installed. -#[cfg(all(test, feature = "play-uri"))] +/// Whether the driver installed. Gated as its only caller is: the lifecycle rig's +/// `uri_boot_tests`, which `run.rs` builds under `hostsim` and `play-feed`. +#[cfg(all(test, feature = "hostsim", feature = "play-feed", feature = "play-uri"))] pub(crate) fn install_and_publish_uri_product(adapter: &mut PlayerAdapter, session: &mut plx_media::route::PlaybackSession, product: UriProduct, transport: &'static dyn plx_os::tv::uri::UriMedia, @@ -823,8 +824,20 @@ mod tests { assert!(acb.contains(" major=4 evidence=none\n"), "{acb}"); } - /// The composition the boot runs, over a fresh adapter and session, published as the boot - /// publishes it. `install_uri` stands for the platform's URI installer. + /// The television's own composition ([`compose_native`], which is what `Platform::media` names + /// for webOS, with the product installer behind it) over a fresh adapter and session, published + /// as the boot publishes it. + #[cfg(feature = "play-uri")] + fn composed_natively(controlled: bool) -> (PlayerAdapter, plx_media::route::PlaybackSession) { + let mut adapter = PlayerAdapter::new(unsafe { MainThread::assume() }); + let mut session = plx_media::route::PlaybackSession::IDLE; + let composed = compose_native(&mut adapter, controlled); + crate::app::platform::publish_composition(&mut session, &adapter, composed); + (adapter, session) + } + + /// The composition over an injected URI installer, for the one outcome the product installer + /// cannot be made to produce here: a refused install. #[cfg(feature = "play-uri")] fn composed_and_published(controlled: bool, install_uri: impl FnOnce(&mut PlayerAdapter) -> Option) @@ -836,18 +849,10 @@ mod tests { (adapter, session) } - /// The URI installer a normal boot runs, over ports that take any driver: the product with no - /// window path, which installs and answers a resolver. - #[cfg(feature = "play-uri")] - fn product_over_null_ports(adapter: &mut PlayerAdapter) -> Option { - install_uri_product_with_ports(adapter, UriProduct::production(UriBinding::Unbound), - &plx_os::tv::uri::NoUriMedia, &sink::NoSink) - } - #[test] #[cfg(feature = "play-uri")] fn a_composed_uri_driver_is_published_with_its_resolver() { - let (adapter, session) = composed_and_published(false, product_over_null_ports); + let (adapter, session) = composed_natively(false); assert!(adapter.composed_backends().uri, "the product driver installed"); assert_eq!(session.backends(), adapter.composed_backends(), "the session is told the adapter's set"); assert!(session.uri_preflight_port().is_some(), "and the resolver that driver comes with"); @@ -871,10 +876,10 @@ mod tests { #[test] #[cfg(feature = "play-uri")] - fn a_controlled_boot_composes_no_uri_driver_and_never_asks_for_one() { - let (adapter, session) = composed_and_published(true, |_| { - panic!("a controlled run touches no native port, so it installs no URI driver") - }); + fn a_controlled_boot_composes_no_uri_driver_and_no_resolver() { + // The same composition as the normal boot's test above, with the one flag a replay or a + // scripted Home sets: it touches no native port, so the product driver is not installed. + let (adapter, session) = composed_natively(true); assert!(!adapter.composed_backends().uri); assert!(!session.backends().uri); assert!(session.uri_preflight_port().is_none()); @@ -882,17 +887,6 @@ mod tests { "the Feed is composed as in a normal boot (or the build has none)"); } - #[test] - fn the_desktop_composition_is_the_feed_and_no_resolver() { - let mut adapter = PlayerAdapter::new(unsafe { MainThread::assume() }); - let mut session = plx_media::route::PlaybackSession::IDLE; - compose_feed(&mut adapter); - crate::app::platform::publish_composition(&mut session, &adapter, Composition::default()); - assert_eq!(session.backends(), adapter.composed_backends()); - assert!(!session.backends().uri); - assert!(session.uri_preflight_port().is_none()); - } - #[cfg(feature = "play-uri")] fn settings(packet_feed: bool) -> UriDriverSettings { struct Clock; diff --git a/rust-modules/src/platform_desktop.rs b/rust-modules/src/platform_desktop.rs index 017b99f6b..266eb0bb9 100644 --- a/rust-modules/src/platform_desktop.rs +++ b/rust-modules/src/platform_desktop.rs @@ -170,4 +170,21 @@ mod tests { "display_installed() is the host sink"); assert_eq!(std::ptr::from_ref(media.sink).cast::<()>(), host, "so is the video sink"); } + + /// The desktop's own `media.compose`, the one `run_application` calls, composes the Feed and no + /// URI driver: published, the session offers the adapter's set (no `Uri` in it) and holds no + /// resolver. A resolver here would describe a driver this platform never installed. + #[test] + fn the_desktop_platform_composes_the_feed_and_no_resolver() { + use plx_media::player::adapter::PlayerAdapter; + let mut adapter = PlayerAdapter::new(unsafe { plx_base::task::MainThread::assume() }); + let mut session = plx_media::route::PlaybackSession::IDLE; + let composed = (PLATFORM.media.compose)(&mut adapter, false); + crate::app::platform::publish_composition(&mut session, &adapter, composed); + assert_eq!(session.backends(), adapter.composed_backends()); + assert!(!session.backends().uri); + assert!(session.uri_preflight_port().is_none()); + #[cfg(feature = "play-feed")] + assert!(session.backends().feed, "the Feed is the desktop's driver"); + } }