What we share and what we watch are in the AppState now (Sharing, Watching), with the transitions of the engine's stream events (apply handles them, the Stream Studio's stream excepted), the user's choices (watch, leave, volume, quality, the share dialog's plan, the capture that started) and the rows and texts of the streams panel, the share card and the viewer, as plain data in streams/logic.rs with tests of their own. The Slint side (streams/bind.rs) writes the Bridge, owns the capture and the decoder, and attaches or drops them as an update says (StreamEffects). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
112 lines
3.5 KiB
Rust
112 lines
3.5 KiB
Rust
//! 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<Rgba8Pixel>;
|
|
|
|
/// The models both windows show.
|
|
#[derive(Default)]
|
|
struct Models {
|
|
scenes: Rows<vm::studio_bridge::StudioScene>,
|
|
sources: Rows<vm::studio_bridge::StudioSource>,
|
|
audio: Rows<vm::studio_bridge::StudioAudio>,
|
|
layers: Rows<vm::studio_bridge::StudioLayer>,
|
|
viewers: Rows<vm::studio_bridge::StudioViewer>,
|
|
destinations: Rows<vm::studio_bridge::StudioPick>,
|
|
picks: Rows<vm::studio_bridge::StudioPick>,
|
|
/// The destination channel's chat (`studio_sync_chat`).
|
|
chat: Rows<vm::bridge::ChatLine>,
|
|
}
|
|
|
|
/// 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<Overlay>),
|
|
}
|
|
|
|
/// A running studio.
|
|
struct Running {
|
|
studio: Arc<Studio>,
|
|
/// Encodes the composite; `None` until it started (or if it failed).
|
|
streamer: Option<Streamer>,
|
|
ops: mpsc::UnboundedSender<Op>,
|
|
/// The newest preview picture, for the UI thread.
|
|
pictures: Arc<Latest<Picture>>,
|
|
/// Stops the preview thread.
|
|
stop: Arc<AtomicBool>,
|
|
tasks: Vec<tokio::task::JoinHandle<()>>,
|
|
/// 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<StudioWindow>,
|
|
run: Option<Running>,
|
|
starting: bool,
|
|
/// What the studio knows apart from its running parts.
|
|
data: StudioData,
|
|
/// Applications that play audio, for the audio picker.
|
|
apps: Option<AudioApps>,
|
|
/// The mixer source of each audio row.
|
|
meters: Vec<Option<SourceHandle>>,
|
|
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)
|
|
}
|
|
}
|