xref: /webrtc/constraints/src/enumerations.rs (revision 86143b07)
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)]
6 pub 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 
20 impl FacingMode {
21     /// Returns `"user"`, the string-value of the `User` facing mode.
user() -> String22     pub fn user() -> String {
23         Self::User.to_string()
24     }
25 
26     /// Returns `"environment"`, the string-value of the `Environment` facing mode.
environment() -> String27     pub fn environment() -> String {
28         Self::Environment.to_string()
29     }
30 
31     /// Returns `"left"`, the string-value of the `Left` facing mode.
left() -> String32     pub fn left() -> String {
33         Self::Left.to_string()
34     }
35 
36     /// Returns `"right"`, the string-value of the `Right` facing mode.
right() -> String37     pub fn right() -> String {
38         Self::Right.to_string()
39     }
40 }
41 
42 impl std::fmt::Display for FacingMode {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result43     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)]
58 pub 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 
77 impl ResizeMode {
78     /// Returns `"none"`, the string-value of the `None` resize mode.
none() -> String79     pub fn none() -> String {
80         Self::None.to_string()
81     }
82 
83     /// Returns `"crop-and-scale"`, the string-value of the `CropAndScale` resize mode.
crop_and_scale() -> String84     pub fn crop_and_scale() -> String {
85         Self::CropAndScale.to_string()
86     }
87 }
88 
89 impl std::fmt::Display for ResizeMode {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result90     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)]
99 mod tests {
100     use super::*;
101 
102     mod facing_mode {
103         use super::*;
104 
105         #[test]
to_string()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]
to_string()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 }
132