diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 4af1c13c8..71e06f3d6 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -58,6 +58,11 @@ pub use crate::log::{ CAT_REGISTRY, CAT_RUST, CAT_SCHEDULING, CAT_SIGNAL, CAT_STATES, }; +#[cfg(target_os = "macos")] +mod macos; +#[cfg(target_os = "macos")] +pub use crate::macos::*; + #[macro_use] mod error; pub use crate::error::*; diff --git a/gstreamer/src/macos.rs b/gstreamer/src/macos.rs new file mode 100644 index 000000000..ff78ce9fb --- /dev/null +++ b/gstreamer/src/macos.rs @@ -0,0 +1,37 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +type GstMainFuncSimple = Option; + +#[link(name = "gstreamer-1.0")] +extern "C" { + #[cfg(feature = "v1_22")] + fn gst_macos_main_simple(func: GstMainFuncSimple, user_data: glib::ffi::gpointer); +} + +#[cfg(feature = "v1_22")] +#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))] +#[doc(alias = "gst_macos_main")] +pub fn macos_main(func: F) -> T +where + F: FnOnce() -> T + Send, +{ + skip_assert_initialized!(); + unsafe extern "C" fn trampoline T + Send>(user_data: glib::ffi::gpointer) { + let data = &mut *(user_data as *mut (Option, Option)); + let func = data.0.take().unwrap(); + let res = func(); + + data.1 = Some(res); + } + + let mut func: (Option, Option) = (Some(func), None); + + unsafe { + gst_macos_main_simple( + Some(trampoline::), + &mut func as *mut (Option, Option) as *mut _, + ); + } + + func.1.unwrap() +}