webrtc_constraints/
enumerations.rs

1/// The directions that the camera can face, as seen from the user's perspective.
2///
3/// # Note
4/// The enumeration is not exhaustive and merely provides a list of known values.
5#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
6pub enum FacingMode {
7    /// The source is facing toward the user (a self-view camera).
8    User,
9
10    /// The source is facing away from the user (viewing the environment).
11    Environment,
12
13    /// The source is facing to the left of the user.
14    Left,
15
16    /// The source is facing to the right of the user.
17    Right,
18}
19
20impl FacingMode {
21    /// Returns `"user"`, the string-value of the `User` facing mode.
22    pub fn user() -> String {
23        Self::User.to_string()
24    }
25
26    /// Returns `"environment"`, the string-value of the `Environment` facing mode.
27    pub fn environment() -> String {
28        Self::Environment.to_string()
29    }
30
31    /// Returns `"left"`, the string-value of the `Left` facing mode.
32    pub fn left() -> String {
33        Self::Left.to_string()
34    }
35
36    /// Returns `"right"`, the string-value of the `Right` facing mode.
37    pub fn right() -> String {
38        Self::Right.to_string()
39    }
40}
41
42impl std::fmt::Display for FacingMode {
43    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44        match self {
45            Self::User => f.write_str("user"),
46            Self::Environment => f.write_str("environment"),
47            Self::Left => f.write_str("left"),
48            Self::Right => f.write_str("right"),
49        }
50    }
51}
52
53/// The means by which the resolution can be derived by the client.
54///
55/// # Note
56/// The enumeration is not exhaustive and merely provides a list of known values.
57#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
58pub enum ResizeMode {
59    /// This resolution and frame rate is offered by the camera, its driver, or the OS.
60    ///
61    /// # Note
62    /// The user agent MAY report this value to disguise concurrent use,
63    /// but only when the camera is in use in another browsing context.
64    ///
65    /// # Important
66    /// This value is a possible finger-printing surface.
67    None,
68
69    /// This resolution is downscaled and/or cropped from a higher camera resolution by the user agent,
70    /// or its frame rate is decimated by the User Agent.
71    ///
72    /// # Important
73    /// The media MUST NOT be upscaled, stretched or have fake data created that did not occur in the input source.
74    CropAndScale,
75}
76
77impl ResizeMode {
78    /// Returns `"none"`, the string-value of the `None` resize mode.
79    pub fn none() -> String {
80        Self::None.to_string()
81    }
82
83    /// Returns `"crop-and-scale"`, the string-value of the `CropAndScale` resize mode.
84    pub fn crop_and_scale() -> String {
85        Self::CropAndScale.to_string()
86    }
87}
88
89impl std::fmt::Display for ResizeMode {
90    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
91        match self {
92            Self::None => f.write_str("none"),
93            Self::CropAndScale => f.write_str("crop-and-scale"),
94        }
95    }
96}
97
98#[cfg(test)]
99mod tests {
100    use super::*;
101
102    mod facing_mode {
103        use super::*;
104
105        #[test]
106        fn to_string() {
107            assert_eq!(FacingMode::User.to_string(), "user");
108            assert_eq!(FacingMode::Environment.to_string(), "environment");
109            assert_eq!(FacingMode::Left.to_string(), "left");
110            assert_eq!(FacingMode::Right.to_string(), "right");
111
112            assert_eq!(FacingMode::user(), "user");
113            assert_eq!(FacingMode::environment(), "environment");
114            assert_eq!(FacingMode::left(), "left");
115            assert_eq!(FacingMode::right(), "right");
116        }
117    }
118
119    mod resize_mode {
120        use super::*;
121
122        #[test]
123        fn to_string() {
124            assert_eq!(ResizeMode::None.to_string(), "none");
125            assert_eq!(ResizeMode::CropAndScale.to_string(), "crop-and-scale");
126
127            assert_eq!(ResizeMode::none(), "none");
128            assert_eq!(ResizeMode::crop_and_scale(), "crop-and-scale");
129        }
130    }
131}