Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

How can I access current module from the source? #27

Open
erickskrauch opened this issue Aug 27, 2022 · 1 comment
Open

How can I access current module from the source? #27

erickskrauch opened this issue Aug 27, 2022 · 1 comment

Comments

@erickskrauch
Copy link

Hi.

I'm developing a module that has a filter and a source. They must be interconnected. I assume that the connection should be done through the structure of the module. But I can't find any way how I can get the current module from my filter and source.

OBS has a function obs_current_module(), but it is not suitable for my task, because it only returns a pointer, which I still can't somehow cast to the Rust's module data struct.

Could you please help me with this task? I'm still just learning Rust and don't understand a lot.

@bennetthardwick
Copy link
Owner

Hi @erickskrauch I'm not sure what the best way to do this is. If you have any examples in other languages that do this I can try and create an API that can help.

I haven't tested this but you might be able to create a static variable to store your shared state or channel. Kinda like how the module is stored:

static mut OBS_MODULE: Option<$t> = None;
static mut LOAD_CONTEXT: Option<$crate::module::LoadContext> = None;
#[allow(missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn obs_module_set_pointer(raw: *mut $crate::obs_sys::obs_module_t) {
OBS_MODULE = Some(<$t>::new(ModuleContext::new(raw)));
}
#[allow(missing_safety_doc)]
#[no_mangle]
pub unsafe extern "C" fn obs_current_module() -> *mut $crate::obs_sys::obs_module_t {
if let Some(module) = &OBS_MODULE {
module.get_ctx().get_raw()
} else {
panic!("Could not get current module!");
}
}

If that doesn't work you could create a named pipe but that would probably have performance implications.

Let me know if the static variable works for you 👍🏻

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants