waycap_rs/pipeline/
builder.rs

1use crate::{
2    encoders::dynamic_encoder::DynamicEncoder,
3    types::{
4        config::{AudioEncoder, QualityPreset, VideoEncoder},
5        error::Result,
6    },
7    Capture,
8};
9
10pub struct CaptureBuilder {
11    video_encoder: Option<VideoEncoder>,
12    audio_encoder: Option<AudioEncoder>,
13    quality_preset: Option<QualityPreset>,
14    include_cursor: bool,
15    include_audio: bool,
16    target_fps: u64,
17}
18
19impl Default for CaptureBuilder {
20    fn default() -> Self {
21        Self::new()
22    }
23}
24
25impl CaptureBuilder {
26    pub fn new() -> Self {
27        Self {
28            video_encoder: None,
29            audio_encoder: None,
30            quality_preset: None,
31            include_cursor: false,
32            include_audio: false,
33            target_fps: 60,
34        }
35    }
36
37    /// Optional: Force use a specific video encoder.
38    /// Default: Uses EGL to determine GPU at runtime.
39    pub fn with_video_encoder(mut self, encoder: VideoEncoder) -> Self {
40        self.video_encoder = Some(encoder);
41        self
42    }
43
44    /// Optional: Force use a specific audio encoder.
45    /// Default: Opus audio encoder.
46    pub fn with_audio_encoder(mut self, encoder: AudioEncoder) -> Self {
47        self.audio_encoder = Some(encoder);
48        self
49    }
50
51    pub fn with_cursor_shown(mut self) -> Self {
52        self.include_cursor = true;
53        self
54    }
55
56    pub fn with_audio(mut self) -> Self {
57        self.include_audio = true;
58        self
59    }
60
61    pub fn with_quality_preset(mut self, quality: QualityPreset) -> Self {
62        self.quality_preset = Some(quality);
63        self
64    }
65
66    /// Optional: Set a target FPS for the recording.
67    /// Default: 60fps
68    pub fn with_target_fps(mut self, fps: u64) -> Self {
69        self.target_fps = fps;
70        self
71    }
72
73    pub fn build(self) -> Result<Capture<DynamicEncoder>> {
74        let quality = match self.quality_preset {
75            Some(qual) => qual,
76            None => QualityPreset::Medium,
77        };
78
79        let audio_encoder = if self.include_audio {
80            match self.audio_encoder {
81                Some(enc) => enc,
82                None => AudioEncoder::Opus,
83            }
84        } else {
85            AudioEncoder::Opus
86        };
87
88        Capture::new(
89            self.video_encoder,
90            audio_encoder,
91            quality,
92            self.include_cursor,
93            self.include_audio,
94            self.target_fps,
95        )
96    }
97}