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#[cfg_attr(target_os = "windows", repr(i32))]
89#[cfg_attr(not(target_os = "windows"), repr(u32))]
90#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
91/// Selects whether scene-item blending uses OBS's default sRGB conversion behavior.
92pub enum ObsBlendMethod {
93    Default = libobs::obs_blending_method_OBS_BLEND_METHOD_DEFAULT,
94    SrgbOff = libobs::obs_blending_method_OBS_BLEND_METHOD_SRGB_OFF,
95}
96
97#[cfg_attr(target_os = "windows", repr(i32))]
98#[cfg_attr(not(target_os = "windows"), repr(u32))]
99#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
100/// Selects the scene-item blend equation used by libobs.
101pub enum ObsBlendMode {
102    Normal = libobs::obs_blending_type_OBS_BLEND_NORMAL,
103    Additive = libobs::obs_blending_type_OBS_BLEND_ADDITIVE,
104    Subtract = libobs::obs_blending_type_OBS_BLEND_SUBTRACT,
105    Screen = libobs::obs_blending_type_OBS_BLEND_SCREEN,
106    Multiply = libobs::obs_blending_type_OBS_BLEND_MULTIPLY,
107    Lighten = libobs::obs_blending_type_OBS_BLEND_LIGHTEN,
108    Darken = libobs::obs_blending_type_OBS_BLEND_DARKEN,
109}
110
111#[derive(Clone, Copy, Debug, PartialEq, Eq)]
112/// Describes which graphics backend should be used
113/// in the OBS video context. Used in `ObsVideoInfo`.
114pub enum ObsGraphicsModule {
115    OpenGL,
116    DirectX11,
117    /// Native Metal renderer used by OBS on macOS.
118    Metal,
119}
120
121#[repr(i32)]
122#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
123/// Status types returned after attempting to
124/// reset the OBS video context using the
125/// function `obs_reset_video`.
126pub enum ObsResetVideoStatus {
127    /// `obs_reset_video` was successful.
128    Success = libobs::OBS_VIDEO_SUCCESS as i32,
129    /// The adapter is not supported as it
130    /// lacks capabilities.
131    NotSupported = libobs::OBS_VIDEO_NOT_SUPPORTED,
132    /// A parameter is invalid.
133    InvalidParameter = libobs::OBS_VIDEO_INVALID_PARAM,
134    /// An output is currently running, preventing
135    /// resetting the video context.
136    CurrentlyActive = libobs::OBS_VIDEO_CURRENTLY_ACTIVE,
137    /// Generic error occured when attempting to
138    /// reset the OBS video context.
139    Failure = libobs::OBS_VIDEO_FAIL,
140}
141
142/// Audio samples per second options that are
143/// supported by libobs.
144#[cfg_attr(target_os = "windows", repr(i32))]
145#[cfg_attr(not(target_os = "windows"), repr(u32))]
146#[derive(Clone, Copy, Debug, PartialEq, Eq)]
147pub enum ObsSamplesPerSecond {
148    /// 44.1 kHz
149    F44100 = 44100,
150    /// 48.0 kHz
151    F48000 = 48000,
152}
153
154#[cfg_attr(target_os = "windows", repr(i32))]
155#[cfg_attr(not(target_os = "windows"), repr(u32))]
156#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
157pub enum ObsSpeakerLayout {
158    S2Point1 = libobs::speaker_layout_SPEAKERS_2POINT1,
159    S4Point0 = libobs::speaker_layout_SPEAKERS_4POINT0,
160    S4Point1 = libobs::speaker_layout_SPEAKERS_4POINT1,
161    S5Point1 = libobs::speaker_layout_SPEAKERS_5POINT1,
162    S7Point1 = libobs::speaker_layout_SPEAKERS_7POINT1,
163    Mono = libobs::speaker_layout_SPEAKERS_MONO,
164    Stereo = libobs::speaker_layout_SPEAKERS_STEREO,
165    Unknown = libobs::speaker_layout_SPEAKERS_UNKNOWN,
166}
167
168#[derive(Clone, Copy, Debug, PartialEq, Eq)]
169pub enum ObsOutputStopSignal {
170    /// Successfully stopped
171    Success,
172    /// The specified path was invalid
173    BadPath,
174    /// Failed to connect to a server
175    ConnectFailed,
176    /// Invalid stream path
177    InvalidStream,
178    /// Generic error
179    Error,
180    /// Unexpectedly disconnected
181    Disconnected,
182    /// The settings, video/audio format, or codecs are unsupported by this output
183    Unsupported,
184    /// Ran out of disk space
185    NoSpace,
186    /// Encoder error
187    EncodeError,
188}
189
190impl fmt::Display for ObsOutputStopSignal {
191    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
192        let s = match self {
193            ObsOutputStopSignal::Success => "Success",
194            ObsOutputStopSignal::BadPath => "Bad Path",
195            ObsOutputStopSignal::ConnectFailed => "Connect Failed",
196            ObsOutputStopSignal::InvalidStream => "Invalid Stream",
197            ObsOutputStopSignal::Error => "Error",
198            ObsOutputStopSignal::Disconnected => "Disconnected",
199            ObsOutputStopSignal::Unsupported => "Unsupported",
200            ObsOutputStopSignal::NoSpace => "No Space",
201            ObsOutputStopSignal::EncodeError => "Encode Error",
202        };
203        write!(f, "{}", s)
204    }
205}
206
207impl From<ObsOutputStopSignal> for i32 {
208    fn from(val: ObsOutputStopSignal) -> Self {
209        match val {
210            ObsOutputStopSignal::Success => libobs::OBS_OUTPUT_SUCCESS as i32,
211            ObsOutputStopSignal::BadPath => libobs::OBS_OUTPUT_BAD_PATH,
212            ObsOutputStopSignal::ConnectFailed => libobs::OBS_OUTPUT_CONNECT_FAILED,
213            ObsOutputStopSignal::InvalidStream => libobs::OBS_OUTPUT_INVALID_STREAM,
214            ObsOutputStopSignal::Error => libobs::OBS_OUTPUT_ERROR,
215            ObsOutputStopSignal::Disconnected => libobs::OBS_OUTPUT_DISCONNECTED,
216            ObsOutputStopSignal::Unsupported => libobs::OBS_OUTPUT_UNSUPPORTED,
217            ObsOutputStopSignal::NoSpace => libobs::OBS_OUTPUT_NO_SPACE,
218            ObsOutputStopSignal::EncodeError => libobs::OBS_OUTPUT_ENCODE_ERROR,
219        }
220    }
221}
222
223impl TryFrom<i32> for ObsOutputStopSignal {
224    type Error = &'static str;
225
226    fn try_from(value: i32) -> Result<Self, <ObsOutputStopSignal as TryFrom<i32>>::Error> {
227        match value {
228            x if x == libobs::OBS_OUTPUT_SUCCESS as i32 => Ok(ObsOutputStopSignal::Success),
229            x if x == libobs::OBS_OUTPUT_BAD_PATH => Ok(ObsOutputStopSignal::BadPath),
230            x if x == libobs::OBS_OUTPUT_CONNECT_FAILED => Ok(ObsOutputStopSignal::ConnectFailed),
231            x if x == libobs::OBS_OUTPUT_INVALID_STREAM => Ok(ObsOutputStopSignal::InvalidStream),
232            x if x == libobs::OBS_OUTPUT_ERROR => Ok(ObsOutputStopSignal::Error),
233            x if x == libobs::OBS_OUTPUT_DISCONNECTED => Ok(ObsOutputStopSignal::Disconnected),
234            x if x == libobs::OBS_OUTPUT_UNSUPPORTED => Ok(ObsOutputStopSignal::Unsupported),
235            x if x == libobs::OBS_OUTPUT_NO_SPACE => Ok(ObsOutputStopSignal::NoSpace),
236            x if x == libobs::OBS_OUTPUT_ENCODE_ERROR => Ok(ObsOutputStopSignal::EncodeError),
237            _ => Err("Invalid value"),
238        }
239    }
240}
241
242#[cfg_attr(target_os = "windows", repr(i32))]
243#[cfg_attr(not(target_os = "windows"), repr(u32))]
244#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
245pub enum ObsEncoderType {
246    Video = libobs::obs_encoder_type_OBS_ENCODER_VIDEO,
247    Audio = libobs::obs_encoder_type_OBS_ENCODER_AUDIO,
248}
249
250#[cfg_attr(target_os = "windows", repr(i32))]
251#[cfg_attr(not(target_os = "windows"), repr(u32))]
252#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
253pub enum ObsLogLevel {
254    Error = libobs::LOG_ERROR,
255    Warning = libobs::LOG_WARNING,
256    Info = libobs::LOG_INFO,
257    Debug = libobs::LOG_DEBUG,
258}
259
260impl Display for ObsLogLevel {
261    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
262        write!(f, "{:?}", self)
263    }
264}
265
266#[cfg(feature = "color-logger")]
267impl ObsLogLevel {
268    pub fn colorize(&self, s: &str) -> String {
269        use colored::Colorize;
270
271        match self {
272            ObsLogLevel::Error => s.on_red().to_string(),
273            ObsLogLevel::Warning => s.yellow().to_string(),
274            ObsLogLevel::Info => s.green().bold().to_string(),
275            ObsLogLevel::Debug => s.blue().to_string(),
276        }
277    }
278}
279
280#[cfg_attr(target_os = "windows", repr(i32))]
281#[cfg_attr(not(target_os = "windows"), repr(u32))]
282#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
283/// Used with scene items to indicate the type of bounds to use for scene items.
284/// Mostly determines how the image will be scaled within those bounds, or
285/// whether to use bounds at all.
286pub enum ObsBounds {
287    /// No bounds
288    None = libobs::obs_bounds_type_OBS_BOUNDS_NONE,
289    /// stretch (ignores base scale)
290    Stretch = libobs::obs_bounds_type_OBS_BOUNDS_STRETCH,
291    /// scales to inner rectangle
292    ScaleInner = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_INNER,
293    /// scales to outer rectangle
294    ScaleOuter = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_OUTER,
295    /// scales to the width
296    ScaleToWidth = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_TO_WIDTH,
297    /// scales to the height
298    ScaleToHeight = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_TO_HEIGHT,
299    /// no scaling, maximum size only
300    MaxOnly = libobs::obs_bounds_type_OBS_BOUNDS_MAX_ONLY,
301}
302
303#[cfg_attr(target_os = "windows", repr(i32))]
304#[cfg_attr(not(target_os = "windows"), repr(u32))]
305#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
306pub enum ObsBoundsType {
307    None = libobs::obs_bounds_type_OBS_BOUNDS_NONE,
308    Stretch = libobs::obs_bounds_type_OBS_BOUNDS_STRETCH,
309    ScaleInner = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_INNER,
310    ScaleOuter = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_OUTER,
311    ScaleToWidth = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_TO_WIDTH,
312    ScaleToHeight = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_TO_HEIGHT,
313    MaxOnly = libobs::obs_bounds_type_OBS_BOUNDS_MAX_ONLY,
314}
315
316#[cfg_attr(target_os = "windows", repr(i32))]
317#[cfg_attr(not(target_os = "windows"), repr(u32))]
318#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
319/// Relative movement operations for reordering an item within a scene.
320pub enum ObsOrderMovement {
321    Up = libobs::obs_order_movement_OBS_ORDER_MOVE_UP,
322    Down = libobs::obs_order_movement_OBS_ORDER_MOVE_DOWN,
323    Top = libobs::obs_order_movement_OBS_ORDER_MOVE_TOP,
324    Bottom = libobs::obs_order_movement_OBS_ORDER_MOVE_BOTTOM,
325}
326
327bitflags! {
328    /// Represents a set of flags.
329    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
330    pub struct ObsAlignment: u32 {
331        const LEFT = libobs::OBS_ALIGN_LEFT;
332        const TOP = libobs::OBS_ALIGN_TOP;
333        const RIGHT = libobs::OBS_ALIGN_RIGHT;
334        const BOTTOM = libobs::OBS_ALIGN_BOTTOM;
335        const CENTER = libobs::OBS_ALIGN_CENTER;
336    }
337}