libobs_wrapper/
enums.rs

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