Skip to main content

libobs_wrapper/
enums.rs

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