1use 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)]
16pub 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)]
50pub 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)]
64pub 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)]
76pub 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)]
91pub 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)]
100pub 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)]
112pub enum ObsGraphicsModule {
115 OpenGL,
116 DirectX11,
117 Metal,
119}
120
121#[repr(i32)]
122#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
123pub enum ObsResetVideoStatus {
127 Success = libobs::OBS_VIDEO_SUCCESS as i32,
129 NotSupported = libobs::OBS_VIDEO_NOT_SUPPORTED,
132 InvalidParameter = libobs::OBS_VIDEO_INVALID_PARAM,
134 CurrentlyActive = libobs::OBS_VIDEO_CURRENTLY_ACTIVE,
137 Failure = libobs::OBS_VIDEO_FAIL,
140}
141
142#[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 F44100 = 44100,
150 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 Success,
172 BadPath,
174 ConnectFailed,
176 InvalidStream,
178 Error,
180 Disconnected,
182 Unsupported,
184 NoSpace,
186 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)]
283pub enum ObsBounds {
287 None = libobs::obs_bounds_type_OBS_BOUNDS_NONE,
289 Stretch = libobs::obs_bounds_type_OBS_BOUNDS_STRETCH,
291 ScaleInner = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_INNER,
293 ScaleOuter = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_OUTER,
295 ScaleToWidth = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_TO_WIDTH,
297 ScaleToHeight = libobs::obs_bounds_type_OBS_BOUNDS_SCALE_TO_HEIGHT,
299 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)]
319pub 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 #[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}