1use crate::{
2 error::{PinrayError, Result},
3 frame::{ColorSpace, PixelFormat, Rect},
4 source::SourceId,
5};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum CursorMode {
9 Embedded,
10 Hidden,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub enum VideoCaptureTarget {
15 Display(SourceId),
16 Window(SourceId),
17}
18
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub enum AudioCapture {
21 SystemMix,
22 Microphone(SourceId),
23}
24
25#[derive(Debug, Clone, PartialEq, Eq)]
26pub struct SessionConfig {
27 pub backend_preference: crate::backend::BackendPreference,
28 pub video_target: Option<VideoCaptureTarget>,
29 pub audio_capture: Option<AudioCapture>,
30 pub restore_token: Option<String>,
31 pub pixel_format: PixelFormat,
32 pub color_space: Option<ColorSpace>,
33 pub cursor_mode: CursorMode,
34 pub crop_rect: Option<Rect>,
35 pub frame_rate: Option<u32>,
36 pub queue_depth: u32,
37}
38
39impl Default for SessionConfig {
40 fn default() -> Self {
41 Self {
42 backend_preference: crate::backend::BackendPreference::Auto,
43 video_target: None,
44 audio_capture: None,
45 restore_token: None,
46 pixel_format: PixelFormat::Bgra8888,
47 color_space: Some(ColorSpace::Srgb),
48 cursor_mode: CursorMode::Embedded,
49 crop_rect: None,
50 frame_rate: Some(60),
51 queue_depth: 2,
52 }
53 }
54}
55
56impl SessionConfig {
57 pub fn validate(&self) -> Result<()> {
58 if self.video_target.is_none() && self.audio_capture.is_none() {
59 return Err(PinrayError::InvalidConfig(
60 "at least one of video_target or audio_capture must be set".into(),
61 ));
62 }
63
64 if let Some(frame_rate) = self.frame_rate
65 && frame_rate == 0
66 {
67 return Err(PinrayError::InvalidConfig(
68 "frame_rate must be greater than zero".into(),
69 ));
70 }
71
72 if self.queue_depth == 0 {
73 return Err(PinrayError::InvalidConfig(
74 "queue_depth must be greater than zero".into(),
75 ));
76 }
77
78 if let Some(rect) = self.crop_rect
79 && (rect.width == 0 || rect.height == 0)
80 {
81 return Err(PinrayError::InvalidConfig(
82 "crop_rect width and height must be greater than zero".into(),
83 ));
84 }
85
86 Ok(())
87 }
88}