BlueGit

ict rusty-teams

feat(call): show thumbnails of screens and windows in the share menu

- the engine grabs one frame per screen and the first 12 windows after listing them, scaled to 320x180
- share menu rows show the thumbnail next to the title (screens 128x72, windows 96x54), an icon until it arrives
- demo call sends thumbnails for the first three sources

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-10 · 3 weeks ago

Hash
9a1b6f9d700ed752b0c4e6a9923055e94ae950c2
Parent
4c113fc9
7 files changed +206 −19
crates/app-call-model/src/demo.rs +30 −3
@@ -1,3 +1,4 @@
1 use std::sync::Arc;
1 2 use std::time::{Duration, Instant};
2 3
3 4 use calling::CameraDevice;
@@ -9,7 +10,7 @@ use calling::{
9 10 DeviceLists, EndReason, HealthSample, HoldState, IncomingRing, Limitation, MediaPath,
10 11 MeetingCapability, MeetingOptions, MeetingRole, MeetingTarget, Modality, NetworkLevel, Progress,
11 12 PublishedState, RaisedHand, Reaction, RecordingKind, Replacement, RosterEntry, ShareKind, ShareSource, StopScope,
12 TransportDetails, VideoKey, call_channel,
13 TransportDetails, VideoKey, VideoPicture, call_channel,
13 14 };
14 15 use calling::call::VideoReport;
15 16 use calling::timeline::TimelineEntry;
@@ -36,6 +37,7 @@ const SPEAKING_LEVEL: f32 = 0.3;
36 37 const SPEAKER_TICKS: u32 = 10;
37 38 const VIDEO_PERIOD: Duration = Duration::from_millis(125);
38 39 const DEMO_CAMERAS: usize = 4;
40 const DEMO_THUMBNAILS: usize = 3;
39 41 const GALLERY_CAMERAS: usize = 7;
40 42 const GALLERY_SPEAKER_TICKS: u32 = 15;
41 43 const SCREEN_EVERY_TICKS: u32 = 4;
@@ -281,6 +283,31 @@ fn demo_share_sources() -> Vec<ShareSource> {
281 283 ]
282 284 }
283 285
286 fn send_demo_share_sources(control: &CallControl) {
287 let sources = demo_share_sources();
288 control.send(CallUpdate::ShareSources(sources.clone()));
289 for (index, source) in sources.into_iter().take(DEMO_THUMBNAILS).enumerate() {
290 control.send(CallUpdate::ShareThumbnail { source, picture: Arc::new(demo_thumbnail(index as u8)) });
291 }
292 }
293
294 fn demo_thumbnail(seed: u8) -> VideoPicture {
295 let (width, height) = (160u32, 90u32);
296 let mut bgra = Vec::with_capacity((width * height * 4) as usize);
297 for row in 0..height {
298 for column in 0..width {
299 let shade = (column * 255 / width) as u8;
300 let header = row < height / 6;
301 bgra.extend_from_slice(&if header {
302 [70, 50, 40, 255]
303 } else {
304 [shade / 2 + 60, seed.wrapping_mul(60).wrapping_add((row * 120 / height) as u8), 90, 255]
305 });
306 }
307 }
308 VideoPicture { width, height, bgra }
309 }
310
284 311 fn demo_devices() -> DeviceLists {
285 312 DeviceLists {
286 313 inputs: vec![
@@ -338,7 +365,7 @@ async fn run_demo_call(mut control: CallControl, script: DemoCall, scene: DemoSc
338 365 control.send(CallUpdate::ListenOnly(false));
339 366 control.send(CallUpdate::Devices(demo_devices()));
340 367 control.send(CallUpdate::Cameras(demo_cameras()));
341 control.send(CallUpdate::ShareSources(demo_share_sources()));
368 send_demo_share_sources(&control);
342 369 control.send(CallUpdate::Selected {
343 370 input: DeviceChoice::SystemDefault,
344 371 output: DeviceChoice::SystemDefault,
@@ -741,7 +768,7 @@ async fn speak_until_hangup(
741 768 return;
742 769 }
743 770 Some(CallCommand::OpenWhiteboard { .. }) => control.send(CallUpdate::WhiteboardUrl(DEMO_BOARD_URL.to_owned())),
744 Some(CallCommand::RefreshShareSources) => control.send(CallUpdate::ShareSources(demo_share_sources())),
771 Some(CallCommand::RefreshShareSources) => send_demo_share_sources(&control),
745 772 Some(CallCommand::Hangup | CallCommand::EndMeeting) | None => {
746 773 end(&control, EndReason::LocalHangup);
747 774 return;
@@ -1,3 +1,4 @@
1use std::sync::Arc;
1use std::time::{Duration, Instant};
2use std::time::{Duration, Instant};
2
3
3use calling::CameraDevice;
4use calling::CameraDevice;
@@ -9,7 +10,7 @@ use calling::{
9 DeviceLists, EndReason, HealthSample, HoldState, IncomingRing, Limitation, MediaPath,
10 DeviceLists, EndReason, HealthSample, HoldState, IncomingRing, Limitation, MediaPath,
10 MeetingCapability, MeetingOptions, MeetingRole, MeetingTarget, Modality, NetworkLevel, Progress,
11 MeetingCapability, MeetingOptions, MeetingRole, MeetingTarget, Modality, NetworkLevel, Progress,
11 PublishedState, RaisedHand, Reaction, RecordingKind, Replacement, RosterEntry, ShareKind, ShareSource, StopScope,
12 PublishedState, RaisedHand, Reaction, RecordingKind, Replacement, RosterEntry, ShareKind, ShareSource, StopScope,
12 TransportDetails, VideoKey, call_channel,
13 TransportDetails, VideoKey, VideoPicture, call_channel,
13};
14};
14use calling::call::VideoReport;
15use calling::call::VideoReport;
15use calling::timeline::TimelineEntry;
16use calling::timeline::TimelineEntry;
@@ -36,6 +37,7 @@ const SPEAKING_LEVEL: f32 = 0.3;
36const SPEAKER_TICKS: u32 = 10;
37const SPEAKER_TICKS: u32 = 10;
37const VIDEO_PERIOD: Duration = Duration::from_millis(125);
38const VIDEO_PERIOD: Duration = Duration::from_millis(125);
38const DEMO_CAMERAS: usize = 4;
39const DEMO_CAMERAS: usize = 4;
40const DEMO_THUMBNAILS: usize = 3;
39const GALLERY_CAMERAS: usize = 7;
41const GALLERY_CAMERAS: usize = 7;
40const GALLERY_SPEAKER_TICKS: u32 = 15;
42const GALLERY_SPEAKER_TICKS: u32 = 15;
41const SCREEN_EVERY_TICKS: u32 = 4;
43const SCREEN_EVERY_TICKS: u32 = 4;
@@ -281,6 +283,31 @@ fn demo_share_sources() -> Vec<ShareSource> {
281 ]
283 ]
282}
284}
283
285
286fn send_demo_share_sources(control: &CallControl) {
287 let sources = demo_share_sources();
288 control.send(CallUpdate::ShareSources(sources.clone()));
289 for (index, source) in sources.into_iter().take(DEMO_THUMBNAILS).enumerate() {
290 control.send(CallUpdate::ShareThumbnail { source, picture: Arc::new(demo_thumbnail(index as u8)) });
291 }
292}
293
294fn demo_thumbnail(seed: u8) -> VideoPicture {
295 let (width, height) = (160u32, 90u32);
296 let mut bgra = Vec::with_capacity((width * height * 4) as usize);
297 for row in 0..height {
298 for column in 0..width {
299 let shade = (column * 255 / width) as u8;
300 let header = row < height / 6;
301 bgra.extend_from_slice(&if header {
302 [70, 50, 40, 255]
303 } else {
304 [shade / 2 + 60, seed.wrapping_mul(60).wrapping_add((row * 120 / height) as u8), 90, 255]
305 });
306 }
307 }
308 VideoPicture { width, height, bgra }
309}
310
284fn demo_devices() -> DeviceLists {
311fn demo_devices() -> DeviceLists {
285 DeviceLists {
312 DeviceLists {
286 inputs: vec![
313 inputs: vec![
@@ -338,7 +365,7 @@ async fn run_demo_call(mut control: CallControl, script: DemoCall, scene: DemoSc
338 control.send(CallUpdate::ListenOnly(false));
365 control.send(CallUpdate::ListenOnly(false));
339 control.send(CallUpdate::Devices(demo_devices()));
366 control.send(CallUpdate::Devices(demo_devices()));
340 control.send(CallUpdate::Cameras(demo_cameras()));
367 control.send(CallUpdate::Cameras(demo_cameras()));
341 control.send(CallUpdate::ShareSources(demo_share_sources()));
368 send_demo_share_sources(&control);
342 control.send(CallUpdate::Selected {
369 control.send(CallUpdate::Selected {
343 input: DeviceChoice::SystemDefault,
370 input: DeviceChoice::SystemDefault,
344 output: DeviceChoice::SystemDefault,
371 output: DeviceChoice::SystemDefault,
@@ -741,7 +768,7 @@ async fn speak_until_hangup(
741 return;
768 return;
742 }
769 }
743 Some(CallCommand::OpenWhiteboard { .. }) => control.send(CallUpdate::WhiteboardUrl(DEMO_BOARD_URL.to_owned())),
770 Some(CallCommand::OpenWhiteboard { .. }) => control.send(CallUpdate::WhiteboardUrl(DEMO_BOARD_URL.to_owned())),
744 Some(CallCommand::RefreshShareSources) => control.send(CallUpdate::ShareSources(demo_share_sources())),
771 Some(CallCommand::RefreshShareSources) => send_demo_share_sources(&control),
745 Some(CallCommand::Hangup | CallCommand::EndMeeting) | None => {
772 Some(CallCommand::Hangup | CallCommand::EndMeeting) | None => {
746 end(&control, EndReason::LocalHangup);
773 end(&control, EndReason::LocalHangup);
747 return;
774 return;
crates/app-call-model/src/model.rs +19 −1
@@ -298,6 +298,7 @@ pub struct CallModel {
298 298 pub camera: DeviceChoice,
299 299 pub local_share: Option<String>,
300 300 pub share_sources: Vec<ShareSource>,
301 pub share_thumbnails: Vec<(ShareSource, Arc<gpui_kit::RenderImage>)>,
301 302 pub last_sample: Option<StatsSample>,
302 303 pub share_sound: bool,
303 304 pub own_hand: Option<u64>,
@@ -366,6 +367,7 @@ impl CallModel {
366 367 camera: DeviceChoice::SystemDefault,
367 368 local_share: None,
368 369 share_sources: Vec::new(),
370 share_thumbnails: Vec::new(),
369 371 last_sample: None,
370 372 share_sound: false,
371 373 own_hand: None,
@@ -502,7 +504,16 @@ impl CallModel {
502 504 }
503 505 self.local_share = label;
504 506 }
505 CallUpdate::ShareSources(sources) => self.share_sources = sources,
507 CallUpdate::ShareSources(sources) => {
508 self.share_thumbnails.retain(|(source, _)| sources.contains(source));
509 self.share_sources = sources;
510 }
511 CallUpdate::ShareThumbnail { source, picture } => {
512 if let Some(image) = crate::pictures::render_image((*picture).clone()) {
513 self.share_thumbnails.retain(|(known, _)| *known != source);
514 self.share_thumbnails.push((source, image));
515 }
516 }
506 517 CallUpdate::ShareSound(active) => self.share_sound = active,
507 518 CallUpdate::OwnHand(rank) => self.own_hand = rank,
508 519 CallUpdate::Reaction { mri, reaction } => {
@@ -1193,6 +1204,13 @@ impl CallModel {
1193 1204 .collect()
1194 1205 }
1195 1206
1207 pub fn share_thumbnail(&self, source: &ShareSource) -> Option<Arc<gpui_kit::RenderImage>> {
1208 self.share_thumbnails
1209 .iter()
1210 .find(|(known, _)| known == source)
1211 .map(|(_, image)| image.clone())
1212 }
1213
1196 1214 pub fn windows(&self) -> Vec<&ShareSource> {
1197 1215 self.share_sources
1198 1216 .iter()
@@ -298,6 +298,7 @@ pub struct CallModel {
298 pub camera: DeviceChoice,
298 pub camera: DeviceChoice,
299 pub local_share: Option<String>,
299 pub local_share: Option<String>,
300 pub share_sources: Vec<ShareSource>,
300 pub share_sources: Vec<ShareSource>,
301 pub share_thumbnails: Vec<(ShareSource, Arc<gpui_kit::RenderImage>)>,
301 pub last_sample: Option<StatsSample>,
302 pub last_sample: Option<StatsSample>,
302 pub share_sound: bool,
303 pub share_sound: bool,
303 pub own_hand: Option<u64>,
304 pub own_hand: Option<u64>,
@@ -366,6 +367,7 @@ impl CallModel {
366 camera: DeviceChoice::SystemDefault,
367 camera: DeviceChoice::SystemDefault,
367 local_share: None,
368 local_share: None,
368 share_sources: Vec::new(),
369 share_sources: Vec::new(),
370 share_thumbnails: Vec::new(),
369 last_sample: None,
371 last_sample: None,
370 share_sound: false,
372 share_sound: false,
371 own_hand: None,
373 own_hand: None,
@@ -502,7 +504,16 @@ impl CallModel {
502 }
504 }
503 self.local_share = label;
505 self.local_share = label;
504 }
506 }
505 CallUpdate::ShareSources(sources) => self.share_sources = sources,
507 CallUpdate::ShareSources(sources) => {
508 self.share_thumbnails.retain(|(source, _)| sources.contains(source));
509 self.share_sources = sources;
510 }
511 CallUpdate::ShareThumbnail { source, picture } => {
512 if let Some(image) = crate::pictures::render_image((*picture).clone()) {
513 self.share_thumbnails.retain(|(known, _)| *known != source);
514 self.share_thumbnails.push((source, image));
515 }
516 }
506 CallUpdate::ShareSound(active) => self.share_sound = active,
517 CallUpdate::ShareSound(active) => self.share_sound = active,
507 CallUpdate::OwnHand(rank) => self.own_hand = rank,
518 CallUpdate::OwnHand(rank) => self.own_hand = rank,
508 CallUpdate::Reaction { mri, reaction } => {
519 CallUpdate::Reaction { mri, reaction } => {
@@ -1193,6 +1204,13 @@ impl CallModel {
1193 .collect()
1204 .collect()
1194 }
1205 }
1195
1206
1207 pub fn share_thumbnail(&self, source: &ShareSource) -> Option<Arc<gpui_kit::RenderImage>> {
1208 self.share_thumbnails
1209 .iter()
1210 .find(|(known, _)| known == source)
1211 .map(|(_, image)| image.clone())
1212 }
1213
1196 pub fn windows(&self) -> Vec<&ShareSource> {
1214 pub fn windows(&self) -> Vec<&ShareSource> {
1197 self.share_sources
1215 self.share_sources
1198 .iter()
1216 .iter()
crates/app-call-model/src/pictures.rs +1 −1
@@ -18,7 +18,7 @@ pub struct CallPictures {
18 18 shown: HashMap<VideoKey, Shown>,
19 19 }
20 20
21 fn render_image(picture: VideoPicture) -> Option<Arc<RenderImage>> {
21 pub(crate) fn render_image(picture: VideoPicture) -> Option<Arc<RenderImage>> {
22 22 let bytes = RgbaImage::from_raw(picture.width, picture.height, picture.bgra)?;
23 23 Some(Arc::new(RenderImage::new(vec![Frame::new(bytes)])))
24 24 }
@@ -18,7 +18,7 @@ pub struct CallPictures {
18 shown: HashMap<VideoKey, Shown>,
18 shown: HashMap<VideoKey, Shown>,
19}
19}
20
20
21fn render_image(picture: VideoPicture) -> Option<Arc<RenderImage>> {
21pub(crate) fn render_image(picture: VideoPicture) -> Option<Arc<RenderImage>> {
22 let bytes = RgbaImage::from_raw(picture.width, picture.height, picture.bgra)?;
22 let bytes = RgbaImage::from_raw(picture.width, picture.height, picture.bgra)?;
23 Some(Arc::new(RenderImage::new(vec![Frame::new(bytes)])))
23 Some(Arc::new(RenderImage::new(vec![Frame::new(bytes)])))
24}
24}
crates/app/src/views/call_view.rs +57 −9
@@ -48,6 +48,7 @@ const RING_GAP: f32 = 4.;
48 48 pub(super) const CONTROL_SIZE: f32 = 44.;
49 49 const CONTROL_ICON: f32 = 20.;
50 50 pub(super) const MENU_WIDTH: f32 = 280.;
51 const SHARE_MENU_WIDTH: f32 = 360.;
51 52 const PULSE_PERIOD: Duration = Duration::from_millis(1400);
52 53 const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);
53 54 const BLINK_DIMMED_OPACITY: f32 = 0.45;
@@ -62,6 +63,11 @@ pub const NO_SHARE_HINT: &str = "Sharing starts once the call is connected";
62 63 pub const NO_WINDOWS_HINT: &str = "No windows found";
63 64 pub(super) const BANNER_HEIGHT: f32 = 40.;
64 65 const MAX_WINDOW_ITEMS: usize = 12;
66 pub const SHARE_THUMBNAIL_TAG: &str = "call/share-menu/thumbnail";
67 const SCREEN_THUMBNAIL: (f32, f32) = (128., 72.);
68 const WINDOW_THUMBNAIL: (f32, f32) = (96., 54.);
69 const THUMBNAIL_RADIUS: f32 = 6.;
70 const THUMBNAIL_ICON: f32 = 22.;
65 71 pub const LOBBY_TEXT: &str = "Waiting in the lobby...";
66 72 pub(super) const CHAT_PANEL_WIDTH: f32 = 320.;
67 73 pub(super) const OVERLAY_BELOW: f32 = 720.;
@@ -574,7 +580,7 @@ fn share_items(
574 580 let screens = model.screens();
575 581 let single_screen = screens.len() == 1;
576 582 let mut popup = popup
577 .min_w(px(MENU_WIDTH))
583 .min_w(px(SHARE_MENU_WIDTH))
578 584 .item(sound_switch_item(app, options.sound))
579 585 .item(motion_switch_item(app, options.motion))
580 586 .item(standout_switch_item(app, options.standout, model.camera_on))
@@ -585,11 +591,14 @@ fn share_items(
585 591 } else {
586 592 format!("Share screen {}", index + 1)
587 593 };
594 let thumbnail = model.share_thumbnail(source);
588 595 let source = source.clone();
589 596 let app = app.clone();
590 popup = popup.item(PopupMenuItem::new(label).icon(IconName::Monitor).on_click(
591 move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),
592 ));
597 popup = popup.item(
598 share_source_item(label, thumbnail, IconName::Monitor, SCREEN_THUMBNAIL).on_click(
599 move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),
600 ),
601 );
593 602 }
594 603 popup = popup
595 604 .separator()
@@ -600,19 +609,58 @@ fn share_items(
600 609 }
601 610 for source in windows.into_iter().take(MAX_WINDOW_ITEMS) {
602 611 let label = source.label();
612 let thumbnail = model.share_thumbnail(source);
603 613 let source = source.clone();
604 614 let app = app.clone();
605 615 popup = popup.item(
606 PopupMenuItem::new(label)
607 .icon(IconName::AppWindow)
608 .on_click(move |_, _, cx| {
609 app.update(cx, |state, cx| state.start_call_share(source.clone(), cx))
610 }),
616 share_source_item(label, thumbnail, IconName::AppWindow, WINDOW_THUMBNAIL).on_click(
617 move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),
618 ),
611 619 );
612 620 }
613 621 popup
614 622 }
615 623
624 fn share_source_item(
625 label: String,
626 thumbnail: Option<Arc<RenderImage>>,
627 fallback: IconName,
628 (width, height): (f32, f32),
629 ) -> PopupMenuItem {
630 PopupMenuItem::element(move |_, _| {
631 let preview = div()
632 .debug_selector(|| SHARE_THUMBNAIL_TAG.into())
633 .flex_none()
634 .w(px(width))
635 .h(px(height))
636 .rounded(px(THUMBNAIL_RADIUS))
637 .bg(theme::popup_hover())
638 .flex()
639 .items_center()
640 .justify_center();
641 let preview = match &thumbnail {
642 Some(image) => preview.child(
643 img(ImageSource::Render(image.clone()))
644 .size_full()
645 .object_fit(ObjectFit::Contain)
646 .rounded(px(THUMBNAIL_RADIUS)),
647 ),
648 None => preview.child(
649 gpui_kit::component::Icon::new(fallback.clone())
650 .size(px(THUMBNAIL_ICON))
651 .text_color(theme::text_muted()),
652 ),
653 };
654 h_flex()
655 .w_full()
656 .py(px(4.))
657 .gap(px(12.))
658 .items_center()
659 .child(preview)
660 .child(div().flex_1().min_w_0().truncate().child(label.clone()))
661 })
662 }
663
616 664 fn share_button(
617 665 app: &Entity<AppState>,
618 666 model: &CallModel,
@@ -48,6 +48,7 @@ const RING_GAP: f32 = 4.;
48pub(super) const CONTROL_SIZE: f32 = 44.;
48pub(super) const CONTROL_SIZE: f32 = 44.;
49const CONTROL_ICON: f32 = 20.;
49const CONTROL_ICON: f32 = 20.;
50pub(super) const MENU_WIDTH: f32 = 280.;
50pub(super) const MENU_WIDTH: f32 = 280.;
51const SHARE_MENU_WIDTH: f32 = 360.;
51const PULSE_PERIOD: Duration = Duration::from_millis(1400);
52const PULSE_PERIOD: Duration = Duration::from_millis(1400);
52const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);
53const BLINK_HALF_PERIOD: Duration = Duration::from_millis(500);
53const BLINK_DIMMED_OPACITY: f32 = 0.45;
54const BLINK_DIMMED_OPACITY: f32 = 0.45;
@@ -62,6 +63,11 @@ pub const NO_SHARE_HINT: &str = "Sharing starts once the call is connected";
62pub const NO_WINDOWS_HINT: &str = "No windows found";
63pub const NO_WINDOWS_HINT: &str = "No windows found";
63pub(super) const BANNER_HEIGHT: f32 = 40.;
64pub(super) const BANNER_HEIGHT: f32 = 40.;
64const MAX_WINDOW_ITEMS: usize = 12;
65const MAX_WINDOW_ITEMS: usize = 12;
66pub const SHARE_THUMBNAIL_TAG: &str = "call/share-menu/thumbnail";
67const SCREEN_THUMBNAIL: (f32, f32) = (128., 72.);
68const WINDOW_THUMBNAIL: (f32, f32) = (96., 54.);
69const THUMBNAIL_RADIUS: f32 = 6.;
70const THUMBNAIL_ICON: f32 = 22.;
65pub const LOBBY_TEXT: &str = "Waiting in the lobby...";
71pub const LOBBY_TEXT: &str = "Waiting in the lobby...";
66pub(super) const CHAT_PANEL_WIDTH: f32 = 320.;
72pub(super) const CHAT_PANEL_WIDTH: f32 = 320.;
67pub(super) const OVERLAY_BELOW: f32 = 720.;
73pub(super) const OVERLAY_BELOW: f32 = 720.;
@@ -574,7 +580,7 @@ fn share_items(
574 let screens = model.screens();
580 let screens = model.screens();
575 let single_screen = screens.len() == 1;
581 let single_screen = screens.len() == 1;
576 let mut popup = popup
582 let mut popup = popup
577 .min_w(px(MENU_WIDTH))
583 .min_w(px(SHARE_MENU_WIDTH))
578 .item(sound_switch_item(app, options.sound))
584 .item(sound_switch_item(app, options.sound))
579 .item(motion_switch_item(app, options.motion))
585 .item(motion_switch_item(app, options.motion))
580 .item(standout_switch_item(app, options.standout, model.camera_on))
586 .item(standout_switch_item(app, options.standout, model.camera_on))
@@ -585,11 +591,14 @@ fn share_items(
585 } else {
591 } else {
586 format!("Share screen {}", index + 1)
592 format!("Share screen {}", index + 1)
587 };
593 };
594 let thumbnail = model.share_thumbnail(source);
588 let source = source.clone();
595 let source = source.clone();
589 let app = app.clone();
596 let app = app.clone();
590 popup = popup.item(PopupMenuItem::new(label).icon(IconName::Monitor).on_click(
597 popup = popup.item(
591 move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),
598 share_source_item(label, thumbnail, IconName::Monitor, SCREEN_THUMBNAIL).on_click(
592 ));
599 move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),
600 ),
601 );
593 }
602 }
594 popup = popup
603 popup = popup
595 .separator()
604 .separator()
@@ -600,19 +609,58 @@ fn share_items(
600 }
609 }
601 for source in windows.into_iter().take(MAX_WINDOW_ITEMS) {
610 for source in windows.into_iter().take(MAX_WINDOW_ITEMS) {
602 let label = source.label();
611 let label = source.label();
612 let thumbnail = model.share_thumbnail(source);
603 let source = source.clone();
613 let source = source.clone();
604 let app = app.clone();
614 let app = app.clone();
605 popup = popup.item(
615 popup = popup.item(
606 PopupMenuItem::new(label)
616 share_source_item(label, thumbnail, IconName::AppWindow, WINDOW_THUMBNAIL).on_click(
607 .icon(IconName::AppWindow)
617 move |_, _, cx| app.update(cx, |state, cx| state.start_call_share(source.clone(), cx)),
608 .on_click(move |_, _, cx| {
618 ),
609 app.update(cx, |state, cx| state.start_call_share(source.clone(), cx))
610 }),
611 );
619 );
612 }
620 }
613 popup
621 popup
614}
622}
615
623
624fn share_source_item(
625 label: String,
626 thumbnail: Option<Arc<RenderImage>>,
627 fallback: IconName,
628 (width, height): (f32, f32),
629) -> PopupMenuItem {
630 PopupMenuItem::element(move |_, _| {
631 let preview = div()
632 .debug_selector(|| SHARE_THUMBNAIL_TAG.into())
633 .flex_none()
634 .w(px(width))
635 .h(px(height))
636 .rounded(px(THUMBNAIL_RADIUS))
637 .bg(theme::popup_hover())
638 .flex()
639 .items_center()
640 .justify_center();
641 let preview = match &thumbnail {
642 Some(image) => preview.child(
643 img(ImageSource::Render(image.clone()))
644 .size_full()
645 .object_fit(ObjectFit::Contain)
646 .rounded(px(THUMBNAIL_RADIUS)),
647 ),
648 None => preview.child(
649 gpui_kit::component::Icon::new(fallback.clone())
650 .size(px(THUMBNAIL_ICON))
651 .text_color(theme::text_muted()),
652 ),
653 };
654 h_flex()
655 .w_full()
656 .py(px(4.))
657 .gap(px(12.))
658 .items_center()
659 .child(preview)
660 .child(div().flex_1().min_w_0().truncate().child(label.clone()))
661 })
662}
663
616fn share_button(
664fn share_button(
617 app: &Entity<AppState>,
665 app: &Entity<AppState>,
618 model: &CallModel,
666 model: &CallModel,
crates/calling/src/call.rs +28 −3
@@ -57,13 +57,13 @@ use crate::software_audio::{SoftwareAudio, SoftwareAudioPlan};
57 57 use crate::state::{CallSignal, CallState};
58 58 use crate::timeline::{Timeline, TimelineEntry};
59 59 use crate::transfer::{Replacement, TransferEvent, TransferTarget};
60 use crate::video_frame::VideoKey;
60 use crate::video_frame::{VideoKey, VideoPicture};
61 61 use crate::video_layout::{
62 62 CAMERA_MID, MediaDescription, ONE_TO_ONE_SHARE_MID, SCREEN_STREAM, SendCapabilityReporter, SlotTable, VideoLines, VideoRouter, add_one_to_one_lines, add_share_line, add_video_lines, offer_plan, one_to_one_plan,
63 63 };
64 64 use crate::send_control::{RequestFilter, parse_request};
65 65 use crate::video_send::{LocalVideo, SendSource, VideoMode};
66 use crate::screen::{ShareKind, ShareSource, list_share_sources};
66 use crate::screen::{ShareKind, ShareSource, list_share_sources, share_thumbnail};
67 67 use crate::video_receive::{ReceiveChange, SourceRequester, VideoCounters, VideoReceive, spawn_video_pump};
68 68 use crate::trouter_events::{
69 69 CallEnd, CallEvent, CallbackLinks, ProgressStatus, callback_tag, classify, decode_body,
@@ -2676,6 +2676,10 @@ fn refresh_cameras(updates: mpsc::UnboundedSender<CallUpdate>, mode: VideoMode,
2676 2676 });
2677 2677 }
2678 2678
2679 const SHARE_THUMBNAIL_WINDOWS: usize = 12;
2680 const SHARE_THUMBNAIL_WIDTH: u32 = 320;
2681 const SHARE_THUMBNAIL_HEIGHT: u32 = 180;
2682
2679 2683 fn refresh_share_sources(updates: mpsc::UnboundedSender<CallUpdate>, mode: VideoMode) {
2680 2684 tokio::spawn(async move {
2681 2685 let sources = match mode {
@@ -2686,7 +2690,28 @@ fn refresh_share_sources(updates: mpsc::UnboundedSender<CallUpdate>, mode: Video
2686 2690 VideoMode::Off => Vec::new(),
2687 2691 VideoMode::Platform => tokio::task::spawn_blocking(list_share_sources).await.unwrap_or_default(),
2688 2692 };
2689 let _ = updates.send(CallUpdate::ShareSources(sources));
2693 let _ = updates.send(CallUpdate::ShareSources(sources.clone()));
2694 let wanted: Vec<ShareSource> = sources
2695 .iter()
2696 .filter(|source| source.kind == ShareKind::Screen)
2697 .chain(sources.iter().filter(|source| source.kind == ShareKind::Window).take(SHARE_THUMBNAIL_WINDOWS))
2698 .cloned()
2699 .collect();
2700 for source in wanted {
2701 let picture = match mode {
2702 VideoMode::Platform => {
2703 let wanted = source.clone();
2704 tokio::task::spawn_blocking(move || share_thumbnail(&wanted, SHARE_THUMBNAIL_WIDTH, SHARE_THUMBNAIL_HEIGHT)).await.ok().flatten()
2705 }
2706 VideoMode::Pattern => Some(VideoPicture::solid(SHARE_THUMBNAIL_WIDTH, SHARE_THUMBNAIL_HEIGHT, 120, 80, 40)),
2707 VideoMode::Off => None,
2708 };
2709 if let Some(picture) = picture
2710 && updates.send(CallUpdate::ShareThumbnail { source, picture: Arc::new(picture) }).is_err()
2711 {
2712 return;
2713 }
2714 }
2690 2715 });
2691 2716 }
2692 2717
@@ -57,13 +57,13 @@ use crate::software_audio::{SoftwareAudio, SoftwareAudioPlan};
57use crate::state::{CallSignal, CallState};
57use crate::state::{CallSignal, CallState};
58use crate::timeline::{Timeline, TimelineEntry};
58use crate::timeline::{Timeline, TimelineEntry};
59use crate::transfer::{Replacement, TransferEvent, TransferTarget};
59use crate::transfer::{Replacement, TransferEvent, TransferTarget};
60use crate::video_frame::VideoKey;
60use crate::video_frame::{VideoKey, VideoPicture};
61use crate::video_layout::{
61use crate::video_layout::{
62 CAMERA_MID, MediaDescription, ONE_TO_ONE_SHARE_MID, SCREEN_STREAM, SendCapabilityReporter, SlotTable, VideoLines, VideoRouter, add_one_to_one_lines, add_share_line, add_video_lines, offer_plan, one_to_one_plan,
62 CAMERA_MID, MediaDescription, ONE_TO_ONE_SHARE_MID, SCREEN_STREAM, SendCapabilityReporter, SlotTable, VideoLines, VideoRouter, add_one_to_one_lines, add_share_line, add_video_lines, offer_plan, one_to_one_plan,
63};
63};
64use crate::send_control::{RequestFilter, parse_request};
64use crate::send_control::{RequestFilter, parse_request};
65use crate::video_send::{LocalVideo, SendSource, VideoMode};
65use crate::video_send::{LocalVideo, SendSource, VideoMode};
66use crate::screen::{ShareKind, ShareSource, list_share_sources};
66use crate::screen::{ShareKind, ShareSource, list_share_sources, share_thumbnail};
67use crate::video_receive::{ReceiveChange, SourceRequester, VideoCounters, VideoReceive, spawn_video_pump};
67use crate::video_receive::{ReceiveChange, SourceRequester, VideoCounters, VideoReceive, spawn_video_pump};
68use crate::trouter_events::{
68use crate::trouter_events::{
69 CallEnd, CallEvent, CallbackLinks, ProgressStatus, callback_tag, classify, decode_body,
69 CallEnd, CallEvent, CallbackLinks, ProgressStatus, callback_tag, classify, decode_body,
@@ -2676,6 +2676,10 @@ fn refresh_cameras(updates: mpsc::UnboundedSender<CallUpdate>, mode: VideoMode,
2676 });
2676 });
2677}
2677}
2678
2678
2679const SHARE_THUMBNAIL_WINDOWS: usize = 12;
2680const SHARE_THUMBNAIL_WIDTH: u32 = 320;
2681const SHARE_THUMBNAIL_HEIGHT: u32 = 180;
2682
2679fn refresh_share_sources(updates: mpsc::UnboundedSender<CallUpdate>, mode: VideoMode) {
2683fn refresh_share_sources(updates: mpsc::UnboundedSender<CallUpdate>, mode: VideoMode) {
2680 tokio::spawn(async move {
2684 tokio::spawn(async move {
2681 let sources = match mode {
2685 let sources = match mode {
@@ -2686,7 +2690,28 @@ fn refresh_share_sources(updates: mpsc::UnboundedSender<CallUpdate>, mode: Video
2686 VideoMode::Off => Vec::new(),
2690 VideoMode::Off => Vec::new(),
2687 VideoMode::Platform => tokio::task::spawn_blocking(list_share_sources).await.unwrap_or_default(),
2691 VideoMode::Platform => tokio::task::spawn_blocking(list_share_sources).await.unwrap_or_default(),
2688 };
2692 };
2689 let _ = updates.send(CallUpdate::ShareSources(sources));
2693 let _ = updates.send(CallUpdate::ShareSources(sources.clone()));
2694 let wanted: Vec<ShareSource> = sources
2695 .iter()
2696 .filter(|source| source.kind == ShareKind::Screen)
2697 .chain(sources.iter().filter(|source| source.kind == ShareKind::Window).take(SHARE_THUMBNAIL_WINDOWS))
2698 .cloned()
2699 .collect();
2700 for source in wanted {
2701 let picture = match mode {
2702 VideoMode::Platform => {
2703 let wanted = source.clone();
2704 tokio::task::spawn_blocking(move || share_thumbnail(&wanted, SHARE_THUMBNAIL_WIDTH, SHARE_THUMBNAIL_HEIGHT)).await.ok().flatten()
2705 }
2706 VideoMode::Pattern => Some(VideoPicture::solid(SHARE_THUMBNAIL_WIDTH, SHARE_THUMBNAIL_HEIGHT, 120, 80, 40)),
2707 VideoMode::Off => None,
2708 };
2709 if let Some(picture) = picture
2710 && updates.send(CallUpdate::ShareThumbnail { source, picture: Arc::new(picture) }).is_err()
2711 {
2712 return;
2713 }
2714 }
2690 });
2715 });
2691}
2716}
2692
2717
crates/calling/src/control.rs +2 −1
@@ -25,7 +25,7 @@ use crate::signaling::{Callee, MeetingTarget};
25 25 use crate::transfer::Replacement;
26 26 use crate::state::CallState;
27 27 use crate::video_layout::VideoWant;
28 use crate::video_frame::VideoHub;
28 use crate::video_frame::{VideoHub, VideoPicture};
29 29 use crate::whiteboard::ContentShare;
30 30
31 31 #[derive(Debug, Clone, PartialEq, Eq)]
@@ -107,6 +107,7 @@ pub enum CallUpdate {
107 107 Cameras(Vec<CameraDevice>),
108 108 LocalShare(Option<String>),
109 109 ShareSources(Vec<ShareSource>),
110 ShareThumbnail { source: ShareSource, picture: Arc<VideoPicture> },
110 111 ShareSound(bool),
111 112 OwnHand(Option<u64>),
112 113 Reaction { mri: String, reaction: Reaction },
@@ -25,7 +25,7 @@ use crate::signaling::{Callee, MeetingTarget};
25use crate::transfer::Replacement;
25use crate::transfer::Replacement;
26use crate::state::CallState;
26use crate::state::CallState;
27use crate::video_layout::VideoWant;
27use crate::video_layout::VideoWant;
28use crate::video_frame::VideoHub;
28use crate::video_frame::{VideoHub, VideoPicture};
29use crate::whiteboard::ContentShare;
29use crate::whiteboard::ContentShare;
30
30
31#[derive(Debug, Clone, PartialEq, Eq)]
31#[derive(Debug, Clone, PartialEq, Eq)]
@@ -107,6 +107,7 @@ pub enum CallUpdate {
107 Cameras(Vec<CameraDevice>),
107 Cameras(Vec<CameraDevice>),
108 LocalShare(Option<String>),
108 LocalShare(Option<String>),
109 ShareSources(Vec<ShareSource>),
109 ShareSources(Vec<ShareSource>),
110 ShareThumbnail { source: ShareSource, picture: Arc<VideoPicture> },
110 ShareSound(bool),
111 ShareSound(bool),
111 OwnHand(Option<u64>),
112 OwnHand(Option<u64>),
112 Reaction { mri: String, reaction: Reaction },
113 Reaction { mri: String, reaction: Reaction },
crates/calling/src/screen.rs +69 −1
@@ -1,4 +1,4 @@
1 use std::sync::Arc;
1 use std::sync::{Arc, Mutex};
2 2 use std::sync::atomic::{AtomicU32, Ordering};
3 3 use std::time::Duration;
4 4
@@ -7,6 +7,7 @@ use libwebrtc::native::yuv_helper::argb_to_i420;
7 7 use libwebrtc::video_frame::I420Buffer;
8 8
9 9 use crate::capture::Capture;
10 use crate::video_frame::VideoPicture;
10 11 use crate::error::{Error, Result};
11 12
12 13
@@ -73,6 +74,51 @@ pub fn list_share_sources() -> Vec<ShareSource> {
73 74 .collect()
74 75 }
75 76
77 const THUMBNAIL_ATTEMPTS: u32 = 5;
78 const THUMBNAIL_RETRY: Duration = Duration::from_millis(40);
79
80 pub fn share_thumbnail(wanted: &ShareSource, max_width: u32, max_height: u32) -> Option<VideoPicture> {
81 let source = sources_of(wanted.kind).into_iter().find(|(source, _)| source.id == wanted.id).map(|(_, raw)| raw)?;
82 let mut capturer = capturer(wanted.kind)?;
83 let captured: Arc<Mutex<Option<VideoPicture>>> = Arc::default();
84 let sink = captured.clone();
85 capturer.start_capture(Some(source), move |result| {
86 let Ok(frame) = result else { return };
87 let (width, height) = (frame.width().max(0) as u32, frame.height().max(0) as u32);
88 if let Some(picture) = scaled_bgra(frame.data(), width, height, frame.stride(), max_width, max_height)
89 && let Ok(mut slot) = sink.lock()
90 {
91 *slot = Some(picture);
92 }
93 });
94 for _ in 0..THUMBNAIL_ATTEMPTS {
95 capturer.capture_frame();
96 if let Some(picture) = captured.lock().ok().and_then(|mut slot| slot.take()) {
97 return Some(picture);
98 }
99 std::thread::sleep(THUMBNAIL_RETRY);
100 }
101 None
102 }
103
104 fn scaled_bgra(bytes: &[u8], width: u32, height: u32, stride: u32, max_width: u32, max_height: u32) -> Option<VideoPicture> {
105 if width == 0 || height == 0 || (stride as usize) < width as usize * 4 || bytes.len() < stride as usize * height as usize {
106 return None;
107 }
108 let scale = (max_width as f32 / width as f32).min(max_height as f32 / height as f32).min(1.);
109 let (target_width, target_height) = (((width as f32 * scale) as u32).max(1), ((height as f32 * scale) as u32).max(1));
110 let mut bgra = Vec::with_capacity(target_width as usize * target_height as usize * 4);
111 for row in 0..target_height {
112 let source_row = (row as u64 * height as u64 / target_height as u64) as usize;
113 for column in 0..target_width {
114 let source_column = (column as u64 * width as u64 / target_width as u64) as usize;
115 let offset = source_row * stride as usize + source_column * 4;
116 bgra.extend_from_slice(&[bytes[offset], bytes[offset + 1], bytes[offset + 2], u8::MAX]);
117 }
118 }
119 Some(VideoPicture { width: target_width, height: target_height, bgra })
120 }
121
76 122 fn i420_from_bgra(bytes: &[u8], width: u32, height: u32, stride: u32) -> I420Buffer {
77 123 let mut buffer = I420Buffer::new(width, height);
78 124 let (stride_y, stride_u, stride_v) = buffer.strides();
@@ -121,3 +167,25 @@ mod tests {
121 167 assert_eq!(window.label(), "Notes");
122 168 }
123 169 }
170
171 #[cfg(test)]
172 mod thumbnail_tests {
173 use super::scaled_bgra;
174
175 #[test]
176 fn a_thumbnail_keeps_the_aspect_and_drops_the_row_padding() {
177 let (width, height, stride) = (8u32, 4u32, 40u32);
178 let mut bytes = vec![0u8; (stride * height) as usize];
179 for row in 0..height as usize {
180 for column in 0..width as usize {
181 let offset = row * stride as usize + column * 4;
182 bytes[offset..offset + 4].copy_from_slice(&[column as u8, row as u8, 7, 0]);
183 }
184 }
185 let picture = scaled_bgra(&bytes, width, height, stride, 4, 4).unwrap();
186 assert_eq!((picture.width, picture.height), (4, 2));
187 assert_eq!(picture.bgra.len(), 4 * 2 * 4);
188 assert_eq!(&picture.bgra[4..8], &[2, 0, 7, 255]);
189 assert!(scaled_bgra(&bytes, width, height, 8, 4, 4).is_none());
190 }
191 }
@@ -1,4 +1,4 @@
1use std::sync::Arc;
1use std::sync::{Arc, Mutex};
2use std::sync::atomic::{AtomicU32, Ordering};
2use std::sync::atomic::{AtomicU32, Ordering};
3use std::time::Duration;
3use std::time::Duration;
4
4
@@ -7,6 +7,7 @@ use libwebrtc::native::yuv_helper::argb_to_i420;
7use libwebrtc::video_frame::I420Buffer;
7use libwebrtc::video_frame::I420Buffer;
8
8
9use crate::capture::Capture;
9use crate::capture::Capture;
10use crate::video_frame::VideoPicture;
10use crate::error::{Error, Result};
11use crate::error::{Error, Result};
11
12
12
13
@@ -73,6 +74,51 @@ pub fn list_share_sources() -> Vec<ShareSource> {
73 .collect()
74 .collect()
74}
75}
75
76
77const THUMBNAIL_ATTEMPTS: u32 = 5;
78const THUMBNAIL_RETRY: Duration = Duration::from_millis(40);
79
80pub fn share_thumbnail(wanted: &ShareSource, max_width: u32, max_height: u32) -> Option<VideoPicture> {
81 let source = sources_of(wanted.kind).into_iter().find(|(source, _)| source.id == wanted.id).map(|(_, raw)| raw)?;
82 let mut capturer = capturer(wanted.kind)?;
83 let captured: Arc<Mutex<Option<VideoPicture>>> = Arc::default();
84 let sink = captured.clone();
85 capturer.start_capture(Some(source), move |result| {
86 let Ok(frame) = result else { return };
87 let (width, height) = (frame.width().max(0) as u32, frame.height().max(0) as u32);
88 if let Some(picture) = scaled_bgra(frame.data(), width, height, frame.stride(), max_width, max_height)
89 && let Ok(mut slot) = sink.lock()
90 {
91 *slot = Some(picture);
92 }
93 });
94 for _ in 0..THUMBNAIL_ATTEMPTS {
95 capturer.capture_frame();
96 if let Some(picture) = captured.lock().ok().and_then(|mut slot| slot.take()) {
97 return Some(picture);
98 }
99 std::thread::sleep(THUMBNAIL_RETRY);
100 }
101 None
102}
103
104fn scaled_bgra(bytes: &[u8], width: u32, height: u32, stride: u32, max_width: u32, max_height: u32) -> Option<VideoPicture> {
105 if width == 0 || height == 0 || (stride as usize) < width as usize * 4 || bytes.len() < stride as usize * height as usize {
106 return None;
107 }
108 let scale = (max_width as f32 / width as f32).min(max_height as f32 / height as f32).min(1.);
109 let (target_width, target_height) = (((width as f32 * scale) as u32).max(1), ((height as f32 * scale) as u32).max(1));
110 let mut bgra = Vec::with_capacity(target_width as usize * target_height as usize * 4);
111 for row in 0..target_height {
112 let source_row = (row as u64 * height as u64 / target_height as u64) as usize;
113 for column in 0..target_width {
114 let source_column = (column as u64 * width as u64 / target_width as u64) as usize;
115 let offset = source_row * stride as usize + source_column * 4;
116 bgra.extend_from_slice(&[bytes[offset], bytes[offset + 1], bytes[offset + 2], u8::MAX]);
117 }
118 }
119 Some(VideoPicture { width: target_width, height: target_height, bgra })
120}
121
76fn i420_from_bgra(bytes: &[u8], width: u32, height: u32, stride: u32) -> I420Buffer {
122fn i420_from_bgra(bytes: &[u8], width: u32, height: u32, stride: u32) -> I420Buffer {
77 let mut buffer = I420Buffer::new(width, height);
123 let mut buffer = I420Buffer::new(width, height);
78 let (stride_y, stride_u, stride_v) = buffer.strides();
124 let (stride_y, stride_u, stride_v) = buffer.strides();
@@ -121,3 +167,25 @@ mod tests {
121 assert_eq!(window.label(), "Notes");
167 assert_eq!(window.label(), "Notes");
122 }
168 }
123}
169}
170
171#[cfg(test)]
172mod thumbnail_tests {
173 use super::scaled_bgra;
174
175 #[test]
176 fn a_thumbnail_keeps_the_aspect_and_drops_the_row_padding() {
177 let (width, height, stride) = (8u32, 4u32, 40u32);
178 let mut bytes = vec![0u8; (stride * height) as usize];
179 for row in 0..height as usize {
180 for column in 0..width as usize {
181 let offset = row * stride as usize + column * 4;
182 bytes[offset..offset + 4].copy_from_slice(&[column as u8, row as u8, 7, 0]);
183 }
184 }
185 let picture = scaled_bgra(&bytes, width, height, stride, 4, 4).unwrap();
186 assert_eq!((picture.width, picture.height), (4, 2));
187 assert_eq!(picture.bgra.len(), 4 * 2 * 4);
188 assert_eq!(&picture.bgra[4..8], &[2, 0, 7, 255]);
189 assert!(scaled_bgra(&bytes, width, height, 8, 4, 4).is_none());
190 }
191}