mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-22 01:21:05 +00:00
gstreamer: Move initialization panic into a separate function
This keeps the number of duplicated panics all over the codebase lower and reduces generated code size. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1184>
This commit is contained in:
parent
7b279b9d6c
commit
ba1d8c5ce6
24 changed files with 58 additions and 133 deletions
|
@ -12,12 +12,7 @@ pub use gst;
|
|||
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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -10,6 +10,14 @@ 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) {
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! skip_assert_initialized {
|
||||
() => {};
|
||||
}
|
||||
|
|
|
@ -13,12 +13,7 @@ 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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -12,12 +12,7 @@ pub use gst;
|
|||
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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -12,12 +12,7 @@ pub use gst;
|
|||
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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -12,12 +12,7 @@ pub use gst;
|
|||
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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -39,12 +39,7 @@ pub unsafe fn deinit() {
|
|||
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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
crate::GES_INIT.call_once(|| {
|
||||
unsafe { ffi::ges_init() };
|
||||
|
|
|
@ -15,8 +15,8 @@ pub use gst_gl;
|
|||
|
||||
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) {
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -14,12 +14,7 @@ pub use gst_video;
|
|||
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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ pub use gst_gl;
|
|||
|
||||
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) {
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ pub use gst_gl;
|
|||
|
||||
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) {
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -13,12 +13,7 @@ static MPEGTS_INIT: Once = Once::new();
|
|||
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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
crate::MPEGTS_INIT.call_once(|| unsafe { ffi::gst_mpegts_initialize() });
|
||||
};
|
||||
|
|
|
@ -12,12 +12,7 @@ pub use gst;
|
|||
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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -16,12 +16,7 @@ static PBUTILS_INIT: Once = Once::new();
|
|||
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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
crate::PBUTILS_INIT.call_once(|| {
|
||||
unsafe { ffi::gst_pb_utils_init() };
|
||||
|
|
|
@ -16,12 +16,7 @@ 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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -16,12 +16,7 @@ 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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -13,12 +13,7 @@ pub use gst;
|
|||
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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -16,12 +16,7 @@ pub use gst_sdp;
|
|||
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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -13,12 +13,7 @@ pub use gst_sdp;
|
|||
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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -12,12 +12,7 @@ pub use gst;
|
|||
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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -8,25 +8,25 @@
|
|||
#[doc(hidden)]
|
||||
pub static INITIALIZED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
#[track_caller]
|
||||
pub fn assert_initialized() {
|
||||
if unsafe { ffi::gst_validate_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!("GStreamer Validate has not been initialized. Call `gst_validate::init` first.");
|
||||
} else {
|
||||
crate::INITIALIZED.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
|
||||
if !crate::INITIALIZED.load(std::sync::atomic::Ordering::SeqCst) {
|
||||
if unsafe { ffi::gst_validate_is_initialized() } != glib::ffi::GTRUE {
|
||||
panic!(
|
||||
"GStreamer Validate has not been initialized. Call `gst_validate::init` first."
|
||||
);
|
||||
} else {
|
||||
crate::INITIALIZED.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
$crate::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -13,12 +13,7 @@ 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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -13,12 +13,7 @@ pub use gst_sdp;
|
|||
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);
|
||||
}
|
||||
gst::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -15,15 +15,22 @@ pub use paste;
|
|||
#[doc(hidden)]
|
||||
pub static INITIALIZED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
#[track_caller]
|
||||
pub fn assert_initialized() {
|
||||
#[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);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! assert_initialized_main_thread {
|
||||
() => {
|
||||
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);
|
||||
}
|
||||
$crate::assert_initialized();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue