From e43bf21ded443f23968e3b3e73b9dd29bbc6897e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 10 Jul 2017 12:36:15 +0300 Subject: [PATCH] Add initialization safety assertions Ensure that GStreamer is initialized before allowing to call any functions --- Gir_Gst.toml | 1 + gstreamer/src/auto/bin.rs | 1 + gstreamer/src/auto/bus.rs | 1 + gstreamer/src/auto/device_monitor.rs | 1 + gstreamer/src/auto/device_provider.rs | 1 + gstreamer/src/auto/device_provider_factory.rs | 2 + gstreamer/src/auto/element.rs | 4 ++ gstreamer/src/auto/element_factory.rs | 2 + gstreamer/src/auto/enums.rs | 34 ++++++++++++ gstreamer/src/auto/flags.rs | 3 ++ gstreamer/src/auto/functions.rs | 53 +++++++++++++++++++ gstreamer/src/auto/object.rs | 1 + gstreamer/src/auto/pad.rs | 3 ++ gstreamer/src/auto/pipeline.rs | 1 + gstreamer/src/auto/plugin.rs | 3 ++ gstreamer/src/auto/stream_collection.rs | 1 + gstreamer/src/lib.rs | 11 ++++ gstreamer/src/message.rs | 1 + gstreamer/src/structure.rs | 3 ++ 19 files changed, 127 insertions(+) diff --git a/Gir_Gst.toml b/Gir_Gst.toml index 52b2c677f..e198dea2b 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -6,6 +6,7 @@ min_cfg_version = "1.8" target_path = "gstreamer" work_mode = "normal" concurrency = "send+sync" +generate_safety_asserts = true external_libraries = [ "GLib", diff --git a/gstreamer/src/auto/bin.rs b/gstreamer/src/auto/bin.rs index 74f6e9d75..ee65abe33 100644 --- a/gstreamer/src/auto/bin.rs +++ b/gstreamer/src/auto/bin.rs @@ -27,6 +27,7 @@ glib_wrapper! { impl Bin { pub fn new<'a, P: Into>>(name: P) -> Bin { + assert_initialized_main_thread!(); let name = name.into(); let name = name.to_glib_none(); unsafe { diff --git a/gstreamer/src/auto/bus.rs b/gstreamer/src/auto/bus.rs index fe19ef997..435c8c1bc 100644 --- a/gstreamer/src/auto/bus.rs +++ b/gstreamer/src/auto/bus.rs @@ -21,6 +21,7 @@ glib_wrapper! { impl Bus { pub fn new() -> Bus { + assert_initialized_main_thread!(); unsafe { from_glib_full(ffi::gst_bus_new()) } diff --git a/gstreamer/src/auto/device_monitor.rs b/gstreamer/src/auto/device_monitor.rs index 0bf90e5ac..229ca7497 100644 --- a/gstreamer/src/auto/device_monitor.rs +++ b/gstreamer/src/auto/device_monitor.rs @@ -21,6 +21,7 @@ glib_wrapper! { impl DeviceMonitor { pub fn new() -> DeviceMonitor { + assert_initialized_main_thread!(); unsafe { from_glib_full(ffi::gst_device_monitor_new()) } diff --git a/gstreamer/src/auto/device_provider.rs b/gstreamer/src/auto/device_provider.rs index 8bfd5d9b6..23759126c 100644 --- a/gstreamer/src/auto/device_provider.rs +++ b/gstreamer/src/auto/device_provider.rs @@ -27,6 +27,7 @@ glib_wrapper! { impl DeviceProvider { pub fn register<'a, P: Into>>(plugin: P, name: &str, rank: u32, type_: glib::types::Type) -> bool { + assert_initialized_main_thread!(); let plugin = plugin.into(); let plugin = plugin.to_glib_none(); unsafe { diff --git a/gstreamer/src/auto/device_provider_factory.rs b/gstreamer/src/auto/device_provider_factory.rs index f494c08ea..650edcf46 100644 --- a/gstreamer/src/auto/device_provider_factory.rs +++ b/gstreamer/src/auto/device_provider_factory.rs @@ -18,12 +18,14 @@ glib_wrapper! { impl DeviceProviderFactory { pub fn find(name: &str) -> Option { + assert_initialized_main_thread!(); unsafe { from_glib_full(ffi::gst_device_provider_factory_find(name.to_glib_none().0)) } } pub fn get_by_name(factoryname: &str) -> Option { + assert_initialized_main_thread!(); unsafe { from_glib_full(ffi::gst_device_provider_factory_get_by_name(factoryname.to_glib_none().0)) } diff --git a/gstreamer/src/auto/element.rs b/gstreamer/src/auto/element.rs index 4fcbb7d91..d1ada6d09 100644 --- a/gstreamer/src/auto/element.rs +++ b/gstreamer/src/auto/element.rs @@ -42,6 +42,7 @@ glib_wrapper! { impl Element { pub fn make_from_uri<'a, P: Into>>(type_: URIType, uri: &str, elementname: P) -> Result { + assert_initialized_main_thread!(); let elementname = elementname.into(); let elementname = elementname.to_glib_none(); unsafe { @@ -52,6 +53,7 @@ impl Element { } pub fn register<'a, P: Into>>(plugin: P, name: &str, rank: u32, type_: glib::types::Type) -> bool { + assert_initialized_main_thread!(); let plugin = plugin.into(); let plugin = plugin.to_glib_none(); unsafe { @@ -60,12 +62,14 @@ impl Element { } pub fn state_change_return_get_name(state_ret: StateChangeReturn) -> Option { + assert_initialized_main_thread!(); unsafe { from_glib_none(ffi::gst_element_state_change_return_get_name(state_ret.to_glib())) } } pub fn state_get_name(state: State) -> Option { + assert_initialized_main_thread!(); unsafe { from_glib_none(ffi::gst_element_state_get_name(state.to_glib())) } diff --git a/gstreamer/src/auto/element_factory.rs b/gstreamer/src/auto/element_factory.rs index 9cbca900c..df909c9d8 100644 --- a/gstreamer/src/auto/element_factory.rs +++ b/gstreamer/src/auto/element_factory.rs @@ -95,6 +95,7 @@ impl ElementFactory { } pub fn find(name: &str) -> Option { + assert_initialized_main_thread!(); unsafe { from_glib_full(ffi::gst_element_factory_find(name.to_glib_none().0)) } @@ -109,6 +110,7 @@ impl ElementFactory { //} pub fn make<'a, P: Into>>(factoryname: &str, name: P) -> Option { + assert_initialized_main_thread!(); let name = name.into(); let name = name.to_glib_none(); unsafe { diff --git a/gstreamer/src/auto/enums.rs b/gstreamer/src/auto/enums.rs index 876fb9cbd..abbdb2817 100644 --- a/gstreamer/src/auto/enums.rs +++ b/gstreamer/src/auto/enums.rs @@ -35,6 +35,7 @@ impl ToGlib for BufferingMode { #[doc(hidden)] impl FromGlib for BufferingMode { fn from_glib(value: ffi::GstBufferingMode) -> Self { + skip_assert_initialized!(); match value as i32 { 0 => BufferingMode::Stream, 1 => BufferingMode::Download, @@ -95,6 +96,7 @@ impl ToGlib for CoreError { #[doc(hidden)] impl FromGlib for CoreError { fn from_glib(value: ffi::GstCoreError) -> Self { + skip_assert_initialized!(); match value as i32 { 1 => CoreError::Failed, 2 => CoreError::TooLazy, @@ -118,6 +120,7 @@ impl FromGlib for CoreError { impl ErrorDomain for CoreError { fn domain() -> glib_ffi::GQuark { + skip_assert_initialized!(); unsafe { ffi::gst_core_error_quark() } } @@ -126,6 +129,7 @@ impl ErrorDomain for CoreError { } fn from(code: i32) -> Option { + skip_assert_initialized!(); match code { 1 => Some(CoreError::Failed), 2 => Some(CoreError::TooLazy), @@ -193,6 +197,7 @@ impl ToGlib for FlowReturn { #[doc(hidden)] impl FromGlib for FlowReturn { fn from_glib(value: ffi::GstFlowReturn) -> Self { + skip_assert_initialized!(); match value as i32 { 102 => FlowReturn::CustomSuccess2, 101 => FlowReturn::CustomSuccess1, @@ -244,6 +249,7 @@ impl ToGlib for Format { #[doc(hidden)] impl FromGlib for Format { fn from_glib(value: ffi::GstFormat) -> Self { + skip_assert_initialized!(); match value as i32 { 0 => Format::Undefined, 1 => Format::Default, @@ -290,6 +296,7 @@ impl ToGlib for LibraryError { #[doc(hidden)] impl FromGlib for LibraryError { fn from_glib(value: ffi::GstLibraryError) -> Self { + skip_assert_initialized!(); match value as i32 { 1 => LibraryError::Failed, 2 => LibraryError::TooLazy, @@ -305,6 +312,7 @@ impl FromGlib for LibraryError { impl ErrorDomain for LibraryError { fn domain() -> glib_ffi::GQuark { + skip_assert_initialized!(); unsafe { ffi::gst_library_error_quark() } } @@ -313,6 +321,7 @@ impl ErrorDomain for LibraryError { } fn from(code: i32) -> Option { + skip_assert_initialized!(); match code { 1 => Some(LibraryError::Failed), 2 => Some(LibraryError::TooLazy), @@ -352,6 +361,7 @@ impl ToGlib for PadDirection { #[doc(hidden)] impl FromGlib for PadDirection { fn from_glib(value: ffi::GstPadDirection) -> Self { + skip_assert_initialized!(); match value as i32 { 0 => PadDirection::Unknown, 1 => PadDirection::Src, @@ -395,6 +405,7 @@ impl ToGlib for PadLinkReturn { #[doc(hidden)] impl FromGlib for PadLinkReturn { fn from_glib(value: ffi::GstPadLinkReturn) -> Self { + skip_assert_initialized!(); match value as i32 { 0 => PadLinkReturn::Ok, -1 => PadLinkReturn::WrongHierarchy, @@ -444,6 +455,7 @@ impl ToGlib for ParseError { #[doc(hidden)] impl FromGlib for ParseError { fn from_glib(value: ffi::GstParseError) -> Self { + skip_assert_initialized!(); match value as i32 { 0 => ParseError::Syntax, 1 => ParseError::NoSuchElement, @@ -460,6 +472,7 @@ impl FromGlib for ParseError { impl ErrorDomain for ParseError { fn domain() -> glib_ffi::GQuark { + skip_assert_initialized!(); unsafe { ffi::gst_parse_error_quark() } } @@ -468,6 +481,7 @@ impl ErrorDomain for ParseError { } fn from(code: i32) -> Option { + skip_assert_initialized!(); match code { 0 => Some(ParseError::Syntax), 1 => Some(ParseError::NoSuchElement), @@ -508,6 +522,7 @@ impl ToGlib for PluginError { #[doc(hidden)] impl FromGlib for PluginError { fn from_glib(value: ffi::GstPluginError) -> Self { + skip_assert_initialized!(); match value as i32 { 0 => PluginError::Module, 1 => PluginError::Dependencies, @@ -519,6 +534,7 @@ impl FromGlib for PluginError { impl ErrorDomain for PluginError { fn domain() -> glib_ffi::GQuark { + skip_assert_initialized!(); unsafe { ffi::gst_plugin_error_quark() } } @@ -527,6 +543,7 @@ impl ErrorDomain for PluginError { } fn from(code: i32) -> Option { + skip_assert_initialized!(); match code { 0 => Some(PluginError::Module), 1 => Some(PluginError::Dependencies), @@ -566,6 +583,7 @@ impl ToGlib for ProgressType { #[doc(hidden)] impl FromGlib for ProgressType { fn from_glib(value: ffi::GstProgressType) -> Self { + skip_assert_initialized!(); match value as i32 { 0 => ProgressType::Start, 1 => ProgressType::Continue, @@ -629,6 +647,7 @@ impl ToGlib for ResourceError { #[doc(hidden)] impl FromGlib for ResourceError { fn from_glib(value: ffi::GstResourceError) -> Self { + skip_assert_initialized!(); match value as i32 { 1 => ResourceError::Failed, 2 => ResourceError::TooLazy, @@ -653,6 +672,7 @@ impl FromGlib for ResourceError { impl ErrorDomain for ResourceError { fn domain() -> glib_ffi::GQuark { + skip_assert_initialized!(); unsafe { ffi::gst_resource_error_quark() } } @@ -661,6 +681,7 @@ impl ErrorDomain for ResourceError { } fn from(code: i32) -> Option { + skip_assert_initialized!(); match code { 1 => Some(ResourceError::Failed), 2 => Some(ResourceError::TooLazy), @@ -709,6 +730,7 @@ impl ToGlib for SeekType { #[doc(hidden)] impl FromGlib for SeekType { fn from_glib(value: ffi::GstSeekType) -> Self { + skip_assert_initialized!(); match value as i32 { 0 => SeekType::None, 1 => SeekType::Set, @@ -748,6 +770,7 @@ impl ToGlib for State { #[doc(hidden)] impl FromGlib for State { fn from_glib(value: ffi::GstState) -> Self { + skip_assert_initialized!(); match value as i32 { 0 => State::VoidPending, 1 => State::Null, @@ -791,6 +814,7 @@ impl ToGlib for StateChange { #[doc(hidden)] impl FromGlib for StateChange { fn from_glib(value: ffi::GstStateChange) -> Self { + skip_assert_initialized!(); match value as i32 { 10 => StateChange::NullToReady, 19 => StateChange::ReadyToPaused, @@ -831,6 +855,7 @@ impl ToGlib for StateChangeReturn { #[doc(hidden)] impl FromGlib for StateChangeReturn { fn from_glib(value: ffi::GstStateChangeReturn) -> Self { + skip_assert_initialized!(); match value as i32 { 0 => StateChangeReturn::Failure, 1 => StateChangeReturn::Success, @@ -889,6 +914,7 @@ impl ToGlib for StreamError { #[doc(hidden)] impl FromGlib for StreamError { fn from_glib(value: ffi::GstStreamError) -> Self { + skip_assert_initialized!(); match value as i32 { 1 => StreamError::Failed, 2 => StreamError::TooLazy, @@ -911,6 +937,7 @@ impl FromGlib for StreamError { impl ErrorDomain for StreamError { fn domain() -> glib_ffi::GQuark { + skip_assert_initialized!(); unsafe { ffi::gst_stream_error_quark() } } @@ -919,6 +946,7 @@ impl ErrorDomain for StreamError { } fn from(code: i32) -> Option { + skip_assert_initialized!(); match code { 1 => Some(StreamError::Failed), 2 => Some(StreamError::TooLazy), @@ -973,6 +1001,7 @@ impl ToGlib for StreamStatusType { #[doc(hidden)] impl FromGlib for StreamStatusType { fn from_glib(value: ffi::GstStreamStatusType) -> Self { + skip_assert_initialized!(); match value as i32 { 0 => StreamStatusType::Create, 1 => StreamStatusType::Enter, @@ -1010,6 +1039,7 @@ impl ToGlib for StructureChangeType { #[doc(hidden)] impl FromGlib for StructureChangeType { fn from_glib(value: ffi::GstStructureChangeType) -> Self { + skip_assert_initialized!(); match value as i32 { 0 => StructureChangeType::Link, 1 => StructureChangeType::Unlink, @@ -1046,6 +1076,7 @@ impl ToGlib for URIError { #[doc(hidden)] impl FromGlib for URIError { fn from_glib(value: ffi::GstURIError) -> Self { + skip_assert_initialized!(); match value as i32 { 0 => URIError::UnsupportedProtocol, 1 => URIError::BadUri, @@ -1058,6 +1089,7 @@ impl FromGlib for URIError { impl ErrorDomain for URIError { fn domain() -> glib_ffi::GQuark { + skip_assert_initialized!(); unsafe { ffi::gst_uri_error_quark() } } @@ -1066,6 +1098,7 @@ impl ErrorDomain for URIError { } fn from(code: i32) -> Option { + skip_assert_initialized!(); match code { 0 => Some(URIError::UnsupportedProtocol), 1 => Some(URIError::BadUri), @@ -1102,6 +1135,7 @@ impl ToGlib for URIType { #[doc(hidden)] impl FromGlib for URIType { fn from_glib(value: ffi::GstURIType) -> Self { + skip_assert_initialized!(); match value as i32 { 0 => URIType::Unknown, 1 => URIType::Sink, diff --git a/gstreamer/src/auto/flags.rs b/gstreamer/src/auto/flags.rs index 6c37c7e00..9e76d53c4 100644 --- a/gstreamer/src/auto/flags.rs +++ b/gstreamer/src/auto/flags.rs @@ -33,6 +33,7 @@ impl ToGlib for SeekFlags { #[doc(hidden)] impl FromGlib for SeekFlags { fn from_glib(value: ffi::GstSeekFlags) -> SeekFlags { + skip_assert_initialized!(); SeekFlags::from_bits_truncate(value.bits()) } } @@ -58,6 +59,7 @@ impl ToGlib for StreamFlags { #[doc(hidden)] impl FromGlib for StreamFlags { fn from_glib(value: ffi::GstStreamFlags) -> StreamFlags { + skip_assert_initialized!(); StreamFlags::from_bits_truncate(value.bits()) } } @@ -84,6 +86,7 @@ impl ToGlib for StreamType { #[doc(hidden)] impl FromGlib for StreamType { fn from_glib(value: ffi::GstStreamType) -> StreamType { + skip_assert_initialized!(); StreamType::from_bits_truncate(value.bits()) } } diff --git a/gstreamer/src/auto/functions.rs b/gstreamer/src/auto/functions.rs index 4f386a31b..fd135b788 100644 --- a/gstreamer/src/auto/functions.rs +++ b/gstreamer/src/auto/functions.rs @@ -16,6 +16,7 @@ use std::ptr; #[cfg(feature = "v1_12")] pub fn calculate_linear_regression(xy: ClockTime, temp: ClockTime, n: u32) -> Option<(ClockTime, ClockTime, ClockTime, ClockTime, f64)> { + assert_initialized_main_thread!(); unsafe { let mut m_num = mem::uninitialized(); let mut m_denom = mem::uninitialized(); @@ -44,12 +45,14 @@ pub fn calculate_linear_regression(xy: ClockTime, temp: ClockTime, n: u32) -> Op //} pub fn debug_construct_term_color(colorinfo: u32) -> Option { + assert_initialized_main_thread!(); unsafe { from_glib_full(ffi::gst_debug_construct_term_color(colorinfo)) } } pub fn debug_construct_win_color(colorinfo: u32) -> i32 { + assert_initialized_main_thread!(); unsafe { ffi::gst_debug_construct_win_color(colorinfo) } @@ -73,12 +76,14 @@ pub fn debug_construct_win_color(colorinfo: u32) -> i32 { //} pub fn debug_is_active() -> bool { + assert_initialized_main_thread!(); unsafe { from_glib(ffi::gst_debug_is_active()) } } pub fn debug_is_colored() -> bool { + assert_initialized_main_thread!(); unsafe { from_glib(ffi::gst_debug_is_colored()) } @@ -97,6 +102,7 @@ pub fn debug_is_colored() -> bool { //} pub fn debug_print_stack_trace() { + assert_initialized_main_thread!(); unsafe { ffi::gst_debug_print_stack_trace(); } @@ -111,6 +117,7 @@ pub fn debug_print_stack_trace() { //} pub fn debug_set_active(active: bool) { + assert_initialized_main_thread!(); unsafe { ffi::gst_debug_set_active(active.to_glib()); } @@ -121,12 +128,14 @@ pub fn debug_set_active(active: bool) { //} pub fn debug_set_color_mode_from_string(mode: &str) { + assert_initialized_main_thread!(); unsafe { ffi::gst_debug_set_color_mode_from_string(mode.to_glib_none().0); } } pub fn debug_set_colored(colored: bool) { + assert_initialized_main_thread!(); unsafe { ffi::gst_debug_set_colored(colored.to_glib()); } @@ -141,24 +150,28 @@ pub fn debug_set_colored(colored: bool) { //} pub fn debug_set_threshold_from_string(list: &str, reset: bool) { + assert_initialized_main_thread!(); unsafe { ffi::gst_debug_set_threshold_from_string(list.to_glib_none().0, reset.to_glib()); } } pub fn debug_unset_threshold_for_name(name: &str) { + assert_initialized_main_thread!(); unsafe { ffi::gst_debug_unset_threshold_for_name(name.to_glib_none().0); } } pub fn deinit() { + assert_initialized_main_thread!(); unsafe { ffi::gst_deinit(); } } pub fn dynamic_type_register(plugin: &Plugin, type_: glib::types::Type) -> bool { + skip_assert_initialized!(); unsafe { from_glib(ffi::gst_dynamic_type_register(plugin.to_glib_none().0, type_.to_glib())) } @@ -169,6 +182,7 @@ pub fn dynamic_type_register(plugin: &Plugin, type_: glib::types::Type) -> bool //} pub fn filename_to_uri(filename: &str) -> Result { + assert_initialized_main_thread!(); unsafe { let mut error = ptr::null_mut(); let ret = ffi::gst_filename_to_uri(filename.to_glib_none().0, &mut error); @@ -177,6 +191,7 @@ pub fn filename_to_uri(filename: &str) -> Result { } pub fn flow_get_name(ret: FlowReturn) -> Option { + assert_initialized_main_thread!(); unsafe { from_glib_none(ffi::gst_flow_get_name(ret.to_glib())) } @@ -219,6 +234,7 @@ pub fn flow_get_name(ret: FlowReturn) -> Option { //} pub fn is_initialized() -> bool { + assert_initialized_main_thread!(); unsafe { from_glib(ffi::gst_is_initialized()) } @@ -237,12 +253,14 @@ pub fn is_initialized() -> bool { //} pub fn parent_buffer_meta_api_get_type() -> glib::types::Type { + assert_initialized_main_thread!(); unsafe { from_glib(ffi::gst_parent_buffer_meta_api_get_type()) } } pub fn parse_bin_from_description(bin_description: &str, ghost_unlinked_pads: bool) -> Result, Error> { + assert_initialized_main_thread!(); unsafe { let mut error = ptr::null_mut(); let ret = ffi::gst_parse_bin_from_description(bin_description.to_glib_none().0, ghost_unlinked_pads.to_glib(), &mut error); @@ -255,6 +273,7 @@ pub fn parse_bin_from_description(bin_description: &str, ghost_unlinked_pads: bo //} pub fn parse_launch(pipeline_description: &str) -> Result { + assert_initialized_main_thread!(); unsafe { let mut error = ptr::null_mut(); let ret = ffi::gst_parse_launch(pipeline_description.to_glib_none().0, &mut error); @@ -267,6 +286,7 @@ pub fn parse_launch(pipeline_description: &str) -> Result { //} pub fn parse_launchv(argv: &[&str]) -> Result { + assert_initialized_main_thread!(); unsafe { let mut error = ptr::null_mut(); let ret = ffi::gst_parse_launchv(argv.to_glib_none().0, &mut error); @@ -299,42 +319,49 @@ pub fn parse_launchv(argv: &[&str]) -> Result { //} pub fn protection_meta_api_get_type() -> glib::types::Type { + assert_initialized_main_thread!(); unsafe { from_glib(ffi::gst_protection_meta_api_get_type()) } } pub fn segtrap_is_enabled() -> bool { + assert_initialized_main_thread!(); unsafe { from_glib(ffi::gst_segtrap_is_enabled()) } } pub fn segtrap_set_enabled(enabled: bool) { + assert_initialized_main_thread!(); unsafe { ffi::gst_segtrap_set_enabled(enabled.to_glib()); } } pub fn static_caps_get_type() -> glib::types::Type { + assert_initialized_main_thread!(); unsafe { from_glib(ffi::gst_static_caps_get_type()) } } pub fn static_pad_template_get_type() -> glib::types::Type { + assert_initialized_main_thread!(); unsafe { from_glib(ffi::gst_static_pad_template_get_type()) } } pub fn tag_exists(tag: &str) -> bool { + assert_initialized_main_thread!(); unsafe { from_glib(ffi::gst_tag_exists(tag.to_glib_none().0)) } } pub fn tag_get_description(tag: &str) -> Option { + assert_initialized_main_thread!(); unsafe { from_glib_none(ffi::gst_tag_get_description(tag.to_glib_none().0)) } @@ -345,18 +372,21 @@ pub fn tag_get_description(tag: &str) -> Option { //} pub fn tag_get_nick(tag: &str) -> Option { + assert_initialized_main_thread!(); unsafe { from_glib_none(ffi::gst_tag_get_nick(tag.to_glib_none().0)) } } pub fn tag_get_type(tag: &str) -> glib::types::Type { + assert_initialized_main_thread!(); unsafe { from_glib(ffi::gst_tag_get_type(tag.to_glib_none().0)) } } pub fn tag_is_fixed(tag: &str) -> bool { + assert_initialized_main_thread!(); unsafe { from_glib(ffi::gst_tag_is_fixed(tag.to_glib_none().0)) } @@ -379,12 +409,14 @@ pub fn tag_is_fixed(tag: &str) -> bool { //} pub fn type_find_get_type() -> glib::types::Type { + assert_initialized_main_thread!(); unsafe { from_glib(ffi::gst_type_find_get_type()) } } pub fn update_registry() -> Result<(), glib::error::BoolError> { + assert_initialized_main_thread!(); unsafe { glib::error::BoolError::from_glib(ffi::gst_update_registry(), "Failed to update registry") } @@ -395,6 +427,7 @@ pub fn update_registry() -> Result<(), glib::error::BoolError> { //} pub fn util_double_to_fraction(src: f64) -> (i32, i32) { + assert_initialized_main_thread!(); unsafe { let mut dest_n = mem::uninitialized(); let mut dest_d = mem::uninitialized(); @@ -404,6 +437,7 @@ pub fn util_double_to_fraction(src: f64) -> (i32, i32) { } pub fn util_fraction_add(a_n: i32, a_d: i32, b_n: i32, b_d: i32) -> Option<(i32, i32)> { + assert_initialized_main_thread!(); unsafe { let mut res_n = mem::uninitialized(); let mut res_d = mem::uninitialized(); @@ -413,12 +447,14 @@ pub fn util_fraction_add(a_n: i32, a_d: i32, b_n: i32, b_d: i32) -> Option<(i32, } pub fn util_fraction_compare(a_n: i32, a_d: i32, b_n: i32, b_d: i32) -> i32 { + assert_initialized_main_thread!(); unsafe { ffi::gst_util_fraction_compare(a_n, a_d, b_n, b_d) } } pub fn util_fraction_multiply(a_n: i32, a_d: i32, b_n: i32, b_d: i32) -> Option<(i32, i32)> { + assert_initialized_main_thread!(); unsafe { let mut res_n = mem::uninitialized(); let mut res_d = mem::uninitialized(); @@ -428,6 +464,7 @@ pub fn util_fraction_multiply(a_n: i32, a_d: i32, b_n: i32, b_d: i32) -> Option< } pub fn util_fraction_to_double(src_n: i32, src_d: i32) -> f64 { + assert_initialized_main_thread!(); unsafe { let mut dest = mem::uninitialized(); ffi::gst_util_fraction_to_double(src_n, src_d, &mut dest); @@ -436,6 +473,7 @@ pub fn util_fraction_to_double(src_n: i32, src_d: i32) -> f64 { } pub fn util_gdouble_to_guint64(value: f64) -> u64 { + assert_initialized_main_thread!(); unsafe { ffi::gst_util_gdouble_to_guint64(value) } @@ -447,42 +485,49 @@ pub fn util_gdouble_to_guint64(value: f64) -> u64 { //} pub fn util_get_timestamp() -> ClockTime { + assert_initialized_main_thread!(); unsafe { ffi::gst_util_get_timestamp() } } pub fn util_greatest_common_divisor(a: i32, b: i32) -> i32 { + assert_initialized_main_thread!(); unsafe { ffi::gst_util_greatest_common_divisor(a, b) } } pub fn util_greatest_common_divisor_int64(a: i64, b: i64) -> i64 { + assert_initialized_main_thread!(); unsafe { ffi::gst_util_greatest_common_divisor_int64(a, b) } } pub fn util_group_id_next() -> u32 { + assert_initialized_main_thread!(); unsafe { ffi::gst_util_group_id_next() } } pub fn util_guint64_to_gdouble(value: u64) -> f64 { + assert_initialized_main_thread!(); unsafe { ffi::gst_util_guint64_to_gdouble(value) } } pub fn util_seqnum_compare(s1: u32, s2: u32) -> i32 { + assert_initialized_main_thread!(); unsafe { ffi::gst_util_seqnum_compare(s1, s2) } } pub fn util_seqnum_next() -> u32 { + assert_initialized_main_thread!(); unsafe { ffi::gst_util_seqnum_next() } @@ -502,36 +547,42 @@ pub fn util_seqnum_next() -> u32 { //} pub fn util_uint64_scale(val: u64, num: u64, denom: u64) -> u64 { + assert_initialized_main_thread!(); unsafe { ffi::gst_util_uint64_scale(val, num, denom) } } pub fn util_uint64_scale_ceil(val: u64, num: u64, denom: u64) -> u64 { + assert_initialized_main_thread!(); unsafe { ffi::gst_util_uint64_scale_ceil(val, num, denom) } } pub fn util_uint64_scale_int(val: u64, num: i32, denom: i32) -> u64 { + assert_initialized_main_thread!(); unsafe { ffi::gst_util_uint64_scale_int(val, num, denom) } } pub fn util_uint64_scale_int_ceil(val: u64, num: i32, denom: i32) -> u64 { + assert_initialized_main_thread!(); unsafe { ffi::gst_util_uint64_scale_int_ceil(val, num, denom) } } pub fn util_uint64_scale_int_round(val: u64, num: i32, denom: i32) -> u64 { + assert_initialized_main_thread!(); unsafe { ffi::gst_util_uint64_scale_int_round(val, num, denom) } } pub fn util_uint64_scale_round(val: u64, num: u64, denom: u64) -> u64 { + assert_initialized_main_thread!(); unsafe { ffi::gst_util_uint64_scale_round(val, num, denom) } @@ -730,6 +781,7 @@ pub fn util_uint64_scale_round(val: u64, num: u64, denom: u64) -> u64 { //} pub fn version() -> (u32, u32, u32, u32) { + assert_initialized_main_thread!(); unsafe { let mut major = mem::uninitialized(); let mut minor = mem::uninitialized(); @@ -741,6 +793,7 @@ pub fn version() -> (u32, u32, u32, u32) { } pub fn version_string() -> Option { + assert_initialized_main_thread!(); unsafe { from_glib_full(ffi::gst_version_string()) } diff --git a/gstreamer/src/auto/object.rs b/gstreamer/src/auto/object.rs index 9e4fbaa76..ec159261d 100644 --- a/gstreamer/src/auto/object.rs +++ b/gstreamer/src/auto/object.rs @@ -18,6 +18,7 @@ glib_wrapper! { impl Object { pub fn check_uniqueness(list: &[Object], name: &str) -> bool { + assert_initialized_main_thread!(); unsafe { from_glib(ffi::gst_object_check_uniqueness(list.to_glib_none().0, name.to_glib_none().0)) } diff --git a/gstreamer/src/auto/pad.rs b/gstreamer/src/auto/pad.rs index bad553a50..4138b0b8c 100644 --- a/gstreamer/src/auto/pad.rs +++ b/gstreamer/src/auto/pad.rs @@ -34,6 +34,7 @@ glib_wrapper! { impl Pad { pub fn new<'a, P: Into>>(name: P, direction: PadDirection) -> Pad { + assert_initialized_main_thread!(); let name = name.into(); let name = name.to_glib_none(); unsafe { @@ -46,6 +47,7 @@ impl Pad { //} pub fn new_from_template<'a, P: Into>>(templ: &PadTemplate, name: P) -> Pad { + skip_assert_initialized!(); let name = name.into(); let name = name.to_glib_none(); unsafe { @@ -54,6 +56,7 @@ impl Pad { } pub fn link_get_name(ret: PadLinkReturn) -> Option { + assert_initialized_main_thread!(); unsafe { from_glib_none(ffi::gst_pad_link_get_name(ret.to_glib())) } diff --git a/gstreamer/src/auto/pipeline.rs b/gstreamer/src/auto/pipeline.rs index 4c789324b..e71d92d0f 100644 --- a/gstreamer/src/auto/pipeline.rs +++ b/gstreamer/src/auto/pipeline.rs @@ -21,6 +21,7 @@ glib_wrapper! { impl Pipeline { pub fn new<'a, P: Into>>(name: P) -> Pipeline { + assert_initialized_main_thread!(); let name = name.into(); let name = name.to_glib_none(); unsafe { diff --git a/gstreamer/src/auto/plugin.rs b/gstreamer/src/auto/plugin.rs index 5d6594f81..fa3bc54c5 100644 --- a/gstreamer/src/auto/plugin.rs +++ b/gstreamer/src/auto/plugin.rs @@ -98,18 +98,21 @@ impl Plugin { } pub fn list_free(list: &[Plugin]) { + assert_initialized_main_thread!(); unsafe { ffi::gst_plugin_list_free(list.to_glib_full()); } } pub fn load_by_name(name: &str) -> Option { + assert_initialized_main_thread!(); unsafe { from_glib_full(ffi::gst_plugin_load_by_name(name.to_glib_none().0)) } } pub fn load_file(filename: &str) -> Result { + assert_initialized_main_thread!(); unsafe { let mut error = ptr::null_mut(); let ret = ffi::gst_plugin_load_file(filename.to_glib_none().0, &mut error); diff --git a/gstreamer/src/auto/stream_collection.rs b/gstreamer/src/auto/stream_collection.rs index 8b22fe143..be06b181b 100644 --- a/gstreamer/src/auto/stream_collection.rs +++ b/gstreamer/src/auto/stream_collection.rs @@ -22,6 +22,7 @@ glib_wrapper! { impl StreamCollection { #[cfg(feature = "v1_10")] pub fn new<'a, P: Into>>(upstream_id: P) -> StreamCollection { + assert_initialized_main_thread!(); let upstream_id = upstream_id.into(); let upstream_id = upstream_id.to_glib_none(); unsafe { diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 9c70776cf..a1587d9ad 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -25,6 +25,17 @@ macro_rules! callback_guard { ) } +macro_rules! assert_initialized_main_thread { + () => ( + assert_eq!(unsafe {ffi::gst_is_initialized()}, ::glib_ffi::GTRUE) + ) +} + +macro_rules! skip_assert_initialized { + () => ( + ) +} + pub use glib::{ Cast, Continue, diff --git a/gstreamer/src/message.rs b/gstreamer/src/message.rs index 47612495f..bf64eab6b 100644 --- a/gstreamer/src/message.rs +++ b/gstreamer/src/message.rs @@ -724,6 +724,7 @@ macro_rules! message_builder_generic_impl { } pub fn build(mut self) -> Message { + assert_initialized_main_thread!(); unsafe { let src = self.src.to_glib_none().0; let msg = $new_fn(&mut self, src); diff --git a/gstreamer/src/structure.rs b/gstreamer/src/structure.rs index 13a121e0f..ab0eb1161 100644 --- a/gstreamer/src/structure.rs +++ b/gstreamer/src/structure.rs @@ -24,6 +24,7 @@ pub struct Structure(*mut StructureRef, PhantomData, bool); impl Structure { pub fn new_empty(name: &str) -> Structure { + assert_initialized_main_thread!(); Structure( unsafe { ffi::gst_structure_new_empty(name.to_glib_none().0) as *mut StructureRef }, PhantomData, @@ -32,6 +33,7 @@ impl Structure { } pub fn new(name: &str, values: &[(&str, &Value)]) -> Structure { + assert_initialized_main_thread!(); let mut structure = Structure::new_empty(name); for &(f, v) in values { @@ -42,6 +44,7 @@ impl Structure { } pub fn from_string(s: &str) -> Option { + assert_initialized_main_thread!(); unsafe { let structure = ffi::gst_structure_from_string(s.to_glib_none().0, ptr::null_mut()); if structure.is_null() {