voelin-ui: pick and mix the quick share's sound as the studio does
The "Share screen" dialog had one switch for sound, "Share system audio", which shared whatever stream.audio_sources held: changing what the stream carries (an application, the microphone, desktop audio without Voelin) or how loud meant the Stream Studio or the settings, and a running share never followed. The dialog now shows the studio's audio mixer while the switch is on (off still means no audio at all): the studio's MixerRow for each source (meter, gain, mute, the menu) and Add, which opens the studio's PickDialog over the dialog to switch several sources on and off. They read the main window's StudioBridge, filled without starting the studio (App::mixer_show). Starting a share hands the sources with their gain and mute to the capture (CaptureRequest::audio_sources); the stream announces sound only when there is some. While it runs, the dialog shows the same rows with the share mixer's meters, about 15 times a second (the share keeps the timer), and every change of stream.audio_sources, from the dialog or anywhere else (the settings change event), goes to the running capture at once through Capture::follow_audio, which reconfigures the streamer. A share started without sound has no audio track, so the dialog says so instead. The studio's rows and meters follow whichever streamer goes out: a quick share's while one runs, else the studio's encoder. The picker's application list is let go once neither the dialog nor the studio needs it. With sample data, VOELIN_OPEN=share:live shares the test pattern with the sample studio's sources, live at once with sample viewers, and Stop ends it, as the studio's demo does. On a phone the frame-rate and bitrate fields of the dialog no longer run past its edge. Tests: capture_request carries the picked sources with gain and mute, and nothing with the switch off or no sources; a running capture on the test pattern follows changed sources, keeps a silent track when all are removed, and one started without sound stays so. Headless screenshots of the dialog before and during a share, 1440x900 and 390x844. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1c6251e7b7
commit
318850fcd8
14 files changed
+410
-59
No files matched your search
@@ -735,6 +735,9 @@ impl App {
|
||||
self.playback = self.prefs.get(&CLIENT_PLAYBACK);
|
||||
} else if appearance_keys().iter().any(|k| k.name() == key) {
|
||||
self.apply_appearance();
|
||||
} else if key == voelin_core::settings::STREAM_AUDIO_SOURCES.name() {
|
||||
// A running share mixes the new sources (streams.rs).
|
||||
self.share_audio_changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,13 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
||||
"server" => nav.invoke_show(Page::Server),
|
||||
"settings" => nav.invoke_open_settings(section(arg)),
|
||||
"about" => nav.invoke_open_about(),
|
||||
"share" => nav.invoke_open_share(),
|
||||
"share" => {
|
||||
nav.invoke_open_share();
|
||||
// The sample share of the test pattern, live at once.
|
||||
if arg == "live" && switches.demo_ui {
|
||||
with_app(|app| app.demo_share());
|
||||
}
|
||||
}
|
||||
"bookmark" => nav.invoke_add_server(),
|
||||
"emoji" => nav.set_emoji_open(true),
|
||||
"panel" => nav.set_right_panel_open(true),
|
||||
|
||||
+155
-31
@@ -2,16 +2,22 @@
|
||||
//! viewer. The engine runs the stream sessions; `video.rs` captures,
|
||||
//! encodes and decodes.
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use slint::{ComponentHandle, Model};
|
||||
use tracing::warn;
|
||||
use voelin_core::media::audio_source_specs;
|
||||
use voelin_core::settings::{STREAM_AUDIO_SOURCES, STREAM_BITRATE_KBPS, STREAM_FPS};
|
||||
use voelin_core::media::{Streamer, audio_source_specs};
|
||||
use voelin_core::settings::{
|
||||
AudioSourceSetting, STREAM_AUDIO_SOURCES, STREAM_BITRATE_KBPS, STREAM_FPS,
|
||||
};
|
||||
use voelin_core::stream::{
|
||||
EndReason, LayerId, LayerSpec, LeaveReason, StreamKind, StreamSetup, ViewerInfo, ViewerState,
|
||||
};
|
||||
use voelin_core::{Command, Event, StreamState, WatchState};
|
||||
|
||||
use crate::app::{App, Bridge, ShareForm, SourceItem, StreamItem, ViewerItem, later, model};
|
||||
use crate::app::{
|
||||
App, Bridge, ShareForm, SourceItem, StreamItem, ViewerItem, later, model, with_app,
|
||||
};
|
||||
use crate::settings::{
|
||||
BITRATE_CHOICES, FPS_CHOICES, ShareDefaults, nearest_choice, parse_positive,
|
||||
};
|
||||
@@ -27,6 +33,46 @@ pub(crate) struct Share {
|
||||
viewers: Vec<ViewerInfo>,
|
||||
/// The capture ended by itself and the stream is being stopped.
|
||||
stopping: bool,
|
||||
/// The audio mixer's meters (the studio's rows), about 15 times a second.
|
||||
_meters: slint::Timer,
|
||||
}
|
||||
|
||||
/// What the share dialog asks of the capture: the audio mixer's `sources`
|
||||
/// (`stream.audio_sources`) while "Share system audio" is on; off, or with
|
||||
/// no sources, no audio at all.
|
||||
fn capture_request(
|
||||
fps: u32,
|
||||
bitrate_kbps: u32,
|
||||
audio: bool,
|
||||
sources: &[AudioSourceSetting],
|
||||
restore_token: Option<String>,
|
||||
) -> CaptureRequest {
|
||||
let audio_sources = if audio { audio_source_specs(sources) } else { Vec::new() };
|
||||
CaptureRequest {
|
||||
fps,
|
||||
bitrate_kbps,
|
||||
audio: !audio_sources.is_empty(),
|
||||
audio_sources,
|
||||
restore_token,
|
||||
}
|
||||
}
|
||||
|
||||
/// The viewers of the sample share (VOELIN_DEMO_UI): two watch, one asks.
|
||||
fn demo_viewers() -> Vec<ViewerInfo> {
|
||||
let viewer = |id, state, message: &str| ViewerInfo {
|
||||
client: tsclientlib::ClientId(id),
|
||||
state,
|
||||
message: message.into(),
|
||||
layer: None,
|
||||
estimate: None,
|
||||
srtp_profile: None,
|
||||
codec: None,
|
||||
};
|
||||
vec![
|
||||
viewer(3, ViewerState::Connected, ""),
|
||||
viewer(5, ViewerState::Connected, ""),
|
||||
viewer(4, ViewerState::Requested, "Can I watch?"),
|
||||
]
|
||||
}
|
||||
|
||||
/// The stream in the viewer.
|
||||
@@ -171,6 +217,7 @@ impl App {
|
||||
} else {
|
||||
share_end_text(&reason)
|
||||
});
|
||||
self.mixer_refresh();
|
||||
}
|
||||
}
|
||||
self.refresh_streams();
|
||||
@@ -287,6 +334,7 @@ impl App {
|
||||
bridge.set_share_state(state.into());
|
||||
bridge.set_share_busy(self.share_busy);
|
||||
bridge.set_share_error(self.share_error.clone().into());
|
||||
bridge.set_share_audio(share.is_some_and(|s| s.capture.has_audio()));
|
||||
let viewers: Vec<ViewerItem> = share
|
||||
.map(|s| {
|
||||
s.viewers
|
||||
@@ -416,6 +464,8 @@ impl App {
|
||||
if self.share.is_some() {
|
||||
self.refresh_streams();
|
||||
}
|
||||
// The share dialog's audio mixer (studio.rs).
|
||||
self.mixer_tick();
|
||||
if self.watch.is_some() {
|
||||
self.refresh_viewer();
|
||||
}
|
||||
@@ -449,6 +499,8 @@ impl App {
|
||||
ui.global::<Bridge>().set_share_sources(model(items));
|
||||
}
|
||||
self.refresh_streams();
|
||||
// Its audio: the Stream Studio's mixer rows and picker.
|
||||
self.mixer_show();
|
||||
let defaults = &self.settings.share;
|
||||
let nickname = self.current.and_then(|id| self.bookmark(id)).map(|b| b.nickname.clone());
|
||||
let (fps, bitrate) = (self.prefs.get(&STREAM_FPS), self.prefs.get(&STREAM_BITRATE_KBPS));
|
||||
@@ -467,21 +519,34 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
/// The share dialog's form with the test pattern chosen.
|
||||
fn test_pattern_form(&mut self) -> Option<ShareForm> {
|
||||
let mut form = self.open_share();
|
||||
let ui = self.ui.upgrade()?;
|
||||
let sources = ui.global::<Bridge>().get_share_sources();
|
||||
let pattern = (0..sources.row_count())
|
||||
.find(|&i| sources.row_data(i).is_some_and(|s| s.name == "Test pattern"))?;
|
||||
form.source = pattern as i32;
|
||||
Some(form)
|
||||
}
|
||||
|
||||
/// Development switch `VOELIN_AUTOSHARE`: share the test pattern once.
|
||||
pub(crate) fn autoshare(&mut self) {
|
||||
if !self.autoshare || !self.view().is_some_and(|v| v.streams_available()) {
|
||||
return;
|
||||
}
|
||||
self.autoshare = false;
|
||||
let mut form = self.open_share();
|
||||
let Some(ui) = self.ui.upgrade() else { return };
|
||||
let sources = ui.global::<Bridge>().get_share_sources();
|
||||
let pattern = (0..sources.row_count())
|
||||
.find(|&i| sources.row_data(i).is_some_and(|s| s.name == "Test pattern"));
|
||||
let Some(index) = pattern else { return };
|
||||
form.source = index as i32;
|
||||
form.auto_accept = true;
|
||||
self.start_share(form);
|
||||
if let Some(form) = self.test_pattern_form() {
|
||||
self.start_share(ShareForm { auto_accept: true, ..form });
|
||||
}
|
||||
}
|
||||
|
||||
/// `VOELIN_OPEN=share:live` with sample data: the test pattern shared
|
||||
/// with the sample mixer's sources (live at once, `capture_ready`).
|
||||
pub(crate) fn demo_share(&mut self) {
|
||||
if let Some(form) = self.test_pattern_form() {
|
||||
self.start_share(ShareForm { audio: true, ..form });
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn start_share(&mut self, form: ShareForm) {
|
||||
@@ -515,15 +580,10 @@ impl App {
|
||||
audio: form.audio,
|
||||
auto_accept: form.auto_accept,
|
||||
};
|
||||
// No sources configured: no audio.
|
||||
let audio_sources = audio_source_specs(&self.prefs.get(&STREAM_AUDIO_SOURCES));
|
||||
let request = CaptureRequest {
|
||||
fps,
|
||||
bitrate_kbps: bitrate,
|
||||
audio: form.audio && !audio_sources.is_empty(),
|
||||
audio_sources,
|
||||
restore_token: self.settings.portal_restore_token.clone(),
|
||||
};
|
||||
// The mixer's sources (the sample studio's with VOELIN_DEMO_UI).
|
||||
let sources = self.studio_settings().get(&STREAM_AUDIO_SOURCES);
|
||||
let token = self.settings.portal_restore_token.clone();
|
||||
let request = capture_request(fps, bitrate, form.audio, &sources, token);
|
||||
self.settings.share = defaults;
|
||||
self.store_settings();
|
||||
self.share_busy = true;
|
||||
@@ -532,7 +592,7 @@ impl App {
|
||||
let setup = StreamSetup {
|
||||
name: form.name.trim().to_owned(),
|
||||
bitrate,
|
||||
audio: form.audio,
|
||||
audio: request.audio,
|
||||
..StreamSetup::default()
|
||||
};
|
||||
let auto_accept = form.auto_accept;
|
||||
@@ -568,30 +628,64 @@ impl App {
|
||||
let reason = capture.audio_error().unwrap_or_default();
|
||||
self.set_status(format!("Sharing without sound: {reason}"));
|
||||
}
|
||||
self.engine.send(Command::StartStream {
|
||||
session: session as u64,
|
||||
setup,
|
||||
auto_accept,
|
||||
// Sample data has no server: live at once, with viewers.
|
||||
let (live, viewers) = if self.demo_ui {
|
||||
(true, demo_viewers())
|
||||
} else {
|
||||
let session = session as u64;
|
||||
self.engine.send(Command::StartStream { session, setup, auto_accept });
|
||||
(false, Vec::new())
|
||||
};
|
||||
let meters = slint::Timer::default();
|
||||
meters.start(slint::TimerMode::Repeated, Duration::from_millis(66), || {
|
||||
with_app(|app| app.studio_meters());
|
||||
});
|
||||
self.share = Some(Share {
|
||||
session,
|
||||
capture,
|
||||
live: false,
|
||||
viewers: Vec::new(),
|
||||
live,
|
||||
viewers,
|
||||
stopping: false,
|
||||
_meters: meters,
|
||||
});
|
||||
// The mixer's rows follow this capture's sources.
|
||||
self.mixer_refresh();
|
||||
}
|
||||
}
|
||||
self.refresh_streams();
|
||||
}
|
||||
|
||||
pub(crate) fn stop_share(&mut self) {
|
||||
if let Some(share) = &mut self.share {
|
||||
share.stopping = true;
|
||||
self.engine.send(Command::StopStream { session: share.session as u64 });
|
||||
let Some(share) = &mut self.share else { return };
|
||||
share.stopping = true;
|
||||
let session = share.session;
|
||||
if self.demo_ui {
|
||||
self.share_state(session, StreamState::Ended(EndReason::Local));
|
||||
} else {
|
||||
self.engine.send(Command::StopStream { session: session as u64 });
|
||||
}
|
||||
}
|
||||
|
||||
/// The running share's streamer (the mixer's rows, studio.rs).
|
||||
pub(crate) fn share_streamer(&self) -> Option<&Streamer> {
|
||||
self.share.as_ref().map(|s| s.capture.streamer())
|
||||
}
|
||||
|
||||
/// `stream.audio_sources` changed (the mixer, the settings, another
|
||||
/// window): a running share mixes the new sources.
|
||||
pub(crate) fn share_audio_changed(&mut self) {
|
||||
if self.share.is_none() {
|
||||
return;
|
||||
}
|
||||
let sources = audio_source_specs(&self.studio_settings().get(&STREAM_AUDIO_SOURCES));
|
||||
let codecs = self.video.codecs();
|
||||
let Some(share) = &self.share else { return };
|
||||
if let Err(e) = share.capture.follow_audio(&codecs, sources) {
|
||||
self.set_status(format!("Stream audio: {e}"));
|
||||
}
|
||||
self.mixer_refresh();
|
||||
}
|
||||
|
||||
pub(crate) fn respond_viewer(&mut self, viewer: u16, accept: bool) {
|
||||
if let Some(share) = &self.share {
|
||||
let session = share.session as u64;
|
||||
@@ -802,4 +896,34 @@ mod tests {
|
||||
assert_eq!(super::bitrate_text(8000), "8 Mbit/s");
|
||||
assert_eq!(super::bitrate_text(4608), "4.6 Mbit/s");
|
||||
}
|
||||
|
||||
/// What the share dialog's mixer holds goes to the capture, with each
|
||||
/// source's gain and mute; "Share system audio" off (or nothing picked)
|
||||
/// shares no audio at all.
|
||||
#[test]
|
||||
fn the_share_carries_the_picked_audio() {
|
||||
use voelin_core::media::{AppMatch, AudioSourceKind};
|
||||
use voelin_core::settings::{AudioSourceKindSetting, AudioSourceSetting};
|
||||
let app = AudioSourceKindSetting::App { name: Some("firefox".into()), pid: None };
|
||||
let picked = [
|
||||
AudioSourceSetting { gain: 0.5, ..AudioSourceSetting::new(app) },
|
||||
AudioSourceSetting {
|
||||
muted: true,
|
||||
..AudioSourceSetting::new(AudioSourceKindSetting::Microphone)
|
||||
},
|
||||
];
|
||||
let request = super::capture_request(30, 4608, true, &picked, None);
|
||||
assert!(request.audio);
|
||||
let kinds: Vec<_> = request.audio_sources.iter().map(|s| s.kind.clone()).collect();
|
||||
let firefox = AudioSourceKind::App(AppMatch::Name("firefox".into()));
|
||||
assert_eq!(kinds, [firefox, AudioSourceKind::Microphone]);
|
||||
let mix: Vec<_> = request.audio_sources.iter().map(|s| (s.gain, s.muted)).collect();
|
||||
assert_eq!(mix, [(0.5, false), (1.0, true)]);
|
||||
assert_eq!((request.fps, request.bitrate_kbps), (30, 4608));
|
||||
|
||||
let off = super::capture_request(30, 4608, false, &picked, None);
|
||||
assert!(!off.audio && off.audio_sources.is_empty());
|
||||
let none = super::capture_request(30, 4608, true, &[], None);
|
||||
assert!(!none.audio && none.audio_sources.is_empty());
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,8 @@ use voelin_core::media::voelin_media::handoff::Handoff;
|
||||
use voelin_core::media::voelin_media::mix::SourceHandle;
|
||||
use voelin_core::media::voelin_media::{VideoFrame, convert};
|
||||
use voelin_core::media::{
|
||||
AudioApps, AudioSourceSpec, Latest, Streamer, StreamerConfigUpdate, StreamerStats, audio_apps,
|
||||
audio_source_specs, screen_sources,
|
||||
AudioApps, AudioSourceSpec, AudioSourceStats, Latest, Streamer, StreamerConfigUpdate,
|
||||
StreamerStats, audio_apps, audio_source_specs, screen_sources,
|
||||
};
|
||||
use voelin_core::settings::{
|
||||
AudioSourceKindSetting, AudioSourceSetting, Key, Kind, STREAM_AUDIO_SOURCES,
|
||||
@@ -421,8 +421,9 @@ fn file_name(what: &str) -> String {
|
||||
}
|
||||
|
||||
impl App {
|
||||
/// The studio's settings (made once).
|
||||
fn studio_settings(&mut self) -> Settings {
|
||||
/// The studio's settings (made once): its mixer's `stream.audio_sources`
|
||||
/// are the share dialog's too.
|
||||
pub(crate) fn studio_settings(&mut self) -> Settings {
|
||||
let demo = self.demo_ui;
|
||||
let prefs = &self.prefs;
|
||||
self.studio
|
||||
@@ -478,14 +479,19 @@ impl App {
|
||||
|| self.ui.upgrade().is_some_and(|ui| ui.global::<Nav>().get_page() == Page::Studio)
|
||||
}
|
||||
|
||||
/// The studio page or window appeared: show it and start the studio.
|
||||
pub(crate) fn studio_open(&mut self) {
|
||||
/// The models in the main window's StudioBridge (once).
|
||||
fn studio_attach_main(&mut self) {
|
||||
if !self.studio.attached
|
||||
&& let Some(ui) = self.ui.upgrade()
|
||||
{
|
||||
self.studio_attach(&ui.global::<StudioBridge>());
|
||||
self.studio.attached = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// The studio page or window appeared: show it and start the studio.
|
||||
pub(crate) fn studio_open(&mut self) {
|
||||
self.studio_attach_main();
|
||||
if let Some(window) = &self.studio.window
|
||||
&& let Err(e) = window.show()
|
||||
{
|
||||
@@ -726,12 +732,23 @@ impl App {
|
||||
vm::list::sync(&m.sources, &vm::studio::sources(self.studio.scenes.active(), stats));
|
||||
}
|
||||
|
||||
/// The streamer whose mixer the audio rows show: a quick share's while
|
||||
/// one runs (what goes out; both mix `stream.audio_sources`), else the
|
||||
/// studio's encoder.
|
||||
fn mixer_streamer(&self) -> Option<&Streamer> {
|
||||
self.share_streamer().or_else(|| self.studio_streamer())
|
||||
}
|
||||
|
||||
/// What the mixer says about each of its sources now.
|
||||
fn mixer_stats(&self) -> Vec<AudioSourceStats> {
|
||||
self.mixer_streamer().map(|s| s.stats().audio_sources).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// The mixer source of each audio row, and why one captures nothing.
|
||||
fn studio_map_meters(&mut self) {
|
||||
let sources = self.studio.settings.as_ref().map(|s| s.get(&STREAM_AUDIO_SOURCES));
|
||||
let streamer = self.studio_streamer();
|
||||
let mixer = streamer.and_then(Streamer::audio_mixer);
|
||||
let stats = self.studio.encoder.as_ref().map(|s| &s.audio_sources[..]).unwrap_or_default();
|
||||
let mixer = self.mixer_streamer().and_then(Streamer::audio_mixer);
|
||||
let stats = self.mixer_stats();
|
||||
self.studio.meters = sources
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
@@ -746,7 +763,7 @@ impl App {
|
||||
fn studio_refresh_audio(&self) {
|
||||
let Some(settings) = &self.studio.settings else { return };
|
||||
let sources = settings.get(&STREAM_AUDIO_SOURCES);
|
||||
let stats = self.studio.encoder.as_ref().map(|s| &s.audio_sources[..]).unwrap_or_default();
|
||||
let stats = self.mixer_stats();
|
||||
let live: Vec<Option<vm::studio::AudioLive>> = sources
|
||||
.iter()
|
||||
.enumerate()
|
||||
@@ -761,8 +778,38 @@ impl App {
|
||||
vm::list::sync(&self.studio.models.audio, &vm::studio::audio(&sources, &live));
|
||||
}
|
||||
|
||||
/// The share dialog's audio: the studio's mixer rows and picker in the
|
||||
/// main window, without starting the studio.
|
||||
pub(crate) fn mixer_show(&mut self) {
|
||||
self.studio_attach_main();
|
||||
self.studio_settings();
|
||||
self.mixer_refresh();
|
||||
}
|
||||
|
||||
/// The audio rows again: which mixer source each meter reads, levels
|
||||
/// and errors.
|
||||
pub(crate) fn mixer_refresh(&mut self) {
|
||||
self.studio_map_meters();
|
||||
self.studio_refresh_audio();
|
||||
}
|
||||
|
||||
/// Once a second while the studio does not run (it has its own tick):
|
||||
/// the share's rows, and the picker's application list let go once the
|
||||
/// share dialog is closed.
|
||||
pub(crate) fn mixer_tick(&mut self) {
|
||||
if self.studio.run.is_some() {
|
||||
return;
|
||||
}
|
||||
if self.share.is_some() {
|
||||
self.mixer_refresh();
|
||||
}
|
||||
if !self.ui.upgrade().is_some_and(|ui| ui.global::<Nav>().get_share_open()) {
|
||||
self.studio.apps = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// The meters, about 15 times a second (only rows that moved redraw).
|
||||
fn studio_meters(&mut self) {
|
||||
pub(crate) fn studio_meters(&mut self) {
|
||||
let model = &self.studio.models.audio;
|
||||
for (i, meter) in self.studio.meters.iter().enumerate() {
|
||||
let level = meter.as_ref().map_or(-100.0, |m| m.level().peak_db().max(-100.0));
|
||||
@@ -1689,6 +1736,8 @@ impl App {
|
||||
if let Err(e) = settings.set(&STREAM_AUDIO_SOURCES, sources) {
|
||||
self.set_status(e.to_string());
|
||||
}
|
||||
// A quick share follows at once (the studio through its watch).
|
||||
self.share_audio_changed();
|
||||
self.studio_refresh_audio();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ use voelin_core::media::voelin_media::capture::{CaptureSource, SourceId};
|
||||
use voelin_core::media::voelin_media::{Codec, Codecs, EncoderReport, VideoFrame, convert};
|
||||
use voelin_core::media::{
|
||||
self, AudioSourceSpec, EncoderPreference, Latest, LocalPreview, Streamer, StreamerConfig,
|
||||
Viewer, peer_config, preferred_codec, stream_codec,
|
||||
StreamerConfigUpdate, Viewer, peer_config, preferred_codec, stream_codec,
|
||||
};
|
||||
use voelin_core::stream::{LayerSpec, PeerConfig};
|
||||
use voelin_core::studio::Studio;
|
||||
@@ -426,6 +426,28 @@ impl Capture {
|
||||
self.streamer.audio_error()
|
||||
}
|
||||
|
||||
/// For the audio mixer's rows: its levels and errors.
|
||||
pub fn streamer(&self) -> &Streamer {
|
||||
&self.streamer
|
||||
}
|
||||
|
||||
/// Mix `sources` from now on (`stream.audio_sources` changed while
|
||||
/// sharing): a source whose kind stays keeps capturing with the new
|
||||
/// gain and mute, new ones start, removed ones stop. True if anything
|
||||
/// changed. A capture without sound stays so: its stream has no audio
|
||||
/// track to carry them.
|
||||
pub fn follow_audio(
|
||||
&self,
|
||||
codecs: &Codecs,
|
||||
sources: Vec<AudioSourceSpec>,
|
||||
) -> Result<bool, String> {
|
||||
if !self.has_audio() || self.streamer.audio_sources() == sources {
|
||||
return Ok(false);
|
||||
}
|
||||
let update = StreamerConfigUpdate { audio_sources: Some(sources), ..Default::default() };
|
||||
self.streamer.reconfigure(codecs, update).map(|()| true).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// The portal's token for this choice, to keep.
|
||||
pub fn restore_token(&self) -> Option<String> {
|
||||
self.streamer.restore_token().map(str::to_owned)
|
||||
@@ -523,4 +545,41 @@ mod tests {
|
||||
let restore: Vec<_> = entries.iter().map(|e| e.2).collect();
|
||||
assert_eq!(restore, [false, true]);
|
||||
}
|
||||
|
||||
/// A running share mixes what `stream.audio_sources` says now; one
|
||||
/// started without sound has no audio track to change.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn a_share_follows_its_audio_sources() {
|
||||
use voelin_core::media::AudioSourceKind;
|
||||
let codecs = Codecs::new();
|
||||
let tone = |hz| AudioSourceSpec::new(AudioSourceKind::Synthetic { hz });
|
||||
let start = async |audio| {
|
||||
let config = StreamerConfig {
|
||||
source: SourceId::Synthetic,
|
||||
synthetic_size: (64, 48),
|
||||
audio,
|
||||
audio_sources: vec![tone(440)],
|
||||
..StreamerConfig::default()
|
||||
};
|
||||
let streamer = Streamer::start(&codecs, config).await.unwrap();
|
||||
Capture { streamer, name: "Test pattern".into() }
|
||||
};
|
||||
let share = start(true).await;
|
||||
let mixed = vec![
|
||||
AudioSourceSpec { muted: true, ..tone(440) },
|
||||
AudioSourceSpec { gain: 0.5, ..tone(660) },
|
||||
];
|
||||
assert_eq!(share.follow_audio(&codecs, mixed.clone()), Ok(true));
|
||||
assert_eq!(share.streamer().audio_sources(), mixed);
|
||||
assert_eq!(share.follow_audio(&codecs, mixed), Ok(false), "nothing changed");
|
||||
// Every source taken out: silence, the track stays for new ones.
|
||||
assert_eq!(share.follow_audio(&codecs, Vec::new()), Ok(true));
|
||||
assert!(share.has_audio() && share.streamer().audio_sources().is_empty());
|
||||
assert_eq!(share.follow_audio(&codecs, vec![tone(330)]), Ok(true));
|
||||
assert_eq!(share.streamer().audio_sources(), [tone(330)]);
|
||||
|
||||
let silent = start(false).await;
|
||||
assert_eq!(silent.follow_audio(&codecs, vec![tone(660)]), Ok(false));
|
||||
assert!(!silent.has_audio());
|
||||
}
|
||||
}
|
||||
@@ -380,6 +380,8 @@ export global Bridge {
|
||||
in property <[SourceItem]> share-sources;
|
||||
in property <string> share-error;
|
||||
in property <bool> share-busy;
|
||||
// Our share carries sound: its audio mixer can change it.
|
||||
in property <bool> share-audio;
|
||||
// Whether capture and encoding are built in.
|
||||
in property <bool> can-share: true;
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import { Bridge, BookmarkForm, ShareForm } from "../bridge.slint";
|
||||
import { Nav } from "../nav.slint";
|
||||
import { Icon, Button, ButtonKind, IconButton, TextField, Field, Select, Toggle, ToggleRow, Slider, Modal, Card, Chip, Banner, Avatar, Status, ListView, ScrollView } from "../components/index.slint";
|
||||
import { AboutSlint } from "std-widgets.slint";
|
||||
import { StudioBridge } from "../studio-bridge.slint";
|
||||
import { MixerRow, PickDialog } from "studio-parts.slint";
|
||||
|
||||
// Buttons at the bottom right of a dialog.
|
||||
component Footer inherits HorizontalLayout {
|
||||
@@ -175,15 +177,57 @@ component SourceCard inherits Rectangle {
|
||||
}
|
||||
}
|
||||
|
||||
export component ShareDialog inherits Modal {
|
||||
// The stream's audio: the Stream Studio's mixer rows (`stream.audio_sources`,
|
||||
// levels while live) and Add, which opens its picker.
|
||||
component ShareAudio inherits VerticalLayout {
|
||||
callback add();
|
||||
spacing: Theme.space-1;
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-2;
|
||||
Text {
|
||||
text: @tr("Audio sources");
|
||||
color: Theme.text-secondary;
|
||||
font-size: Theme.font-sm;
|
||||
font-weight: Theme.weight-semibold;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
Button {
|
||||
small: true;
|
||||
icon: Icons.plus;
|
||||
text: @tr("Add");
|
||||
clicked => { root.add(); }
|
||||
}
|
||||
}
|
||||
if StudioBridge.audio.length == 0: Text {
|
||||
text: @tr("No audio: add your microphone, the desktop or an application.");
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-sm;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
// Three rows at a time.
|
||||
if StudioBridge.audio.length > 0: ListView {
|
||||
height: min(StudioBridge.audio.length, 3) * 56px;
|
||||
accessible-label: @tr("Audio sources");
|
||||
for audio[i] in StudioBridge.audio: MixerRow {
|
||||
audio: audio;
|
||||
index: i;
|
||||
compact: true;
|
||||
phone: Nav.narrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component ShareCard inherits Modal {
|
||||
in-out property <ShareForm> form;
|
||||
callback done();
|
||||
callback pick-audio();
|
||||
property <bool> live: Bridge.share-state == "live" || Bridge.share-state == "starting";
|
||||
title: Bridge.share-state == "live" ? @tr("You are sharing your screen") : Bridge.share-state == "starting" ? @tr("Starting…") : @tr("Share screen");
|
||||
subtitle: live ? Bridge.share-status : @tr("Stream to the people in your channel.");
|
||||
icon: Icons.radio;
|
||||
card-width: 600px;
|
||||
card-height: 660px;
|
||||
card-height: 860px;
|
||||
dismissed => { done(); }
|
||||
|
||||
if live: VerticalLayout {
|
||||
@@ -257,6 +301,15 @@ export component ShareDialog inherits Modal {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Changes apply to the stream at once.
|
||||
if Bridge.share-audio: ShareAudio {
|
||||
add => { root.pick-audio(); }
|
||||
}
|
||||
if !Bridge.share-audio: Text {
|
||||
text: @tr("This stream has no sound.");
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-sm;
|
||||
}
|
||||
Footer {
|
||||
Button {
|
||||
text: @tr("Close");
|
||||
@@ -313,7 +366,8 @@ export component ShareDialog inherits Modal {
|
||||
input-type: number;
|
||||
placeholder: @tr("fps");
|
||||
label: @tr("Frames per second");
|
||||
width: 80px;
|
||||
// On a phone both pairs fit side by side.
|
||||
width: Nav.narrow ? 60px : 80px;
|
||||
horizontal-stretch: 0;
|
||||
}
|
||||
}
|
||||
@@ -333,17 +387,22 @@ export component ShareDialog inherits Modal {
|
||||
input-type: number;
|
||||
placeholder: @tr("kbit/s");
|
||||
label: @tr("Bitrate in kbit/s");
|
||||
width: 80px;
|
||||
// On a phone both pairs fit side by side.
|
||||
width: Nav.narrow ? 60px : 80px;
|
||||
horizontal-stretch: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Off: no audio at all.
|
||||
ToggleRow {
|
||||
text: @tr("Share system audio");
|
||||
icon: Icons.volume-2;
|
||||
checked <=> form.audio;
|
||||
}
|
||||
if form.audio: ShareAudio {
|
||||
add => { root.pick-audio(); }
|
||||
}
|
||||
ToggleRow {
|
||||
text: @tr("Let everyone in the channel watch without asking");
|
||||
icon: Icons.users;
|
||||
@@ -370,6 +429,30 @@ export component ShareDialog inherits Modal {
|
||||
}
|
||||
}
|
||||
|
||||
// Share the screen or a window, with the stream's audio; the studio's
|
||||
// audio picker opens over it.
|
||||
export component ShareDialog inherits Rectangle {
|
||||
in-out property <ShareForm> form;
|
||||
callback done();
|
||||
property <bool> picking;
|
||||
ShareCard {
|
||||
width: parent.width;
|
||||
height: parent.height;
|
||||
form <=> root.form;
|
||||
done => { root.done(); }
|
||||
pick-audio => {
|
||||
StudioBridge.list-audio();
|
||||
root.picking = true;
|
||||
}
|
||||
}
|
||||
if root.picking: PickDialog {
|
||||
width: parent.width;
|
||||
height: parent.height;
|
||||
kind: "audio";
|
||||
done => { root.picking = false; }
|
||||
}
|
||||
}
|
||||
|
||||
// Local volume and mute of one client.
|
||||
export component ClientAudioDialog inherits Modal {
|
||||
callback done();
|
||||
|
||||
@@ -735,8 +735,8 @@ export component StudioHeader inherits HorizontalLayout {
|
||||
}
|
||||
}
|
||||
|
||||
// One audio source: meter, gain, mute, a menu.
|
||||
component MixerRow inherits Rectangle {
|
||||
// One audio source: meter, gain, mute, a menu (also the share dialog's).
|
||||
export component MixerRow inherits Rectangle {
|
||||
in property <StudioAudio> audio;
|
||||
in property <int> index;
|
||||
in property <bool> compact;
|
||||
@@ -1922,8 +1922,9 @@ component SourceDialog inherits Modal {
|
||||
}
|
||||
}
|
||||
|
||||
// Pick a screen, window, camera or audio source.
|
||||
component PickDialog inherits Modal {
|
||||
// Pick a screen, window, camera or audio source (audio: also over the
|
||||
// share dialog).
|
||||
export component PickDialog inherits Modal {
|
||||
in property <string> kind;
|
||||
callback done();
|
||||
title: kind == "screen" ? @tr("Share a screen") : kind == "window" ? @tr("Share a window") : kind == "camera" ? @tr("Add a camera") : @tr("Audio sources");
|
||||
|
||||
+8
-3
@@ -234,9 +234,13 @@ The audio of our stream is a mix of any number of sources
|
||||
`[{"kind": "desktop"}, {"kind": "app", "name": "firefox", "gain": 0.5},
|
||||
{"kind": "microphone", "muted": true}]`. Other kinds are `"window"` and
|
||||
`"synthetic"` (`frequency`), and an app can be given by `"pid"`. The
|
||||
default is desktop audio; `[]` shares without sound. The desktop app
|
||||
reads it when sharing starts (`media::audio_source_specs`).
|
||||
`media::audio_apps()` lists the applications for a picker.
|
||||
default is desktop audio; `[]` shares without sound. The app's share
|
||||
dialog and the Stream Studio pick and mix the sources with the same
|
||||
mixer rows and picker ([ui.md](ui.md#sound-in-the-quick-share)); a share
|
||||
hands them to its capture when it starts (`media::audio_source_specs`),
|
||||
and a running share or studio follows every change of the key through
|
||||
`Streamer::reconfigure`. `media::audio_apps()` lists the applications
|
||||
for a picker.
|
||||
|
||||
What applications play is captured by `capture::playback::start_playback`:
|
||||
|
||||
@@ -979,6 +983,7 @@ has not run on Windows yet.
|
||||
| Stream mixer (latency, fade on underrun, drift correction, rate conversion, limiter, levels, live source changes), `BlockClock` | `voelin-media` `mix::tests`, `tests/mix_alloc.rs` (no allocation per block) | tested |
|
||||
| Application audio on PipeWire: desktop without our own stream, by name, by pid, a new player linked live, a quit one dropped, a restarted one matched again, the app list | `voelin-media/tests/pipewire_apps.rs` (private PipeWire, WirePlumber and D-Bus; tones told apart by frequency) | tested with PipeWire 1.0 and WirePlumber 0.4; skipped without them |
|
||||
| Streamer audio sources (mix levels, gain, mute, live change, microphone tap, window source error, silence) | `voelin-core` `media::tests::audio_sources_change_live`, `audio_sources_from_settings`, `settings::tests::audio_sources` | tested |
|
||||
| The share dialog's audio: the picked sources (gain, mute) in the capture request, none with "Share system audio" off; a running share following `stream.audio_sources` (a share without sound left so) | `voelin-ui` `streams::tests::the_share_carries_the_picked_audio`, `video::tests::a_share_follows_its_audio_sources`; headless screenshots (`share`, `share:live`) | tested; the dialog itself only in headless screenshots (nothing clicked) |
|
||||
| X11 `_NET_WM_PID` of the shared window | `tests/x11_capture.rs` under Xvfb (`VOELIN_X11_TEST_DISPLAY`) | tested |
|
||||
| WASAPI per-process loopback, audio sessions, `HWND` owner | – | type-checked for `x86_64-pc-windows-gnu` only |
|
||||
| Android per-app and all-but-ours playback capture | `cargo ndk -t arm64-v8a clippy`, `gradlew compileDebugKotlin` | compiles only (no device or emulator here) |
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 108 KiB After Width: | Height: | Size: 114 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 124 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
+23
-4
@@ -181,6 +181,25 @@ game"), which is also what the gateway's directory shows. With sample data
|
||||
the synthetic camera with background blur, text, colours) and test tones,
|
||||
on settings in memory, and recordings go to a temporary folder.
|
||||
|
||||
### Sound in the quick share
|
||||
|
||||
The share dialog (`share`, and `share:live` for a running share) mixes its
|
||||
sound with the studio's pieces: while "Share system audio" is on (off: no
|
||||
audio at all) it shows the studio's mixer rows (`MixerRow`: meter, gain,
|
||||
mute, a menu) for `stream.audio_sources`, and Add opens the studio's picker
|
||||
(`PickDialog`) over it: the microphone, desktop audio without Voelin, the
|
||||
shared window's application, any application that plays (on Android the
|
||||
launchable apps with their icons), several at once. The rows read the
|
||||
main window's `StudioBridge`, filled without starting the studio
|
||||
(`App::mixer_show`). Starting a share hands the sources to the capture
|
||||
(`CaptureRequest::audio_sources`); while it runs the dialog shows the
|
||||
same rows with the share mixer's meters (about 15 times a second), and
|
||||
every change of `stream.audio_sources`, from the dialog or anywhere else,
|
||||
goes to the running capture at once (`Capture::follow_audio`, which calls
|
||||
`Streamer::reconfigure`). A share started without sound has no audio track
|
||||
to add sources to. With sample data `share:live` shares the test pattern
|
||||
with the sample studio's sources, live at once with sample viewers.
|
||||
|
||||
## Adding a screen
|
||||
|
||||
1. Write the screen in `ui/screens/<name>.slint` from the components
|
||||
@@ -243,7 +262,7 @@ Environment variables (see `src/dev.rs`):
|
||||
- `VOELIN_DEMO_UI=1`: sample servers, channels, members, chat with emoji and
|
||||
a stream, without a server (nothing is stored).
|
||||
- `VOELIN_OPEN=<what>[,<what>...]`: `home`, `server`, `settings[:voice|keybinds|streaming|privacy|appearance]`,
|
||||
`about`, `share`, `bookmark`, `emoji`, `client`, `panel`, `no-panel`,
|
||||
`about`, `share[:live]`, `bookmark`, `emoji`, `client`, `panel`, `no-panel`,
|
||||
`voice`, `pins`, `topics`, `topic:<id>`, `member`, `watch`, `popout`
|
||||
(the server page, above), `tab:<home|servers|chat|activity|you>` (phone
|
||||
layout). With sample data, `watch` plays the local test pattern in the
|
||||
@@ -296,13 +315,13 @@ the window's size so the pointer is not over the window, and passes
|
||||
|  |  |
|
||||
|  |  |
|
||||
|  |  |
|
||||
|  |  |
|
||||
|  | |
|
||||
|  |  |
|
||||
|  |  |
|
||||
|
||||
| Phone layout | | | | |
|
||||
|---|---|---|---|---|
|
||||
|  |  |  |  |  |
|
||||
|  |  |  | | |
|
||||
|  |  |  |  |  |
|
||||
|
||||
## Limits
|
||||
|
||||
|
||||
Reference in new issue
Block a user