diff --git a/gstreamer-app/src/app_sink.rs b/gstreamer-app/src/app_sink.rs index be1dea64b..c00e42c32 100644 --- a/gstreamer-app/src/app_sink.rs +++ b/gstreamer-app/src/app_sink.rs @@ -273,6 +273,7 @@ impl AppSink { /// /// This method returns an instance of [`AppSinkBuilder`](crate::builders::AppSinkBuilder) which can be used to create [`AppSink`] objects. pub fn builder() -> AppSinkBuilder { + assert_initialized_main_thread!(); AppSinkBuilder::default() } diff --git a/gstreamer-app/src/app_src.rs b/gstreamer-app/src/app_src.rs index 7169a5eca..fb366714d 100644 --- a/gstreamer-app/src/app_src.rs +++ b/gstreamer-app/src/app_src.rs @@ -210,6 +210,7 @@ impl AppSrc { /// /// This method returns an instance of [`AppSrcBuilder`](crate::builders::AppSrcBuilder) which can be used to create [`AppSrc`] objects. pub fn builder() -> AppSrcBuilder { + assert_initialized_main_thread!(); AppSrcBuilder::default() } diff --git a/gstreamer-app/src/lib.rs b/gstreamer-app/src/lib.rs index 1d8bfc167..52bf150e4 100644 --- a/gstreamer-app/src/lib.rs +++ b/gstreamer-app/src/lib.rs @@ -10,6 +10,19 @@ pub use glib; pub use gst; pub use gst_base; +macro_rules! assert_initialized_main_thread { + () => { + if !gst::INITIALIZED.load(std::sync::atomic::Ordering::SeqCst) { + #[allow(unused_unsafe)] + if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE { + panic!("GStreamer has not been initialized. Call `gst::init` first."); + } else { + gst::INITIALIZED.store(true, std::sync::atomic::Ordering::SeqCst); + } + } + }; +} + macro_rules! skip_assert_initialized { () => {}; }