From 13ec58dfe30935bea06d7da14eb12e4506b506a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 26 Nov 2026 10:33:43 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20camera=20resolution=20and?= =?UTF-8?q?=20fps=20settings=20in=20a=20Screen/Camera=20tab,=20camera=20st?= =?UTF-8?q?ats=20in=20sharing=20and=20watching=20panels,=20clicking=20a=20?= =?UTF-8?q?focused=20video=20closes=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/client/src/gui.rs | 2 + crates/client/src/gui/chat.rs | 14 +++-- crates/client/src/gui/share_view.rs | 83 ++++++++++++++++++++-------- crates/client/src/gui/voice_stats.rs | 38 +++++++++---- crates/client/src/net/media.rs | 82 +++++++++++++-------------- crates/client/src/settings.rs | 21 ++++++- crates/client/src/share/session.rs | 4 +- 7 files changed, 159 insertions(+), 85 deletions(-) diff --git a/crates/client/src/gui.rs b/crates/client/src/gui.rs index 0e9623f..3bac5da 100644 --- a/crates/client/src/gui.rs +++ b/crates/client/src/gui.rs @@ -603,6 +603,7 @@ pub struct Yumush { backups: Vec, pending_backup_delete: Option, share_apps: Vec, + share_tab: common::share::Kind, send_order: Arc>, } @@ -662,6 +663,7 @@ impl Yumush { backups: Vec::new(), pending_backup_delete: None, share_apps: Vec::new(), + share_tab: common::share::Kind::Screen, send_order: Default::default(), }; yumush.chat.camera_task = Some(camera_view::ticker(cx)); diff --git a/crates/client/src/gui/chat.rs b/crates/client/src/gui/chat.rs index 1efb65f..f114a8a 100644 --- a/crates/client/src/gui/chat.rs +++ b/crates/client/src/gui/chat.rs @@ -253,7 +253,7 @@ pub struct Chat { pub(super) user_volume: Option, pub(super) voice_samples: VecDeque, pub(super) share_sample: ShareSample, - pub(super) share_loss: HashMap>, + pub(super) share_loss: HashMap<(Id, Kind), VecDeque>, pub(super) stats_tab: StatsTab, pub(super) ringing: HashSet, pub(super) ring_task: Option>, @@ -1167,10 +1167,14 @@ impl Chat { } pub fn record_share(&mut self, sample: ShareSample) { - self.share_loss - .retain(|user_id, _| sample.watching.iter().any(|(id, _)| id == user_id)); - for (user_id, stats) in &sample.watching { - let history = self.share_loss.entry(*user_id).or_default(); + self.share_loss.retain(|key, _| { + sample + .watching + .iter() + .any(|(user_id, kind, _)| (*user_id, *kind) == *key) + }); + for (user_id, kind, stats) in &sample.watching { + let history = self.share_loss.entry((*user_id, *kind)).or_default(); history.push_back(stats.loss); while history.len() > SAMPLE_HISTORY { history.pop_front(); diff --git a/crates/client/src/gui/share_view.rs b/crates/client/src/gui/share_view.rs index 34b3948..618571f 100644 --- a/crates/client/src/gui/share_view.rs +++ b/crates/client/src/gui/share_view.rs @@ -20,7 +20,9 @@ use gpui_kit::{ slider::{Slider, SliderEvent, SliderState}, switch::Switch, }, - div, img, px, + div, img, + prelude::FluentBuilder as _, + px, }; use super::{ @@ -148,7 +150,7 @@ impl Yumush { change(&mut self.settings.share); settings::save(&self.settings); self.network.set_share_settings(&self.settings.share); - if self.network.sharing() && before.encoding_differs(&self.settings.share) { + if self.network.sharing_any() && before.encoding_differs(&self.settings.share) { let network = self.network.clone(); let settings = self.settings.share.clone(); spawn_warn(cx, "share update", async move { @@ -175,7 +177,16 @@ impl Yumush { } pub(super) fn set_share_resolution(&mut self, resolution: Resolution, cx: &mut Context) { - self.update_share(cx, |settings| settings.top.resolution = resolution); + let kind = self.share_tab; + self.update_share(cx, |settings| match kind { + Kind::Screen => settings.top.resolution = resolution, + Kind::Camera => settings.camera.resolution = resolution, + }); + } + + pub(super) fn set_share_tab(&mut self, kind: Kind, cx: &mut Context) { + self.share_tab = kind; + cx.notify(); } pub(super) fn set_share_codec(&mut self, codec: ShareCodec, cx: &mut Context) { @@ -183,7 +194,11 @@ impl Yumush { } pub(super) fn set_share_fps(&mut self, fps: Fps, cx: &mut Context) { - self.update_share(cx, |settings| settings.top.fps = fps); + let kind = self.share_tab; + self.update_share(cx, |settings| match kind { + Kind::Screen => settings.top.fps = fps, + Kind::Camera => settings.camera.fps = fps, + }); } pub(super) fn set_share_audio_mode(&mut self, mode: AudioMode, cx: &mut Context) { @@ -485,11 +500,20 @@ impl Yumush { .occlude() .bg(gpui_kit::black()) .group("viewer") - .children( - viewer - .frame - .clone() - .map(|frame| img(frame).size_full().object_fit(ObjectFit::Contain)), + .child( + div() + .id("viewer_video") + .size_full() + .on_click({ + let entity = entity.clone(); + move |_, _, cx| entity.update(cx, |yumush, cx| yumush.close_viewer(cx)) + }) + .children( + viewer + .frame + .clone() + .map(|frame| img(frame).size_full().object_fit(ObjectFit::Contain)), + ), ) .child( div() @@ -498,6 +522,7 @@ impl Yumush { .right_0() .bottom_0() .h(px(44.)) + .on_mouse_up(MouseButton::Left, |_, _, cx| cx.stop_propagation()) .px(px(12.)) .flex() .items_center() @@ -560,7 +585,10 @@ pub(super) fn kind_icon(kind: Kind) -> IconName { fn settings_card(entity: &Entity, yumush: &Yumush, palette: Palette) -> Div { let settings = &yumush.settings.share; - let (resolutions, fps) = share_limits(yumush.network.share_source()); + let kind = yumush.share_tab; + let top = settings.top(kind); + let (resolutions, fps) = share_limits(yumush.network.share_source(kind)); + let screen = kind == Kind::Screen; div() .w(px(320.)) @@ -573,13 +601,20 @@ fn settings_card(entity: &Entity, yumush: &Yumush, palette: Palette) -> .border_1() .border_color(palette.border) .bg(palette.panel) + .child(segmented( + [(Kind::Screen, "Screen"), (Kind::Camera, "Camera")], + kind, + entity, + palette, + Yumush::set_share_tab, + )) .child(field( "Resolution", segmented( RESOLUTIONS .into_iter() .filter(|(resolution, _)| resolutions.contains(resolution)), - settings.top.resolution, + top.resolution, entity, palette, Yumush::set_share_resolution, @@ -590,7 +625,7 @@ fn settings_card(entity: &Entity, yumush: &Yumush, palette: Palette) -> "FPS", segmented( FPS.into_iter().filter(|(value, _)| fps.contains(value)), - settings.top.fps, + top.fps, entity, palette, Yumush::set_share_fps, @@ -611,18 +646,20 @@ fn settings_card(entity: &Entity, yumush: &Yumush, palette: Palette) -> ), palette, )) - .child(field( - "Audio", - segmented( - AudioMode::ALL, - AudioMode::of(&settings.audio), - entity, + .when(screen, |this| { + this.child(field( + "Audio", + segmented( + AudioMode::ALL, + AudioMode::of(&settings.audio), + entity, + palette, + Yumush::set_share_audio_mode, + ), palette, - Yumush::set_share_audio_mode, - ), - palette, - )) - .children(audio_list(entity, yumush, palette)) + )) + .children(audio_list(entity, yumush, palette)) + }) } fn share_limits(source: Option) -> (Vec, Vec) { diff --git a/crates/client/src/gui/voice_stats.rs b/crates/client/src/gui/voice_stats.rs index 9387ae3..0023608 100644 --- a/crates/client/src/gui/voice_stats.rs +++ b/crates/client/src/gui/voice_stats.rs @@ -1,12 +1,15 @@ use std::collections::VecDeque; -use common::{model::Id, share::Layer}; +use common::{ + model::Id, + share::{Kind, Layer}, +}; use gpui_kit::{ - Context, Div, Entity, FontWeight, Hsla, ParentElement, Styled, div, hsla, + Context, Div, Entity, FontWeight, Hsla, ParentElement, Styled, component::Icon, div, hsla, prelude::FluentBuilder as _, px, }; -use super::{Palette, Yumush, chat::Chat, settings_page::segmented, text}; +use super::{Palette, Yumush, chat::Chat, settings_page::segmented, share_view::kind_icon, text}; use crate::media::decode::Engine; use crate::share::session::{LayerStats, WatchStats}; use crate::voice::VoiceSample; @@ -211,12 +214,13 @@ fn voice_body(samples: &VecDeque, palette: Palette) -> Div { })) } -fn sharing_body(layers: &[LayerStats], palette: Palette) -> Div { - let upload: u32 = layers.iter().map(|layer| layer.kbps).sum(); +fn sharing_body(layers: &[(Kind, LayerStats)], palette: Palette) -> Div { + let upload: u32 = layers.iter().map(|(_, layer)| layer.kbps).sum(); column() .child(tile_grid([("Upload", format!("{upload} kbps"))], palette)) - .children(layers.iter().map(|stat| { + .children(layers.iter().map(|(kind, stat)| { row_line( + *kind, describe(Some(stat.layer), Some(stat.engine)), format!("{} kbps ยท {:.0} fps", stat.kbps, stat.fps), palette, @@ -224,8 +228,8 @@ fn sharing_body(layers: &[LayerStats], palette: Palette) -> Div { })) } -fn watching_body(watching: &[(Id, WatchStats)], chat: &Chat, palette: Palette) -> Div { - column().children(watching.iter().map(|(user_id, stats)| { +fn watching_body(watching: &[(Id, Kind, WatchStats)], chat: &Chat, palette: Palette) -> Div { + column().children(watching.iter().map(|(user_id, kind, stats)| { let name = chat .author(*user_id) .map_or_else(|| user_id.to_string(), |user| user.username.clone()); @@ -237,12 +241,17 @@ fn watching_body(watching: &[(Id, WatchStats)], chat: &Chat, palette: Palette) - ("Keyframes", stats.keyframes.to_string()), ]; column() - .child(row_line(name, describe(stats.layer, stats.engine), palette)) + .child(row_line( + *kind, + name, + describe(stats.layer, stats.engine), + palette, + )) .child(tile_grid(tiles, palette)) .child(graph( "Loss", chat.share_loss - .get(user_id) + .get(&(*user_id, *kind)) .into_iter() .flatten() .map(|loss| { @@ -277,7 +286,7 @@ fn describe(layer: Option, engine: Option) -> String { } } -fn row_line(left: String, right: String, palette: Palette) -> Div { +fn row_line(kind: Kind, left: String, right: String, palette: Palette) -> Div { div() .flex() .items_center() @@ -287,6 +296,13 @@ fn row_line(left: String, right: String, palette: Palette) -> Div { .py(px(4.)) .rounded(px(6.)) .bg(palette.window) + .child( + Icon::new(kind_icon(kind)) + .w(px(12.)) + .h(px(12.)) + .flex_none() + .text_color(palette.muted), + ) .child( div() .flex_1() diff --git a/crates/client/src/net/media.rs b/crates/client/src/net/media.rs index 0f7e1f0..593e960 100644 --- a/crates/client/src/net/media.rs +++ b/crates/client/src/net/media.rs @@ -13,7 +13,7 @@ use common::{ datagram::{Packet, RELAY_PREFIX}, event::{Event, Media as Down}, model::Id, - share::{Fps, Kind, Quality, Resolution, Source}, + share::{Kind, Quality, Source}, }; use quinn::Connection; use tokio::{runtime::Handle, sync::mpsc}; @@ -36,11 +36,6 @@ const TICK: Duration = Duration::from_secs(1); const WAIT_STEP: Duration = Duration::from_millis(100); const WAIT_STEPS: u32 = 50; -const CAMERA_TOP: Quality = Quality { - resolution: Resolution::P2160, - fps: Fps::F60, -}; - #[derive(Clone)] struct Want { community_id: Id, @@ -343,10 +338,7 @@ impl Media { async fn start_share(self: Arc, kind: Kind, settings: ShareSettings) -> Result<(), Fail> { let (connection, epoch) = self.current_wait().await?; - let top = match kind { - Kind::Screen => settings.top, - Kind::Camera => CAMERA_TOP, - }; + let top = settings.top(kind); let sharing = Sharing::start( connection.clone(), kind, @@ -374,24 +366,28 @@ impl Media { } async fn update_share(self: Arc, settings: ShareSettings) -> Result<(), Fail> { - let kind = Kind::Screen; let (connection, _) = self.current_wait().await?; - let source = { + let sources = { let mut inner = self.lock(); - let Some(sharing) = inner.sharing.get_mut(&kind) else { - return Ok(()); - }; - sharing - .update( - &connection, - settings.top, - settings.encode(), - settings.audio_mode(), - ) - .map_err(Fail::Io)? + let mut sources = Vec::new(); + for (kind, sharing) in &mut inner.sharing { + let source = sharing + .update( + &connection, + settings.top(*kind), + settings.encode(), + settings.audio_mode(), + ) + .map_err(Fail::Io)?; + sources.push((*kind, source)); + } + sources }; + for (kind, source) in sources { + call(&connection, StartShare { kind, source }).await?; + } - call(&connection, StartShare { kind, source }).await + Ok(()) } async fn stop_share(self: Arc, kind: Kind) -> Result<(), Fail> { @@ -625,12 +621,12 @@ impl NetworkHandle { self.media().lock().sharing.contains_key(&Kind::Camera) } - pub fn share_source(&self) -> Option { - self.media() - .lock() - .sharing - .get(&Kind::Screen) - .map(Sharing::source) + pub fn share_source(&self, kind: Kind) -> Option { + self.media().lock().sharing.get(&kind).map(Sharing::source) + } + + pub fn sharing_any(&self) -> bool { + !self.media().lock().sharing.is_empty() } pub async fn shares(&self, community_id: Id) -> Result, Fail> { @@ -693,19 +689,19 @@ impl NetworkHandle { pub fn share_sample(&self) -> ShareSample { let mut inner = self.media().lock(); - ShareSample { - sending: inner - .sharing - .get(&Kind::Screen) - .map(Sharing::stats) - .unwrap_or_default(), - watching: inner - .watching - .iter_mut() - .filter(|((_, kind), _)| *kind == Kind::Screen) - .map(|((user_id, _), watching)| (*user_id, watching.stats())) - .collect(), - } + let mut sending: Vec<_> = inner + .sharing + .iter() + .flat_map(|(kind, sharing)| sharing.stats().into_iter().map(|stat| (*kind, stat))) + .collect(); + sending.sort_by_key(|(kind, _)| *kind == Kind::Camera); + let mut watching: Vec<_> = inner + .watching + .iter_mut() + .map(|((user_id, kind), watching)| (*user_id, *kind, watching.stats())) + .collect(); + watching.sort_by_key(|(user_id, kind, _)| (*kind == Kind::Camera, *user_id)); + ShareSample { sending, watching } } pub fn share_frame(&self, user_id: Id, kind: Kind) -> Option { diff --git a/crates/client/src/settings.rs b/crates/client/src/settings.rs index 1d5f7c9..174c82e 100644 --- a/crates/client/src/settings.rs +++ b/crates/client/src/settings.rs @@ -3,7 +3,7 @@ use std::{collections::BTreeMap, fmt::Display, ops::RangeInclusive}; use common::{ config::Config, model::Id, - share::{Codec, Fps, Quality, Resolution}, + share::{Codec, Fps, Kind, Quality, Resolution}, string_enum, }; use gpui_kit::{ @@ -19,6 +19,11 @@ use crate::{ write_config, }; +pub const CAMERA_QUALITY: Quality = Quality { + resolution: Resolution::P720, + fps: Fps::F30, +}; + pub const SHARE_QUALITY: Quality = Quality { resolution: Resolution::P1080, fps: Fps::F30, @@ -142,6 +147,7 @@ pub enum ShareCodec { #[derive(Debug, Clone, PartialEq)] pub struct ShareSettings { pub top: Quality, + pub camera: Quality, pub codec: ShareCodec, pub audio: ShareAudio, pub excluded: Vec, @@ -152,6 +158,7 @@ impl Default for ShareSettings { fn default() -> Self { Self { top: SHARE_QUALITY, + camera: CAMERA_QUALITY, codec: ShareCodec::Auto, audio: ShareAudio::Everything, excluded: Vec::new(), @@ -161,8 +168,16 @@ impl Default for ShareSettings { } impl ShareSettings { + pub fn top(&self, kind: Kind) -> Quality { + match kind { + Kind::Screen => self.top, + Kind::Camera => self.camera, + } + } + pub fn encoding_differs(&self, other: &Self) -> bool { self.top != other.top + || self.camera != other.camera || self.codec != other.codec || self.audio != other.audio || self.excluded != other.excluded @@ -278,6 +293,9 @@ pub fn load() -> Settings { top: text("share.top") .and_then(|value| parse_quality(&value)) .unwrap_or(defaults.share.top), + camera: text("share.camera") + .and_then(|value| parse_quality(&value)) + .unwrap_or(defaults.share.camera), codec: text("share.codec") .and_then(|value| Codec::parse(&value)) .map_or(ShareCodec::Auto, ShareCodec::Only), @@ -348,6 +366,7 @@ pub fn save(settings: &Settings) { .join(","), ), line("share.top", quality_text(share.top)), + line("share.camera", quality_text(share.camera)), line( "share.codec", match share.codec { diff --git a/crates/client/src/share/session.rs b/crates/client/src/share/session.rs index da909c5..06943eb 100644 --- a/crates/client/src/share/session.rs +++ b/crates/client/src/share/session.rs @@ -96,8 +96,8 @@ pub struct WatchStats { #[derive(Default)] pub struct ShareSample { - pub sending: Vec, - pub watching: Vec<(Id, WatchStats)>, + pub sending: Vec<(Kind, LayerStats)>, + pub watching: Vec<(Id, Kind, WatchStats)>, } struct Tally {