diff --git a/crates/tsc-core/Cargo.toml b/crates/tsc-core/Cargo.toml index e675292..3271e8c 100644 --- a/crates/tsc-core/Cargo.toml +++ b/crates/tsc-core/Cargo.toml @@ -9,13 +9,17 @@ repository.workspace = true publish.workspace = true [features] -default = ["audio-device", "media"] +default = ["audio-device"] # Capture and play audio through the system's devices. audio-device = ["tsc-audio/device"] -# Screen / system-audio capture and video codecs for streams (`media` -# module; tsc-media with its default backends: libvpx, OpenH264 loaded at -# runtime, X11 and PipeWire on Linux). Off for mobile builds. +# The `media` module: capture and video codecs for streams, with whatever +# tsc-media backends are enabled (e.g. MediaCodec and a registered capture +# source on Android). media = ["dep:tsc-media"] +# `media` with tsc-media's desktop backends: libvpx, OpenH264 loaded at +# runtime, X11 and PipeWire on Linux. Not for Android (libvpx does not +# cross-compile there). +media-desktop = ["media", "tsc-media/default"] [dependencies] anyhow = "1" @@ -27,7 +31,7 @@ tokio-tungstenite = "0.30" tracing = "0.1" tsc-audio = { path = "../tsc-audio", default-features = false } tsc-gateway-proto = { path = "../tsc-gateway-proto" } -tsc-media = { path = "../tsc-media", features = ["str0m"], optional = true } +tsc-media = { path = "../tsc-media", default-features = false, features = ["str0m"], optional = true } tsc-model = { path = "../tsc-model" } tsc-observer = { path = "../tsc-observer" } tsc-query = { path = "../tsc-query" } diff --git a/crates/tsc-core/src/media.rs b/crates/tsc-core/src/media.rs index bb9ceac..fd4e8f8 100644 --- a/crates/tsc-core/src/media.rs +++ b/crates/tsc-core/src/media.rs @@ -18,6 +18,9 @@ //! - [`LocalPreview`] runs capture → encoder → decoder without a server. //! //! [`tsc_media`] is re-exported for sources, codecs and pixel conversion. +//! Codecs are chosen through `tsc_media::Codecs`, so whatever backends the +//! build has are used (libvpx and OpenH264 with feature `media-desktop`, +//! MediaCodec on Android). use std::collections::VecDeque; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; @@ -262,38 +265,38 @@ impl Streamer { }, )?; let options = CaptureOptions { fps, cursor: config.cursor, ..CaptureOptions::default() }; - let mut restore_token = None; - let (screen, frames): (Box, _) = match &config.source { + // The portal's token for this choice comes with the capture. + let (screen, frames, restore_token): (Box, _, _) = match &config.source { SourceId::Synthetic => { let (w, h) = config.synthetic_size; let mut screen = SyntheticScreen::new(w, h); let frames = screen.start(&SourceId::Synthetic, &options).await?; - (Box::new(screen), frames) + (Box::new(screen), frames, None) } - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", feature = "media-desktop"))] SourceId::Portal => { use tsc_media::capture::portal::PortalCapture; let mut portal = PortalCapture::with_restore_token(config.restore_token.clone()); let frames = portal.start(&SourceId::Portal, &options).await?; - restore_token = portal.restore_token().map(str::to_owned); - (Box::new(portal), frames) + let token = portal.restore_token().map(str::to_owned); + (Box::new(portal), frames, token) } source => { let mut screen = match config.backend { CaptureBackend::Auto => capture::default_screen_capture()?, - #[cfg(target_os = "linux")] + #[cfg(all(target_os = "linux", feature = "media-desktop"))] CaptureBackend::X11 => Box::new(tsc_media::capture::x11::X11Capture::new()), - #[cfg(not(target_os = "linux"))] + #[cfg(not(all(target_os = "linux", feature = "media-desktop")))] CaptureBackend::X11 => { return Err(tsc_media::Error::CaptureUnavailable { backend: "x11", - reason: "X11 capture is only built on Linux".into(), + reason: "X11 capture is only in Linux desktop builds".into(), } .into()); } }; let frames = screen.start(source, &options).await?; - (screen, frames) + (screen, frames, None) } }; let backend = screen.backend(); @@ -969,7 +972,7 @@ impl LocalPreview { /// decoded test pattern. Checks that pixels further than two columns from /// its edges (which the codec blurs) have the colour of the rectangle or /// the background. -#[cfg(test)] +#[cfg(all(test, feature = "media-desktop"))] pub(crate) fn rectangle_span(picture: &VideoFrame) -> (u32, u32) { use tsc_media::capture::synthetic::{BACKGROUND, RECT_COLOR}; @@ -1024,6 +1027,7 @@ mod tests { assert!(latest.put(3)); } + #[cfg(feature = "media-desktop")] #[test] fn peer_config_follows_codecs() { let codecs = Codecs::new(); @@ -1038,6 +1042,7 @@ mod tests { /// The test pattern through VP8 and back, without a network: pictures /// show the moving rectangle. + #[cfg(feature = "media-desktop")] #[tokio::test(flavor = "multi_thread")] async fn local_preview_decodes_the_pattern() { let codecs = Arc::new(Codecs::new()); @@ -1071,6 +1076,7 @@ mod tests { } /// Audio of the test pattern: 20 ms Opus frames on a 48 kHz clock. + #[cfg(feature = "media-desktop")] #[tokio::test(flavor = "multi_thread")] async fn streamer_sends_opus() { let codecs = Codecs::new(); diff --git a/crates/tsc-core/src/stream.rs b/crates/tsc-core/src/stream.rs index 773bcef..b820d9e 100644 --- a/crates/tsc-core/src/stream.rs +++ b/crates/tsc-core/src/stream.rs @@ -587,7 +587,7 @@ mod tests { /// The whole path: test pattern → VP8 → stream task → str0m peers on /// loopback → the viewer's frame bus → decoder. The pictures show the /// moving rectangle. - #[cfg(feature = "media")] + #[cfg(feature = "media-desktop")] #[tokio::test(flavor = "multi_thread")] async fn test_pattern_through_stream_tasks() { use std::sync::mpsc as std_mpsc; diff --git a/crates/tsc-core/tests/media_live.rs b/crates/tsc-core/tests/media_live.rs index 48da4ca..585fd13 100644 --- a/crates/tsc-core/tests/media_live.rs +++ b/crates/tsc-core/tests/media_live.rs @@ -2,7 +2,7 @@ //! server (dev/docker-compose.yml): one session streams the test pattern //! (VP8 + Opus), another decodes it. Runs only with `TSC_LIVE=1`. -#![cfg(feature = "media")] +#![cfg(feature = "media-desktop")] use std::sync::Arc; use std::sync::mpsc as std_mpsc; diff --git a/tools/tsctl/Cargo.toml b/tools/tsctl/Cargo.toml index 5e10de9..aa44919 100644 --- a/tools/tsctl/Cargo.toml +++ b/tools/tsctl/Cargo.toml @@ -26,7 +26,7 @@ tsc-query = { path = "../../crates/tsc-query" } tsc-observer = { path = "../../crates/tsc-observer" } tsc-audio = { path = "../../crates/tsc-audio", default-features = false } # The stream media pipeline (capture, VP8, decoding), without audio devices. -tsc-core = { path = "../../crates/tsc-core", default-features = false, features = ["media"] } +tsc-core = { path = "../../crates/tsc-core", default-features = false, features = ["media-desktop"] } tsc-stream = { path = "../../crates/tsc-stream" } tokio-tungstenite = "0.30" futures-util = "0.3.34"