forked from mirrors/gstreamer-rs
gstreamer-app: Assert that GStreamer is initialized before creating instances
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1193>
This commit is contained in:
parent
80fba8f1e0
commit
b7a52b0da0
3 changed files with 15 additions and 0 deletions
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
() => {};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue