libobs_wrapper\sources/
filter.rs

1use libobs::{obs_scene_t, obs_source_t};
2
3use crate::{
4    data::ImmutableObsData,
5    forward_obs_object_impl, forward_obs_source_impl, impl_obs_drop,
6    macros::impl_eq_of_ptr,
7    runtime::ObsRuntime,
8    sources::ObsSourceRef,
9    unsafe_send::SmartPointerSendable,
10    utils::{ObsDropGuard, ObsError, ObsString},
11};
12
13#[derive(Debug, Clone)]
14// This is essentially the same as the OsSourceRef but we want to make sure
15// the dev doesn't confuse a filter with a source.
16pub struct ObsFilterRef {
17    inner: ObsSourceRef,
18}
19
20impl ObsFilterRef {
21    /// Creates a new OBS filter, this is a more advanced usage as you'll have to specify
22    /// the id, name, settings and hotkey_data yourself. This will be easier in the future...
23    pub fn new<T: Into<ObsString> + Sync + Send, K: Into<ObsString> + Sync + Send>(
24        id: T,
25        name: K,
26        settings: Option<ImmutableObsData>,
27        hotkey_data: Option<ImmutableObsData>,
28        runtime: ObsRuntime,
29    ) -> Result<Self, ObsError> {
30        let inner = ObsSourceRef::new(id, name, settings, hotkey_data, runtime)?;
31        Ok(Self { inner })
32    }
33}
34
35#[derive(Debug)]
36pub(crate) struct _ObsRemoveFilterOnDrop {
37    source: SmartPointerSendable<*mut obs_source_t>,
38    filter: SmartPointerSendable<*mut obs_source_t>,
39    // This could be generic as well but I don't want to bother implementing generics for the impl_obs_drop for now
40    _additional_ptr: Option<SmartPointerSendable<*mut obs_scene_t>>,
41    runtime: ObsRuntime,
42}
43
44impl _ObsRemoveFilterOnDrop {
45    pub fn new(
46        source: SmartPointerSendable<*mut obs_source_t>,
47        filter: SmartPointerSendable<*mut obs_source_t>,
48        additional_ptr: Option<SmartPointerSendable<*mut obs_scene_t>>,
49        runtime: ObsRuntime,
50    ) -> Self {
51        Self {
52            source,
53            filter,
54            _additional_ptr: additional_ptr,
55            runtime,
56        }
57    }
58}
59
60impl ObsDropGuard for _ObsRemoveFilterOnDrop {}
61impl_obs_drop!(_ObsRemoveFilterOnDrop, (source, filter), move || unsafe {
62    // Safety: This is safe because both pointers still exist because of the SmartPointers.
63    libobs::obs_source_filter_remove(source.get_ptr(), filter.get_ptr());
64});
65
66forward_obs_object_impl!(ObsFilterRef, inner, *mut libobs::obs_source_t);
67forward_obs_source_impl!(ObsFilterRef, inner);
68
69impl_eq_of_ptr!(ObsFilterRef);