Add initialization safety assertions

Ensure that GStreamer is initialized before allowing to call any
functions
This commit is contained in:
Sebastian Dröge 2017-07-10 12:36:15 +03:00
parent 992105b49f
commit e43bf21ded
19 changed files with 127 additions and 0 deletions

View file

@ -6,6 +6,7 @@ min_cfg_version = "1.8"
target_path = "gstreamer" target_path = "gstreamer"
work_mode = "normal" work_mode = "normal"
concurrency = "send+sync" concurrency = "send+sync"
generate_safety_asserts = true
external_libraries = [ external_libraries = [
"GLib", "GLib",

View file

@ -27,6 +27,7 @@ glib_wrapper! {
impl Bin { impl Bin {
pub fn new<'a, P: Into<Option<&'a str>>>(name: P) -> Bin { pub fn new<'a, P: Into<Option<&'a str>>>(name: P) -> Bin {
assert_initialized_main_thread!();
let name = name.into(); let name = name.into();
let name = name.to_glib_none(); let name = name.to_glib_none();
unsafe { unsafe {

View file

@ -21,6 +21,7 @@ glib_wrapper! {
impl Bus { impl Bus {
pub fn new() -> Bus { pub fn new() -> Bus {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full(ffi::gst_bus_new()) from_glib_full(ffi::gst_bus_new())
} }

View file

@ -21,6 +21,7 @@ glib_wrapper! {
impl DeviceMonitor { impl DeviceMonitor {
pub fn new() -> DeviceMonitor { pub fn new() -> DeviceMonitor {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full(ffi::gst_device_monitor_new()) from_glib_full(ffi::gst_device_monitor_new())
} }

View file

@ -27,6 +27,7 @@ glib_wrapper! {
impl DeviceProvider { impl DeviceProvider {
pub fn register<'a, P: Into<Option<&'a Plugin>>>(plugin: P, name: &str, rank: u32, type_: glib::types::Type) -> bool { pub fn register<'a, P: Into<Option<&'a Plugin>>>(plugin: P, name: &str, rank: u32, type_: glib::types::Type) -> bool {
assert_initialized_main_thread!();
let plugin = plugin.into(); let plugin = plugin.into();
let plugin = plugin.to_glib_none(); let plugin = plugin.to_glib_none();
unsafe { unsafe {

View file

@ -18,12 +18,14 @@ glib_wrapper! {
impl DeviceProviderFactory { impl DeviceProviderFactory {
pub fn find(name: &str) -> Option<DeviceProviderFactory> { pub fn find(name: &str) -> Option<DeviceProviderFactory> {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full(ffi::gst_device_provider_factory_find(name.to_glib_none().0)) from_glib_full(ffi::gst_device_provider_factory_find(name.to_glib_none().0))
} }
} }
pub fn get_by_name(factoryname: &str) -> Option<DeviceProvider> { pub fn get_by_name(factoryname: &str) -> Option<DeviceProvider> {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full(ffi::gst_device_provider_factory_get_by_name(factoryname.to_glib_none().0)) from_glib_full(ffi::gst_device_provider_factory_get_by_name(factoryname.to_glib_none().0))
} }

View file

@ -42,6 +42,7 @@ glib_wrapper! {
impl Element { impl Element {
pub fn make_from_uri<'a, P: Into<Option<&'a str>>>(type_: URIType, uri: &str, elementname: P) -> Result<Element, Error> { pub fn make_from_uri<'a, P: Into<Option<&'a str>>>(type_: URIType, uri: &str, elementname: P) -> Result<Element, Error> {
assert_initialized_main_thread!();
let elementname = elementname.into(); let elementname = elementname.into();
let elementname = elementname.to_glib_none(); let elementname = elementname.to_glib_none();
unsafe { unsafe {
@ -52,6 +53,7 @@ impl Element {
} }
pub fn register<'a, P: Into<Option<&'a Plugin>>>(plugin: P, name: &str, rank: u32, type_: glib::types::Type) -> bool { pub fn register<'a, P: Into<Option<&'a Plugin>>>(plugin: P, name: &str, rank: u32, type_: glib::types::Type) -> bool {
assert_initialized_main_thread!();
let plugin = plugin.into(); let plugin = plugin.into();
let plugin = plugin.to_glib_none(); let plugin = plugin.to_glib_none();
unsafe { unsafe {
@ -60,12 +62,14 @@ impl Element {
} }
pub fn state_change_return_get_name(state_ret: StateChangeReturn) -> Option<String> { pub fn state_change_return_get_name(state_ret: StateChangeReturn) -> Option<String> {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_none(ffi::gst_element_state_change_return_get_name(state_ret.to_glib())) from_glib_none(ffi::gst_element_state_change_return_get_name(state_ret.to_glib()))
} }
} }
pub fn state_get_name(state: State) -> Option<String> { pub fn state_get_name(state: State) -> Option<String> {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_none(ffi::gst_element_state_get_name(state.to_glib())) from_glib_none(ffi::gst_element_state_get_name(state.to_glib()))
} }

View file

@ -95,6 +95,7 @@ impl ElementFactory {
} }
pub fn find(name: &str) -> Option<ElementFactory> { pub fn find(name: &str) -> Option<ElementFactory> {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full(ffi::gst_element_factory_find(name.to_glib_none().0)) 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<Option<&'a str>>>(factoryname: &str, name: P) -> Option<Element> { pub fn make<'a, P: Into<Option<&'a str>>>(factoryname: &str, name: P) -> Option<Element> {
assert_initialized_main_thread!();
let name = name.into(); let name = name.into();
let name = name.to_glib_none(); let name = name.to_glib_none();
unsafe { unsafe {

View file

@ -35,6 +35,7 @@ impl ToGlib for BufferingMode {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstBufferingMode> for BufferingMode { impl FromGlib<ffi::GstBufferingMode> for BufferingMode {
fn from_glib(value: ffi::GstBufferingMode) -> Self { fn from_glib(value: ffi::GstBufferingMode) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
0 => BufferingMode::Stream, 0 => BufferingMode::Stream,
1 => BufferingMode::Download, 1 => BufferingMode::Download,
@ -95,6 +96,7 @@ impl ToGlib for CoreError {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstCoreError> for CoreError { impl FromGlib<ffi::GstCoreError> for CoreError {
fn from_glib(value: ffi::GstCoreError) -> Self { fn from_glib(value: ffi::GstCoreError) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
1 => CoreError::Failed, 1 => CoreError::Failed,
2 => CoreError::TooLazy, 2 => CoreError::TooLazy,
@ -118,6 +120,7 @@ impl FromGlib<ffi::GstCoreError> for CoreError {
impl ErrorDomain for CoreError { impl ErrorDomain for CoreError {
fn domain() -> glib_ffi::GQuark { fn domain() -> glib_ffi::GQuark {
skip_assert_initialized!();
unsafe { ffi::gst_core_error_quark() } unsafe { ffi::gst_core_error_quark() }
} }
@ -126,6 +129,7 @@ impl ErrorDomain for CoreError {
} }
fn from(code: i32) -> Option<Self> { fn from(code: i32) -> Option<Self> {
skip_assert_initialized!();
match code { match code {
1 => Some(CoreError::Failed), 1 => Some(CoreError::Failed),
2 => Some(CoreError::TooLazy), 2 => Some(CoreError::TooLazy),
@ -193,6 +197,7 @@ impl ToGlib for FlowReturn {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstFlowReturn> for FlowReturn { impl FromGlib<ffi::GstFlowReturn> for FlowReturn {
fn from_glib(value: ffi::GstFlowReturn) -> Self { fn from_glib(value: ffi::GstFlowReturn) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
102 => FlowReturn::CustomSuccess2, 102 => FlowReturn::CustomSuccess2,
101 => FlowReturn::CustomSuccess1, 101 => FlowReturn::CustomSuccess1,
@ -244,6 +249,7 @@ impl ToGlib for Format {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstFormat> for Format { impl FromGlib<ffi::GstFormat> for Format {
fn from_glib(value: ffi::GstFormat) -> Self { fn from_glib(value: ffi::GstFormat) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
0 => Format::Undefined, 0 => Format::Undefined,
1 => Format::Default, 1 => Format::Default,
@ -290,6 +296,7 @@ impl ToGlib for LibraryError {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstLibraryError> for LibraryError { impl FromGlib<ffi::GstLibraryError> for LibraryError {
fn from_glib(value: ffi::GstLibraryError) -> Self { fn from_glib(value: ffi::GstLibraryError) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
1 => LibraryError::Failed, 1 => LibraryError::Failed,
2 => LibraryError::TooLazy, 2 => LibraryError::TooLazy,
@ -305,6 +312,7 @@ impl FromGlib<ffi::GstLibraryError> for LibraryError {
impl ErrorDomain for LibraryError { impl ErrorDomain for LibraryError {
fn domain() -> glib_ffi::GQuark { fn domain() -> glib_ffi::GQuark {
skip_assert_initialized!();
unsafe { ffi::gst_library_error_quark() } unsafe { ffi::gst_library_error_quark() }
} }
@ -313,6 +321,7 @@ impl ErrorDomain for LibraryError {
} }
fn from(code: i32) -> Option<Self> { fn from(code: i32) -> Option<Self> {
skip_assert_initialized!();
match code { match code {
1 => Some(LibraryError::Failed), 1 => Some(LibraryError::Failed),
2 => Some(LibraryError::TooLazy), 2 => Some(LibraryError::TooLazy),
@ -352,6 +361,7 @@ impl ToGlib for PadDirection {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstPadDirection> for PadDirection { impl FromGlib<ffi::GstPadDirection> for PadDirection {
fn from_glib(value: ffi::GstPadDirection) -> Self { fn from_glib(value: ffi::GstPadDirection) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
0 => PadDirection::Unknown, 0 => PadDirection::Unknown,
1 => PadDirection::Src, 1 => PadDirection::Src,
@ -395,6 +405,7 @@ impl ToGlib for PadLinkReturn {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstPadLinkReturn> for PadLinkReturn { impl FromGlib<ffi::GstPadLinkReturn> for PadLinkReturn {
fn from_glib(value: ffi::GstPadLinkReturn) -> Self { fn from_glib(value: ffi::GstPadLinkReturn) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
0 => PadLinkReturn::Ok, 0 => PadLinkReturn::Ok,
-1 => PadLinkReturn::WrongHierarchy, -1 => PadLinkReturn::WrongHierarchy,
@ -444,6 +455,7 @@ impl ToGlib for ParseError {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstParseError> for ParseError { impl FromGlib<ffi::GstParseError> for ParseError {
fn from_glib(value: ffi::GstParseError) -> Self { fn from_glib(value: ffi::GstParseError) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
0 => ParseError::Syntax, 0 => ParseError::Syntax,
1 => ParseError::NoSuchElement, 1 => ParseError::NoSuchElement,
@ -460,6 +472,7 @@ impl FromGlib<ffi::GstParseError> for ParseError {
impl ErrorDomain for ParseError { impl ErrorDomain for ParseError {
fn domain() -> glib_ffi::GQuark { fn domain() -> glib_ffi::GQuark {
skip_assert_initialized!();
unsafe { ffi::gst_parse_error_quark() } unsafe { ffi::gst_parse_error_quark() }
} }
@ -468,6 +481,7 @@ impl ErrorDomain for ParseError {
} }
fn from(code: i32) -> Option<Self> { fn from(code: i32) -> Option<Self> {
skip_assert_initialized!();
match code { match code {
0 => Some(ParseError::Syntax), 0 => Some(ParseError::Syntax),
1 => Some(ParseError::NoSuchElement), 1 => Some(ParseError::NoSuchElement),
@ -508,6 +522,7 @@ impl ToGlib for PluginError {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstPluginError> for PluginError { impl FromGlib<ffi::GstPluginError> for PluginError {
fn from_glib(value: ffi::GstPluginError) -> Self { fn from_glib(value: ffi::GstPluginError) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
0 => PluginError::Module, 0 => PluginError::Module,
1 => PluginError::Dependencies, 1 => PluginError::Dependencies,
@ -519,6 +534,7 @@ impl FromGlib<ffi::GstPluginError> for PluginError {
impl ErrorDomain for PluginError { impl ErrorDomain for PluginError {
fn domain() -> glib_ffi::GQuark { fn domain() -> glib_ffi::GQuark {
skip_assert_initialized!();
unsafe { ffi::gst_plugin_error_quark() } unsafe { ffi::gst_plugin_error_quark() }
} }
@ -527,6 +543,7 @@ impl ErrorDomain for PluginError {
} }
fn from(code: i32) -> Option<Self> { fn from(code: i32) -> Option<Self> {
skip_assert_initialized!();
match code { match code {
0 => Some(PluginError::Module), 0 => Some(PluginError::Module),
1 => Some(PluginError::Dependencies), 1 => Some(PluginError::Dependencies),
@ -566,6 +583,7 @@ impl ToGlib for ProgressType {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstProgressType> for ProgressType { impl FromGlib<ffi::GstProgressType> for ProgressType {
fn from_glib(value: ffi::GstProgressType) -> Self { fn from_glib(value: ffi::GstProgressType) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
0 => ProgressType::Start, 0 => ProgressType::Start,
1 => ProgressType::Continue, 1 => ProgressType::Continue,
@ -629,6 +647,7 @@ impl ToGlib for ResourceError {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstResourceError> for ResourceError { impl FromGlib<ffi::GstResourceError> for ResourceError {
fn from_glib(value: ffi::GstResourceError) -> Self { fn from_glib(value: ffi::GstResourceError) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
1 => ResourceError::Failed, 1 => ResourceError::Failed,
2 => ResourceError::TooLazy, 2 => ResourceError::TooLazy,
@ -653,6 +672,7 @@ impl FromGlib<ffi::GstResourceError> for ResourceError {
impl ErrorDomain for ResourceError { impl ErrorDomain for ResourceError {
fn domain() -> glib_ffi::GQuark { fn domain() -> glib_ffi::GQuark {
skip_assert_initialized!();
unsafe { ffi::gst_resource_error_quark() } unsafe { ffi::gst_resource_error_quark() }
} }
@ -661,6 +681,7 @@ impl ErrorDomain for ResourceError {
} }
fn from(code: i32) -> Option<Self> { fn from(code: i32) -> Option<Self> {
skip_assert_initialized!();
match code { match code {
1 => Some(ResourceError::Failed), 1 => Some(ResourceError::Failed),
2 => Some(ResourceError::TooLazy), 2 => Some(ResourceError::TooLazy),
@ -709,6 +730,7 @@ impl ToGlib for SeekType {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstSeekType> for SeekType { impl FromGlib<ffi::GstSeekType> for SeekType {
fn from_glib(value: ffi::GstSeekType) -> Self { fn from_glib(value: ffi::GstSeekType) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
0 => SeekType::None, 0 => SeekType::None,
1 => SeekType::Set, 1 => SeekType::Set,
@ -748,6 +770,7 @@ impl ToGlib for State {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstState> for State { impl FromGlib<ffi::GstState> for State {
fn from_glib(value: ffi::GstState) -> Self { fn from_glib(value: ffi::GstState) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
0 => State::VoidPending, 0 => State::VoidPending,
1 => State::Null, 1 => State::Null,
@ -791,6 +814,7 @@ impl ToGlib for StateChange {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstStateChange> for StateChange { impl FromGlib<ffi::GstStateChange> for StateChange {
fn from_glib(value: ffi::GstStateChange) -> Self { fn from_glib(value: ffi::GstStateChange) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
10 => StateChange::NullToReady, 10 => StateChange::NullToReady,
19 => StateChange::ReadyToPaused, 19 => StateChange::ReadyToPaused,
@ -831,6 +855,7 @@ impl ToGlib for StateChangeReturn {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstStateChangeReturn> for StateChangeReturn { impl FromGlib<ffi::GstStateChangeReturn> for StateChangeReturn {
fn from_glib(value: ffi::GstStateChangeReturn) -> Self { fn from_glib(value: ffi::GstStateChangeReturn) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
0 => StateChangeReturn::Failure, 0 => StateChangeReturn::Failure,
1 => StateChangeReturn::Success, 1 => StateChangeReturn::Success,
@ -889,6 +914,7 @@ impl ToGlib for StreamError {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstStreamError> for StreamError { impl FromGlib<ffi::GstStreamError> for StreamError {
fn from_glib(value: ffi::GstStreamError) -> Self { fn from_glib(value: ffi::GstStreamError) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
1 => StreamError::Failed, 1 => StreamError::Failed,
2 => StreamError::TooLazy, 2 => StreamError::TooLazy,
@ -911,6 +937,7 @@ impl FromGlib<ffi::GstStreamError> for StreamError {
impl ErrorDomain for StreamError { impl ErrorDomain for StreamError {
fn domain() -> glib_ffi::GQuark { fn domain() -> glib_ffi::GQuark {
skip_assert_initialized!();
unsafe { ffi::gst_stream_error_quark() } unsafe { ffi::gst_stream_error_quark() }
} }
@ -919,6 +946,7 @@ impl ErrorDomain for StreamError {
} }
fn from(code: i32) -> Option<Self> { fn from(code: i32) -> Option<Self> {
skip_assert_initialized!();
match code { match code {
1 => Some(StreamError::Failed), 1 => Some(StreamError::Failed),
2 => Some(StreamError::TooLazy), 2 => Some(StreamError::TooLazy),
@ -973,6 +1001,7 @@ impl ToGlib for StreamStatusType {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstStreamStatusType> for StreamStatusType { impl FromGlib<ffi::GstStreamStatusType> for StreamStatusType {
fn from_glib(value: ffi::GstStreamStatusType) -> Self { fn from_glib(value: ffi::GstStreamStatusType) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
0 => StreamStatusType::Create, 0 => StreamStatusType::Create,
1 => StreamStatusType::Enter, 1 => StreamStatusType::Enter,
@ -1010,6 +1039,7 @@ impl ToGlib for StructureChangeType {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstStructureChangeType> for StructureChangeType { impl FromGlib<ffi::GstStructureChangeType> for StructureChangeType {
fn from_glib(value: ffi::GstStructureChangeType) -> Self { fn from_glib(value: ffi::GstStructureChangeType) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
0 => StructureChangeType::Link, 0 => StructureChangeType::Link,
1 => StructureChangeType::Unlink, 1 => StructureChangeType::Unlink,
@ -1046,6 +1076,7 @@ impl ToGlib for URIError {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstURIError> for URIError { impl FromGlib<ffi::GstURIError> for URIError {
fn from_glib(value: ffi::GstURIError) -> Self { fn from_glib(value: ffi::GstURIError) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
0 => URIError::UnsupportedProtocol, 0 => URIError::UnsupportedProtocol,
1 => URIError::BadUri, 1 => URIError::BadUri,
@ -1058,6 +1089,7 @@ impl FromGlib<ffi::GstURIError> for URIError {
impl ErrorDomain for URIError { impl ErrorDomain for URIError {
fn domain() -> glib_ffi::GQuark { fn domain() -> glib_ffi::GQuark {
skip_assert_initialized!();
unsafe { ffi::gst_uri_error_quark() } unsafe { ffi::gst_uri_error_quark() }
} }
@ -1066,6 +1098,7 @@ impl ErrorDomain for URIError {
} }
fn from(code: i32) -> Option<Self> { fn from(code: i32) -> Option<Self> {
skip_assert_initialized!();
match code { match code {
0 => Some(URIError::UnsupportedProtocol), 0 => Some(URIError::UnsupportedProtocol),
1 => Some(URIError::BadUri), 1 => Some(URIError::BadUri),
@ -1102,6 +1135,7 @@ impl ToGlib for URIType {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstURIType> for URIType { impl FromGlib<ffi::GstURIType> for URIType {
fn from_glib(value: ffi::GstURIType) -> Self { fn from_glib(value: ffi::GstURIType) -> Self {
skip_assert_initialized!();
match value as i32 { match value as i32 {
0 => URIType::Unknown, 0 => URIType::Unknown,
1 => URIType::Sink, 1 => URIType::Sink,

View file

@ -33,6 +33,7 @@ impl ToGlib for SeekFlags {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstSeekFlags> for SeekFlags { impl FromGlib<ffi::GstSeekFlags> for SeekFlags {
fn from_glib(value: ffi::GstSeekFlags) -> SeekFlags { fn from_glib(value: ffi::GstSeekFlags) -> SeekFlags {
skip_assert_initialized!();
SeekFlags::from_bits_truncate(value.bits()) SeekFlags::from_bits_truncate(value.bits())
} }
} }
@ -58,6 +59,7 @@ impl ToGlib for StreamFlags {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstStreamFlags> for StreamFlags { impl FromGlib<ffi::GstStreamFlags> for StreamFlags {
fn from_glib(value: ffi::GstStreamFlags) -> StreamFlags { fn from_glib(value: ffi::GstStreamFlags) -> StreamFlags {
skip_assert_initialized!();
StreamFlags::from_bits_truncate(value.bits()) StreamFlags::from_bits_truncate(value.bits())
} }
} }
@ -84,6 +86,7 @@ impl ToGlib for StreamType {
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<ffi::GstStreamType> for StreamType { impl FromGlib<ffi::GstStreamType> for StreamType {
fn from_glib(value: ffi::GstStreamType) -> StreamType { fn from_glib(value: ffi::GstStreamType) -> StreamType {
skip_assert_initialized!();
StreamType::from_bits_truncate(value.bits()) StreamType::from_bits_truncate(value.bits())
} }
} }

View file

@ -16,6 +16,7 @@ use std::ptr;
#[cfg(feature = "v1_12")] #[cfg(feature = "v1_12")]
pub fn calculate_linear_regression(xy: ClockTime, temp: ClockTime, n: u32) -> Option<(ClockTime, ClockTime, ClockTime, ClockTime, f64)> { pub fn calculate_linear_regression(xy: ClockTime, temp: ClockTime, n: u32) -> Option<(ClockTime, ClockTime, ClockTime, ClockTime, f64)> {
assert_initialized_main_thread!();
unsafe { unsafe {
let mut m_num = mem::uninitialized(); let mut m_num = mem::uninitialized();
let mut m_denom = 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<String> { pub fn debug_construct_term_color(colorinfo: u32) -> Option<String> {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full(ffi::gst_debug_construct_term_color(colorinfo)) from_glib_full(ffi::gst_debug_construct_term_color(colorinfo))
} }
} }
pub fn debug_construct_win_color(colorinfo: u32) -> i32 { pub fn debug_construct_win_color(colorinfo: u32) -> i32 {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_debug_construct_win_color(colorinfo) 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 { pub fn debug_is_active() -> bool {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib(ffi::gst_debug_is_active()) from_glib(ffi::gst_debug_is_active())
} }
} }
pub fn debug_is_colored() -> bool { pub fn debug_is_colored() -> bool {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib(ffi::gst_debug_is_colored()) from_glib(ffi::gst_debug_is_colored())
} }
@ -97,6 +102,7 @@ pub fn debug_is_colored() -> bool {
//} //}
pub fn debug_print_stack_trace() { pub fn debug_print_stack_trace() {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_debug_print_stack_trace(); ffi::gst_debug_print_stack_trace();
} }
@ -111,6 +117,7 @@ pub fn debug_print_stack_trace() {
//} //}
pub fn debug_set_active(active: bool) { pub fn debug_set_active(active: bool) {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_debug_set_active(active.to_glib()); 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) { pub fn debug_set_color_mode_from_string(mode: &str) {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_debug_set_color_mode_from_string(mode.to_glib_none().0); ffi::gst_debug_set_color_mode_from_string(mode.to_glib_none().0);
} }
} }
pub fn debug_set_colored(colored: bool) { pub fn debug_set_colored(colored: bool) {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_debug_set_colored(colored.to_glib()); 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) { pub fn debug_set_threshold_from_string(list: &str, reset: bool) {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_debug_set_threshold_from_string(list.to_glib_none().0, reset.to_glib()); ffi::gst_debug_set_threshold_from_string(list.to_glib_none().0, reset.to_glib());
} }
} }
pub fn debug_unset_threshold_for_name(name: &str) { pub fn debug_unset_threshold_for_name(name: &str) {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_debug_unset_threshold_for_name(name.to_glib_none().0); ffi::gst_debug_unset_threshold_for_name(name.to_glib_none().0);
} }
} }
pub fn deinit() { pub fn deinit() {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_deinit(); ffi::gst_deinit();
} }
} }
pub fn dynamic_type_register(plugin: &Plugin, type_: glib::types::Type) -> bool { pub fn dynamic_type_register(plugin: &Plugin, type_: glib::types::Type) -> bool {
skip_assert_initialized!();
unsafe { unsafe {
from_glib(ffi::gst_dynamic_type_register(plugin.to_glib_none().0, type_.to_glib())) 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<String, Error> { pub fn filename_to_uri(filename: &str) -> Result<String, Error> {
assert_initialized_main_thread!();
unsafe { unsafe {
let mut error = ptr::null_mut(); let mut error = ptr::null_mut();
let ret = ffi::gst_filename_to_uri(filename.to_glib_none().0, &mut error); 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<String, Error> {
} }
pub fn flow_get_name(ret: FlowReturn) -> Option<String> { pub fn flow_get_name(ret: FlowReturn) -> Option<String> {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_none(ffi::gst_flow_get_name(ret.to_glib())) from_glib_none(ffi::gst_flow_get_name(ret.to_glib()))
} }
@ -219,6 +234,7 @@ pub fn flow_get_name(ret: FlowReturn) -> Option<String> {
//} //}
pub fn is_initialized() -> bool { pub fn is_initialized() -> bool {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib(ffi::gst_is_initialized()) 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 { pub fn parent_buffer_meta_api_get_type() -> glib::types::Type {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib(ffi::gst_parent_buffer_meta_api_get_type()) from_glib(ffi::gst_parent_buffer_meta_api_get_type())
} }
} }
pub fn parse_bin_from_description(bin_description: &str, ghost_unlinked_pads: bool) -> Result<Option<Bin>, Error> { pub fn parse_bin_from_description(bin_description: &str, ghost_unlinked_pads: bool) -> Result<Option<Bin>, Error> {
assert_initialized_main_thread!();
unsafe { unsafe {
let mut error = ptr::null_mut(); 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); 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<Element, Error> { pub fn parse_launch(pipeline_description: &str) -> Result<Element, Error> {
assert_initialized_main_thread!();
unsafe { unsafe {
let mut error = ptr::null_mut(); let mut error = ptr::null_mut();
let ret = ffi::gst_parse_launch(pipeline_description.to_glib_none().0, &mut error); 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<Element, Error> {
//} //}
pub fn parse_launchv(argv: &[&str]) -> Result<Element, Error> { pub fn parse_launchv(argv: &[&str]) -> Result<Element, Error> {
assert_initialized_main_thread!();
unsafe { unsafe {
let mut error = ptr::null_mut(); let mut error = ptr::null_mut();
let ret = ffi::gst_parse_launchv(argv.to_glib_none().0, &mut error); let ret = ffi::gst_parse_launchv(argv.to_glib_none().0, &mut error);
@ -299,42 +319,49 @@ pub fn parse_launchv(argv: &[&str]) -> Result<Element, Error> {
//} //}
pub fn protection_meta_api_get_type() -> glib::types::Type { pub fn protection_meta_api_get_type() -> glib::types::Type {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib(ffi::gst_protection_meta_api_get_type()) from_glib(ffi::gst_protection_meta_api_get_type())
} }
} }
pub fn segtrap_is_enabled() -> bool { pub fn segtrap_is_enabled() -> bool {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib(ffi::gst_segtrap_is_enabled()) from_glib(ffi::gst_segtrap_is_enabled())
} }
} }
pub fn segtrap_set_enabled(enabled: bool) { pub fn segtrap_set_enabled(enabled: bool) {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_segtrap_set_enabled(enabled.to_glib()); ffi::gst_segtrap_set_enabled(enabled.to_glib());
} }
} }
pub fn static_caps_get_type() -> glib::types::Type { pub fn static_caps_get_type() -> glib::types::Type {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib(ffi::gst_static_caps_get_type()) from_glib(ffi::gst_static_caps_get_type())
} }
} }
pub fn static_pad_template_get_type() -> glib::types::Type { pub fn static_pad_template_get_type() -> glib::types::Type {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib(ffi::gst_static_pad_template_get_type()) from_glib(ffi::gst_static_pad_template_get_type())
} }
} }
pub fn tag_exists(tag: &str) -> bool { pub fn tag_exists(tag: &str) -> bool {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib(ffi::gst_tag_exists(tag.to_glib_none().0)) from_glib(ffi::gst_tag_exists(tag.to_glib_none().0))
} }
} }
pub fn tag_get_description(tag: &str) -> Option<String> { pub fn tag_get_description(tag: &str) -> Option<String> {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_none(ffi::gst_tag_get_description(tag.to_glib_none().0)) 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<String> {
//} //}
pub fn tag_get_nick(tag: &str) -> Option<String> { pub fn tag_get_nick(tag: &str) -> Option<String> {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_none(ffi::gst_tag_get_nick(tag.to_glib_none().0)) from_glib_none(ffi::gst_tag_get_nick(tag.to_glib_none().0))
} }
} }
pub fn tag_get_type(tag: &str) -> glib::types::Type { pub fn tag_get_type(tag: &str) -> glib::types::Type {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib(ffi::gst_tag_get_type(tag.to_glib_none().0)) from_glib(ffi::gst_tag_get_type(tag.to_glib_none().0))
} }
} }
pub fn tag_is_fixed(tag: &str) -> bool { pub fn tag_is_fixed(tag: &str) -> bool {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib(ffi::gst_tag_is_fixed(tag.to_glib_none().0)) 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 { pub fn type_find_get_type() -> glib::types::Type {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib(ffi::gst_type_find_get_type()) from_glib(ffi::gst_type_find_get_type())
} }
} }
pub fn update_registry() -> Result<(), glib::error::BoolError> { pub fn update_registry() -> Result<(), glib::error::BoolError> {
assert_initialized_main_thread!();
unsafe { unsafe {
glib::error::BoolError::from_glib(ffi::gst_update_registry(), "Failed to update registry") 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) { pub fn util_double_to_fraction(src: f64) -> (i32, i32) {
assert_initialized_main_thread!();
unsafe { unsafe {
let mut dest_n = mem::uninitialized(); let mut dest_n = mem::uninitialized();
let mut dest_d = 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)> { 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 { unsafe {
let mut res_n = mem::uninitialized(); let mut res_n = mem::uninitialized();
let mut res_d = 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 { pub fn util_fraction_compare(a_n: i32, a_d: i32, b_n: i32, b_d: i32) -> i32 {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_util_fraction_compare(a_n, a_d, b_n, b_d) 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)> { 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 { unsafe {
let mut res_n = mem::uninitialized(); let mut res_n = mem::uninitialized();
let mut res_d = 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 { pub fn util_fraction_to_double(src_n: i32, src_d: i32) -> f64 {
assert_initialized_main_thread!();
unsafe { unsafe {
let mut dest = mem::uninitialized(); let mut dest = mem::uninitialized();
ffi::gst_util_fraction_to_double(src_n, src_d, &mut dest); 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 { pub fn util_gdouble_to_guint64(value: f64) -> u64 {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_util_gdouble_to_guint64(value) 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 { pub fn util_get_timestamp() -> ClockTime {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_util_get_timestamp() ffi::gst_util_get_timestamp()
} }
} }
pub fn util_greatest_common_divisor(a: i32, b: i32) -> i32 { pub fn util_greatest_common_divisor(a: i32, b: i32) -> i32 {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_util_greatest_common_divisor(a, b) ffi::gst_util_greatest_common_divisor(a, b)
} }
} }
pub fn util_greatest_common_divisor_int64(a: i64, b: i64) -> i64 { pub fn util_greatest_common_divisor_int64(a: i64, b: i64) -> i64 {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_util_greatest_common_divisor_int64(a, b) ffi::gst_util_greatest_common_divisor_int64(a, b)
} }
} }
pub fn util_group_id_next() -> u32 { pub fn util_group_id_next() -> u32 {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_util_group_id_next() ffi::gst_util_group_id_next()
} }
} }
pub fn util_guint64_to_gdouble(value: u64) -> f64 { pub fn util_guint64_to_gdouble(value: u64) -> f64 {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_util_guint64_to_gdouble(value) ffi::gst_util_guint64_to_gdouble(value)
} }
} }
pub fn util_seqnum_compare(s1: u32, s2: u32) -> i32 { pub fn util_seqnum_compare(s1: u32, s2: u32) -> i32 {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_util_seqnum_compare(s1, s2) ffi::gst_util_seqnum_compare(s1, s2)
} }
} }
pub fn util_seqnum_next() -> u32 { pub fn util_seqnum_next() -> u32 {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_util_seqnum_next() 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 { pub fn util_uint64_scale(val: u64, num: u64, denom: u64) -> u64 {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_util_uint64_scale(val, num, denom) ffi::gst_util_uint64_scale(val, num, denom)
} }
} }
pub fn util_uint64_scale_ceil(val: u64, num: u64, denom: u64) -> u64 { pub fn util_uint64_scale_ceil(val: u64, num: u64, denom: u64) -> u64 {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_util_uint64_scale_ceil(val, num, denom) ffi::gst_util_uint64_scale_ceil(val, num, denom)
} }
} }
pub fn util_uint64_scale_int(val: u64, num: i32, denom: i32) -> u64 { pub fn util_uint64_scale_int(val: u64, num: i32, denom: i32) -> u64 {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_util_uint64_scale_int(val, num, denom) ffi::gst_util_uint64_scale_int(val, num, denom)
} }
} }
pub fn util_uint64_scale_int_ceil(val: u64, num: i32, denom: i32) -> u64 { pub fn util_uint64_scale_int_ceil(val: u64, num: i32, denom: i32) -> u64 {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_util_uint64_scale_int_ceil(val, num, denom) ffi::gst_util_uint64_scale_int_ceil(val, num, denom)
} }
} }
pub fn util_uint64_scale_int_round(val: u64, num: i32, denom: i32) -> u64 { pub fn util_uint64_scale_int_round(val: u64, num: i32, denom: i32) -> u64 {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_util_uint64_scale_int_round(val, num, denom) ffi::gst_util_uint64_scale_int_round(val, num, denom)
} }
} }
pub fn util_uint64_scale_round(val: u64, num: u64, denom: u64) -> u64 { pub fn util_uint64_scale_round(val: u64, num: u64, denom: u64) -> u64 {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_util_uint64_scale_round(val, num, denom) 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) { pub fn version() -> (u32, u32, u32, u32) {
assert_initialized_main_thread!();
unsafe { unsafe {
let mut major = mem::uninitialized(); let mut major = mem::uninitialized();
let mut minor = mem::uninitialized(); let mut minor = mem::uninitialized();
@ -741,6 +793,7 @@ pub fn version() -> (u32, u32, u32, u32) {
} }
pub fn version_string() -> Option<String> { pub fn version_string() -> Option<String> {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full(ffi::gst_version_string()) from_glib_full(ffi::gst_version_string())
} }

View file

@ -18,6 +18,7 @@ glib_wrapper! {
impl Object { impl Object {
pub fn check_uniqueness(list: &[Object], name: &str) -> bool { pub fn check_uniqueness(list: &[Object], name: &str) -> bool {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib(ffi::gst_object_check_uniqueness(list.to_glib_none().0, name.to_glib_none().0)) from_glib(ffi::gst_object_check_uniqueness(list.to_glib_none().0, name.to_glib_none().0))
} }

View file

@ -34,6 +34,7 @@ glib_wrapper! {
impl Pad { impl Pad {
pub fn new<'a, P: Into<Option<&'a str>>>(name: P, direction: PadDirection) -> Pad { pub fn new<'a, P: Into<Option<&'a str>>>(name: P, direction: PadDirection) -> Pad {
assert_initialized_main_thread!();
let name = name.into(); let name = name.into();
let name = name.to_glib_none(); let name = name.to_glib_none();
unsafe { unsafe {
@ -46,6 +47,7 @@ impl Pad {
//} //}
pub fn new_from_template<'a, P: Into<Option<&'a str>>>(templ: &PadTemplate, name: P) -> Pad { pub fn new_from_template<'a, P: Into<Option<&'a str>>>(templ: &PadTemplate, name: P) -> Pad {
skip_assert_initialized!();
let name = name.into(); let name = name.into();
let name = name.to_glib_none(); let name = name.to_glib_none();
unsafe { unsafe {
@ -54,6 +56,7 @@ impl Pad {
} }
pub fn link_get_name(ret: PadLinkReturn) -> Option<String> { pub fn link_get_name(ret: PadLinkReturn) -> Option<String> {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_none(ffi::gst_pad_link_get_name(ret.to_glib())) from_glib_none(ffi::gst_pad_link_get_name(ret.to_glib()))
} }

View file

@ -21,6 +21,7 @@ glib_wrapper! {
impl Pipeline { impl Pipeline {
pub fn new<'a, P: Into<Option<&'a str>>>(name: P) -> Pipeline { pub fn new<'a, P: Into<Option<&'a str>>>(name: P) -> Pipeline {
assert_initialized_main_thread!();
let name = name.into(); let name = name.into();
let name = name.to_glib_none(); let name = name.to_glib_none();
unsafe { unsafe {

View file

@ -98,18 +98,21 @@ impl Plugin {
} }
pub fn list_free(list: &[Plugin]) { pub fn list_free(list: &[Plugin]) {
assert_initialized_main_thread!();
unsafe { unsafe {
ffi::gst_plugin_list_free(list.to_glib_full()); ffi::gst_plugin_list_free(list.to_glib_full());
} }
} }
pub fn load_by_name(name: &str) -> Option<Plugin> { pub fn load_by_name(name: &str) -> Option<Plugin> {
assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full(ffi::gst_plugin_load_by_name(name.to_glib_none().0)) from_glib_full(ffi::gst_plugin_load_by_name(name.to_glib_none().0))
} }
} }
pub fn load_file(filename: &str) -> Result<Plugin, Error> { pub fn load_file(filename: &str) -> Result<Plugin, Error> {
assert_initialized_main_thread!();
unsafe { unsafe {
let mut error = ptr::null_mut(); let mut error = ptr::null_mut();
let ret = ffi::gst_plugin_load_file(filename.to_glib_none().0, &mut error); let ret = ffi::gst_plugin_load_file(filename.to_glib_none().0, &mut error);

View file

@ -22,6 +22,7 @@ glib_wrapper! {
impl StreamCollection { impl StreamCollection {
#[cfg(feature = "v1_10")] #[cfg(feature = "v1_10")]
pub fn new<'a, P: Into<Option<&'a str>>>(upstream_id: P) -> StreamCollection { pub fn new<'a, P: Into<Option<&'a str>>>(upstream_id: P) -> StreamCollection {
assert_initialized_main_thread!();
let upstream_id = upstream_id.into(); let upstream_id = upstream_id.into();
let upstream_id = upstream_id.to_glib_none(); let upstream_id = upstream_id.to_glib_none();
unsafe { unsafe {

View file

@ -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::{ pub use glib::{
Cast, Cast,
Continue, Continue,

View file

@ -724,6 +724,7 @@ macro_rules! message_builder_generic_impl {
} }
pub fn build(mut self) -> Message { pub fn build(mut self) -> Message {
assert_initialized_main_thread!();
unsafe { unsafe {
let src = self.src.to_glib_none().0; let src = self.src.to_glib_none().0;
let msg = $new_fn(&mut self, src); let msg = $new_fn(&mut self, src);

View file

@ -24,6 +24,7 @@ pub struct Structure(*mut StructureRef, PhantomData<StructureRef>, bool);
impl Structure { impl Structure {
pub fn new_empty(name: &str) -> Structure { pub fn new_empty(name: &str) -> Structure {
assert_initialized_main_thread!();
Structure( Structure(
unsafe { ffi::gst_structure_new_empty(name.to_glib_none().0) as *mut StructureRef }, unsafe { ffi::gst_structure_new_empty(name.to_glib_none().0) as *mut StructureRef },
PhantomData, PhantomData,
@ -32,6 +33,7 @@ impl Structure {
} }
pub fn new(name: &str, values: &[(&str, &Value)]) -> Structure { pub fn new(name: &str, values: &[(&str, &Value)]) -> Structure {
assert_initialized_main_thread!();
let mut structure = Structure::new_empty(name); let mut structure = Structure::new_empty(name);
for &(f, v) in values { for &(f, v) in values {
@ -42,6 +44,7 @@ impl Structure {
} }
pub fn from_string(s: &str) -> Option<Structure> { pub fn from_string(s: &str) -> Option<Structure> {
assert_initialized_main_thread!();
unsafe { unsafe {
let structure = ffi::gst_structure_from_string(s.to_glib_none().0, ptr::null_mut()); let structure = ffi::gst_structure_from_string(s.to_glib_none().0, ptr::null_mut());
if structure.is_null() { if structure.is_null() {