Skip to main content

libobs_wrapper\encoders/
enums.rs

1use std::{convert::Infallible, str::FromStr};
2
3use crate::utils::ObsString;
4
5macro_rules! encoder_enum {
6    ($name:ident, { $($plugin:literal: [ $($(#[$attr:meta])* $variant:ident,)* ],)* }) => { paste::paste! {
7        #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
8        #[allow(non_camel_case_types)]
9        pub enum $name {
10            $(
11                $(
12                    #[doc = "From plugin: `" $plugin "`"]
13                    $(#[$attr])*
14                    [<$variant:upper>],
15                )*
16            )*
17            Other(String),
18        }
19
20        impl FromStr for $name {
21            type Err = Infallible;
22            fn from_str(s: &str) -> Result<Self, Self::Err> {
23                #[allow(deprecated)]
24                return Ok(match s {
25                    $( $( stringify!($variant) => Self::[<$variant:upper>], )* )*
26                    e => Self::Other(e.to_string()),
27                });
28            }
29        }
30        impl From<&str> for $name {
31            fn from(value: &str) -> Self {
32                match Self::from_str(value) {
33                    Ok(value) => value,
34                    Err(never) => match never {},
35                }
36            }
37        }
38        impl From<$name> for ObsString {
39            fn from(v: $name) -> ObsString {
40                #[allow(deprecated)]
41                return match v {
42                    $( $( $name::[<$variant:upper>] => ObsString::new(stringify!($variant)), )* )*
43                    $name::Other(e) => ObsString::new(&e),
44                };
45            }
46        }
47    } };
48}
49
50// These lists were produced using
51//   rg "struct obs_encoder_info [^\*].*=" -A 4
52// on the OBS codebase, which lists all of the encoders and their types, as well as their
53// capabilities (including whether they're deprecated or not).
54
55encoder_enum!(
56    ObsVideoEncoderType,
57    {
58        "obs-ffmpeg": [
59            h264_texture_amf,
60            h265_texture_amf,
61            av1_texture_amf,
62            ffmpeg_vaapi,
63            ffmpeg_vaapi_tex,
64            av1_ffmpeg_vaapi,
65            av1_ffmpeg_vaapi_tex,
66            hevc_ffmpeg_vaapi,
67            hevc_ffmpeg_vaapi_tex,
68            ffmpeg_openh264,
69            #[deprecated]
70            ffmpeg_nvenc,
71            #[deprecated]
72            ffmpeg_hevc_nvenc,
73            ffmpeg_svt_av1,
74            ffmpeg_aom_av1,
75        ],
76        "obs-nvenc": [
77            #[deprecated]
78            obs_nvenc_h264_cuda,
79            #[deprecated]
80            obs_nvenc_hevc_cuda,
81            #[deprecated]
82            obs_nvenc_av1_cuda,
83            obs_nvenc_h264_tex,
84            obs_nvenc_hevc_tex,
85            obs_nvenc_av1_tex,
86            #[deprecated]
87            jim_nvenc,
88            #[deprecated]
89            jim_hevc_nvenc,
90            #[deprecated]
91            jim_av1_nvenc,
92            obs_nvenc_h264_soft,
93            obs_nvenc_hevc_soft,
94            obs_nvenc_av1_soft,
95        ],
96        "obs-qsv11": [
97            obs_qsv11,
98            obs_qsv11_soft,
99            obs_qsv11_v2,
100            obs_qsv11_soft_v2,
101            obs_qsv11_av1,
102            obs_qsv11_av1_soft,
103            obs_qsv11_hevc,
104            obs_qsv11_hevc_soft,
105        ],
106        "obs-x264": [
107            obs_x264,
108        ],
109    }
110);
111
112encoder_enum!(
113    ObsAudioEncoderType,
114    {
115        "obs-ffmpeg": [
116            ffmpeg_aac,
117            ffmpeg_opus,
118            ffmpeg_pcm_s16le,
119            ffmpeg_pcm_s24le,
120            ffmpeg_pcm_f32le,
121            ffmpeg_alac,
122            ffmpeg_flac,
123        ],
124        "obs-libfdk": [
125            libfdk_aac,
126        ],
127    }
128);