mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-22 01:21:05 +00:00
Store whether GStreamer was initialized in an AtomicBool
Avoids a function call in the normal case.
This commit is contained in:
parent
7754b8dd70
commit
c9d07219c8
18 changed files with 137 additions and 36 deletions
|
@ -11,9 +11,13 @@ pub use gst;
|
|||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
#[allow(unused_unsafe)]
|
||||
if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -12,8 +12,13 @@ pub use gst_base;
|
|||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -11,8 +11,13 @@ pub use gst;
|
|||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -11,8 +11,13 @@ pub use gst;
|
|||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -11,8 +11,13 @@ pub use gst;
|
|||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -39,8 +39,13 @@ pub unsafe fn deinit() {
|
|||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
crate::GES_INIT.call_once(|| {
|
||||
unsafe { ffi::ges_init() };
|
||||
|
|
|
@ -13,8 +13,13 @@ pub use gst_video;
|
|||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -11,8 +11,13 @@ pub use gst;
|
|||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -15,8 +15,13 @@ static PBUTILS_INIT: Once = Once::new();
|
|||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
crate::PBUTILS_INIT.call_once(|| {
|
||||
unsafe { ffi::gst_pb_utils_init() };
|
||||
|
|
|
@ -14,7 +14,16 @@ macro_rules! skip_assert_initialized {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_borrow)]
|
||||
|
|
|
@ -14,7 +14,16 @@ macro_rules! skip_assert_initialized {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(clippy::unreadable_literal)]
|
||||
|
|
|
@ -12,8 +12,13 @@ pub use gst;
|
|||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -15,8 +15,13 @@ pub use gst_sdp;
|
|||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -12,8 +12,13 @@ pub use gst_sdp;
|
|||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -11,8 +11,13 @@ pub use gst;
|
|||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -12,9 +12,13 @@ pub use gst_base;
|
|||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
#[allow(unused_unsafe)]
|
||||
if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -12,8 +12,13 @@ pub use gst_sdp;
|
|||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -14,10 +14,18 @@ pub use paste;
|
|||
|
||||
use glib::translate::{from_glib, from_glib_full};
|
||||
|
||||
#[doc(hidden)]
|
||||
pub static INITIALIZED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
if unsafe { ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
if !crate::INITIALIZED.load(std::sync::atomic::Ordering::SeqCst) {
|
||||
#[allow(unused_unsafe)]
|
||||
if unsafe { ffi::gst_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer has not been initialized. Call `gst::init` first.");
|
||||
} else {
|
||||
crate::INITIALIZED.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -263,6 +271,7 @@ pub fn init() -> Result<(), glib::Error> {
|
|||
ptr::null_mut(),
|
||||
&mut error,
|
||||
)) {
|
||||
crate::INITIALIZED.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(from_glib_full(error))
|
||||
|
@ -278,6 +287,7 @@ pub fn init() -> Result<(), glib::Error> {
|
|||
/// This must only be called once during the lifetime of the process, once no GStreamer threads
|
||||
/// are running anymore and all GStreamer resources are released.
|
||||
pub unsafe fn deinit() {
|
||||
crate::INITIALIZED.store(false, std::sync::atomic::Ordering::SeqCst);
|
||||
ffi::gst_deinit();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue