pinray_core/source.rs
1/// Opaque identifier for a capturable source.
2///
3/// Formats are platform-specific (e.g. `display:\\.\DISPLAY1`,
4/// `window:1234`, `audio:system-mix`); treat them as opaque strings from
5/// [`CaptureSource`] enumeration. The special value `"auto"` selects the
6/// primary display without enumerating. Window ids are only valid while the
7/// window exists — re-enumerate before building a session.
8#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9pub struct SourceId(pub String);
10
11impl SourceId {
12 pub fn new(value: impl Into<String>) -> Self {
13 Self(value.into())
14 }
15}
16
17/// A capturable display/monitor.
18#[derive(Debug, Clone, PartialEq, Eq)]
19pub struct DisplaySource {
20 pub id: SourceId,
21 pub name: String,
22 pub width: u32,
23 pub height: u32,
24 /// Display scale × 1000 (e.g. 2000 = 2× HiDPI). Best-effort; 1000 where
25 /// the platform has no reliable per-monitor scale.
26 pub scale_factor_milli: u32,
27 pub is_primary: bool,
28}
29
30/// A capturable application window.
31#[derive(Debug, Clone, PartialEq, Eq)]
32pub struct WindowSource {
33 pub id: SourceId,
34 pub title: String,
35 /// Owning application, when the platform exposes it.
36 pub app_name: Option<String>,
37}
38
39/// A capturable audio endpoint.
40#[derive(Debug, Clone, PartialEq, Eq)]
41pub struct AudioDeviceSource {
42 pub id: SourceId,
43 pub name: String,
44 pub is_default: bool,
45}
46
47/// Anything [`enumerate_sources`](crate::CaptureSession) can return.
48#[derive(Debug, Clone, PartialEq, Eq)]
49pub enum CaptureSource {
50 Display(DisplaySource),
51 Window(WindowSource),
52 SystemAudio(AudioDeviceSource),
53 Microphone(AudioDeviceSource),
54}