From c07fe14191be3221def41820c5aec9550d773873 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 22 Mar 2020 15:18:47 +0100 Subject: [PATCH] gstreamer*: Add missing init checks --- gstreamer-app/src/app_sink.rs | 1 + gstreamer-app/src/app_src.rs | 1 + gstreamer-audio/src/audio_meta.rs | 1 + gstreamer-base/src/base_parse_frame.rs | 2 ++ gstreamer-base/src/utils.rs | 1 + gstreamer-editing-services/src/lib.rs | 1 + gstreamer-gl/src/gl_context.rs | 2 ++ gstreamer-gl/src/gl_sync_meta.rs | 1 + gstreamer-gl/src/gl_video_frame.rs | 3 +++ gstreamer-net/src/lib.rs | 4 ++++ gstreamer-net/src/net_address_meta.rs | 1 + gstreamer-pbutils/src/encoding_profile.rs | 1 + gstreamer-rtp/src/rtp_buffer.rs | 4 ++++ gstreamer-rtsp-server/src/rtsp_thread.rs | 1 + gstreamer-rtsp-server/src/rtsp_token.rs | 1 + gstreamer-video/src/functions.rs | 5 +++++ gstreamer-video/src/video_codec_frame.rs | 1 + gstreamer-video/src/video_codec_state.rs | 2 ++ gstreamer-video/src/video_converter.rs | 1 + gstreamer-video/src/video_event.rs | 6 ++++++ gstreamer-video/src/video_info.rs | 3 +++ gstreamer-video/src/video_meta.rs | 6 ++++++ gstreamer-video/src/video_overlay.rs | 1 + .../src/video_overlay_composition.rs | 2 ++ gstreamer-video/src/video_rectangle.rs | 2 ++ gstreamer-video/src/video_time_code.rs | 5 +++++ gstreamer/src/allocation_params.rs | 1 + gstreamer/src/buffer_cursor.rs | 4 ++++ gstreamer/src/buffer_pool.rs | 2 ++ gstreamer/src/buffer_serde.rs | 2 ++ gstreamer/src/bufferlist_serde.rs | 1 + gstreamer/src/caps.rs | 2 ++ gstreamer/src/caps_features.rs | 1 + gstreamer/src/caps_features_serde.rs | 3 +++ gstreamer/src/caps_serde.rs | 4 ++++ gstreamer/src/clock.rs | 2 ++ gstreamer/src/clock_time.rs | 4 ++++ gstreamer/src/clock_time_serde.rs | 1 + gstreamer/src/date_time.rs | 5 +++++ gstreamer/src/date_time_serde.rs | 5 +++++ gstreamer/src/enums.rs | 20 +++++++++++++++++++ gstreamer/src/error.rs | 3 +++ gstreamer/src/format.rs | 12 +++++++++++ gstreamer/src/format_serde.rs | 3 +++ gstreamer/src/functions.rs | 1 + gstreamer/src/iterator.rs | 4 ++++ gstreamer/src/log.rs | 5 +++++ gstreamer/src/memory.rs | 2 ++ gstreamer/src/meta.rs | 2 ++ gstreamer/src/miniobject.rs | 2 ++ gstreamer/src/param_spec.rs | 2 ++ gstreamer/src/promise.rs | 1 + gstreamer/src/query.rs | 3 +++ gstreamer/src/sample_serde.rs | 2 ++ gstreamer/src/segment_serde.rs | 2 ++ gstreamer/src/structure.rs | 3 +++ gstreamer/src/structure_serde.rs | 4 ++++ gstreamer/src/tags.rs | 9 +++++++++ gstreamer/src/tags_serde.rs | 7 +++++++ gstreamer/src/toc_serde.rs | 4 ++++ gstreamer/src/typefind.rs | 3 +++ gstreamer/src/utils.rs | 1 + gstreamer/src/value_serde.rs | 5 +++++ 63 files changed, 196 insertions(+) diff --git a/gstreamer-app/src/app_sink.rs b/gstreamer-app/src/app_sink.rs index a182a3468..4587c9a4d 100644 --- a/gstreamer-app/src/app_sink.rs +++ b/gstreamer-app/src/app_sink.rs @@ -146,6 +146,7 @@ impl AppSinkCallbacksBuilder { } fn post_panic_error_message(element: &AppSink, err: &dyn std::any::Any) { + skip_assert_initialized!(); if let Some(cause) = err.downcast_ref::<&str>() { gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked: {}", cause]); } else if let Some(cause) = err.downcast_ref::() { diff --git a/gstreamer-app/src/app_src.rs b/gstreamer-app/src/app_src.rs index 9f74036fb..b7819c3c0 100644 --- a/gstreamer-app/src/app_src.rs +++ b/gstreamer-app/src/app_src.rs @@ -118,6 +118,7 @@ impl AppSrcCallbacksBuilder { } fn post_panic_error_message(element: &AppSrc, err: &dyn std::any::Any) { + skip_assert_initialized!(); if let Some(cause) = err.downcast_ref::<&str>() { gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked: {}", cause]); } else if let Some(cause) = err.downcast_ref::() { diff --git a/gstreamer-audio/src/audio_meta.rs b/gstreamer-audio/src/audio_meta.rs index 8d763ef05..8c4fe2490 100644 --- a/gstreamer-audio/src/audio_meta.rs +++ b/gstreamer-audio/src/audio_meta.rs @@ -27,6 +27,7 @@ impl AudioClippingMeta { start: V, end: V, ) -> gst::MetaRefMut { + skip_assert_initialized!(); let start = start.into(); let end = end.into(); assert_eq!(start.get_format(), end.get_format()); diff --git a/gstreamer-base/src/base_parse_frame.rs b/gstreamer-base/src/base_parse_frame.rs index 43b9a2c3a..9d81902a7 100644 --- a/gstreamer-base/src/base_parse_frame.rs +++ b/gstreamer-base/src/base_parse_frame.rs @@ -49,6 +49,7 @@ impl ToGlib for Overhead { impl FromGlib for Overhead { #[inline] fn from_glib(val: i32) -> Overhead { + skip_assert_initialized!(); match val { 0 => Overhead::None, 1 => Overhead::Frame, @@ -94,6 +95,7 @@ impl<'a> BaseParseFrame<'a> { frame: *mut gst_base_sys::GstBaseParseFrame, _parse: &'a BaseParse, ) -> BaseParseFrame<'a> { + skip_assert_initialized!(); assert!(!frame.is_null()); BaseParseFrame(ptr::NonNull::new_unchecked(frame), PhantomData) } diff --git a/gstreamer-base/src/utils.rs b/gstreamer-base/src/utils.rs index ff456cd06..d4308fb51 100644 --- a/gstreamer-base/src/utils.rs +++ b/gstreamer-base/src/utils.rs @@ -15,6 +15,7 @@ pub struct MutexGuard<'a>(&'a glib_sys::GMutex); impl<'a> MutexGuard<'a> { #[allow(clippy::trivially_copy_pass_by_ref)] pub fn lock(mutex: &'a glib_sys::GMutex) -> Self { + skip_assert_initialized!(); unsafe { glib_sys::g_mutex_lock(mut_override(mutex)); } diff --git a/gstreamer-editing-services/src/lib.rs b/gstreamer-editing-services/src/lib.rs index 1f3b6d825..45eb3df50 100644 --- a/gstreamer-editing-services/src/lib.rs +++ b/gstreamer-editing-services/src/lib.rs @@ -75,6 +75,7 @@ pub use auto::*; #[macro_use] extern crate bitflags; +mod asset; mod timeline_element; pub use timeline_element::TimelineElementExtManual; diff --git a/gstreamer-gl/src/gl_context.rs b/gstreamer-gl/src/gl_context.rs index 791285310..2a2723d0a 100644 --- a/gstreamer-gl/src/gl_context.rs +++ b/gstreamer-gl/src/gl_context.rs @@ -31,6 +31,7 @@ impl GLContext { } pub fn get_current_gl_context(context_type: GLPlatform) -> uintptr_t { + skip_assert_initialized!(); unsafe { gst_gl_sys::gst_gl_context_get_current_gl_context(context_type.to_glib()) as uintptr_t } @@ -41,6 +42,7 @@ impl GLContext { gl_api: GLAPI, name: &str, ) -> uintptr_t { + skip_assert_initialized!(); unsafe { gst_gl_sys::gst_gl_context_get_proc_address_with_platform( context_type.to_glib(), diff --git a/gstreamer-gl/src/gl_sync_meta.rs b/gstreamer-gl/src/gl_sync_meta.rs index 5f0fd95d3..f491b1d18 100644 --- a/gstreamer-gl/src/gl_sync_meta.rs +++ b/gstreamer-gl/src/gl_sync_meta.rs @@ -19,6 +19,7 @@ impl GLSyncMeta { buffer: &'a mut gst::BufferRef, context: &C, ) -> gst::MetaRefMut<'a, Self, gst::meta::Standalone> { + skip_assert_initialized!(); unsafe { let meta = gst_gl_sys::gst_buffer_add_gl_sync_meta( context.as_ref().to_glib_none().0, diff --git a/gstreamer-gl/src/gl_video_frame.rs b/gstreamer-gl/src/gl_video_frame.rs index 3f39efd23..e9646a70a 100644 --- a/gstreamer-gl/src/gl_video_frame.rs +++ b/gstreamer-gl/src/gl_video_frame.rs @@ -39,6 +39,7 @@ impl VideoFrameGLExt for VideoFrame { buffer: gst::Buffer, info: &VideoInfo, ) -> Result, gst::Buffer> { + skip_assert_initialized!(); VideoFrameRef::<&gst::BufferRef>::from_buffer_readable_gl(buffer, info) } @@ -46,6 +47,7 @@ impl VideoFrameGLExt for VideoFrame { buffer: &'a gst::BufferRef, info: &'b VideoInfo, ) -> Result, glib::error::BoolError> { + skip_assert_initialized!(); VideoFrameRef::<&gst::BufferRef>::from_buffer_ref_readable_gl(buffer, info) } @@ -153,6 +155,7 @@ impl<'a> VideoFrameGLExt for VideoFrameRef<&'a gst::BufferRef> { } fn buffer_n_gl_memory(buffer: &gst::BufferRef) -> Option { + skip_assert_initialized!(); unsafe { let buf = buffer.as_mut_ptr(); let num = gst_sys::gst_buffer_n_memory(buf); diff --git a/gstreamer-net/src/lib.rs b/gstreamer-net/src/lib.rs index a8cc89b43..31e41e414 100644 --- a/gstreamer-net/src/lib.rs +++ b/gstreamer-net/src/lib.rs @@ -24,6 +24,10 @@ macro_rules! assert_initialized_main_thread { }; } +macro_rules! skip_assert_initialized { + () => {}; +} + #[allow(clippy::unreadable_literal)] #[allow(clippy::too_many_arguments)] #[allow(clippy::match_same_arms)] diff --git a/gstreamer-net/src/net_address_meta.rs b/gstreamer-net/src/net_address_meta.rs index 3e0c18dc6..1da4fbdca 100644 --- a/gstreamer-net/src/net_address_meta.rs +++ b/gstreamer-net/src/net_address_meta.rs @@ -18,6 +18,7 @@ impl NetAddressMeta { buffer: &'a mut gst::BufferRef, addr: &A, ) -> gst::MetaRefMut<'a, Self, gst::meta::Standalone> { + skip_assert_initialized!(); unsafe { let meta = gst_net_sys::gst_buffer_add_net_address_meta( buffer.as_mut_ptr(), diff --git a/gstreamer-pbutils/src/encoding_profile.rs b/gstreamer-pbutils/src/encoding_profile.rs index f2a071d1d..f0d59e671 100644 --- a/gstreamer-pbutils/src/encoding_profile.rs +++ b/gstreamer-pbutils/src/encoding_profile.rs @@ -362,6 +362,7 @@ fn set_common_fields( profile: &T, base_data: &EncodingProfileBuilderCommonData, ) { + skip_assert_initialized!(); profile.set_name(base_data.name); profile.set_description(base_data.description); profile.set_preset(base_data.preset); diff --git a/gstreamer-rtp/src/rtp_buffer.rs b/gstreamer-rtp/src/rtp_buffer.rs index ffcfa7360..7b3aef411 100644 --- a/gstreamer-rtp/src/rtp_buffer.rs +++ b/gstreamer-rtp/src/rtp_buffer.rs @@ -32,6 +32,7 @@ impl<'a> RTPBuffer<'a, Readable> { pub fn from_buffer_readable( buffer: &gst::Buffer, ) -> Result, glib::BoolError> { + skip_assert_initialized!(); unsafe { let mut rtp_buffer = mem::MaybeUninit::zeroed(); let res: bool = from_glib(gst_rtp_sys::gst_rtp_buffer_map( @@ -57,6 +58,7 @@ impl<'a> RTPBuffer<'a, Writable> { pub fn from_buffer_writable( buffer: &mut gst::Buffer, ) -> Result, glib::BoolError> { + skip_assert_initialized!(); unsafe { let mut rtp_buffer = mem::MaybeUninit::zeroed(); let res: bool = from_glib(gst_rtp_sys::gst_rtp_buffer_map( @@ -132,6 +134,7 @@ impl RTPBufferExt for gst::Buffer { pad_len: u8, csrc_count: u8, ) -> Result { + assert_initialized_main_thread!(); unsafe { Option::<_>::from_glib_full(gst_rtp_sys::gst_rtp_buffer_new_allocate( payload_len, @@ -144,6 +147,7 @@ impl RTPBufferExt for gst::Buffer { } pub fn compare_seqnum(seqnum1: u16, seqnum2: u16) -> i32 { + skip_assert_initialized!(); unsafe { gst_rtp_sys::gst_rtp_buffer_compare_seqnum(seqnum1, seqnum2) } } diff --git a/gstreamer-rtsp-server/src/rtsp_thread.rs b/gstreamer-rtsp-server/src/rtsp_thread.rs index be21cab4f..6ace67caf 100644 --- a/gstreamer-rtsp-server/src/rtsp_thread.rs +++ b/gstreamer-rtsp-server/src/rtsp_thread.rs @@ -14,6 +14,7 @@ gst_define_mini_object_wrapper!( impl RTSPThread { pub fn new(type_: ::RTSPThreadType) -> Option { + assert_initialized_main_thread!(); unsafe { from_glib_full(gst_rtsp_server_sys::gst_rtsp_thread_new(type_.to_glib())) } } } diff --git a/gstreamer-rtsp-server/src/rtsp_token.rs b/gstreamer-rtsp-server/src/rtsp_token.rs index 564a9b095..e76d604b3 100644 --- a/gstreamer-rtsp-server/src/rtsp_token.rs +++ b/gstreamer-rtsp-server/src/rtsp_token.rs @@ -22,6 +22,7 @@ impl RTSPToken { } pub fn new(values: &[(&str, &dyn ToSendValue)]) -> Self { + assert_initialized_main_thread!(); let mut token = RTSPToken::new_empty(); { diff --git a/gstreamer-video/src/functions.rs b/gstreamer-video/src/functions.rs index 33b465cb8..ca86a9a44 100644 --- a/gstreamer-video/src/functions.rs +++ b/gstreamer-video/src/functions.rs @@ -22,6 +22,7 @@ pub fn convert_sample( caps: &gst::Caps, timeout: gst::ClockTime, ) -> Result { + skip_assert_initialized!(); unsafe { let mut error = ptr::null_mut(); let ret = gst_video_sys::gst_video_convert_sample( @@ -47,6 +48,7 @@ pub fn convert_sample_async( ) where F: FnOnce(Result) + Send + 'static, { + skip_assert_initialized!(); unsafe { convert_sample_async_unsafe(sample, caps, timeout, func) } } @@ -58,6 +60,7 @@ pub fn convert_sample_async_local( ) where F: FnOnce(Result) + Send + 'static, { + skip_assert_initialized!(); unsafe { assert!(glib::MainContext::ref_thread_default().is_owner()); convert_sample_async_unsafe(sample, caps, timeout, func) @@ -113,6 +116,8 @@ pub fn convert_sample_future( timeout: gst::ClockTime, ) -> std::pin::Pin> + 'static>> { + skip_assert_initialized!(); + use futures_channel::oneshot; use futures_util::future::lazy; use futures_util::future::FutureExt; diff --git a/gstreamer-video/src/video_codec_frame.rs b/gstreamer-video/src/video_codec_frame.rs index 1c63347e9..72a99e3ce 100644 --- a/gstreamer-video/src/video_codec_frame.rs +++ b/gstreamer-video/src/video_codec_frame.rs @@ -69,6 +69,7 @@ impl<'a> VideoCodecFrame<'a> { frame: *mut gst_video_sys::GstVideoCodecFrame, element: &'a T, ) -> Self { + skip_assert_initialized!(); let stream_lock = element.get_stream_lock(); glib_sys::g_rec_mutex_lock(stream_lock); Self { frame, element } diff --git a/gstreamer-video/src/video_codec_state.rs b/gstreamer-video/src/video_codec_state.rs index 0fe675303..278458149 100644 --- a/gstreamer-video/src/video_codec_state.rs +++ b/gstreamer-video/src/video_codec_state.rs @@ -73,6 +73,7 @@ impl<'a, T: VideoCodecStateContext<'a>> fmt::Debug for VideoCodecState<'a, T> { impl<'a> VideoCodecState<'a, Readable> { // Take ownership of @state pub(crate) unsafe fn new(state: *mut gst_video_sys::GstVideoCodecState) -> Self { + skip_assert_initialized!(); Self { state, context: Readable {}, @@ -87,6 +88,7 @@ impl<'a> VideoCodecState<'a, InNegotiation<'a>> { state: *mut gst_video_sys::GstVideoCodecState, element: &'a T, ) -> Self { + skip_assert_initialized!(); let stream_lock = element.get_stream_lock(); glib_sys::g_rec_mutex_lock(stream_lock); Self { diff --git a/gstreamer-video/src/video_converter.rs b/gstreamer-video/src/video_converter.rs index c24f2bb65..7eb21d166 100644 --- a/gstreamer-video/src/video_converter.rs +++ b/gstreamer-video/src/video_converter.rs @@ -35,6 +35,7 @@ impl VideoConverter { out_info: &::VideoInfo, config: Option, ) -> Result { + assert_initialized_main_thread!(); if in_info.fps() != out_info.fps() { return Err(glib_bool_error!("Can't do framerate conversion")); } diff --git a/gstreamer-video/src/video_event.rs b/gstreamer-video/src/video_event.rs index 135fd9a89..be3e6e46c 100644 --- a/gstreamer-video/src/video_event.rs +++ b/gstreamer-video/src/video_event.rs @@ -16,6 +16,7 @@ use gst::MiniObject; use std::mem; pub fn is_force_key_unit_event(event: &gst::EventRef) -> bool { + skip_assert_initialized!(); unsafe { from_glib(gst_video_sys::gst_video_event_is_force_key_unit( event.as_mut_ptr(), @@ -159,6 +160,7 @@ pub struct DownstreamForceKeyUnitEvent { pub fn parse_downstream_force_key_unit_event( event: &gst::EventRef, ) -> Result { + skip_assert_initialized!(); unsafe { let mut timestamp = mem::MaybeUninit::uninit(); let mut stream_time = mem::MaybeUninit::uninit(); @@ -253,6 +255,7 @@ pub struct UpstreamForceKeyUnitEvent { pub fn parse_upstream_force_key_unit_event( event: &gst::EventRef, ) -> Result { + skip_assert_initialized!(); unsafe { let mut running_time = mem::MaybeUninit::uninit(); let mut all_headers = mem::MaybeUninit::uninit(); @@ -287,6 +290,7 @@ pub enum ForceKeyUnitEvent { pub fn parse_force_key_unit_event( event: &gst::EventRef, ) -> Result { + skip_assert_initialized!(); if event.is_upstream() { parse_upstream_force_key_unit_event(event).map(ForceKeyUnitEvent::Upstream) } else { @@ -295,6 +299,7 @@ pub fn parse_force_key_unit_event( } pub fn new_still_frame_event<'a>(in_still: bool) -> StillFrameEventBuilder<'a> { + assert_initialized_main_thread!(); StillFrameEventBuilder::new(in_still) } @@ -329,6 +334,7 @@ pub struct StillFrameEvent { pub fn parse_still_frame_event( event: &gst::EventRef, ) -> Result { + skip_assert_initialized!(); unsafe { let mut in_still = mem::MaybeUninit::uninit(); diff --git a/gstreamer-video/src/video_info.rs b/gstreamer-video/src/video_info.rs index 486c07eac..6ba17fc5c 100644 --- a/gstreamer-video/src/video_info.rs +++ b/gstreamer-video/src/video_info.rs @@ -189,6 +189,7 @@ impl fmt::Display for ::VideoColorimetry { impl From<::VideoMultiviewFramePacking> for ::VideoMultiviewMode { fn from(v: ::VideoMultiviewFramePacking) -> Self { + skip_assert_initialized!(); from_glib(v.to_glib()) } } @@ -199,6 +200,8 @@ impl std::convert::TryFrom<::VideoMultiviewMode> for ::VideoMultiviewFramePackin fn try_from( v: ::VideoMultiviewMode, ) -> Result<::VideoMultiviewFramePacking, ::VideoMultiviewMode> { + skip_assert_initialized!(); + let v2 = from_glib(v.to_glib()); if let ::VideoMultiviewFramePacking::__Unknown(_) = v2 { diff --git a/gstreamer-video/src/video_meta.rs b/gstreamer-video/src/video_meta.rs index d7abd2403..1f4ca8981 100644 --- a/gstreamer-video/src/video_meta.rs +++ b/gstreamer-video/src/video_meta.rs @@ -29,6 +29,8 @@ impl VideoMeta { width: u32, height: u32, ) -> gst::MetaRefMut { + skip_assert_initialized!(); + let info = ::VideoInfo::new(format, width, height).build().unwrap(); assert!(buffer.get_size() >= info.size()); @@ -54,6 +56,8 @@ impl VideoMeta { offset: &[usize], stride: &[i32], ) -> gst::MetaRefMut<'a, Self, gst::meta::Standalone> { + skip_assert_initialized!(); + let n_planes = offset.len() as u32; let info = ::VideoInfo::new(format, width, height) .offset(offset) @@ -145,6 +149,7 @@ impl VideoOverlayCompositionMeta { buffer: &'a mut gst::BufferRef, overlay: &::VideoOverlayComposition, ) -> gst::MetaRefMut<'a, Self, gst::meta::Standalone> { + skip_assert_initialized!(); unsafe { let meta = gst_video_sys::gst_buffer_add_video_overlay_composition_meta( buffer.as_mut_ptr(), @@ -204,6 +209,7 @@ impl VideoCaptionMeta { caption_type: ::VideoCaptionType, data: &[u8], ) -> gst::MetaRefMut<'a, Self, gst::meta::Standalone> { + skip_assert_initialized!(); unsafe { let meta = gst_video_sys::gst_buffer_add_video_caption_meta( buffer.as_mut_ptr(), diff --git a/gstreamer-video/src/video_overlay.rs b/gstreamer-video/src/video_overlay.rs index 39456fbfa..a054795ed 100644 --- a/gstreamer-video/src/video_overlay.rs +++ b/gstreamer-video/src/video_overlay.rs @@ -31,6 +31,7 @@ impl> VideoOverlayExtManual for O { } pub fn is_video_overlay_prepare_window_handle_message(msg: &gst::MessageRef) -> bool { + skip_assert_initialized!(); unsafe { from_glib( gst_video_sys::gst_is_video_overlay_prepare_window_handle_message(msg.as_mut_ptr()), diff --git a/gstreamer-video/src/video_overlay_composition.rs b/gstreamer-video/src/video_overlay_composition.rs index 4eb2e1085..00b2d4a31 100644 --- a/gstreamer-video/src/video_overlay_composition.rs +++ b/gstreamer-video/src/video_overlay_composition.rs @@ -43,6 +43,7 @@ impl VideoOverlayRectangle { render_height: u32, flags: ::VideoOverlayFormatFlags, ) -> Self { + assert_initialized_main_thread!(); assert!(buffer.get_meta::<::VideoMeta>().is_some()); unsafe { from_glib_full(gst_video_sys::gst_video_overlay_rectangle_new_raw( @@ -201,6 +202,7 @@ impl VideoOverlayComposition { pub fn new<'a, T: IntoIterator>( rects: T, ) -> Result { + assert_initialized_main_thread!(); unsafe { let mut iter = rects.into_iter(); diff --git a/gstreamer-video/src/video_rectangle.rs b/gstreamer-video/src/video_rectangle.rs index 452817392..99bbc78e3 100644 --- a/gstreamer-video/src/video_rectangle.rs +++ b/gstreamer-video/src/video_rectangle.rs @@ -19,6 +19,7 @@ pub struct VideoRectangle { impl VideoRectangle { pub fn new(x: i32, y: i32, w: i32, h: i32) -> Self { + skip_assert_initialized!(); VideoRectangle { x, y, w, h } } } @@ -28,6 +29,7 @@ pub fn center_video_rectangle( dst: &VideoRectangle, scale: bool, ) -> VideoRectangle { + skip_assert_initialized!(); let mut result = gst_video_sys::GstVideoRectangle { x: 0, y: 0, diff --git a/gstreamer-video/src/video_time_code.rs b/gstreamer-video/src/video_time_code.rs index 539d7a4f8..99fa7c75f 100644 --- a/gstreamer-video/src/video_time_code.rs +++ b/gstreamer-video/src/video_time_code.rs @@ -144,6 +144,7 @@ impl TryFrom for ValidVideoTimeCode { type Error = VideoTimeCode; fn try_from(v: VideoTimeCode) -> Result { + skip_assert_initialized!(); if v.is_valid() { Ok(ValidVideoTimeCode(v.0)) } else { @@ -164,6 +165,7 @@ impl ValidVideoTimeCode { frames: u32, field_count: u32, ) -> Result { + assert_initialized_main_thread!(); let tc = VideoTimeCode::new( fps, latest_daily_jam, @@ -192,6 +194,7 @@ impl ValidVideoTimeCode { // } pub fn add_frames(&mut self, frames: i64) { + skip_assert_initialized!(); unsafe { gst_video_sys::gst_video_time_code_add_frames(self.to_glib_none_mut().0, frames); } @@ -517,6 +520,7 @@ impl Ord for ValidVideoTimeCode { impl From for VideoTimeCode { fn from(v: ValidVideoTimeCode) -> VideoTimeCode { + skip_assert_initialized!(); VideoTimeCode(v.0) } } @@ -532,6 +536,7 @@ impl VideoTimeCodeMeta { buffer: &'a mut gst::BufferRef, tc: &ValidVideoTimeCode, ) -> gst::MetaRefMut<'a, Self, gst::meta::Standalone> { + skip_assert_initialized!(); unsafe { let meta = gst_video_sys::gst_buffer_add_video_time_code_meta( buffer.as_mut_ptr(), diff --git a/gstreamer/src/allocation_params.rs b/gstreamer/src/allocation_params.rs index 7fe794d04..da37295ff 100644 --- a/gstreamer/src/allocation_params.rs +++ b/gstreamer/src/allocation_params.rs @@ -58,6 +58,7 @@ impl AllocationParams { impl From for AllocationParams { fn from(params: gst_sys::GstAllocationParams) -> Self { + skip_assert_initialized!(); AllocationParams(params) } } diff --git a/gstreamer/src/buffer_cursor.rs b/gstreamer/src/buffer_cursor.rs index d393b0d53..691eacda1 100644 --- a/gstreamer/src/buffer_cursor.rs +++ b/gstreamer/src/buffer_cursor.rs @@ -286,6 +286,7 @@ impl BufferCursor { impl BufferCursor { pub(crate) fn new_readable(buffer: Buffer) -> BufferCursor { + skip_assert_initialized!(); let size = buffer.get_size() as u64; let num_mem = buffer.n_memory(); @@ -304,6 +305,7 @@ impl BufferCursor { impl BufferCursor { pub(crate) fn new_writable(buffer: Buffer) -> Result, glib::BoolError> { + skip_assert_initialized!(); if !buffer.is_writable() || !buffer.is_all_memory_writable() { return Err(glib_bool_error!("Not all memories are writable")); } @@ -383,6 +385,7 @@ impl<'a> BufferRefCursor<&'a BufferRef> { } pub(crate) fn new_readable(buffer: &'a BufferRef) -> BufferRefCursor<&'a BufferRef> { + skip_assert_initialized!(); let size = buffer.get_size() as u64; let num_mem = buffer.n_memory(); @@ -406,6 +409,7 @@ impl<'a> BufferRefCursor<&'a mut BufferRef> { pub(crate) fn new_writable( buffer: &'a mut BufferRef, ) -> Result, glib::BoolError> { + skip_assert_initialized!(); if !buffer.is_all_memory_writable() { return Err(glib_bool_error!("Not all memories are writable")); } diff --git a/gstreamer/src/buffer_pool.rs b/gstreamer/src/buffer_pool.rs index 3054dca39..e4183ae9a 100644 --- a/gstreamer/src/buffer_pool.rs +++ b/gstreamer/src/buffer_pool.rs @@ -192,6 +192,7 @@ unsafe impl Sync for BufferPoolAcquireParams {} impl BufferPoolAcquireParams { pub fn with_flags(flags: ::BufferPoolAcquireFlags) -> Self { + skip_assert_initialized!(); BufferPoolAcquireParams(gst_sys::GstBufferPoolAcquireParams { format: gst_sys::GST_FORMAT_UNDEFINED, start: -1, @@ -206,6 +207,7 @@ impl BufferPoolAcquireParams { stop: T, flags: ::BufferPoolAcquireFlags, ) -> Self { + skip_assert_initialized!(); unsafe { BufferPoolAcquireParams(gst_sys::GstBufferPoolAcquireParams { format: start.get_format().to_glib(), diff --git a/gstreamer/src/buffer_serde.rs b/gstreamer/src/buffer_serde.rs index 3fb054004..16b2a49b0 100644 --- a/gstreamer/src/buffer_serde.rs +++ b/gstreamer/src/buffer_serde.rs @@ -57,6 +57,7 @@ struct BufferDe { impl From for Buffer { fn from(buf_de: BufferDe) -> Self { + skip_assert_initialized!(); let mut buffer = Buffer::from_mut_slice(buf_de.buffer.to_vec()); { let buffer = buffer.get_mut().unwrap(); @@ -73,6 +74,7 @@ impl From for Buffer { impl<'de> Deserialize<'de> for Buffer { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); BufferDe::deserialize(deserializer).map(|buffer_de| buffer_de.into()) } } diff --git a/gstreamer/src/bufferlist_serde.rs b/gstreamer/src/bufferlist_serde.rs index cd0407b19..cc9ffc940 100644 --- a/gstreamer/src/bufferlist_serde.rs +++ b/gstreamer/src/bufferlist_serde.rs @@ -60,6 +60,7 @@ impl<'de> Visitor<'de> for BufferListVisitor { impl<'de> Deserialize<'de> for BufferList { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); deserializer.deserialize_seq(BufferListVisitor) } } diff --git a/gstreamer/src/caps.rs b/gstreamer/src/caps.rs index 368a94e62..6d5e85dd0 100644 --- a/gstreamer/src/caps.rs +++ b/gstreamer/src/caps.rs @@ -570,6 +570,7 @@ impl fmt::Debug for Builder { impl Builder { fn new(name: &str) -> Builder { + skip_assert_initialized!(); Builder { s: ::Structure::new_empty(name), features: None, @@ -639,6 +640,7 @@ impl BuilderFull { } fn new_with_features(features: CapsFeatures) -> Self { + skip_assert_initialized!(); BuilderFull { caps: Caps::new_empty(), features: Some(features), diff --git a/gstreamer/src/caps_features.rs b/gstreamer/src/caps_features.rs index 05d9b763c..d57a2a98f 100644 --- a/gstreamer/src/caps_features.rs +++ b/gstreamer/src/caps_features.rs @@ -32,6 +32,7 @@ unsafe impl Sync for CapsFeatures {} impl CapsFeatures { pub fn new(features: &[&str]) -> Self { + assert_initialized_main_thread!(); let mut f = Self::new_empty(); for feature in features { diff --git a/gstreamer/src/caps_features_serde.rs b/gstreamer/src/caps_features_serde.rs index b60d2f292..5b7f8da5a 100644 --- a/gstreamer/src/caps_features_serde.rs +++ b/gstreamer/src/caps_features_serde.rs @@ -94,6 +94,7 @@ impl<'de> Visitor<'de> for CapsFeaturesSomeVisitor { impl<'de> Deserialize<'de> for CapsFeaturesSome { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); deserializer.deserialize_seq(CapsFeaturesSomeVisitor) } } @@ -131,6 +132,7 @@ impl<'de> Visitor<'de> for CapsFeaturesVariantKindsVisitor { impl<'de> Deserialize<'de> for CapsFeaturesVariantKinds { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); deserializer.deserialize_identifier(CapsFeaturesVariantKindsVisitor) } } @@ -157,6 +159,7 @@ impl<'de> Visitor<'de> for CapsFeaturesVisitor { impl<'de> Deserialize<'de> for CapsFeatures { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); deserializer.deserialize_enum( stringify!(Caps), CAPS_FEATURES_VARIANT_NAMES, diff --git a/gstreamer/src/caps_serde.rs b/gstreamer/src/caps_serde.rs index 0596a6467..4ffe32ce4 100644 --- a/gstreamer/src/caps_serde.rs +++ b/gstreamer/src/caps_serde.rs @@ -128,6 +128,7 @@ impl<'de> Visitor<'de> for CapsItemVisitor { impl<'de> Deserialize<'de> for CapsItemDe { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); deserializer.deserialize_tuple(2, CapsItemVisitor) } } @@ -156,6 +157,7 @@ impl<'de> Visitor<'de> for CapsSomeVisitor { impl<'de> Deserialize<'de> for CapsSome { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); deserializer.deserialize_seq(CapsSomeVisitor) } } @@ -192,6 +194,7 @@ impl<'de> Visitor<'de> for CapsVariantKindsVisitor { impl<'de> Deserialize<'de> for CapsVariantKinds { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); deserializer.deserialize_identifier(CapsVariantKindsVisitor) } } @@ -219,6 +222,7 @@ impl<'de> Visitor<'de> for CapsVisitor { impl<'de> Deserialize<'de> for Caps { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); deserializer.deserialize_enum(stringify!(Caps), CAPS_VARIANT_NAMES, CapsVisitor) } } diff --git a/gstreamer/src/clock.rs b/gstreamer/src/clock.rs index 1b7755585..c643a5284 100644 --- a/gstreamer/src/clock.rs +++ b/gstreamer/src/clock.rs @@ -188,6 +188,7 @@ impl Clock { cnum: ClockTime, cdenom: ClockTime, ) -> ClockTime { + skip_assert_initialized!(); unsafe { from_glib(gst_sys::gst_clock_adjust_with_calibration( ptr::null_mut(), @@ -207,6 +208,7 @@ impl Clock { cnum: ClockTime, cdenom: ClockTime, ) -> ClockTime { + skip_assert_initialized!(); unsafe { from_glib(gst_sys::gst_clock_unadjust_with_calibration( ptr::null_mut(), diff --git a/gstreamer/src/clock_time.rs b/gstreamer/src/clock_time.rs index 075274707..77da81925 100644 --- a/gstreamer/src/clock_time.rs +++ b/gstreamer/src/clock_time.rs @@ -44,18 +44,22 @@ impl ClockTime { } pub fn from_seconds(seconds: u64) -> ClockTime { + skip_assert_initialized!(); seconds * ::SECOND } pub fn from_mseconds(mseconds: u64) -> ClockTime { + skip_assert_initialized!(); mseconds * ::MSECOND } pub fn from_useconds(useconds: u64) -> ClockTime { + skip_assert_initialized!(); useconds * ::USECOND } pub fn from_nseconds(nseconds: u64) -> ClockTime { + skip_assert_initialized!(); nseconds * ::NSECOND } diff --git a/gstreamer/src/clock_time_serde.rs b/gstreamer/src/clock_time_serde.rs index 4ebf39d11..f7eb04006 100644 --- a/gstreamer/src/clock_time_serde.rs +++ b/gstreamer/src/clock_time_serde.rs @@ -45,6 +45,7 @@ impl<'de> Visitor<'de> for ClockTimeVisitor { impl<'de> Deserialize<'de> for ClockTime { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); deserializer.deserialize_option(ClockTimeVisitor) } } diff --git a/gstreamer/src/date_time.rs b/gstreamer/src/date_time.rs index 54ae7c77e..0e6caedef 100644 --- a/gstreamer/src/date_time.rs +++ b/gstreamer/src/date_time.rs @@ -89,6 +89,7 @@ impl cmp::PartialOrd for DateTime { fn partial_cmp(&self, other: &Self) -> Option { #[inline] fn get_cmp(delta: i32) -> Option { + skip_assert_initialized!(); Some(delta.cmp(&0)) } @@ -235,6 +236,7 @@ impl<'a> convert::TryFrom<&'a glib::DateTime> for DateTime { type Error = glib::BoolError; fn try_from(v: &'a glib::DateTime) -> Result { + skip_assert_initialized!(); DateTime::new_from_g_date_time(v) } } @@ -243,6 +245,7 @@ impl convert::TryFrom for DateTime { type Error = glib::BoolError; fn try_from(v: glib::DateTime) -> Result { + skip_assert_initialized!(); DateTime::new_from_g_date_time(&v) } } @@ -251,6 +254,7 @@ impl<'a> convert::TryFrom<&'a DateTime> for glib::DateTime { type Error = glib::BoolError; fn try_from(v: &'a DateTime) -> Result { + skip_assert_initialized!(); v.to_g_date_time() } } @@ -259,6 +263,7 @@ impl convert::TryFrom for glib::DateTime { type Error = glib::BoolError; fn try_from(v: DateTime) -> Result { + skip_assert_initialized!(); v.to_g_date_time() } } diff --git a/gstreamer/src/date_time_serde.rs b/gstreamer/src/date_time_serde.rs index 2f1ea2416..5b8c98860 100644 --- a/gstreamer/src/date_time_serde.rs +++ b/gstreamer/src/date_time_serde.rs @@ -34,6 +34,7 @@ pub(crate) struct Date(glib::Date); impl From for Date { fn from(glib_date: glib::Date) -> Self { + skip_assert_initialized!(); Date(glib_date) } } @@ -109,6 +110,7 @@ impl TryFrom for Date { type Error = &'static str; fn try_from(dt_variant: DateTimeVariants) -> Result { + skip_assert_initialized!(); match dt_variant { DateTimeVariants::YMD(y, m, d) => { let month = glib::DateMonth::from_glib(m); @@ -129,6 +131,7 @@ impl TryFrom for Date { impl<'de> Deserialize<'de> for Date { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); DateTimeVariants::deserialize(deserializer) .and_then(|dt_variant| dt_variant.try_into().map_err(D::Error::custom)) } @@ -139,6 +142,7 @@ impl TryFrom for DateTime { type Error = glib::BoolError; fn try_from(dt_variant: DateTimeVariants) -> Result { + skip_assert_initialized!(); match dt_variant { DateTimeVariants::Y(y) => DateTime::new_y(y), DateTimeVariants::YM(y, m) => DateTime::new_ym(y, m), @@ -155,6 +159,7 @@ impl TryFrom for DateTime { impl<'de> Deserialize<'de> for DateTime { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); DateTimeVariants::deserialize(deserializer) .and_then(|dt_variant| dt_variant.try_into().map_err(D::Error::custom)) } diff --git a/gstreamer/src/enums.rs b/gstreamer/src/enums.rs index 8eb0d3e31..d72a3adf2 100644 --- a/gstreamer/src/enums.rs +++ b/gstreamer/src/enums.rs @@ -33,10 +33,12 @@ impl StateChangeReturn { } pub fn from_error(_: StateChangeError) -> Self { + skip_assert_initialized!(); StateChangeReturn::Failure } pub fn from_ok(v: StateChangeSuccess) -> Self { + skip_assert_initialized!(); match v { StateChangeSuccess::Success => StateChangeReturn::Success, StateChangeSuccess::Async => StateChangeReturn::Async, @@ -54,6 +56,7 @@ pub enum StateChangeSuccess { impl From for StateChangeReturn { fn from(value: StateChangeSuccess) -> Self { + skip_assert_initialized!(); StateChangeReturn::from_ok(value) } } @@ -65,12 +68,14 @@ pub struct StateChangeError; impl From for StateChangeReturn { fn from(value: StateChangeError) -> Self { + skip_assert_initialized!(); StateChangeReturn::from_error(value) } } impl From> for StateChangeReturn { fn from(res: Result) -> Self { + skip_assert_initialized!(); match res { Ok(success) => StateChangeReturn::from_ok(success), Err(error) => StateChangeReturn::from_error(error), @@ -106,6 +111,7 @@ impl FlowReturn { } pub fn from_error(v: FlowError) -> Self { + skip_assert_initialized!(); match v { FlowError::NotLinked => FlowReturn::NotLinked, FlowError::Flushing => FlowReturn::Flushing, @@ -120,6 +126,7 @@ impl FlowReturn { } pub fn from_ok(v: FlowSuccess) -> Self { + skip_assert_initialized!(); match v { FlowSuccess::CustomSuccess2 => FlowReturn::CustomSuccess2, FlowSuccess::CustomSuccess1 => FlowReturn::CustomSuccess1, @@ -139,6 +146,7 @@ pub enum FlowSuccess { impl From for FlowReturn { fn from(value: FlowSuccess) -> Self { + skip_assert_initialized!(); FlowReturn::from_ok(value) } } @@ -168,12 +176,14 @@ pub enum FlowError { impl From for FlowReturn { fn from(value: FlowError) -> Self { + skip_assert_initialized!(); FlowReturn::from_error(value) } } impl From> for FlowReturn { fn from(res: Result) -> Self { + skip_assert_initialized!(); match res { Ok(success) => FlowReturn::from_ok(success), Err(error) => FlowReturn::from_error(error), @@ -196,6 +206,7 @@ impl PadLinkReturn { } pub fn from_error(v: PadLinkError) -> Self { + skip_assert_initialized!(); match v { PadLinkError::WrongHierarchy => PadLinkReturn::WrongHierarchy, PadLinkError::WasLinked => PadLinkReturn::WasLinked, @@ -207,6 +218,7 @@ impl PadLinkReturn { } pub fn from_ok(_: PadLinkSuccess) -> Self { + skip_assert_initialized!(); PadLinkReturn::Ok } } @@ -216,6 +228,7 @@ pub struct PadLinkSuccess; impl From for PadLinkReturn { fn from(value: PadLinkSuccess) -> Self { + skip_assert_initialized!(); PadLinkReturn::from_ok(value) } } @@ -239,12 +252,14 @@ pub enum PadLinkError { impl From for PadLinkReturn { fn from(value: PadLinkError) -> Self { + skip_assert_initialized!(); PadLinkReturn::from_error(value) } } impl From> for PadLinkReturn { fn from(res: Result) -> Self { + skip_assert_initialized!(); match res { Ok(success) => PadLinkReturn::from_ok(success), Err(error) => PadLinkReturn::from_error(error), @@ -268,6 +283,7 @@ impl ClockReturn { } pub fn from_error(v: ClockError) -> Self { + skip_assert_initialized!(); match v { ClockError::Early => ClockReturn::Early, ClockError::Unscheduled => ClockReturn::Unscheduled, @@ -279,6 +295,7 @@ impl ClockReturn { } pub fn from_ok(v: ClockSuccess) -> Self { + skip_assert_initialized!(); match v { ClockSuccess::Ok => ClockReturn::Ok, ClockSuccess::Done => ClockReturn::Done, @@ -294,6 +311,7 @@ pub enum ClockSuccess { impl From for ClockReturn { fn from(value: ClockSuccess) -> Self { + skip_assert_initialized!(); ClockReturn::from_ok(value) } } @@ -317,12 +335,14 @@ pub enum ClockError { impl From for ClockReturn { fn from(value: ClockError) -> Self { + skip_assert_initialized!(); ClockReturn::from_error(value) } } impl From> for ClockReturn { fn from(res: Result) -> Self { + skip_assert_initialized!(); match res { Ok(success) => ClockReturn::from_ok(success), Err(error) => ClockReturn::from_error(error), diff --git a/gstreamer/src/error.rs b/gstreamer/src/error.rs index 6aeb7c632..890a072cd 100644 --- a/gstreamer/src/error.rs +++ b/gstreamer/src/error.rs @@ -70,6 +70,7 @@ impl ErrorMessage { function: &'static str, line: u32, ) -> ErrorMessage { + assert_initialized_main_thread!(); let error_domain = T::domain(); let error_code = error.code(); @@ -122,6 +123,7 @@ pub struct LoggableError { impl LoggableError { pub fn new(category: ::DebugCategory, bool_error: glib::BoolError) -> LoggableError { + assert_initialized_main_thread!(); LoggableError { category, bool_error, @@ -157,6 +159,7 @@ impl LoggableError { impl From for LoggableError { fn from(bool_error: glib::BoolError) -> Self { + skip_assert_initialized!(); LoggableError { category: *::CAT_RUST, bool_error, diff --git a/gstreamer/src/format.rs b/gstreamer/src/format.rs index c4e2fbfbd..8df51739b 100644 --- a/gstreamer/src/format.rs +++ b/gstreamer/src/format.rs @@ -77,6 +77,7 @@ impl FormattedValue for GenericFormattedValue { impl GenericFormattedValue { pub fn new(format: Format, value: i64) -> Self { + skip_assert_initialized!(); match format { Format::Undefined => GenericFormattedValue::Undefined(Undefined(value)), Format::Default => GenericFormattedValue::Default(if value == -1 { @@ -298,6 +299,7 @@ macro_rules! impl_format_value_traits( impl From<$name> for GenericFormattedValue { fn from(v: $name) -> GenericFormattedValue { + skip_assert_initialized!(); GenericFormattedValue::$format_value(v) } } @@ -306,6 +308,7 @@ macro_rules! impl_format_value_traits( type Error = TryFromGenericFormattedValueError; fn try_from(v: GenericFormattedValue) -> Result<$name, TryFromGenericFormattedValueError> { + skip_assert_initialized!(); if let GenericFormattedValue::$format_value(v) = v { Ok(v) } else { @@ -318,12 +321,14 @@ macro_rules! impl_format_value_traits( impl From for $name { fn from(v: u64) -> $name { + skip_assert_initialized!(); $name(Some(v)) } } impl From> for $name { fn from(v: Option) -> $name { + skip_assert_initialized!(); $name(v) } } @@ -535,6 +540,7 @@ impl FormattedValue for Undefined { impl From for GenericFormattedValue { fn from(v: Undefined) -> GenericFormattedValue { + skip_assert_initialized!(); GenericFormattedValue::Undefined(v) } } @@ -543,6 +549,7 @@ impl TryFrom for Undefined { type Error = TryFromGenericFormattedValueError; fn try_from(v: GenericFormattedValue) -> Result { + skip_assert_initialized!(); if let GenericFormattedValue::Undefined(v) = v { Ok(v) } else { @@ -555,6 +562,7 @@ impl SpecificFormattedValue for Undefined {} impl From for Undefined { fn from(v: i64) -> Undefined { + skip_assert_initialized!(); Undefined(v) } } @@ -616,6 +624,7 @@ impl FormattedValue for Percent { impl From for GenericFormattedValue { fn from(v: Percent) -> GenericFormattedValue { + skip_assert_initialized!(); GenericFormattedValue::Percent(v) } } @@ -624,6 +633,7 @@ impl TryFrom for Percent { type Error = TryFromGenericFormattedValueError; fn try_from(v: GenericFormattedValue) -> Result { + skip_assert_initialized!(); if let GenericFormattedValue::Percent(v) = v { Ok(v) } else { @@ -675,6 +685,7 @@ impl TryFrom for Percent { type Error = TryPercentFromFloatError; fn try_from(v: f64) -> Result { + skip_assert_initialized!(); if v < 0.0 || v > 1.0 { Err(TryPercentFromFloatError(())) } else { @@ -689,6 +700,7 @@ impl TryFrom for Percent { type Error = TryPercentFromFloatError; fn try_from(v: f32) -> Result { + skip_assert_initialized!(); if v < 0.0 || v > 1.0 { Err(TryPercentFromFloatError(())) } else { diff --git a/gstreamer/src/format_serde.rs b/gstreamer/src/format_serde.rs index 430fc8b92..8f57c3b7d 100644 --- a/gstreamer/src/format_serde.rs +++ b/gstreamer/src/format_serde.rs @@ -24,6 +24,7 @@ macro_rules! impl_ser_de( impl<'de> Deserialize<'de> for $t { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); Option::::deserialize(deserializer).map($t) } } @@ -42,6 +43,7 @@ impl Serialize for Undefined { impl<'de> Deserialize<'de> for Undefined { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); i64::deserialize(deserializer).map(Undefined) } } @@ -54,6 +56,7 @@ impl Serialize for Percent { impl<'de> Deserialize<'de> for Percent { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); Option::::deserialize(deserializer).map(Percent) } } diff --git a/gstreamer/src/functions.rs b/gstreamer/src/functions.rs index bbd20fb7f..7650080dd 100644 --- a/gstreamer/src/functions.rs +++ b/gstreamer/src/functions.rs @@ -88,6 +88,7 @@ pub fn calculate_linear_regression( xy: &[(u64, u64)], temp: Option<&mut [(u64, u64)]>, ) -> Option<(u64, u64, u64, u64, f64)> { + skip_assert_initialized!(); use std::mem; unsafe { diff --git a/gstreamer/src/iterator.rs b/gstreamer/src/iterator.rs index dde226488..64ffaa4e1 100644 --- a/gstreamer/src/iterator.rs +++ b/gstreamer/src/iterator.rs @@ -178,6 +178,7 @@ where for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static, { pub fn new>(imp: I) -> Self { + assert_initialized_main_thread!(); static DUMMY_COOKIE: u32 = 0; unsafe { @@ -208,6 +209,7 @@ where for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Clone + Send + 'static, { pub fn from_vec(items: Vec) -> Self { + skip_assert_initialized!(); Self::new(VecIteratorImpl::new(items)) } } @@ -291,6 +293,7 @@ where for<'a> T: StaticType + ToValue + FromValueOptional<'a> + Clone + Send + 'static, { fn new(items: Vec) -> Self { + skip_assert_initialized!(); Self { pos: 0, items } } } @@ -616,6 +619,7 @@ pub struct StdIterator { impl StdIterator { fn new(inner: Iterator) -> Self { + skip_assert_initialized!(); Self { inner, error: None } } } diff --git a/gstreamer/src/log.rs b/gstreamer/src/log.rs index ea45bee7e..8771f89fd 100644 --- a/gstreamer/src/log.rs +++ b/gstreamer/src/log.rs @@ -51,6 +51,7 @@ pub struct DebugCategory(ptr::NonNull); impl DebugCategory { pub fn new(name: &str, color: ::DebugColorFlags, description: Option<&str>) -> DebugCategory { + assert_initialized_main_thread!(); extern "C" { fn _gst_debug_category_new( name: *const c_char, @@ -72,6 +73,7 @@ impl DebugCategory { } pub fn get(name: &str) -> Option { + skip_assert_initialized!(); unsafe { extern "C" { fn _gst_debug_get_category(name: *const c_char) -> *mut gst_sys::GstDebugCategory; @@ -364,6 +366,7 @@ where + Sync + 'static, { + skip_assert_initialized!(); unsafe { let user_data = Box::new(function); let user_data_ptr = Box::into_raw(user_data) as gpointer; @@ -377,12 +380,14 @@ where } pub fn debug_remove_default_log_function() { + skip_assert_initialized!(); unsafe { gst_sys::gst_debug_remove_log_function(Some(gst_sys::gst_debug_log_default)); } } pub fn debug_remove_log_function(log_fn: DebugLogFunction) { + skip_assert_initialized!(); unsafe { let removed = gst_sys::gst_debug_remove_log_function_by_data(log_fn.0.as_ptr()); assert_eq!(removed, 1); diff --git a/gstreamer/src/memory.rs b/gstreamer/src/memory.rs index 3ef920f12..3bec12c4b 100644 --- a/gstreamer/src/memory.rs +++ b/gstreamer/src/memory.rs @@ -65,6 +65,7 @@ impl Memory { } pub fn with_size(size: usize) -> Self { + assert_initialized_main_thread!(); unsafe { from_glib_full(gst_sys::gst_allocator_alloc( ptr::null_mut(), @@ -75,6 +76,7 @@ impl Memory { } pub fn with_size_and_params(size: usize, params: &AllocationParams) -> Self { + assert_initialized_main_thread!(); unsafe { from_glib_full(gst_sys::gst_allocator_alloc( ptr::null_mut(), diff --git a/gstreamer/src/meta.rs b/gstreamer/src/meta.rs index 2d30df2a9..374ccaedf 100644 --- a/gstreamer/src/meta.rs +++ b/gstreamer/src/meta.rs @@ -264,6 +264,7 @@ unsafe impl Sync for ParentBufferMeta {} impl ParentBufferMeta { pub fn add<'a>(buffer: &'a mut BufferRef, parent: &Buffer) -> MetaRefMut<'a, Self, Standalone> { + skip_assert_initialized!(); unsafe { let meta = gst_sys::gst_buffer_add_parent_buffer_meta( buffer.as_mut_ptr(), @@ -316,6 +317,7 @@ impl ReferenceTimestampMeta { timestamp: ClockTime, duration: ClockTime, ) -> MetaRefMut<'a, Self, Standalone> { + skip_assert_initialized!(); unsafe { let meta = gst_sys::gst_buffer_add_reference_timestamp_meta( buffer.as_mut_ptr(), diff --git a/gstreamer/src/miniobject.rs b/gstreamer/src/miniobject.rs index c1e79aad3..638826e85 100644 --- a/gstreamer/src/miniobject.rs +++ b/gstreamer/src/miniobject.rs @@ -25,6 +25,7 @@ pub struct GstRc { impl GstRc { pub unsafe fn from_glib_none(ptr: *const T::GstType) -> Self { + skip_assert_initialized!(); assert!(!ptr.is_null()); gst_sys::gst_mini_object_ref(ptr as *mut gst_sys::GstMiniObject); @@ -538,6 +539,7 @@ macro_rules! gst_define_mini_object_wrapper( impl From<$crate::GstRc<$ref_name>> for $name { fn from(rc: $crate::GstRc<$ref_name>) -> $name { + skip_assert_initialized!(); $name(rc) } } diff --git a/gstreamer/src/param_spec.rs b/gstreamer/src/param_spec.rs index 376940be6..e9c0b5aa6 100644 --- a/gstreamer/src/param_spec.rs +++ b/gstreamer/src/param_spec.rs @@ -40,6 +40,7 @@ impl GstParamSpecExt for glib::ParamSpec { element_spec: &glib::ParamSpec, flags: glib::ParamFlags, ) -> glib::ParamSpec { + assert_initialized_main_thread!(); unsafe { from_glib_full(gst_sys::gst_param_spec_array( name.to_glib_none().0, @@ -60,6 +61,7 @@ impl GstParamSpecExt for glib::ParamSpec { default: ::Fraction, flags: glib::ParamFlags, ) -> glib::ParamSpec { + assert_initialized_main_thread!(); unsafe { from_glib_full(gst_sys::gst_param_spec_fraction( name.to_glib_none().0, diff --git a/gstreamer/src/promise.rs b/gstreamer/src/promise.rs index 37540156a..cad623b79 100644 --- a/gstreamer/src/promise.rs +++ b/gstreamer/src/promise.rs @@ -44,6 +44,7 @@ impl Promise { where F: FnOnce(Result<&StructureRef, PromiseError>) + Send + 'static, { + assert_initialized_main_thread!(); let user_data: Box> = Box::new(Some(func)); unsafe extern "C" fn trampoline< diff --git a/gstreamer/src/query.rs b/gstreamer/src/query.rs index c73de40d3..625e49822 100644 --- a/gstreamer/src/query.rs +++ b/gstreamer/src/query.rs @@ -355,6 +355,7 @@ macro_rules! declare_concrete_query( impl From<$name> for Query { fn from(concrete: $name) -> Self { + skip_assert_initialized!(); unsafe { from_glib_none(concrete.0.as_mut_ptr()) } } } @@ -1319,6 +1320,7 @@ mod tests { ::init().unwrap(); fn check_mut(query: &mut QueryRef) { + skip_assert_initialized!(); match query.view_mut() { QueryView::Position(ref mut p) => { let pos = p.get_result(); @@ -1332,6 +1334,7 @@ mod tests { } fn check_ref(query: &QueryRef) { + skip_assert_initialized!(); match query.view() { QueryView::Position(ref p) => { let pos = p.get_result(); diff --git a/gstreamer/src/sample_serde.rs b/gstreamer/src/sample_serde.rs index a82806343..b4799adfc 100644 --- a/gstreamer/src/sample_serde.rs +++ b/gstreamer/src/sample_serde.rs @@ -46,6 +46,7 @@ struct SampleDe { impl From for Sample { fn from(buf_de: SampleDe) -> Self { + skip_assert_initialized!(); let mut builder = Sample::new(); if let Some(buffer) = buf_de.buffer.as_ref() { @@ -74,6 +75,7 @@ impl From for Sample { impl<'de> Deserialize<'de> for Sample { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); SampleDe::deserialize(deserializer).map(|sample_de| sample_de.into()) } } diff --git a/gstreamer/src/segment_serde.rs b/gstreamer/src/segment_serde.rs index 8ea85e700..0182034a4 100644 --- a/gstreamer/src/segment_serde.rs +++ b/gstreamer/src/segment_serde.rs @@ -56,6 +56,7 @@ impl Serialize for FormattedSegment { impl<'de> Deserialize<'de> for Segment { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); FormattedSegmentSerde::deserialize(deserializer).map(|fmt_seg_de| { let mut segment = Self::new(); segment.set_flags(fmt_seg_de.flags); @@ -98,6 +99,7 @@ impl<'de> Deserialize<'de> for Segment { impl<'de, T: FormattedValue + SpecificFormattedValue> Deserialize<'de> for FormattedSegment { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); Segment::deserialize(deserializer).and_then(|segment| { segment.downcast::().map_err(|segment| { de::Error::custom(format!( diff --git a/gstreamer/src/structure.rs b/gstreamer/src/structure.rs index 6a41a1e48..e98938954 100644 --- a/gstreamer/src/structure.rs +++ b/gstreamer/src/structure.rs @@ -44,10 +44,12 @@ pub enum GetError<'name> { impl<'name> GetError<'name> { fn new_field_not_found(name: &'name str) -> GetError { + skip_assert_initialized!(); GetError::FieldNotFound { name } } fn from_value_get_error(name: &'name str, value_get_error: glib::value::GetError) -> GetError { + skip_assert_initialized!(); GetError::ValueGetError { name, value_get_error, @@ -713,6 +715,7 @@ pub struct Builder { impl Builder { fn new(name: &str) -> Self { + skip_assert_initialized!(); Builder { s: Structure::new_empty(name), } diff --git a/gstreamer/src/structure_serde.rs b/gstreamer/src/structure_serde.rs index 61966e6a0..1d90ead74 100644 --- a/gstreamer/src/structure_serde.rs +++ b/gstreamer/src/structure_serde.rs @@ -76,6 +76,7 @@ impl Serialize for Structure { struct FieldDe(String, SendValue); impl From for (String, glib::SendValue) { fn from(field_de: FieldDe) -> Self { + skip_assert_initialized!(); (field_de.0, field_de.1.into()) } } @@ -105,6 +106,7 @@ impl<'de> Visitor<'de> for FieldVisitor { impl<'de> Deserialize<'de> for FieldDe { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); deserializer.deserialize_tuple(3, FieldVisitor) } } @@ -133,6 +135,7 @@ impl<'de, 'a> DeserializeSeed<'de> for FieldsDe<'a> { type Value = (); fn deserialize>(self, deserializer: D) -> Result<(), D::Error> { + skip_assert_initialized!(); deserializer.deserialize_seq(FieldsVisitor(self.0)) } } @@ -159,6 +162,7 @@ impl<'de> Visitor<'de> for StructureVisitor { impl<'de> Deserialize<'de> for Structure { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); deserializer.deserialize_tuple(2, StructureVisitor) } } diff --git a/gstreamer/src/tags.rs b/gstreamer/src/tags.rs index b8effe643..e82439ae1 100644 --- a/gstreamer/src/tags.rs +++ b/gstreamer/src/tags.rs @@ -789,14 +789,17 @@ impl<'a> DoubleEndedIterator for Iter<'a> { impl<'a> ExactSizeIterator for Iter<'a> {} pub fn tag_exists(name: &str) -> bool { + skip_assert_initialized!(); unsafe { from_glib(gst_sys::gst_tag_exists(name.to_glib_none().0)) } } pub fn tag_get_type(name: &str) -> glib::Type { + skip_assert_initialized!(); unsafe { from_glib(gst_sys::gst_tag_get_type(name.to_glib_none().0)) } } pub fn tag_get_nick(name: &str) -> Option<&'static str> { + skip_assert_initialized!(); unsafe { let ptr = gst_sys::gst_tag_get_nick(name.to_glib_none().0); @@ -809,6 +812,7 @@ pub fn tag_get_nick(name: &str) -> Option<&'static str> { } pub fn tag_get_description(name: &str) -> Option<&'static str> { + skip_assert_initialized!(); unsafe { let ptr = gst_sys::gst_tag_get_description(name.to_glib_none().0); @@ -821,6 +825,7 @@ pub fn tag_get_description(name: &str) -> Option<&'static str> { } pub fn tag_get_flag(name: &str) -> ::TagFlag { + skip_assert_initialized!(); unsafe { from_glib(gst_sys::gst_tag_get_flag(name.to_glib_none().0)) } } @@ -830,6 +835,7 @@ pub trait CustomTag<'a>: Tag<'a> { const DESCRIPTION: &'static str; fn merge_func(src: &Value) -> Value { + skip_assert_initialized!(); merge_use_first(src) } } @@ -857,6 +863,7 @@ pub fn register CustomTag<'a>>() { } pub fn merge_use_first(src: &Value) -> Value { + skip_assert_initialized!(); assert_eq!(src.type_(), ::List::static_type()); unsafe { @@ -869,6 +876,7 @@ pub fn merge_use_first(src: &Value) -> Value { } pub fn merge_strings_with_comma(src: &Value) -> Value { + skip_assert_initialized!(); assert_eq!(src.type_(), ::List::static_type()); unsafe { @@ -1064,6 +1072,7 @@ mod tests { const DESCRIPTION: &'static str = "My own custom tag type for testing"; fn merge_func(src: &Value) -> Value { + skip_assert_initialized!(); merge_strings_with_comma(src) } } diff --git a/gstreamer/src/tags_serde.rs b/gstreamer/src/tags_serde.rs index 46ed1903c..761291a67 100644 --- a/gstreamer/src/tags_serde.rs +++ b/gstreamer/src/tags_serde.rs @@ -52,6 +52,7 @@ macro_rules! ser_opt_tag ( struct TagValuesSer<'a>(Rc>>); impl<'a> TagValuesSer<'a> { fn from(tags_ser: &TagsSer<'a>) -> Self { + skip_assert_initialized!(); TagValuesSer(Rc::clone(&tags_ser.1)) } } @@ -107,6 +108,7 @@ impl<'a> Serialize for TagValuesSer<'a> { struct TagsSer<'a>(&'a str, Rc>>); impl<'a> TagsSer<'a> { fn new(name: &'a str, tag_iter: GenericTagIter<'a>) -> Self { + skip_assert_initialized!(); TagsSer(name, Rc::new(RefCell::new(tag_iter))) } } @@ -238,6 +240,7 @@ impl<'de, 'a> DeserializeSeed<'de> for TagValues<'a> { type Value = (); fn deserialize>(self, deserializer: D) -> Result<(), D::Error> { + skip_assert_initialized!(); deserializer.deserialize_seq(TagValuesVisitor(self.0, self.1)) } } @@ -267,6 +270,7 @@ impl<'de, 'a> DeserializeSeed<'de> for TagValuesTuple<'a> { type Value = (); fn deserialize>(self, deserializer: D) -> Result<(), D::Error> { + skip_assert_initialized!(); deserializer.deserialize_tuple(2, TagValuesTupleVisitor(self.0)) } } @@ -295,6 +299,7 @@ impl<'de> Visitor<'de> for TagsVisitor { impl<'de> Deserialize<'de> for TagsDe { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); deserializer.deserialize_seq(TagsVisitor) } } @@ -307,6 +312,7 @@ struct TagListDe { impl From for TagList { fn from(tag_list_de: TagListDe) -> Self { + skip_assert_initialized!(); let mut tag_list = tag_list_de.tags.0; tag_list.get_mut().unwrap().set_scope(tag_list_de.scope); @@ -316,6 +322,7 @@ impl From for TagList { impl<'de> Deserialize<'de> for TagList { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); TagListDe::deserialize(deserializer).map(|tag_list_de| tag_list_de.into()) } } diff --git a/gstreamer/src/toc_serde.rs b/gstreamer/src/toc_serde.rs index da525b29f..73bcbea79 100644 --- a/gstreamer/src/toc_serde.rs +++ b/gstreamer/src/toc_serde.rs @@ -59,6 +59,7 @@ struct TocDe { impl From for Toc { fn from(mut toc_de: TocDe) -> Self { + skip_assert_initialized!(); let mut toc = Toc::new(toc_de.scope); { let toc = toc.get_mut().unwrap(); @@ -76,6 +77,7 @@ impl From for Toc { impl<'de> Deserialize<'de> for Toc { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); TocDe::deserialize(deserializer).map(|toc_de| toc_de.into()) } } @@ -93,6 +95,7 @@ struct TocEntryDe { impl From for TocEntry { fn from(mut toc_entry_de: TocEntryDe) -> Self { + skip_assert_initialized!(); let mut toc_entry = TocEntry::new(toc_entry_de.entry_type, toc_entry_de.uid.as_str()); { let toc_entry = toc_entry.get_mut().unwrap(); @@ -117,6 +120,7 @@ impl From for TocEntry { impl<'de> Deserialize<'de> for TocEntry { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); TocEntryDe::deserialize(deserializer).map(|toc_entry_de| toc_entry_de.into()) } } diff --git a/gstreamer/src/typefind.rs b/gstreamer/src/typefind.rs index a062fdec2..00651aee0 100644 --- a/gstreamer/src/typefind.rs +++ b/gstreamer/src/typefind.rs @@ -44,6 +44,7 @@ impl<'a> TypeFind<'a> { where F: Fn(&mut TypeFind) + Send + Sync + 'static, { + assert_initialized_main_thread!(); unsafe { let func: Box = Box::new(func); let func = Box::into_raw(func); @@ -160,6 +161,7 @@ pub struct SliceTypeFind> { impl> SliceTypeFind { pub fn new(data: T) -> SliceTypeFind { + assert_initialized_main_thread!(); SliceTypeFind { probability: None, caps: None, @@ -181,6 +183,7 @@ impl> SliceTypeFind { } pub fn type_find(data: T) -> (TypeFindProbability, Option) { + assert_initialized_main_thread!(); let mut t = SliceTypeFind { probability: None, caps: None, diff --git a/gstreamer/src/utils.rs b/gstreamer/src/utils.rs index ff456cd06..d4308fb51 100644 --- a/gstreamer/src/utils.rs +++ b/gstreamer/src/utils.rs @@ -15,6 +15,7 @@ pub struct MutexGuard<'a>(&'a glib_sys::GMutex); impl<'a> MutexGuard<'a> { #[allow(clippy::trivially_copy_pass_by_ref)] pub fn lock(mutex: &'a glib_sys::GMutex) -> Self { + skip_assert_initialized!(); unsafe { glib_sys::g_mutex_lock(mut_override(mutex)); } diff --git a/gstreamer/src/value_serde.rs b/gstreamer/src/value_serde.rs index 8186b90e5..dd857ef14 100644 --- a/gstreamer/src/value_serde.rs +++ b/gstreamer/src/value_serde.rs @@ -57,6 +57,7 @@ impl<'a> Serialize for Fraction { impl<'de> Deserialize<'de> for Fraction { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); Rational32::deserialize(deserializer) .map(|rational| Fraction::new(*rational.numer(), *rational.denom())) } @@ -143,12 +144,14 @@ macro_rules! ser_value ( pub(crate) struct SendValue(glib::SendValue); impl SendValue { pub(crate) fn from(send_value: glib::SendValue) -> Self { + skip_assert_initialized!(); SendValue(send_value) } } impl From for glib::SendValue { fn from(send_value: SendValue) -> Self { + skip_assert_initialized!(); send_value.0 } } @@ -279,6 +282,7 @@ impl<'de> Visitor<'de> for SendValueVisitor { impl<'de> Deserialize<'de> for SendValue { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); deserializer.deserialize_tuple(2, SendValueVisitor {}) } } @@ -287,6 +291,7 @@ macro_rules! impl_de_send_value_collection ( ($t:ident) => { impl<'a, 'de> Deserialize<'de> for $t<'a> { fn deserialize>(deserializer: D) -> Result { + skip_assert_initialized!(); let send_value_vec = Vec::::deserialize(deserializer)?; Ok($t::from_owned(unsafe{ mem::transmute::, Vec>(send_value_vec)