obws 0.15.0

The obws (obvious) remote control library for OBS.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
//! Additional structs for use with
//! [`crate::client::Inputs::set_settings`].

use std::path::Path;

use rgb::RGBA8;
use serde::{Serialize, Serializer, ser::SerializeStruct};
use time::Duration;

use crate::common::FontFlags;

/// Identifier for input capture sources.
pub const SOURCE_COREAUDIO_INPUT_CAPTURE: &str = "coreaudio_input_capture";
/// Identifier for output capture sources.
pub const SOURCE_COREAUDIO_OUTPUT_CAPTURE: &str = "coreaudio_output_capture";
/// Identifier for browser sources.
pub const SOURCE_BROWSER_SOURCE: &str = "browser_source";
/// Identifier for color sources.
pub const SOURCE_COLOR_SOURCE_V3: &str = "color_source_v3";
/// Identifier for display capture sources.
pub const SOURCE_DISPLAY_CAPTURE: &str = "display_capture";
/// Identifier for image sources.
pub const SOURCE_IMAGE_SOURCE: &str = "image_source";
/// Identifier for image slide-show sources.
pub const SOURCE_SLIDESHOW: &str = "slideshow";
/// Identifier for `FFmpeg` video sources.
pub const SOURCE_FFMPEG_SOURCE: &str = "ffmpeg_source";
/// Identifier for `FreeType2` text sources.
pub const SOURCE_TEXT_FT2_SOURCE_V2: &str = "text_ft2_source_v2";
/// Identifier for VLC video sources.
pub const SOURCE_VLC_SOURCE: &str = "vlc_source";
/// Identifier for audio/video input capture sources.
pub const SOURCE_AV_CAPTURE_INPUT_V2: &str = "av_capture_input_v2";
/// Identifier for source window capture sources.
pub const SOURCE_WINDOW_CAPTURE: &str = "window_capture";

/// Settings specific to a **`CoreAudio`** input capture source.
#[derive(Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct CoreaudioInputCapture<'a> {
    /// Input device identifier.
    pub device_id: &'a str,
}

/// Settings specific to a **`CoreAudio`** output capture source.
#[derive(Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct CoreaudioOutputCapture<'a> {
    /// Output device identifier.
    pub device_id: &'a str,
}

/// Settings specific to a browser source.
#[derive(Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct BrowserSource<'a> {
    /// Whether to use a local file instead of a remote location.
    ///
    /// If true, the [`Self::local_file`] setting is used, [`Self::url`] otherwise.
    pub is_local_file: bool,
    /// Local file to open as web page. Only used if [`Self::is_local_file`] is set to `true`.
    pub local_file: &'a Path,
    /// Remote location of a web page. Only used if [`Self::is_local_file`] is set to `false`.
    pub url: &'a str,
    /// Browser window width in pixels.
    pub width: u32,
    /// Browser window height in pixels.
    pub height: u32,
    /// Use custom frame rate.
    pub fps_custom: bool,
    /// Custom FPS, only used if [`Self::fps_custom`] is set to `true`.
    pub fps: u16,
    /// Control audio via OBS.
    pub reroute_audio: bool,
    /// Custom CSS.
    pub css: &'a str,
    /// Shutdown source when not visible.
    pub shutdown: bool,
    /// Refresh browser when scene becomes active.
    pub restart_when_active: bool,
}

impl Default for BrowserSource<'_> {
    fn default() -> Self {
        Self {
            is_local_file: false,
            local_file: Path::new(""),
            url: "https://obsproject.com/browser-source",
            width: 800,
            height: 600,
            fps_custom: false,
            fps: 30,
            reroute_audio: false,
            css: "body { background-color: rgba(0, 0, 0, 0); margin: 0px auto; overflow: hidden; }",
            shutdown: false,
            restart_when_active: false,
        }
    }
}

/// Settings specific to a color source.
#[derive(Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct ColorSourceV3 {
    /// Color to display.
    #[serde(with = "crate::serde::rgba8_inverse")]
    pub color: RGBA8,
    /// Source width in pixels.
    pub width: u32,
    /// Source height in pixels.
    pub height: u32,
}

impl Default for ColorSourceV3 {
    fn default() -> Self {
        Self {
            color: RGBA8::new(209, 209, 209, 255),
            width: 0,
            height: 0,
        }
    }
}

/// Settings specific to a display capture source.
#[derive(Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct DisplayCapture<'a> {
    /// Index of the display to capture. Usually `0` for the main display.
    pub display: u8,
    /// Whether to show the cursor on the captured input.
    pub show_cursor: bool,
    /// Cropping of the window input.
    #[serde(flatten)]
    pub crop_mode: CropMode<'a>,
}

/// The capture cropping for a [`DisplayCapture`] source.
#[non_exhaustive]
pub enum CropMode<'a> {
    /// Disable any cropping.
    None,
    /// Manual cropping by pixel dimensions.
    Manual {
        /// Left side cropping.
        left: f64,
        /// Top side cropping.
        top: f64,
        /// Right side cropping.
        right: f64,
        /// Bottom side cropping.
        bottom: f64,
    },
    /// Crop the capture to a specific window on the screen.
    ToWindow {
        /// Owner of the window. Usually the program name.
        owner_name: &'a str,
        /// Title of the window. Depending on the OS usually found at the top window corner.
        window_name: &'a str,
        /// ID of the window.
        window: u32,
        /// List up windows with empty names in the UI drop-down selection.
        show_empty_names: bool,
    },
    /// A combination of [`Self::ToWindow`] and [`Self::Manual`], cropping to the window first,
    /// then applying manual cropping.
    ToWindowAndManual {
        /// Owner of the window. Usually the program name.
        owner_name: &'a str,
        /// Title of the window. Depending on the OS usually found at the top window corner.
        window_name: &'a str,
        /// ID of the window.
        window: u32,
        /// List up windows with empty names in the UI drop-down selection.
        show_empty_names: bool,
        /// Left side cropping.
        left: f64,
        /// Top side cropping.
        top: f64,
        /// Right side cropping.
        right: f64,
        /// Bottom side cropping.
        bottom: f64,
    },
}

impl Serialize for CropMode<'_> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        match self {
            Self::None => {
                let mut s = serializer.serialize_struct("CropMode", 1)?;
                s.serialize_field("crop_mode", &0u8)?;
                s.end()
            }
            Self::Manual {
                left,
                top,
                right,
                bottom,
            } => {
                let mut s = serializer.serialize_struct("CropMode", 5)?;
                s.serialize_field("crop_mode", &1u8)?;
                s.serialize_field("manual.origin.x", left)?;
                s.serialize_field("manual.origin.y", top)?;
                s.serialize_field("manual.size.width", right)?;
                s.serialize_field("manual.size.height", bottom)?;
                s.end()
            }
            Self::ToWindow {
                owner_name,
                window_name,
                window,
                show_empty_names,
            } => {
                let mut s = serializer.serialize_struct("CropMode", 5)?;
                s.serialize_field("crop_mode", &2u8)?;
                s.serialize_field("owner_name", owner_name)?;
                s.serialize_field("window_name", window_name)?;
                s.serialize_field("window", window)?;
                s.serialize_field("show_empty_names", show_empty_names)?;
                s.end()
            }
            CropMode::ToWindowAndManual {
                owner_name,
                window_name,
                window,
                show_empty_names,
                left,
                top,
                right,
                bottom,
            } => {
                let mut s = serializer.serialize_struct("CropMode", 9)?;
                s.serialize_field("crop_mode", &3u8)?;
                s.serialize_field("owner_name", owner_name)?;
                s.serialize_field("window_name", window_name)?;
                s.serialize_field("window", window)?;
                s.serialize_field("show_empty_names", show_empty_names)?;
                s.serialize_field("window.origin.x", left)?;
                s.serialize_field("window.origin.y", top)?;
                s.serialize_field("window.size.width", right)?;
                s.serialize_field("window.size.height", bottom)?;
                s.end()
            }
        }
    }
}

/// Settings specific to an image source.
#[derive(Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct ImageSource<'a> {
    /// Location of the file to display.
    pub file: &'a Path,
    /// Unload the image file when the source isn't visible.
    pub unload: bool,
}

impl Default for ImageSource<'_> {
    fn default() -> Self {
        Self {
            file: Path::new(""),
            unload: false,
        }
    }
}

/// Settings specific to an image slide-show source.
#[derive(Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct Slideshow<'a> {
    /// Behavior of playback in relation to visibility.
    pub playback_behavior: PlaybackBehavior,
    /// Control mode to change between pictures.
    pub slide_mode: SlideMode,
    /// Swapping animation between current and next picture.
    pub transition: Transition,
    /// Time between Slides. Minimum value is `50ms`.
    #[serde(with = "crate::serde::duration_millis")]
    pub slide_time: Duration,
    /// Minimum value is `0ms`.
    #[serde(with = "crate::serde::duration_millis")]
    pub transition_speed: Duration,
    /// Whether to endlessly loop the slide-show images.
    #[serde(rename = "loop")]
    pub loop_: bool,
    /// Hide when slide-show is done.
    pub hide: bool,
    /// Randomize playback.
    pub randomize: bool,
    /// Bounding Size / Aspect Ratio.
    pub use_custom_size: CustomSize,
    /// Image files.
    pub files: &'a [SlideshowFile<'a>],
}

impl Default for Slideshow<'_> {
    fn default() -> Self {
        Self {
            playback_behavior: PlaybackBehavior::AlwaysPlay,
            slide_mode: SlideMode::default(),
            transition: Transition::default(),
            slide_time: Duration::seconds(8),
            transition_speed: Duration::milliseconds(700),
            loop_: true,
            hide: false,
            randomize: false,
            use_custom_size: CustomSize::default(),
            files: &[],
        }
    }
}

/// Single file as part of a [`Slideshow`].
#[derive(Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct SlideshowFile<'a> {
    /// Location of the file to display.
    pub value: &'a Path,
    /// Whether the file is currently visible in the source.
    pub hidden: bool,
    /// Whether the file is currently selected.
    pub selected: bool,
}

impl Default for SlideshowFile<'_> {
    fn default() -> Self {
        Self {
            value: Path::new(""),
            hidden: false,
            selected: false,
        }
    }
}

/// Playback behavior setting for use in [`Slideshow`].
#[derive(Clone, Copy, Serialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum PlaybackBehavior {
    /// Always play even when not visible.
    AlwaysPlay,
    /// Stop when not visible, restart when visible.
    StopRestart,
    /// Pause when not visible, un-pause when visible
    PauseUnpause,
}

/// Playback control mode for use in [`Slideshow`].
#[derive(Clone, Copy, Default, Serialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum SlideMode {
    /// Automatic.
    #[default]
    ModeAuto,
    /// Manual (Use hotkeys to control slide-show).
    ModeManual,
}

/// Transition animation between images in a [`Slideshow`].
#[derive(Default, Serialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum Transition {
    /// Immediately replace without animation.
    Cut,
    /// Gradually fade between the two images until the new one is fully visible.
    #[default]
    Fade,
    /// Swipe the new image over the old one.
    Swipe,
    /// Slide out the old and slide in the new image.
    Slide,
}

/// Aspect ratios and bounding sizes for use in [`Slideshow`].
#[derive(Clone, Copy, Default, Serialize)]
#[serde(into = "String")]
#[non_exhaustive]
pub enum CustomSize {
    /// Automatically detect a ratio based on the input.
    #[default]
    Automatic,
    /// 16:9 aspect ratio.
    SixteenToNine,
    /// 16:10 aspect ratio.
    SixteenToTen,
    /// 4:3 aspect ratio.
    FourToThree,
    /// 1:1 aspect ratio.
    OneToOne,
    /// Custom width:height ratio.
    CustomRatio(u32, u32),
    /// Custom width x height size.
    CustomSize(u32, u32),
}

impl From<CustomSize> for String {
    fn from(s: CustomSize) -> Self {
        match s {
            CustomSize::Automatic => "Automatic".to_owned(),
            CustomSize::SixteenToNine => "16:9".to_owned(),
            CustomSize::SixteenToTen => "16:10".to_owned(),
            CustomSize::FourToThree => "4:3".to_owned(),
            CustomSize::OneToOne => "1:1".to_owned(),
            CustomSize::CustomRatio(w, h) => format!("{w}:{h}"),
            CustomSize::CustomSize(w, h) => format!("{w}x{h}"),
        }
    }
}

/// Settings specific to a **`FFmpeg`** video source.
#[derive(Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct FfmpegSource<'a> {
    /// Whether the source is a local file or remote.
    pub is_local_file: bool,
    /// Location of a local media file. Only used if [`Self::is_local_file`] is set to `true`.
    pub local_file: &'a Path,
    /// Endlessly play the media.  Only used if [`Self::is_local_file`] is set to `true`.
    pub looping: bool,
    /// Network buffering in Megabytes. Only used if [`Self::is_local_file`] is set to `false`.
    pub buffering_mb: u8,
    /// URL of the remote media file. Only used if [`Self::is_local_file`] is set to `false`.
    pub input: &'a str,
    /// Format of the remote media. Only used if [`Self::is_local_file`] is set to `false`.
    pub input_format: &'a str,
    /// Reconnect delay in seconds. Only used if [`Self::is_local_file`] is set to `false`.
    pub reconnect_delay_sec: u8,
    /// Restart playback when source becomes active.  Only used if [`Self::is_local_file`] is set
    /// to `true`.
    pub restart_on_activate: bool,
    /// Show nothing when playback ends.
    pub clear_on_media_end: bool,
    /// Close file when inactive.
    pub close_when_inactive: bool,
    /// Playback speed as percentage.  Only used if [`Self::is_local_file`] is set to `true`.
    pub speed_percent: u8,
    /// YUV color range.
    pub color_range: ColorRange,
    /// Whether the media source is seek-able. Only used if [`Self::is_local_file`] is set to
    /// `false`.
    pub seekable: bool,
}

/// YUV color range of a [`FfmpegSource`].
#[derive(Clone, Copy, Default, Serialize)]
#[serde(into = "u8")]
#[repr(u8)]
#[non_exhaustive]
pub enum ColorRange {
    /// Automatic detection.
    #[default]
    Auto = 0,
    /// Partial color range.
    Partial = 1,
    /// Full color range.
    Full = 2,
}

impl From<ColorRange> for u8 {
    fn from(value: ColorRange) -> Self {
        value as Self
    }
}

/// Settings specific to a **`FreeType2`** text source.
#[derive(Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct TextFt2SourceV2<'a> {
    /// Draw the text with smoothed corners.
    pub antialiasing: bool,
    /// Top color of the text.
    #[serde(with = "crate::serde::rgba8_inverse")]
    pub color1: RGBA8,
    /// Bottom color of the text.
    #[serde(with = "crate::serde::rgba8_inverse")]
    pub color2: RGBA8,
    /// Custom width (seems to have no effect).
    pub custom_width: u32,
    /// Draw a dark blurred shadow effect behind the text.
    pub drop_shadow: bool,
    /// Settings for the font.
    pub font: Font<'a>,
    /// Load the text from a file (must be set in combination with [`Self::text_file`]).
    pub from_file: bool,
    /// Amount of log lines if [`Self::log_mode`] is `true`. Minimum value is `1`.
    pub log_lines: u32,
    /// Log mode (not sure what this does).
    pub log_mode: bool,
    /// Draw a black border around the text corners.
    pub outline: bool,
    /// Text to display (only used if [`Self::from_file`] is `false`).
    pub text: &'a str,
    /// File to load the display text from ([`Self::from_file`] must be `true`). The
    /// content must be in either **UTF-8** or **UTF-16** encoding.
    pub text_file: &'a Path,
    /// Wrap the words within the boundaries of the scene item.
    pub word_wrap: bool,
}

impl Default for TextFt2SourceV2<'_> {
    fn default() -> Self {
        Self {
            antialiasing: true,
            color1: RGBA8::new(255, 255, 255, 255),
            color2: RGBA8::new(255, 255, 255, 255),
            custom_width: 0,
            drop_shadow: false,
            font: Font::default(),
            from_file: false,
            log_lines: 6,
            log_mode: false,
            outline: false,
            text: "",
            text_file: Path::new(""),
            word_wrap: false,
        }
    }
}

/// Font settings for a [`TextFt2SourceV2`].
#[derive(Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct Font<'a> {
    /// Font face.
    pub face: &'a str,
    /// Flags for different display styles.
    pub flags: FontFlags,
    /// Display size.
    pub size: u32,
    /// Specific font style. Must eventually be set together with [`Self::flags`].
    ///
    /// For example:
    /// - [`FontFlags::BOLD`] and style `"Bold"`.
    /// - [`FontFlags::ITALIC`] and style `"Italic"`.
    pub style: &'a str,
}

impl Default for Font<'_> {
    fn default() -> Self {
        Self {
            face: "Helvetica",
            flags: FontFlags::empty(),
            size: 256,
            style: "Regular",
        }
    }
}

/// Settings specific to a **VLC** video source.
#[derive(Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct VlcSource<'a> {
    /// Loop play-list.
    #[serde(rename = "bool")]
    pub loop_: bool,
    /// Shuffle play-list.
    pub shuffle: bool,
    /// Visibility behavior.
    pub playback_behavior: PlaybackBehavior,
    /// List of files to play.
    pub playlist: &'a [SlideshowFile<'a>],
    /// Network caching time. Minimum value is `100ms`.
    #[serde(with = "crate::serde::duration_millis")]
    pub network_caching: Duration,
    /// Audio track. Minimum value is `1`.
    pub track: u32,
    /// Subtitles enabled.
    pub subtitle_enable: bool,
    /// Subtitle track. Minimum value is `1`.
    pub subtitle: u32,
}

impl Default for VlcSource<'_> {
    fn default() -> Self {
        Self {
            loop_: true,
            shuffle: false,
            playback_behavior: PlaybackBehavior::StopRestart,
            playlist: &[],
            network_caching: Duration::milliseconds(400),
            track: 1,
            subtitle_enable: false,
            subtitle: 1,
        }
    }
}

/// Settings specific to an audio/video input capture source.
#[derive(Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct AvCaptureInputV2<'a> {
    /// Whether to use buffering.
    pub buffering: bool,
    /// Specific color space of the video. Only used if [`Self::use_preset`] is
    /// `false`).
    pub color_space: ColorSpace,
    /// Device identifier.
    pub device: &'a str,
    /// Name of the capture device.
    pub device_name: &'a str,
    /// Frame rate of the capture. Only used if [`Self::use_preset`] is `false`).
    pub frame_rate: FrameRate,
    /// Encoded input format. Only used if [`Self::use_preset`] is `false`).
    pub input_format: u32,
    /// Pre-configured setting. Only used if [`Self::use_preset`] is `true`).
    pub preset: AvPreset,
    /// Video resolution. Only used if [`Self::use_preset`] is `false`).
    #[serde(with = "crate::serde::json_string")]
    pub resolution: Resolution,
    /// Whether to use a setting preset.
    pub use_preset: bool,
    /// Video color range. Only used if [`Self::use_preset`] is `false`).
    pub video_range: VideoRange,
}

/// Color space as part of an [`AvCaptureInputV2`].
#[derive(Clone, Copy, Default, Serialize)]
#[serde(into = "i8")]
#[repr(i8)]
#[non_exhaustive]
pub enum ColorSpace {
    /// Automatic detection.
    #[default]
    Auto = -1,
    /// Rec. 601 color space.
    Rec601 = 1,
    /// Rec. 709 color space.
    Rec709 = 2,
}

impl From<ColorSpace> for i8 {
    fn from(value: ColorSpace) -> Self {
        value as Self
    }
}

/// Video color range as part of an [`AvCaptureInputV2`].
#[derive(Clone, Copy, Default, Serialize)]
#[serde(into = "i8")]
#[repr(i8)]
#[non_exhaustive]
pub enum VideoRange {
    /// Automatic detection.
    #[default]
    Auto = -1,
    /// Partial color range.
    Partial = 1,
    /// Full color range.
    Full = 2,
}

impl From<VideoRange> for i8 {
    fn from(value: VideoRange) -> Self {
        value as Self
    }
}

/// Different presets for the [`AvCaptureInputV2`].
#[derive(Serialize)]
#[non_exhaustive]
pub enum AvPreset {
    /// Preset for resolution _3840x2160_ (may not be available).
    #[serde(rename = "AVCaptureSessionPreset3840x2160")]
    Res3840x2160,
    /// Preset for resolution _1920x1080_ (may not be available).
    #[serde(rename = "AVCaptureSessionPreset1920x1080")]
    Res1920x1080,
    /// Preset for resolution _1280x720_.
    #[serde(rename = "AVCaptureSessionPreset1280x720")]
    Res1280x720,
    /// Preset for resolution _960x540_.
    #[serde(rename = "AVCaptureSessionPreset960x540")]
    Res960x540,
    /// Preset for resolution _640x480_.
    #[serde(rename = "AVCaptureSessionPreset640x480")]
    Res640x480,
    /// Preset for resolution _352x288_.
    #[serde(rename = "AVCaptureSessionPreset352x288")]
    Res352x288,
    /// Preset for resolution _320x240_.
    #[serde(rename = "AVCaptureSessionPreset320x240")]
    Res320x240,
    /// Preset for high quality.
    #[serde(rename = "AVCaptureSessionPresetHigh")]
    High,
    /// Preset for medium quality (may not be available).
    #[serde(rename = "AVCaptureSessionPresetMedium")]
    Medium,
    /// Preset for low quality (may not be available).
    #[serde(rename = "AVCaptureSessionPresetLow")]
    Low,
}

/// Video frame rate of an [`AvCaptureInputV2`].
///
/// The value is split into numerator and denominator as integer values instead of a floating point
/// value. To calculate the frame rate as FPS divide the `numerator` by the `denominator`.
#[derive(Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct FrameRate {
    /// The numerator to form the frame rate.
    pub numerator: u64,
    /// Denominator to form the frame rate.
    pub denominator: u64,
}

/// Video resolution for an [`AvCaptureInputV2`].
#[derive(Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct Resolution {
    /// Video width.
    pub width: u32,
    /// Video height.
    pub height: u32,
}

/// Settings specific to a window capture source.
#[derive(Default, Serialize)]
#[cfg_attr(feature = "builder", derive(bon::Builder))]
pub struct WindowCapture<'a> {
    /// Name of the owning process.
    pub owner_name: &'a str,
    /// Name of the window, usually seen in the title bar of the window frame.
    pub window_name: &'a str,
    /// Unique ID of the window.
    pub window: u16,
    /// Show windows with empty names.
    pub show_empty_names: bool,
    /// Show window shadow.
    pub show_shadow: bool,
}