pub struct ObsContext { /* private fields */ }Expand description
Interface to the process-global OBS context.
Context-level native objects are owned by an internal registry. Each native handle retains the runtime independently, so correctness does not depend on Rust struct field declaration order.
Implementations§
Source§impl ObsContext
impl ObsContext
pub fn source_types(&self) -> Result<Vec<SourceTypeInfo>, ObsError>
pub fn input_types(&self) -> Result<Vec<SourceTypeInfo>, ObsError>
pub fn filter_types(&self) -> Result<Vec<SourceTypeInfo>, ObsError>
pub fn transition_types(&self) -> Result<Vec<SourceTypeInfo>, ObsError>
pub fn output_types(&self) -> Result<Vec<OutputTypeInfo>, ObsError>
pub fn encoder_types(&self) -> Result<Vec<EncoderTypeInfo>, ObsError>
pub fn service_types(&self) -> Result<Vec<ServiceTypeInfo>, ObsError>
pub fn protocols(&self) -> Result<Vec<String>, ObsError>
pub fn loaded_modules(&self) -> Result<Vec<ModuleInfo>, ObsError>
pub fn source_type(&self, id: &str) -> Result<Option<SourceTypeInfo>, ObsError>
pub fn output_type(&self, id: &str) -> Result<Option<OutputTypeInfo>, ObsError>
pub fn encoder_type( &self, id: &str, ) -> Result<Option<EncoderTypeInfo>, ObsError>
pub fn service_type( &self, id: &str, ) -> Result<Option<ServiceTypeInfo>, ObsError>
Sourcepub fn create_source(
&self,
source_type: &SourceTypeInfo,
name: impl Into<ObsString>,
settings: Option<ObsData>,
) -> Result<ObsSourceRef, ObsError>
pub fn create_source( &self, source_type: &SourceTypeInfo, name: impl Into<ObsString>, settings: Option<ObsData>, ) -> Result<ObsSourceRef, ObsError>
Creates a typed source from a discovered source descriptor. Filters use
ObsContext::create_filter so callers cannot accidentally lose filter semantics.
Sourcepub fn create_filter(
&mut self,
filter_type: &SourceTypeInfo,
name: impl Into<ObsString>,
settings: Option<ObsData>,
) -> Result<ObsFilterRef, ObsError>
pub fn create_filter( &mut self, filter_type: &SourceTypeInfo, name: impl Into<ObsString>, settings: Option<ObsData>, ) -> Result<ObsFilterRef, ObsError>
Creates and registers a typed filter from a discovered filter descriptor.
Sourcepub fn create_output(
&mut self,
output_type: &OutputTypeInfo,
name: impl Into<ObsString>,
settings: Option<ObsData>,
) -> Result<ObsOutputRef, ObsError>
pub fn create_output( &mut self, output_type: &OutputTypeInfo, name: impl Into<ObsString>, settings: Option<ObsData>, ) -> Result<ObsOutputRef, ObsError>
Creates and registers an output from a discovered output descriptor.
Sourcepub fn create_video_encoder(
&self,
encoder_type: &EncoderTypeInfo,
name: impl Into<ObsString>,
settings: Option<ObsData>,
) -> Result<Arc<ObsVideoEncoder>, ObsError>
pub fn create_video_encoder( &self, encoder_type: &EncoderTypeInfo, name: impl Into<ObsString>, settings: Option<ObsData>, ) -> Result<Arc<ObsVideoEncoder>, ObsError>
Creates a video encoder from a discovered encoder descriptor.
Sourcepub fn create_audio_encoder(
&self,
encoder_type: &EncoderTypeInfo,
name: impl Into<ObsString>,
settings: Option<ObsData>,
mixer_index: usize,
) -> Result<Arc<ObsAudioEncoder>, ObsError>
pub fn create_audio_encoder( &self, encoder_type: &EncoderTypeInfo, name: impl Into<ObsString>, settings: Option<ObsData>, mixer_index: usize, ) -> Result<Arc<ObsAudioEncoder>, ObsError>
Creates an audio encoder from a discovered encoder descriptor.
Sourcepub fn create_service(
&self,
service_type: &ServiceTypeInfo,
name: impl Into<ObsString>,
settings: Option<ObsData>,
) -> Result<Arc<ObsServiceRef>, ObsError>
pub fn create_service( &self, service_type: &ServiceTypeInfo, name: impl Into<ObsString>, settings: Option<ObsData>, ) -> Result<Arc<ObsServiceRef>, ObsError>
Creates a managed streaming service from a discovered service descriptor.
pub fn capabilities(&self) -> Result<ObsCapabilities, ObsError>
Source§impl ObsContext
impl ObsContext
pub fn startup_info(&self) -> &Arc<RwLock<StartupInfo>> ⓘ
pub fn runtime(&self) -> &ObsRuntime
Source§impl ObsContext
impl ObsContext
Sourcepub fn check_version_compatibility() -> bool
pub fn check_version_compatibility() -> bool
Checks if the installed OBS version matches the expected version. Returns true if the major version matches, false otherwise.
pub fn builder() -> StartupInfo
Sourcepub fn new(info: StartupInfo) -> Result<ObsContext, ObsError>
pub fn new(info: StartupInfo) -> Result<ObsContext, ObsError>
Initializes libobs on the current thread.
Note that there can be only one ObsContext initialized at a time. This is because libobs is not completely thread-safe.
Also note that this might leak a very tiny amount of memory. As a result, it is probably a good idea not to restart the OBS context repeatedly over a very long period of time. Unfortunately the memory leak is caused by a bug in libobs itself.
On Linux, make sure to call ObsContext::check_version_compatibility before
initializing the context. If that method returns false, it may be possible for the binary to crash.
If initialization fails, an ObsError is returned.
pub fn get_version(&self) -> Result<String, ObsError>
pub fn get_version_global() -> Result<String, ObsError>
pub fn log(&self, level: ObsLogLevel, msg: &str)
Sourcepub fn reset_video(&mut self, ovi: ObsVideoInfo) -> Result<(), ObsError>
pub fn reset_video(&mut self, ovi: ObsVideoInfo) -> Result<(), ObsError>
Resets the OBS video context. This is often called when one wants to change a setting related to the OBS video info sent on startup.
It is important to register your video encoders to a video handle after you reset the video context if you are using a video handle other than the main video handle. For convenience, this function sets all video encoder back to the main video handler by default.
Note that you cannot reset the graphics module without destroying the entire OBS context. Trying so will result in an error.
Sourcepub unsafe fn get_video_ptr(&self) -> Result<*mut video_output, ObsError>
pub unsafe fn get_video_ptr(&self) -> Result<*mut video_output, ObsError>
Returns a pointer to the video output.
§Safety
This function is unsafe because it returns a raw pointer that must be handled carefully. Only use this pointer if you REALLY know what you are doing.
Sourcepub unsafe fn get_audio_ptr(&self) -> Result<*mut audio_output, ObsError>
pub unsafe fn get_audio_ptr(&self) -> Result<*mut audio_output, ObsError>
Returns a pointer to the audio output.
§Safety
This function is unsafe because it returns a raw pointer that must be handled carefully. Only use this pointer if you REALLY know what you are doing.
pub fn data(&self) -> Result<ObsData, ObsError>
pub fn replay_buffer( &mut self, info: OutputInfo, ) -> Result<ObsReplayBufferOutputRef, ObsError>
pub fn output(&mut self, info: OutputInfo) -> Result<ObsOutputRef, ObsError>
pub fn obs_filter(&mut self, info: FilterInfo) -> Result<ObsFilterRef, ObsError>
Sourcepub fn display(
&mut self,
data: ObsDisplayCreationData,
) -> Result<ObsDisplayRef, ObsError>
pub fn display( &mut self, data: ObsDisplayCreationData, ) -> Result<ObsDisplayRef, ObsError>
Creates a new display and returns its ID.
You must call update_color_space on the display when the window is moved, resized or the display settings change.
Note: When calling set_size or set_pos, update_color_space is called automatically.
Another note: On Linux, this method is unsafe because you must ensure that every display reference is dropped before your window exits.
pub fn remove_display( &mut self, display: &ObsDisplayRef, ) -> Result<(), ObsError>
pub fn remove_display_by_id(&mut self, id: usize) -> Result<(), ObsError>
pub fn get_display_by_id( &self, id: usize, ) -> Result<Option<ObsDisplayRef>, ObsError>
pub fn get_output( &self, name: &str, ) -> Result<Option<Arc<dyn ObsOutputTrait>>, ObsError>
pub fn update_output( &self, name: &str, settings: ObsData, ) -> Result<(), ObsError>
pub fn get_filter(&self, name: &str) -> Result<Option<ObsFilterRef>, ObsError>
Sourcepub fn scene<T: Into<ObsString> + Send + Sync>(
&mut self,
name: T,
channel: Option<u32>,
) -> Result<ObsSceneRef, ObsError>
pub fn scene<T: Into<ObsString> + Send + Sync>( &mut self, name: T, channel: Option<u32>, ) -> Result<ObsSceneRef, ObsError>
Creates a new scene
If the channel is provided, the scene will be set to that output channel.
There are 64 channels that you can assign scenes to, which will draw on top of each other in ascending index order when a output is rendered.
§Arguments
name- The name of the scene. This must be unique.channel- Optional channel to bind the scene to. If provided, the scene will be set as active for that channel.
§Returns
A Result containing the new ObsSceneRef or an error
pub fn get_scene(&self, name: &str) -> Result<Option<ObsSceneRef>, ObsError>
pub fn source_builder<T: ObsSourceBuilder, K: Into<ObsString> + Send + Sync>( &self, name: K, ) -> Result<T, ObsError>
Source§impl ObsContext
impl ObsContext
Sourcepub fn output_pipeline(
&self,
output_type: &OutputTypeInfo,
name: impl Into<ObsString>,
settings: Option<ObsData>,
) -> ObsOutputPipelineBuilder
pub fn output_pipeline( &self, output_type: &OutputTypeInfo, name: impl Into<ObsString>, settings: Option<ObsData>, ) -> ObsOutputPipelineBuilder
Starts a high-level pipeline builder for a discovered output type.
Trait Implementations§
Source§impl Clone for ObsContext
impl Clone for ObsContext
Source§fn clone(&self) -> ObsContext
fn clone(&self) -> ObsContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ObsContext
impl Debug for ObsContext
Source§impl ObsContextEncoders for ObsContext
impl ObsContextEncoders for ObsContext
Source§fn best_video_encoder(&self) -> Result<ObsVideoEncoderBuilder, ObsError>
fn best_video_encoder(&self) -> Result<ObsVideoEncoderBuilder, ObsError>
Use ObsContext::capabilities()?.select_video_encoder()
Source§fn best_audio_encoder(&self) -> Result<ObsAudioEncoderBuilder, ObsError>
fn best_audio_encoder(&self) -> Result<ObsAudioEncoderBuilder, ObsError>
Use ObsContext::capabilities()?.select_audio_encoder()
Source§fn available_audio_encoders(
&self,
) -> Result<Vec<ObsAudioEncoderBuilder>, ObsError>
fn available_audio_encoders( &self, ) -> Result<Vec<ObsAudioEncoderBuilder>, ObsError>
Use ObsContext::capabilities()?.select_audio_encoder().matches()
Source§fn available_video_encoders(
&self,
) -> Result<Vec<ObsVideoEncoderBuilder>, ObsError>
fn available_video_encoders( &self, ) -> Result<Vec<ObsVideoEncoderBuilder>, ObsError>
Use ObsContext::capabilities()?.select_video_encoder().matches()