Module runtime

Source
Expand description

Runtime management for safe OBS API access across threads

This module provides the core thread management functionality for the libobs-wrapper. It ensures that OBS API calls are always executed on the same thread, as required by the OBS API, while still allowing application code to interact with OBS from any thread.

§Thread Safety

The OBS C API is not thread-safe and requires that all operations occur on the same thread. The ObsRuntime struct creates a dedicated thread for all OBS operations and manages message passing between application threads and the OBS thread.

§Async and Blocking APIs

The runtime supports both async and blocking APIs:

  • By default, all operations are asynchronous
  • With the blocking feature enabled, operations are synchronous

§Example

use libobs_wrapper::runtime::ObsRuntime;
use libobs_wrapper::utils::StartupInfo;

async fn example() {
    // Assuming that the OBS context is already initialized

    // Run an operation on the OBS thread
    let runtime = context.runtime();
    runtime.run_with_obs(|| {
        // This code runs on the OBS thread
        println!("Running on OBS thread");
    }).await.unwrap();
}

Structs§

ObsRuntime
Core runtime that manages the OBS thread
_ObsRuntimeGuard
Guard object to ensure proper cleanup when the runtime is dropped

Enums§

ObsRuntimeReturn
Return type for OBS runtime initialization