//! The Stream Studio: the controller behind its page in the main window, its //! window of its own and the phone layout (ui/screens/studio*.slint, //! ui/studio-window.slint). //! //! The engine's studio (`voelin_core::studio`) composites the scenes; a //! `Streamer` started for it encodes the composite from the start, so the //! recording and the replay buffer need no live stream, and going live //! attaches it to a TeamSpeak stream of our voice channel like any share. //! The studio runs while it is shown, live or recording. //! //! Both windows' StudioBridge globals show the same models (shared //! rows) and get the same values; their callbacks come here //! (bind/studio.rs). Commands go to the studio through one task, in order. //! //! What the studio decides (where the stream goes, what the header says, //! what the controls change) is `voelin_ui_vm::studio::logic`; `bind.rs` runs //! the studio and puts the rows and values on the two windows. mod bind; use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; use slint::{Rgba8Pixel, SharedPixelBuffer}; use tokio::sync::mpsc; use voelin_core::media::voelin_media::mix::SourceHandle; use voelin_core::media::{AudioApps, Latest, Streamer}; use voelin_core::studio::scene::Source; use voelin_core::studio::{self, Studio}; use crate::app::StudioWindow; use crate::bind::rows::Rows; use crate::vm; use crate::vm::studio::Overlay; use crate::vm::studio::logic::StudioData; type Picture = SharedPixelBuffer; /// The models both windows show. #[derive(Default)] struct Models { scenes: Rows, sources: Rows, audio: Rows, layers: Rows, viewers: Rows, destinations: Rows, picks: Rows, /// The destination channel's chat (`studio_sync_chat`). chat: Rows, } /// A change of the scene graph, applied in order by one task. enum Op { Apply(studio::Command), /// A source for the live scene (a new scene if there is none). Add(Source), /// Keep the overlay sources as asked. Overlays(Vec), } /// A running studio. struct Running { studio: Arc, /// Encodes the composite; `None` until it started (or if it failed). streamer: Option, ops: mpsc::UnboundedSender, /// The newest preview picture, for the UI thread. pictures: Arc>, /// Stops the preview thread. stop: Arc, tasks: Vec>, /// The mixer's meters, about 15 times a second. _meters: slint::Timer, } impl Drop for Running { fn drop(&mut self) { self.stop.store(true, Ordering::Relaxed); for task in &self.tasks { task.abort(); } } } /// The studio's state on the UI thread (`App::studio`). #[derive(Default)] pub(crate) struct StudioState { models: Models, /// The main window's globals have the models. attached: bool, /// The studio in a window of its own. pub(crate) window: Option, run: Option, starting: bool, /// What the studio knows apart from its running parts. data: StudioData, /// Applications that play audio, for the audio picker. apps: Option, /// The mixer source of each audio row. meters: Vec>, has_preview: bool, } impl StudioState { /// The Stream Studio streams to `session`: the events of that stream /// are its own. pub(crate) fn streams_to(&self, session: i64) -> bool { self.data.streams_to(session) } }