libobs_wrapper/
enums.rs

1//! Contains all important enums for this crate
2use core::fmt;
3use std::fmt::Display;
4
5use num_derive::{FromPrimitive, ToPrimitive};
6
7#[cfg(target_os = "windows")]
8pub(crate) type OsEnumType = std::os::raw::c_int;
9#[cfg(not(target_os = "windows"))]
10pub(crate) type OsEnumType = std::os::raw::c_uint;
11
12#[cfg_attr(target_os = "windows", repr(i32))]
13#[cfg_attr(not(target_os = "windows"), repr(u32))]
14#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
15/// Describes the video output format used by the
16/// OBS video context. Used in `ObsVideoInfo`.
17pub enum ObsVideoFormat {
18    AYUV = libobs::video_format_VIDEO_FORMAT_AYUV,
19    BGR3 = libobs::video_format_VIDEO_FORMAT_BGR3,
20    BGRA = libobs::video_format_VIDEO_FORMAT_BGRA,
21    BGRX = libobs::video_format_VIDEO_FORMAT_BGRX,
22    I010 = libobs::video_format_VIDEO_FORMAT_I010,
23    I210 = libobs::video_format_VIDEO_FORMAT_I210,
24    I40A = libobs::video_format_VIDEO_FORMAT_I40A,
25    I412 = libobs::video_format_VIDEO_FORMAT_I412,
26    I420 = libobs::video_format_VIDEO_FORMAT_I420,
27    I422 = libobs::video_format_VIDEO_FORMAT_I422,
28    I42A = libobs::video_format_VIDEO_FORMAT_I42A,
29    I444 = libobs::video_format_VIDEO_FORMAT_I444,
30    NONE = libobs::video_format_VIDEO_FORMAT_NONE,
31    NV12 = libobs::video_format_VIDEO_FORMAT_NV12,
32    P010 = libobs::video_format_VIDEO_FORMAT_P010,
33    P216 = libobs::video_format_VIDEO_FORMAT_P216,
34    P416 = libobs::video_format_VIDEO_FORMAT_P416,
35    R10L = libobs::video_format_VIDEO_FORMAT_R10L,
36    RGBA = libobs::video_format_VIDEO_FORMAT_RGBA,
37    UYVY = libobs::video_format_VIDEO_FORMAT_UYVY,
38    V210 = libobs::video_format_VIDEO_FORMAT_V210,
39    Y800 = libobs::video_format_VIDEO_FORMAT_Y800,
40    YA2L = libobs::video_format_VIDEO_FORMAT_YA2L,
41    YUVA = libobs::video_format_VIDEO_FORMAT_YUVA,
42    YUY2 = libobs::video_format_VIDEO_FORMAT_YUY2,
43    YVYU = libobs::video_format_VIDEO_FORMAT_YVYU,
44}
45
46#[cfg_attr(target_os = "windows", repr(i32))]
47#[cfg_attr(not(target_os = "windows"), repr(u32))]
48#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
49/// Describes the colorspace that an OBS video context
50/// uses. Used in `ObsVideoInfo`.
51pub enum ObsColorspace {
52    CS2100HLG = libobs::video_colorspace_VIDEO_CS_2100_HLG,
53    CS2100PQ = libobs::video_colorspace_VIDEO_CS_2100_PQ,
54    CS601 = libobs::video_colorspace_VIDEO_CS_601,
55    CS709 = libobs::video_colorspace_VIDEO_CS_709,
56    Default = libobs::video_colorspace_VIDEO_CS_DEFAULT,
57    CSRGB = libobs::video_colorspace_VIDEO_CS_SRGB,
58}
59
60#[cfg_attr(target_os = "windows", repr(i32))]
61#[cfg_attr(not(target_os = "windows"), repr(u32))]
62#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
63/// Describes the minimum and maximum color levels that
64/// an OBS video context is allowed to encode. Used in
65/// `ObsVideoInfo.`
66pub enum ObsVideoRange {
67    Default = libobs::video_range_type_VIDEO_RANGE_DEFAULT,
68    Partial = libobs::video_range_type_VIDEO_RANGE_PARTIAL,
69    Full = libobs::video_range_type_VIDEO_RANGE_FULL,
70}
71
72#[cfg_attr(target_os = "windows", repr(i32))]
73#[cfg_attr(not(target_os = "windows"), repr(u32))]
74#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
75/// Describes how libobs should reconcile non-matching
76/// base and output resolutions when creating a video
77/// context.
78pub enum ObsScaleType {
79    Area = libobs::obs_scale_type_OBS_SCALE_AREA,
80    Bicubic = libobs::obs_scale_type_OBS_SCALE_BICUBIC,
81    Bilinear = libobs::obs_scale_type_OBS_SCALE_BILINEAR,
82    Disable = libobs::obs_scale_type_OBS_SCALE_DISABLE,
83    Lanczos = libobs::obs_scale_type_OBS_SCALE_LANCZOS,
84    Point = libobs::obs_scale_type_OBS_SCALE_POINT,
85}
86
87#[derive(Clone, Copy, Debug, PartialEq, Eq)]
88/// Describes which graphics backend should be used
89/// in the OBS video context. Used in `ObsVideoInfo`.
90pub enum ObsGraphicsModule {
91    OpenGL,
92    DirectX11,
93}
94
95#[repr(i32)]
96#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
97/// Status types returned after attempting to
98/// reset the OBS video context using the
99/// function `obs_reset_video`.
100pub enum ObsResetVideoStatus {
101    /// `obs_reset_video` was successful.
102    Success = libobs::OBS_VIDEO_SUCCESS as i32,
103    /// The adapter is not supported as it
104    /// lacks capabilities.
105    NotSupported = libobs::OBS_VIDEO_NOT_SUPPORTED,
106    /// A parameter is invalid.
107    InvalidParameter = libobs::OBS_VIDEO_INVALID_PARAM,
108    /// An output is currently running, preventing
109    /// resetting the video context.
110    CurrentlyActive = libobs::OBS_VIDEO_CURRENTLY_ACTIVE,
111    /// Generic error occured when attempting to
112    /// reset the OBS video context.
113    Failure = libobs::OBS_VIDEO_FAIL,
114}
115
116/// Audio samples per second options that are
117/// supported by libobs.
118#[cfg_attr(target_os = "windows", repr(i32))]
119#[cfg_attr(not(target_os = "windows"), repr(u32))]
120#[derive(Clone, Copy, Debug, PartialEq, Eq)]
121pub enum ObsSamplesPerSecond {
122    /// 44.1 kHz
123    F44100 = 44100,
124    /// 48.0 kHz
125    F48000 = 48000,
126}
127
128#[cfg_attr(target_os = "windows", repr(i32))]
129#[cfg_attr(not(target_os = "windows"), repr(u32))]
130#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
131pub enum ObsSpeakerLayout {
132    S2Point1 = libobs::speaker_layout_SPEAKERS_2POINT1,
133    S4Point0 = libobs::speaker_layout_SPEAKERS_4POINT0,
134    S4Point1 = libobs::speaker_layout_SPEAKERS_4POINT1,
135    S5Point1 = libobs::speaker_layout_SPEAKERS_5POINT1,
136    S7Point1 = libobs::speaker_layout_SPEAKERS_7POINT1,
137    Mono = libobs::speaker_layout_SPEAKERS_MONO,
138    Stereo = libobs::speaker_layout_SPEAKERS_STEREO,
139    Unknown = libobs::speaker_layout_SPEAKERS_UNKNOWN,
140}
141
142#[derive(Clone, Copy, Debug, PartialEq, Eq)]
143pub enum ObsOutputStopSignal {
144    /// Successfully stopped
145    Success,
146    /// The specified path was invalid
147    BadPath,
148    /// Failed to connect to a server
149    ConnectFailed,
150    /// Invalid stream path
151    InvalidStream,
152    /// Generic error
153    Error,
154    /// Unexpectedly disconnected
155    Disconnected,
156    /// The settings, video/audio format, or codecs are unsupported by this output
157    Unsupported,
158    /// Ran out of disk space
159    NoSpace,
160    /// Encoder error
161    EncodeError,
162}
163
164impl fmt::Display for ObsOutputStopSignal {
165    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
166        let s = match self {
167            ObsOutputStopSignal::Success => "Success",
168            ObsOutputStopSignal::BadPath => "Bad Path",
169            ObsOutputStopSignal::ConnectFailed => "Connect Failed",
170            ObsOutputStopSignal::InvalidStream => "Invalid Stream",
171            ObsOutputStopSignal::Error => "Error",
172            ObsOutputStopSignal::Disconnected => "Disconnected",
173            ObsOutputStopSignal::Unsupported => "Unsupported",
174            ObsOutputStopSignal::NoSpace => "No Space",
175            ObsOutputStopSignal::EncodeError => "Encode Error",
176        };
177        write!(f, "{}", s)
178    }
179}
180
181impl From<ObsOutputStopSignal> for i32 {
182    fn from(val: ObsOutputStopSignal) -> Self {
183        match val {
184            ObsOutputStopSignal::Success => libobs::OBS_OUTPUT_SUCCESS as i32,
185            ObsOutputStopSignal::BadPath => libobs::OBS_OUTPUT_BAD_PATH,
186            ObsOutputStopSignal::ConnectFailed => libobs::OBS_OUTPUT_CONNECT_FAILED,
187            ObsOutputStopSignal::InvalidStream => libobs::OBS_OUTPUT_INVALID_STREAM,
188            ObsOutputStopSignal::Error => libobs::OBS_OUTPUT_ERROR,
189            ObsOutputStopSignal::Disconnected => libobs::OBS_OUTPUT_DISCONNECTED,
190            ObsOutputStopSignal::Unsupported => libobs::OBS_OUTPUT_UNSUPPORTED,
191            ObsOutputStopSignal::NoSpace => libobs::OBS_OUTPUT_NO_SPACE,
192            ObsOutputStopSignal::EncodeError => libobs::OBS_OUTPUT_ENCODE_ERROR,
193        }
194    }
195}
196
197impl TryFrom<i32> for ObsOutputStopSignal {
198    type Error = &'static str;
199
200    fn try_from(value: i32) -> Result<Self, <ObsOutputStopSignal as TryFrom<i32>>::Error> {
201        match value {
202            x if x == libobs::OBS_OUTPUT_SUCCESS as i32 => Ok(ObsOutputStopSignal::Success),
203            x if x == libobs::OBS_OUTPUT_BAD_PATH => Ok(ObsOutputStopSignal::BadPath),
204            x if x == libobs::OBS_OUTPUT_CONNECT_FAILED => Ok(ObsOutputStopSignal::ConnectFailed),
205            x if x == libobs::OBS_OUTPUT_INVALID_STREAM => Ok(ObsOutputStopSignal::InvalidStream),
206            x if x == libobs::OBS_OUTPUT_ERROR => Ok(ObsOutputStopSignal::Error),
207            x if x == libobs::OBS_OUTPUT_DISCONNECTED => Ok(ObsOutputStopSignal::Disconnected),
208            x if x == libobs::OBS_OUTPUT_UNSUPPORTED => Ok(ObsOutputStopSignal::Unsupported),
209            x if x == libobs::OBS_OUTPUT_NO_SPACE => Ok(ObsOutputStopSignal::NoSpace),
210            x if x == libobs::OBS_OUTPUT_ENCODE_ERROR => Ok(ObsOutputStopSignal::EncodeError),
211            _ => Err("Invalid value"),
212        }
213    }
214}
215
216#[cfg_attr(target_os = "windows", repr(i32))]
217#[cfg_attr(not(target_os = "windows"), repr(u32))]
218#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
219pub enum ObsEncoderType {
220    Video = libobs::obs_encoder_type_OBS_ENCODER_VIDEO,
221    Audio = libobs::obs_encoder_type_OBS_ENCODER_AUDIO,
222}
223
224#[cfg_attr(target_os = "windows", repr(i32))]
225#[cfg_attr(not(target_os = "windows"), repr(u32))]
226#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
227pub enum ObsLogLevel {
228    Error = libobs::LOG_ERROR,
229    Warning = libobs::LOG_WARNING,
230    Info = libobs::LOG_INFO,
231    Debug = libobs::LOG_DEBUG,
232}
233
234impl Display for ObsLogLevel {
235    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
236        write!(f, "{:?}", self)
237    }
238}
239
240#[cfg(feature = "color-logger")]
241impl ObsLogLevel {
242    pub fn colorize(&self, s: &str) -> String {
243        use colored::Colorize;
244
245        match self {
246            ObsLogLevel::Error => s.on_red().to_string(),
247            ObsLogLevel::Warning => s.yellow().to_string(),
248            ObsLogLevel::Info => s.green().bold().to_string(),
249            ObsLogLevel::Debug => s.blue().to_string(),
250        }
251    }
252}
253
254#[cfg_attr(target_os = "windows", repr(i32))]
255#[cfg_attr(not(target_os = "windows"), repr(u32))]
256#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
257/// Used with scene items to indicate the type of bounds to use for scene items.
258/// Mostly determines how the image will be scaled within those bounds, or
259/// whether to use bounds at all.
260pub enum ObsBounds {
261    /// No bounds
262    None = libobs::obs_bounds_type_OBS_BOUNDS_NONE,
263    /// stretch (ignores base scale)
264    Stretch = libobs::obs_bounds_type_OBS_BOUNDS_STRETCH,
265    /// scales to inner rectangle
266    ScaleInner = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_INNER,
267    /// scales to outer rectangle
268    ScaleOuter = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_OUTER,
269    /// scales to the width
270    ScaleToWidth = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_TO_WIDTH,
271    /// scales to the height
272    ScaleToHeight = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_TO_HEIGHT,
273    /// no scaling, maximum size only
274    MaxOnly = libobs::obs_bounds_type_OBS_BOUNDS_MAX_ONLY,
275}
276
277#[cfg_attr(target_os = "windows", repr(i32))]
278#[cfg_attr(not(target_os = "windows"), repr(u32))]
279#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
280pub enum ObsBoundsType {
281    None = libobs::obs_bounds_type_OBS_BOUNDS_NONE,
282    Stretch = libobs::obs_bounds_type_OBS_BOUNDS_STRETCH,
283    ScaleInner = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_INNER,
284    ScaleOuter = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_OUTER,
285    ScaleToWidth = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_TO_WIDTH,
286    ScaleToHeight = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_TO_HEIGHT,
287    MaxOnly = libobs::obs_bounds_type_OBS_BOUNDS_MAX_ONLY,
288}
289
290pub mod obs_alignment {
291    pub const LEFT: u32 = libobs::OBS_ALIGN_LEFT;
292    pub const TOP: u32 = libobs::OBS_ALIGN_TOP;
293    pub const RIGHT: u32 = libobs::OBS_ALIGN_RIGHT;
294    pub const BOTTOM: u32 = libobs::OBS_ALIGN_BOTTOM;
295    pub const CENTER: u32 = libobs::OBS_ALIGN_CENTER;
296}